cm_msgs.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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. enum cm_msg_sequence {
  44. CM_MSG_SEQUENCE_REQ,
  45. CM_MSG_SEQUENCE_LAP,
  46. CM_MSG_SEQUENCE_DREQ,
  47. CM_MSG_SEQUENCE_SIDR
  48. };
  49. struct cm_req_msg {
  50. struct ib_mad_hdr hdr;
  51. __be32 local_comm_id;
  52. __be32 rsvd4;
  53. __be64 service_id;
  54. __be64 local_ca_guid;
  55. __be32 rsvd24;
  56. __be32 local_qkey;
  57. /* local QPN:24, responder resources:8 */
  58. __be32 offset32;
  59. /* local EECN:24, initiator depth:8 */
  60. __be32 offset36;
  61. /*
  62. * remote EECN:24, remote CM response timeout:5,
  63. * transport service type:2, end-to-end flow control:1
  64. */
  65. __be32 offset40;
  66. /* starting PSN:24, local CM response timeout:5, retry count:3 */
  67. __be32 offset44;
  68. __be16 pkey;
  69. /* path MTU:4, RDC exists:1, RNR retry count:3. */
  70. u8 offset50;
  71. /* max CM Retries:4, SRQ:1, extended transport type:3 */
  72. u8 offset51;
  73. __be16 primary_local_lid;
  74. __be16 primary_remote_lid;
  75. union ib_gid primary_local_gid;
  76. union ib_gid primary_remote_gid;
  77. /* flow label:20, rsvd:6, packet rate:6 */
  78. __be32 primary_offset88;
  79. u8 primary_traffic_class;
  80. u8 primary_hop_limit;
  81. /* SL:4, subnet local:1, rsvd:3 */
  82. u8 primary_offset94;
  83. /* local ACK timeout:5, rsvd:3 */
  84. u8 primary_offset95;
  85. __be16 alt_local_lid;
  86. __be16 alt_remote_lid;
  87. union ib_gid alt_local_gid;
  88. union ib_gid alt_remote_gid;
  89. /* flow label:20, rsvd:6, packet rate:6 */
  90. __be32 alt_offset132;
  91. u8 alt_traffic_class;
  92. u8 alt_hop_limit;
  93. /* SL:4, subnet local:1, rsvd:3 */
  94. u8 alt_offset138;
  95. /* local ACK timeout:5, rsvd:3 */
  96. u8 alt_offset139;
  97. u32 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE / sizeof(u32)];
  98. } __attribute__ ((packed));
  99. static inline __be32 cm_req_get_local_qpn(struct cm_req_msg *req_msg)
  100. {
  101. return cpu_to_be32(be32_to_cpu(req_msg->offset32) >> 8);
  102. }
  103. static inline void cm_req_set_local_qpn(struct cm_req_msg *req_msg, __be32 qpn)
  104. {
  105. req_msg->offset32 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  106. (be32_to_cpu(req_msg->offset32) &
  107. 0x000000FF));
  108. }
  109. static inline u8 cm_req_get_resp_res(struct cm_req_msg *req_msg)
  110. {
  111. return (u8) be32_to_cpu(req_msg->offset32);
  112. }
  113. static inline void cm_req_set_resp_res(struct cm_req_msg *req_msg, u8 resp_res)
  114. {
  115. req_msg->offset32 = cpu_to_be32(resp_res |
  116. (be32_to_cpu(req_msg->offset32) &
  117. 0xFFFFFF00));
  118. }
  119. static inline u8 cm_req_get_init_depth(struct cm_req_msg *req_msg)
  120. {
  121. return (u8) be32_to_cpu(req_msg->offset36);
  122. }
  123. static inline void cm_req_set_init_depth(struct cm_req_msg *req_msg,
  124. u8 init_depth)
  125. {
  126. req_msg->offset36 = cpu_to_be32(init_depth |
  127. (be32_to_cpu(req_msg->offset36) &
  128. 0xFFFFFF00));
  129. }
  130. static inline u8 cm_req_get_remote_resp_timeout(struct cm_req_msg *req_msg)
  131. {
  132. return (u8) ((be32_to_cpu(req_msg->offset40) & 0xF8) >> 3);
  133. }
  134. static inline void cm_req_set_remote_resp_timeout(struct cm_req_msg *req_msg,
  135. u8 resp_timeout)
  136. {
  137. req_msg->offset40 = cpu_to_be32((resp_timeout << 3) |
  138. (be32_to_cpu(req_msg->offset40) &
  139. 0xFFFFFF07));
  140. }
  141. static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
  142. {
  143. u8 transport_type = (u8) (be32_to_cpu(req_msg->offset40) & 0x06) >> 1;
  144. switch(transport_type) {
  145. case 0: return IB_QPT_RC;
  146. case 1: return IB_QPT_UC;
  147. case 3:
  148. switch (req_msg->offset51 & 0x7) {
  149. case 1: return IB_QPT_XRC_TGT;
  150. default: return 0;
  151. }
  152. default: return 0;
  153. }
  154. }
  155. static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
  156. enum ib_qp_type qp_type)
  157. {
  158. switch(qp_type) {
  159. case IB_QPT_UC:
  160. req_msg->offset40 = cpu_to_be32((be32_to_cpu(
  161. req_msg->offset40) &
  162. 0xFFFFFFF9) | 0x2);
  163. break;
  164. case IB_QPT_XRC_INI:
  165. req_msg->offset40 = cpu_to_be32((be32_to_cpu(
  166. req_msg->offset40) &
  167. 0xFFFFFFF9) | 0x6);
  168. req_msg->offset51 = (req_msg->offset51 & 0xF8) | 1;
  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_local_eecn(struct cm_rep_msg *rep_msg)
  450. {
  451. return cpu_to_be32(be32_to_cpu(rep_msg->offset16) >> 8);
  452. }
  453. static inline void cm_rep_set_local_eecn(struct cm_rep_msg *rep_msg, __be32 eecn)
  454. {
  455. rep_msg->offset16 = cpu_to_be32((be32_to_cpu(eecn) << 8) |
  456. (be32_to_cpu(rep_msg->offset16) & 0x000000FF));
  457. }
  458. static inline __be32 cm_rep_get_qpn(struct cm_rep_msg *rep_msg, enum ib_qp_type qp_type)
  459. {
  460. return (qp_type == IB_QPT_XRC_INI) ?
  461. cm_rep_get_local_eecn(rep_msg) : cm_rep_get_local_qpn(rep_msg);
  462. }
  463. static inline __be32 cm_rep_get_starting_psn(struct cm_rep_msg *rep_msg)
  464. {
  465. return cpu_to_be32(be32_to_cpu(rep_msg->offset20) >> 8);
  466. }
  467. static inline void cm_rep_set_starting_psn(struct cm_rep_msg *rep_msg,
  468. __be32 starting_psn)
  469. {
  470. rep_msg->offset20 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
  471. (be32_to_cpu(rep_msg->offset20) & 0x000000FF));
  472. }
  473. static inline u8 cm_rep_get_target_ack_delay(struct cm_rep_msg *rep_msg)
  474. {
  475. return (u8) (rep_msg->offset26 >> 3);
  476. }
  477. static inline void cm_rep_set_target_ack_delay(struct cm_rep_msg *rep_msg,
  478. u8 target_ack_delay)
  479. {
  480. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0x07) |
  481. (target_ack_delay << 3));
  482. }
  483. static inline u8 cm_rep_get_failover(struct cm_rep_msg *rep_msg)
  484. {
  485. return (u8) ((rep_msg->offset26 & 0x06) >> 1);
  486. }
  487. static inline void cm_rep_set_failover(struct cm_rep_msg *rep_msg, u8 failover)
  488. {
  489. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xF9) |
  490. ((failover & 0x3) << 1));
  491. }
  492. static inline u8 cm_rep_get_flow_ctrl(struct cm_rep_msg *rep_msg)
  493. {
  494. return (u8) (rep_msg->offset26 & 0x01);
  495. }
  496. static inline void cm_rep_set_flow_ctrl(struct cm_rep_msg *rep_msg,
  497. u8 flow_ctrl)
  498. {
  499. rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xFE) |
  500. (flow_ctrl & 0x1));
  501. }
  502. static inline u8 cm_rep_get_rnr_retry_count(struct cm_rep_msg *rep_msg)
  503. {
  504. return (u8) (rep_msg->offset27 >> 5);
  505. }
  506. static inline void cm_rep_set_rnr_retry_count(struct cm_rep_msg *rep_msg,
  507. u8 rnr_retry_count)
  508. {
  509. rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0x1F) |
  510. (rnr_retry_count << 5));
  511. }
  512. static inline u8 cm_rep_get_srq(struct cm_rep_msg *rep_msg)
  513. {
  514. return (u8) ((rep_msg->offset27 >> 4) & 0x1);
  515. }
  516. static inline void cm_rep_set_srq(struct cm_rep_msg *rep_msg, u8 srq)
  517. {
  518. rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0xEF) |
  519. ((srq & 0x1) << 4));
  520. }
  521. struct cm_rtu_msg {
  522. struct ib_mad_hdr hdr;
  523. __be32 local_comm_id;
  524. __be32 remote_comm_id;
  525. u8 private_data[IB_CM_RTU_PRIVATE_DATA_SIZE];
  526. } __attribute__ ((packed));
  527. struct cm_dreq_msg {
  528. struct ib_mad_hdr hdr;
  529. __be32 local_comm_id;
  530. __be32 remote_comm_id;
  531. /* remote QPN/EECN:24, rsvd:8 */
  532. __be32 offset8;
  533. u8 private_data[IB_CM_DREQ_PRIVATE_DATA_SIZE];
  534. } __attribute__ ((packed));
  535. static inline __be32 cm_dreq_get_remote_qpn(struct cm_dreq_msg *dreq_msg)
  536. {
  537. return cpu_to_be32(be32_to_cpu(dreq_msg->offset8) >> 8);
  538. }
  539. static inline void cm_dreq_set_remote_qpn(struct cm_dreq_msg *dreq_msg, __be32 qpn)
  540. {
  541. dreq_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  542. (be32_to_cpu(dreq_msg->offset8) & 0x000000FF));
  543. }
  544. struct cm_drep_msg {
  545. struct ib_mad_hdr hdr;
  546. __be32 local_comm_id;
  547. __be32 remote_comm_id;
  548. u8 private_data[IB_CM_DREP_PRIVATE_DATA_SIZE];
  549. } __attribute__ ((packed));
  550. struct cm_lap_msg {
  551. struct ib_mad_hdr hdr;
  552. __be32 local_comm_id;
  553. __be32 remote_comm_id;
  554. __be32 rsvd8;
  555. /* remote QPN/EECN:24, remote CM response timeout:5, rsvd:3 */
  556. __be32 offset12;
  557. __be32 rsvd16;
  558. __be16 alt_local_lid;
  559. __be16 alt_remote_lid;
  560. union ib_gid alt_local_gid;
  561. union ib_gid alt_remote_gid;
  562. /* flow label:20, rsvd:4, traffic class:8 */
  563. __be32 offset56;
  564. u8 alt_hop_limit;
  565. /* rsvd:2, packet rate:6 */
  566. u8 offset61;
  567. /* SL:4, subnet local:1, rsvd:3 */
  568. u8 offset62;
  569. /* local ACK timeout:5, rsvd:3 */
  570. u8 offset63;
  571. u8 private_data[IB_CM_LAP_PRIVATE_DATA_SIZE];
  572. } __attribute__ ((packed));
  573. static inline __be32 cm_lap_get_remote_qpn(struct cm_lap_msg *lap_msg)
  574. {
  575. return cpu_to_be32(be32_to_cpu(lap_msg->offset12) >> 8);
  576. }
  577. static inline void cm_lap_set_remote_qpn(struct cm_lap_msg *lap_msg, __be32 qpn)
  578. {
  579. lap_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  580. (be32_to_cpu(lap_msg->offset12) &
  581. 0x000000FF));
  582. }
  583. static inline u8 cm_lap_get_remote_resp_timeout(struct cm_lap_msg *lap_msg)
  584. {
  585. return (u8) ((be32_to_cpu(lap_msg->offset12) & 0xF8) >> 3);
  586. }
  587. static inline void cm_lap_set_remote_resp_timeout(struct cm_lap_msg *lap_msg,
  588. u8 resp_timeout)
  589. {
  590. lap_msg->offset12 = cpu_to_be32((resp_timeout << 3) |
  591. (be32_to_cpu(lap_msg->offset12) &
  592. 0xFFFFFF07));
  593. }
  594. static inline __be32 cm_lap_get_flow_label(struct cm_lap_msg *lap_msg)
  595. {
  596. return cpu_to_be32(be32_to_cpu(lap_msg->offset56) >> 12);
  597. }
  598. static inline void cm_lap_set_flow_label(struct cm_lap_msg *lap_msg,
  599. __be32 flow_label)
  600. {
  601. lap_msg->offset56 = cpu_to_be32(
  602. (be32_to_cpu(lap_msg->offset56) & 0x00000FFF) |
  603. (be32_to_cpu(flow_label) << 12));
  604. }
  605. static inline u8 cm_lap_get_traffic_class(struct cm_lap_msg *lap_msg)
  606. {
  607. return (u8) be32_to_cpu(lap_msg->offset56);
  608. }
  609. static inline void cm_lap_set_traffic_class(struct cm_lap_msg *lap_msg,
  610. u8 traffic_class)
  611. {
  612. lap_msg->offset56 = cpu_to_be32(traffic_class |
  613. (be32_to_cpu(lap_msg->offset56) &
  614. 0xFFFFFF00));
  615. }
  616. static inline u8 cm_lap_get_packet_rate(struct cm_lap_msg *lap_msg)
  617. {
  618. return lap_msg->offset61 & 0x3F;
  619. }
  620. static inline void cm_lap_set_packet_rate(struct cm_lap_msg *lap_msg,
  621. u8 packet_rate)
  622. {
  623. lap_msg->offset61 = (packet_rate & 0x3F) | (lap_msg->offset61 & 0xC0);
  624. }
  625. static inline u8 cm_lap_get_sl(struct cm_lap_msg *lap_msg)
  626. {
  627. return lap_msg->offset62 >> 4;
  628. }
  629. static inline void cm_lap_set_sl(struct cm_lap_msg *lap_msg, u8 sl)
  630. {
  631. lap_msg->offset62 = (sl << 4) | (lap_msg->offset62 & 0x0F);
  632. }
  633. static inline u8 cm_lap_get_subnet_local(struct cm_lap_msg *lap_msg)
  634. {
  635. return (lap_msg->offset62 >> 3) & 0x1;
  636. }
  637. static inline void cm_lap_set_subnet_local(struct cm_lap_msg *lap_msg,
  638. u8 subnet_local)
  639. {
  640. lap_msg->offset62 = ((subnet_local & 0x1) << 3) |
  641. (lap_msg->offset61 & 0xF7);
  642. }
  643. static inline u8 cm_lap_get_local_ack_timeout(struct cm_lap_msg *lap_msg)
  644. {
  645. return lap_msg->offset63 >> 3;
  646. }
  647. static inline void cm_lap_set_local_ack_timeout(struct cm_lap_msg *lap_msg,
  648. u8 local_ack_timeout)
  649. {
  650. lap_msg->offset63 = (local_ack_timeout << 3) |
  651. (lap_msg->offset63 & 0x07);
  652. }
  653. struct cm_apr_msg {
  654. struct ib_mad_hdr hdr;
  655. __be32 local_comm_id;
  656. __be32 remote_comm_id;
  657. u8 info_length;
  658. u8 ap_status;
  659. __be16 rsvd;
  660. u8 info[IB_CM_APR_INFO_LENGTH];
  661. u8 private_data[IB_CM_APR_PRIVATE_DATA_SIZE];
  662. } __attribute__ ((packed));
  663. struct cm_sidr_req_msg {
  664. struct ib_mad_hdr hdr;
  665. __be32 request_id;
  666. __be16 pkey;
  667. __be16 rsvd;
  668. __be64 service_id;
  669. u32 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE / sizeof(u32)];
  670. } __attribute__ ((packed));
  671. struct cm_sidr_rep_msg {
  672. struct ib_mad_hdr hdr;
  673. __be32 request_id;
  674. u8 status;
  675. u8 info_length;
  676. __be16 rsvd;
  677. /* QPN:24, rsvd:8 */
  678. __be32 offset8;
  679. __be64 service_id;
  680. __be32 qkey;
  681. u8 info[IB_CM_SIDR_REP_INFO_LENGTH];
  682. u8 private_data[IB_CM_SIDR_REP_PRIVATE_DATA_SIZE];
  683. } __attribute__ ((packed));
  684. static inline __be32 cm_sidr_rep_get_qpn(struct cm_sidr_rep_msg *sidr_rep_msg)
  685. {
  686. return cpu_to_be32(be32_to_cpu(sidr_rep_msg->offset8) >> 8);
  687. }
  688. static inline void cm_sidr_rep_set_qpn(struct cm_sidr_rep_msg *sidr_rep_msg,
  689. __be32 qpn)
  690. {
  691. sidr_rep_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
  692. (be32_to_cpu(sidr_rep_msg->offset8) &
  693. 0x000000FF));
  694. }
  695. #endif /* CM_MSGS_H */