cm_msgs.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. /*
  2. * Copyright (c) 2004, 2011 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  4. * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING the madirectory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use source and binary forms, with or
  13. * withmodification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retathe above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHWARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS THE
  32. * SOFTWARE.
  33. */
  34. #if !defined(CM_MSGS_H)
  35. #define CM_MSGS_H
  36. #include <rdma/ib_mad.h>
  37. #include <rdma/ib_cm.h>
  38. /*
  39. * Parameters to routines below should be in network-byte order, and values
  40. * are returned in network-byte order.
  41. */
  42. #define IB_CM_CLASS_VERSION 2 /* IB specification 1.2 */
  43. #define CM_REQ_ATTR_ID cpu_to_be16(0x0010)
  44. #define CM_MRA_ATTR_ID cpu_to_be16(0x0011)
  45. #define CM_REJ_ATTR_ID cpu_to_be16(0x0012)
  46. #define CM_REP_ATTR_ID cpu_to_be16(0x0013)
  47. #define CM_RTU_ATTR_ID cpu_to_be16(0x0014)
  48. #define CM_DREQ_ATTR_ID cpu_to_be16(0x0015)
  49. #define CM_DREP_ATTR_ID cpu_to_be16(0x0016)
  50. #define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017)
  51. #define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018)
  52. #define CM_LAP_ATTR_ID cpu_to_be16(0x0019)
  53. #define CM_APR_ATTR_ID cpu_to_be16(0x001A)
  54. enum cm_msg_sequence {
  55. CM_MSG_SEQUENCE_REQ,
  56. CM_MSG_SEQUENCE_LAP,
  57. CM_MSG_SEQUENCE_DREQ,
  58. CM_MSG_SEQUENCE_SIDR
  59. };
  60. struct cm_req_msg {
  61. struct ib_mad_hdr hdr;
  62. __be32 local_comm_id;
  63. __be32 rsvd4;
  64. __be64 service_id;
  65. __be64 local_ca_guid;
  66. __be32 rsvd24;
  67. __be32 local_qkey;
  68. /* local QPN:24, responder resources:8 */
  69. __be32 offset32;
  70. /* local EECN:24, initiator depth:8 */
  71. __be32 offset36;
  72. /*
  73. * remote EECN:24, remote CM response timeout:5,
  74. * transport service type:2, end-to-end flow control:1
  75. */
  76. __be32 offset40;
  77. /* starting PSN:24, local CM response timeout:5, retry count:3 */
  78. __be32 offset44;
  79. __be16 pkey;
  80. /* path MTU:4, RDC exists:1, RNR retry count:3. */
  81. u8 offset50;
  82. /* max CM Retries:4, SRQ:1, extended transport type:3 */
  83. u8 offset51;
  84. __be16 primary_local_lid;
  85. __be16 primary_remote_lid;
  86. union ib_gid primary_local_gid;
  87. union ib_gid primary_remote_gid;
  88. /* flow label:20, rsvd:6, packet rate:6 */
  89. __be32 primary_offset88;
  90. u8 primary_traffic_class;
  91. u8 primary_hop_limit;
  92. /* SL:4, subnet local:1, rsvd:3 */
  93. u8 primary_offset94;
  94. /* local ACK timeout:5, rsvd:3 */
  95. u8 primary_offset95;
  96. __be16 alt_local_lid;
  97. __be16 alt_remote_lid;
  98. union ib_gid alt_local_gid;
  99. union ib_gid alt_remote_gid;
  100. /* flow label:20, rsvd:6, packet rate:6 */
  101. __be32 alt_offset132;
  102. u8 alt_traffic_class;
  103. u8 alt_hop_limit;
  104. /* SL:4, subnet local:1, rsvd:3 */
  105. u8 alt_offset138;
  106. /* local ACK timeout:5, rsvd:3 */
  107. u8 alt_offset139;
  108. u8 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE];
  109. } __attribute__ ((packed));
  110. static inline __be32 cm_req_get_local_qpn(struct cm_req_msg *req_msg)
  111. {
  112. return cpu_to_be32(be32_to_cpu(req_msg->offset32) >> 8);
  113. }
  114. static inline void cm_req_set_local_qpn(struct cm_req_msg *req_msg, __be32 qpn)
  115. {
  116. req_msg->offset32 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  117. (be32_to_cpu(req_msg->offset32) &
  118. 0x000000FF));
  119. }
  120. static inline u8 cm_req_get_resp_res(struct cm_req_msg *req_msg)
  121. {
  122. return (u8) be32_to_cpu(req_msg->offset32);
  123. }
  124. static inline void cm_req_set_resp_res(struct cm_req_msg *req_msg, u8 resp_res)
  125. {
  126. req_msg->offset32 = cpu_to_be32(resp_res |
  127. (be32_to_cpu(req_msg->offset32) &
  128. 0xFFFFFF00));
  129. }
  130. static inline u8 cm_req_get_init_depth(struct cm_req_msg *req_msg)
  131. {
  132. return (u8) be32_to_cpu(req_msg->offset36);
  133. }
  134. static inline void cm_req_set_init_depth(struct cm_req_msg *req_msg,
  135. u8 init_depth)
  136. {
  137. req_msg->offset36 = cpu_to_be32(init_depth |
  138. (be32_to_cpu(req_msg->offset36) &
  139. 0xFFFFFF00));
  140. }
  141. static inline u8 cm_req_get_remote_resp_timeout(struct cm_req_msg *req_msg)
  142. {
  143. return (u8) ((be32_to_cpu(req_msg->offset40) & 0xF8) >> 3);
  144. }
  145. static inline void cm_req_set_remote_resp_timeout(struct cm_req_msg *req_msg,
  146. u8 resp_timeout)
  147. {
  148. req_msg->offset40 = cpu_to_be32((resp_timeout << 3) |
  149. (be32_to_cpu(req_msg->offset40) &
  150. 0xFFFFFF07));
  151. }
  152. static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
  153. {
  154. u8 transport_type = (u8) (be32_to_cpu(req_msg->offset40) & 0x06) >> 1;
  155. switch(transport_type) {
  156. case 0: return IB_QPT_RC;
  157. case 1: return IB_QPT_UC;
  158. case 3:
  159. switch (req_msg->offset51 & 0x7) {
  160. case 1: return IB_QPT_XRC_TGT;
  161. default: return 0;
  162. }
  163. default: return 0;
  164. }
  165. }
  166. static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
  167. enum ib_qp_type qp_type)
  168. {
  169. switch(qp_type) {
  170. case IB_QPT_UC:
  171. req_msg->offset40 = cpu_to_be32((be32_to_cpu(
  172. req_msg->offset40) &
  173. 0xFFFFFFF9) | 0x2);
  174. break;
  175. case IB_QPT_XRC_INI:
  176. req_msg->offset40 = cpu_to_be32((be32_to_cpu(
  177. req_msg->offset40) &
  178. 0xFFFFFFF9) | 0x6);
  179. req_msg->offset51 = (req_msg->offset51 & 0xF8) | 1;
  180. break;
  181. default:
  182. req_msg->offset40 = cpu_to_be32(be32_to_cpu(
  183. req_msg->offset40) &
  184. 0xFFFFFFF9);
  185. }
  186. }
  187. static inline u8 cm_req_get_flow_ctrl(struct cm_req_msg *req_msg)
  188. {
  189. return be32_to_cpu(req_msg->offset40) & 0x1;
  190. }
  191. static inline void cm_req_set_flow_ctrl(struct cm_req_msg *req_msg,
  192. u8 flow_ctrl)
  193. {
  194. req_msg->offset40 = cpu_to_be32((flow_ctrl & 0x1) |
  195. (be32_to_cpu(req_msg->offset40) &
  196. 0xFFFFFFFE));
  197. }
  198. static inline __be32 cm_req_get_starting_psn(struct cm_req_msg *req_msg)
  199. {
  200. return cpu_to_be32(be32_to_cpu(req_msg->offset44) >> 8);
  201. }
  202. static inline void cm_req_set_starting_psn(struct cm_req_msg *req_msg,
  203. __be32 starting_psn)
  204. {
  205. req_msg->offset44 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
  206. (be32_to_cpu(req_msg->offset44) & 0x000000FF));
  207. }
  208. static inline u8 cm_req_get_local_resp_timeout(struct cm_req_msg *req_msg)
  209. {
  210. return (u8) ((be32_to_cpu(req_msg->offset44) & 0xF8) >> 3);
  211. }
  212. static inline void cm_req_set_local_resp_timeout(struct cm_req_msg *req_msg,
  213. u8 resp_timeout)
  214. {
  215. req_msg->offset44 = cpu_to_be32((resp_timeout << 3) |
  216. (be32_to_cpu(req_msg->offset44) & 0xFFFFFF07));
  217. }
  218. static inline u8 cm_req_get_retry_count(struct cm_req_msg *req_msg)
  219. {
  220. return (u8) (be32_to_cpu(req_msg->offset44) & 0x7);
  221. }
  222. static inline void cm_req_set_retry_count(struct cm_req_msg *req_msg,
  223. u8 retry_count)
  224. {
  225. req_msg->offset44 = cpu_to_be32((retry_count & 0x7) |
  226. (be32_to_cpu(req_msg->offset44) & 0xFFFFFFF8));
  227. }
  228. static inline u8 cm_req_get_path_mtu(struct cm_req_msg *req_msg)
  229. {
  230. return req_msg->offset50 >> 4;
  231. }
  232. static inline void cm_req_set_path_mtu(struct cm_req_msg *req_msg, u8 path_mtu)
  233. {
  234. req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF) | (path_mtu << 4));
  235. }
  236. static inline u8 cm_req_get_rnr_retry_count(struct cm_req_msg *req_msg)
  237. {
  238. return req_msg->offset50 & 0x7;
  239. }
  240. static inline void cm_req_set_rnr_retry_count(struct cm_req_msg *req_msg,
  241. u8 rnr_retry_count)
  242. {
  243. req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF8) |
  244. (rnr_retry_count & 0x7));
  245. }
  246. static inline u8 cm_req_get_max_cm_retries(struct cm_req_msg *req_msg)
  247. {
  248. return req_msg->offset51 >> 4;
  249. }
  250. static inline void cm_req_set_max_cm_retries(struct cm_req_msg *req_msg,
  251. u8 retries)
  252. {
  253. req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF) | (retries << 4));
  254. }
  255. static inline u8 cm_req_get_srq(struct cm_req_msg *req_msg)
  256. {
  257. return (req_msg->offset51 & 0x8) >> 3;
  258. }
  259. static inline void cm_req_set_srq(struct cm_req_msg *req_msg, u8 srq)
  260. {
  261. req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF7) |
  262. ((srq & 0x1) << 3));
  263. }
  264. static inline __be32 cm_req_get_primary_flow_label(struct cm_req_msg *req_msg)
  265. {
  266. return cpu_to_be32(be32_to_cpu(req_msg->primary_offset88) >> 12);
  267. }
  268. static inline void cm_req_set_primary_flow_label(struct cm_req_msg *req_msg,
  269. __be32 flow_label)
  270. {
  271. req_msg->primary_offset88 = cpu_to_be32(
  272. (be32_to_cpu(req_msg->primary_offset88) &
  273. 0x00000FFF) |
  274. (be32_to_cpu(flow_label) << 12));
  275. }
  276. static inline u8 cm_req_get_primary_packet_rate(struct cm_req_msg *req_msg)
  277. {
  278. return (u8) (be32_to_cpu(req_msg->primary_offset88) & 0x3F);
  279. }
  280. static inline void cm_req_set_primary_packet_rate(struct cm_req_msg *req_msg,
  281. u8 rate)
  282. {
  283. req_msg->primary_offset88 = cpu_to_be32(
  284. (be32_to_cpu(req_msg->primary_offset88) &
  285. 0xFFFFFFC0) | (rate & 0x3F));
  286. }
  287. static inline u8 cm_req_get_primary_sl(struct cm_req_msg *req_msg)
  288. {
  289. return (u8) (req_msg->primary_offset94 >> 4);
  290. }
  291. static inline void cm_req_set_primary_sl(struct cm_req_msg *req_msg, u8 sl)
  292. {
  293. req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0x0F) |
  294. (sl << 4));
  295. }
  296. static inline u8 cm_req_get_primary_subnet_local(struct cm_req_msg *req_msg)
  297. {
  298. return (u8) ((req_msg->primary_offset94 & 0x08) >> 3);
  299. }
  300. static inline void cm_req_set_primary_subnet_local(struct cm_req_msg *req_msg,
  301. u8 subnet_local)
  302. {
  303. req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0xF7) |
  304. ((subnet_local & 0x1) << 3));
  305. }
  306. static inline u8 cm_req_get_primary_local_ack_timeout(struct cm_req_msg *req_msg)
  307. {
  308. return (u8) (req_msg->primary_offset95 >> 3);
  309. }
  310. static inline void cm_req_set_primary_local_ack_timeout(struct cm_req_msg *req_msg,
  311. u8 local_ack_timeout)
  312. {
  313. req_msg->primary_offset95 = (u8) ((req_msg->primary_offset95 & 0x07) |
  314. (local_ack_timeout << 3));
  315. }
  316. static inline __be32 cm_req_get_alt_flow_label(struct cm_req_msg *req_msg)
  317. {
  318. return cpu_to_be32(be32_to_cpu(req_msg->alt_offset132) >> 12);
  319. }
  320. static inline void cm_req_set_alt_flow_label(struct cm_req_msg *req_msg,
  321. __be32 flow_label)
  322. {
  323. req_msg->alt_offset132 = cpu_to_be32(
  324. (be32_to_cpu(req_msg->alt_offset132) &
  325. 0x00000FFF) |
  326. (be32_to_cpu(flow_label) << 12));
  327. }
  328. static inline u8 cm_req_get_alt_packet_rate(struct cm_req_msg *req_msg)
  329. {
  330. return (u8) (be32_to_cpu(req_msg->alt_offset132) & 0x3F);
  331. }
  332. static inline void cm_req_set_alt_packet_rate(struct cm_req_msg *req_msg,
  333. u8 rate)
  334. {
  335. req_msg->alt_offset132 = cpu_to_be32(
  336. (be32_to_cpu(req_msg->alt_offset132) &
  337. 0xFFFFFFC0) | (rate & 0x3F));
  338. }
  339. static inline u8 cm_req_get_alt_sl(struct cm_req_msg *req_msg)
  340. {
  341. return (u8) (req_msg->alt_offset138 >> 4);
  342. }
  343. static inline void cm_req_set_alt_sl(struct cm_req_msg *req_msg, u8 sl)
  344. {
  345. req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0x0F) |
  346. (sl << 4));
  347. }
  348. static inline u8 cm_req_get_alt_subnet_local(struct cm_req_msg *req_msg)
  349. {
  350. return (u8) ((req_msg->alt_offset138 & 0x08) >> 3);
  351. }
  352. static inline void cm_req_set_alt_subnet_local(struct cm_req_msg *req_msg,
  353. u8 subnet_local)
  354. {
  355. req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0xF7) |
  356. ((subnet_local & 0x1) << 3));
  357. }
  358. static inline u8 cm_req_get_alt_local_ack_timeout(struct cm_req_msg *req_msg)
  359. {
  360. return (u8) (req_msg->alt_offset139 >> 3);
  361. }
  362. static inline void cm_req_set_alt_local_ack_timeout(struct cm_req_msg *req_msg,
  363. u8 local_ack_timeout)
  364. {
  365. req_msg->alt_offset139 = (u8) ((req_msg->alt_offset139 & 0x07) |
  366. (local_ack_timeout << 3));
  367. }
  368. /* Message REJected or MRAed */
  369. enum cm_msg_response {
  370. CM_MSG_RESPONSE_REQ = 0x0,
  371. CM_MSG_RESPONSE_REP = 0x1,
  372. CM_MSG_RESPONSE_OTHER = 0x2
  373. };
  374. struct cm_mra_msg {
  375. struct ib_mad_hdr hdr;
  376. __be32 local_comm_id;
  377. __be32 remote_comm_id;
  378. /* message MRAed:2, rsvd:6 */
  379. u8 offset8;
  380. /* service timeout:5, rsvd:3 */
  381. u8 offset9;
  382. u8 private_data[IB_CM_MRA_PRIVATE_DATA_SIZE];
  383. } __attribute__ ((packed));
  384. static inline u8 cm_mra_get_msg_mraed(struct cm_mra_msg *mra_msg)
  385. {
  386. return (u8) (mra_msg->offset8 >> 6);
  387. }
  388. static inline void cm_mra_set_msg_mraed(struct cm_mra_msg *mra_msg, u8 msg)
  389. {
  390. mra_msg->offset8 = (u8) ((mra_msg->offset8 & 0x3F) | (msg << 6));
  391. }
  392. static inline u8 cm_mra_get_service_timeout(struct cm_mra_msg *mra_msg)
  393. {
  394. return (u8) (mra_msg->offset9 >> 3);
  395. }
  396. static inline void cm_mra_set_service_timeout(struct cm_mra_msg *mra_msg,
  397. u8 service_timeout)
  398. {
  399. mra_msg->offset9 = (u8) ((mra_msg->offset9 & 0x07) |
  400. (service_timeout << 3));
  401. }
  402. struct cm_rej_msg {
  403. struct ib_mad_hdr hdr;
  404. __be32 local_comm_id;
  405. __be32 remote_comm_id;
  406. /* message REJected:2, rsvd:6 */
  407. u8 offset8;
  408. /* reject info length:7, rsvd:1. */
  409. u8 offset9;
  410. __be16 reason;
  411. u8 ari[IB_CM_REJ_ARI_LENGTH];
  412. u8 private_data[IB_CM_REJ_PRIVATE_DATA_SIZE];
  413. } __attribute__ ((packed));
  414. static inline u8 cm_rej_get_msg_rejected(struct cm_rej_msg *rej_msg)
  415. {
  416. return (u8) (rej_msg->offset8 >> 6);
  417. }
  418. static inline void cm_rej_set_msg_rejected(struct cm_rej_msg *rej_msg, u8 msg)
  419. {
  420. rej_msg->offset8 = (u8) ((rej_msg->offset8 & 0x3F) | (msg << 6));
  421. }
  422. static inline u8 cm_rej_get_reject_info_len(struct cm_rej_msg *rej_msg)
  423. {
  424. return (u8) (rej_msg->offset9 >> 1);
  425. }
  426. static inline void cm_rej_set_reject_info_len(struct cm_rej_msg *rej_msg,
  427. u8 len)
  428. {
  429. rej_msg->offset9 = (u8) ((rej_msg->offset9 & 0x1) | (len << 1));
  430. }
  431. struct cm_rep_msg {
  432. struct ib_mad_hdr hdr;
  433. __be32 local_comm_id;
  434. __be32 remote_comm_id;
  435. __be32 local_qkey;
  436. /* local QPN:24, rsvd:8 */
  437. __be32 offset12;
  438. /* local EECN:24, rsvd:8 */
  439. __be32 offset16;
  440. /* starting PSN:24 rsvd:8 */
  441. __be32 offset20;
  442. u8 resp_resources;
  443. u8 initiator_depth;
  444. /* target ACK delay:5, failover accepted:2, end-to-end flow control:1 */
  445. u8 offset26;
  446. /* RNR retry count:3, SRQ:1, rsvd:5 */
  447. u8 offset27;
  448. __be64 local_ca_guid;
  449. u8 private_data[IB_CM_REP_PRIVATE_DATA_SIZE];
  450. } __attribute__ ((packed));
  451. static inline __be32 cm_rep_get_local_qpn(struct cm_rep_msg *rep_msg)
  452. {
  453. return cpu_to_be32(be32_to_cpu(rep_msg->offset12) >> 8);
  454. }
  455. static inline void cm_rep_set_local_qpn(struct cm_rep_msg *rep_msg, __be32 qpn)
  456. {
  457. rep_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  458. (be32_to_cpu(rep_msg->offset12) & 0x000000FF));
  459. }
  460. static inline __be32 cm_rep_get_local_eecn(struct cm_rep_msg *rep_msg)
  461. {
  462. return cpu_to_be32(be32_to_cpu(rep_msg->offset16) >> 8);
  463. }
  464. static inline void cm_rep_set_local_eecn(struct cm_rep_msg *rep_msg, __be32 eecn)
  465. {
  466. rep_msg->offset16 = cpu_to_be32((be32_to_cpu(eecn) << 8) |
  467. (be32_to_cpu(rep_msg->offset16) & 0x000000FF));
  468. }
  469. static inline __be32 cm_rep_get_qpn(struct cm_rep_msg *rep_msg, enum ib_qp_type qp_type)
  470. {
  471. return (qp_type == IB_QPT_XRC_INI) ?
  472. cm_rep_get_local_eecn(rep_msg) : cm_rep_get_local_qpn(rep_msg);
  473. }
  474. static inline __be32 cm_rep_get_starting_psn(struct cm_rep_msg *rep_msg)
  475. {
  476. return cpu_to_be32(be32_to_cpu(rep_msg->offset20) >> 8);
  477. }
  478. static inline void cm_rep_set_starting_psn(struct cm_rep_msg *rep_msg,
  479. __be32 starting_psn)
  480. {
  481. rep_msg->offset20 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
  482. (be32_to_cpu(rep_msg->offset20) & 0x000000FF));
  483. }
  484. static inline u8 cm_rep_get_target_ack_delay(struct cm_rep_msg *rep_msg)
  485. {
  486. return (u8) (rep_msg->offset26 >> 3);
  487. }
  488. static inline void cm_rep_set_target_ack_delay(struct cm_rep_msg *rep_msg,
  489. u8 target_ack_delay)
  490. {
  491. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0x07) |
  492. (target_ack_delay << 3));
  493. }
  494. static inline u8 cm_rep_get_failover(struct cm_rep_msg *rep_msg)
  495. {
  496. return (u8) ((rep_msg->offset26 & 0x06) >> 1);
  497. }
  498. static inline void cm_rep_set_failover(struct cm_rep_msg *rep_msg, u8 failover)
  499. {
  500. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xF9) |
  501. ((failover & 0x3) << 1));
  502. }
  503. static inline u8 cm_rep_get_flow_ctrl(struct cm_rep_msg *rep_msg)
  504. {
  505. return (u8) (rep_msg->offset26 & 0x01);
  506. }
  507. static inline void cm_rep_set_flow_ctrl(struct cm_rep_msg *rep_msg,
  508. u8 flow_ctrl)
  509. {
  510. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xFE) |
  511. (flow_ctrl & 0x1));
  512. }
  513. static inline u8 cm_rep_get_rnr_retry_count(struct cm_rep_msg *rep_msg)
  514. {
  515. return (u8) (rep_msg->offset27 >> 5);
  516. }
  517. static inline void cm_rep_set_rnr_retry_count(struct cm_rep_msg *rep_msg,
  518. u8 rnr_retry_count)
  519. {
  520. rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0x1F) |
  521. (rnr_retry_count << 5));
  522. }
  523. static inline u8 cm_rep_get_srq(struct cm_rep_msg *rep_msg)
  524. {
  525. return (u8) ((rep_msg->offset27 >> 4) & 0x1);
  526. }
  527. static inline void cm_rep_set_srq(struct cm_rep_msg *rep_msg, u8 srq)
  528. {
  529. rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0xEF) |
  530. ((srq & 0x1) << 4));
  531. }
  532. struct cm_rtu_msg {
  533. struct ib_mad_hdr hdr;
  534. __be32 local_comm_id;
  535. __be32 remote_comm_id;
  536. u8 private_data[IB_CM_RTU_PRIVATE_DATA_SIZE];
  537. } __attribute__ ((packed));
  538. struct cm_dreq_msg {
  539. struct ib_mad_hdr hdr;
  540. __be32 local_comm_id;
  541. __be32 remote_comm_id;
  542. /* remote QPN/EECN:24, rsvd:8 */
  543. __be32 offset8;
  544. u8 private_data[IB_CM_DREQ_PRIVATE_DATA_SIZE];
  545. } __attribute__ ((packed));
  546. static inline __be32 cm_dreq_get_remote_qpn(struct cm_dreq_msg *dreq_msg)
  547. {
  548. return cpu_to_be32(be32_to_cpu(dreq_msg->offset8) >> 8);
  549. }
  550. static inline void cm_dreq_set_remote_qpn(struct cm_dreq_msg *dreq_msg, __be32 qpn)
  551. {
  552. dreq_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  553. (be32_to_cpu(dreq_msg->offset8) & 0x000000FF));
  554. }
  555. struct cm_drep_msg {
  556. struct ib_mad_hdr hdr;
  557. __be32 local_comm_id;
  558. __be32 remote_comm_id;
  559. u8 private_data[IB_CM_DREP_PRIVATE_DATA_SIZE];
  560. } __attribute__ ((packed));
  561. struct cm_lap_msg {
  562. struct ib_mad_hdr hdr;
  563. __be32 local_comm_id;
  564. __be32 remote_comm_id;
  565. __be32 rsvd8;
  566. /* remote QPN/EECN:24, remote CM response timeout:5, rsvd:3 */
  567. __be32 offset12;
  568. __be32 rsvd16;
  569. __be16 alt_local_lid;
  570. __be16 alt_remote_lid;
  571. union ib_gid alt_local_gid;
  572. union ib_gid alt_remote_gid;
  573. /* flow label:20, rsvd:4, traffic class:8 */
  574. __be32 offset56;
  575. u8 alt_hop_limit;
  576. /* rsvd:2, packet rate:6 */
  577. u8 offset61;
  578. /* SL:4, subnet local:1, rsvd:3 */
  579. u8 offset62;
  580. /* local ACK timeout:5, rsvd:3 */
  581. u8 offset63;
  582. u8 private_data[IB_CM_LAP_PRIVATE_DATA_SIZE];
  583. } __attribute__ ((packed));
  584. static inline __be32 cm_lap_get_remote_qpn(struct cm_lap_msg *lap_msg)
  585. {
  586. return cpu_to_be32(be32_to_cpu(lap_msg->offset12) >> 8);
  587. }
  588. static inline void cm_lap_set_remote_qpn(struct cm_lap_msg *lap_msg, __be32 qpn)
  589. {
  590. lap_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  591. (be32_to_cpu(lap_msg->offset12) &
  592. 0x000000FF));
  593. }
  594. static inline u8 cm_lap_get_remote_resp_timeout(struct cm_lap_msg *lap_msg)
  595. {
  596. return (u8) ((be32_to_cpu(lap_msg->offset12) & 0xF8) >> 3);
  597. }
  598. static inline void cm_lap_set_remote_resp_timeout(struct cm_lap_msg *lap_msg,
  599. u8 resp_timeout)
  600. {
  601. lap_msg->offset12 = cpu_to_be32((resp_timeout << 3) |
  602. (be32_to_cpu(lap_msg->offset12) &
  603. 0xFFFFFF07));
  604. }
  605. static inline __be32 cm_lap_get_flow_label(struct cm_lap_msg *lap_msg)
  606. {
  607. return cpu_to_be32(be32_to_cpu(lap_msg->offset56) >> 12);
  608. }
  609. static inline void cm_lap_set_flow_label(struct cm_lap_msg *lap_msg,
  610. __be32 flow_label)
  611. {
  612. lap_msg->offset56 = cpu_to_be32(
  613. (be32_to_cpu(lap_msg->offset56) & 0x00000FFF) |
  614. (be32_to_cpu(flow_label) << 12));
  615. }
  616. static inline u8 cm_lap_get_traffic_class(struct cm_lap_msg *lap_msg)
  617. {
  618. return (u8) be32_to_cpu(lap_msg->offset56);
  619. }
  620. static inline void cm_lap_set_traffic_class(struct cm_lap_msg *lap_msg,
  621. u8 traffic_class)
  622. {
  623. lap_msg->offset56 = cpu_to_be32(traffic_class |
  624. (be32_to_cpu(lap_msg->offset56) &
  625. 0xFFFFFF00));
  626. }
  627. static inline u8 cm_lap_get_packet_rate(struct cm_lap_msg *lap_msg)
  628. {
  629. return lap_msg->offset61 & 0x3F;
  630. }
  631. static inline void cm_lap_set_packet_rate(struct cm_lap_msg *lap_msg,
  632. u8 packet_rate)
  633. {
  634. lap_msg->offset61 = (packet_rate & 0x3F) | (lap_msg->offset61 & 0xC0);
  635. }
  636. static inline u8 cm_lap_get_sl(struct cm_lap_msg *lap_msg)
  637. {
  638. return lap_msg->offset62 >> 4;
  639. }
  640. static inline void cm_lap_set_sl(struct cm_lap_msg *lap_msg, u8 sl)
  641. {
  642. lap_msg->offset62 = (sl << 4) | (lap_msg->offset62 & 0x0F);
  643. }
  644. static inline u8 cm_lap_get_subnet_local(struct cm_lap_msg *lap_msg)
  645. {
  646. return (lap_msg->offset62 >> 3) & 0x1;
  647. }
  648. static inline void cm_lap_set_subnet_local(struct cm_lap_msg *lap_msg,
  649. u8 subnet_local)
  650. {
  651. lap_msg->offset62 = ((subnet_local & 0x1) << 3) |
  652. (lap_msg->offset61 & 0xF7);
  653. }
  654. static inline u8 cm_lap_get_local_ack_timeout(struct cm_lap_msg *lap_msg)
  655. {
  656. return lap_msg->offset63 >> 3;
  657. }
  658. static inline void cm_lap_set_local_ack_timeout(struct cm_lap_msg *lap_msg,
  659. u8 local_ack_timeout)
  660. {
  661. lap_msg->offset63 = (local_ack_timeout << 3) |
  662. (lap_msg->offset63 & 0x07);
  663. }
  664. struct cm_apr_msg {
  665. struct ib_mad_hdr hdr;
  666. __be32 local_comm_id;
  667. __be32 remote_comm_id;
  668. u8 info_length;
  669. u8 ap_status;
  670. __be16 rsvd;
  671. u8 info[IB_CM_APR_INFO_LENGTH];
  672. u8 private_data[IB_CM_APR_PRIVATE_DATA_SIZE];
  673. } __attribute__ ((packed));
  674. struct cm_sidr_req_msg {
  675. struct ib_mad_hdr hdr;
  676. __be32 request_id;
  677. __be16 pkey;
  678. __be16 rsvd;
  679. __be64 service_id;
  680. u8 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE];
  681. } __attribute__ ((packed));
  682. struct cm_sidr_rep_msg {
  683. struct ib_mad_hdr hdr;
  684. __be32 request_id;
  685. u8 status;
  686. u8 info_length;
  687. __be16 rsvd;
  688. /* QPN:24, rsvd:8 */
  689. __be32 offset8;
  690. __be64 service_id;
  691. __be32 qkey;
  692. u8 info[IB_CM_SIDR_REP_INFO_LENGTH];
  693. u8 private_data[IB_CM_SIDR_REP_PRIVATE_DATA_SIZE];
  694. } __attribute__ ((packed));
  695. static inline __be32 cm_sidr_rep_get_qpn(struct cm_sidr_rep_msg *sidr_rep_msg)
  696. {
  697. return cpu_to_be32(be32_to_cpu(sidr_rep_msg->offset8) >> 8);
  698. }
  699. static inline void cm_sidr_rep_set_qpn(struct cm_sidr_rep_msg *sidr_rep_msg,
  700. __be32 qpn)
  701. {
  702. sidr_rep_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  703. (be32_to_cpu(sidr_rep_msg->offset8) &
  704. 0x000000FF));
  705. }
  706. #endif /* CM_MSGS_H */