/*-1* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.02*3* Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.4* Copyright (c) 2004 Infinicon Corporation. All rights reserved.5* Copyright (c) 2004 Intel Corporation. All rights reserved.6* Copyright (c) 2004 Topspin Corporation. All rights reserved.7* Copyright (c) 2004-2006 Voltaire Corporation. All rights reserved.8*9* This software is available to you under a choice of one of two10* licenses. You may choose to be licensed under the terms of the GNU11* General Public License (GPL) Version 2, available from the file12* COPYING in the main directory of this source tree, or the13* OpenIB.org BSD license below:14*15* Redistribution and use in source and binary forms, with or16* without modification, are permitted provided that the following17* conditions are met:18*19* - Redistributions of source code must retain the above20* copyright notice, this list of conditions and the following21* disclaimer.22*23* - Redistributions in binary form must reproduce the above24* copyright notice, this list of conditions and the following25* disclaimer in the documentation and/or other materials26* provided with the distribution.27*28* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,29* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF30* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND31* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS32* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN33* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN34* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE35* SOFTWARE.36*/3738#if !defined(IB_MAD_H)39#define IB_MAD_H4041#include <linux/list.h>4243#include <rdma/ib_verbs.h>44#include <uapi/rdma/ib_user_mad.h>4546/* Management base versions */47#define IB_MGMT_BASE_VERSION 148#define OPA_MGMT_BASE_VERSION 0x804950#define OPA_SMP_CLASS_VERSION 0x805152/* Management classes */53#define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x0154#define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x8155#define IB_MGMT_CLASS_SUBN_ADM 0x0356#define IB_MGMT_CLASS_PERF_MGMT 0x0457#define IB_MGMT_CLASS_BM 0x0558#define IB_MGMT_CLASS_DEVICE_MGMT 0x0659#define IB_MGMT_CLASS_CM 0x0760#define IB_MGMT_CLASS_SNMP 0x0861#define IB_MGMT_CLASS_DEVICE_ADM 0x1062#define IB_MGMT_CLASS_BOOT_MGMT 0x1163#define IB_MGMT_CLASS_BIS 0x1264#define IB_MGMT_CLASS_CONG_MGMT 0x2165#define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x3066#define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F6768#define IB_OPENIB_OUI (0x001405)6970/* Management methods */71#define IB_MGMT_METHOD_GET 0x0172#define IB_MGMT_METHOD_SET 0x0273#define IB_MGMT_METHOD_GET_RESP 0x8174#define IB_MGMT_METHOD_SEND 0x0375#define IB_MGMT_METHOD_TRAP 0x0576#define IB_MGMT_METHOD_REPORT 0x0677#define IB_MGMT_METHOD_REPORT_RESP 0x8678#define IB_MGMT_METHOD_TRAP_REPRESS 0x077980#define IB_MGMT_METHOD_RESP 0x8081#define IB_BM_ATTR_MOD_RESP cpu_to_be32(1)8283#define IB_MGMT_MAX_METHODS 1288485/* MAD Status field bit masks */86#define IB_MGMT_MAD_STATUS_SUCCESS 0x000087#define IB_MGMT_MAD_STATUS_BUSY 0x000188#define IB_MGMT_MAD_STATUS_REDIRECT_REQD 0x000289#define IB_MGMT_MAD_STATUS_BAD_VERSION 0x000490#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD 0x000891#define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB 0x000c92#define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE 0x001c9394/* RMPP information */95#define IB_MGMT_RMPP_VERSION 19697#define IB_MGMT_RMPP_TYPE_DATA 198#define IB_MGMT_RMPP_TYPE_ACK 299#define IB_MGMT_RMPP_TYPE_STOP 3100#define IB_MGMT_RMPP_TYPE_ABORT 4101102#define IB_MGMT_RMPP_FLAG_ACTIVE 1103#define IB_MGMT_RMPP_FLAG_FIRST (1<<1)104#define IB_MGMT_RMPP_FLAG_LAST (1<<2)105106#define IB_MGMT_RMPP_NO_RESPTIME 0x1F107108#define IB_MGMT_RMPP_STATUS_SUCCESS 0109#define IB_MGMT_RMPP_STATUS_RESX 1110#define IB_MGMT_RMPP_STATUS_ABORT_MIN 118111#define IB_MGMT_RMPP_STATUS_T2L 118112#define IB_MGMT_RMPP_STATUS_BAD_LEN 119113#define IB_MGMT_RMPP_STATUS_BAD_SEG 120114#define IB_MGMT_RMPP_STATUS_BADT 121115#define IB_MGMT_RMPP_STATUS_W2S 122116#define IB_MGMT_RMPP_STATUS_S2B 123117#define IB_MGMT_RMPP_STATUS_BAD_STATUS 124118#define IB_MGMT_RMPP_STATUS_UNV 125119#define IB_MGMT_RMPP_STATUS_TMR 126120#define IB_MGMT_RMPP_STATUS_UNSPEC 127121#define IB_MGMT_RMPP_STATUS_ABORT_MAX 127122123#define IB_QP0 0124#define IB_QP1 cpu_to_be32(1)125#define IB_QP1_QKEY 0x80010000126#define IB_QP_SET_QKEY 0x80000000127128#define IB_DEFAULT_PKEY_PARTIAL 0x7FFF129#define IB_DEFAULT_PKEY_FULL 0xFFFF130131/*132* Generic trap/notice types133*/134#define IB_NOTICE_TYPE_FATAL 0x80135#define IB_NOTICE_TYPE_URGENT 0x81136#define IB_NOTICE_TYPE_SECURITY 0x82137#define IB_NOTICE_TYPE_SM 0x83138#define IB_NOTICE_TYPE_INFO 0x84139140/*141* Generic trap/notice producers142*/143#define IB_NOTICE_PROD_CA cpu_to_be16(1)144#define IB_NOTICE_PROD_SWITCH cpu_to_be16(2)145#define IB_NOTICE_PROD_ROUTER cpu_to_be16(3)146#define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16(4)147148enum {149IB_MGMT_MAD_HDR = 24,150IB_MGMT_MAD_DATA = 232,151IB_MGMT_RMPP_HDR = 36,152IB_MGMT_RMPP_DATA = 220,153IB_MGMT_VENDOR_HDR = 40,154IB_MGMT_VENDOR_DATA = 216,155IB_MGMT_SA_HDR = 56,156IB_MGMT_SA_DATA = 200,157IB_MGMT_DEVICE_HDR = 64,158IB_MGMT_DEVICE_DATA = 192,159IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,160OPA_MGMT_MAD_DATA = 2024,161OPA_MGMT_RMPP_DATA = 2012,162OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,163};164165struct ib_mad_hdr {166u8 base_version;167u8 mgmt_class;168u8 class_version;169u8 method;170__be16 status;171__be16 class_specific;172__be64 tid;173__be16 attr_id;174__be16 resv;175__be32 attr_mod;176};177178struct ib_rmpp_hdr {179u8 rmpp_version;180u8 rmpp_type;181u8 rmpp_rtime_flags;182u8 rmpp_status;183__be32 seg_num;184__be32 paylen_newwin;185};186187typedef u64 __bitwise ib_sa_comp_mask;188189#define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))190191/*192* ib_sa_hdr and ib_sa_mad structures must be packed because they have193* 64-bit fields that are only 32-bit aligned. 64-bit architectures will194* lay them out wrong otherwise. (And unfortunately they are sent on195* the wire so we can't change the layout)196*/197struct ib_sa_hdr {198__be64 sm_key;199__be16 attr_offset;200__be16 reserved;201ib_sa_comp_mask comp_mask;202} __attribute__ ((packed));203204struct ib_mad {205struct ib_mad_hdr mad_hdr;206u8 data[IB_MGMT_MAD_DATA];207};208209struct opa_mad {210struct ib_mad_hdr mad_hdr;211u8 data[OPA_MGMT_MAD_DATA];212};213214struct ib_rmpp_mad {215struct ib_mad_hdr mad_hdr;216struct ib_rmpp_hdr rmpp_hdr;217u8 data[IB_MGMT_RMPP_DATA];218};219220struct opa_rmpp_mad {221struct ib_mad_hdr mad_hdr;222struct ib_rmpp_hdr rmpp_hdr;223u8 data[OPA_MGMT_RMPP_DATA];224};225226struct ib_sa_mad {227struct ib_mad_hdr mad_hdr;228struct ib_rmpp_hdr rmpp_hdr;229struct ib_sa_hdr sa_hdr;230u8 data[IB_MGMT_SA_DATA];231} __attribute__ ((packed));232233struct ib_vendor_mad {234struct ib_mad_hdr mad_hdr;235struct ib_rmpp_hdr rmpp_hdr;236u8 reserved;237u8 oui[3];238u8 data[IB_MGMT_VENDOR_DATA];239};240241#define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001)242243#define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F244#define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5245246struct ib_class_port_info {247u8 base_version;248u8 class_version;249__be16 capability_mask;250/* 27 bits for cap_mask2, 5 bits for resp_time */251__be32 cap_mask2_resp_time;252u8 redirect_gid[16];253__be32 redirect_tcslfl;254__be16 redirect_lid;255__be16 redirect_pkey;256__be32 redirect_qp;257__be32 redirect_qkey;258u8 trap_gid[16];259__be32 trap_tcslfl;260__be16 trap_lid;261__be16 trap_pkey;262__be32 trap_hlqp;263__be32 trap_qkey;264};265266/**267* ib_get_cpi_resp_time - Returns the resp_time value from268* cap_mask2_resp_time in ib_class_port_info.269* @cpi: A struct ib_class_port_info mad.270*/271static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)272{273return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &274IB_CLASS_PORT_INFO_RESP_TIME_MASK);275}276277/**278* ib_set_cpi_resptime - Sets the response time in an279* ib_class_port_info mad.280* @cpi: A struct ib_class_port_info.281* @rtime: The response time to set.282*/283static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,284u8 rtime)285{286cpi->cap_mask2_resp_time =287(cpi->cap_mask2_resp_time &288cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |289cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);290}291292/**293* ib_get_cpi_capmask2 - Returns the capmask2 value from294* cap_mask2_resp_time in ib_class_port_info.295* @cpi: A struct ib_class_port_info mad.296*/297static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)298{299return (be32_to_cpu(cpi->cap_mask2_resp_time) >>300IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);301}302303/**304* ib_set_cpi_capmask2 - Sets the capmask2 in an305* ib_class_port_info mad.306* @cpi: A struct ib_class_port_info.307* @capmask2: The capmask2 to set.308*/309static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,310u32 capmask2)311{312cpi->cap_mask2_resp_time =313(cpi->cap_mask2_resp_time &314cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |315cpu_to_be32(capmask2 <<316IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);317}318319struct ib_mad_notice_attr {320u8 generic_type;321u8 prod_type_msb;322__be16 prod_type_lsb;323__be16 trap_num;324__be16 issuer_lid;325__be16 toggle_count;326327union {328struct {329u8 details[54];330} raw_data;331332struct {333__be16 reserved;334__be16 lid; /* where violation happened */335u8 port_num; /* where violation happened */336} __packed ntc_129_131;337338struct {339__be16 reserved;340__be16 lid; /* LID where change occurred */341u8 reserved2;342u8 local_changes; /* low bit - local changes */343__be32 new_cap_mask; /* new capability mask */344u8 reserved3;345u8 change_flags; /* low 3 bits only */346} __packed ntc_144;347348struct {349__be16 reserved;350__be16 lid; /* lid where sys guid changed */351__be16 reserved2;352__be64 new_sys_guid;353} __packed ntc_145;354355struct {356__be16 reserved;357__be16 lid;358__be16 dr_slid;359u8 method;360u8 reserved2;361__be16 attr_id;362__be32 attr_mod;363__be64 mkey;364u8 reserved3;365u8 dr_trunc_hop;366u8 dr_rtn_path[30];367} __packed ntc_256;368369struct {370__be16 reserved;371__be16 lid1;372__be16 lid2;373__be32 key;374__be32 sl_qp1; /* SL: high 4 bits */375__be32 qp2; /* high 8 bits reserved */376union ib_gid gid1;377union ib_gid gid2;378} __packed ntc_257_258;379380} details;381};382383/**384* ib_mad_send_buf - MAD data buffer and work request for sends.385* @next: A pointer used to chain together MADs for posting.386* @mad: References an allocated MAD data buffer for MADs that do not have387* RMPP active. For MADs using RMPP, references the common and management388* class specific headers.389* @mad_agent: MAD agent that allocated the buffer.390* @ah: The address handle to use when sending the MAD.391* @context: User-controlled context fields.392* @hdr_len: Indicates the size of the data header of the MAD. This length393* includes the common MAD, RMPP, and class specific headers.394* @data_len: Indicates the total size of user-transferred data.395* @seg_count: The number of RMPP segments allocated for this send.396* @seg_size: Size of the data in each RMPP segment. This does not include397* class specific headers.398* @seg_rmpp_size: Size of each RMPP segment including the class specific399* headers.400* @timeout_ms: Time to wait for a response.401* @retries: Number of times to retry a request for a response. For MADs402* using RMPP, this applies per window. On completion, returns the number403* of retries needed to complete the transfer.404*405* Users are responsible for initializing the MAD buffer itself, with the406* exception of any RMPP header. Additional segment buffer space allocated407* beyond data_len is padding.408*/409struct ib_mad_send_buf {410struct ib_mad_send_buf *next;411void *mad;412struct ib_mad_agent *mad_agent;413struct ib_ah *ah;414void *context[2];415int hdr_len;416int data_len;417int seg_count;418int seg_size;419int seg_rmpp_size;420int timeout_ms;421int retries;422};423424/**425* ib_response_mad - Returns if the specified MAD has been generated in426* response to a sent request or trap.427*/428int ib_response_mad(const struct ib_mad_hdr *hdr);429430/**431* ib_get_rmpp_resptime - Returns the RMPP response time.432* @rmpp_hdr: An RMPP header.433*/434static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)435{436return rmpp_hdr->rmpp_rtime_flags >> 3;437}438439/**440* ib_get_rmpp_flags - Returns the RMPP flags.441* @rmpp_hdr: An RMPP header.442*/443static inline u8 ib_get_rmpp_flags(const struct ib_rmpp_hdr *rmpp_hdr)444{445return rmpp_hdr->rmpp_rtime_flags & 0x7;446}447448/**449* ib_set_rmpp_resptime - Sets the response time in an RMPP header.450* @rmpp_hdr: An RMPP header.451* @rtime: The response time to set.452*/453static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)454{455rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);456}457458/**459* ib_set_rmpp_flags - Sets the flags in an RMPP header.460* @rmpp_hdr: An RMPP header.461* @flags: The flags to set.462*/463static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)464{465rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |466(flags & 0x7);467}468469struct ib_mad_agent;470struct ib_mad_send_wc;471struct ib_mad_recv_wc;472473/**474* ib_mad_send_handler - callback handler for a sent MAD.475* @mad_agent: MAD agent that sent the MAD.476* @mad_send_wc: Send work completion information on the sent MAD.477*/478typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,479struct ib_mad_send_wc *mad_send_wc);480481/**482* ib_mad_snoop_handler - Callback handler for snooping sent MADs.483* @mad_agent: MAD agent that snooped the MAD.484* @send_buf: send MAD data buffer.485* @mad_send_wc: Work completion information on the sent MAD. Valid486* only for snooping that occurs on a send completion.487*488* Clients snooping MADs should not modify data referenced by the @send_buf489* or @mad_send_wc.490*/491typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent,492struct ib_mad_send_buf *send_buf,493struct ib_mad_send_wc *mad_send_wc);494495/**496* ib_mad_recv_handler - callback handler for a received MAD.497* @mad_agent: MAD agent requesting the received MAD.498* @send_buf: Send buffer if found, else NULL499* @mad_recv_wc: Received work completion information on the received MAD.500*501* MADs received in response to a send request operation will be handed to502* the user before the send operation completes. All data buffers given503* to registered agents through this routine are owned by the receiving504* client, except for snooping agents. Clients snooping MADs should not505* modify the data referenced by @mad_recv_wc.506*/507typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,508struct ib_mad_send_buf *send_buf,509struct ib_mad_recv_wc *mad_recv_wc);510511/**512* ib_mad_agent - Used to track MAD registration with the access layer.513* @device: Reference to device registration is on.514* @qp: Reference to QP used for sending and receiving MADs.515* @mr: Memory region for system memory usable for DMA.516* @recv_handler: Callback handler for a received MAD.517* @send_handler: Callback handler for a sent MAD.518* @snoop_handler: Callback handler for snooped sent MADs.519* @context: User-specified context associated with this registration.520* @hi_tid: Access layer assigned transaction ID for this client.521* Unsolicited MADs sent by this client will have the upper 32-bits522* of their TID set to this value.523* @flags: registration flags524* @port_num: Port number on which QP is registered525* @rmpp_version: If set, indicates the RMPP version used by this agent.526*/527enum {528IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,529};530struct ib_mad_agent {531struct ib_device *device;532struct ib_qp *qp;533ib_mad_recv_handler recv_handler;534ib_mad_send_handler send_handler;535ib_mad_snoop_handler snoop_handler;536void *context;537u32 hi_tid;538u32 flags;539u8 port_num;540u8 rmpp_version;541};542543/**544* ib_mad_send_wc - MAD send completion information.545* @send_buf: Send MAD data buffer associated with the send MAD request.546* @status: Completion status.547* @vendor_err: Optional vendor error information returned with a failed548* request.549*/550struct ib_mad_send_wc {551struct ib_mad_send_buf *send_buf;552enum ib_wc_status status;553u32 vendor_err;554};555556/**557* ib_mad_recv_buf - received MAD buffer information.558* @list: Reference to next data buffer for a received RMPP MAD.559* @grh: References a data buffer containing the global route header.560* The data refereced by this buffer is only valid if the GRH is561* valid.562* @mad: References the start of the received MAD.563*/564struct ib_mad_recv_buf {565struct list_head list;566struct ib_grh *grh;567union {568struct ib_mad *mad;569struct opa_mad *opa_mad;570};571};572573/**574* ib_mad_recv_wc - received MAD information.575* @wc: Completion information for the received data.576* @recv_buf: Specifies the location of the received data buffer(s).577* @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.578* @mad_len: The length of the received MAD, without duplicated headers.579* @mad_seg_size: The size of individual MAD segments580*581* For received response, the wr_id contains a pointer to the ib_mad_send_buf582* for the corresponding send request.583*/584struct ib_mad_recv_wc {585struct ib_wc *wc;586struct ib_mad_recv_buf recv_buf;587struct list_head rmpp_list;588int mad_len;589size_t mad_seg_size;590};591592/**593* ib_mad_reg_req - MAD registration request594* @mgmt_class: Indicates which management class of MADs should be receive595* by the caller. This field is only required if the user wishes to596* receive unsolicited MADs, otherwise it should be 0.597* @mgmt_class_version: Indicates which version of MADs for the given598* management class to receive.599* @oui: Indicates IEEE OUI when mgmt_class is a vendor class600* in the range from 0x30 to 0x4f. Otherwise not used.601* @method_mask: The caller will receive unsolicited MADs for any method602* where @method_mask = 1.603*604*/605struct ib_mad_reg_req {606u8 mgmt_class;607u8 mgmt_class_version;608u8 oui[3];609DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);610};611612/**613* ib_register_mad_agent - Register to send/receive MADs.614* @device: The device to register with.615* @port_num: The port on the specified device to use.616* @qp_type: Specifies which QP to access. Must be either617* IB_QPT_SMI or IB_QPT_GSI.618* @mad_reg_req: Specifies which unsolicited MADs should be received619* by the caller. This parameter may be NULL if the caller only620* wishes to receive solicited responses.621* @rmpp_version: If set, indicates that the client will send622* and receive MADs that contain the RMPP header for the given version.623* If set to 0, indicates that RMPP is not used by this client.624* @send_handler: The completion callback routine invoked after a send625* request has completed.626* @recv_handler: The completion callback routine invoked for a received627* MAD.628* @context: User specified context associated with the registration.629* @registration_flags: Registration flags to set for this agent630*/631struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,632u8 port_num,633enum ib_qp_type qp_type,634struct ib_mad_reg_req *mad_reg_req,635u8 rmpp_version,636ib_mad_send_handler send_handler,637ib_mad_recv_handler recv_handler,638void *context,639u32 registration_flags);640641enum ib_mad_snoop_flags {642/*IB_MAD_SNOOP_POSTED_SENDS = 1,*/643/*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/644IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2),645/*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/646IB_MAD_SNOOP_RECVS = (1<<4)647/*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/648/*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/649};650651/**652* ib_register_mad_snoop - Register to snoop sent and received MADs.653* @device: The device to register with.654* @port_num: The port on the specified device to use.655* @qp_type: Specifies which QP traffic to snoop. Must be either656* IB_QPT_SMI or IB_QPT_GSI.657* @mad_snoop_flags: Specifies information where snooping occurs.658* @send_handler: The callback routine invoked for a snooped send.659* @recv_handler: The callback routine invoked for a snooped receive.660* @context: User specified context associated with the registration.661*/662struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,663u8 port_num,664enum ib_qp_type qp_type,665int mad_snoop_flags,666ib_mad_snoop_handler snoop_handler,667ib_mad_recv_handler recv_handler,668void *context);669670/**671* ib_unregister_mad_agent - Unregisters a client from using MAD services.672* @mad_agent: Corresponding MAD registration request to deregister.673*674* After invoking this routine, MAD services are no longer usable by the675* client on the associated QP.676*/677int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);678679/**680* ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated681* with the registered client.682* @send_buf: Specifies the information needed to send the MAD(s).683* @bad_send_buf: Specifies the MAD on which an error was encountered. This684* parameter is optional if only a single MAD is posted.685*686* Sent MADs are not guaranteed to complete in the order that they were posted.687*688* If the MAD requires RMPP, the data buffer should contain a single copy689* of the common MAD, RMPP, and class specific headers, followed by the class690* defined data. If the class defined data would not divide evenly into691* RMPP segments, then space must be allocated at the end of the referenced692* buffer for any required padding. To indicate the amount of class defined693* data being transferred, the paylen_newwin field in the RMPP header should694* be set to the size of the class specific header plus the amount of class695* defined data being transferred. The paylen_newwin field should be696* specified in network-byte order.697*/698int ib_post_send_mad(struct ib_mad_send_buf *send_buf,699struct ib_mad_send_buf **bad_send_buf);700701702/**703* ib_free_recv_mad - Returns data buffers used to receive a MAD.704* @mad_recv_wc: Work completion information for a received MAD.705*706* Clients receiving MADs through their ib_mad_recv_handler must call this707* routine to return the work completion buffers to the access layer.708*/709void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);710711/**712* ib_cancel_mad - Cancels an outstanding send MAD operation.713* @mad_agent: Specifies the registration associated with sent MAD.714* @send_buf: Indicates the MAD to cancel.715*716* MADs will be returned to the user through the corresponding717* ib_mad_send_handler.718*/719void ib_cancel_mad(struct ib_mad_agent *mad_agent,720struct ib_mad_send_buf *send_buf);721722/**723* ib_modify_mad - Modifies an outstanding send MAD operation.724* @mad_agent: Specifies the registration associated with sent MAD.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_agent *mad_agent,732struct ib_mad_send_buf *send_buf, u32 timeout_ms);733734/**735* ib_redirect_mad_qp - Registers a QP for MAD services.736* @qp: Reference to a QP that requires MAD services.737* @rmpp_version: If set, indicates that the client will send738* and receive MADs that contain the RMPP header for the given version.739* If set to 0, indicates that RMPP is not used by this client.740* @send_handler: The completion callback routine invoked after a send741* request has completed.742* @recv_handler: The completion callback routine invoked for a received743* MAD.744* @context: User specified context associated with the registration.745*746* Use of this call allows clients to use MAD services, such as RMPP,747* on user-owned QPs. After calling this routine, users may send748* MADs on the specified QP by calling ib_mad_post_send.749*/750struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,751u8 rmpp_version,752ib_mad_send_handler send_handler,753ib_mad_recv_handler recv_handler,754void *context);755756/**757* ib_process_mad_wc - Processes a work completion associated with a758* MAD sent or received on a redirected QP.759* @mad_agent: Specifies the registered MAD service using the redirected QP.760* @wc: References a work completion associated with a sent or received761* MAD segment.762*763* This routine is used to complete or continue processing on a MAD request.764* If the work completion is associated with a send operation, calling765* this routine is required to continue an RMPP transfer or to wait for a766* corresponding response, if it is a request. If the work completion is767* associated with a receive operation, calling this routine is required to768* process an inbound or outbound RMPP transfer, or to match a response MAD769* with its corresponding request.770*/771int ib_process_mad_wc(struct ib_mad_agent *mad_agent,772struct ib_wc *wc);773774/**775* ib_create_send_mad - Allocate and initialize a data buffer and work request776* for sending a MAD.777* @mad_agent: Specifies the registered MAD service to associate with the MAD.778* @remote_qpn: Specifies the QPN of the receiving node.779* @pkey_index: Specifies which PKey the MAD will be sent using. This field780* is valid only if the remote_qpn is QP 1.781* @rmpp_active: Indicates if the send will enable RMPP.782* @hdr_len: Indicates the size of the data header of the MAD. This length783* should include the common MAD header, RMPP header, plus any class784* specific header.785* @data_len: Indicates the size of any user-transferred data. The call will786* automatically adjust the allocated buffer size to account for any787* additional padding that may be necessary.788* @gfp_mask: GFP mask used for the memory allocation.789* @base_version: Base Version of this MAD790*791* This routine allocates a MAD for sending. The returned MAD send buffer792* will reference a data buffer usable for sending a MAD, along793* with an initialized work request structure. Users may modify the returned794* MAD data buffer before posting the send.795*796* The returned MAD header, class specific headers, and any padding will be797* cleared. Users are responsible for initializing the common MAD header,798* any class specific header, and MAD data area.799* If @rmpp_active is set, the RMPP header will be initialized for sending.800*/801struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,802u32 remote_qpn, u16 pkey_index,803int rmpp_active,804int hdr_len, int data_len,805gfp_t gfp_mask,806u8 base_version);807808/**809* ib_is_mad_class_rmpp - returns whether given management class810* supports RMPP.811* @mgmt_class: management class812*813* This routine returns whether the management class supports RMPP.814*/815int ib_is_mad_class_rmpp(u8 mgmt_class);816817/**818* ib_get_mad_data_offset - returns the data offset for a given819* management class.820* @mgmt_class: management class821*822* This routine returns the data offset in the MAD for the management823* class requested.824*/825int ib_get_mad_data_offset(u8 mgmt_class);826827/**828* ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.829* @send_buf: Previously allocated send data buffer.830* @seg_num: number of segment to return831*832* This routine returns a pointer to the data buffer of an RMPP MAD.833* Users must provide synchronization to @send_buf around this call.834*/835void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);836837/**838* ib_free_send_mad - Returns data buffers used to send a MAD.839* @send_buf: Previously allocated send data buffer.840*/841void ib_free_send_mad(struct ib_mad_send_buf *send_buf);842843/**844* ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.845* @agent: the agent in question846* @return: true if agent is performing rmpp, false otherwise.847*/848int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);849850#endif /* IB_MAD_H */851852853