cm_msgs.h 21 KB

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