Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
0002 /*
0003  * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
0004  * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
0005  * Copyright (c) 2004 Intel Corporation.  All rights reserved.
0006  * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
0007  * Copyright (c) 2004-2006 Voltaire Corporation.  All rights reserved.
0008  */
0009 
0010 #ifndef IB_MAD_H
0011 #define IB_MAD_H
0012 
0013 #include <linux/list.h>
0014 
0015 #include <rdma/ib_verbs.h>
0016 #include <uapi/rdma/ib_user_mad.h>
0017 
0018 /* Management base versions */
0019 #define IB_MGMT_BASE_VERSION            1
0020 #define OPA_MGMT_BASE_VERSION           0x80
0021 
0022 #define OPA_SM_CLASS_VERSION            0x80
0023 
0024 /* Management classes */
0025 #define IB_MGMT_CLASS_SUBN_LID_ROUTED       0x01
0026 #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE   0x81
0027 #define IB_MGMT_CLASS_SUBN_ADM          0x03
0028 #define IB_MGMT_CLASS_PERF_MGMT         0x04
0029 #define IB_MGMT_CLASS_BM            0x05
0030 #define IB_MGMT_CLASS_DEVICE_MGMT       0x06
0031 #define IB_MGMT_CLASS_CM            0x07
0032 #define IB_MGMT_CLASS_SNMP          0x08
0033 #define IB_MGMT_CLASS_DEVICE_ADM        0x10
0034 #define IB_MGMT_CLASS_BOOT_MGMT         0x11
0035 #define IB_MGMT_CLASS_BIS           0x12
0036 #define IB_MGMT_CLASS_CONG_MGMT         0x21
0037 #define IB_MGMT_CLASS_VENDOR_RANGE2_START   0x30
0038 #define IB_MGMT_CLASS_VENDOR_RANGE2_END     0x4F
0039 
0040 #define IB_OPENIB_OUI               (0x001405)
0041 
0042 /* Management methods */
0043 #define IB_MGMT_METHOD_GET          0x01
0044 #define IB_MGMT_METHOD_SET          0x02
0045 #define IB_MGMT_METHOD_GET_RESP         0x81
0046 #define IB_MGMT_METHOD_SEND         0x03
0047 #define IB_MGMT_METHOD_TRAP         0x05
0048 #define IB_MGMT_METHOD_REPORT           0x06
0049 #define IB_MGMT_METHOD_REPORT_RESP      0x86
0050 #define IB_MGMT_METHOD_TRAP_REPRESS     0x07
0051 
0052 #define IB_MGMT_METHOD_RESP         0x80
0053 #define IB_BM_ATTR_MOD_RESP         cpu_to_be32(1)
0054 
0055 #define IB_MGMT_MAX_METHODS         128
0056 
0057 /* MAD Status field bit masks */
0058 #define IB_MGMT_MAD_STATUS_SUCCESS          0x0000
0059 #define IB_MGMT_MAD_STATUS_BUSY             0x0001
0060 #define IB_MGMT_MAD_STATUS_REDIRECT_REQD        0x0002
0061 #define IB_MGMT_MAD_STATUS_BAD_VERSION          0x0004
0062 #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD       0x0008
0063 #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB    0x000c
0064 #define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE     0x001c
0065 
0066 /* RMPP information */
0067 #define IB_MGMT_RMPP_VERSION            1
0068 
0069 #define IB_MGMT_RMPP_TYPE_DATA          1
0070 #define IB_MGMT_RMPP_TYPE_ACK           2
0071 #define IB_MGMT_RMPP_TYPE_STOP          3
0072 #define IB_MGMT_RMPP_TYPE_ABORT         4
0073 
0074 #define IB_MGMT_RMPP_FLAG_ACTIVE        1
0075 #define IB_MGMT_RMPP_FLAG_FIRST         (1<<1)
0076 #define IB_MGMT_RMPP_FLAG_LAST          (1<<2)
0077 
0078 #define IB_MGMT_RMPP_NO_RESPTIME        0x1F
0079 
0080 #define IB_MGMT_RMPP_STATUS_SUCCESS     0
0081 #define IB_MGMT_RMPP_STATUS_RESX        1
0082 #define IB_MGMT_RMPP_STATUS_ABORT_MIN       118
0083 #define IB_MGMT_RMPP_STATUS_T2L         118
0084 #define IB_MGMT_RMPP_STATUS_BAD_LEN     119
0085 #define IB_MGMT_RMPP_STATUS_BAD_SEG     120
0086 #define IB_MGMT_RMPP_STATUS_BADT        121
0087 #define IB_MGMT_RMPP_STATUS_W2S         122
0088 #define IB_MGMT_RMPP_STATUS_S2B         123
0089 #define IB_MGMT_RMPP_STATUS_BAD_STATUS      124
0090 #define IB_MGMT_RMPP_STATUS_UNV         125
0091 #define IB_MGMT_RMPP_STATUS_TMR         126
0092 #define IB_MGMT_RMPP_STATUS_UNSPEC      127
0093 #define IB_MGMT_RMPP_STATUS_ABORT_MAX       127
0094 
0095 #define IB_QP0      0
0096 #define IB_QP1      cpu_to_be32(1)
0097 #define IB_QP1_QKEY 0x80010000
0098 #define IB_QP_SET_QKEY  0x80000000
0099 
0100 #define IB_DEFAULT_PKEY_PARTIAL 0x7FFF
0101 #define IB_DEFAULT_PKEY_FULL    0xFFFF
0102 
0103 /*
0104  * Generic trap/notice types
0105  */
0106 #define IB_NOTICE_TYPE_FATAL    0x80
0107 #define IB_NOTICE_TYPE_URGENT   0x81
0108 #define IB_NOTICE_TYPE_SECURITY 0x82
0109 #define IB_NOTICE_TYPE_SM   0x83
0110 #define IB_NOTICE_TYPE_INFO 0x84
0111 
0112 /*
0113  * Generic trap/notice producers
0114  */
0115 #define IB_NOTICE_PROD_CA       cpu_to_be16(1)
0116 #define IB_NOTICE_PROD_SWITCH       cpu_to_be16(2)
0117 #define IB_NOTICE_PROD_ROUTER       cpu_to_be16(3)
0118 #define IB_NOTICE_PROD_CLASS_MGR    cpu_to_be16(4)
0119 
0120 enum {
0121     IB_MGMT_MAD_HDR = 24,
0122     IB_MGMT_MAD_DATA = 232,
0123     IB_MGMT_RMPP_HDR = 36,
0124     IB_MGMT_RMPP_DATA = 220,
0125     IB_MGMT_VENDOR_HDR = 40,
0126     IB_MGMT_VENDOR_DATA = 216,
0127     IB_MGMT_SA_HDR = 56,
0128     IB_MGMT_SA_DATA = 200,
0129     IB_MGMT_DEVICE_HDR = 64,
0130     IB_MGMT_DEVICE_DATA = 192,
0131     IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,
0132     OPA_MGMT_MAD_DATA = 2024,
0133     OPA_MGMT_RMPP_DATA = 2012,
0134     OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,
0135 };
0136 
0137 struct ib_mad_hdr {
0138     u8  base_version;
0139     u8  mgmt_class;
0140     u8  class_version;
0141     u8  method;
0142     __be16  status;
0143     __be16  class_specific;
0144     __be64  tid;
0145     __be16  attr_id;
0146     __be16  resv;
0147     __be32  attr_mod;
0148 };
0149 
0150 struct ib_rmpp_hdr {
0151     u8  rmpp_version;
0152     u8  rmpp_type;
0153     u8  rmpp_rtime_flags;
0154     u8  rmpp_status;
0155     __be32  seg_num;
0156     __be32  paylen_newwin;
0157 };
0158 
0159 typedef u64 __bitwise ib_sa_comp_mask;
0160 
0161 #define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))
0162 
0163 /*
0164  * ib_sa_hdr and ib_sa_mad structures must be packed because they have
0165  * 64-bit fields that are only 32-bit aligned. 64-bit architectures will
0166  * lay them out wrong otherwise.  (And unfortunately they are sent on
0167  * the wire so we can't change the layout)
0168  */
0169 struct ib_sa_hdr {
0170     __be64          sm_key;
0171     __be16          attr_offset;
0172     __be16          reserved;
0173     ib_sa_comp_mask     comp_mask;
0174 } __packed;
0175 
0176 struct ib_mad {
0177     struct ib_mad_hdr   mad_hdr;
0178     u8          data[IB_MGMT_MAD_DATA];
0179 };
0180 
0181 struct opa_mad {
0182     struct ib_mad_hdr   mad_hdr;
0183     u8          data[OPA_MGMT_MAD_DATA];
0184 };
0185 
0186 struct ib_rmpp_mad {
0187     struct ib_mad_hdr   mad_hdr;
0188     struct ib_rmpp_hdr  rmpp_hdr;
0189     u8          data[IB_MGMT_RMPP_DATA];
0190 };
0191 
0192 struct opa_rmpp_mad {
0193     struct ib_mad_hdr   mad_hdr;
0194     struct ib_rmpp_hdr  rmpp_hdr;
0195     u8          data[OPA_MGMT_RMPP_DATA];
0196 };
0197 
0198 struct ib_sa_mad {
0199     struct ib_mad_hdr   mad_hdr;
0200     struct ib_rmpp_hdr  rmpp_hdr;
0201     struct ib_sa_hdr    sa_hdr;
0202     u8          data[IB_MGMT_SA_DATA];
0203 } __packed;
0204 
0205 struct ib_vendor_mad {
0206     struct ib_mad_hdr   mad_hdr;
0207     struct ib_rmpp_hdr  rmpp_hdr;
0208     u8          reserved;
0209     u8          oui[3];
0210     u8          data[IB_MGMT_VENDOR_DATA];
0211 };
0212 
0213 #define IB_MGMT_CLASSPORTINFO_ATTR_ID   cpu_to_be16(0x0001)
0214 
0215 #define IB_CLASS_PORT_INFO_RESP_TIME_MASK   0x1F
0216 #define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5
0217 
0218 struct ib_class_port_info {
0219     u8          base_version;
0220     u8          class_version;
0221     __be16          capability_mask;
0222       /* 27 bits for cap_mask2, 5 bits for resp_time */
0223     __be32          cap_mask2_resp_time;
0224     u8          redirect_gid[16];
0225     __be32          redirect_tcslfl;
0226     __be16          redirect_lid;
0227     __be16          redirect_pkey;
0228     __be32          redirect_qp;
0229     __be32          redirect_qkey;
0230     u8          trap_gid[16];
0231     __be32          trap_tcslfl;
0232     __be16          trap_lid;
0233     __be16          trap_pkey;
0234     __be32          trap_hlqp;
0235     __be32          trap_qkey;
0236 };
0237 
0238 /* PortInfo CapabilityMask */
0239 enum ib_port_capability_mask_bits {
0240     IB_PORT_SM = 1 << 1,
0241     IB_PORT_NOTICE_SUP = 1 << 2,
0242     IB_PORT_TRAP_SUP = 1 << 3,
0243     IB_PORT_OPT_IPD_SUP = 1 << 4,
0244     IB_PORT_AUTO_MIGR_SUP = 1 << 5,
0245     IB_PORT_SL_MAP_SUP = 1 << 6,
0246     IB_PORT_MKEY_NVRAM = 1 << 7,
0247     IB_PORT_PKEY_NVRAM = 1 << 8,
0248     IB_PORT_LED_INFO_SUP = 1 << 9,
0249     IB_PORT_SM_DISABLED = 1 << 10,
0250     IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
0251     IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
0252     IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
0253     IB_PORT_CAP_MASK2_SUP = 1 << 15,
0254     IB_PORT_CM_SUP = 1 << 16,
0255     IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
0256     IB_PORT_REINIT_SUP = 1 << 18,
0257     IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
0258     IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
0259     IB_PORT_DR_NOTICE_SUP = 1 << 21,
0260     IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
0261     IB_PORT_BOOT_MGMT_SUP = 1 << 23,
0262     IB_PORT_LINK_LATENCY_SUP = 1 << 24,
0263     IB_PORT_CLIENT_REG_SUP = 1 << 25,
0264     IB_PORT_OTHER_LOCAL_CHANGES_SUP = 1 << 26,
0265     IB_PORT_LINK_SPEED_WIDTH_TABLE_SUP = 1 << 27,
0266     IB_PORT_VENDOR_SPECIFIC_MADS_TABLE_SUP = 1 << 28,
0267     IB_PORT_MCAST_PKEY_TRAP_SUPPRESSION_SUP = 1 << 29,
0268     IB_PORT_MCAST_FDB_TOP_SUP = 1 << 30,
0269     IB_PORT_HIERARCHY_INFO_SUP = 1ULL << 31,
0270 };
0271 
0272 enum ib_port_capability_mask2_bits {
0273     IB_PORT_SET_NODE_DESC_SUP       = 1 << 0,
0274     IB_PORT_EX_PORT_INFO_EX_SUP     = 1 << 1,
0275     IB_PORT_VIRT_SUP            = 1 << 2,
0276     IB_PORT_SWITCH_PORT_STATE_TABLE_SUP = 1 << 3,
0277     IB_PORT_LINK_WIDTH_2X_SUP       = 1 << 4,
0278     IB_PORT_LINK_SPEED_HDR_SUP      = 1 << 5,
0279     IB_PORT_LINK_SPEED_NDR_SUP      = 1 << 10,
0280 };
0281 
0282 #define OPA_CLASS_PORT_INFO_PR_SUPPORT BIT(26)
0283 
0284 struct opa_class_port_info {
0285     u8 base_version;
0286     u8 class_version;
0287     __be16 cap_mask;
0288     __be32 cap_mask2_resp_time;
0289 
0290     u8 redirect_gid[16];
0291     __be32 redirect_tc_fl;
0292     __be32 redirect_lid;
0293     __be32 redirect_sl_qp;
0294     __be32 redirect_qkey;
0295 
0296     u8 trap_gid[16];
0297     __be32 trap_tc_fl;
0298     __be32 trap_lid;
0299     __be32 trap_hl_qp;
0300     __be32 trap_qkey;
0301 
0302     __be16 trap_pkey;
0303     __be16 redirect_pkey;
0304 
0305     u8 trap_sl_rsvd;
0306     u8 reserved[3];
0307 } __packed;
0308 
0309 /**
0310  * ib_get_cpi_resp_time - Returns the resp_time value from
0311  * cap_mask2_resp_time in ib_class_port_info.
0312  * @cpi: A struct ib_class_port_info mad.
0313  */
0314 static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)
0315 {
0316     return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &
0317             IB_CLASS_PORT_INFO_RESP_TIME_MASK);
0318 }
0319 
0320 /**
0321  * ib_set_cpi_resptime - Sets the response time in an
0322  * ib_class_port_info mad.
0323  * @cpi: A struct ib_class_port_info.
0324  * @rtime: The response time to set.
0325  */
0326 static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,
0327                     u8 rtime)
0328 {
0329     cpi->cap_mask2_resp_time =
0330         (cpi->cap_mask2_resp_time &
0331          cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
0332         cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);
0333 }
0334 
0335 /**
0336  * ib_get_cpi_capmask2 - Returns the capmask2 value from
0337  * cap_mask2_resp_time in ib_class_port_info.
0338  * @cpi: A struct ib_class_port_info mad.
0339  */
0340 static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)
0341 {
0342     return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
0343         IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
0344 }
0345 
0346 /**
0347  * ib_set_cpi_capmask2 - Sets the capmask2 in an
0348  * ib_class_port_info mad.
0349  * @cpi: A struct ib_class_port_info.
0350  * @capmask2: The capmask2 to set.
0351  */
0352 static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,
0353                        u32 capmask2)
0354 {
0355     cpi->cap_mask2_resp_time =
0356         (cpi->cap_mask2_resp_time &
0357          cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
0358         cpu_to_be32(capmask2 <<
0359                 IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
0360 }
0361 
0362 /**
0363  * opa_get_cpi_capmask2 - Returns the capmask2 value from
0364  * cap_mask2_resp_time in ib_class_port_info.
0365  * @cpi: A struct opa_class_port_info mad.
0366  */
0367 static inline u32 opa_get_cpi_capmask2(struct opa_class_port_info *cpi)
0368 {
0369     return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
0370         IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
0371 }
0372 
0373 struct ib_mad_notice_attr {
0374     u8 generic_type;
0375     u8 prod_type_msb;
0376     __be16 prod_type_lsb;
0377     __be16 trap_num;
0378     __be16 issuer_lid;
0379     __be16 toggle_count;
0380 
0381     union {
0382         struct {
0383             u8  details[54];
0384         } raw_data;
0385 
0386         struct {
0387             __be16  reserved;
0388             __be16  lid;        /* where violation happened */
0389             u8  port_num;   /* where violation happened */
0390         } __packed ntc_129_131;
0391 
0392         struct {
0393             __be16  reserved;
0394             __be16  lid;        /* LID where change occurred */
0395             u8  reserved2;
0396             u8  local_changes;  /* low bit - local changes */
0397             __be32  new_cap_mask;   /* new capability mask */
0398             u8  reserved3;
0399             u8  change_flags;   /* low 3 bits only */
0400         } __packed ntc_144;
0401 
0402         struct {
0403             __be16  reserved;
0404             __be16  lid;        /* lid where sys guid changed */
0405             __be16  reserved2;
0406             __be64  new_sys_guid;
0407         } __packed ntc_145;
0408 
0409         struct {
0410             __be16  reserved;
0411             __be16  lid;
0412             __be16  dr_slid;
0413             u8  method;
0414             u8  reserved2;
0415             __be16  attr_id;
0416             __be32  attr_mod;
0417             __be64  mkey;
0418             u8  reserved3;
0419             u8  dr_trunc_hop;
0420             u8  dr_rtn_path[30];
0421         } __packed ntc_256;
0422 
0423         struct {
0424             __be16      reserved;
0425             __be16      lid1;
0426             __be16      lid2;
0427             __be32      key;
0428             __be32      sl_qp1; /* SL: high 4 bits */
0429             __be32      qp2;    /* high 8 bits reserved */
0430             union ib_gid    gid1;
0431             union ib_gid    gid2;
0432         } __packed ntc_257_258;
0433 
0434     } details;
0435 };
0436 
0437 /**
0438  * ib_mad_send_buf - MAD data buffer and work request for sends.
0439  * @next: A pointer used to chain together MADs for posting.
0440  * @mad: References an allocated MAD data buffer for MADs that do not have
0441  *   RMPP active.  For MADs using RMPP, references the common and management
0442  *   class specific headers.
0443  * @mad_agent: MAD agent that allocated the buffer.
0444  * @ah: The address handle to use when sending the MAD.
0445  * @context: User-controlled context fields.
0446  * @hdr_len: Indicates the size of the data header of the MAD.  This length
0447  *   includes the common MAD, RMPP, and class specific headers.
0448  * @data_len: Indicates the total size of user-transferred data.
0449  * @seg_count: The number of RMPP segments allocated for this send.
0450  * @seg_size: Size of the data in each RMPP segment.  This does not include
0451  *   class specific headers.
0452  * @seg_rmpp_size: Size of each RMPP segment including the class specific
0453  *   headers.
0454  * @timeout_ms: Time to wait for a response.
0455  * @retries: Number of times to retry a request for a response.  For MADs
0456  *   using RMPP, this applies per window.  On completion, returns the number
0457  *   of retries needed to complete the transfer.
0458  *
0459  * Users are responsible for initializing the MAD buffer itself, with the
0460  * exception of any RMPP header.  Additional segment buffer space allocated
0461  * beyond data_len is padding.
0462  */
0463 struct ib_mad_send_buf {
0464     struct ib_mad_send_buf  *next;
0465     void            *mad;
0466     struct ib_mad_agent *mad_agent;
0467     struct ib_ah        *ah;
0468     void            *context[2];
0469     int         hdr_len;
0470     int         data_len;
0471     int         seg_count;
0472     int         seg_size;
0473     int         seg_rmpp_size;
0474     int         timeout_ms;
0475     int         retries;
0476 };
0477 
0478 /**
0479  * ib_response_mad - Returns if the specified MAD has been generated in
0480  *   response to a sent request or trap.
0481  */
0482 int ib_response_mad(const struct ib_mad_hdr *hdr);
0483 
0484 /**
0485  * ib_get_rmpp_resptime - Returns the RMPP response time.
0486  * @rmpp_hdr: An RMPP header.
0487  */
0488 static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)
0489 {
0490     return rmpp_hdr->rmpp_rtime_flags >> 3;
0491 }
0492 
0493 /**
0494  * ib_get_rmpp_flags - Returns the RMPP flags.
0495  * @rmpp_hdr: An RMPP header.
0496  */
0497 static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)
0498 {
0499     return rmpp_hdr->rmpp_rtime_flags & 0x7;
0500 }
0501 
0502 /**
0503  * ib_set_rmpp_resptime - Sets the response time in an RMPP header.
0504  * @rmpp_hdr: An RMPP header.
0505  * @rtime: The response time to set.
0506  */
0507 static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)
0508 {
0509     rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);
0510 }
0511 
0512 /**
0513  * ib_set_rmpp_flags - Sets the flags in an RMPP header.
0514  * @rmpp_hdr: An RMPP header.
0515  * @flags: The flags to set.
0516  */
0517 static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)
0518 {
0519     rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |
0520                      (flags & 0x7);
0521 }
0522 
0523 struct ib_mad_agent;
0524 struct ib_mad_send_wc;
0525 struct ib_mad_recv_wc;
0526 
0527 /**
0528  * ib_mad_send_handler - callback handler for a sent MAD.
0529  * @mad_agent: MAD agent that sent the MAD.
0530  * @mad_send_wc: Send work completion information on the sent MAD.
0531  */
0532 typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
0533                     struct ib_mad_send_wc *mad_send_wc);
0534 
0535 /**
0536  * ib_mad_recv_handler - callback handler for a received MAD.
0537  * @mad_agent: MAD agent requesting the received MAD.
0538  * @send_buf: Send buffer if found, else NULL
0539  * @mad_recv_wc: Received work completion information on the received MAD.
0540  *
0541  * MADs received in response to a send request operation will be handed to
0542  * the user before the send operation completes.  All data buffers given
0543  * to registered agents through this routine are owned by the receiving
0544  * client.
0545  */
0546 typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
0547                     struct ib_mad_send_buf *send_buf,
0548                     struct ib_mad_recv_wc *mad_recv_wc);
0549 
0550 /**
0551  * ib_mad_agent - Used to track MAD registration with the access layer.
0552  * @device: Reference to device registration is on.
0553  * @qp: Reference to QP used for sending and receiving MADs.
0554  * @mr: Memory region for system memory usable for DMA.
0555  * @recv_handler: Callback handler for a received MAD.
0556  * @send_handler: Callback handler for a sent MAD.
0557  * @context: User-specified context associated with this registration.
0558  * @hi_tid: Access layer assigned transaction ID for this client.
0559  *   Unsolicited MADs sent by this client will have the upper 32-bits
0560  *   of their TID set to this value.
0561  * @flags: registration flags
0562  * @port_num: Port number on which QP is registered
0563  * @rmpp_version: If set, indicates the RMPP version used by this agent.
0564  */
0565 enum {
0566     IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,
0567 };
0568 struct ib_mad_agent {
0569     struct ib_device    *device;
0570     struct ib_qp        *qp;
0571     ib_mad_recv_handler recv_handler;
0572     ib_mad_send_handler send_handler;
0573     void            *context;
0574     u32         hi_tid;
0575     u32         flags;
0576     void            *security;
0577     struct list_head    mad_agent_sec_list;
0578     u8          port_num;
0579     u8          rmpp_version;
0580     bool            smp_allowed;
0581 };
0582 
0583 /**
0584  * ib_mad_send_wc - MAD send completion information.
0585  * @send_buf: Send MAD data buffer associated with the send MAD request.
0586  * @status: Completion status.
0587  * @vendor_err: Optional vendor error information returned with a failed
0588  *   request.
0589  */
0590 struct ib_mad_send_wc {
0591     struct ib_mad_send_buf  *send_buf;
0592     enum ib_wc_status   status;
0593     u32         vendor_err;
0594 };
0595 
0596 /**
0597  * ib_mad_recv_buf - received MAD buffer information.
0598  * @list: Reference to next data buffer for a received RMPP MAD.
0599  * @grh: References a data buffer containing the global route header.
0600  *   The data refereced by this buffer is only valid if the GRH is
0601  *   valid.
0602  * @mad: References the start of the received MAD.
0603  */
0604 struct ib_mad_recv_buf {
0605     struct list_head    list;
0606     struct ib_grh       *grh;
0607     union {
0608         struct ib_mad   *mad;
0609         struct opa_mad  *opa_mad;
0610     };
0611 };
0612 
0613 /**
0614  * ib_mad_recv_wc - received MAD information.
0615  * @wc: Completion information for the received data.
0616  * @recv_buf: Specifies the location of the received data buffer(s).
0617  * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.
0618  * @mad_len: The length of the received MAD, without duplicated headers.
0619  * @mad_seg_size: The size of individual MAD segments
0620  *
0621  * For received response, the wr_id contains a pointer to the ib_mad_send_buf
0622  *   for the corresponding send request.
0623  */
0624 struct ib_mad_recv_wc {
0625     struct ib_wc        *wc;
0626     struct ib_mad_recv_buf  recv_buf;
0627     struct list_head    rmpp_list;
0628     int         mad_len;
0629     size_t          mad_seg_size;
0630 };
0631 
0632 /**
0633  * ib_mad_reg_req - MAD registration request
0634  * @mgmt_class: Indicates which management class of MADs should be receive
0635  *   by the caller.  This field is only required if the user wishes to
0636  *   receive unsolicited MADs, otherwise it should be 0.
0637  * @mgmt_class_version: Indicates which version of MADs for the given
0638  *   management class to receive.
0639  * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
0640  *   in the range from 0x30 to 0x4f. Otherwise not used.
0641  * @method_mask: The caller will receive unsolicited MADs for any method
0642  *   where @method_mask = 1.
0643  *
0644  */
0645 struct ib_mad_reg_req {
0646     u8  mgmt_class;
0647     u8  mgmt_class_version;
0648     u8  oui[3];
0649     DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
0650 };
0651 
0652 /**
0653  * ib_register_mad_agent - Register to send/receive MADs.
0654  * @device: The device to register with.
0655  * @port_num: The port on the specified device to use.
0656  * @qp_type: Specifies which QP to access.  Must be either
0657  *   IB_QPT_SMI or IB_QPT_GSI.
0658  * @mad_reg_req: Specifies which unsolicited MADs should be received
0659  *   by the caller.  This parameter may be NULL if the caller only
0660  *   wishes to receive solicited responses.
0661  * @rmpp_version: If set, indicates that the client will send
0662  *   and receive MADs that contain the RMPP header for the given version.
0663  *   If set to 0, indicates that RMPP is not used by this client.
0664  * @send_handler: The completion callback routine invoked after a send
0665  *   request has completed.
0666  * @recv_handler: The completion callback routine invoked for a received
0667  *   MAD.
0668  * @context: User specified context associated with the registration.
0669  * @registration_flags: Registration flags to set for this agent
0670  */
0671 struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
0672                        u32 port_num,
0673                        enum ib_qp_type qp_type,
0674                        struct ib_mad_reg_req *mad_reg_req,
0675                        u8 rmpp_version,
0676                        ib_mad_send_handler send_handler,
0677                        ib_mad_recv_handler recv_handler,
0678                        void *context,
0679                        u32 registration_flags);
0680 /**
0681  * ib_unregister_mad_agent - Unregisters a client from using MAD services.
0682  * @mad_agent: Corresponding MAD registration request to deregister.
0683  *
0684  * After invoking this routine, MAD services are no longer usable by the
0685  * client on the associated QP.
0686  */
0687 void ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
0688 
0689 /**
0690  * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
0691  *   with the registered client.
0692  * @send_buf: Specifies the information needed to send the MAD(s).
0693  * @bad_send_buf: Specifies the MAD on which an error was encountered.  This
0694  *   parameter is optional if only a single MAD is posted.
0695  *
0696  * Sent MADs are not guaranteed to complete in the order that they were posted.
0697  *
0698  * If the MAD requires RMPP, the data buffer should contain a single copy
0699  * of the common MAD, RMPP, and class specific headers, followed by the class
0700  * defined data.  If the class defined data would not divide evenly into
0701  * RMPP segments, then space must be allocated at the end of the referenced
0702  * buffer for any required padding.  To indicate the amount of class defined
0703  * data being transferred, the paylen_newwin field in the RMPP header should
0704  * be set to the size of the class specific header plus the amount of class
0705  * defined data being transferred.  The paylen_newwin field should be
0706  * specified in network-byte order.
0707  */
0708 int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
0709              struct ib_mad_send_buf **bad_send_buf);
0710 
0711 
0712 /**
0713  * ib_free_recv_mad - Returns data buffers used to receive a MAD.
0714  * @mad_recv_wc: Work completion information for a received MAD.
0715  *
0716  * Clients receiving MADs through their ib_mad_recv_handler must call this
0717  * routine to return the work completion buffers to the access layer.
0718  */
0719 void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
0720 
0721 /**
0722  * ib_modify_mad - Modifies an outstanding send MAD operation.
0723  * @send_buf: Indicates the MAD to modify.
0724  * @timeout_ms: New timeout value for sent MAD.
0725  *
0726  * This call will reset the timeout value for a sent MAD to the specified
0727  * value.
0728  */
0729 int ib_modify_mad(struct ib_mad_send_buf *send_buf, u32 timeout_ms);
0730 
0731 /**
0732  * ib_cancel_mad - Cancels an outstanding send MAD operation.
0733  * @send_buf: Indicates the MAD to cancel.
0734  *
0735  * MADs will be returned to the user through the corresponding
0736  * ib_mad_send_handler.
0737  */
0738 static inline void ib_cancel_mad(struct ib_mad_send_buf *send_buf)
0739 {
0740     ib_modify_mad(send_buf, 0);
0741 }
0742 
0743 /**
0744  * ib_create_send_mad - Allocate and initialize a data buffer and work request
0745  *   for sending a MAD.
0746  * @mad_agent: Specifies the registered MAD service to associate with the MAD.
0747  * @remote_qpn: Specifies the QPN of the receiving node.
0748  * @pkey_index: Specifies which PKey the MAD will be sent using.  This field
0749  *   is valid only if the remote_qpn is QP 1.
0750  * @rmpp_active: Indicates if the send will enable RMPP.
0751  * @hdr_len: Indicates the size of the data header of the MAD.  This length
0752  *   should include the common MAD header, RMPP header, plus any class
0753  *   specific header.
0754  * @data_len: Indicates the size of any user-transferred data.  The call will
0755  *   automatically adjust the allocated buffer size to account for any
0756  *   additional padding that may be necessary.
0757  * @gfp_mask: GFP mask used for the memory allocation.
0758  * @base_version: Base Version of this MAD
0759  *
0760  * This routine allocates a MAD for sending.  The returned MAD send buffer
0761  * will reference a data buffer usable for sending a MAD, along
0762  * with an initialized work request structure.  Users may modify the returned
0763  * MAD data buffer before posting the send.
0764  *
0765  * The returned MAD header, class specific headers, and any padding will be
0766  * cleared.  Users are responsible for initializing the common MAD header,
0767  * any class specific header, and MAD data area.
0768  * If @rmpp_active is set, the RMPP header will be initialized for sending.
0769  */
0770 struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,
0771                        u32 remote_qpn, u16 pkey_index,
0772                        int rmpp_active,
0773                        int hdr_len, int data_len,
0774                        gfp_t gfp_mask,
0775                        u8 base_version);
0776 
0777 /**
0778  * ib_is_mad_class_rmpp - returns whether given management class
0779  * supports RMPP.
0780  * @mgmt_class: management class
0781  *
0782  * This routine returns whether the management class supports RMPP.
0783  */
0784 int ib_is_mad_class_rmpp(u8 mgmt_class);
0785 
0786 /**
0787  * ib_get_mad_data_offset - returns the data offset for a given
0788  * management class.
0789  * @mgmt_class: management class
0790  *
0791  * This routine returns the data offset in the MAD for the management
0792  * class requested.
0793  */
0794 int ib_get_mad_data_offset(u8 mgmt_class);
0795 
0796 /**
0797  * ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.
0798  * @send_buf: Previously allocated send data buffer.
0799  * @seg_num: number of segment to return
0800  *
0801  * This routine returns a pointer to the data buffer of an RMPP MAD.
0802  * Users must provide synchronization to @send_buf around this call.
0803  */
0804 void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);
0805 
0806 /**
0807  * ib_free_send_mad - Returns data buffers used to send a MAD.
0808  * @send_buf: Previously allocated send data buffer.
0809  */
0810 void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
0811 
0812 /**
0813  * ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.
0814  * @agent: the agent in question
0815  * @return: true if agent is performing rmpp, false otherwise.
0816  */
0817 int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);
0818 
0819 #endif /* IB_MAD_H */