cm_msgs.h 21 KB

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