cm_msgs.h 21 KB

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