cm_msgs.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. * Copyright (c) 2004 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, rsvd: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. default: return 0;
  159. }
  160. }
  161. static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
  162. enum ib_qp_type qp_type)
  163. {
  164. switch(qp_type) {
  165. case IB_QPT_UC:
  166. req_msg->offset40 = cpu_to_be32((be32_to_cpu(
  167. req_msg->offset40) &
  168. 0xFFFFFFF9) | 0x2);
  169. break;
  170. default:
  171. req_msg->offset40 = cpu_to_be32(be32_to_cpu(
  172. req_msg->offset40) &
  173. 0xFFFFFFF9);
  174. }
  175. }
  176. static inline u8 cm_req_get_flow_ctrl(struct cm_req_msg *req_msg)
  177. {
  178. return be32_to_cpu(req_msg->offset40) & 0x1;
  179. }
  180. static inline void cm_req_set_flow_ctrl(struct cm_req_msg *req_msg,
  181. u8 flow_ctrl)
  182. {
  183. req_msg->offset40 = cpu_to_be32((flow_ctrl & 0x1) |
  184. (be32_to_cpu(req_msg->offset40) &
  185. 0xFFFFFFFE));
  186. }
  187. static inline __be32 cm_req_get_starting_psn(struct cm_req_msg *req_msg)
  188. {
  189. return cpu_to_be32(be32_to_cpu(req_msg->offset44) >> 8);
  190. }
  191. static inline void cm_req_set_starting_psn(struct cm_req_msg *req_msg,
  192. __be32 starting_psn)
  193. {
  194. req_msg->offset44 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
  195. (be32_to_cpu(req_msg->offset44) & 0x000000FF));
  196. }
  197. static inline u8 cm_req_get_local_resp_timeout(struct cm_req_msg *req_msg)
  198. {
  199. return (u8) ((be32_to_cpu(req_msg->offset44) & 0xF8) >> 3);
  200. }
  201. static inline void cm_req_set_local_resp_timeout(struct cm_req_msg *req_msg,
  202. u8 resp_timeout)
  203. {
  204. req_msg->offset44 = cpu_to_be32((resp_timeout << 3) |
  205. (be32_to_cpu(req_msg->offset44) & 0xFFFFFF07));
  206. }
  207. static inline u8 cm_req_get_retry_count(struct cm_req_msg *req_msg)
  208. {
  209. return (u8) (be32_to_cpu(req_msg->offset44) & 0x7);
  210. }
  211. static inline void cm_req_set_retry_count(struct cm_req_msg *req_msg,
  212. u8 retry_count)
  213. {
  214. req_msg->offset44 = cpu_to_be32((retry_count & 0x7) |
  215. (be32_to_cpu(req_msg->offset44) & 0xFFFFFFF8));
  216. }
  217. static inline u8 cm_req_get_path_mtu(struct cm_req_msg *req_msg)
  218. {
  219. return req_msg->offset50 >> 4;
  220. }
  221. static inline void cm_req_set_path_mtu(struct cm_req_msg *req_msg, u8 path_mtu)
  222. {
  223. req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF) | (path_mtu << 4));
  224. }
  225. static inline u8 cm_req_get_rnr_retry_count(struct cm_req_msg *req_msg)
  226. {
  227. return req_msg->offset50 & 0x7;
  228. }
  229. static inline void cm_req_set_rnr_retry_count(struct cm_req_msg *req_msg,
  230. u8 rnr_retry_count)
  231. {
  232. req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF8) |
  233. (rnr_retry_count & 0x7));
  234. }
  235. static inline u8 cm_req_get_max_cm_retries(struct cm_req_msg *req_msg)
  236. {
  237. return req_msg->offset51 >> 4;
  238. }
  239. static inline void cm_req_set_max_cm_retries(struct cm_req_msg *req_msg,
  240. u8 retries)
  241. {
  242. req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF) | (retries << 4));
  243. }
  244. static inline u8 cm_req_get_srq(struct cm_req_msg *req_msg)
  245. {
  246. return (req_msg->offset51 & 0x8) >> 3;
  247. }
  248. static inline void cm_req_set_srq(struct cm_req_msg *req_msg, u8 srq)
  249. {
  250. req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF7) |
  251. ((srq & 0x1) << 3));
  252. }
  253. static inline __be32 cm_req_get_primary_flow_label(struct cm_req_msg *req_msg)
  254. {
  255. return cpu_to_be32(be32_to_cpu(req_msg->primary_offset88) >> 12);
  256. }
  257. static inline void cm_req_set_primary_flow_label(struct cm_req_msg *req_msg,
  258. __be32 flow_label)
  259. {
  260. req_msg->primary_offset88 = cpu_to_be32(
  261. (be32_to_cpu(req_msg->primary_offset88) &
  262. 0x00000FFF) |
  263. (be32_to_cpu(flow_label) << 12));
  264. }
  265. static inline u8 cm_req_get_primary_packet_rate(struct cm_req_msg *req_msg)
  266. {
  267. return (u8) (be32_to_cpu(req_msg->primary_offset88) & 0x3F);
  268. }
  269. static inline void cm_req_set_primary_packet_rate(struct cm_req_msg *req_msg,
  270. u8 rate)
  271. {
  272. req_msg->primary_offset88 = cpu_to_be32(
  273. (be32_to_cpu(req_msg->primary_offset88) &
  274. 0xFFFFFFC0) | (rate & 0x3F));
  275. }
  276. static inline u8 cm_req_get_primary_sl(struct cm_req_msg *req_msg)
  277. {
  278. return (u8) (req_msg->primary_offset94 >> 4);
  279. }
  280. static inline void cm_req_set_primary_sl(struct cm_req_msg *req_msg, u8 sl)
  281. {
  282. req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0x0F) |
  283. (sl << 4));
  284. }
  285. static inline u8 cm_req_get_primary_subnet_local(struct cm_req_msg *req_msg)
  286. {
  287. return (u8) ((req_msg->primary_offset94 & 0x08) >> 3);
  288. }
  289. static inline void cm_req_set_primary_subnet_local(struct cm_req_msg *req_msg,
  290. u8 subnet_local)
  291. {
  292. req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0xF7) |
  293. ((subnet_local & 0x1) << 3));
  294. }
  295. static inline u8 cm_req_get_primary_local_ack_timeout(struct cm_req_msg *req_msg)
  296. {
  297. return (u8) (req_msg->primary_offset95 >> 3);
  298. }
  299. static inline void cm_req_set_primary_local_ack_timeout(struct cm_req_msg *req_msg,
  300. u8 local_ack_timeout)
  301. {
  302. req_msg->primary_offset95 = (u8) ((req_msg->primary_offset95 & 0x07) |
  303. (local_ack_timeout << 3));
  304. }
  305. static inline __be32 cm_req_get_alt_flow_label(struct cm_req_msg *req_msg)
  306. {
  307. return cpu_to_be32(be32_to_cpu(req_msg->alt_offset132) >> 12);
  308. }
  309. static inline void cm_req_set_alt_flow_label(struct cm_req_msg *req_msg,
  310. __be32 flow_label)
  311. {
  312. req_msg->alt_offset132 = cpu_to_be32(
  313. (be32_to_cpu(req_msg->alt_offset132) &
  314. 0x00000FFF) |
  315. (be32_to_cpu(flow_label) << 12));
  316. }
  317. static inline u8 cm_req_get_alt_packet_rate(struct cm_req_msg *req_msg)
  318. {
  319. return (u8) (be32_to_cpu(req_msg->alt_offset132) & 0x3F);
  320. }
  321. static inline void cm_req_set_alt_packet_rate(struct cm_req_msg *req_msg,
  322. u8 rate)
  323. {
  324. req_msg->alt_offset132 = cpu_to_be32(
  325. (be32_to_cpu(req_msg->alt_offset132) &
  326. 0xFFFFFFC0) | (rate & 0x3F));
  327. }
  328. static inline u8 cm_req_get_alt_sl(struct cm_req_msg *req_msg)
  329. {
  330. return (u8) (req_msg->alt_offset138 >> 4);
  331. }
  332. static inline void cm_req_set_alt_sl(struct cm_req_msg *req_msg, u8 sl)
  333. {
  334. req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0x0F) |
  335. (sl << 4));
  336. }
  337. static inline u8 cm_req_get_alt_subnet_local(struct cm_req_msg *req_msg)
  338. {
  339. return (u8) ((req_msg->alt_offset138 & 0x08) >> 3);
  340. }
  341. static inline void cm_req_set_alt_subnet_local(struct cm_req_msg *req_msg,
  342. u8 subnet_local)
  343. {
  344. req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0xF7) |
  345. ((subnet_local & 0x1) << 3));
  346. }
  347. static inline u8 cm_req_get_alt_local_ack_timeout(struct cm_req_msg *req_msg)
  348. {
  349. return (u8) (req_msg->alt_offset139 >> 3);
  350. }
  351. static inline void cm_req_set_alt_local_ack_timeout(struct cm_req_msg *req_msg,
  352. u8 local_ack_timeout)
  353. {
  354. req_msg->alt_offset139 = (u8) ((req_msg->alt_offset139 & 0x07) |
  355. (local_ack_timeout << 3));
  356. }
  357. /* Message REJected or MRAed */
  358. enum cm_msg_response {
  359. CM_MSG_RESPONSE_REQ = 0x0,
  360. CM_MSG_RESPONSE_REP = 0x1,
  361. CM_MSG_RESPONSE_OTHER = 0x2
  362. };
  363. struct cm_mra_msg {
  364. struct ib_mad_hdr hdr;
  365. __be32 local_comm_id;
  366. __be32 remote_comm_id;
  367. /* message MRAed:2, rsvd:6 */
  368. u8 offset8;
  369. /* service timeout:5, rsvd:3 */
  370. u8 offset9;
  371. u8 private_data[IB_CM_MRA_PRIVATE_DATA_SIZE];
  372. } __attribute__ ((packed));
  373. static inline u8 cm_mra_get_msg_mraed(struct cm_mra_msg *mra_msg)
  374. {
  375. return (u8) (mra_msg->offset8 >> 6);
  376. }
  377. static inline void cm_mra_set_msg_mraed(struct cm_mra_msg *mra_msg, u8 msg)
  378. {
  379. mra_msg->offset8 = (u8) ((mra_msg->offset8 & 0x3F) | (msg << 6));
  380. }
  381. static inline u8 cm_mra_get_service_timeout(struct cm_mra_msg *mra_msg)
  382. {
  383. return (u8) (mra_msg->offset9 >> 3);
  384. }
  385. static inline void cm_mra_set_service_timeout(struct cm_mra_msg *mra_msg,
  386. u8 service_timeout)
  387. {
  388. mra_msg->offset9 = (u8) ((mra_msg->offset9 & 0x07) |
  389. (service_timeout << 3));
  390. }
  391. struct cm_rej_msg {
  392. struct ib_mad_hdr hdr;
  393. __be32 local_comm_id;
  394. __be32 remote_comm_id;
  395. /* message REJected:2, rsvd:6 */
  396. u8 offset8;
  397. /* reject info length:7, rsvd:1. */
  398. u8 offset9;
  399. __be16 reason;
  400. u8 ari[IB_CM_REJ_ARI_LENGTH];
  401. u8 private_data[IB_CM_REJ_PRIVATE_DATA_SIZE];
  402. } __attribute__ ((packed));
  403. static inline u8 cm_rej_get_msg_rejected(struct cm_rej_msg *rej_msg)
  404. {
  405. return (u8) (rej_msg->offset8 >> 6);
  406. }
  407. static inline void cm_rej_set_msg_rejected(struct cm_rej_msg *rej_msg, u8 msg)
  408. {
  409. rej_msg->offset8 = (u8) ((rej_msg->offset8 & 0x3F) | (msg << 6));
  410. }
  411. static inline u8 cm_rej_get_reject_info_len(struct cm_rej_msg *rej_msg)
  412. {
  413. return (u8) (rej_msg->offset9 >> 1);
  414. }
  415. static inline void cm_rej_set_reject_info_len(struct cm_rej_msg *rej_msg,
  416. u8 len)
  417. {
  418. rej_msg->offset9 = (u8) ((rej_msg->offset9 & 0x1) | (len << 1));
  419. }
  420. struct cm_rep_msg {
  421. struct ib_mad_hdr hdr;
  422. __be32 local_comm_id;
  423. __be32 remote_comm_id;
  424. __be32 local_qkey;
  425. /* local QPN:24, rsvd:8 */
  426. __be32 offset12;
  427. /* local EECN:24, rsvd:8 */
  428. __be32 offset16;
  429. /* starting PSN:24 rsvd:8 */
  430. __be32 offset20;
  431. u8 resp_resources;
  432. u8 initiator_depth;
  433. /* target ACK delay:5, failover accepted:2, end-to-end flow control:1 */
  434. u8 offset26;
  435. /* RNR retry count:3, SRQ:1, rsvd:5 */
  436. u8 offset27;
  437. __be64 local_ca_guid;
  438. u8 private_data[IB_CM_REP_PRIVATE_DATA_SIZE];
  439. } __attribute__ ((packed));
  440. static inline __be32 cm_rep_get_local_qpn(struct cm_rep_msg *rep_msg)
  441. {
  442. return cpu_to_be32(be32_to_cpu(rep_msg->offset12) >> 8);
  443. }
  444. static inline void cm_rep_set_local_qpn(struct cm_rep_msg *rep_msg, __be32 qpn)
  445. {
  446. rep_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  447. (be32_to_cpu(rep_msg->offset12) & 0x000000FF));
  448. }
  449. static inline __be32 cm_rep_get_starting_psn(struct cm_rep_msg *rep_msg)
  450. {
  451. return cpu_to_be32(be32_to_cpu(rep_msg->offset20) >> 8);
  452. }
  453. static inline void cm_rep_set_starting_psn(struct cm_rep_msg *rep_msg,
  454. __be32 starting_psn)
  455. {
  456. rep_msg->offset20 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
  457. (be32_to_cpu(rep_msg->offset20) & 0x000000FF));
  458. }
  459. static inline u8 cm_rep_get_target_ack_delay(struct cm_rep_msg *rep_msg)
  460. {
  461. return (u8) (rep_msg->offset26 >> 3);
  462. }
  463. static inline void cm_rep_set_target_ack_delay(struct cm_rep_msg *rep_msg,
  464. u8 target_ack_delay)
  465. {
  466. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0x07) |
  467. (target_ack_delay << 3));
  468. }
  469. static inline u8 cm_rep_get_failover(struct cm_rep_msg *rep_msg)
  470. {
  471. return (u8) ((rep_msg->offset26 & 0x06) >> 1);
  472. }
  473. static inline void cm_rep_set_failover(struct cm_rep_msg *rep_msg, u8 failover)
  474. {
  475. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xF9) |
  476. ((failover & 0x3) << 1));
  477. }
  478. static inline u8 cm_rep_get_flow_ctrl(struct cm_rep_msg *rep_msg)
  479. {
  480. return (u8) (rep_msg->offset26 & 0x01);
  481. }
  482. static inline void cm_rep_set_flow_ctrl(struct cm_rep_msg *rep_msg,
  483. u8 flow_ctrl)
  484. {
  485. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xFE) |
  486. (flow_ctrl & 0x1));
  487. }
  488. static inline u8 cm_rep_get_rnr_retry_count(struct cm_rep_msg *rep_msg)
  489. {
  490. return (u8) (rep_msg->offset27 >> 5);
  491. }
  492. static inline void cm_rep_set_rnr_retry_count(struct cm_rep_msg *rep_msg,
  493. u8 rnr_retry_count)
  494. {
  495. rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0x1F) |
  496. (rnr_retry_count << 5));
  497. }
  498. static inline u8 cm_rep_get_srq(struct cm_rep_msg *rep_msg)
  499. {
  500. return (u8) ((rep_msg->offset27 >> 4) & 0x1);
  501. }
  502. static inline void cm_rep_set_srq(struct cm_rep_msg *rep_msg, u8 srq)
  503. {
  504. rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0xEF) |
  505. ((srq & 0x1) << 4));
  506. }
  507. struct cm_rtu_msg {
  508. struct ib_mad_hdr hdr;
  509. __be32 local_comm_id;
  510. __be32 remote_comm_id;
  511. u8 private_data[IB_CM_RTU_PRIVATE_DATA_SIZE];
  512. } __attribute__ ((packed));
  513. struct cm_dreq_msg {
  514. struct ib_mad_hdr hdr;
  515. __be32 local_comm_id;
  516. __be32 remote_comm_id;
  517. /* remote QPN/EECN:24, rsvd:8 */
  518. __be32 offset8;
  519. u8 private_data[IB_CM_DREQ_PRIVATE_DATA_SIZE];
  520. } __attribute__ ((packed));
  521. static inline __be32 cm_dreq_get_remote_qpn(struct cm_dreq_msg *dreq_msg)
  522. {
  523. return cpu_to_be32(be32_to_cpu(dreq_msg->offset8) >> 8);
  524. }
  525. static inline void cm_dreq_set_remote_qpn(struct cm_dreq_msg *dreq_msg, __be32 qpn)
  526. {
  527. dreq_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  528. (be32_to_cpu(dreq_msg->offset8) & 0x000000FF));
  529. }
  530. struct cm_drep_msg {
  531. struct ib_mad_hdr hdr;
  532. __be32 local_comm_id;
  533. __be32 remote_comm_id;
  534. u8 private_data[IB_CM_DREP_PRIVATE_DATA_SIZE];
  535. } __attribute__ ((packed));
  536. struct cm_lap_msg {
  537. struct ib_mad_hdr hdr;
  538. __be32 local_comm_id;
  539. __be32 remote_comm_id;
  540. __be32 rsvd8;
  541. /* remote QPN/EECN:24, remote CM response timeout:5, rsvd:3 */
  542. __be32 offset12;
  543. __be32 rsvd16;
  544. __be16 alt_local_lid;
  545. __be16 alt_remote_lid;
  546. union ib_gid alt_local_gid;
  547. union ib_gid alt_remote_gid;
  548. /* flow label:20, rsvd:4, traffic class:8 */
  549. __be32 offset56;
  550. u8 alt_hop_limit;
  551. /* rsvd:2, packet rate:6 */
  552. u8 offset61;
  553. /* SL:4, subnet local:1, rsvd:3 */
  554. u8 offset62;
  555. /* local ACK timeout:5, rsvd:3 */
  556. u8 offset63;
  557. u8 private_data[IB_CM_LAP_PRIVATE_DATA_SIZE];
  558. } __attribute__ ((packed));
  559. static inline __be32 cm_lap_get_remote_qpn(struct cm_lap_msg *lap_msg)
  560. {
  561. return cpu_to_be32(be32_to_cpu(lap_msg->offset12) >> 8);
  562. }
  563. static inline void cm_lap_set_remote_qpn(struct cm_lap_msg *lap_msg, __be32 qpn)
  564. {
  565. lap_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  566. (be32_to_cpu(lap_msg->offset12) &
  567. 0x000000FF));
  568. }
  569. static inline u8 cm_lap_get_remote_resp_timeout(struct cm_lap_msg *lap_msg)
  570. {
  571. return (u8) ((be32_to_cpu(lap_msg->offset12) & 0xF8) >> 3);
  572. }
  573. static inline void cm_lap_set_remote_resp_timeout(struct cm_lap_msg *lap_msg,
  574. u8 resp_timeout)
  575. {
  576. lap_msg->offset12 = cpu_to_be32((resp_timeout << 3) |
  577. (be32_to_cpu(lap_msg->offset12) &
  578. 0xFFFFFF07));
  579. }
  580. static inline __be32 cm_lap_get_flow_label(struct cm_lap_msg *lap_msg)
  581. {
  582. return cpu_to_be32(be32_to_cpu(lap_msg->offset56) >> 12);
  583. }
  584. static inline void cm_lap_set_flow_label(struct cm_lap_msg *lap_msg,
  585. __be32 flow_label)
  586. {
  587. lap_msg->offset56 = cpu_to_be32(
  588. (be32_to_cpu(lap_msg->offset56) & 0x00000FFF) |
  589. (be32_to_cpu(flow_label) << 12));
  590. }
  591. static inline u8 cm_lap_get_traffic_class(struct cm_lap_msg *lap_msg)
  592. {
  593. return (u8) be32_to_cpu(lap_msg->offset56);
  594. }
  595. static inline void cm_lap_set_traffic_class(struct cm_lap_msg *lap_msg,
  596. u8 traffic_class)
  597. {
  598. lap_msg->offset56 = cpu_to_be32(traffic_class |
  599. (be32_to_cpu(lap_msg->offset56) &
  600. 0xFFFFFF00));
  601. }
  602. static inline u8 cm_lap_get_packet_rate(struct cm_lap_msg *lap_msg)
  603. {
  604. return lap_msg->offset61 & 0x3F;
  605. }
  606. static inline void cm_lap_set_packet_rate(struct cm_lap_msg *lap_msg,
  607. u8 packet_rate)
  608. {
  609. lap_msg->offset61 = (packet_rate & 0x3F) | (lap_msg->offset61 & 0xC0);
  610. }
  611. static inline u8 cm_lap_get_sl(struct cm_lap_msg *lap_msg)
  612. {
  613. return lap_msg->offset62 >> 4;
  614. }
  615. static inline void cm_lap_set_sl(struct cm_lap_msg *lap_msg, u8 sl)
  616. {
  617. lap_msg->offset62 = (sl << 4) | (lap_msg->offset62 & 0x0F);
  618. }
  619. static inline u8 cm_lap_get_subnet_local(struct cm_lap_msg *lap_msg)
  620. {
  621. return (lap_msg->offset62 >> 3) & 0x1;
  622. }
  623. static inline void cm_lap_set_subnet_local(struct cm_lap_msg *lap_msg,
  624. u8 subnet_local)
  625. {
  626. lap_msg->offset62 = ((subnet_local & 0x1) << 3) |
  627. (lap_msg->offset61 & 0xF7);
  628. }
  629. static inline u8 cm_lap_get_local_ack_timeout(struct cm_lap_msg *lap_msg)
  630. {
  631. return lap_msg->offset63 >> 3;
  632. }
  633. static inline void cm_lap_set_local_ack_timeout(struct cm_lap_msg *lap_msg,
  634. u8 local_ack_timeout)
  635. {
  636. lap_msg->offset63 = (local_ack_timeout << 3) |
  637. (lap_msg->offset63 & 0x07);
  638. }
  639. struct cm_apr_msg {
  640. struct ib_mad_hdr hdr;
  641. __be32 local_comm_id;
  642. __be32 remote_comm_id;
  643. u8 info_length;
  644. u8 ap_status;
  645. u8 info[IB_CM_APR_INFO_LENGTH];
  646. u8 private_data[IB_CM_APR_PRIVATE_DATA_SIZE];
  647. } __attribute__ ((packed));
  648. struct cm_sidr_req_msg {
  649. struct ib_mad_hdr hdr;
  650. __be32 request_id;
  651. __be16 pkey;
  652. __be16 rsvd;
  653. __be64 service_id;
  654. u8 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE];
  655. } __attribute__ ((packed));
  656. struct cm_sidr_rep_msg {
  657. struct ib_mad_hdr hdr;
  658. __be32 request_id;
  659. u8 status;
  660. u8 info_length;
  661. __be16 rsvd;
  662. /* QPN:24, rsvd:8 */
  663. __be32 offset8;
  664. __be64 service_id;
  665. __be32 qkey;
  666. u8 info[IB_CM_SIDR_REP_INFO_LENGTH];
  667. u8 private_data[IB_CM_SIDR_REP_PRIVATE_DATA_SIZE];
  668. } __attribute__ ((packed));
  669. static inline __be32 cm_sidr_rep_get_qpn(struct cm_sidr_rep_msg *sidr_rep_msg)
  670. {
  671. return cpu_to_be32(be32_to_cpu(sidr_rep_msg->offset8) >> 8);
  672. }
  673. static inline void cm_sidr_rep_set_qpn(struct cm_sidr_rep_msg *sidr_rep_msg,
  674. __be32 qpn)
  675. {
  676. sidr_rep_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  677. (be32_to_cpu(sidr_rep_msg->offset8) &
  678. 0x000000FF));
  679. }
  680. #endif /* CM_MSGS_H */