ib_mad.h revision 331769
1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved. 3219820Sjeff * Copyright (c) 2004 Infinicon Corporation. All rights reserved. 4219820Sjeff * Copyright (c) 2004 Intel Corporation. All rights reserved. 5219820Sjeff * Copyright (c) 2004 Topspin Corporation. All rights reserved. 6219820Sjeff * Copyright (c) 2004-2006 Voltaire Corporation. All rights reserved. 7219820Sjeff * 8219820Sjeff * This software is available to you under a choice of one of two 9219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 10219820Sjeff * General Public License (GPL) Version 2, available from the file 11219820Sjeff * COPYING in the main directory of this source tree, or the 12219820Sjeff * OpenIB.org BSD license below: 13219820Sjeff * 14219820Sjeff * Redistribution and use in source and binary forms, with or 15219820Sjeff * without modification, are permitted provided that the following 16219820Sjeff * conditions are met: 17219820Sjeff * 18219820Sjeff * - Redistributions of source code must retain the above 19219820Sjeff * copyright notice, this list of conditions and the following 20219820Sjeff * disclaimer. 21219820Sjeff * 22219820Sjeff * - Redistributions in binary form must reproduce the above 23219820Sjeff * copyright notice, this list of conditions and the following 24219820Sjeff * disclaimer in the documentation and/or other materials 25219820Sjeff * provided with the distribution. 26219820Sjeff * 27219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 30219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 31219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 32219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 33219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 34219820Sjeff * SOFTWARE. 35219820Sjeff */ 36219820Sjeff 37219820Sjeff#if !defined(IB_MAD_H) 38219820Sjeff#define IB_MAD_H 39219820Sjeff 40219820Sjeff#include <linux/list.h> 41219820Sjeff 42219820Sjeff#include <rdma/ib_verbs.h> 43331769Shselasky#include <rdma/ib_user_mad.h> 44219820Sjeff 45331769Shselasky/* Management base versions */ 46219820Sjeff#define IB_MGMT_BASE_VERSION 1 47331769Shselasky#define OPA_MGMT_BASE_VERSION 0x80 48219820Sjeff 49331769Shselasky#define OPA_SMP_CLASS_VERSION 0x80 50331769Shselasky 51219820Sjeff/* Management classes */ 52219820Sjeff#define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01 53219820Sjeff#define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81 54219820Sjeff#define IB_MGMT_CLASS_SUBN_ADM 0x03 55219820Sjeff#define IB_MGMT_CLASS_PERF_MGMT 0x04 56219820Sjeff#define IB_MGMT_CLASS_BM 0x05 57219820Sjeff#define IB_MGMT_CLASS_DEVICE_MGMT 0x06 58219820Sjeff#define IB_MGMT_CLASS_CM 0x07 59219820Sjeff#define IB_MGMT_CLASS_SNMP 0x08 60219820Sjeff#define IB_MGMT_CLASS_DEVICE_ADM 0x10 61219820Sjeff#define IB_MGMT_CLASS_BOOT_MGMT 0x11 62219820Sjeff#define IB_MGMT_CLASS_BIS 0x12 63219820Sjeff#define IB_MGMT_CLASS_CONG_MGMT 0x21 64219820Sjeff#define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30 65219820Sjeff#define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F 66219820Sjeff 67219820Sjeff#define IB_OPENIB_OUI (0x001405) 68219820Sjeff 69219820Sjeff/* Management methods */ 70219820Sjeff#define IB_MGMT_METHOD_GET 0x01 71219820Sjeff#define IB_MGMT_METHOD_SET 0x02 72219820Sjeff#define IB_MGMT_METHOD_GET_RESP 0x81 73219820Sjeff#define IB_MGMT_METHOD_SEND 0x03 74219820Sjeff#define IB_MGMT_METHOD_TRAP 0x05 75219820Sjeff#define IB_MGMT_METHOD_REPORT 0x06 76219820Sjeff#define IB_MGMT_METHOD_REPORT_RESP 0x86 77219820Sjeff#define IB_MGMT_METHOD_TRAP_REPRESS 0x07 78219820Sjeff 79219820Sjeff#define IB_MGMT_METHOD_RESP 0x80 80219820Sjeff#define IB_BM_ATTR_MOD_RESP cpu_to_be32(1) 81219820Sjeff 82219820Sjeff#define IB_MGMT_MAX_METHODS 128 83219820Sjeff 84278886Shselasky/* MAD Status field bit masks */ 85278886Shselasky#define IB_MGMT_MAD_STATUS_SUCCESS 0x0000 86278886Shselasky#define IB_MGMT_MAD_STATUS_BUSY 0x0001 87278886Shselasky#define IB_MGMT_MAD_STATUS_REDIRECT_REQD 0x0002 88278886Shselasky#define IB_MGMT_MAD_STATUS_BAD_VERSION 0x0004 89278886Shselasky#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD 0x0008 90278886Shselasky#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB 0x000c 91278886Shselasky#define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE 0x001c 92278886Shselasky 93219820Sjeff/* RMPP information */ 94219820Sjeff#define IB_MGMT_RMPP_VERSION 1 95219820Sjeff 96219820Sjeff#define IB_MGMT_RMPP_TYPE_DATA 1 97219820Sjeff#define IB_MGMT_RMPP_TYPE_ACK 2 98219820Sjeff#define IB_MGMT_RMPP_TYPE_STOP 3 99219820Sjeff#define IB_MGMT_RMPP_TYPE_ABORT 4 100219820Sjeff 101219820Sjeff#define IB_MGMT_RMPP_FLAG_ACTIVE 1 102219820Sjeff#define IB_MGMT_RMPP_FLAG_FIRST (1<<1) 103219820Sjeff#define IB_MGMT_RMPP_FLAG_LAST (1<<2) 104219820Sjeff 105219820Sjeff#define IB_MGMT_RMPP_NO_RESPTIME 0x1F 106219820Sjeff 107219820Sjeff#define IB_MGMT_RMPP_STATUS_SUCCESS 0 108219820Sjeff#define IB_MGMT_RMPP_STATUS_RESX 1 109219820Sjeff#define IB_MGMT_RMPP_STATUS_ABORT_MIN 118 110219820Sjeff#define IB_MGMT_RMPP_STATUS_T2L 118 111219820Sjeff#define IB_MGMT_RMPP_STATUS_BAD_LEN 119 112219820Sjeff#define IB_MGMT_RMPP_STATUS_BAD_SEG 120 113219820Sjeff#define IB_MGMT_RMPP_STATUS_BADT 121 114219820Sjeff#define IB_MGMT_RMPP_STATUS_W2S 122 115219820Sjeff#define IB_MGMT_RMPP_STATUS_S2B 123 116219820Sjeff#define IB_MGMT_RMPP_STATUS_BAD_STATUS 124 117219820Sjeff#define IB_MGMT_RMPP_STATUS_UNV 125 118219820Sjeff#define IB_MGMT_RMPP_STATUS_TMR 126 119219820Sjeff#define IB_MGMT_RMPP_STATUS_UNSPEC 127 120219820Sjeff#define IB_MGMT_RMPP_STATUS_ABORT_MAX 127 121219820Sjeff 122219820Sjeff#define IB_QP0 0 123219820Sjeff#define IB_QP1 cpu_to_be32(1) 124219820Sjeff#define IB_QP1_QKEY 0x80010000 125219820Sjeff#define IB_QP_SET_QKEY 0x80000000 126219820Sjeff 127219820Sjeff#define IB_DEFAULT_PKEY_PARTIAL 0x7FFF 128219820Sjeff#define IB_DEFAULT_PKEY_FULL 0xFFFF 129219820Sjeff 130331769Shselasky/* 131331769Shselasky * Generic trap/notice types 132331769Shselasky */ 133331769Shselasky#define IB_NOTICE_TYPE_FATAL 0x80 134331769Shselasky#define IB_NOTICE_TYPE_URGENT 0x81 135331769Shselasky#define IB_NOTICE_TYPE_SECURITY 0x82 136331769Shselasky#define IB_NOTICE_TYPE_SM 0x83 137331769Shselasky#define IB_NOTICE_TYPE_INFO 0x84 138331769Shselasky 139331769Shselasky/* 140331769Shselasky * Generic trap/notice producers 141331769Shselasky */ 142331769Shselasky#define IB_NOTICE_PROD_CA cpu_to_be16(1) 143331769Shselasky#define IB_NOTICE_PROD_SWITCH cpu_to_be16(2) 144331769Shselasky#define IB_NOTICE_PROD_ROUTER cpu_to_be16(3) 145331769Shselasky#define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16(4) 146331769Shselasky 147219820Sjeffenum { 148219820Sjeff IB_MGMT_MAD_HDR = 24, 149219820Sjeff IB_MGMT_MAD_DATA = 232, 150219820Sjeff IB_MGMT_RMPP_HDR = 36, 151219820Sjeff IB_MGMT_RMPP_DATA = 220, 152219820Sjeff IB_MGMT_VENDOR_HDR = 40, 153219820Sjeff IB_MGMT_VENDOR_DATA = 216, 154219820Sjeff IB_MGMT_SA_HDR = 56, 155219820Sjeff IB_MGMT_SA_DATA = 200, 156219820Sjeff IB_MGMT_DEVICE_HDR = 64, 157219820Sjeff IB_MGMT_DEVICE_DATA = 192, 158325604Shselasky IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA, 159331769Shselasky OPA_MGMT_MAD_DATA = 2024, 160331769Shselasky OPA_MGMT_RMPP_DATA = 2012, 161331769Shselasky OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA, 162219820Sjeff}; 163219820Sjeff 164219820Sjeffstruct ib_mad_hdr { 165219820Sjeff u8 base_version; 166219820Sjeff u8 mgmt_class; 167219820Sjeff u8 class_version; 168219820Sjeff u8 method; 169219820Sjeff __be16 status; 170219820Sjeff __be16 class_specific; 171219820Sjeff __be64 tid; 172219820Sjeff __be16 attr_id; 173219820Sjeff __be16 resv; 174219820Sjeff __be32 attr_mod; 175219820Sjeff}; 176219820Sjeff 177219820Sjeffstruct ib_rmpp_hdr { 178219820Sjeff u8 rmpp_version; 179219820Sjeff u8 rmpp_type; 180219820Sjeff u8 rmpp_rtime_flags; 181219820Sjeff u8 rmpp_status; 182219820Sjeff __be32 seg_num; 183219820Sjeff __be32 paylen_newwin; 184219820Sjeff}; 185219820Sjeff 186219820Sjefftypedef u64 __bitwise ib_sa_comp_mask; 187219820Sjeff 188255932Salfred#define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n))) 189219820Sjeff 190219820Sjeff/* 191219820Sjeff * ib_sa_hdr and ib_sa_mad structures must be packed because they have 192219820Sjeff * 64-bit fields that are only 32-bit aligned. 64-bit architectures will 193219820Sjeff * lay them out wrong otherwise. (And unfortunately they are sent on 194219820Sjeff * the wire so we can't change the layout) 195219820Sjeff */ 196219820Sjeffstruct ib_sa_hdr { 197219820Sjeff __be64 sm_key; 198219820Sjeff __be16 attr_offset; 199219820Sjeff __be16 reserved; 200219820Sjeff ib_sa_comp_mask comp_mask; 201219820Sjeff} __attribute__ ((packed)); 202219820Sjeff 203219820Sjeffstruct ib_mad { 204219820Sjeff struct ib_mad_hdr mad_hdr; 205219820Sjeff u8 data[IB_MGMT_MAD_DATA]; 206219820Sjeff}; 207219820Sjeff 208331769Shselaskystruct opa_mad { 209331769Shselasky struct ib_mad_hdr mad_hdr; 210331769Shselasky u8 data[OPA_MGMT_MAD_DATA]; 211331769Shselasky}; 212331769Shselasky 213219820Sjeffstruct ib_rmpp_mad { 214219820Sjeff struct ib_mad_hdr mad_hdr; 215219820Sjeff struct ib_rmpp_hdr rmpp_hdr; 216219820Sjeff u8 data[IB_MGMT_RMPP_DATA]; 217219820Sjeff}; 218219820Sjeff 219331769Shselaskystruct opa_rmpp_mad { 220331769Shselasky struct ib_mad_hdr mad_hdr; 221331769Shselasky struct ib_rmpp_hdr rmpp_hdr; 222331769Shselasky u8 data[OPA_MGMT_RMPP_DATA]; 223331769Shselasky}; 224331769Shselasky 225219820Sjeffstruct ib_sa_mad { 226219820Sjeff struct ib_mad_hdr mad_hdr; 227219820Sjeff struct ib_rmpp_hdr rmpp_hdr; 228219820Sjeff struct ib_sa_hdr sa_hdr; 229219820Sjeff u8 data[IB_MGMT_SA_DATA]; 230219820Sjeff} __attribute__ ((packed)); 231219820Sjeff 232219820Sjeffstruct ib_vendor_mad { 233219820Sjeff struct ib_mad_hdr mad_hdr; 234219820Sjeff struct ib_rmpp_hdr rmpp_hdr; 235219820Sjeff u8 reserved; 236219820Sjeff u8 oui[3]; 237219820Sjeff u8 data[IB_MGMT_VENDOR_DATA]; 238219820Sjeff}; 239219820Sjeff 240331769Shselasky#define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001) 241331769Shselasky 242331769Shselasky#define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F 243331769Shselasky#define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5 244331769Shselasky 245219820Sjeffstruct ib_class_port_info { 246219820Sjeff u8 base_version; 247219820Sjeff u8 class_version; 248219820Sjeff __be16 capability_mask; 249331769Shselasky /* 27 bits for cap_mask2, 5 bits for resp_time */ 250331769Shselasky __be32 cap_mask2_resp_time; 251219820Sjeff u8 redirect_gid[16]; 252219820Sjeff __be32 redirect_tcslfl; 253219820Sjeff __be16 redirect_lid; 254219820Sjeff __be16 redirect_pkey; 255219820Sjeff __be32 redirect_qp; 256219820Sjeff __be32 redirect_qkey; 257219820Sjeff u8 trap_gid[16]; 258219820Sjeff __be32 trap_tcslfl; 259219820Sjeff __be16 trap_lid; 260219820Sjeff __be16 trap_pkey; 261219820Sjeff __be32 trap_hlqp; 262219820Sjeff __be32 trap_qkey; 263219820Sjeff}; 264219820Sjeff 265219820Sjeff/** 266331769Shselasky * ib_get_cpi_resp_time - Returns the resp_time value from 267331769Shselasky * cap_mask2_resp_time in ib_class_port_info. 268331769Shselasky * @cpi: A struct ib_class_port_info mad. 269331769Shselasky */ 270331769Shselaskystatic inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi) 271331769Shselasky{ 272331769Shselasky return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) & 273331769Shselasky IB_CLASS_PORT_INFO_RESP_TIME_MASK); 274331769Shselasky} 275331769Shselasky 276331769Shselasky/** 277331769Shselasky * ib_set_cpi_resptime - Sets the response time in an 278331769Shselasky * ib_class_port_info mad. 279331769Shselasky * @cpi: A struct ib_class_port_info. 280331769Shselasky * @rtime: The response time to set. 281331769Shselasky */ 282331769Shselaskystatic inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi, 283331769Shselasky u8 rtime) 284331769Shselasky{ 285331769Shselasky cpi->cap_mask2_resp_time = 286331769Shselasky (cpi->cap_mask2_resp_time & 287331769Shselasky cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) | 288331769Shselasky cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK); 289331769Shselasky} 290331769Shselasky 291331769Shselasky/** 292331769Shselasky * ib_get_cpi_capmask2 - Returns the capmask2 value from 293331769Shselasky * cap_mask2_resp_time in ib_class_port_info. 294331769Shselasky * @cpi: A struct ib_class_port_info mad. 295331769Shselasky */ 296331769Shselaskystatic inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi) 297331769Shselasky{ 298331769Shselasky return (be32_to_cpu(cpi->cap_mask2_resp_time) >> 299331769Shselasky IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE); 300331769Shselasky} 301331769Shselasky 302331769Shselasky/** 303331769Shselasky * ib_set_cpi_capmask2 - Sets the capmask2 in an 304331769Shselasky * ib_class_port_info mad. 305331769Shselasky * @cpi: A struct ib_class_port_info. 306331769Shselasky * @capmask2: The capmask2 to set. 307331769Shselasky */ 308331769Shselaskystatic inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi, 309331769Shselasky u32 capmask2) 310331769Shselasky{ 311331769Shselasky cpi->cap_mask2_resp_time = 312331769Shselasky (cpi->cap_mask2_resp_time & 313331769Shselasky cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) | 314331769Shselasky cpu_to_be32(capmask2 << 315331769Shselasky IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE); 316331769Shselasky} 317331769Shselasky 318331769Shselaskystruct ib_mad_notice_attr { 319331769Shselasky u8 generic_type; 320331769Shselasky u8 prod_type_msb; 321331769Shselasky __be16 prod_type_lsb; 322331769Shselasky __be16 trap_num; 323331769Shselasky __be16 issuer_lid; 324331769Shselasky __be16 toggle_count; 325331769Shselasky 326331769Shselasky union { 327331769Shselasky struct { 328331769Shselasky u8 details[54]; 329331769Shselasky } raw_data; 330331769Shselasky 331331769Shselasky struct { 332331769Shselasky __be16 reserved; 333331769Shselasky __be16 lid; /* where violation happened */ 334331769Shselasky u8 port_num; /* where violation happened */ 335331769Shselasky } __packed ntc_129_131; 336331769Shselasky 337331769Shselasky struct { 338331769Shselasky __be16 reserved; 339331769Shselasky __be16 lid; /* LID where change occurred */ 340331769Shselasky u8 reserved2; 341331769Shselasky u8 local_changes; /* low bit - local changes */ 342331769Shselasky __be32 new_cap_mask; /* new capability mask */ 343331769Shselasky u8 reserved3; 344331769Shselasky u8 change_flags; /* low 3 bits only */ 345331769Shselasky } __packed ntc_144; 346331769Shselasky 347331769Shselasky struct { 348331769Shselasky __be16 reserved; 349331769Shselasky __be16 lid; /* lid where sys guid changed */ 350331769Shselasky __be16 reserved2; 351331769Shselasky __be64 new_sys_guid; 352331769Shselasky } __packed ntc_145; 353331769Shselasky 354331769Shselasky struct { 355331769Shselasky __be16 reserved; 356331769Shselasky __be16 lid; 357331769Shselasky __be16 dr_slid; 358331769Shselasky u8 method; 359331769Shselasky u8 reserved2; 360331769Shselasky __be16 attr_id; 361331769Shselasky __be32 attr_mod; 362331769Shselasky __be64 mkey; 363331769Shselasky u8 reserved3; 364331769Shselasky u8 dr_trunc_hop; 365331769Shselasky u8 dr_rtn_path[30]; 366331769Shselasky } __packed ntc_256; 367331769Shselasky 368331769Shselasky struct { 369331769Shselasky __be16 reserved; 370331769Shselasky __be16 lid1; 371331769Shselasky __be16 lid2; 372331769Shselasky __be32 key; 373331769Shselasky __be32 sl_qp1; /* SL: high 4 bits */ 374331769Shselasky __be32 qp2; /* high 8 bits reserved */ 375331769Shselasky union ib_gid gid1; 376331769Shselasky union ib_gid gid2; 377331769Shselasky } __packed ntc_257_258; 378331769Shselasky 379331769Shselasky } details; 380331769Shselasky}; 381331769Shselasky 382331769Shselasky/** 383219820Sjeff * ib_mad_send_buf - MAD data buffer and work request for sends. 384219820Sjeff * @next: A pointer used to chain together MADs for posting. 385219820Sjeff * @mad: References an allocated MAD data buffer for MADs that do not have 386219820Sjeff * RMPP active. For MADs using RMPP, references the common and management 387219820Sjeff * class specific headers. 388219820Sjeff * @mad_agent: MAD agent that allocated the buffer. 389219820Sjeff * @ah: The address handle to use when sending the MAD. 390219820Sjeff * @context: User-controlled context fields. 391219820Sjeff * @hdr_len: Indicates the size of the data header of the MAD. This length 392219820Sjeff * includes the common MAD, RMPP, and class specific headers. 393219820Sjeff * @data_len: Indicates the total size of user-transferred data. 394219820Sjeff * @seg_count: The number of RMPP segments allocated for this send. 395331769Shselasky * @seg_size: Size of the data in each RMPP segment. This does not include 396331769Shselasky * class specific headers. 397331769Shselasky * @seg_rmpp_size: Size of each RMPP segment including the class specific 398331769Shselasky * headers. 399219820Sjeff * @timeout_ms: Time to wait for a response. 400219820Sjeff * @retries: Number of times to retry a request for a response. For MADs 401219820Sjeff * using RMPP, this applies per window. On completion, returns the number 402219820Sjeff * of retries needed to complete the transfer. 403219820Sjeff * 404219820Sjeff * Users are responsible for initializing the MAD buffer itself, with the 405219820Sjeff * exception of any RMPP header. Additional segment buffer space allocated 406219820Sjeff * beyond data_len is padding. 407219820Sjeff */ 408219820Sjeffstruct ib_mad_send_buf { 409219820Sjeff struct ib_mad_send_buf *next; 410219820Sjeff void *mad; 411219820Sjeff struct ib_mad_agent *mad_agent; 412219820Sjeff struct ib_ah *ah; 413219820Sjeff void *context[2]; 414219820Sjeff int hdr_len; 415219820Sjeff int data_len; 416219820Sjeff int seg_count; 417219820Sjeff int seg_size; 418331769Shselasky int seg_rmpp_size; 419219820Sjeff int timeout_ms; 420219820Sjeff int retries; 421219820Sjeff}; 422219820Sjeff 423219820Sjeff/** 424219820Sjeff * ib_response_mad - Returns if the specified MAD has been generated in 425219820Sjeff * response to a sent request or trap. 426219820Sjeff */ 427331769Shselaskyint ib_response_mad(const struct ib_mad_hdr *hdr); 428219820Sjeff 429219820Sjeff/** 430219820Sjeff * ib_get_rmpp_resptime - Returns the RMPP response time. 431219820Sjeff * @rmpp_hdr: An RMPP header. 432219820Sjeff */ 433219820Sjeffstatic inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr) 434219820Sjeff{ 435219820Sjeff return rmpp_hdr->rmpp_rtime_flags >> 3; 436219820Sjeff} 437219820Sjeff 438219820Sjeff/** 439219820Sjeff * ib_get_rmpp_flags - Returns the RMPP flags. 440219820Sjeff * @rmpp_hdr: An RMPP header. 441219820Sjeff */ 442331769Shselaskystatic inline u8 ib_get_rmpp_flags(const struct ib_rmpp_hdr *rmpp_hdr) 443219820Sjeff{ 444219820Sjeff return rmpp_hdr->rmpp_rtime_flags & 0x7; 445219820Sjeff} 446219820Sjeff 447219820Sjeff/** 448219820Sjeff * ib_set_rmpp_resptime - Sets the response time in an RMPP header. 449219820Sjeff * @rmpp_hdr: An RMPP header. 450219820Sjeff * @rtime: The response time to set. 451219820Sjeff */ 452219820Sjeffstatic inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime) 453219820Sjeff{ 454219820Sjeff rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3); 455219820Sjeff} 456219820Sjeff 457219820Sjeff/** 458219820Sjeff * ib_set_rmpp_flags - Sets the flags in an RMPP header. 459219820Sjeff * @rmpp_hdr: An RMPP header. 460219820Sjeff * @flags: The flags to set. 461219820Sjeff */ 462219820Sjeffstatic inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags) 463219820Sjeff{ 464219820Sjeff rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) | 465219820Sjeff (flags & 0x7); 466219820Sjeff} 467219820Sjeff 468219820Sjeffstruct ib_mad_agent; 469219820Sjeffstruct ib_mad_send_wc; 470219820Sjeffstruct ib_mad_recv_wc; 471219820Sjeff 472219820Sjeff/** 473219820Sjeff * ib_mad_send_handler - callback handler for a sent MAD. 474219820Sjeff * @mad_agent: MAD agent that sent the MAD. 475219820Sjeff * @mad_send_wc: Send work completion information on the sent MAD. 476219820Sjeff */ 477219820Sjefftypedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent, 478219820Sjeff struct ib_mad_send_wc *mad_send_wc); 479219820Sjeff 480219820Sjeff/** 481219820Sjeff * ib_mad_snoop_handler - Callback handler for snooping sent MADs. 482219820Sjeff * @mad_agent: MAD agent that snooped the MAD. 483331769Shselasky * @send_buf: send MAD data buffer. 484219820Sjeff * @mad_send_wc: Work completion information on the sent MAD. Valid 485219820Sjeff * only for snooping that occurs on a send completion. 486219820Sjeff * 487331769Shselasky * Clients snooping MADs should not modify data referenced by the @send_buf 488219820Sjeff * or @mad_send_wc. 489219820Sjeff */ 490219820Sjefftypedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent, 491219820Sjeff struct ib_mad_send_buf *send_buf, 492219820Sjeff struct ib_mad_send_wc *mad_send_wc); 493219820Sjeff 494219820Sjeff/** 495219820Sjeff * ib_mad_recv_handler - callback handler for a received MAD. 496219820Sjeff * @mad_agent: MAD agent requesting the received MAD. 497331769Shselasky * @send_buf: Send buffer if found, else NULL 498219820Sjeff * @mad_recv_wc: Received work completion information on the received MAD. 499219820Sjeff * 500219820Sjeff * MADs received in response to a send request operation will be handed to 501219820Sjeff * the user before the send operation completes. All data buffers given 502219820Sjeff * to registered agents through this routine are owned by the receiving 503219820Sjeff * client, except for snooping agents. Clients snooping MADs should not 504219820Sjeff * modify the data referenced by @mad_recv_wc. 505219820Sjeff */ 506219820Sjefftypedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent, 507331769Shselasky struct ib_mad_send_buf *send_buf, 508219820Sjeff struct ib_mad_recv_wc *mad_recv_wc); 509219820Sjeff 510219820Sjeff/** 511219820Sjeff * ib_mad_agent - Used to track MAD registration with the access layer. 512219820Sjeff * @device: Reference to device registration is on. 513219820Sjeff * @qp: Reference to QP used for sending and receiving MADs. 514219820Sjeff * @mr: Memory region for system memory usable for DMA. 515219820Sjeff * @recv_handler: Callback handler for a received MAD. 516219820Sjeff * @send_handler: Callback handler for a sent MAD. 517219820Sjeff * @snoop_handler: Callback handler for snooped sent MADs. 518219820Sjeff * @context: User-specified context associated with this registration. 519219820Sjeff * @hi_tid: Access layer assigned transaction ID for this client. 520219820Sjeff * Unsolicited MADs sent by this client will have the upper 32-bits 521219820Sjeff * of their TID set to this value. 522331769Shselasky * @flags: registration flags 523219820Sjeff * @port_num: Port number on which QP is registered 524219820Sjeff * @rmpp_version: If set, indicates the RMPP version used by this agent. 525219820Sjeff */ 526331769Shselaskyenum { 527331769Shselasky IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP, 528331769Shselasky}; 529219820Sjeffstruct ib_mad_agent { 530219820Sjeff struct ib_device *device; 531219820Sjeff struct ib_qp *qp; 532219820Sjeff ib_mad_recv_handler recv_handler; 533219820Sjeff ib_mad_send_handler send_handler; 534219820Sjeff ib_mad_snoop_handler snoop_handler; 535219820Sjeff void *context; 536219820Sjeff u32 hi_tid; 537331769Shselasky u32 flags; 538219820Sjeff u8 port_num; 539219820Sjeff u8 rmpp_version; 540219820Sjeff}; 541219820Sjeff 542219820Sjeff/** 543219820Sjeff * ib_mad_send_wc - MAD send completion information. 544219820Sjeff * @send_buf: Send MAD data buffer associated with the send MAD request. 545219820Sjeff * @status: Completion status. 546219820Sjeff * @vendor_err: Optional vendor error information returned with a failed 547219820Sjeff * request. 548219820Sjeff */ 549219820Sjeffstruct ib_mad_send_wc { 550219820Sjeff struct ib_mad_send_buf *send_buf; 551219820Sjeff enum ib_wc_status status; 552219820Sjeff u32 vendor_err; 553219820Sjeff}; 554219820Sjeff 555219820Sjeff/** 556219820Sjeff * ib_mad_recv_buf - received MAD buffer information. 557219820Sjeff * @list: Reference to next data buffer for a received RMPP MAD. 558219820Sjeff * @grh: References a data buffer containing the global route header. 559219820Sjeff * The data refereced by this buffer is only valid if the GRH is 560219820Sjeff * valid. 561219820Sjeff * @mad: References the start of the received MAD. 562219820Sjeff */ 563219820Sjeffstruct ib_mad_recv_buf { 564219820Sjeff struct list_head list; 565219820Sjeff struct ib_grh *grh; 566331769Shselasky union { 567331769Shselasky struct ib_mad *mad; 568331769Shselasky struct opa_mad *opa_mad; 569331769Shselasky }; 570219820Sjeff}; 571219820Sjeff 572219820Sjeff/** 573219820Sjeff * ib_mad_recv_wc - received MAD information. 574219820Sjeff * @wc: Completion information for the received data. 575219820Sjeff * @recv_buf: Specifies the location of the received data buffer(s). 576219820Sjeff * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers. 577219820Sjeff * @mad_len: The length of the received MAD, without duplicated headers. 578331769Shselasky * @mad_seg_size: The size of individual MAD segments 579219820Sjeff * 580219820Sjeff * For received response, the wr_id contains a pointer to the ib_mad_send_buf 581219820Sjeff * for the corresponding send request. 582219820Sjeff */ 583219820Sjeffstruct ib_mad_recv_wc { 584219820Sjeff struct ib_wc *wc; 585219820Sjeff struct ib_mad_recv_buf recv_buf; 586219820Sjeff struct list_head rmpp_list; 587219820Sjeff int mad_len; 588331769Shselasky size_t mad_seg_size; 589219820Sjeff}; 590219820Sjeff 591219820Sjeff/** 592219820Sjeff * ib_mad_reg_req - MAD registration request 593219820Sjeff * @mgmt_class: Indicates which management class of MADs should be receive 594219820Sjeff * by the caller. This field is only required if the user wishes to 595219820Sjeff * receive unsolicited MADs, otherwise it should be 0. 596219820Sjeff * @mgmt_class_version: Indicates which version of MADs for the given 597219820Sjeff * management class to receive. 598219820Sjeff * @oui: Indicates IEEE OUI when mgmt_class is a vendor class 599219820Sjeff * in the range from 0x30 to 0x4f. Otherwise not used. 600219820Sjeff * @method_mask: The caller will receive unsolicited MADs for any method 601219820Sjeff * where @method_mask = 1. 602331769Shselasky * 603219820Sjeff */ 604219820Sjeffstruct ib_mad_reg_req { 605219820Sjeff u8 mgmt_class; 606219820Sjeff u8 mgmt_class_version; 607219820Sjeff u8 oui[3]; 608219820Sjeff DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS); 609219820Sjeff}; 610219820Sjeff 611219820Sjeff/** 612219820Sjeff * ib_register_mad_agent - Register to send/receive MADs. 613219820Sjeff * @device: The device to register with. 614219820Sjeff * @port_num: The port on the specified device to use. 615219820Sjeff * @qp_type: Specifies which QP to access. Must be either 616219820Sjeff * IB_QPT_SMI or IB_QPT_GSI. 617219820Sjeff * @mad_reg_req: Specifies which unsolicited MADs should be received 618219820Sjeff * by the caller. This parameter may be NULL if the caller only 619219820Sjeff * wishes to receive solicited responses. 620219820Sjeff * @rmpp_version: If set, indicates that the client will send 621219820Sjeff * and receive MADs that contain the RMPP header for the given version. 622219820Sjeff * If set to 0, indicates that RMPP is not used by this client. 623219820Sjeff * @send_handler: The completion callback routine invoked after a send 624219820Sjeff * request has completed. 625219820Sjeff * @recv_handler: The completion callback routine invoked for a received 626219820Sjeff * MAD. 627219820Sjeff * @context: User specified context associated with the registration. 628331769Shselasky * @registration_flags: Registration flags to set for this agent 629219820Sjeff */ 630219820Sjeffstruct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, 631219820Sjeff u8 port_num, 632219820Sjeff enum ib_qp_type qp_type, 633219820Sjeff struct ib_mad_reg_req *mad_reg_req, 634219820Sjeff u8 rmpp_version, 635219820Sjeff ib_mad_send_handler send_handler, 636219820Sjeff ib_mad_recv_handler recv_handler, 637331769Shselasky void *context, 638331769Shselasky u32 registration_flags); 639219820Sjeff 640219820Sjeffenum ib_mad_snoop_flags { 641219820Sjeff /*IB_MAD_SNOOP_POSTED_SENDS = 1,*/ 642219820Sjeff /*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/ 643219820Sjeff IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2), 644219820Sjeff /*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/ 645219820Sjeff IB_MAD_SNOOP_RECVS = (1<<4) 646219820Sjeff /*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/ 647219820Sjeff /*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/ 648219820Sjeff}; 649219820Sjeff 650219820Sjeff/** 651219820Sjeff * ib_register_mad_snoop - Register to snoop sent and received MADs. 652219820Sjeff * @device: The device to register with. 653219820Sjeff * @port_num: The port on the specified device to use. 654219820Sjeff * @qp_type: Specifies which QP traffic to snoop. Must be either 655219820Sjeff * IB_QPT_SMI or IB_QPT_GSI. 656219820Sjeff * @mad_snoop_flags: Specifies information where snooping occurs. 657219820Sjeff * @send_handler: The callback routine invoked for a snooped send. 658219820Sjeff * @recv_handler: The callback routine invoked for a snooped receive. 659219820Sjeff * @context: User specified context associated with the registration. 660219820Sjeff */ 661219820Sjeffstruct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device, 662219820Sjeff u8 port_num, 663219820Sjeff enum ib_qp_type qp_type, 664219820Sjeff int mad_snoop_flags, 665219820Sjeff ib_mad_snoop_handler snoop_handler, 666219820Sjeff ib_mad_recv_handler recv_handler, 667219820Sjeff void *context); 668219820Sjeff 669219820Sjeff/** 670219820Sjeff * ib_unregister_mad_agent - Unregisters a client from using MAD services. 671219820Sjeff * @mad_agent: Corresponding MAD registration request to deregister. 672219820Sjeff * 673219820Sjeff * After invoking this routine, MAD services are no longer usable by the 674219820Sjeff * client on the associated QP. 675219820Sjeff */ 676219820Sjeffint ib_unregister_mad_agent(struct ib_mad_agent *mad_agent); 677219820Sjeff 678219820Sjeff/** 679219820Sjeff * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated 680219820Sjeff * with the registered client. 681219820Sjeff * @send_buf: Specifies the information needed to send the MAD(s). 682219820Sjeff * @bad_send_buf: Specifies the MAD on which an error was encountered. This 683219820Sjeff * parameter is optional if only a single MAD is posted. 684219820Sjeff * 685219820Sjeff * Sent MADs are not guaranteed to complete in the order that they were posted. 686219820Sjeff * 687219820Sjeff * If the MAD requires RMPP, the data buffer should contain a single copy 688219820Sjeff * of the common MAD, RMPP, and class specific headers, followed by the class 689219820Sjeff * defined data. If the class defined data would not divide evenly into 690219820Sjeff * RMPP segments, then space must be allocated at the end of the referenced 691219820Sjeff * buffer for any required padding. To indicate the amount of class defined 692219820Sjeff * data being transferred, the paylen_newwin field in the RMPP header should 693219820Sjeff * be set to the size of the class specific header plus the amount of class 694219820Sjeff * defined data being transferred. The paylen_newwin field should be 695219820Sjeff * specified in network-byte order. 696219820Sjeff */ 697219820Sjeffint ib_post_send_mad(struct ib_mad_send_buf *send_buf, 698219820Sjeff struct ib_mad_send_buf **bad_send_buf); 699219820Sjeff 700219820Sjeff 701219820Sjeff/** 702219820Sjeff * ib_free_recv_mad - Returns data buffers used to receive a MAD. 703219820Sjeff * @mad_recv_wc: Work completion information for a received MAD. 704219820Sjeff * 705219820Sjeff * Clients receiving MADs through their ib_mad_recv_handler must call this 706219820Sjeff * routine to return the work completion buffers to the access layer. 707219820Sjeff */ 708219820Sjeffvoid ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc); 709219820Sjeff 710219820Sjeff/** 711219820Sjeff * ib_cancel_mad - Cancels an outstanding send MAD operation. 712219820Sjeff * @mad_agent: Specifies the registration associated with sent MAD. 713219820Sjeff * @send_buf: Indicates the MAD to cancel. 714219820Sjeff * 715219820Sjeff * MADs will be returned to the user through the corresponding 716219820Sjeff * ib_mad_send_handler. 717219820Sjeff */ 718219820Sjeffvoid ib_cancel_mad(struct ib_mad_agent *mad_agent, 719219820Sjeff struct ib_mad_send_buf *send_buf); 720219820Sjeff 721219820Sjeff/** 722219820Sjeff * ib_modify_mad - Modifies an outstanding send MAD operation. 723219820Sjeff * @mad_agent: Specifies the registration associated with sent MAD. 724219820Sjeff * @send_buf: Indicates the MAD to modify. 725219820Sjeff * @timeout_ms: New timeout value for sent MAD. 726219820Sjeff * 727219820Sjeff * This call will reset the timeout value for a sent MAD to the specified 728219820Sjeff * value. 729219820Sjeff */ 730219820Sjeffint ib_modify_mad(struct ib_mad_agent *mad_agent, 731219820Sjeff struct ib_mad_send_buf *send_buf, u32 timeout_ms); 732219820Sjeff 733219820Sjeff/** 734219820Sjeff * ib_redirect_mad_qp - Registers a QP for MAD services. 735219820Sjeff * @qp: Reference to a QP that requires MAD services. 736219820Sjeff * @rmpp_version: If set, indicates that the client will send 737219820Sjeff * and receive MADs that contain the RMPP header for the given version. 738219820Sjeff * If set to 0, indicates that RMPP is not used by this client. 739219820Sjeff * @send_handler: The completion callback routine invoked after a send 740219820Sjeff * request has completed. 741219820Sjeff * @recv_handler: The completion callback routine invoked for a received 742219820Sjeff * MAD. 743219820Sjeff * @context: User specified context associated with the registration. 744219820Sjeff * 745219820Sjeff * Use of this call allows clients to use MAD services, such as RMPP, 746219820Sjeff * on user-owned QPs. After calling this routine, users may send 747219820Sjeff * MADs on the specified QP by calling ib_mad_post_send. 748219820Sjeff */ 749219820Sjeffstruct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp, 750219820Sjeff u8 rmpp_version, 751219820Sjeff ib_mad_send_handler send_handler, 752219820Sjeff ib_mad_recv_handler recv_handler, 753219820Sjeff void *context); 754219820Sjeff 755219820Sjeff/** 756219820Sjeff * ib_process_mad_wc - Processes a work completion associated with a 757219820Sjeff * MAD sent or received on a redirected QP. 758219820Sjeff * @mad_agent: Specifies the registered MAD service using the redirected QP. 759219820Sjeff * @wc: References a work completion associated with a sent or received 760219820Sjeff * MAD segment. 761219820Sjeff * 762219820Sjeff * This routine is used to complete or continue processing on a MAD request. 763219820Sjeff * If the work completion is associated with a send operation, calling 764219820Sjeff * this routine is required to continue an RMPP transfer or to wait for a 765219820Sjeff * corresponding response, if it is a request. If the work completion is 766219820Sjeff * associated with a receive operation, calling this routine is required to 767219820Sjeff * process an inbound or outbound RMPP transfer, or to match a response MAD 768219820Sjeff * with its corresponding request. 769219820Sjeff */ 770219820Sjeffint ib_process_mad_wc(struct ib_mad_agent *mad_agent, 771219820Sjeff struct ib_wc *wc); 772219820Sjeff 773219820Sjeff/** 774219820Sjeff * ib_create_send_mad - Allocate and initialize a data buffer and work request 775219820Sjeff * for sending a MAD. 776219820Sjeff * @mad_agent: Specifies the registered MAD service to associate with the MAD. 777219820Sjeff * @remote_qpn: Specifies the QPN of the receiving node. 778219820Sjeff * @pkey_index: Specifies which PKey the MAD will be sent using. This field 779219820Sjeff * is valid only if the remote_qpn is QP 1. 780219820Sjeff * @rmpp_active: Indicates if the send will enable RMPP. 781219820Sjeff * @hdr_len: Indicates the size of the data header of the MAD. This length 782219820Sjeff * should include the common MAD header, RMPP header, plus any class 783219820Sjeff * specific header. 784219820Sjeff * @data_len: Indicates the size of any user-transferred data. The call will 785219820Sjeff * automatically adjust the allocated buffer size to account for any 786219820Sjeff * additional padding that may be necessary. 787219820Sjeff * @gfp_mask: GFP mask used for the memory allocation. 788331769Shselasky * @base_version: Base Version of this MAD 789219820Sjeff * 790219820Sjeff * This routine allocates a MAD for sending. The returned MAD send buffer 791219820Sjeff * will reference a data buffer usable for sending a MAD, along 792219820Sjeff * with an initialized work request structure. Users may modify the returned 793219820Sjeff * MAD data buffer before posting the send. 794219820Sjeff * 795219820Sjeff * The returned MAD header, class specific headers, and any padding will be 796219820Sjeff * cleared. Users are responsible for initializing the common MAD header, 797219820Sjeff * any class specific header, and MAD data area. 798219820Sjeff * If @rmpp_active is set, the RMPP header will be initialized for sending. 799219820Sjeff */ 800219820Sjeffstruct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent, 801219820Sjeff u32 remote_qpn, u16 pkey_index, 802219820Sjeff int rmpp_active, 803219820Sjeff int hdr_len, int data_len, 804331769Shselasky gfp_t gfp_mask, 805331769Shselasky u8 base_version); 806219820Sjeff 807219820Sjeff/** 808219820Sjeff * ib_is_mad_class_rmpp - returns whether given management class 809219820Sjeff * supports RMPP. 810219820Sjeff * @mgmt_class: management class 811219820Sjeff * 812219820Sjeff * This routine returns whether the management class supports RMPP. 813219820Sjeff */ 814219820Sjeffint ib_is_mad_class_rmpp(u8 mgmt_class); 815219820Sjeff 816219820Sjeff/** 817219820Sjeff * ib_get_mad_data_offset - returns the data offset for a given 818219820Sjeff * management class. 819219820Sjeff * @mgmt_class: management class 820219820Sjeff * 821219820Sjeff * This routine returns the data offset in the MAD for the management 822219820Sjeff * class requested. 823219820Sjeff */ 824219820Sjeffint ib_get_mad_data_offset(u8 mgmt_class); 825219820Sjeff 826219820Sjeff/** 827219820Sjeff * ib_get_rmpp_segment - returns the data buffer for a given RMPP segment. 828219820Sjeff * @send_buf: Previously allocated send data buffer. 829219820Sjeff * @seg_num: number of segment to return 830219820Sjeff * 831219820Sjeff * This routine returns a pointer to the data buffer of an RMPP MAD. 832219820Sjeff * Users must provide synchronization to @send_buf around this call. 833219820Sjeff */ 834219820Sjeffvoid *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num); 835219820Sjeff 836219820Sjeff/** 837219820Sjeff * ib_free_send_mad - Returns data buffers used to send a MAD. 838219820Sjeff * @send_buf: Previously allocated send data buffer. 839219820Sjeff */ 840219820Sjeffvoid ib_free_send_mad(struct ib_mad_send_buf *send_buf); 841219820Sjeff 842331769Shselasky/** 843331769Shselasky * ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP. 844331769Shselasky * @agent: the agent in question 845331769Shselasky * @return: true if agent is performing rmpp, false otherwise. 846331769Shselasky */ 847331769Shselaskyint ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent); 848331769Shselasky 849219820Sjeff#endif /* IB_MAD_H */ 850