/* BEGIN_ICS_COPYRIGHT3 **************************************** Copyright (c) 2015-2017, Intel Corporation Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** END_ICS_COPYRIGHT3 ****************************************/ /* [ICS VERSION STRING: unknown] */ #ifndef __IBA_IB_MAD_H__ #define __IBA_IB_MAD_H__ #include "iba/public/datatypes.h" /* Ths should be removed from here */ #include "iba/stl_types.h" #include "iba/public/ibyteswap.h" #include "iba/public/imemory.h" #if defined (__cplusplus) extern "C" { #endif #include "iba/public/ipackon.h" /* -------------------------------------------------------------------------- * Defines */ // convert a 0-N bit number to a index and uint8 mask for access to // multi-byte fields which are stored as uint8[] arrays for long bit masks // Note for uint16, uint32 bytes, byte swapping has already been done so // simple (1<common.mr.s.R == 0 \ && (mad)->common.mr.s.Method != MMTHD_TRAP_REPRESS \ && (mad)->common.mr.s.Method != MMTHD_SEND) \ || (((mad)->common.MgmtClass == MCLASS_BM) && \ ( (mad)->common.mr.s.Method == MMTHD_SEND && !((mad)->common.AttributeModifier & BM_ATTRIB_MOD_RESPONSE)))) /* mads for which a GET_RESP should be returned if validation fails */ #define MAD_EXPECT_GET_RESP(mad) \ ((mad)->common.mr.s.R == 0 \ && ((mad)->common.mr.s.Method == MMTHD_GET \ || (mad)->common.mr.s.Method == MMTHD_SET)) /* could optimize and skip MMTHD_SEND test below since R=1 -> != SEND * however we play it safe in case remote node fails to initialize * R bit for a SEND message. */ #define MAD_IS_RESPONSE(mad) \ ((((mad)->common.mr.s.R \ || (mad)->common.mr.s.Method == MMTHD_TRAP_REPRESS) \ && (mad)->common.mr.s.Method != MMTHD_SEND) \ || (((mad)->common.MgmtClass == MCLASS_BM) && \ ((mad)->common.mr.s.Method == MMTHD_SEND && ((mad)->common.AttributeModifier & BM_ATTRIB_MOD_RESPONSE)))) /* SENDs are technically a 3rd type, not necessarily a request nor response */ #define MAD_IS_SEND(mad) \ ((mad)->common.mr.s.Method == MMTHD_SEND) #define MAD_SET_VERSION_INFO(mad, base_ver, mgmt_class, class_ver) {\ (mad)->common.BaseVersion = base_ver; \ (mad)->common.MgmtClass = mgmt_class; \ (mad)->common.ClassVersion = class_ver; \ } #define MAD_GET_VERSION_INFO(mad, base_ver, mgmt_class, class_ver) {\ (*base_ver) = (mad)->common.BaseVersion; \ (*mgmt_class) = (mad)->common.MgmtClass; \ (*class_ver) = (mad)->common.ClassVersion; \ } #define MAD_GET_STATUS(mad, status) {\ (*status) = (mad)->common.u.NS.Status; \ } #define MAD_SET_TRANSACTION_ID(mad, id) {\ (mad)->common.TransactionID = id; \ } #define MAD_GET_TRANSACTION_ID(mad, id) {\ (*id) = (mad)->common.TransactionID; \ } #define MAD_SET_ATTRIB_ID(mad, id) {\ (mad)->common.AttributeID = id; \ } #define MAD_GET_ATTRIB_ID(mad, id) {\ (*id) = (mad)->common.AttributeID; \ } #define MAD_SET_ATTRIB_MOD(mad, amod) {\ (mad)->common.AttributeModifier = amod; \ } #define MAD_GET_ATTRIB_MOD(mad, amod) {\ (*amod) = (mad)->common.AttributeModifier; \ } #define MAD_SET_METHOD_TYPE(mad, method) {\ (mad)->common.mr.s.Method = method; \ } #define MAD_GET_METHOD_TYPE(mad, method) {\ (*method) = (mad)->common.mr.s.Method; \ } /* * ClassPortInfo */ /* CapMask common bits */ #define CLASS_PORT_CAPMASK_TRAP 0x0001 /* can generate traps */ #define CLASS_PORT_CAPMASK_NOTICE 0x0002 /* implements Get/Set Notice */ /* mask for class specific bits */ #define CLASS_PORT_CAPMASK_CLASS_SPECIFIC 0xff00 typedef struct _ClassPortInfo{ uint8 BaseVersion; uint8 ClassVersion; uint16 CapMask; union { uint32 AsReg32; struct { IB_BITFIELD2(uint32, CapMask2: 27, RespTimeValue: 5) } PACK_SUFFIX s; } u1; /* Define any re-direction. */ IB_GID RedirectGID; union { uint32 AsReg32; struct { IB_BITFIELD3(uint32, RedirectTClass: 8, RedirectSL: 4, RedirectFlowLabel:20) } PACK_SUFFIX s; } u2; IB_LID RedirectLID; uint16 Redirect_P_Key; union { uint32 AsReg32; struct { IB_BITFIELD2(uint32, Reserved2: 8, RedirectQP: 24) } PACK_SUFFIX s; } u3; uint32 Redirect_Q_Key; /* Define any refor traps */ IB_GID TrapGID; union { uint32 AsReg32; struct { IB_BITFIELD3(uint32, TrapTClass: 8, TrapSL: 4, TrapFlowLabel: 20) } PACK_SUFFIX s; } u4; IB_LID TrapLID; uint16 Trap_P_Key; union { uint32 AsReg32; struct { IB_BITFIELD2(uint32, TrapHopLimit: 8, TrapQP: 24) } PACK_SUFFIX s; } u5; uint32 Trap_Q_Key; } PACK_SUFFIX ClassPortInfo, IB_CLASS_PORT_INFO; /* Notice */ /* Channel adapters, switches, and routers implementing Notice attributes * shall conform to the definition specified. */ /* * Node type info */ typedef enum _NODE_TYPE { IBA_NODE_CHANNEL_ADAPTER = 1, IBA_NODE_SWITCH = 2, IBA_NODE_ROUTER = 3, } NODE_TYPE; /* * Trap/Notice type */ typedef enum _NOTICE_TYPE { IB_NOTICE_FATAL = 0, IB_NOTICE_URGENT = 1, IB_NOTICE_SECURITY = 2, IB_NOTICE_SM = 3, IB_NOTICE_INFO = 4, IB_NOTICE_ALL = 0xFFFF } IB_NOTICE_TYPE; /* * Notice */ typedef struct _NOTICE { union { /* Generic Notice attributes */ struct /*_GENERIC*/ { union { uint32 AsReg32; struct { IB_BITFIELD3(uint32, IsGeneric: 1, /* 1= generic */ Type : 7, /* IB_NOTICE_TYPE */ ProducerType:24) /* NODE_TYPE */ } PACK_SUFFIX s; } u; /* If generic, indicates a class-defined trap number. */ /* Number 0xFFFF is reserved. */ uint16 TrapNumber; } PACK_SUFFIX Generic; /* Vendor specific Notice attributes */ struct /*_VENDOR*/ { union { uint32 AsReg32; struct { IB_BITFIELD3(uint32, IsGeneric: 1, Type : 7, VendorID: 24) /* Vendor OUI */ } PACK_SUFFIX s; } u; /* If not generic, this is Device ID information as assigned by */ /* device manufacturer. */ uint16 DeviceID; } PACK_SUFFIX Vendor; } u; /* Common Notice attributes */ IB_LID IssuerLID; /* LID of requester */ /* Toggle: * For Notices, alternates between zero and one after each Notice is * cleared. * For Traps, this shall be set to 0. * * Count: * For Notices, indicates the number of notices queued on this channel * adapter, switch, or router. * For Traps, this shall be set to all zeroes. */ struct { IB_BITFIELD2(uint16, Toggle :1, Count :15) } PACK_SUFFIX Stats; uint8 Data[54]; IB_GID IssuerGID; } PACK_SUFFIX IB_NOTICE; /* * Structure of the IB_NOTICE Data for the following traps: * SMA_TRAP_GID_NOW_IN_SERVICE * SMA_TRAP_GID_OUT_OF_SERVICE * SMA_TRAP_ADD_MULTICAST_GROUP * SMA_TRAP_DEL_MULTICAST_GROUP */ typedef struct _TRAPS_64_65_66_67_DETAILS { uint8 Reserved[6]; IB_GID GIDAddress; uint8 Padding[32]; } PACK_SUFFIX TRAPS_64_65_66_67_DETAILS, TRAP_64_DETAILS, TRAP_65_DETAILS, TRAP_66_DETAILS, TRAP_67_DETAILS; /* * InformInfo */ typedef struct _INFORM_INFO { IB_GID GID; /* specifies specific GID to subscribe for. */ /* Set to zero if not desired. */ IB_LID LIDRangeBegin; /* 0xFFFF encapsulates all LIDs */ IB_LID LIDRangeEnd; uint16 Reserved; uint8 IsGeneric; /* 1 = forward generic traps */ /* 0 = vendor specific */ uint8 Subscribe; /* 1 = subscribe, 0 = unsubscribe */ uint16 Type; /* IB_NOTICE_TYPE */ union { struct /*_GENERIC_II*/ { uint16 TrapNumber; union { uint32 AsReg32; struct { IB_BITFIELD3(uint32, QPNumber:24, Reserved:3, RespTimeValue:5) } PACK_SUFFIX s; } u2; union { uint32 AsReg32; struct { IB_BITFIELD2(uint32, Reserved: 8, ProducerType: 24) /* NODE_TYPE */ } PACK_SUFFIX s; } u; } PACK_SUFFIX Generic; struct /*_VENDOR_II*/ { uint16 DeviceID; union { uint32 AsReg32; struct { IB_BITFIELD3(uint32, QPNumber:24, Reserved:3, RespTimeValue:5) } PACK_SUFFIX s; } u2; union { uint32 AsReg32; struct { IB_BITFIELD2(uint32, Reserved: 8, VendorID: 24) /* Vendor OUI */ } PACK_SUFFIX s; } u; } PACK_SUFFIX Vendor; } u; } PACK_SUFFIX IB_INFORM_INFO; #include "iba/public/ipackoff.h" /* -------------------------------------------------------------------------- * Swap between cpu and wire formats */ static __inline void BSWAP_MAD_HEADER( MAD *Dest ) { #if CPU_LE Dest->common.u.NS.Status.AsReg16 = ntoh16( Dest->common.u.NS.Status.AsReg16); Dest->common.TransactionID = ntoh64(Dest->common.TransactionID); Dest->common.AttributeID = ntoh16(Dest->common.AttributeID ); Dest->common.AttributeModifier = ntoh32(Dest->common.AttributeModifier); #endif } static __inline void BSWAP_IB_CLASS_PORT_INFO( IB_CLASS_PORT_INFO *Dest ) { #if CPU_LE Dest->CapMask = ntoh16(Dest->CapMask); Dest->u1.AsReg32 = ntoh32(Dest->u1.AsReg32); BSWAP_IB_GID(&Dest->RedirectGID); Dest->u2.AsReg32 = ntoh32(Dest->u2.AsReg32); Dest->RedirectLID = ntoh16(Dest->RedirectLID); Dest->Redirect_P_Key = ntoh16(Dest->Redirect_P_Key); Dest->u3.AsReg32 = ntoh32(Dest->u3.AsReg32); Dest->Redirect_Q_Key = ntoh32(Dest->Redirect_Q_Key); BSWAP_IB_GID(&Dest->TrapGID); Dest->u4.AsReg32 = ntoh32(Dest->u4.AsReg32); Dest->TrapLID = ntoh16(Dest->TrapLID); Dest->Trap_P_Key = ntoh16(Dest->Trap_P_Key); Dest->u5.AsReg32 = ntoh32(Dest->u5.AsReg32); Dest->Trap_Q_Key = ntoh32(Dest->Trap_Q_Key); #endif } static __inline void BSWAP_IB_NOTICE( IB_NOTICE *Dest ) { #if CPU_LE /* Can do Generic since Vendor has same types, just different field names */ Dest->u.Generic.u.AsReg32 = ntoh32(Dest->u.Generic.u.AsReg32); Dest->u.Generic.TrapNumber = ntoh16(Dest->u.Generic.TrapNumber); Dest->IssuerLID = ntoh16(Dest->IssuerLID); BSWAP_IB_GID(&Dest->IssuerGID); #endif } /* * Swaps the GIDAddress in the IB_NOTICE Data */ static __inline void BSWAP_TRAPS_64_65_66_67_DETAILS(TRAPS_64_65_66_67_DETAILS *Dest) { #if CPU_LE BSWAP_IB_GID(&Dest->GIDAddress); #endif } #define BSWAP_TRAP_64_DETAILS(Dest) BSWAP_TRAPS_64_65_66_67_DETAILS(Dest) #define BSWAP_TRAP_65_DETAILS(Dest) BSWAP_TRAPS_64_65_66_67_DETAILS(Dest) #define BSWAP_TRAP_66_DETAILS(Dest) BSWAP_TRAPS_64_65_66_67_DETAILS(Dest) #define BSWAP_TRAP_67_DETAILS(Dest) BSWAP_TRAPS_64_65_66_67_DETAILS(Dest) static __inline void BSWAP_INFORM_INFO( IB_INFORM_INFO *Dest ) { #if CPU_LE BSWAP_IB_GID(&Dest->GID); Dest->LIDRangeBegin = ntoh16(Dest->LIDRangeBegin); Dest->LIDRangeEnd = ntoh16(Dest->LIDRangeEnd); Dest->Type = ntoh16(Dest->Type); /* Can do Generic since Vendor has same types, just different field names */ Dest->u.Generic.TrapNumber = ntoh16(Dest->u.Generic.TrapNumber); Dest->u.Generic.u2.AsReg32 = ntoh32(Dest->u.Generic.u2.AsReg32); Dest->u.Generic.u.AsReg32 = ntoh32(Dest->u.Generic.u.AsReg32); #endif } #if defined (__cplusplus) }; #endif #endif /* __IBA_IB_MAD_H__ */