/* 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 0x075051#define IB_MGMT_METHOD_RESP 0x8052#define IB_BM_ATTR_MOD_RESP cpu_to_be32(1)5354#define IB_MGMT_MAX_METHODS 1285556/* MAD Status field bit masks */57#define IB_MGMT_MAD_STATUS_SUCCESS 0x000058#define IB_MGMT_MAD_STATUS_BUSY 0x000159#define IB_MGMT_MAD_STATUS_REDIRECT_REQD 0x000260#define IB_MGMT_MAD_STATUS_BAD_VERSION 0x000461#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD 0x000862#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB 0x000c63#define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE 0x001c6465/* RMPP information */66#define IB_MGMT_RMPP_VERSION 16768#define IB_MGMT_RMPP_TYPE_DATA 169#define IB_MGMT_RMPP_TYPE_ACK 270#define IB_MGMT_RMPP_TYPE_STOP 371#define IB_MGMT_RMPP_TYPE_ABORT 47273#define IB_MGMT_RMPP_FLAG_ACTIVE 174#define IB_MGMT_RMPP_FLAG_FIRST (1<<1)75#define IB_MGMT_RMPP_FLAG_LAST (1<<2)7677#define IB_MGMT_RMPP_NO_RESPTIME 0x1F7879#define IB_MGMT_RMPP_STATUS_SUCCESS 080#define IB_MGMT_RMPP_STATUS_RESX 181#define IB_MGMT_RMPP_STATUS_ABORT_MIN 11882#define IB_MGMT_RMPP_STATUS_T2L 11883#define IB_MGMT_RMPP_STATUS_BAD_LEN 11984#define IB_MGMT_RMPP_STATUS_BAD_SEG 12085#define IB_MGMT_RMPP_STATUS_BADT 12186#define IB_MGMT_RMPP_STATUS_W2S 12287#define IB_MGMT_RMPP_STATUS_S2B 12388#define IB_MGMT_RMPP_STATUS_BAD_STATUS 12489#define IB_MGMT_RMPP_STATUS_UNV 12590#define IB_MGMT_RMPP_STATUS_TMR 12691#define IB_MGMT_RMPP_STATUS_UNSPEC 12792#define IB_MGMT_RMPP_STATUS_ABORT_MAX 1279394#define IB_QP0 095#define IB_QP1 cpu_to_be32(1)96#define IB_QP1_QKEY 0x8001000097#define IB_QP_SET_QKEY 0x800000009899#define IB_DEFAULT_PKEY_PARTIAL 0x7FFF100#define IB_DEFAULT_PKEY_FULL 0xFFFF101102/*103* Generic trap/notice types104*/105#define IB_NOTICE_TYPE_FATAL 0x80106#define IB_NOTICE_TYPE_URGENT 0x81107#define IB_NOTICE_TYPE_SECURITY 0x82108#define IB_NOTICE_TYPE_SM 0x83109#define IB_NOTICE_TYPE_INFO 0x84110111/*112* Generic trap/notice producers113*/114#define IB_NOTICE_PROD_CA cpu_to_be16(1)115#define IB_NOTICE_PROD_SWITCH cpu_to_be16(2)116#define IB_NOTICE_PROD_ROUTER cpu_to_be16(3)117#define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16(4)118119enum {120IB_MGMT_MAD_HDR = 24,121IB_MGMT_MAD_DATA = 232,122IB_MGMT_RMPP_HDR = 36,123IB_MGMT_RMPP_DATA = 220,124IB_MGMT_VENDOR_HDR = 40,125IB_MGMT_VENDOR_DATA = 216,126IB_MGMT_SA_HDR = 56,127IB_MGMT_SA_DATA = 200,128IB_MGMT_DEVICE_HDR = 64,129IB_MGMT_DEVICE_DATA = 192,130IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,131OPA_MGMT_MAD_DATA = 2024,132OPA_MGMT_RMPP_DATA = 2012,133OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,134};135136struct ib_mad_hdr {137u8 base_version;138u8 mgmt_class;139u8 class_version;140u8 method;141__be16 status;142__be16 class_specific;143__be64 tid;144__be16 attr_id;145__be16 resv;146__be32 attr_mod;147};148149struct ib_rmpp_hdr {150u8 rmpp_version;151u8 rmpp_type;152u8 rmpp_rtime_flags;153u8 rmpp_status;154__be32 seg_num;155__be32 paylen_newwin;156};157158typedef u64 __bitwise ib_sa_comp_mask;159160#define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))161162/*163* ib_sa_hdr and ib_sa_mad structures must be packed because they have164* 64-bit fields that are only 32-bit aligned. 64-bit architectures will165* lay them out wrong otherwise. (And unfortunately they are sent on166* the wire so we can't change the layout)167*/168struct ib_sa_hdr {169__be64 sm_key;170__be16 attr_offset;171__be16 reserved;172ib_sa_comp_mask comp_mask;173} __packed;174175struct ib_mad {176struct ib_mad_hdr mad_hdr;177u8 data[IB_MGMT_MAD_DATA];178};179180struct opa_mad {181struct ib_mad_hdr mad_hdr;182u8 data[OPA_MGMT_MAD_DATA];183};184185struct ib_rmpp_mad {186struct ib_mad_hdr mad_hdr;187struct ib_rmpp_hdr rmpp_hdr;188u8 data[IB_MGMT_RMPP_DATA];189};190191struct opa_rmpp_mad {192struct ib_mad_hdr mad_hdr;193struct ib_rmpp_hdr rmpp_hdr;194u8 data[OPA_MGMT_RMPP_DATA];195};196197struct ib_sa_mad {198struct ib_mad_hdr mad_hdr;199struct ib_rmpp_hdr rmpp_hdr;200struct ib_sa_hdr sa_hdr;201u8 data[IB_MGMT_SA_DATA];202} __packed;203204struct ib_vendor_mad {205struct ib_mad_hdr mad_hdr;206struct ib_rmpp_hdr rmpp_hdr;207u8 reserved;208u8 oui[3];209u8 data[IB_MGMT_VENDOR_DATA];210};211212#define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001)213214#define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F215#define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5216217struct ib_class_port_info {218u8 base_version;219u8 class_version;220__be16 capability_mask;221/* 27 bits for cap_mask2, 5 bits for resp_time */222__be32 cap_mask2_resp_time;223u8 redirect_gid[16];224__be32 redirect_tcslfl;225__be16 redirect_lid;226__be16 redirect_pkey;227__be32 redirect_qp;228__be32 redirect_qkey;229u8 trap_gid[16];230__be32 trap_tcslfl;231__be16 trap_lid;232__be16 trap_pkey;233__be32 trap_hlqp;234__be32 trap_qkey;235};236237/* PortInfo CapabilityMask */238enum ib_port_capability_mask_bits {239IB_PORT_SM = 1 << 1,240IB_PORT_NOTICE_SUP = 1 << 2,241IB_PORT_TRAP_SUP = 1 << 3,242IB_PORT_OPT_IPD_SUP = 1 << 4,243IB_PORT_AUTO_MIGR_SUP = 1 << 5,244IB_PORT_SL_MAP_SUP = 1 << 6,245IB_PORT_MKEY_NVRAM = 1 << 7,246IB_PORT_PKEY_NVRAM = 1 << 8,247IB_PORT_LED_INFO_SUP = 1 << 9,248IB_PORT_SM_DISABLED = 1 << 10,249IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,250IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,251IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,252IB_PORT_CAP_MASK2_SUP = 1 << 15,253IB_PORT_CM_SUP = 1 << 16,254IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,255IB_PORT_REINIT_SUP = 1 << 18,256IB_PORT_DEVICE_MGMT_SUP = 1 << 19,257IB_PORT_VENDOR_CLASS_SUP = 1 << 20,258IB_PORT_DR_NOTICE_SUP = 1 << 21,259IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,260IB_PORT_BOOT_MGMT_SUP = 1 << 23,261IB_PORT_LINK_LATENCY_SUP = 1 << 24,262IB_PORT_CLIENT_REG_SUP = 1 << 25,263IB_PORT_OTHER_LOCAL_CHANGES_SUP = 1 << 26,264IB_PORT_LINK_SPEED_WIDTH_TABLE_SUP = 1 << 27,265IB_PORT_VENDOR_SPECIFIC_MADS_TABLE_SUP = 1 << 28,266IB_PORT_MCAST_PKEY_TRAP_SUPPRESSION_SUP = 1 << 29,267IB_PORT_MCAST_FDB_TOP_SUP = 1 << 30,268IB_PORT_HIERARCHY_INFO_SUP = 1ULL << 31,269};270271enum ib_port_capability_mask2_bits {272IB_PORT_SET_NODE_DESC_SUP = 1 << 0,273IB_PORT_EX_PORT_INFO_EX_SUP = 1 << 1,274IB_PORT_VIRT_SUP = 1 << 2,275IB_PORT_SWITCH_PORT_STATE_TABLE_SUP = 1 << 3,276IB_PORT_LINK_WIDTH_2X_SUP = 1 << 4,277IB_PORT_LINK_SPEED_HDR_SUP = 1 << 5,278IB_PORT_LINK_SPEED_NDR_SUP = 1 << 10,279IB_PORT_EXTENDED_SPEEDS2_SUP = 1 << 11,280IB_PORT_LINK_SPEED_XDR_SUP = 1 << 12,281};282283#define OPA_CLASS_PORT_INFO_PR_SUPPORT BIT(26)284285struct opa_class_port_info {286u8 base_version;287u8 class_version;288__be16 cap_mask;289__be32 cap_mask2_resp_time;290291u8 redirect_gid[16];292__be32 redirect_tc_fl;293__be32 redirect_lid;294__be32 redirect_sl_qp;295__be32 redirect_qkey;296297u8 trap_gid[16];298__be32 trap_tc_fl;299__be32 trap_lid;300__be32 trap_hl_qp;301__be32 trap_qkey;302303__be16 trap_pkey;304__be16 redirect_pkey;305306u8 trap_sl_rsvd;307u8 reserved[3];308} __packed;309310/**311* ib_get_cpi_resp_time - Returns the resp_time value from312* cap_mask2_resp_time in ib_class_port_info.313* @cpi: A struct ib_class_port_info mad.314*/315static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)316{317return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &318IB_CLASS_PORT_INFO_RESP_TIME_MASK);319}320321/**322* ib_set_cpi_resptime - Sets the response time in an323* ib_class_port_info mad.324* @cpi: A struct ib_class_port_info.325* @rtime: The response time to set.326*/327static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,328u8 rtime)329{330cpi->cap_mask2_resp_time =331(cpi->cap_mask2_resp_time &332cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |333cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);334}335336/**337* ib_get_cpi_capmask2 - Returns the capmask2 value from338* cap_mask2_resp_time in ib_class_port_info.339* @cpi: A struct ib_class_port_info mad.340*/341static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)342{343return (be32_to_cpu(cpi->cap_mask2_resp_time) >>344IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);345}346347/**348* ib_set_cpi_capmask2 - Sets the capmask2 in an349* ib_class_port_info mad.350* @cpi: A struct ib_class_port_info.351* @capmask2: The capmask2 to set.352*/353static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,354u32 capmask2)355{356cpi->cap_mask2_resp_time =357(cpi->cap_mask2_resp_time &358cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |359cpu_to_be32(capmask2 <<360IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);361}362363/**364* opa_get_cpi_capmask2 - Returns the capmask2 value from365* cap_mask2_resp_time in ib_class_port_info.366* @cpi: A struct opa_class_port_info mad.367*/368static inline u32 opa_get_cpi_capmask2(struct opa_class_port_info *cpi)369{370return (be32_to_cpu(cpi->cap_mask2_resp_time) >>371IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);372}373374struct ib_mad_notice_attr {375u8 generic_type;376u8 prod_type_msb;377__be16 prod_type_lsb;378__be16 trap_num;379__be16 issuer_lid;380__be16 toggle_count;381382union {383struct {384u8 details[54];385} raw_data;386387struct {388__be16 reserved;389__be16 lid; /* where violation happened */390u8 port_num; /* where violation happened */391} __packed ntc_129_131;392393struct {394__be16 reserved;395__be16 lid; /* LID where change occurred */396u8 reserved2;397u8 local_changes; /* low bit - local changes */398__be32 new_cap_mask; /* new capability mask */399u8 reserved3;400u8 change_flags; /* low 3 bits only */401} __packed ntc_144;402403struct {404__be16 reserved;405__be16 lid; /* lid where sys guid changed */406__be16 reserved2;407__be64 new_sys_guid;408} __packed ntc_145;409410struct {411__be16 reserved;412__be16 lid;413__be16 dr_slid;414u8 method;415u8 reserved2;416__be16 attr_id;417__be32 attr_mod;418__be64 mkey;419u8 reserved3;420u8 dr_trunc_hop;421u8 dr_rtn_path[30];422} __packed ntc_256;423424struct {425__be16 reserved;426__be16 lid1;427__be16 lid2;428__be32 key;429__be32 sl_qp1; /* SL: high 4 bits */430__be32 qp2; /* high 8 bits reserved */431union ib_gid gid1;432union ib_gid gid2;433} __packed ntc_257_258;434435} details;436};437438/**439* ib_mad_send_buf - MAD data buffer and work request for sends.440* @next: A pointer used to chain together MADs for posting.441* @mad: References an allocated MAD data buffer for MADs that do not have442* RMPP active. For MADs using RMPP, references the common and management443* class specific headers.444* @mad_agent: MAD agent that allocated the buffer.445* @ah: The address handle to use when sending the MAD.446* @context: User-controlled context fields.447* @hdr_len: Indicates the size of the data header of the MAD. This length448* includes the common MAD, RMPP, and class specific headers.449* @data_len: Indicates the total size of user-transferred data.450* @seg_count: The number of RMPP segments allocated for this send.451* @seg_size: Size of the data in each RMPP segment. This does not include452* class specific headers.453* @seg_rmpp_size: Size of each RMPP segment including the class specific454* headers.455* @timeout_ms: Time to wait for a response.456* @retries: Number of times to retry a request for a response. For MADs457* using RMPP, this applies per window. On completion, returns the number458* of retries needed to complete the transfer.459*460* Users are responsible for initializing the MAD buffer itself, with the461* exception of any RMPP header. Additional segment buffer space allocated462* beyond data_len is padding.463*/464struct ib_mad_send_buf {465struct ib_mad_send_buf *next;466void *mad;467struct ib_mad_agent *mad_agent;468struct ib_ah *ah;469void *context[2];470int hdr_len;471int data_len;472int seg_count;473int seg_size;474int seg_rmpp_size;475int timeout_ms;476int retries;477};478479/**480* ib_response_mad - Returns if the specified MAD has been generated in481* response to a sent request or trap.482*/483int ib_response_mad(const struct ib_mad_hdr *hdr);484485/**486* ib_get_rmpp_resptime - Returns the RMPP response time.487* @rmpp_hdr: An RMPP header.488*/489static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)490{491return rmpp_hdr->rmpp_rtime_flags >> 3;492}493494/**495* ib_get_rmpp_flags - Returns the RMPP flags.496* @rmpp_hdr: An RMPP header.497*/498static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)499{500return rmpp_hdr->rmpp_rtime_flags & 0x7;501}502503/**504* ib_set_rmpp_resptime - Sets the response time in an RMPP header.505* @rmpp_hdr: An RMPP header.506* @rtime: The response time to set.507*/508static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)509{510rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);511}512513/**514* ib_set_rmpp_flags - Sets the flags in an RMPP header.515* @rmpp_hdr: An RMPP header.516* @flags: The flags to set.517*/518static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)519{520rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |521(flags & 0x7);522}523524struct ib_mad_agent;525struct ib_mad_send_wc;526struct ib_mad_recv_wc;527528/**529* ib_mad_send_handler - callback handler for a sent MAD.530* @mad_agent: MAD agent that sent the MAD.531* @mad_send_wc: Send work completion information on the sent MAD.532*/533typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,534struct ib_mad_send_wc *mad_send_wc);535536/**537* ib_mad_recv_handler - callback handler for a received MAD.538* @mad_agent: MAD agent requesting the received MAD.539* @send_buf: Send buffer if found, else NULL540* @mad_recv_wc: Received work completion information on the received MAD.541*542* MADs received in response to a send request operation will be handed to543* the user before the send operation completes. All data buffers given544* to registered agents through this routine are owned by the receiving545* client.546*/547typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,548struct ib_mad_send_buf *send_buf,549struct ib_mad_recv_wc *mad_recv_wc);550551/**552* ib_mad_agent - Used to track MAD registration with the access layer.553* @device: Reference to device registration is on.554* @qp: Reference to QP used for sending and receiving MADs.555* @mr: Memory region for system memory usable for DMA.556* @recv_handler: Callback handler for a received MAD.557* @send_handler: Callback handler for a sent MAD.558* @context: User-specified context associated with this registration.559* @hi_tid: Access layer assigned transaction ID for this client.560* Unsolicited MADs sent by this client will have the upper 32-bits561* of their TID set to this value.562* @flags: registration flags563* @port_num: Port number on which QP is registered564* @rmpp_version: If set, indicates the RMPP version used by this agent.565*/566enum {567IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,568};569struct ib_mad_agent {570struct ib_device *device;571struct ib_qp *qp;572ib_mad_recv_handler recv_handler;573ib_mad_send_handler send_handler;574void *context;575u32 hi_tid;576u32 flags;577void *security;578struct list_head mad_agent_sec_list;579u8 port_num;580u8 rmpp_version;581bool smp_allowed;582};583584/**585* ib_mad_send_wc - MAD send completion information.586* @send_buf: Send MAD data buffer associated with the send MAD request.587* @status: Completion status.588* @vendor_err: Optional vendor error information returned with a failed589* request.590*/591struct ib_mad_send_wc {592struct ib_mad_send_buf *send_buf;593enum ib_wc_status status;594u32 vendor_err;595};596597/**598* ib_mad_recv_buf - received MAD buffer information.599* @list: Reference to next data buffer for a received RMPP MAD.600* @grh: References a data buffer containing the global route header.601* The data refereced by this buffer is only valid if the GRH is602* valid.603* @mad: References the start of the received MAD.604*/605struct ib_mad_recv_buf {606struct list_head list;607struct ib_grh *grh;608union {609struct ib_mad *mad;610struct opa_mad *opa_mad;611};612};613614/**615* ib_mad_recv_wc - received MAD information.616* @wc: Completion information for the received data.617* @recv_buf: Specifies the location of the received data buffer(s).618* @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.619* @mad_len: The length of the received MAD, without duplicated headers.620* @mad_seg_size: The size of individual MAD segments621*622* For received response, the wr_id contains a pointer to the ib_mad_send_buf623* for the corresponding send request.624*/625struct ib_mad_recv_wc {626struct ib_wc *wc;627struct ib_mad_recv_buf recv_buf;628struct list_head rmpp_list;629int mad_len;630size_t mad_seg_size;631};632633/**634* ib_mad_reg_req - MAD registration request635* @mgmt_class: Indicates which management class of MADs should be receive636* by the caller. This field is only required if the user wishes to637* receive unsolicited MADs, otherwise it should be 0.638* @mgmt_class_version: Indicates which version of MADs for the given639* management class to receive.640* @oui: Indicates IEEE OUI when mgmt_class is a vendor class641* in the range from 0x30 to 0x4f. Otherwise not used.642* @method_mask: The caller will receive unsolicited MADs for any method643* where @method_mask = 1.644*645*/646struct ib_mad_reg_req {647u8 mgmt_class;648u8 mgmt_class_version;649u8 oui[3];650DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);651};652653/**654* ib_register_mad_agent - Register to send/receive MADs.655* @device: The device to register with.656* @port_num: The port on the specified device to use.657* @qp_type: Specifies which QP to access. Must be either658* IB_QPT_SMI or IB_QPT_GSI.659* @mad_reg_req: Specifies which unsolicited MADs should be received660* by the caller. This parameter may be NULL if the caller only661* wishes to receive solicited responses.662* @rmpp_version: If set, indicates that the client will send663* and receive MADs that contain the RMPP header for the given version.664* If set to 0, indicates that RMPP is not used by this client.665* @send_handler: The completion callback routine invoked after a send666* request has completed.667* @recv_handler: The completion callback routine invoked for a received668* MAD.669* @context: User specified context associated with the registration.670* @registration_flags: Registration flags to set for this agent671*/672struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,673u32 port_num,674enum ib_qp_type qp_type,675struct ib_mad_reg_req *mad_reg_req,676u8 rmpp_version,677ib_mad_send_handler send_handler,678ib_mad_recv_handler recv_handler,679void *context,680u32 registration_flags);681/**682* ib_unregister_mad_agent - Unregisters a client from using MAD services.683* @mad_agent: Corresponding MAD registration request to deregister.684*685* After invoking this routine, MAD services are no longer usable by the686* client on the associated QP.687*/688void ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);689690/**691* ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated692* with the registered client.693* @send_buf: Specifies the information needed to send the MAD(s).694* @bad_send_buf: Specifies the MAD on which an error was encountered. This695* parameter is optional if only a single MAD is posted.696*697* Sent MADs are not guaranteed to complete in the order that they were posted.698*699* If the MAD requires RMPP, the data buffer should contain a single copy700* of the common MAD, RMPP, and class specific headers, followed by the class701* defined data. If the class defined data would not divide evenly into702* RMPP segments, then space must be allocated at the end of the referenced703* buffer for any required padding. To indicate the amount of class defined704* data being transferred, the paylen_newwin field in the RMPP header should705* be set to the size of the class specific header plus the amount of class706* defined data being transferred. The paylen_newwin field should be707* specified in network-byte order.708*/709int ib_post_send_mad(struct ib_mad_send_buf *send_buf,710struct ib_mad_send_buf **bad_send_buf);711712713/**714* ib_free_recv_mad - Returns data buffers used to receive a MAD.715* @mad_recv_wc: Work completion information for a received MAD.716*717* Clients receiving MADs through their ib_mad_recv_handler must call this718* routine to return the work completion buffers to the access layer.719*/720void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);721722/**723* ib_modify_mad - Modifies an outstanding send MAD operation.724* @send_buf: Indicates the MAD to modify.725* @timeout_ms: New timeout value for sent MAD.726*727* This call will reset the timeout value for a sent MAD to the specified728* value.729*/730int ib_modify_mad(struct ib_mad_send_buf *send_buf, u32 timeout_ms);731732/**733* ib_cancel_mad - Cancels an outstanding send MAD operation.734* @send_buf: Indicates the MAD to cancel.735*736* MADs will be returned to the user through the corresponding737* ib_mad_send_handler.738*/739static inline void ib_cancel_mad(struct ib_mad_send_buf *send_buf)740{741ib_modify_mad(send_buf, 0);742}743744/**745* ib_create_send_mad - Allocate and initialize a data buffer and work request746* for sending a MAD.747* @mad_agent: Specifies the registered MAD service to associate with the MAD.748* @remote_qpn: Specifies the QPN of the receiving node.749* @pkey_index: Specifies which PKey the MAD will be sent using. This field750* is valid only if the remote_qpn is QP 1.751* @rmpp_active: Indicates if the send will enable RMPP.752* @hdr_len: Indicates the size of the data header of the MAD. This length753* should include the common MAD header, RMPP header, plus any class754* specific header.755* @data_len: Indicates the size of any user-transferred data. The call will756* automatically adjust the allocated buffer size to account for any757* additional padding that may be necessary.758* @gfp_mask: GFP mask used for the memory allocation.759* @base_version: Base Version of this MAD760*761* This routine allocates a MAD for sending. The returned MAD send buffer762* will reference a data buffer usable for sending a MAD, along763* with an initialized work request structure. Users may modify the returned764* MAD data buffer before posting the send.765*766* The returned MAD header, class specific headers, and any padding will be767* cleared. Users are responsible for initializing the common MAD header,768* any class specific header, and MAD data area.769* If @rmpp_active is set, the RMPP header will be initialized for sending.770*/771struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,772u32 remote_qpn, u16 pkey_index,773int rmpp_active,774int hdr_len, int data_len,775gfp_t gfp_mask,776u8 base_version);777778/**779* ib_is_mad_class_rmpp - returns whether given management class780* supports RMPP.781* @mgmt_class: management class782*783* This routine returns whether the management class supports RMPP.784*/785int ib_is_mad_class_rmpp(u8 mgmt_class);786787/**788* ib_get_mad_data_offset - returns the data offset for a given789* management class.790* @mgmt_class: management class791*792* This routine returns the data offset in the MAD for the management793* class requested.794*/795int ib_get_mad_data_offset(u8 mgmt_class);796797/**798* ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.799* @send_buf: Previously allocated send data buffer.800* @seg_num: number of segment to return801*802* This routine returns a pointer to the data buffer of an RMPP MAD.803* Users must provide synchronization to @send_buf around this call.804*/805void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);806807/**808* ib_free_send_mad - Returns data buffers used to send a MAD.809* @send_buf: Previously allocated send data buffer.810*/811void ib_free_send_mad(struct ib_mad_send_buf *send_buf);812813/**814* ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.815* @agent: the agent in question816* @return: true if agent is performing rmpp, false otherwise.817*/818int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);819820#endif /* IB_MAD_H */821822823