/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */1/*2* Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.3* Copyright (c) 2004 Infinicon Corporation. All rights reserved.4* Copyright (c) 2004 Intel Corporation. All rights reserved.5* Copyright (c) 2004 Topspin Corporation. All rights reserved.6* Copyright (c) 2004-2006 Voltaire Corporation. All rights reserved.7*/89#ifndef IB_MAD_H10#define IB_MAD_H1112#include <linux/list.h>1314#include <rdma/ib_verbs.h>15#include <uapi/rdma/ib_user_mad.h>1617/* Management base versions */18#define IB_MGMT_BASE_VERSION 119#define OPA_MGMT_BASE_VERSION 0x802021#define OPA_SM_CLASS_VERSION 0x802223/* Management classes */24#define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x0125#define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x8126#define IB_MGMT_CLASS_SUBN_ADM 0x0327#define IB_MGMT_CLASS_PERF_MGMT 0x0428#define IB_MGMT_CLASS_BM 0x0529#define IB_MGMT_CLASS_DEVICE_MGMT 0x0630#define IB_MGMT_CLASS_CM 0x0731#define IB_MGMT_CLASS_SNMP 0x0832#define IB_MGMT_CLASS_DEVICE_ADM 0x1033#define IB_MGMT_CLASS_BOOT_MGMT 0x1134#define IB_MGMT_CLASS_BIS 0x1235#define IB_MGMT_CLASS_CONG_MGMT 0x2136#define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x3037#define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F3839#define IB_OPENIB_OUI (0x001405)4041/* Management methods */42#define IB_MGMT_METHOD_GET 0x0143#define IB_MGMT_METHOD_SET 0x0244#define IB_MGMT_METHOD_GET_RESP 0x8145#define IB_MGMT_METHOD_SEND 0x0346#define IB_MGMT_METHOD_TRAP 0x0547#define IB_MGMT_METHOD_REPORT 0x0648#define IB_MGMT_METHOD_REPORT_RESP 0x8649#define IB_MGMT_METHOD_TRAP_REPRESS 0x0750#define IB_MGMT_METHOD_GET_TABLE 0x125152#define IB_MGMT_METHOD_RESP 0x8053#define IB_BM_ATTR_MOD_RESP cpu_to_be32(1)5455#define IB_MGMT_MAX_METHODS 1285657/* MAD Status field bit masks */58#define IB_MGMT_MAD_STATUS_SUCCESS 0x000059#define IB_MGMT_MAD_STATUS_BUSY 0x000160#define IB_MGMT_MAD_STATUS_REDIRECT_REQD 0x000261#define IB_MGMT_MAD_STATUS_BAD_VERSION 0x000462#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD 0x000863#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB 0x000c64#define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE 0x001c6566/* RMPP information */67#define IB_MGMT_RMPP_VERSION 16869#define IB_MGMT_RMPP_TYPE_DATA 170#define IB_MGMT_RMPP_TYPE_ACK 271#define IB_MGMT_RMPP_TYPE_STOP 372#define IB_MGMT_RMPP_TYPE_ABORT 47374#define IB_MGMT_RMPP_FLAG_ACTIVE 175#define IB_MGMT_RMPP_FLAG_FIRST (1<<1)76#define IB_MGMT_RMPP_FLAG_LAST (1<<2)7778#define IB_MGMT_RMPP_NO_RESPTIME 0x1F7980#define IB_MGMT_RMPP_STATUS_SUCCESS 081#define IB_MGMT_RMPP_STATUS_RESX 182#define IB_MGMT_RMPP_STATUS_ABORT_MIN 11883#define IB_MGMT_RMPP_STATUS_T2L 11884#define IB_MGMT_RMPP_STATUS_BAD_LEN 11985#define IB_MGMT_RMPP_STATUS_BAD_SEG 12086#define IB_MGMT_RMPP_STATUS_BADT 12187#define IB_MGMT_RMPP_STATUS_W2S 12288#define IB_MGMT_RMPP_STATUS_S2B 12389#define IB_MGMT_RMPP_STATUS_BAD_STATUS 12490#define IB_MGMT_RMPP_STATUS_UNV 12591#define IB_MGMT_RMPP_STATUS_TMR 12692#define IB_MGMT_RMPP_STATUS_UNSPEC 12793#define IB_MGMT_RMPP_STATUS_ABORT_MAX 1279495#define IB_QP0 096#define IB_QP1 cpu_to_be32(1)97#define IB_QP1_QKEY 0x8001000098#define IB_QP_SET_QKEY 0x8000000099100#define IB_DEFAULT_PKEY_PARTIAL 0x7FFF101#define IB_DEFAULT_PKEY_FULL 0xFFFF102103/*104* Generic trap/notice types105*/106#define IB_NOTICE_TYPE_FATAL 0x80107#define IB_NOTICE_TYPE_URGENT 0x81108#define IB_NOTICE_TYPE_SECURITY 0x82109#define IB_NOTICE_TYPE_SM 0x83110#define IB_NOTICE_TYPE_INFO 0x84111112/*113* Generic trap/notice producers114*/115#define IB_NOTICE_PROD_CA cpu_to_be16(1)116#define IB_NOTICE_PROD_SWITCH cpu_to_be16(2)117#define IB_NOTICE_PROD_ROUTER cpu_to_be16(3)118#define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16(4)119120enum {121IB_MGMT_MAD_HDR = 24,122IB_MGMT_MAD_DATA = 232,123IB_MGMT_RMPP_HDR = 36,124IB_MGMT_RMPP_DATA = 220,125IB_MGMT_VENDOR_HDR = 40,126IB_MGMT_VENDOR_DATA = 216,127IB_MGMT_SA_HDR = 56,128IB_MGMT_SA_DATA = 200,129IB_MGMT_DEVICE_HDR = 64,130IB_MGMT_DEVICE_DATA = 192,131IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,132OPA_MGMT_MAD_DATA = 2024,133OPA_MGMT_RMPP_DATA = 2012,134OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,135};136137struct ib_mad_hdr {138u8 base_version;139u8 mgmt_class;140u8 class_version;141u8 method;142__be16 status;143__be16 class_specific;144__be64 tid;145__be16 attr_id;146__be16 resv;147__be32 attr_mod;148};149150struct ib_rmpp_hdr {151u8 rmpp_version;152u8 rmpp_type;153u8 rmpp_rtime_flags;154u8 rmpp_status;155__be32 seg_num;156__be32 paylen_newwin;157};158159typedef u64 __bitwise ib_sa_comp_mask;160161#define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))162163/*164* ib_sa_hdr and ib_sa_mad structures must be packed because they have165* 64-bit fields that are only 32-bit aligned. 64-bit architectures will166* lay them out wrong otherwise. (And unfortunately they are sent on167* the wire so we can't change the layout)168*/169struct ib_sa_hdr {170__be64 sm_key;171__be16 attr_offset;172__be16 reserved;173ib_sa_comp_mask comp_mask;174} __packed;175176struct ib_mad {177struct ib_mad_hdr mad_hdr;178u8 data[IB_MGMT_MAD_DATA];179};180181struct opa_mad {182struct ib_mad_hdr mad_hdr;183u8 data[OPA_MGMT_MAD_DATA];184};185186struct ib_rmpp_mad {187struct ib_mad_hdr mad_hdr;188struct ib_rmpp_hdr rmpp_hdr;189u8 data[IB_MGMT_RMPP_DATA];190};191192struct opa_rmpp_mad {193struct ib_mad_hdr mad_hdr;194struct ib_rmpp_hdr rmpp_hdr;195u8 data[OPA_MGMT_RMPP_DATA];196};197198struct ib_sa_mad {199struct ib_mad_hdr mad_hdr;200struct ib_rmpp_hdr rmpp_hdr;201struct ib_sa_hdr sa_hdr;202u8 data[IB_MGMT_SA_DATA];203} __packed;204205struct ib_vendor_mad {206struct ib_mad_hdr mad_hdr;207struct ib_rmpp_hdr rmpp_hdr;208u8 reserved;209u8 oui[3];210u8 data[IB_MGMT_VENDOR_DATA];211};212213#define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001)214215#define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F216#define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5217218struct ib_class_port_info {219u8 base_version;220u8 class_version;221__be16 capability_mask;222/* 27 bits for cap_mask2, 5 bits for resp_time */223__be32 cap_mask2_resp_time;224u8 redirect_gid[16];225__be32 redirect_tcslfl;226__be16 redirect_lid;227__be16 redirect_pkey;228__be32 redirect_qp;229__be32 redirect_qkey;230u8 trap_gid[16];231__be32 trap_tcslfl;232__be16 trap_lid;233__be16 trap_pkey;234__be32 trap_hlqp;235__be32 trap_qkey;236};237238/* PortInfo CapabilityMask */239enum ib_port_capability_mask_bits {240IB_PORT_SM = 1 << 1,241IB_PORT_NOTICE_SUP = 1 << 2,242IB_PORT_TRAP_SUP = 1 << 3,243IB_PORT_OPT_IPD_SUP = 1 << 4,244IB_PORT_AUTO_MIGR_SUP = 1 << 5,245IB_PORT_SL_MAP_SUP = 1 << 6,246IB_PORT_MKEY_NVRAM = 1 << 7,247IB_PORT_PKEY_NVRAM = 1 << 8,248IB_PORT_LED_INFO_SUP = 1 << 9,249IB_PORT_SM_DISABLED = 1 << 10,250IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,251IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,252IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,253IB_PORT_CAP_MASK2_SUP = 1 << 15,254IB_PORT_CM_SUP = 1 << 16,255IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,256IB_PORT_REINIT_SUP = 1 << 18,257IB_PORT_DEVICE_MGMT_SUP = 1 << 19,258IB_PORT_VENDOR_CLASS_SUP = 1 << 20,259IB_PORT_DR_NOTICE_SUP = 1 << 21,260IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,261IB_PORT_BOOT_MGMT_SUP = 1 << 23,262IB_PORT_LINK_LATENCY_SUP = 1 << 24,263IB_PORT_CLIENT_REG_SUP = 1 << 25,264IB_PORT_OTHER_LOCAL_CHANGES_SUP = 1 << 26,265IB_PORT_LINK_SPEED_WIDTH_TABLE_SUP = 1 << 27,266IB_PORT_VENDOR_SPECIFIC_MADS_TABLE_SUP = 1 << 28,267IB_PORT_MCAST_PKEY_TRAP_SUPPRESSION_SUP = 1 << 29,268IB_PORT_MCAST_FDB_TOP_SUP = 1 << 30,269IB_PORT_HIERARCHY_INFO_SUP = 1ULL << 31,270};271272enum ib_port_capability_mask2_bits {273IB_PORT_SET_NODE_DESC_SUP = 1 << 0,274IB_PORT_EX_PORT_INFO_EX_SUP = 1 << 1,275IB_PORT_VIRT_SUP = 1 << 2,276IB_PORT_SWITCH_PORT_STATE_TABLE_SUP = 1 << 3,277IB_PORT_LINK_WIDTH_2X_SUP = 1 << 4,278IB_PORT_LINK_SPEED_HDR_SUP = 1 << 5,279IB_PORT_LINK_SPEED_NDR_SUP = 1 << 10,280IB_PORT_EXTENDED_SPEEDS2_SUP = 1 << 11,281IB_PORT_LINK_SPEED_XDR_SUP = 1 << 12,282};283284#define OPA_CLASS_PORT_INFO_PR_SUPPORT BIT(26)285286struct opa_class_port_info {287u8 base_version;288u8 class_version;289__be16 cap_mask;290__be32 cap_mask2_resp_time;291292u8 redirect_gid[16];293__be32 redirect_tc_fl;294__be32 redirect_lid;295__be32 redirect_sl_qp;296__be32 redirect_qkey;297298u8 trap_gid[16];299__be32 trap_tc_fl;300__be32 trap_lid;301__be32 trap_hl_qp;302__be32 trap_qkey;303304__be16 trap_pkey;305__be16 redirect_pkey;306307u8 trap_sl_rsvd;308u8 reserved[3];309} __packed;310311/**312* ib_get_cpi_resp_time - Returns the resp_time value from313* cap_mask2_resp_time in ib_class_port_info.314* @cpi: A struct ib_class_port_info mad.315*/316static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)317{318return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &319IB_CLASS_PORT_INFO_RESP_TIME_MASK);320}321322/**323* ib_set_cpi_resptime - Sets the response time in an324* ib_class_port_info mad.325* @cpi: A struct ib_class_port_info.326* @rtime: The response time to set.327*/328static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,329u8 rtime)330{331cpi->cap_mask2_resp_time =332(cpi->cap_mask2_resp_time &333cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |334cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);335}336337/**338* ib_get_cpi_capmask2 - Returns the capmask2 value from339* cap_mask2_resp_time in ib_class_port_info.340* @cpi: A struct ib_class_port_info mad.341*/342static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)343{344return (be32_to_cpu(cpi->cap_mask2_resp_time) >>345IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);346}347348/**349* ib_set_cpi_capmask2 - Sets the capmask2 in an350* ib_class_port_info mad.351* @cpi: A struct ib_class_port_info.352* @capmask2: The capmask2 to set.353*/354static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,355u32 capmask2)356{357cpi->cap_mask2_resp_time =358(cpi->cap_mask2_resp_time &359cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |360cpu_to_be32(capmask2 <<361IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);362}363364/**365* opa_get_cpi_capmask2 - Returns the capmask2 value from366* cap_mask2_resp_time in ib_class_port_info.367* @cpi: A struct opa_class_port_info mad.368*/369static inline u32 opa_get_cpi_capmask2(struct opa_class_port_info *cpi)370{371return (be32_to_cpu(cpi->cap_mask2_resp_time) >>372IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);373}374375struct ib_mad_notice_attr {376u8 generic_type;377u8 prod_type_msb;378__be16 prod_type_lsb;379__be16 trap_num;380__be16 issuer_lid;381__be16 toggle_count;382383union {384struct {385u8 details[54];386} raw_data;387388struct {389__be16 reserved;390__be16 lid; /* where violation happened */391u8 port_num; /* where violation happened */392} __packed ntc_129_131;393394struct {395__be16 reserved;396__be16 lid; /* LID where change occurred */397u8 reserved2;398u8 local_changes; /* low bit - local changes */399__be32 new_cap_mask; /* new capability mask */400u8 reserved3;401u8 change_flags; /* low 3 bits only */402} __packed ntc_144;403404struct {405__be16 reserved;406__be16 lid; /* lid where sys guid changed */407__be16 reserved2;408__be64 new_sys_guid;409} __packed ntc_145;410411struct {412__be16 reserved;413__be16 lid;414__be16 dr_slid;415u8 method;416u8 reserved2;417__be16 attr_id;418__be32 attr_mod;419__be64 mkey;420u8 reserved3;421u8 dr_trunc_hop;422u8 dr_rtn_path[30];423} __packed ntc_256;424425struct {426__be16 reserved;427__be16 lid1;428__be16 lid2;429__be32 key;430__be32 sl_qp1; /* SL: high 4 bits */431__be32 qp2; /* high 8 bits reserved */432union ib_gid gid1;433union ib_gid gid2;434} __packed ntc_257_258;435436} details;437};438439/**440* ib_mad_send_buf - MAD data buffer and work request for sends.441* @next: A pointer used to chain together MADs for posting.442* @mad: References an allocated MAD data buffer for MADs that do not have443* RMPP active. For MADs using RMPP, references the common and management444* class specific headers.445* @mad_agent: MAD agent that allocated the buffer.446* @ah: The address handle to use when sending the MAD.447* @context: User-controlled context fields.448* @hdr_len: Indicates the size of the data header of the MAD. This length449* includes the common MAD, RMPP, and class specific headers.450* @data_len: Indicates the total size of user-transferred data.451* @seg_count: The number of RMPP segments allocated for this send.452* @seg_size: Size of the data in each RMPP segment. This does not include453* class specific headers.454* @seg_rmpp_size: Size of each RMPP segment including the class specific455* headers.456* @timeout_ms: Time to wait for a response.457* @retries: Number of times to retry a request for a response. For MADs458* using RMPP, this applies per window. On completion, returns the number459* of retries needed to complete the transfer.460*461* Users are responsible for initializing the MAD buffer itself, with the462* exception of any RMPP header. Additional segment buffer space allocated463* beyond data_len is padding.464*/465struct ib_mad_send_buf {466struct ib_mad_send_buf *next;467void *mad;468struct ib_mad_agent *mad_agent;469struct ib_ah *ah;470void *context[2];471int hdr_len;472int data_len;473int seg_count;474int seg_size;475int seg_rmpp_size;476int timeout_ms;477int retries;478};479480/**481* ib_response_mad - Returns if the specified MAD has been generated in482* response to a sent request or trap.483*/484int ib_response_mad(const struct ib_mad_hdr *hdr);485486/**487* ib_get_rmpp_resptime - Returns the RMPP response time.488* @rmpp_hdr: An RMPP header.489*/490static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)491{492return rmpp_hdr->rmpp_rtime_flags >> 3;493}494495/**496* ib_get_rmpp_flags - Returns the RMPP flags.497* @rmpp_hdr: An RMPP header.498*/499static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)500{501return rmpp_hdr->rmpp_rtime_flags & 0x7;502}503504/**505* ib_set_rmpp_resptime - Sets the response time in an RMPP header.506* @rmpp_hdr: An RMPP header.507* @rtime: The response time to set.508*/509static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)510{511rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);512}513514/**515* ib_set_rmpp_flags - Sets the flags in an RMPP header.516* @rmpp_hdr: An RMPP header.517* @flags: The flags to set.518*/519static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)520{521rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |522(flags & 0x7);523}524525struct ib_mad_agent;526struct ib_mad_send_wc;527struct ib_mad_recv_wc;528529/**530* ib_mad_send_handler - callback handler for a sent MAD.531* @mad_agent: MAD agent that sent the MAD.532* @mad_send_wc: Send work completion information on the sent MAD.533*/534typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,535struct ib_mad_send_wc *mad_send_wc);536537/**538* ib_mad_recv_handler - callback handler for a received MAD.539* @mad_agent: MAD agent requesting the received MAD.540* @send_buf: Send buffer if found, else NULL541* @mad_recv_wc: Received work completion information on the received MAD.542*543* MADs received in response to a send request operation will be handed to544* the user before the send operation completes. All data buffers given545* to registered agents through this routine are owned by the receiving546* client.547*/548typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,549struct ib_mad_send_buf *send_buf,550struct ib_mad_recv_wc *mad_recv_wc);551552/**553* ib_mad_agent - Used to track MAD registration with the access layer.554* @device: Reference to device registration is on.555* @qp: Reference to QP used for sending and receiving MADs.556* @mr: Memory region for system memory usable for DMA.557* @recv_handler: Callback handler for a received MAD.558* @send_handler: Callback handler for a sent MAD.559* @context: User-specified context associated with this registration.560* @hi_tid: Access layer assigned transaction ID for this client.561* Unsolicited MADs sent by this client will have the upper 32-bits562* of their TID set to this value.563* @flags: registration flags564* @port_num: Port number on which QP is registered565* @rmpp_version: If set, indicates the RMPP version used by this agent.566*/567enum {568IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,569};570struct ib_mad_agent {571struct ib_device *device;572struct ib_qp *qp;573ib_mad_recv_handler recv_handler;574ib_mad_send_handler send_handler;575void *context;576u32 hi_tid;577u32 flags;578void *security;579struct list_head mad_agent_sec_list;580u8 port_num;581u8 rmpp_version;582bool smp_allowed;583};584585/**586* ib_mad_send_wc - MAD send completion information.587* @send_buf: Send MAD data buffer associated with the send MAD request.588* @status: Completion status.589* @vendor_err: Optional vendor error information returned with a failed590* request.591*/592struct ib_mad_send_wc {593struct ib_mad_send_buf *send_buf;594enum ib_wc_status status;595u32 vendor_err;596};597598/**599* ib_mad_recv_buf - received MAD buffer information.600* @list: Reference to next data buffer for a received RMPP MAD.601* @grh: References a data buffer containing the global route header.602* The data refereced by this buffer is only valid if the GRH is603* valid.604* @mad: References the start of the received MAD.605*/606struct ib_mad_recv_buf {607struct list_head list;608struct ib_grh *grh;609union {610struct ib_mad *mad;611struct opa_mad *opa_mad;612};613};614615/**616* ib_mad_recv_wc - received MAD information.617* @wc: Completion information for the received data.618* @recv_buf: Specifies the location of the received data buffer(s).619* @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.620* @mad_len: The length of the received MAD, without duplicated headers.621* @mad_seg_size: The size of individual MAD segments622*623* For received response, the wr_id contains a pointer to the ib_mad_send_buf624* for the corresponding send request.625*/626struct ib_mad_recv_wc {627struct ib_wc *wc;628struct ib_mad_recv_buf recv_buf;629struct list_head rmpp_list;630int mad_len;631size_t mad_seg_size;632};633634/**635* ib_mad_reg_req - MAD registration request636* @mgmt_class: Indicates which management class of MADs should be receive637* by the caller. This field is only required if the user wishes to638* receive unsolicited MADs, otherwise it should be 0.639* @mgmt_class_version: Indicates which version of MADs for the given640* management class to receive.641* @oui: Indicates IEEE OUI when mgmt_class is a vendor class642* in the range from 0x30 to 0x4f. Otherwise not used.643* @method_mask: The caller will receive unsolicited MADs for any method644* where @method_mask = 1.645*646*/647struct ib_mad_reg_req {648u8 mgmt_class;649u8 mgmt_class_version;650u8 oui[3];651DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);652};653654/**655* ib_register_mad_agent - Register to send/receive MADs.656* @device: The device to register with.657* @port_num: The port on the specified device to use.658* @qp_type: Specifies which QP to access. Must be either659* IB_QPT_SMI or IB_QPT_GSI.660* @mad_reg_req: Specifies which unsolicited MADs should be received661* by the caller. This parameter may be NULL if the caller only662* wishes to receive solicited responses.663* @rmpp_version: If set, indicates that the client will send664* and receive MADs that contain the RMPP header for the given version.665* If set to 0, indicates that RMPP is not used by this client.666* @send_handler: The completion callback routine invoked after a send667* request has completed.668* @recv_handler: The completion callback routine invoked for a received669* MAD.670* @context: User specified context associated with the registration.671* @registration_flags: Registration flags to set for this agent672*/673struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,674u32 port_num,675enum ib_qp_type qp_type,676struct ib_mad_reg_req *mad_reg_req,677u8 rmpp_version,678ib_mad_send_handler send_handler,679ib_mad_recv_handler recv_handler,680void *context,681u32 registration_flags);682/**683* ib_unregister_mad_agent - Unregisters a client from using MAD services.684* @mad_agent: Corresponding MAD registration request to deregister.685*686* After invoking this routine, MAD services are no longer usable by the687* client on the associated QP.688*/689void ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);690691/**692* ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated693* with the registered client.694* @send_buf: Specifies the information needed to send the MAD(s).695* @bad_send_buf: Specifies the MAD on which an error was encountered. This696* parameter is optional if only a single MAD is posted.697*698* Sent MADs are not guaranteed to complete in the order that they were posted.699*700* If the MAD requires RMPP, the data buffer should contain a single copy701* of the common MAD, RMPP, and class specific headers, followed by the class702* defined data. If the class defined data would not divide evenly into703* RMPP segments, then space must be allocated at the end of the referenced704* buffer for any required padding. To indicate the amount of class defined705* data being transferred, the paylen_newwin field in the RMPP header should706* be set to the size of the class specific header plus the amount of class707* defined data being transferred. The paylen_newwin field should be708* specified in network-byte order.709*/710int ib_post_send_mad(struct ib_mad_send_buf *send_buf,711struct ib_mad_send_buf **bad_send_buf);712713714/**715* ib_free_recv_mad - Returns data buffers used to receive a MAD.716* @mad_recv_wc: Work completion information for a received MAD.717*718* Clients receiving MADs through their ib_mad_recv_handler must call this719* routine to return the work completion buffers to the access layer.720*/721void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);722723/**724* ib_modify_mad - Modifies an outstanding send MAD operation.725* @send_buf: Indicates the MAD to modify.726* @timeout_ms: New timeout value for sent MAD.727*728* This call will reset the timeout value for a sent MAD to the specified729* value.730*/731int ib_modify_mad(struct ib_mad_send_buf *send_buf, u32 timeout_ms);732733/**734* ib_cancel_mad - Cancels an outstanding send MAD operation.735* @send_buf: Indicates the MAD to cancel.736*737* MADs will be returned to the user through the corresponding738* ib_mad_send_handler.739*/740static inline void ib_cancel_mad(struct ib_mad_send_buf *send_buf)741{742ib_modify_mad(send_buf, 0);743}744745/**746* ib_create_send_mad - Allocate and initialize a data buffer and work request747* for sending a MAD.748* @mad_agent: Specifies the registered MAD service to associate with the MAD.749* @remote_qpn: Specifies the QPN of the receiving node.750* @pkey_index: Specifies which PKey the MAD will be sent using. This field751* is valid only if the remote_qpn is QP 1.752* @rmpp_active: Indicates if the send will enable RMPP.753* @hdr_len: Indicates the size of the data header of the MAD. This length754* should include the common MAD header, RMPP header, plus any class755* specific header.756* @data_len: Indicates the size of any user-transferred data. The call will757* automatically adjust the allocated buffer size to account for any758* additional padding that may be necessary.759* @gfp_mask: GFP mask used for the memory allocation.760* @base_version: Base Version of this MAD761*762* This routine allocates a MAD for sending. The returned MAD send buffer763* will reference a data buffer usable for sending a MAD, along764* with an initialized work request structure. Users may modify the returned765* MAD data buffer before posting the send.766*767* The returned MAD header, class specific headers, and any padding will be768* cleared. Users are responsible for initializing the common MAD header,769* any class specific header, and MAD data area.770* If @rmpp_active is set, the RMPP header will be initialized for sending.771*/772struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,773u32 remote_qpn, u16 pkey_index,774int rmpp_active,775int hdr_len, int data_len,776gfp_t gfp_mask,777u8 base_version);778779/**780* ib_is_mad_class_rmpp - returns whether given management class781* supports RMPP.782* @mgmt_class: management class783*784* This routine returns whether the management class supports RMPP.785*/786int ib_is_mad_class_rmpp(u8 mgmt_class);787788/**789* ib_get_mad_data_offset - returns the data offset for a given790* management class.791* @mgmt_class: management class792*793* This routine returns the data offset in the MAD for the management794* class requested.795*/796int ib_get_mad_data_offset(u8 mgmt_class);797798/**799* ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.800* @send_buf: Previously allocated send data buffer.801* @seg_num: number of segment to return802*803* This routine returns a pointer to the data buffer of an RMPP MAD.804* Users must provide synchronization to @send_buf around this call.805*/806void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);807808/**809* ib_free_send_mad - Returns data buffers used to send a MAD.810* @send_buf: Previously allocated send data buffer.811*/812void ib_free_send_mad(struct ib_mad_send_buf *send_buf);813814/**815* ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.816* @agent: the agent in question817* @return: true if agent is performing rmpp, false otherwise.818*/819int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);820821#endif /* IB_MAD_H */822823824