1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004 Intel Corporation. All rights reserved. 3219820Sjeff * Copyright (c) 2004 Topspin Corporation. All rights reserved. 4219820Sjeff * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 5219820Sjeff * 6219820Sjeff * This software is available to you under a choice of one of two 7219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 8219820Sjeff * General Public License (GPL) Version 2, available from the file 9219820Sjeff * COPYING the madirectory of this source tree, or the 10219820Sjeff * OpenIB.org BSD license below: 11219820Sjeff * 12219820Sjeff * Redistribution and use source and binary forms, with or 13219820Sjeff * withmodification, are permitted provided that the following 14219820Sjeff * conditions are met: 15219820Sjeff * 16219820Sjeff * - Redistributions of source code must retathe above 17219820Sjeff * copyright notice, this list of conditions and the following 18219820Sjeff * disclaimer. 19219820Sjeff * 20219820Sjeff * - Redistributions binary form must reproduce the above 21219820Sjeff * copyright notice, this list of conditions and the following 22219820Sjeff * disclaimer the documentation and/or other materials 23219820Sjeff * provided with the distribution. 24219820Sjeff * 25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHWARRANTY OF ANY KIND, 26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28219820Sjeff * NONINFRINGEMENT. NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER AN 30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OF OR IN 31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS THE 32219820Sjeff * SOFTWARE. 33219820Sjeff */ 34219820Sjeff#if !defined(CM_MSGS_H) 35219820Sjeff#define CM_MSGS_H 36219820Sjeff 37219820Sjeff#include <rdma/ib_mad.h> 38219820Sjeff#include <rdma/ib_cm.h> 39219820Sjeff 40219820Sjeff/* 41219820Sjeff * Parameters to routines below should be in network-byte order, and values 42219820Sjeff * are returned in network-byte order. 43219820Sjeff */ 44219820Sjeff 45219820Sjeff#define IB_CM_CLASS_VERSION 2 /* IB specification 1.2 */ 46219820Sjeff 47219820Sjeff#define CM_REQ_ATTR_ID cpu_to_be16(0x0010) 48219820Sjeff#define CM_MRA_ATTR_ID cpu_to_be16(0x0011) 49219820Sjeff#define CM_REJ_ATTR_ID cpu_to_be16(0x0012) 50219820Sjeff#define CM_REP_ATTR_ID cpu_to_be16(0x0013) 51219820Sjeff#define CM_RTU_ATTR_ID cpu_to_be16(0x0014) 52219820Sjeff#define CM_DREQ_ATTR_ID cpu_to_be16(0x0015) 53219820Sjeff#define CM_DREP_ATTR_ID cpu_to_be16(0x0016) 54219820Sjeff#define CM_SIDR_REQ_ATTR_ID cpu_to_be16(0x0017) 55219820Sjeff#define CM_SIDR_REP_ATTR_ID cpu_to_be16(0x0018) 56219820Sjeff#define CM_LAP_ATTR_ID cpu_to_be16(0x0019) 57219820Sjeff#define CM_APR_ATTR_ID cpu_to_be16(0x001A) 58219820Sjeff 59219820Sjeffenum cm_msg_sequence { 60219820Sjeff CM_MSG_SEQUENCE_REQ, 61219820Sjeff CM_MSG_SEQUENCE_LAP, 62219820Sjeff CM_MSG_SEQUENCE_DREQ, 63219820Sjeff CM_MSG_SEQUENCE_SIDR 64219820Sjeff}; 65219820Sjeff 66219820Sjeffstruct cm_req_msg { 67219820Sjeff struct ib_mad_hdr hdr; 68219820Sjeff 69219820Sjeff __be32 local_comm_id; 70219820Sjeff __be32 rsvd4; 71219820Sjeff __be64 service_id; 72219820Sjeff __be64 local_ca_guid; 73219820Sjeff __be32 rsvd24; 74219820Sjeff __be32 local_qkey; 75219820Sjeff /* local QPN:24, responder resources:8 */ 76219820Sjeff __be32 offset32; 77219820Sjeff /* local EECN:24, initiator depth:8 */ 78219820Sjeff __be32 offset36; 79219820Sjeff /* 80219820Sjeff * remote EECN:24, remote CM response timeout:5, 81219820Sjeff * transport service type:2, end-to-end flow control:1 82219820Sjeff */ 83219820Sjeff __be32 offset40; 84219820Sjeff /* starting PSN:24, local CM response timeout:5, retry count:3 */ 85219820Sjeff __be32 offset44; 86219820Sjeff __be16 pkey; 87219820Sjeff /* path MTU:4, RDC exists:1, RNR retry count:3. */ 88219820Sjeff u8 offset50; 89219820Sjeff /* max CM Retries:4, SRQ:1, rsvd:3 */ 90219820Sjeff u8 offset51; 91219820Sjeff 92219820Sjeff __be16 primary_local_lid; 93219820Sjeff __be16 primary_remote_lid; 94219820Sjeff union ib_gid primary_local_gid; 95219820Sjeff union ib_gid primary_remote_gid; 96219820Sjeff /* flow label:20, rsvd:6, packet rate:6 */ 97219820Sjeff __be32 primary_offset88; 98219820Sjeff u8 primary_traffic_class; 99219820Sjeff u8 primary_hop_limit; 100219820Sjeff /* SL:4, subnet local:1, rsvd:3 */ 101219820Sjeff u8 primary_offset94; 102219820Sjeff /* local ACK timeout:5, rsvd:3 */ 103219820Sjeff u8 primary_offset95; 104219820Sjeff 105219820Sjeff __be16 alt_local_lid; 106219820Sjeff __be16 alt_remote_lid; 107219820Sjeff union ib_gid alt_local_gid; 108219820Sjeff union ib_gid alt_remote_gid; 109219820Sjeff /* flow label:20, rsvd:6, packet rate:6 */ 110219820Sjeff __be32 alt_offset132; 111219820Sjeff u8 alt_traffic_class; 112219820Sjeff u8 alt_hop_limit; 113219820Sjeff /* SL:4, subnet local:1, rsvd:3 */ 114219820Sjeff u8 alt_offset138; 115219820Sjeff /* local ACK timeout:5, rsvd:3 */ 116219820Sjeff u8 alt_offset139; 117219820Sjeff 118219820Sjeff u8 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE]; 119219820Sjeff 120219820Sjeff} __attribute__ ((packed)); 121219820Sjeff 122219820Sjeffstatic inline __be32 cm_req_get_local_qpn(struct cm_req_msg *req_msg) 123219820Sjeff{ 124219820Sjeff return cpu_to_be32(be32_to_cpu(req_msg->offset32) >> 8); 125219820Sjeff} 126219820Sjeff 127219820Sjeffstatic inline void cm_req_set_local_qpn(struct cm_req_msg *req_msg, __be32 qpn) 128219820Sjeff{ 129219820Sjeff req_msg->offset32 = cpu_to_be32((be32_to_cpu(qpn) << 8) | 130219820Sjeff (be32_to_cpu(req_msg->offset32) & 131219820Sjeff 0x000000FF)); 132219820Sjeff} 133219820Sjeff 134219820Sjeffstatic inline u8 cm_req_get_resp_res(struct cm_req_msg *req_msg) 135219820Sjeff{ 136219820Sjeff return (u8) be32_to_cpu(req_msg->offset32); 137219820Sjeff} 138219820Sjeff 139219820Sjeffstatic inline void cm_req_set_resp_res(struct cm_req_msg *req_msg, u8 resp_res) 140219820Sjeff{ 141219820Sjeff req_msg->offset32 = cpu_to_be32(resp_res | 142219820Sjeff (be32_to_cpu(req_msg->offset32) & 143219820Sjeff 0xFFFFFF00)); 144219820Sjeff} 145219820Sjeff 146219820Sjeffstatic inline u8 cm_req_get_init_depth(struct cm_req_msg *req_msg) 147219820Sjeff{ 148219820Sjeff return (u8) be32_to_cpu(req_msg->offset36); 149219820Sjeff} 150219820Sjeff 151219820Sjeffstatic inline void cm_req_set_init_depth(struct cm_req_msg *req_msg, 152219820Sjeff u8 init_depth) 153219820Sjeff{ 154219820Sjeff req_msg->offset36 = cpu_to_be32(init_depth | 155219820Sjeff (be32_to_cpu(req_msg->offset36) & 156219820Sjeff 0xFFFFFF00)); 157219820Sjeff} 158219820Sjeff 159219820Sjeffstatic inline u8 cm_req_get_remote_resp_timeout(struct cm_req_msg *req_msg) 160219820Sjeff{ 161219820Sjeff return (u8) ((be32_to_cpu(req_msg->offset40) & 0xF8) >> 3); 162219820Sjeff} 163219820Sjeff 164219820Sjeffstatic inline void cm_req_set_remote_resp_timeout(struct cm_req_msg *req_msg, 165219820Sjeff u8 resp_timeout) 166219820Sjeff{ 167219820Sjeff req_msg->offset40 = cpu_to_be32((resp_timeout << 3) | 168219820Sjeff (be32_to_cpu(req_msg->offset40) & 169219820Sjeff 0xFFFFFF07)); 170219820Sjeff} 171219820Sjeff 172219820Sjeffstatic inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg) 173219820Sjeff{ 174219820Sjeff u8 transport_type = (u8) (be32_to_cpu(req_msg->offset40) & 0x06) >> 1; 175219820Sjeff switch(transport_type) { 176219820Sjeff case 0: return IB_QPT_RC; 177219820Sjeff case 1: return IB_QPT_UC; 178219820Sjeff default: return 0; 179219820Sjeff } 180219820Sjeff} 181219820Sjeff 182219820Sjeffstatic inline void cm_req_set_qp_type(struct cm_req_msg *req_msg, 183219820Sjeff enum ib_qp_type qp_type) 184219820Sjeff{ 185219820Sjeff switch(qp_type) { 186219820Sjeff case IB_QPT_UC: 187219820Sjeff req_msg->offset40 = cpu_to_be32((be32_to_cpu( 188219820Sjeff req_msg->offset40) & 189219820Sjeff 0xFFFFFFF9) | 0x2); 190219820Sjeff break; 191219820Sjeff default: 192219820Sjeff req_msg->offset40 = cpu_to_be32(be32_to_cpu( 193219820Sjeff req_msg->offset40) & 194219820Sjeff 0xFFFFFFF9); 195219820Sjeff } 196219820Sjeff} 197219820Sjeff 198219820Sjeffstatic inline u8 cm_req_get_flow_ctrl(struct cm_req_msg *req_msg) 199219820Sjeff{ 200219820Sjeff return be32_to_cpu(req_msg->offset40) & 0x1; 201219820Sjeff} 202219820Sjeff 203219820Sjeffstatic inline void cm_req_set_flow_ctrl(struct cm_req_msg *req_msg, 204219820Sjeff u8 flow_ctrl) 205219820Sjeff{ 206219820Sjeff req_msg->offset40 = cpu_to_be32((flow_ctrl & 0x1) | 207219820Sjeff (be32_to_cpu(req_msg->offset40) & 208219820Sjeff 0xFFFFFFFE)); 209219820Sjeff} 210219820Sjeff 211219820Sjeffstatic inline __be32 cm_req_get_starting_psn(struct cm_req_msg *req_msg) 212219820Sjeff{ 213219820Sjeff return cpu_to_be32(be32_to_cpu(req_msg->offset44) >> 8); 214219820Sjeff} 215219820Sjeff 216219820Sjeffstatic inline void cm_req_set_starting_psn(struct cm_req_msg *req_msg, 217219820Sjeff __be32 starting_psn) 218219820Sjeff{ 219219820Sjeff req_msg->offset44 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) | 220219820Sjeff (be32_to_cpu(req_msg->offset44) & 0x000000FF)); 221219820Sjeff} 222219820Sjeff 223219820Sjeffstatic inline u8 cm_req_get_local_resp_timeout(struct cm_req_msg *req_msg) 224219820Sjeff{ 225219820Sjeff return (u8) ((be32_to_cpu(req_msg->offset44) & 0xF8) >> 3); 226219820Sjeff} 227219820Sjeff 228219820Sjeffstatic inline void cm_req_set_local_resp_timeout(struct cm_req_msg *req_msg, 229219820Sjeff u8 resp_timeout) 230219820Sjeff{ 231219820Sjeff req_msg->offset44 = cpu_to_be32((resp_timeout << 3) | 232219820Sjeff (be32_to_cpu(req_msg->offset44) & 0xFFFFFF07)); 233219820Sjeff} 234219820Sjeff 235219820Sjeffstatic inline u8 cm_req_get_retry_count(struct cm_req_msg *req_msg) 236219820Sjeff{ 237219820Sjeff return (u8) (be32_to_cpu(req_msg->offset44) & 0x7); 238219820Sjeff} 239219820Sjeff 240219820Sjeffstatic inline void cm_req_set_retry_count(struct cm_req_msg *req_msg, 241219820Sjeff u8 retry_count) 242219820Sjeff{ 243219820Sjeff req_msg->offset44 = cpu_to_be32((retry_count & 0x7) | 244219820Sjeff (be32_to_cpu(req_msg->offset44) & 0xFFFFFFF8)); 245219820Sjeff} 246219820Sjeff 247219820Sjeffstatic inline u8 cm_req_get_path_mtu(struct cm_req_msg *req_msg) 248219820Sjeff{ 249219820Sjeff return req_msg->offset50 >> 4; 250219820Sjeff} 251219820Sjeff 252219820Sjeffstatic inline void cm_req_set_path_mtu(struct cm_req_msg *req_msg, u8 path_mtu) 253219820Sjeff{ 254219820Sjeff req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF) | (path_mtu << 4)); 255219820Sjeff} 256219820Sjeff 257219820Sjeffstatic inline u8 cm_req_get_rnr_retry_count(struct cm_req_msg *req_msg) 258219820Sjeff{ 259219820Sjeff return req_msg->offset50 & 0x7; 260219820Sjeff} 261219820Sjeff 262219820Sjeffstatic inline void cm_req_set_rnr_retry_count(struct cm_req_msg *req_msg, 263219820Sjeff u8 rnr_retry_count) 264219820Sjeff{ 265219820Sjeff req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF8) | 266219820Sjeff (rnr_retry_count & 0x7)); 267219820Sjeff} 268219820Sjeff 269219820Sjeffstatic inline u8 cm_req_get_max_cm_retries(struct cm_req_msg *req_msg) 270219820Sjeff{ 271219820Sjeff return req_msg->offset51 >> 4; 272219820Sjeff} 273219820Sjeff 274219820Sjeffstatic inline void cm_req_set_max_cm_retries(struct cm_req_msg *req_msg, 275219820Sjeff u8 retries) 276219820Sjeff{ 277219820Sjeff req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF) | (retries << 4)); 278219820Sjeff} 279219820Sjeff 280219820Sjeffstatic inline u8 cm_req_get_srq(struct cm_req_msg *req_msg) 281219820Sjeff{ 282219820Sjeff return (req_msg->offset51 & 0x8) >> 3; 283219820Sjeff} 284219820Sjeff 285219820Sjeffstatic inline void cm_req_set_srq(struct cm_req_msg *req_msg, u8 srq) 286219820Sjeff{ 287219820Sjeff req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF7) | 288219820Sjeff ((srq & 0x1) << 3)); 289219820Sjeff} 290219820Sjeff 291219820Sjeffstatic inline __be32 cm_req_get_primary_flow_label(struct cm_req_msg *req_msg) 292219820Sjeff{ 293219820Sjeff return cpu_to_be32(be32_to_cpu(req_msg->primary_offset88) >> 12); 294219820Sjeff} 295219820Sjeff 296219820Sjeffstatic inline void cm_req_set_primary_flow_label(struct cm_req_msg *req_msg, 297219820Sjeff __be32 flow_label) 298219820Sjeff{ 299219820Sjeff req_msg->primary_offset88 = cpu_to_be32( 300219820Sjeff (be32_to_cpu(req_msg->primary_offset88) & 301219820Sjeff 0x00000FFF) | 302219820Sjeff (be32_to_cpu(flow_label) << 12)); 303219820Sjeff} 304219820Sjeff 305219820Sjeffstatic inline u8 cm_req_get_primary_packet_rate(struct cm_req_msg *req_msg) 306219820Sjeff{ 307219820Sjeff return (u8) (be32_to_cpu(req_msg->primary_offset88) & 0x3F); 308219820Sjeff} 309219820Sjeff 310219820Sjeffstatic inline void cm_req_set_primary_packet_rate(struct cm_req_msg *req_msg, 311219820Sjeff u8 rate) 312219820Sjeff{ 313219820Sjeff req_msg->primary_offset88 = cpu_to_be32( 314219820Sjeff (be32_to_cpu(req_msg->primary_offset88) & 315219820Sjeff 0xFFFFFFC0) | (rate & 0x3F)); 316219820Sjeff} 317219820Sjeff 318219820Sjeffstatic inline u8 cm_req_get_primary_sl(struct cm_req_msg *req_msg) 319219820Sjeff{ 320219820Sjeff return (u8) (req_msg->primary_offset94 >> 4); 321219820Sjeff} 322219820Sjeff 323219820Sjeffstatic inline void cm_req_set_primary_sl(struct cm_req_msg *req_msg, u8 sl) 324219820Sjeff{ 325219820Sjeff req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0x0F) | 326219820Sjeff (sl << 4)); 327219820Sjeff} 328219820Sjeff 329219820Sjeffstatic inline u8 cm_req_get_primary_subnet_local(struct cm_req_msg *req_msg) 330219820Sjeff{ 331219820Sjeff return (u8) ((req_msg->primary_offset94 & 0x08) >> 3); 332219820Sjeff} 333219820Sjeff 334219820Sjeffstatic inline void cm_req_set_primary_subnet_local(struct cm_req_msg *req_msg, 335219820Sjeff u8 subnet_local) 336219820Sjeff{ 337219820Sjeff req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0xF7) | 338219820Sjeff ((subnet_local & 0x1) << 3)); 339219820Sjeff} 340219820Sjeff 341219820Sjeffstatic inline u8 cm_req_get_primary_local_ack_timeout(struct cm_req_msg *req_msg) 342219820Sjeff{ 343219820Sjeff return (u8) (req_msg->primary_offset95 >> 3); 344219820Sjeff} 345219820Sjeff 346219820Sjeffstatic inline void cm_req_set_primary_local_ack_timeout(struct cm_req_msg *req_msg, 347219820Sjeff u8 local_ack_timeout) 348219820Sjeff{ 349219820Sjeff req_msg->primary_offset95 = (u8) ((req_msg->primary_offset95 & 0x07) | 350219820Sjeff (local_ack_timeout << 3)); 351219820Sjeff} 352219820Sjeff 353219820Sjeffstatic inline __be32 cm_req_get_alt_flow_label(struct cm_req_msg *req_msg) 354219820Sjeff{ 355219820Sjeff return cpu_to_be32(be32_to_cpu(req_msg->alt_offset132) >> 12); 356219820Sjeff} 357219820Sjeff 358219820Sjeffstatic inline void cm_req_set_alt_flow_label(struct cm_req_msg *req_msg, 359219820Sjeff __be32 flow_label) 360219820Sjeff{ 361219820Sjeff req_msg->alt_offset132 = cpu_to_be32( 362219820Sjeff (be32_to_cpu(req_msg->alt_offset132) & 363219820Sjeff 0x00000FFF) | 364219820Sjeff (be32_to_cpu(flow_label) << 12)); 365219820Sjeff} 366219820Sjeff 367219820Sjeffstatic inline u8 cm_req_get_alt_packet_rate(struct cm_req_msg *req_msg) 368219820Sjeff{ 369219820Sjeff return (u8) (be32_to_cpu(req_msg->alt_offset132) & 0x3F); 370219820Sjeff} 371219820Sjeff 372219820Sjeffstatic inline void cm_req_set_alt_packet_rate(struct cm_req_msg *req_msg, 373219820Sjeff u8 rate) 374219820Sjeff{ 375219820Sjeff req_msg->alt_offset132 = cpu_to_be32( 376219820Sjeff (be32_to_cpu(req_msg->alt_offset132) & 377219820Sjeff 0xFFFFFFC0) | (rate & 0x3F)); 378219820Sjeff} 379219820Sjeff 380219820Sjeffstatic inline u8 cm_req_get_alt_sl(struct cm_req_msg *req_msg) 381219820Sjeff{ 382219820Sjeff return (u8) (req_msg->alt_offset138 >> 4); 383219820Sjeff} 384219820Sjeff 385219820Sjeffstatic inline void cm_req_set_alt_sl(struct cm_req_msg *req_msg, u8 sl) 386219820Sjeff{ 387219820Sjeff req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0x0F) | 388219820Sjeff (sl << 4)); 389219820Sjeff} 390219820Sjeff 391219820Sjeffstatic inline u8 cm_req_get_alt_subnet_local(struct cm_req_msg *req_msg) 392219820Sjeff{ 393219820Sjeff return (u8) ((req_msg->alt_offset138 & 0x08) >> 3); 394219820Sjeff} 395219820Sjeff 396219820Sjeffstatic inline void cm_req_set_alt_subnet_local(struct cm_req_msg *req_msg, 397219820Sjeff u8 subnet_local) 398219820Sjeff{ 399219820Sjeff req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0xF7) | 400219820Sjeff ((subnet_local & 0x1) << 3)); 401219820Sjeff} 402219820Sjeff 403219820Sjeffstatic inline u8 cm_req_get_alt_local_ack_timeout(struct cm_req_msg *req_msg) 404219820Sjeff{ 405219820Sjeff return (u8) (req_msg->alt_offset139 >> 3); 406219820Sjeff} 407219820Sjeff 408219820Sjeffstatic inline void cm_req_set_alt_local_ack_timeout(struct cm_req_msg *req_msg, 409219820Sjeff u8 local_ack_timeout) 410219820Sjeff{ 411219820Sjeff req_msg->alt_offset139 = (u8) ((req_msg->alt_offset139 & 0x07) | 412219820Sjeff (local_ack_timeout << 3)); 413219820Sjeff} 414219820Sjeff 415219820Sjeff/* Message REJected or MRAed */ 416219820Sjeffenum cm_msg_response { 417219820Sjeff CM_MSG_RESPONSE_REQ = 0x0, 418219820Sjeff CM_MSG_RESPONSE_REP = 0x1, 419219820Sjeff CM_MSG_RESPONSE_OTHER = 0x2 420219820Sjeff}; 421219820Sjeff 422219820Sjeff struct cm_mra_msg { 423219820Sjeff struct ib_mad_hdr hdr; 424219820Sjeff 425219820Sjeff __be32 local_comm_id; 426219820Sjeff __be32 remote_comm_id; 427219820Sjeff /* message MRAed:2, rsvd:6 */ 428219820Sjeff u8 offset8; 429219820Sjeff /* service timeout:5, rsvd:3 */ 430219820Sjeff u8 offset9; 431219820Sjeff 432219820Sjeff u8 private_data[IB_CM_MRA_PRIVATE_DATA_SIZE]; 433219820Sjeff 434219820Sjeff} __attribute__ ((packed)); 435219820Sjeff 436219820Sjeffstatic inline u8 cm_mra_get_msg_mraed(struct cm_mra_msg *mra_msg) 437219820Sjeff{ 438219820Sjeff return (u8) (mra_msg->offset8 >> 6); 439219820Sjeff} 440219820Sjeff 441219820Sjeffstatic inline void cm_mra_set_msg_mraed(struct cm_mra_msg *mra_msg, u8 msg) 442219820Sjeff{ 443219820Sjeff mra_msg->offset8 = (u8) ((mra_msg->offset8 & 0x3F) | (msg << 6)); 444219820Sjeff} 445219820Sjeff 446219820Sjeffstatic inline u8 cm_mra_get_service_timeout(struct cm_mra_msg *mra_msg) 447219820Sjeff{ 448219820Sjeff return (u8) (mra_msg->offset9 >> 3); 449219820Sjeff} 450219820Sjeff 451219820Sjeffstatic inline void cm_mra_set_service_timeout(struct cm_mra_msg *mra_msg, 452219820Sjeff u8 service_timeout) 453219820Sjeff{ 454219820Sjeff mra_msg->offset9 = (u8) ((mra_msg->offset9 & 0x07) | 455219820Sjeff (service_timeout << 3)); 456219820Sjeff} 457219820Sjeff 458219820Sjeffstruct cm_rej_msg { 459219820Sjeff struct ib_mad_hdr hdr; 460219820Sjeff 461219820Sjeff __be32 local_comm_id; 462219820Sjeff __be32 remote_comm_id; 463219820Sjeff /* message REJected:2, rsvd:6 */ 464219820Sjeff u8 offset8; 465219820Sjeff /* reject info length:7, rsvd:1. */ 466219820Sjeff u8 offset9; 467219820Sjeff __be16 reason; 468219820Sjeff u8 ari[IB_CM_REJ_ARI_LENGTH]; 469219820Sjeff 470219820Sjeff u8 private_data[IB_CM_REJ_PRIVATE_DATA_SIZE]; 471219820Sjeff 472219820Sjeff} __attribute__ ((packed)); 473219820Sjeff 474219820Sjeffstatic inline u8 cm_rej_get_msg_rejected(struct cm_rej_msg *rej_msg) 475219820Sjeff{ 476219820Sjeff return (u8) (rej_msg->offset8 >> 6); 477219820Sjeff} 478219820Sjeff 479219820Sjeffstatic inline void cm_rej_set_msg_rejected(struct cm_rej_msg *rej_msg, u8 msg) 480219820Sjeff{ 481219820Sjeff rej_msg->offset8 = (u8) ((rej_msg->offset8 & 0x3F) | (msg << 6)); 482219820Sjeff} 483219820Sjeff 484219820Sjeffstatic inline u8 cm_rej_get_reject_info_len(struct cm_rej_msg *rej_msg) 485219820Sjeff{ 486219820Sjeff return (u8) (rej_msg->offset9 >> 1); 487219820Sjeff} 488219820Sjeff 489219820Sjeffstatic inline void cm_rej_set_reject_info_len(struct cm_rej_msg *rej_msg, 490219820Sjeff u8 len) 491219820Sjeff{ 492219820Sjeff rej_msg->offset9 = (u8) ((rej_msg->offset9 & 0x1) | (len << 1)); 493219820Sjeff} 494219820Sjeff 495219820Sjeffstruct cm_rep_msg { 496219820Sjeff struct ib_mad_hdr hdr; 497219820Sjeff 498219820Sjeff __be32 local_comm_id; 499219820Sjeff __be32 remote_comm_id; 500219820Sjeff __be32 local_qkey; 501219820Sjeff /* local QPN:24, rsvd:8 */ 502219820Sjeff __be32 offset12; 503219820Sjeff /* local EECN:24, rsvd:8 */ 504219820Sjeff __be32 offset16; 505219820Sjeff /* starting PSN:24 rsvd:8 */ 506219820Sjeff __be32 offset20; 507219820Sjeff u8 resp_resources; 508219820Sjeff u8 initiator_depth; 509219820Sjeff /* target ACK delay:5, failover accepted:2, end-to-end flow control:1 */ 510219820Sjeff u8 offset26; 511219820Sjeff /* RNR retry count:3, SRQ:1, rsvd:5 */ 512219820Sjeff u8 offset27; 513219820Sjeff __be64 local_ca_guid; 514219820Sjeff 515219820Sjeff u8 private_data[IB_CM_REP_PRIVATE_DATA_SIZE]; 516219820Sjeff 517219820Sjeff} __attribute__ ((packed)); 518219820Sjeff 519219820Sjeffstatic inline __be32 cm_rep_get_local_qpn(struct cm_rep_msg *rep_msg) 520219820Sjeff{ 521219820Sjeff return cpu_to_be32(be32_to_cpu(rep_msg->offset12) >> 8); 522219820Sjeff} 523219820Sjeff 524219820Sjeffstatic inline void cm_rep_set_local_qpn(struct cm_rep_msg *rep_msg, __be32 qpn) 525219820Sjeff{ 526219820Sjeff rep_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) | 527219820Sjeff (be32_to_cpu(rep_msg->offset12) & 0x000000FF)); 528219820Sjeff} 529219820Sjeff 530219820Sjeffstatic inline __be32 cm_rep_get_starting_psn(struct cm_rep_msg *rep_msg) 531219820Sjeff{ 532219820Sjeff return cpu_to_be32(be32_to_cpu(rep_msg->offset20) >> 8); 533219820Sjeff} 534219820Sjeff 535219820Sjeffstatic inline void cm_rep_set_starting_psn(struct cm_rep_msg *rep_msg, 536219820Sjeff __be32 starting_psn) 537219820Sjeff{ 538219820Sjeff rep_msg->offset20 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) | 539219820Sjeff (be32_to_cpu(rep_msg->offset20) & 0x000000FF)); 540219820Sjeff} 541219820Sjeff 542219820Sjeffstatic inline u8 cm_rep_get_target_ack_delay(struct cm_rep_msg *rep_msg) 543219820Sjeff{ 544219820Sjeff return (u8) (rep_msg->offset26 >> 3); 545219820Sjeff} 546219820Sjeff 547219820Sjeffstatic inline void cm_rep_set_target_ack_delay(struct cm_rep_msg *rep_msg, 548219820Sjeff u8 target_ack_delay) 549219820Sjeff{ 550219820Sjeff rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0x07) | 551219820Sjeff (target_ack_delay << 3)); 552219820Sjeff} 553219820Sjeff 554219820Sjeffstatic inline u8 cm_rep_get_failover(struct cm_rep_msg *rep_msg) 555219820Sjeff{ 556219820Sjeff return (u8) ((rep_msg->offset26 & 0x06) >> 1); 557219820Sjeff} 558219820Sjeff 559219820Sjeffstatic inline void cm_rep_set_failover(struct cm_rep_msg *rep_msg, u8 failover) 560219820Sjeff{ 561219820Sjeff rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xF9) | 562219820Sjeff ((failover & 0x3) << 1)); 563219820Sjeff} 564219820Sjeff 565219820Sjeffstatic inline u8 cm_rep_get_flow_ctrl(struct cm_rep_msg *rep_msg) 566219820Sjeff{ 567219820Sjeff return (u8) (rep_msg->offset26 & 0x01); 568219820Sjeff} 569219820Sjeff 570219820Sjeffstatic inline void cm_rep_set_flow_ctrl(struct cm_rep_msg *rep_msg, 571219820Sjeff u8 flow_ctrl) 572219820Sjeff{ 573219820Sjeff rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xFE) | 574219820Sjeff (flow_ctrl & 0x1)); 575219820Sjeff} 576219820Sjeff 577219820Sjeffstatic inline u8 cm_rep_get_rnr_retry_count(struct cm_rep_msg *rep_msg) 578219820Sjeff{ 579219820Sjeff return (u8) (rep_msg->offset27 >> 5); 580219820Sjeff} 581219820Sjeff 582219820Sjeffstatic inline void cm_rep_set_rnr_retry_count(struct cm_rep_msg *rep_msg, 583219820Sjeff u8 rnr_retry_count) 584219820Sjeff{ 585219820Sjeff rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0x1F) | 586219820Sjeff (rnr_retry_count << 5)); 587219820Sjeff} 588219820Sjeff 589219820Sjeffstatic inline u8 cm_rep_get_srq(struct cm_rep_msg *rep_msg) 590219820Sjeff{ 591219820Sjeff return (u8) ((rep_msg->offset27 >> 4) & 0x1); 592219820Sjeff} 593219820Sjeff 594219820Sjeffstatic inline void cm_rep_set_srq(struct cm_rep_msg *rep_msg, u8 srq) 595219820Sjeff{ 596219820Sjeff rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0xEF) | 597219820Sjeff ((srq & 0x1) << 4)); 598219820Sjeff} 599219820Sjeff 600219820Sjeffstruct cm_rtu_msg { 601219820Sjeff struct ib_mad_hdr hdr; 602219820Sjeff 603219820Sjeff __be32 local_comm_id; 604219820Sjeff __be32 remote_comm_id; 605219820Sjeff 606219820Sjeff u8 private_data[IB_CM_RTU_PRIVATE_DATA_SIZE]; 607219820Sjeff 608219820Sjeff} __attribute__ ((packed)); 609219820Sjeff 610219820Sjeffstruct cm_dreq_msg { 611219820Sjeff struct ib_mad_hdr hdr; 612219820Sjeff 613219820Sjeff __be32 local_comm_id; 614219820Sjeff __be32 remote_comm_id; 615219820Sjeff /* remote QPN/EECN:24, rsvd:8 */ 616219820Sjeff __be32 offset8; 617219820Sjeff 618219820Sjeff u8 private_data[IB_CM_DREQ_PRIVATE_DATA_SIZE]; 619219820Sjeff 620219820Sjeff} __attribute__ ((packed)); 621219820Sjeff 622219820Sjeffstatic inline __be32 cm_dreq_get_remote_qpn(struct cm_dreq_msg *dreq_msg) 623219820Sjeff{ 624219820Sjeff return cpu_to_be32(be32_to_cpu(dreq_msg->offset8) >> 8); 625219820Sjeff} 626219820Sjeff 627219820Sjeffstatic inline void cm_dreq_set_remote_qpn(struct cm_dreq_msg *dreq_msg, __be32 qpn) 628219820Sjeff{ 629219820Sjeff dreq_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) | 630219820Sjeff (be32_to_cpu(dreq_msg->offset8) & 0x000000FF)); 631219820Sjeff} 632219820Sjeff 633219820Sjeffstruct cm_drep_msg { 634219820Sjeff struct ib_mad_hdr hdr; 635219820Sjeff 636219820Sjeff __be32 local_comm_id; 637219820Sjeff __be32 remote_comm_id; 638219820Sjeff 639219820Sjeff u8 private_data[IB_CM_DREP_PRIVATE_DATA_SIZE]; 640219820Sjeff 641219820Sjeff} __attribute__ ((packed)); 642219820Sjeff 643219820Sjeffstruct cm_lap_msg { 644219820Sjeff struct ib_mad_hdr hdr; 645219820Sjeff 646219820Sjeff __be32 local_comm_id; 647219820Sjeff __be32 remote_comm_id; 648219820Sjeff 649219820Sjeff __be32 rsvd8; 650219820Sjeff /* remote QPN/EECN:24, remote CM response timeout:5, rsvd:3 */ 651219820Sjeff __be32 offset12; 652219820Sjeff __be32 rsvd16; 653219820Sjeff 654219820Sjeff __be16 alt_local_lid; 655219820Sjeff __be16 alt_remote_lid; 656219820Sjeff union ib_gid alt_local_gid; 657219820Sjeff union ib_gid alt_remote_gid; 658219820Sjeff /* flow label:20, rsvd:4, traffic class:8 */ 659219820Sjeff __be32 offset56; 660219820Sjeff u8 alt_hop_limit; 661219820Sjeff /* rsvd:2, packet rate:6 */ 662219820Sjeff u8 offset61; 663219820Sjeff /* SL:4, subnet local:1, rsvd:3 */ 664219820Sjeff u8 offset62; 665219820Sjeff /* local ACK timeout:5, rsvd:3 */ 666219820Sjeff u8 offset63; 667219820Sjeff 668219820Sjeff u8 private_data[IB_CM_LAP_PRIVATE_DATA_SIZE]; 669219820Sjeff} __attribute__ ((packed)); 670219820Sjeff 671219820Sjeffstatic inline __be32 cm_lap_get_remote_qpn(struct cm_lap_msg *lap_msg) 672219820Sjeff{ 673219820Sjeff return cpu_to_be32(be32_to_cpu(lap_msg->offset12) >> 8); 674219820Sjeff} 675219820Sjeff 676219820Sjeffstatic inline void cm_lap_set_remote_qpn(struct cm_lap_msg *lap_msg, __be32 qpn) 677219820Sjeff{ 678219820Sjeff lap_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) | 679219820Sjeff (be32_to_cpu(lap_msg->offset12) & 680219820Sjeff 0x000000FF)); 681219820Sjeff} 682219820Sjeff 683219820Sjeffstatic inline u8 cm_lap_get_remote_resp_timeout(struct cm_lap_msg *lap_msg) 684219820Sjeff{ 685219820Sjeff return (u8) ((be32_to_cpu(lap_msg->offset12) & 0xF8) >> 3); 686219820Sjeff} 687219820Sjeff 688219820Sjeffstatic inline void cm_lap_set_remote_resp_timeout(struct cm_lap_msg *lap_msg, 689219820Sjeff u8 resp_timeout) 690219820Sjeff{ 691219820Sjeff lap_msg->offset12 = cpu_to_be32((resp_timeout << 3) | 692219820Sjeff (be32_to_cpu(lap_msg->offset12) & 693219820Sjeff 0xFFFFFF07)); 694219820Sjeff} 695219820Sjeff 696219820Sjeffstatic inline __be32 cm_lap_get_flow_label(struct cm_lap_msg *lap_msg) 697219820Sjeff{ 698219820Sjeff return cpu_to_be32(be32_to_cpu(lap_msg->offset56) >> 12); 699219820Sjeff} 700219820Sjeff 701219820Sjeffstatic inline void cm_lap_set_flow_label(struct cm_lap_msg *lap_msg, 702219820Sjeff __be32 flow_label) 703219820Sjeff{ 704219820Sjeff lap_msg->offset56 = cpu_to_be32( 705219820Sjeff (be32_to_cpu(lap_msg->offset56) & 0x00000FFF) | 706219820Sjeff (be32_to_cpu(flow_label) << 12)); 707219820Sjeff} 708219820Sjeff 709219820Sjeffstatic inline u8 cm_lap_get_traffic_class(struct cm_lap_msg *lap_msg) 710219820Sjeff{ 711219820Sjeff return (u8) be32_to_cpu(lap_msg->offset56); 712219820Sjeff} 713219820Sjeff 714219820Sjeffstatic inline void cm_lap_set_traffic_class(struct cm_lap_msg *lap_msg, 715219820Sjeff u8 traffic_class) 716219820Sjeff{ 717219820Sjeff lap_msg->offset56 = cpu_to_be32(traffic_class | 718219820Sjeff (be32_to_cpu(lap_msg->offset56) & 719219820Sjeff 0xFFFFFF00)); 720219820Sjeff} 721219820Sjeff 722219820Sjeffstatic inline u8 cm_lap_get_packet_rate(struct cm_lap_msg *lap_msg) 723219820Sjeff{ 724219820Sjeff return lap_msg->offset61 & 0x3F; 725219820Sjeff} 726219820Sjeff 727219820Sjeffstatic inline void cm_lap_set_packet_rate(struct cm_lap_msg *lap_msg, 728219820Sjeff u8 packet_rate) 729219820Sjeff{ 730219820Sjeff lap_msg->offset61 = (packet_rate & 0x3F) | (lap_msg->offset61 & 0xC0); 731219820Sjeff} 732219820Sjeff 733219820Sjeffstatic inline u8 cm_lap_get_sl(struct cm_lap_msg *lap_msg) 734219820Sjeff{ 735219820Sjeff return lap_msg->offset62 >> 4; 736219820Sjeff} 737219820Sjeff 738219820Sjeffstatic inline void cm_lap_set_sl(struct cm_lap_msg *lap_msg, u8 sl) 739219820Sjeff{ 740219820Sjeff lap_msg->offset62 = (sl << 4) | (lap_msg->offset62 & 0x0F); 741219820Sjeff} 742219820Sjeff 743219820Sjeffstatic inline u8 cm_lap_get_subnet_local(struct cm_lap_msg *lap_msg) 744219820Sjeff{ 745219820Sjeff return (lap_msg->offset62 >> 3) & 0x1; 746219820Sjeff} 747219820Sjeff 748219820Sjeffstatic inline void cm_lap_set_subnet_local(struct cm_lap_msg *lap_msg, 749219820Sjeff u8 subnet_local) 750219820Sjeff{ 751219820Sjeff lap_msg->offset62 = ((subnet_local & 0x1) << 3) | 752219820Sjeff (lap_msg->offset61 & 0xF7); 753219820Sjeff} 754219820Sjeffstatic inline u8 cm_lap_get_local_ack_timeout(struct cm_lap_msg *lap_msg) 755219820Sjeff{ 756219820Sjeff return lap_msg->offset63 >> 3; 757219820Sjeff} 758219820Sjeff 759219820Sjeffstatic inline void cm_lap_set_local_ack_timeout(struct cm_lap_msg *lap_msg, 760219820Sjeff u8 local_ack_timeout) 761219820Sjeff{ 762219820Sjeff lap_msg->offset63 = (local_ack_timeout << 3) | 763219820Sjeff (lap_msg->offset63 & 0x07); 764219820Sjeff} 765219820Sjeff 766219820Sjeffstruct cm_apr_msg { 767219820Sjeff struct ib_mad_hdr hdr; 768219820Sjeff 769219820Sjeff __be32 local_comm_id; 770219820Sjeff __be32 remote_comm_id; 771219820Sjeff 772219820Sjeff u8 info_length; 773219820Sjeff u8 ap_status; 774219820Sjeff u8 info[IB_CM_APR_INFO_LENGTH]; 775219820Sjeff 776219820Sjeff u8 private_data[IB_CM_APR_PRIVATE_DATA_SIZE]; 777219820Sjeff} __attribute__ ((packed)); 778219820Sjeff 779219820Sjeffstruct cm_sidr_req_msg { 780219820Sjeff struct ib_mad_hdr hdr; 781219820Sjeff 782219820Sjeff __be32 request_id; 783219820Sjeff __be16 pkey; 784219820Sjeff __be16 rsvd; 785219820Sjeff __be64 service_id; 786219820Sjeff 787219820Sjeff u8 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE]; 788219820Sjeff} __attribute__ ((packed)); 789219820Sjeff 790219820Sjeffstruct cm_sidr_rep_msg { 791219820Sjeff struct ib_mad_hdr hdr; 792219820Sjeff 793219820Sjeff __be32 request_id; 794219820Sjeff u8 status; 795219820Sjeff u8 info_length; 796219820Sjeff __be16 rsvd; 797219820Sjeff /* QPN:24, rsvd:8 */ 798219820Sjeff __be32 offset8; 799219820Sjeff __be64 service_id; 800219820Sjeff __be32 qkey; 801219820Sjeff u8 info[IB_CM_SIDR_REP_INFO_LENGTH]; 802219820Sjeff 803219820Sjeff u8 private_data[IB_CM_SIDR_REP_PRIVATE_DATA_SIZE]; 804219820Sjeff} __attribute__ ((packed)); 805219820Sjeff 806219820Sjeffstatic inline __be32 cm_sidr_rep_get_qpn(struct cm_sidr_rep_msg *sidr_rep_msg) 807219820Sjeff{ 808219820Sjeff return cpu_to_be32(be32_to_cpu(sidr_rep_msg->offset8) >> 8); 809219820Sjeff} 810219820Sjeff 811219820Sjeffstatic inline void cm_sidr_rep_set_qpn(struct cm_sidr_rep_msg *sidr_rep_msg, 812219820Sjeff __be32 qpn) 813219820Sjeff{ 814219820Sjeff sidr_rep_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) | 815219820Sjeff (be32_to_cpu(sidr_rep_msg->offset8) & 816219820Sjeff 0x000000FF)); 817219820Sjeff} 818219820Sjeff 819219820Sjeff#endif /* CM_MSGS_H */ 820