From b9d93f19208afe1f14b8ba6b94a207783e56970c Mon Sep 17 00:00:00 2001 From: shefty Date: Thu, 15 Jan 2009 07:31:36 +0000 Subject: [PATCH] libibmad: updated based on merge feedback Latest set of changes to libibmad to support both Windows and Linux. Changes have not yet been accepted back into the main git tree. Signed-off-by: Sean Hefty git-svn-id: svn://openib.tc.cornell.edu/gen1@1833 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- trunk/ulp/libibmad/include/infiniband/mad.h | 1753 +++++++++---------- trunk/ulp/libibmad/src/Sources | 3 +- trunk/ulp/libibmad/src/dump.c | 1565 ++++++++--------- trunk/ulp/libibmad/src/fields.c | 444 +++-- trunk/ulp/libibmad/src/gs.c | 477 +++-- trunk/ulp/libibmad/src/ibmad_export.def | 2 +- trunk/ulp/libibmad/src/ibmad_exports.src | 1 - trunk/ulp/libibmad/src/ibmad_main.cpp | 2 +- trunk/ulp/libibmad/src/mad.c | 423 ++--- trunk/ulp/libibmad/src/portid.c | 295 ++-- trunk/ulp/libibmad/src/register.c | 402 +++-- trunk/ulp/libibmad/src/resolve.c | 375 ++-- trunk/ulp/libibmad/src/rpc.c | 791 ++++----- trunk/ulp/libibmad/src/sa.c | 302 ++-- trunk/ulp/libibmad/src/serv.c | 362 ++-- trunk/ulp/libibmad/src/smp.c | 243 ++- trunk/ulp/libibmad/src/vendor.c | 195 +-- 17 files changed, 3709 insertions(+), 3926 deletions(-) diff --git a/trunk/ulp/libibmad/include/infiniband/mad.h b/trunk/ulp/libibmad/include/infiniband/mad.h index b5acdd38..dd87a3d5 100644 --- a/trunk/ulp/libibmad/include/infiniband/mad.h +++ b/trunk/ulp/libibmad/include/infiniband/mad.h @@ -1,913 +1,840 @@ -/* - * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef _MAD_H_ -#define _MAD_H_ - -/* use complib for portability */ -#include -#include -#include - -#ifdef __cplusplus -# define BEGIN_C_DECLS extern "C" { -# define END_C_DECLS } -#else /* !__cplusplus */ -# define BEGIN_C_DECLS -# define END_C_DECLS -#endif /* __cplusplus */ - -BEGIN_C_DECLS - -#if defined(_WIN32) || defined(_WIN64) -#define MAD_EXPORT __declspec(dllexport) -#else -#define MAD_EXPORT extern -#endif - -#define IB_SUBNET_PATH_HOPS_MAX 64 -#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL -#define IB_DEFAULT_QP1_QKEY 0x80010000 - -#define IB_MAD_SIZE 256 - -#define IB_SMP_DATA_OFFS 64 -#define IB_SMP_DATA_SIZE 64 - -#define IB_VENDOR_RANGE1_DATA_OFFS 24 -#define IB_VENDOR_RANGE1_DATA_SIZE (IB_MAD_SIZE - IB_VENDOR_RANGE1_DATA_OFFS) - -#define IB_VENDOR_RANGE2_DATA_OFFS 40 -#define IB_VENDOR_RANGE2_DATA_SIZE (IB_MAD_SIZE - IB_VENDOR_RANGE2_DATA_OFFS) - -#define IB_SA_DATA_SIZE 200 -#define IB_SA_DATA_OFFS 56 - -#define IB_PC_DATA_OFFS 64 -#define IB_PC_DATA_SZ (IB_MAD_SIZE - IB_PC_DATA_OFFS) - -#define IB_SA_MCM_RECSZ 53 -#define IB_SA_PR_RECSZ 64 - -enum MAD_CLASSES { - IB_SMI_CLASS = 0x1, - IB_SMI_DIRECT_CLASS = 0x81, - IB_SA_CLASS = 0x3, - IB_PERFORMANCE_CLASS = 0x4, - IB_BOARD_MGMT_CLASS = 0x5, - IB_DEVICE_MGMT_CLASS = 0x6, - IB_CM_CLASS = 0x7, - IB_SNMP_CLASS = 0x8, - IB_VENDOR_RANGE1_START_CLASS = 0x9, - IB_VENDOR_RANGE1_END_CLASS = 0x0f, - IB_CC_CLASS = 0x21, - IB_VENDOR_RANGE2_START_CLASS = 0x30, - IB_VENDOR_RANGE2_END_CLASS = 0x4f, -}; - -enum MAD_METHODS { - IB_MAD_METHOD_GET = 0x1, - IB_MAD_METHOD_SET = 0x2, - IB_MAD_METHOD_GET_RESPONSE = 0x81, - - IB_MAD_METHOD_SEND = 0x3, - IB_MAD_METHOD_TRAP = 0x5, - IB_MAD_METHOD_TRAP_REPRESS = 0x7, - - IB_MAD_METHOD_REPORT = 0x6, - IB_MAD_METHOD_REPORT_RESPONSE = 0x86, - IB_MAD_METHOD_GET_TABLE = 0x12, - IB_MAD_METHOD_GET_TABLE_RESPONSE = 0x92, - IB_MAD_METHOD_GET_TRACE_TABLE = 0x13, - IB_MAD_METHOD_GET_TRACE_TABLE_RESPONSE = 0x93, - IB_MAD_METHOD_GETMULTI = 0x14, - IB_MAD_METHOD_GETMULTI_RESPONSE = 0x94, - IB_MAD_METHOD_DELETE = 0x15, - IB_MAD_METHOD_DELETE_RESPONSE = 0x95, - - IB_MAD_RESPONSE = 0x80, -}; - -enum MAD_ATTR_ID { - CLASS_PORT_INFO = 0x1, - NOTICE = 0x2, - INFORM_INFO = 0x3, -}; - -enum SMI_ATTR_ID { - IB_ATTR_NODE_DESC = 0x10, - IB_ATTR_NODE_INFO = 0x11, - IB_ATTR_SWITCH_INFO = 0x12, - IB_ATTR_GUID_INFO = 0x14, - IB_ATTR_PORT_INFO = 0x15, - IB_ATTR_PKEY_TBL = 0x16, - IB_ATTR_SLVL_TABLE = 0x17, - IB_ATTR_VL_ARBITRATION = 0x18, - IB_ATTR_LINEARFORWTBL = 0x19, - IB_ATTR_MULTICASTFORWTBL = 0x1b, - IB_ATTR_SMINFO = 0x20, - - IB_ATTR_LAST -}; - -enum SA_ATTR_ID { - IB_SA_ATTR_NOTICE = 0x02, - IB_SA_ATTR_INFORMINFO = 0x03, - IB_SA_ATTR_PORTINFORECORD = 0x12, - IB_SA_ATTR_LINKRECORD = 0x20, - IB_SA_ATTR_SERVICERECORD = 0x31, - IB_SA_ATTR_PATHRECORD = 0x35, - IB_SA_ATTR_MCRECORD = 0x38, - IB_SA_ATTR_MULTIPATH = 0x3a, - - IB_SA_ATTR_LAST -}; - -enum GSI_ATTR_ID { - IB_GSI_PORT_SAMPLES_CONTROL = 0x10, - IB_GSI_PORT_SAMPLES_RESULT = 0x11, - IB_GSI_PORT_COUNTERS = 0x12, - IB_GSI_PORT_COUNTERS_EXT = 0x1D, - - IB_GSI_ATTR_LAST -}; - -#define IB_VENDOR_OPENIB_PING_CLASS (IB_VENDOR_RANGE2_START_CLASS + 2) -#define IB_VENDOR_OPENIB_SYSSTAT_CLASS (IB_VENDOR_RANGE2_START_CLASS + 3) -#define IB_OPENIB_OUI (0x001405) - -typedef uint8_t ibmad_gid_t[16]; -#ifdef USE_DEPRECATED_IB_GID_T -typedef ibmad_gid_t ib_gid_t __attribute__((deprecated)); -#endif - -typedef struct { - int cnt; - uint8_t p[IB_SUBNET_PATH_HOPS_MAX]; - uint16_t drslid; - uint16_t drdlid; -} ib_dr_path_t; - -typedef struct { - unsigned id; - unsigned mod; -} ib_attr_t; - -typedef struct { - int mgtclass; - int method; - ib_attr_t attr; - uint32_t rstatus; /* return status */ - int dataoffs; - int datasz; - uint64_t mkey; - uint64_t trid; /* used for out mad if nonzero, return real val */ - uint64_t mask; /* for sa mads */ - unsigned recsz; /* for sa mads (attribute offset) */ - int timeout; - uint32_t oui; /* for vendor range 2 mads */ -} ib_rpc_t; - -typedef struct portid { - int lid; /* lid or 0 if directed route */ - ib_dr_path_t drpath; - int grh_present; /* flag */ - ibmad_gid_t gid; - uint32_t qp; - uint32_t qkey; - uint8_t sl; - unsigned pkey_idx; -} ib_portid_t; - -typedef void (ib_mad_dump_fn)(char *buf, int bufsz, void *val, int valsz); - -#define IB_FIELD_NAME_LEN 32 - -typedef struct ib_field { - int bitoffs; - int bitlen; - char name[IB_FIELD_NAME_LEN]; - ib_mad_dump_fn *def_dump_fn; -} ib_field_t; - -enum MAD_FIELDS { - IB_NO_FIELD, - - IB_GID_PREFIX_F, - IB_GID_GUID_F, - - /* first MAD word (0-3 bytes) */ - IB_MAD_METHOD_F, - IB_MAD_RESPONSE_F, - IB_MAD_CLASSVER_F, - IB_MAD_MGMTCLASS_F, - IB_MAD_BASEVER_F, - - /* second MAD word (4-7 bytes) */ - IB_MAD_STATUS_F, - - /* DRSMP only */ - IB_DRSMP_HOPCNT_F, - IB_DRSMP_HOPPTR_F, - IB_DRSMP_STATUS_F, - IB_DRSMP_DIRECTION_F, - - /* words 3,4,5,6 (8-23 bytes) */ - IB_MAD_TRID_F, - IB_MAD_ATTRID_F, - IB_MAD_ATTRMOD_F, - - /* word 7,8 (24-31 bytes) */ - IB_MAD_MKEY_F, - - /* word 9 (32-37 bytes) */ - IB_DRSMP_DRSLID_F, - IB_DRSMP_DRDLID_F, - - /* word 10,11 (36-43 bytes) */ - IB_SA_MKEY_F, - - /* word 12 (44-47 bytes) */ - IB_SA_ATTROFFS_F, - - /* word 13,14 (48-55 bytes) */ - IB_SA_COMPMASK_F, - - /* word 13,14 (56-255 bytes) */ - IB_SA_DATA_F, - - /* bytes 64 - 127 */ - IB_SM_DATA_F, - - /* bytes 64 - 256 */ - IB_GS_DATA_F, - - /* bytes 128 - 191 */ - IB_DRSMP_PATH_F, - - /* bytes 192 - 255 */ - IB_DRSMP_RPATH_F, - - /* - * PortInfo fields: - */ - IB_PORT_FIRST_F, - IB_PORT_MKEY_F = IB_PORT_FIRST_F, - IB_PORT_GID_PREFIX_F, - IB_PORT_LID_F, - IB_PORT_SMLID_F, - IB_PORT_CAPMASK_F, - IB_PORT_DIAG_F, - IB_PORT_MKEY_LEASE_F, - IB_PORT_LOCAL_PORT_F, - IB_PORT_LINK_WIDTH_ENABLED_F, - IB_PORT_LINK_WIDTH_SUPPORTED_F, - IB_PORT_LINK_WIDTH_ACTIVE_F, - IB_PORT_LINK_SPEED_SUPPORTED_F, - IB_PORT_STATE_F, - IB_PORT_PHYS_STATE_F, - IB_PORT_LINK_DOWN_DEF_F, - IB_PORT_MKEY_PROT_BITS_F, - IB_PORT_LMC_F, - IB_PORT_LINK_SPEED_ACTIVE_F, - IB_PORT_LINK_SPEED_ENABLED_F, - IB_PORT_NEIGHBOR_MTU_F, - IB_PORT_SMSL_F, - IB_PORT_VL_CAP_F, - IB_PORT_INIT_TYPE_F, - IB_PORT_VL_HIGH_LIMIT_F, - IB_PORT_VL_ARBITRATION_HIGH_CAP_F, - IB_PORT_VL_ARBITRATION_LOW_CAP_F, - IB_PORT_INIT_TYPE_REPLY_F, - IB_PORT_MTU_CAP_F, - IB_PORT_VL_STALL_COUNT_F, - IB_PORT_HOQ_LIFE_F, - IB_PORT_OPER_VLS_F, - IB_PORT_PART_EN_INB_F, - IB_PORT_PART_EN_OUTB_F, - IB_PORT_FILTER_RAW_INB_F, - IB_PORT_FILTER_RAW_OUTB_F, - IB_PORT_MKEY_VIOL_F, - IB_PORT_PKEY_VIOL_F, - IB_PORT_QKEY_VIOL_F, - IB_PORT_GUID_CAP_F, - IB_PORT_CLIENT_REREG_F, - IB_PORT_SUBN_TIMEOUT_F, - IB_PORT_RESP_TIME_VAL_F, - IB_PORT_LOCAL_PHYS_ERR_F, - IB_PORT_OVERRUN_ERR_F, - IB_PORT_MAX_CREDIT_HINT_F, - IB_PORT_LINK_ROUND_TRIP_F, - IB_PORT_LAST_F, - - /* - * NodeInfo fields: - */ - IB_NODE_FIRST_F, - IB_NODE_BASE_VERS_F = IB_NODE_FIRST_F, - IB_NODE_CLASS_VERS_F, - IB_NODE_TYPE_F, - IB_NODE_NPORTS_F, - IB_NODE_SYSTEM_GUID_F, - IB_NODE_GUID_F, - IB_NODE_PORT_GUID_F, - IB_NODE_PARTITION_CAP_F, - IB_NODE_DEVID_F, - IB_NODE_REVISION_F, - IB_NODE_LOCAL_PORT_F, - IB_NODE_VENDORID_F, - IB_NODE_LAST_F, - - /* - * SwitchInfo fields: - */ - IB_SW_FIRST_F, - IB_SW_LINEAR_FDB_CAP_F = IB_SW_FIRST_F, - IB_SW_RANDOM_FDB_CAP_F, - IB_SW_MCAST_FDB_CAP_F, - IB_SW_LINEAR_FDB_TOP_F, - IB_SW_DEF_PORT_F, - IB_SW_DEF_MCAST_PRIM_F, - IB_SW_DEF_MCAST_NOT_PRIM_F, - IB_SW_LIFE_TIME_F, - IB_SW_STATE_CHANGE_F, - IB_SW_LIDS_PER_PORT_F, - IB_SW_PARTITION_ENFORCE_CAP_F, - IB_SW_PARTITION_ENF_INB_F, - IB_SW_PARTITION_ENF_OUTB_F, - IB_SW_FILTER_RAW_INB_F, - IB_SW_FILTER_RAW_OUTB_F, - IB_SW_ENHANCED_PORT0_F, - IB_SW_LAST_F, - - /* - * SwitchLinearForwardingTable fields: - */ - IB_LINEAR_FORW_TBL_F, - - /* - * SwitchMulticastForwardingTable fields: - */ - IB_MULTICAST_FORW_TBL_F, - - /* - * NodeDescription fields: - */ - IB_NODE_DESC_F, - - /* - * Notice/Trap fields - */ - IB_NOTICE_IS_GENERIC_F, - IB_NOTICE_TYPE_F, - IB_NOTICE_PRODUCER_F, - IB_NOTICE_TRAP_NUMBER_F, - IB_NOTICE_ISSUER_LID_F, - IB_NOTICE_TOGGLE_F, - IB_NOTICE_COUNT_F, - IB_NOTICE_DATA_DETAILS_F, - IB_NOTICE_DATA_LID_F, - IB_NOTICE_DATA_144_LID_F, - IB_NOTICE_DATA_144_CAPMASK_F, - - /* - * GS Performance - */ - IB_PC_FIRST_F, - IB_PC_PORT_SELECT_F = IB_PC_FIRST_F, - IB_PC_COUNTER_SELECT_F, - IB_PC_ERR_SYM_F, - IB_PC_LINK_RECOVERS_F, - IB_PC_LINK_DOWNED_F, - IB_PC_ERR_RCV_F, - IB_PC_ERR_PHYSRCV_F, - IB_PC_ERR_SWITCH_REL_F, - IB_PC_XMT_DISCARDS_F, - IB_PC_ERR_XMTCONSTR_F, - IB_PC_ERR_RCVCONSTR_F, - IB_PC_ERR_LOCALINTEG_F, - IB_PC_ERR_EXCESS_OVR_F, - IB_PC_VL15_DROPPED_F, - IB_PC_XMT_BYTES_F, - IB_PC_RCV_BYTES_F, - IB_PC_XMT_PKTS_F, - IB_PC_RCV_PKTS_F, - IB_PC_LAST_F, - - /* - * SMInfo - */ - IB_SMINFO_GUID_F, - IB_SMINFO_KEY_F, - IB_SMINFO_ACT_F, - IB_SMINFO_PRIO_F, - IB_SMINFO_STATE_F, - - /* - * SA RMPP - */ - IB_SA_RMPP_VERS_F, - IB_SA_RMPP_TYPE_F, - IB_SA_RMPP_RESP_F, - IB_SA_RMPP_FLAGS_F, - IB_SA_RMPP_STATUS_F, - - /* data1 */ - IB_SA_RMPP_D1_F, - IB_SA_RMPP_SEGNUM_F, - /* data2 */ - IB_SA_RMPP_D2_F, - IB_SA_RMPP_LEN_F, /* DATA: Payload len */ - IB_SA_RMPP_NEWWIN_F, /* ACK: new window last */ - - /* - * SA Multi Path rec - */ - IB_SA_MP_NPATH_F, - IB_SA_MP_NSRC_F, - IB_SA_MP_NDEST_F, - IB_SA_MP_GID0_F, - - /* - * SA Path rec - */ - IB_SA_PR_DGID_F, - IB_SA_PR_SGID_F, - IB_SA_PR_DLID_F, - IB_SA_PR_SLID_F, - IB_SA_PR_NPATH_F, - - /* - * MC Member rec - */ - IB_SA_MCM_MGID_F, - IB_SA_MCM_PORTGID_F, - IB_SA_MCM_QKEY_F, - IB_SA_MCM_MLID_F, - IB_SA_MCM_SL_F, - IB_SA_MCM_MTU_F, - IB_SA_MCM_RATE_F, - IB_SA_MCM_TCLASS_F, - IB_SA_MCM_PKEY_F, - IB_SA_MCM_FLOW_LABEL_F, - IB_SA_MCM_JOIN_STATE_F, - IB_SA_MCM_PROXY_JOIN_F, - - /* - * Service record - */ - IB_SA_SR_ID_F, - IB_SA_SR_GID_F, - IB_SA_SR_PKEY_F, - IB_SA_SR_LEASE_F, - IB_SA_SR_KEY_F, - IB_SA_SR_NAME_F, - IB_SA_SR_DATA_F, - - /* - * ATS SM record - within SA_SR_DATA - */ - IB_ATS_SM_NODE_ADDR_F, - IB_ATS_SM_MAGIC_KEY_F, - IB_ATS_SM_NODE_TYPE_F, - IB_ATS_SM_NODE_NAME_F, - - /* - * SLTOVL MAPPING TABLE - */ - IB_SLTOVL_MAPPING_TABLE_F, - - /* - * VL ARBITRATION TABLE - */ - IB_VL_ARBITRATION_TABLE_F, - - /* - * IB vendor class range 2 - */ - IB_VEND2_OUI_F, - IB_VEND2_DATA_F, - - /* - * PortCountersExtended - */ - IB_PC_EXT_FIRST_F, - IB_PC_EXT_PORT_SELECT_F = IB_PC_EXT_FIRST_F, - IB_PC_EXT_COUNTER_SELECT_F, - IB_PC_EXT_XMT_BYTES_F, - IB_PC_EXT_RCV_BYTES_F, - IB_PC_EXT_XMT_PKTS_F, - IB_PC_EXT_RCV_PKTS_F, - IB_PC_EXT_XMT_UPKTS_F, - IB_PC_EXT_RCV_UPKTS_F, - IB_PC_EXT_XMT_MPKTS_F, - IB_PC_EXT_RCV_MPKTS_F, - IB_PC_EXT_LAST_F, - - /* - * GUIDInfo fields - */ - IB_GUID_GUID0_F, - - IB_FIELD_LAST_ /* must be last */ -}; - -/* - * SA RMPP section - */ -enum RMPP_TYPE_ENUM { - IB_RMPP_TYPE_NONE, - IB_RMPP_TYPE_DATA, - IB_RMPP_TYPE_ACK, - IB_RMPP_TYPE_STOP, - IB_RMPP_TYPE_ABORT, -}; - -enum RMPP_FLAGS_ENUM { - IB_RMPP_FLAG_ACTIVE = 1 << 0, - IB_RMPP_FLAG_FIRST = 1 << 1, - IB_RMPP_FLAG_LAST = 1 << 2, -}; - -typedef struct { - int type; - int flags; - int status; - union { - uint32_t u; - uint32_t segnum; - } d1; - union { - uint32_t u; - uint32_t len; - uint32_t newwin; - } d2; -} ib_rmpp_hdr_t; - -enum SA_SIZES_ENUM { - SA_HEADER_SZ = 20, -}; - -typedef struct ib_sa_call { - unsigned attrid; - unsigned mod; - uint64_t mask; - unsigned method; - - uint64_t trid; /* used for out mad if nonzero, return real val */ - unsigned recsz; /* return field */ - ib_rmpp_hdr_t rmpp; -} ib_sa_call_t; - -typedef struct ib_vendor_call { - unsigned method; - unsigned mgmt_class; - unsigned attrid; - unsigned mod; - uint32_t oui; - unsigned timeout; - ib_rmpp_hdr_t rmpp; -} ib_vendor_call_t; - -#define IB_MIN_UCAST_LID 1 -#define IB_MAX_UCAST_LID (0xc000-1) -#define IB_MIN_MCAST_LID 0xc000 -#define IB_MAX_MCAST_LID (0xffff-1) - -#define IB_LID_VALID(lid) ((lid) >= IB_MIN_UCAST_LID && lid <= IB_MAX_UCAST_LID) -#define IB_MLID_VALID(lid) ((lid) >= IB_MIN_MCAST_LID && lid <= IB_MAX_MCAST_LID) - -#define MAD_DEF_RETRIES 3 -#define MAD_DEF_TIMEOUT_MS 1000 - -enum { - IB_DEST_LID, - IB_DEST_DRPATH, - IB_DEST_GUID, - IB_DEST_DRSLID, -}; - -enum { - IB_NODE_CA = 1, - IB_NODE_SWITCH, - IB_NODE_ROUTER, - NODE_RNIC, - - IB_NODE_MAX = NODE_RNIC -}; - -/******************************************************************************/ - -/* portid.c */ -MAD_EXPORT char * portid2str(ib_portid_t *portid); -MAD_EXPORT int portid2portnum(ib_portid_t *portid); -MAD_EXPORT int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid); -MAD_EXPORT char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size); - -static inline int -ib_portid_set(ib_portid_t *portid, int lid, int qp, int qkey) -{ - portid->lid = lid; - portid->qp = qp; - portid->qkey = qkey; - portid->grh_present = 0; - - return 0; -} - -/* fields.c */ -extern ib_field_t ib_mad_f[]; - -void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val); -uint32_t _get_field(void *buf, int base_offs, ib_field_t *f); -void _set_array(void *buf, int base_offs, ib_field_t *f, void *val); -void _get_array(void *buf, int base_offs, ib_field_t *f, void *val); -void _set_field64(void *buf, int base_offs, ib_field_t *f, uint64_t val); -uint64_t _get_field64(void *buf, int base_offs, ib_field_t *f); - -/* mad.c */ -MAD_EXPORT uint32_t mad_get_field(void *buf, int base_offs, int field); -MAD_EXPORT void mad_set_field(void *buf, int base_offs, int field, uint32_t val); -/* field must be byte aligned */ -MAD_EXPORT uint64_t mad_get_field64(void *buf, int base_offs, int field); -MAD_EXPORT void mad_set_field64(void *buf, int base_offs, int field, uint64_t val); -MAD_EXPORT void mad_set_array(void *buf, int base_offs, int field, void *val); -MAD_EXPORT void mad_get_array(void *buf, int base_offs, int field, void *val); -MAD_EXPORT void mad_decode_field(uint8_t *buf, int field, void *val); -MAD_EXPORT void mad_encode_field(uint8_t *buf, int field, void *val); -MAD_EXPORT void *mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data); -MAD_EXPORT uint64_t mad_trid(void); -MAD_EXPORT int mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, - ib_rmpp_hdr_t *rmpp, void *data); - -/* register.c */ -MAD_EXPORT int mad_register_port_client(int port_id, int mgmt, - uint8_t rmpp_version); -MAD_EXPORT int mad_register_client(int mgmt, uint8_t rmpp_version); -MAD_EXPORT int mad_register_server(int mgmt, uint8_t rmpp_version, - long method_mask[16/sizeof(long)], - uint32_t class_oui); -MAD_EXPORT int mad_class_agent(int mgmt); -MAD_EXPORT int mad_agent_class(int agent); - -/* serv.c */ -MAD_EXPORT int mad_send(ib_rpc_t *rpc, ib_portid_t *dport, - ib_rmpp_hdr_t *rmpp, void *data); -MAD_EXPORT void * mad_receive(void *umad, int timeout); -MAD_EXPORT int mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus); -MAD_EXPORT void * mad_alloc(void); -MAD_EXPORT void mad_free(void *umad); - -/* vendor.c */ -MAD_EXPORT uint8_t *ib_vendor_call(void *data, ib_portid_t *portid, - ib_vendor_call_t *call); - -static inline int -mad_is_vendor_range1(int mgmt) -{ - return mgmt >= 0x9 && mgmt <= 0xf; -} - -static inline int -mad_is_vendor_range2(int mgmt) -{ - return mgmt >= 0x30 && mgmt <= 0x4f; -} - -/* rpc.c */ -MAD_EXPORT int madrpc_portid(void); -MAD_EXPORT int madrpc_set_retries(int retries); -MAD_EXPORT int madrpc_set_timeout(int timeout); -MAD_EXPORT void madrpc_init(char *dev_name, int dev_port, - int *mgmt_classes, int num_classes); -MAD_EXPORT void madrpc_show_errors(int set); -void * madrpc(ib_rpc_t *rpc, ib_portid_t *dport, - void *payload, void *rcvdata); -void * madrpc_rmpp(ib_rpc_t *rpc, ib_portid_t *dport, - ib_rmpp_hdr_t *rmpp, void *data); - -void madrpc_save_mad(void *madbuf, int len); -void madrpc_lock(void); -void madrpc_unlock(void); -void * mad_rpc_open_port(char *dev_name, int dev_port, - int *mgmt_classes, int num_classes); -void mad_rpc_close_port(void *ibmad_port); -void * mad_rpc(const void *ibmad_port, ib_rpc_t *rpc, - ib_portid_t *dport, void *payload, - void *rcvdata); -void * mad_rpc_rmpp(const void *ibmad_port, ib_rpc_t *rpc, - ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, - void *data); - -/* smp.c */ -MAD_EXPORT uint8_t * smp_query(void *buf, ib_portid_t *id, unsigned attrid, - unsigned mod, unsigned timeout); -MAD_EXPORT uint8_t * smp_set(void *buf, ib_portid_t *id, unsigned attrid, - unsigned mod, unsigned timeout); -uint8_t * smp_query_via(void *buf, ib_portid_t *id, unsigned attrid, - unsigned mod, unsigned timeout, const void *srcport); -uint8_t * smp_set_via(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod, - unsigned timeout, const void *srcport); - -inline static uint8_t * -safe_smp_query(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod, - unsigned timeout) -{ - uint8_t *p; - - madrpc_lock(); - p = smp_query(rcvbuf, portid, attrid, mod, timeout); - madrpc_unlock(); - - return p; -} - -inline static uint8_t * -safe_smp_set(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod, - unsigned timeout) -{ - uint8_t *p; - - madrpc_lock(); - p = smp_set(rcvbuf, portid, attrid, mod, timeout); - madrpc_unlock(); - - return p; -} - -/* sa.c */ -uint8_t * sa_call(void *rcvbuf, ib_portid_t *portid, ib_sa_call_t *sa, - unsigned timeout); -uint8_t * sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid, - ib_sa_call_t *sa, unsigned timeout); -MAD_EXPORT int ib_path_query(ibmad_gid_t srcgid, ibmad_gid_t destgid, - ib_portid_t *sm_id, void *buf); /* returns lid */ -int ib_path_query_via(const void *srcport, ibmad_gid_t srcgid, - ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf); - -inline static uint8_t * -safe_sa_call(void *rcvbuf, ib_portid_t *portid, ib_sa_call_t *sa, - unsigned timeout) -{ - uint8_t *p; - - madrpc_lock(); - p = sa_call(rcvbuf, portid, sa, timeout); - madrpc_unlock(); - - return p; -} - -/* resolve.c */ -MAD_EXPORT int ib_resolve_smlid(ib_portid_t *sm_id, int timeout); -MAD_EXPORT int ib_resolve_guid(ib_portid_t *portid, uint64_t *guid, - ib_portid_t *sm_id, int timeout); -MAD_EXPORT int ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, - int dest_type, ib_portid_t *sm_id); -MAD_EXPORT int ib_resolve_self(ib_portid_t *portid, int *portnum, - ibmad_gid_t *gid); -int ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout, - const void *srcport); -int ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid, - ib_portid_t *sm_id, int timeout, - const void *srcport); -int ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, - int dest_type, ib_portid_t *sm_id, - const void *srcport); -int ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid, - const void *srcport); - -/* gs.c */ -MAD_EXPORT uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout); -MAD_EXPORT uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout); -MAD_EXPORT uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port, - unsigned mask, unsigned timeout); -MAD_EXPORT uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout); -MAD_EXPORT uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port, - unsigned mask, unsigned timeout); -MAD_EXPORT uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout); -MAD_EXPORT uint8_t *port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout); - -uint8_t *perf_classportinfo_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport); -uint8_t *port_performance_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport); -uint8_t *port_performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned mask, unsigned timeout, const void *srcport); -uint8_t *port_performance_ext_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport); -uint8_t *port_performance_ext_reset_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned mask, unsigned timeout, const void *srcport); -uint8_t *port_samples_control_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport); -uint8_t *port_samples_result_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport); -/* dump.c */ -ib_mad_dump_fn - MAD_EXPORT mad_dump_int, mad_dump_uint, mad_dump_hex, mad_dump_rhex, - mad_dump_bitfield, mad_dump_array, mad_dump_string, - mad_dump_linkwidth, mad_dump_linkwidthsup, mad_dump_linkwidthen, - mad_dump_linkdowndefstate, - mad_dump_linkspeed, mad_dump_linkspeedsup, mad_dump_linkspeeden, - mad_dump_portstate, mad_dump_portstates, - mad_dump_physportstate, mad_dump_portcapmask, - mad_dump_mtu, mad_dump_vlcap, mad_dump_opervls, - mad_dump_node_type, - mad_dump_sltovl, mad_dump_vlarbitration, - mad_dump_nodedesc, mad_dump_nodeinfo, mad_dump_portinfo, mad_dump_switchinfo, - mad_dump_perfcounters, mad_dump_perfcounters_ext; - -int _mad_dump(ib_mad_dump_fn *fn, char *name, void *val, int valsz); -char * _mad_dump_field(ib_field_t *f, char *name, char *buf, int bufsz, - void *val); -int _mad_print_field(ib_field_t *f, char *name, void *val, int valsz); -char * _mad_dump_val(ib_field_t *f, char *buf, int bufsz, void *val); - -static inline int -mad_print_field(int field, char *name, void *val) -{ - if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_) - return -1; - return _mad_print_field(ib_mad_f + field, name, val, 0); -} - -static inline char * -mad_dump_field(int field, char *buf, int bufsz, void *val) -{ - if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_) - return 0; - return _mad_dump_field(ib_mad_f + field, 0, buf, bufsz, val); -} - -static inline char * -mad_dump_val(int field, char *buf, int bufsz, void *val) -{ - if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_) - return 0; - return _mad_dump_val(ib_mad_f + field, buf, bufsz, val); -} - -extern int ibdebug; - -/* remove libibcommon dependencies, use complib */ - -/* dump.c */ -MAD_EXPORT void xdump(FILE *file, char *msg, void *p, int size); - -/** printf style debugging MACRO's, map to cl_msg_out */ -#if !defined(IBWARN) -#define IBWARN(fmt, ...) cl_msg_out(fmt, ## __VA_ARGS__) -#endif -#if !defined(IBPANIC) -#define IBPANIC(fmt, ...) \ -{ \ - cl_msg_out(fmt, ## __VA_ARGS__); \ - CL_ASSERT(0); \ -} -#endif - -/** align value \a l to \a size (ceil) */ -#if !defined(ALIGN) -#define ALIGN(l, size) (((l) + ((size) - 1)) / (size) * (size)) -#endif - -/** align value \a l to \a sizeof 32 bit int (ceil) */ -#if !defined(ALIGN32) -#define ALIGN32(l) (ALIGN((l), sizeof(uint32))) -#endif - - -END_C_DECLS - -#endif /* _MAD_H_ */ +/* + * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#ifndef _MAD_H_ +#define _MAD_H_ + +#include +#include +#include +#include + +#include + +#ifdef __cplusplus +# define BEGIN_C_DECLS extern "C" { +# define END_C_DECLS } +#else /* !__cplusplus */ +# define BEGIN_C_DECLS +# define END_C_DECLS +#endif /* __cplusplus */ + +BEGIN_C_DECLS + +#define IB_SUBNET_PATH_HOPS_MAX 64 +#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL +#define IB_DEFAULT_QP1_QKEY 0x80010000 + +#define IB_MAD_SIZE 256 + +#define IB_SMP_DATA_OFFS 64 +#define IB_SMP_DATA_SIZE 64 + +#define IB_VENDOR_RANGE1_DATA_OFFS 24 +#define IB_VENDOR_RANGE1_DATA_SIZE (IB_MAD_SIZE - IB_VENDOR_RANGE1_DATA_OFFS) + +#define IB_VENDOR_RANGE2_DATA_OFFS 40 +#define IB_VENDOR_RANGE2_DATA_SIZE (IB_MAD_SIZE - IB_VENDOR_RANGE2_DATA_OFFS) + +#define IB_SA_DATA_SIZE 200 +#define IB_SA_DATA_OFFS 56 + +#define IB_PC_DATA_OFFS 64 +#define IB_PC_DATA_SZ (IB_MAD_SIZE - IB_PC_DATA_OFFS) + +#define IB_SA_MCM_RECSZ 53 +#define IB_SA_PR_RECSZ 64 + +enum MAD_CLASSES { + IB_SMI_CLASS = 0x1, + IB_SMI_DIRECT_CLASS = 0x81, + IB_SA_CLASS = 0x3, + IB_PERFORMANCE_CLASS = 0x4, + IB_BOARD_MGMT_CLASS = 0x5, + IB_DEVICE_MGMT_CLASS = 0x6, + IB_CM_CLASS = 0x7, + IB_SNMP_CLASS = 0x8, + IB_VENDOR_RANGE1_START_CLASS = 0x9, + IB_VENDOR_RANGE1_END_CLASS = 0x0f, + IB_CC_CLASS = 0x21, + IB_VENDOR_RANGE2_START_CLASS = 0x30, + IB_VENDOR_RANGE2_END_CLASS = 0x4f, +}; + +enum MAD_METHODS { + IB_MAD_METHOD_GET = 0x1, + IB_MAD_METHOD_SET = 0x2, + IB_MAD_METHOD_GET_RESPONSE = 0x81, + + IB_MAD_METHOD_SEND = 0x3, + IB_MAD_METHOD_TRAP = 0x5, + IB_MAD_METHOD_TRAP_REPRESS = 0x7, + + IB_MAD_METHOD_REPORT = 0x6, + IB_MAD_METHOD_REPORT_RESPONSE = 0x86, + IB_MAD_METHOD_GET_TABLE = 0x12, + IB_MAD_METHOD_GET_TABLE_RESPONSE = 0x92, + IB_MAD_METHOD_GET_TRACE_TABLE = 0x13, + IB_MAD_METHOD_GET_TRACE_TABLE_RESPONSE = 0x93, + IB_MAD_METHOD_GETMULTI = 0x14, + IB_MAD_METHOD_GETMULTI_RESPONSE = 0x94, + IB_MAD_METHOD_DELETE = 0x15, + IB_MAD_METHOD_DELETE_RESPONSE = 0x95, + + IB_MAD_RESPONSE = 0x80, +}; + +enum MAD_ATTR_ID { + CLASS_PORT_INFO = 0x1, + NOTICE = 0x2, + INFORM_INFO = 0x3, +}; + +enum SMI_ATTR_ID { + IB_ATTR_NODE_DESC = 0x10, + IB_ATTR_NODE_INFO = 0x11, + IB_ATTR_SWITCH_INFO = 0x12, + IB_ATTR_GUID_INFO = 0x14, + IB_ATTR_PORT_INFO = 0x15, + IB_ATTR_PKEY_TBL = 0x16, + IB_ATTR_SLVL_TABLE = 0x17, + IB_ATTR_VL_ARBITRATION = 0x18, + IB_ATTR_LINEARFORWTBL = 0x19, + IB_ATTR_MULTICASTFORWTBL = 0x1b, + IB_ATTR_SMINFO = 0x20, + + IB_ATTR_LAST +}; + +enum SA_ATTR_ID { + IB_SA_ATTR_NOTICE = 0x02, + IB_SA_ATTR_INFORMINFO = 0x03, + IB_SA_ATTR_PORTINFORECORD = 0x12, + IB_SA_ATTR_LINKRECORD = 0x20, + IB_SA_ATTR_SERVICERECORD = 0x31, + IB_SA_ATTR_PATHRECORD = 0x35, + IB_SA_ATTR_MCRECORD = 0x38, + IB_SA_ATTR_MULTIPATH = 0x3a, + + IB_SA_ATTR_LAST +}; + +enum GSI_ATTR_ID { + IB_GSI_PORT_SAMPLES_CONTROL = 0x10, + IB_GSI_PORT_SAMPLES_RESULT = 0x11, + IB_GSI_PORT_COUNTERS = 0x12, + IB_GSI_PORT_COUNTERS_EXT = 0x1D, + + IB_GSI_ATTR_LAST +}; + +#define IB_VENDOR_OPENIB_PING_CLASS (IB_VENDOR_RANGE2_START_CLASS + 2) +#define IB_VENDOR_OPENIB_SYSSTAT_CLASS (IB_VENDOR_RANGE2_START_CLASS + 3) +#define IB_OPENIB_OUI (0x001405) + +typedef uint8_t ibmad_gid_t[16]; +#ifdef USE_DEPRECATED_IB_GID_T +typedef ibmad_gid_t ib_gid_t __attribute__((deprecated)); +#endif + +typedef struct { + int cnt; + uint8_t p[IB_SUBNET_PATH_HOPS_MAX]; + uint16_t drslid; + uint16_t drdlid; +} ib_dr_path_t; + +typedef struct { + unsigned id; + unsigned mod; +} ib_attr_t; + +typedef struct { + int mgtclass; + int method; + ib_attr_t attr; + uint32_t rstatus; /* return status */ + int dataoffs; + int datasz; + uint64_t mkey; + uint64_t trid; /* used for out mad if nonzero, return real val */ + uint64_t mask; /* for sa mads */ + unsigned recsz; /* for sa mads (attribute offset) */ + int timeout; + uint32_t oui; /* for vendor range 2 mads */ +} ib_rpc_t; + +typedef struct portid { + int lid; /* lid or 0 if directed route */ + ib_dr_path_t drpath; + int grh_present; /* flag */ + ibmad_gid_t gid; + uint32_t qp; + uint32_t qkey; + uint8_t sl; + unsigned pkey_idx; +} ib_portid_t; + +typedef void (ib_mad_dump_fn)(char *buf, int bufsz, void *val, int valsz); + +#define IB_FIELD_NAME_LEN 32 + +typedef struct ib_field { + int bitoffs; + int bitlen; + char name[IB_FIELD_NAME_LEN]; + ib_mad_dump_fn *def_dump_fn; +} ib_field_t; + +enum MAD_FIELDS { + IB_NO_FIELD, + + IB_GID_PREFIX_F, + IB_GID_GUID_F, + + /* first MAD word (0-3 bytes) */ + IB_MAD_METHOD_F, + IB_MAD_RESPONSE_F, + IB_MAD_CLASSVER_F, + IB_MAD_MGMTCLASS_F, + IB_MAD_BASEVER_F, + + /* second MAD word (4-7 bytes) */ + IB_MAD_STATUS_F, + + /* DRSMP only */ + IB_DRSMP_HOPCNT_F, + IB_DRSMP_HOPPTR_F, + IB_DRSMP_STATUS_F, + IB_DRSMP_DIRECTION_F, + + /* words 3,4,5,6 (8-23 bytes) */ + IB_MAD_TRID_F, + IB_MAD_ATTRID_F, + IB_MAD_ATTRMOD_F, + + /* word 7,8 (24-31 bytes) */ + IB_MAD_MKEY_F, + + /* word 9 (32-37 bytes) */ + IB_DRSMP_DRSLID_F, + IB_DRSMP_DRDLID_F, + + /* word 10,11 (36-43 bytes) */ + IB_SA_MKEY_F, + + /* word 12 (44-47 bytes) */ + IB_SA_ATTROFFS_F, + + /* word 13,14 (48-55 bytes) */ + IB_SA_COMPMASK_F, + + /* word 13,14 (56-255 bytes) */ + IB_SA_DATA_F, + + /* bytes 64 - 127 */ + IB_SM_DATA_F, + + /* bytes 64 - 256 */ + IB_GS_DATA_F, + + /* bytes 128 - 191 */ + IB_DRSMP_PATH_F, + + /* bytes 192 - 255 */ + IB_DRSMP_RPATH_F, + + /* + * PortInfo fields: + */ + IB_PORT_FIRST_F, + IB_PORT_MKEY_F = IB_PORT_FIRST_F, + IB_PORT_GID_PREFIX_F, + IB_PORT_LID_F, + IB_PORT_SMLID_F, + IB_PORT_CAPMASK_F, + IB_PORT_DIAG_F, + IB_PORT_MKEY_LEASE_F, + IB_PORT_LOCAL_PORT_F, + IB_PORT_LINK_WIDTH_ENABLED_F, + IB_PORT_LINK_WIDTH_SUPPORTED_F, + IB_PORT_LINK_WIDTH_ACTIVE_F, + IB_PORT_LINK_SPEED_SUPPORTED_F, + IB_PORT_STATE_F, + IB_PORT_PHYS_STATE_F, + IB_PORT_LINK_DOWN_DEF_F, + IB_PORT_MKEY_PROT_BITS_F, + IB_PORT_LMC_F, + IB_PORT_LINK_SPEED_ACTIVE_F, + IB_PORT_LINK_SPEED_ENABLED_F, + IB_PORT_NEIGHBOR_MTU_F, + IB_PORT_SMSL_F, + IB_PORT_VL_CAP_F, + IB_PORT_INIT_TYPE_F, + IB_PORT_VL_HIGH_LIMIT_F, + IB_PORT_VL_ARBITRATION_HIGH_CAP_F, + IB_PORT_VL_ARBITRATION_LOW_CAP_F, + IB_PORT_INIT_TYPE_REPLY_F, + IB_PORT_MTU_CAP_F, + IB_PORT_VL_STALL_COUNT_F, + IB_PORT_HOQ_LIFE_F, + IB_PORT_OPER_VLS_F, + IB_PORT_PART_EN_INB_F, + IB_PORT_PART_EN_OUTB_F, + IB_PORT_FILTER_RAW_INB_F, + IB_PORT_FILTER_RAW_OUTB_F, + IB_PORT_MKEY_VIOL_F, + IB_PORT_PKEY_VIOL_F, + IB_PORT_QKEY_VIOL_F, + IB_PORT_GUID_CAP_F, + IB_PORT_CLIENT_REREG_F, + IB_PORT_SUBN_TIMEOUT_F, + IB_PORT_RESP_TIME_VAL_F, + IB_PORT_LOCAL_PHYS_ERR_F, + IB_PORT_OVERRUN_ERR_F, + IB_PORT_MAX_CREDIT_HINT_F, + IB_PORT_LINK_ROUND_TRIP_F, + IB_PORT_LAST_F, + + /* + * NodeInfo fields: + */ + IB_NODE_FIRST_F, + IB_NODE_BASE_VERS_F = IB_NODE_FIRST_F, + IB_NODE_CLASS_VERS_F, + IB_NODE_TYPE_F, + IB_NODE_NPORTS_F, + IB_NODE_SYSTEM_GUID_F, + IB_NODE_GUID_F, + IB_NODE_PORT_GUID_F, + IB_NODE_PARTITION_CAP_F, + IB_NODE_DEVID_F, + IB_NODE_REVISION_F, + IB_NODE_LOCAL_PORT_F, + IB_NODE_VENDORID_F, + IB_NODE_LAST_F, + + /* + * SwitchInfo fields: + */ + IB_SW_FIRST_F, + IB_SW_LINEAR_FDB_CAP_F = IB_SW_FIRST_F, + IB_SW_RANDOM_FDB_CAP_F, + IB_SW_MCAST_FDB_CAP_F, + IB_SW_LINEAR_FDB_TOP_F, + IB_SW_DEF_PORT_F, + IB_SW_DEF_MCAST_PRIM_F, + IB_SW_DEF_MCAST_NOT_PRIM_F, + IB_SW_LIFE_TIME_F, + IB_SW_STATE_CHANGE_F, + IB_SW_LIDS_PER_PORT_F, + IB_SW_PARTITION_ENFORCE_CAP_F, + IB_SW_PARTITION_ENF_INB_F, + IB_SW_PARTITION_ENF_OUTB_F, + IB_SW_FILTER_RAW_INB_F, + IB_SW_FILTER_RAW_OUTB_F, + IB_SW_ENHANCED_PORT0_F, + IB_SW_LAST_F, + + /* + * SwitchLinearForwardingTable fields: + */ + IB_LINEAR_FORW_TBL_F, + + /* + * SwitchMulticastForwardingTable fields: + */ + IB_MULTICAST_FORW_TBL_F, + + /* + * NodeDescription fields: + */ + IB_NODE_DESC_F, + + /* + * Notice/Trap fields + */ + IB_NOTICE_IS_GENERIC_F, + IB_NOTICE_TYPE_F, + IB_NOTICE_PRODUCER_F, + IB_NOTICE_TRAP_NUMBER_F, + IB_NOTICE_ISSUER_LID_F, + IB_NOTICE_TOGGLE_F, + IB_NOTICE_COUNT_F, + IB_NOTICE_DATA_DETAILS_F, + IB_NOTICE_DATA_LID_F, + IB_NOTICE_DATA_144_LID_F, + IB_NOTICE_DATA_144_CAPMASK_F, + + /* + * GS Performance + */ + IB_PC_FIRST_F, + IB_PC_PORT_SELECT_F = IB_PC_FIRST_F, + IB_PC_COUNTER_SELECT_F, + IB_PC_ERR_SYM_F, + IB_PC_LINK_RECOVERS_F, + IB_PC_LINK_DOWNED_F, + IB_PC_ERR_RCV_F, + IB_PC_ERR_PHYSRCV_F, + IB_PC_ERR_SWITCH_REL_F, + IB_PC_XMT_DISCARDS_F, + IB_PC_ERR_XMTCONSTR_F, + IB_PC_ERR_RCVCONSTR_F, + IB_PC_ERR_LOCALINTEG_F, + IB_PC_ERR_EXCESS_OVR_F, + IB_PC_VL15_DROPPED_F, + IB_PC_XMT_BYTES_F, + IB_PC_RCV_BYTES_F, + IB_PC_XMT_PKTS_F, + IB_PC_RCV_PKTS_F, + IB_PC_LAST_F, + + /* + * SMInfo + */ + IB_SMINFO_GUID_F, + IB_SMINFO_KEY_F, + IB_SMINFO_ACT_F, + IB_SMINFO_PRIO_F, + IB_SMINFO_STATE_F, + + /* + * SA RMPP + */ + IB_SA_RMPP_VERS_F, + IB_SA_RMPP_TYPE_F, + IB_SA_RMPP_RESP_F, + IB_SA_RMPP_FLAGS_F, + IB_SA_RMPP_STATUS_F, + + /* data1 */ + IB_SA_RMPP_D1_F, + IB_SA_RMPP_SEGNUM_F, + /* data2 */ + IB_SA_RMPP_D2_F, + IB_SA_RMPP_LEN_F, /* DATA: Payload len */ + IB_SA_RMPP_NEWWIN_F, /* ACK: new window last */ + + /* + * SA Multi Path rec + */ + IB_SA_MP_NPATH_F, + IB_SA_MP_NSRC_F, + IB_SA_MP_NDEST_F, + IB_SA_MP_GID0_F, + + /* + * SA Path rec + */ + IB_SA_PR_DGID_F, + IB_SA_PR_SGID_F, + IB_SA_PR_DLID_F, + IB_SA_PR_SLID_F, + IB_SA_PR_NPATH_F, + + /* + * MC Member rec + */ + IB_SA_MCM_MGID_F, + IB_SA_MCM_PORTGID_F, + IB_SA_MCM_QKEY_F, + IB_SA_MCM_MLID_F, + IB_SA_MCM_SL_F, + IB_SA_MCM_MTU_F, + IB_SA_MCM_RATE_F, + IB_SA_MCM_TCLASS_F, + IB_SA_MCM_PKEY_F, + IB_SA_MCM_FLOW_LABEL_F, + IB_SA_MCM_JOIN_STATE_F, + IB_SA_MCM_PROXY_JOIN_F, + + /* + * Service record + */ + IB_SA_SR_ID_F, + IB_SA_SR_GID_F, + IB_SA_SR_PKEY_F, + IB_SA_SR_LEASE_F, + IB_SA_SR_KEY_F, + IB_SA_SR_NAME_F, + IB_SA_SR_DATA_F, + + /* + * ATS SM record - within SA_SR_DATA + */ + IB_ATS_SM_NODE_ADDR_F, + IB_ATS_SM_MAGIC_KEY_F, + IB_ATS_SM_NODE_TYPE_F, + IB_ATS_SM_NODE_NAME_F, + + /* + * SLTOVL MAPPING TABLE + */ + IB_SLTOVL_MAPPING_TABLE_F, + + /* + * VL ARBITRATION TABLE + */ + IB_VL_ARBITRATION_TABLE_F, + + /* + * IB vendor class range 2 + */ + IB_VEND2_OUI_F, + IB_VEND2_DATA_F, + + /* + * PortCountersExtended + */ + IB_PC_EXT_FIRST_F, + IB_PC_EXT_PORT_SELECT_F = IB_PC_EXT_FIRST_F, + IB_PC_EXT_COUNTER_SELECT_F, + IB_PC_EXT_XMT_BYTES_F, + IB_PC_EXT_RCV_BYTES_F, + IB_PC_EXT_XMT_PKTS_F, + IB_PC_EXT_RCV_PKTS_F, + IB_PC_EXT_XMT_UPKTS_F, + IB_PC_EXT_RCV_UPKTS_F, + IB_PC_EXT_XMT_MPKTS_F, + IB_PC_EXT_RCV_MPKTS_F, + IB_PC_EXT_LAST_F, + + /* + * GUIDInfo fields + */ + IB_GUID_GUID0_F, + + IB_FIELD_LAST_ /* must be last */ +}; + +/* + * SA RMPP section + */ +enum RMPP_TYPE_ENUM { + IB_RMPP_TYPE_NONE, + IB_RMPP_TYPE_DATA, + IB_RMPP_TYPE_ACK, + IB_RMPP_TYPE_STOP, + IB_RMPP_TYPE_ABORT, +}; + +enum RMPP_FLAGS_ENUM { + IB_RMPP_FLAG_ACTIVE = 1 << 0, + IB_RMPP_FLAG_FIRST = 1 << 1, + IB_RMPP_FLAG_LAST = 1 << 2, +}; + +typedef struct { + int type; + int flags; + int status; + union { + uint32_t u; + uint32_t segnum; + } d1; + union { + uint32_t u; + uint32_t len; + uint32_t newwin; + } d2; +} ib_rmpp_hdr_t; + +enum SA_SIZES_ENUM { + SA_HEADER_SZ = 20, +}; + +typedef struct ib_sa_call { + unsigned attrid; + unsigned mod; + uint64_t mask; + unsigned method; + + uint64_t trid; /* used for out mad if nonzero, return real val */ + unsigned recsz; /* return field */ + ib_rmpp_hdr_t rmpp; +} ib_sa_call_t; + +typedef struct ib_vendor_call { + unsigned method; + unsigned mgmt_class; + unsigned attrid; + unsigned mod; + uint32_t oui; + unsigned timeout; + ib_rmpp_hdr_t rmpp; +} ib_vendor_call_t; + +#define IB_MIN_UCAST_LID 1 +#define IB_MAX_UCAST_LID (0xc000-1) +#define IB_MIN_MCAST_LID 0xc000 +#define IB_MAX_MCAST_LID (0xffff-1) + +#define IB_LID_VALID(lid) ((lid) >= IB_MIN_UCAST_LID && lid <= IB_MAX_UCAST_LID) +#define IB_MLID_VALID(lid) ((lid) >= IB_MIN_MCAST_LID && lid <= IB_MAX_MCAST_LID) + +#define MAD_DEF_RETRIES 3 +#define MAD_DEF_TIMEOUT_MS 1000 + +enum { + IB_DEST_LID, + IB_DEST_DRPATH, + IB_DEST_GUID, + IB_DEST_DRSLID, +}; + +enum { + IB_NODE_CA = 1, + IB_NODE_SWITCH, + IB_NODE_ROUTER, + NODE_RNIC, + + IB_NODE_MAX = NODE_RNIC +}; + +/******************************************************************************/ + +/* portid.c */ +MAD_EXPORT char * portid2str(ib_portid_t *portid); +MAD_EXPORT int portid2portnum(ib_portid_t *portid); +MAD_EXPORT int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid); +MAD_EXPORT char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size); + +static inline int +ib_portid_set(ib_portid_t *portid, int lid, int qp, int qkey) +{ + portid->lid = lid; + portid->qp = qp; + portid->qkey = qkey; + portid->grh_present = 0; + + return 0; +} + +/* fields.c */ +MAD_EXPORT uint32_t mad_get_field(void *buf, int base_offs, int field); +MAD_EXPORT void mad_set_field(void *buf, int base_offs, int field, uint32_t val); +/* field must be byte aligned */ +MAD_EXPORT uint64_t mad_get_field64(void *buf, int base_offs, int field); +MAD_EXPORT void mad_set_field64(void *buf, int base_offs, int field, uint64_t val); +MAD_EXPORT void mad_set_array(void *buf, int base_offs, int field, void *val); +MAD_EXPORT void mad_get_array(void *buf, int base_offs, int field, void *val); +MAD_EXPORT void mad_decode_field(uint8_t *buf, int field, void *val); +MAD_EXPORT void mad_encode_field(uint8_t *buf, int field, void *val); +MAD_EXPORT int mad_print_field(int field, const char *name, void *val); +MAD_EXPORT char *mad_dump_field(int field, char *buf, int bufsz, void *val); +MAD_EXPORT char *mad_dump_val(int field, char *buf, int bufsz, void *val); + +/* mad.c */ +MAD_EXPORT void *mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data); +MAD_EXPORT uint64_t mad_trid(void); +MAD_EXPORT int mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data); + +/* register.c */ +MAD_EXPORT int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version); +MAD_EXPORT int mad_register_client(int mgmt, uint8_t rmpp_version); +MAD_EXPORT int mad_register_server(int mgmt, uint8_t rmpp_version, + long method_mask[16/sizeof(long)], + uint32_t class_oui); +MAD_EXPORT int mad_class_agent(int mgmt); +MAD_EXPORT int mad_agent_class(int agent); + +/* serv.c */ +MAD_EXPORT int mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, + void *data); +MAD_EXPORT void * mad_receive(void *umad, int timeout); +MAD_EXPORT int mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus); +MAD_EXPORT void * mad_alloc(void); +MAD_EXPORT void mad_free(void *umad); + +/* vendor.c */ +MAD_EXPORT uint8_t *ib_vendor_call(void *data, ib_portid_t *portid, + ib_vendor_call_t *call); + +static inline int +mad_is_vendor_range1(int mgmt) +{ + return mgmt >= 0x9 && mgmt <= 0xf; +} + +static inline int +mad_is_vendor_range2(int mgmt) +{ + return mgmt >= 0x30 && mgmt <= 0x4f; +} + +/* rpc.c */ +MAD_EXPORT int madrpc_portid(void); +MAD_EXPORT int madrpc_set_retries(int retries); +MAD_EXPORT int madrpc_set_timeout(int timeout); +void * madrpc(ib_rpc_t *rpc, ib_portid_t *dport, void *payload, void *rcvdata); +void * madrpc_rmpp(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, + void *data); +MAD_EXPORT void madrpc_init(char *dev_name, int dev_port, int *mgmt_classes, + int num_classes); +void madrpc_save_mad(void *madbuf, int len); +MAD_EXPORT void madrpc_show_errors(int set); + +void * mad_rpc_open_port(char *dev_name, int dev_port, int *mgmt_classes, + int num_classes); +void mad_rpc_close_port(void *ibmad_port); +void * mad_rpc(const void *ibmad_port, ib_rpc_t *rpc, ib_portid_t *dport, + void *payload, void *rcvdata); +void * mad_rpc_rmpp(const void *ibmad_port, ib_rpc_t *rpc, ib_portid_t *dport, + ib_rmpp_hdr_t *rmpp, void *data); + +/* smp.c */ +MAD_EXPORT uint8_t * smp_query(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod, + unsigned timeout); +MAD_EXPORT uint8_t * smp_set(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod, + unsigned timeout); +uint8_t * smp_query_via(void *buf, ib_portid_t *id, unsigned attrid, + unsigned mod, unsigned timeout, const void *srcport); +uint8_t * smp_set_via(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod, + unsigned timeout, const void *srcport); + +/* sa.c */ +uint8_t * sa_call(void *rcvbuf, ib_portid_t *portid, ib_sa_call_t *sa, + unsigned timeout); +uint8_t * sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid, + ib_sa_call_t *sa, unsigned timeout); +MAD_EXPORT int ib_path_query(ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t *sm_id, + void *buf); /* returns lid */ +int ib_path_query_via(const void *srcport, ibmad_gid_t srcgid, + ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf); + +/* resolve.c */ +MAD_EXPORT int ib_resolve_smlid(ib_portid_t *sm_id, int timeout); +MAD_EXPORT int ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, + int dest_type, ib_portid_t *sm_id); +MAD_EXPORT int ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid); + +int ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout, + const void *srcport); +int ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid, + ib_portid_t *sm_id, int timeout, + const void *srcport); +int ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, + int dest_type, ib_portid_t *sm_id, + const void *srcport); +int ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid, + const void *srcport); + +/* gs.c */ +MAD_EXPORT uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout); +MAD_EXPORT uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout); +MAD_EXPORT uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port, + unsigned mask, unsigned timeout); +MAD_EXPORT uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout); +MAD_EXPORT uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port, + unsigned mask, unsigned timeout); +MAD_EXPORT uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout); +MAD_EXPORT uint8_t *port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout); + +uint8_t *perf_classportinfo_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport); +uint8_t *port_performance_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport); +uint8_t *port_performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned mask, unsigned timeout, const void *srcport); +uint8_t *port_performance_ext_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport); +uint8_t *port_performance_ext_reset_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned mask, unsigned timeout, const void *srcport); +uint8_t *port_samples_control_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport); +uint8_t *port_samples_result_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport); +/* dump.c */ +MAD_EXPORT ib_mad_dump_fn + mad_dump_int, mad_dump_uint, mad_dump_hex, mad_dump_rhex, + mad_dump_bitfield, mad_dump_array, mad_dump_string, + mad_dump_linkwidth, mad_dump_linkwidthsup, mad_dump_linkwidthen, + mad_dump_linkdowndefstate, + mad_dump_linkspeed, mad_dump_linkspeedsup, mad_dump_linkspeeden, + mad_dump_portstate, mad_dump_portstates, + mad_dump_physportstate, mad_dump_portcapmask, + mad_dump_mtu, mad_dump_vlcap, mad_dump_opervls, + mad_dump_node_type, + mad_dump_sltovl, mad_dump_vlarbitration, + mad_dump_nodedesc, mad_dump_nodeinfo, mad_dump_portinfo, mad_dump_switchinfo, + mad_dump_perfcounters, mad_dump_perfcounters_ext; + +extern int ibdebug; + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#ifndef ntohll +static inline uint64_t ntohll(uint64_t x) { + return bswap_64(x); +} +#endif +#ifndef htonll +static inline uint64_t htonll(uint64_t x) { + return bswap_64(x); +} +#endif +#elif __BYTE_ORDER == __BIG_ENDIAN +#ifndef ntohll +static inline uint64_t ntohll(uint64_t x) { + return x; +} +#endif +#ifndef htonll +static inline uint64_t htonll(uint64_t x) { + return x; +} +#endif +#endif /* __BYTE_ORDER == __BIG_ENDIAN */ + +/* Misc. macros: */ +/** align value \a l to \a size (ceil) */ +#define ALIGN(l, size) (((l) + ((size) - 1)) / (size) * (size)) + +/** printf style warning MACRO, includes name of function and pid */ +#define IBWARN(fmt, ...) fprintf(stdout, "ibwarn: [%d] %s: "fmt"\n", getpid(), __func__, ## __VA_ARGS__); + +/** printf style abort MACRO, includes name of function and pid */ +#define IBPANIC(fmt, ...) do { \ + fprintf(stdout, "ibpanic: [%d] %s: " fmt ": %m\n", getpid(), __func__, ## __VA_ARGS__); \ + exit(-1); \ +} while(0) + +void xdump(FILE *file, char *msg, void *p, int size); + +END_C_DECLS + +#endif /* _MAD_H_ */ diff --git a/trunk/ulp/libibmad/src/Sources b/trunk/ulp/libibmad/src/Sources index 94ee9c89..11df62fe 100644 --- a/trunk/ulp/libibmad/src/Sources +++ b/trunk/ulp/libibmad/src/Sources @@ -13,7 +13,6 @@ DLLENTRY = DllMain USE_MSVCRT=1 SOURCES = \ - ibmad.rc \ ibmad_main.cpp \ dump.c \ fields.c \ @@ -28,7 +27,7 @@ SOURCES = \ smp.c \ vendor.c -INCLUDES = ..\include\infiniband;..\..\libibverbs\include;..\..\libibumad\include;..\..\..\inc;..\..\..\inc\user; +INCLUDES = ..\include\infiniband;..\..\libibmad\include;..\..\libibverbs\include;..\..\libibumad\include;..\..\..\inc;..\..\..\inc\user; USER_C_FLAGS = $(USER_C_FLAGS) -DEXPORT_IBMAD_SYMBOLS diff --git a/trunk/ulp/libibmad/src/dump.c b/trunk/ulp/libibmad/src/dump.c index afccb575..a7575b9a 100644 --- a/trunk/ulp/libibmad/src/dump.c +++ b/trunk/ulp/libibmad/src/dump.c @@ -1,815 +1,750 @@ -/* - * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved. - * Copyright (c) 2007 Xsigo Systems Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#define snprintf _snprintf -#else -#include -#include -#include -#include -#endif - -#include -#include - -MAD_EXPORT void -xdump(FILE *file, char *msg, void *p, int size) -{ -#define HEX(x) ((x) < 10 ? '0' + (x) : 'a' + ((x) -10)) - uint8_t *cp = p; - int i; - - if (msg) - fputs(msg, file); - - for (i = 0; i < size;) { - fputc(HEX(*cp >> 4), file); - fputc(HEX(*cp & 0xf), file); - if (++i >= size) - break; - fputc(HEX(cp[1] >> 4), file); - fputc(HEX(cp[1] & 0xf), file); - if ((++i) % 16) - fputc(' ', file); - else - fputc('\n', file); - cp += 2; - } - if (i % 16) { - fputc('\n', file); - } -} - -MAD_EXPORT void -mad_dump_int(char *buf, int bufsz, void *val, int valsz) -{ - switch (valsz) { - case 1: - snprintf(buf, bufsz, "%d", *(uint8_t *)val); - break; - case 2: - snprintf(buf, bufsz, "%d", *(uint16_t *)val); - break; - case 3: - case 4: - snprintf(buf, bufsz, "%d", *(uint32_t *)val); - break; - case 5: - case 6: - case 7: - case 8: - snprintf(buf, bufsz, "%" PRIu64, *(uint64_t *)val); - break; - default: - IBWARN("bad int sz %d", valsz); - buf[0] = 0; - } -} - -MAD_EXPORT void -mad_dump_uint(char *buf, int bufsz, void *val, int valsz) -{ - switch (valsz) { - case 1: - snprintf(buf, bufsz, "%u", *(uint8_t *)val); - break; - case 2: - snprintf(buf, bufsz, "%u", *(uint16_t *)val); - break; - case 3: - case 4: - snprintf(buf, bufsz, "%u", *(uint32_t *)val); - break; - case 5: - case 6: - case 7: - case 8: - snprintf(buf, bufsz, "%" PRIu64, *(uint64_t *)val); - break; - default: - IBWARN("bad int sz %u", valsz); - buf[0] = 0; - } -} - -MAD_EXPORT void -mad_dump_hex(char *buf, int bufsz, void *val, int valsz) -{ - switch (valsz) { - case 1: - snprintf(buf, bufsz, "0x%02x", *(uint8_t *)val); - break; - case 2: - snprintf(buf, bufsz, "0x%04x", *(uint16_t *)val); - break; - case 3: - snprintf(buf, bufsz, "0x%06x", *(uint32_t *)val & 0xffffff); - break; - case 4: - snprintf(buf, bufsz, "0x%08x", *(uint32_t *)val); - break; - case 5: - snprintf(buf, bufsz, "0x%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffULL); - break; - case 6: - snprintf(buf, bufsz, "0x%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffULL); - break; - case 7: - snprintf(buf, bufsz, "0x%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffULL); - break; - case 8: - snprintf(buf, bufsz, "0x%016" PRIx64, *(uint64_t *)val); - break; - default: - IBWARN("bad int sz %d", valsz); - buf[0] = 0; - } -} - -MAD_EXPORT void -mad_dump_rhex(char *buf, int bufsz, void *val, int valsz) -{ - switch (valsz) { - case 1: - snprintf(buf, bufsz, "%02x", *(uint8_t *)val); - break; - case 2: - snprintf(buf, bufsz, "%04x", *(uint16_t *)val); - break; - case 3: - snprintf(buf, bufsz, "%06x", *(uint32_t *)val & 0xffffff); - break; - case 4: - snprintf(buf, bufsz, "%08x", *(uint32_t *)val); - break; - case 5: - snprintf(buf, bufsz, "%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffULL); - break; - case 6: - snprintf(buf, bufsz, "%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffULL); - break; - case 7: - snprintf(buf, bufsz, "%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffULL); - break; - case 8: - snprintf(buf, bufsz, "%016" PRIx64, *(uint64_t *)val); - break; - default: - IBWARN("bad int sz %d", valsz); - buf[0] = 0; - } -} - -MAD_EXPORT void -mad_dump_linkwidth(char *buf, int bufsz, void *val, int valsz) -{ - int width = *(int *)val; - - switch (width) { - case 1: - snprintf(buf, bufsz, "1X"); - break; - case 2: - snprintf(buf, bufsz, "4X"); - break; - case 4: - snprintf(buf, bufsz, "8X"); - break; - case 8: - snprintf(buf, bufsz, "12X"); - break; - default: - IBWARN("bad width %d", width); - buf[0] = 0; - } -} - -static void -dump_linkwidth(char *buf, int bufsz, int width) -{ - int n = 0; - - if (width & 0x1) - n += snprintf(buf + n, bufsz - n, "1X or "); - if (n < bufsz && (width & 0x2)) - n += snprintf(buf + n, bufsz - n, "4X or "); - if (n < bufsz && (width & 0x4)) - n += snprintf(buf + n, bufsz - n, "8X or "); - if (n < bufsz && (width & 0x8)) - n += snprintf(buf + n, bufsz - n, "12X or "); - - if (n >= bufsz) - return; - else if (width == 0 || (width >> 4)) - snprintf(buf + n, bufsz - n, "undefined (%d)", width); - else if (bufsz > 3) - buf[n-4] = '\0'; -} - -MAD_EXPORT void -mad_dump_linkwidthsup(char *buf, int bufsz, void *val, int valsz) -{ - int width = *(int *)val; - - dump_linkwidth(buf, bufsz, width); - - switch(width) { - case 1: - case 3: - case 7: - case 11: - case 15: - break; - - default: - if (!(width >> 4)) - snprintf(buf + strlen(buf), bufsz - strlen(buf), - " (IBA extension)"); - break; - } -} - -MAD_EXPORT void -mad_dump_linkwidthen(char *buf, int bufsz, void *val, int valsz) -{ - int width = *(int *)val; - - dump_linkwidth(buf, bufsz, width); -} - -MAD_EXPORT void -mad_dump_linkspeed(char *buf, int bufsz, void *val, int valsz) -{ - int speed = *(int *)val; - - switch (speed) { - case 1: - snprintf(buf, bufsz, "2.5 Gbps"); - break; - case 2: - snprintf(buf, bufsz, "5.0 Gbps"); - break; - case 4: - snprintf(buf, bufsz, "10.0 Gbps"); - break; - default: - snprintf(buf, bufsz, "undefined (%d)", speed); - break; - } -} - -static void -dump_linkspeed(char *buf, int bufsz, int speed) -{ - int n = 0; - - if (speed & 0x1) - n += snprintf(buf + n, bufsz - n, "2.5 Gbps or "); - if (n < bufsz && (speed & 0x2)) - n += snprintf(buf + n, bufsz - n, "5.0 Gbps or "); - if (n < bufsz && (speed & 0x4)) - n += snprintf(buf + n, bufsz - n, "10.0 Gbps or "); - - if (n >= bufsz) - return; - else if (speed == 0 || (speed >> 3)) { - n += snprintf(buf + n, bufsz - n, "undefined (%d)", speed); - if (n >= bufsz) - return; - } else if (bufsz > 3) { - buf[n-4] = '\0'; - n -= 4; - } - - switch (speed) { - case 1: - case 3: - case 5: - case 7: - break; - default: - if (!(speed >> 3)) - snprintf(buf + n, bufsz - n, " (IBA extension)"); - break; - } -} - -MAD_EXPORT void -mad_dump_linkspeedsup(char *buf, int bufsz, void *val, int valsz) -{ - int speed = *(int *)val; - - dump_linkspeed(buf, bufsz, speed); -} - -MAD_EXPORT void -mad_dump_linkspeeden(char *buf, int bufsz, void *val, int valsz) -{ - int speed = *(int *)val; - - dump_linkspeed(buf, bufsz, speed); -} - -MAD_EXPORT void -mad_dump_portstate(char *buf, int bufsz, void *val, int valsz) -{ - int state = *(int *)val; - - switch (state) { - case 0: - snprintf(buf, bufsz, "NoChange"); - break; - case 1: - snprintf(buf, bufsz, "Down"); - break; - case 2: - snprintf(buf, bufsz, "Initialize"); - break; - case 3: - snprintf(buf, bufsz, "Armed"); - break; - case 4: - snprintf(buf, bufsz, "Active"); - break; - default: - snprintf(buf, bufsz, "?(%d)", state); - } -} - -MAD_EXPORT void -mad_dump_linkdowndefstate(char *buf, int bufsz, void *val, int valsz) -{ - int state = *(int *)val; - - switch(state) { - case 0: - snprintf(buf, bufsz, "NoChange"); - break; - case 1: - snprintf(buf, bufsz, "Sleep"); - break; - case 2: - snprintf(buf, bufsz, "Polling"); - break; - default: - snprintf(buf, bufsz, "?(%d)", state); - break; - } -} - -MAD_EXPORT void -mad_dump_physportstate(char *buf, int bufsz, void *val, int valsz) -{ - int state = *(int *)val; - - switch (state) { - case 0: - snprintf(buf, bufsz, "NoChange"); - break; - case 1: - snprintf(buf, bufsz, "Sleep"); - break; - case 2: - snprintf(buf, bufsz, "Polling"); - break; - case 3: - snprintf(buf, bufsz, "Disabled"); - break; - case 4: - snprintf(buf, bufsz, "PortConfigurationTraining"); - break; - case 5: - snprintf(buf, bufsz, "LinkUp"); - break; - case 6: - snprintf(buf, bufsz, "LinkErrorRecovery"); - break; - case 7: - snprintf(buf, bufsz, "PhyTest"); - break; - default: - snprintf(buf, bufsz, "?(%d)", state); - } -} - -MAD_EXPORT void -mad_dump_mtu(char *buf, int bufsz, void *val, int valsz) -{ - int mtu = *(int *)val; - - switch (mtu) { - case 1: - snprintf(buf, bufsz, "256"); - break; - case 2: - snprintf(buf, bufsz, "512"); - break; - case 3: - snprintf(buf, bufsz, "1024"); - break; - case 4: - snprintf(buf, bufsz, "2048"); - break; - case 5: - snprintf(buf, bufsz, "4096"); - break; - default: - snprintf(buf, bufsz, "?(%d)", mtu); - buf[0] = 0; - } -} - -MAD_EXPORT void -mad_dump_vlcap(char *buf, int bufsz, void *val, int valsz) -{ - int vlcap = *(int *)val; - - switch (vlcap) { - case 1: - snprintf(buf, bufsz, "VL0"); - break; - case 2: - snprintf(buf, bufsz, "VL0-1"); - break; - case 3: - snprintf(buf, bufsz, "VL0-3"); - break; - case 4: - snprintf(buf, bufsz, "VL0-7"); - break; - case 5: - snprintf(buf, bufsz, "VL0-14"); - break; - default: - snprintf(buf, bufsz, "?(%d)", vlcap); - } -} - -MAD_EXPORT void -mad_dump_opervls(char *buf, int bufsz, void *val, int valsz) -{ - int opervls = *(int *)val; - - switch (opervls) { - case 0: - snprintf(buf, bufsz, "No change"); - break; - case 1: - snprintf(buf, bufsz, "VL0"); - break; - case 2: - snprintf(buf, bufsz, "VL0-1"); - break; - case 3: - snprintf(buf, bufsz, "VL0-3"); - break; - case 4: - snprintf(buf, bufsz, "VL0-7"); - break; - case 5: - snprintf(buf, bufsz, "VL0-14"); - break; - default: - snprintf(buf, bufsz, "?(%d)", opervls); - } -} - -MAD_EXPORT void -mad_dump_portcapmask(char *buf, int bufsz, void *val, int valsz) -{ - unsigned mask = *(unsigned *)val; - char *s = buf; - - s += sprintf(s, "0x%x\n", mask); - if (mask & (1 << 1)) - s += sprintf(s, "\t\t\t\tIsSM\n"); - if (mask & (1 << 2)) - s += sprintf(s, "\t\t\t\tIsNoticeSupported\n"); - if (mask & (1 << 3)) - s += sprintf(s, "\t\t\t\tIsTrapSupported\n"); - if (mask & (1 << 5)) - s += sprintf(s, "\t\t\t\tIsAutomaticMigrationSupported\n"); - if (mask & (1 << 6)) - s += sprintf(s, "\t\t\t\tIsSLMappingSupported\n"); - if (mask & (1 << 7)) - s += sprintf(s, "\t\t\t\tIsMKeyNVRAM\n"); - if (mask & (1 << 8)) - s += sprintf(s, "\t\t\t\tIsPKeyNVRAM\n"); - if (mask & (1 << 9)) - s += sprintf(s, "\t\t\t\tIsLedInfoSupported\n"); - if (mask & (1 << 10)) - s += sprintf(s, "\t\t\t\tIsSMdisabled\n"); - if (mask & (1 << 11)) - s += sprintf(s, "\t\t\t\tIsSystemImageGUIDsupported\n"); - if (mask & (1 << 12)) - s += sprintf(s, "\t\t\t\tIsPkeySwitchExternalPortTrapSupported\n"); - if (mask & (1 << 16)) - s += sprintf(s, "\t\t\t\tIsCommunicatonManagementSupported\n"); - if (mask & (1 << 17)) - s += sprintf(s, "\t\t\t\tIsSNMPTunnelingSupported\n"); - if (mask & (1 << 18)) - s += sprintf(s, "\t\t\t\tIsReinitSupported\n"); - if (mask & (1 << 19)) - s += sprintf(s, "\t\t\t\tIsDeviceManagementSupported\n"); - if (mask & (1 << 20)) - s += sprintf(s, "\t\t\t\tIsVendorClassSupported\n"); - if (mask & (1 << 21)) - s += sprintf(s, "\t\t\t\tIsDRNoticeSupported\n"); - if (mask & (1 << 22)) - s += sprintf(s, "\t\t\t\tIsCapabilityMaskNoticeSupported\n"); - if (mask & (1 << 23)) - s += sprintf(s, "\t\t\t\tIsBootManagementSupported\n"); - if (mask & (1 << 24)) - s += sprintf(s, "\t\t\t\tIsLinkRoundTripLatencySupported\n"); - if (mask & (1 << 25)) - s += sprintf(s, "\t\t\t\tIsClientRegistrationSupported\n"); - - if (s != buf) - *(--s) = 0; -} - -MAD_EXPORT void -mad_dump_bitfield(char *buf, int bufsz, void *val, int valsz) -{ - snprintf(buf, bufsz, "0x%x", *(uint32_t *)val); -} - -MAD_EXPORT void -mad_dump_array(char *buf, int bufsz, void *val, int valsz) -{ - uint8_t *p = val, *e; - char *s = buf; - - if (bufsz < valsz*2) - valsz = bufsz/2; - - for (p = val, e = p + valsz; p < e; p++, s += 2) - sprintf(s, "%02x", *p); -} - -MAD_EXPORT void -mad_dump_string(char *buf, int bufsz, void *val, int valsz) -{ - if (bufsz < valsz) - valsz = bufsz; - - snprintf(buf, valsz, "'%s'", (char *)val); -} - -MAD_EXPORT void -mad_dump_node_type(char *buf, int bufsz, void *val, int valsz) -{ - int nodetype = *(int*)val; - - switch (nodetype) { - case 1: - snprintf(buf, bufsz, "Channel Adapter"); - break; - case 2: - snprintf(buf, bufsz, "Switch"); - break; - case 3: - snprintf(buf, bufsz, "Router"); - break; - default: - snprintf(buf, bufsz, "?(%d)?", nodetype); - break; - } -} - -#define IB_MAX_NUM_VLS 16 -#define IB_MAX_NUM_VLS_TO_U8 ((IB_MAX_NUM_VLS)/2) - -typedef struct _ib_slvl_table { - uint8_t vl_by_sl_num[IB_MAX_NUM_VLS_TO_U8]; -} ib_slvl_table_t; - -static inline void -ib_slvl_get_i(ib_slvl_table_t *tbl, int i, uint8_t *vl) -{ - *vl = (tbl->vl_by_sl_num[i >> 1] >> ((!(i&1)) << 2)) & 0xf; -} - -#define IB_NUM_VL_ARB_ELEMENTS_IN_BLOCK 32 - -typedef struct _ib_vl_arb_table { - struct { - uint8_t res_vl; - uint8_t weight; - } vl_entry[IB_NUM_VL_ARB_ELEMENTS_IN_BLOCK]; -} ib_vl_arb_table_t; - -static inline void -ib_vl_arb_get_vl(uint8_t res_vl, uint8_t *const vl ) -{ - *vl = res_vl & 0x0F; -} - -MAD_EXPORT void -mad_dump_sltovl(char *buf, int bufsz, void *val, int valsz) -{ - ib_slvl_table_t* p_slvl_tbl = val; - uint8_t vl; - int i, n = 0; - n = snprintf(buf, bufsz, "|"); - for (i = 0; i < 16; i++) { - ib_slvl_get_i(p_slvl_tbl, i, &vl); - n += snprintf(buf + n, bufsz - n, "%2u|", vl); - if (n >= bufsz) - break; - } - snprintf(buf + n, bufsz - n, "\n"); -} - -MAD_EXPORT void -mad_dump_vlarbitration(char *buf, int bufsz, void *val, int num) -{ - ib_vl_arb_table_t* p_vla_tbl = val; - int i, n; - uint8_t vl; - - num /= sizeof(p_vla_tbl->vl_entry[0]); - - n = snprintf(buf, bufsz, "\nVL : |"); - if (n >= bufsz) - return; - for (i = 0; i < num; i++) { - ib_vl_arb_get_vl(p_vla_tbl->vl_entry[i].res_vl, &vl); - n += snprintf(buf + n, bufsz - n, "0x%-2X|", vl); - if (n >= bufsz) - return; - } - - n += snprintf(buf + n, bufsz - n, "\nWEIGHT: |"); - if (n >= bufsz) - return; - for (i = 0; i < num; i++) { - n += snprintf(buf + n, bufsz - n, "0x%-2X|", - p_vla_tbl->vl_entry[i].weight); - if (n >= bufsz) - return; - } - - snprintf(buf + n, bufsz - n, "\n"); -} - -static int -_dump_fields(char *buf, int bufsz, void *data, int start, int end) -{ - char val[64]; - char *s = buf; - int n, field; - - for (field = start; field < end && bufsz > 0; field++) { - mad_decode_field(data, field, val); - if (!mad_dump_field(field, s, bufsz, val)) - return -1; - n = strlen(s); - s += n; - *s++ = '\n'; - *s = 0; - n++; - bufsz -= n; - } - - return (int)(s - buf); -} - -MAD_EXPORT void -mad_dump_nodedesc(char *buf, int bufsz, void *val, int valsz) -{ - strncpy(buf, val, bufsz); - - if (valsz < bufsz) - buf[valsz] = 0; -} - -MAD_EXPORT void -mad_dump_nodeinfo(char *buf, int bufsz, void *val, int valsz) -{ - _dump_fields(buf, bufsz, val, IB_NODE_FIRST_F, IB_NODE_LAST_F); -} - -MAD_EXPORT void -mad_dump_portinfo(char *buf, int bufsz, void *val, int valsz) -{ - _dump_fields(buf, bufsz, val, IB_PORT_FIRST_F, IB_PORT_LAST_F); -} - -MAD_EXPORT void -mad_dump_portstates(char *buf, int bufsz, void *val, int valsz) -{ - _dump_fields(buf, bufsz, val, IB_PORT_STATE_F, IB_PORT_LINK_DOWN_DEF_F); -} - -MAD_EXPORT void -mad_dump_switchinfo(char *buf, int bufsz, void *val, int valsz) -{ - _dump_fields(buf, bufsz, val, IB_SW_FIRST_F, IB_SW_LAST_F); -} - -MAD_EXPORT void -mad_dump_perfcounters(char *buf, int bufsz, void *val, int valsz) -{ - _dump_fields(buf, bufsz, val, IB_PC_FIRST_F, IB_PC_LAST_F); -} - -MAD_EXPORT void -mad_dump_perfcounters_ext(char *buf, int bufsz, void *val, int valsz) -{ - _dump_fields(buf, bufsz, val, IB_PC_EXT_FIRST_F, IB_PC_EXT_LAST_F); -} - -/************************/ - -char * -_mad_dump_val(ib_field_t *f, char *buf, int bufsz, void *val) -{ - f->def_dump_fn(buf, bufsz, val, ALIGN(f->bitlen, 8) / 8); - buf[bufsz - 1] = 0; - - return buf; -} - -char * -_mad_dump_field(ib_field_t *f, char *name, char *buf, int bufsz, void *val) -{ - char dots[128]; - int l, n; - - if (bufsz <= 32) - return 0; /* buf too small */ - - if (!name) - name = f->name; - - l = strlen(name); - if (l < 32) { - memset(dots, '.', 32 - l); - dots[32 - l] = 0; - } - - n = snprintf(buf, bufsz, "%s:%s", name, dots); - _mad_dump_val(f, buf + n, bufsz - n, val); - buf[bufsz - 1] = 0; - - return buf; -} - -int -_mad_dump(ib_mad_dump_fn *fn, char *name, void *val, int valsz) -{ - ib_field_t f; - char buf[512]; - - memset(&f, 0, sizeof(f)); - f.def_dump_fn = fn; - f.bitlen = valsz * 8; - - return printf("%s\n", _mad_dump_field(&f, name, buf, sizeof buf, val)); -} - -int -_mad_print_field(ib_field_t *f, char *name, void *val, int valsz) -{ - return _mad_dump(f->def_dump_fn, name ? name : f->name, val, valsz ? valsz : ALIGN(f->bitlen, 8) / 8); -} - +/* + * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved. + * Copyright (c) 2007 Xsigo Systems Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include + +void +mad_dump_int(char *buf, int bufsz, void *val, int valsz) +{ + switch (valsz) { + case 1: + snprintf(buf, bufsz, "%d", *(uint8_t *)val); + break; + case 2: + snprintf(buf, bufsz, "%d", *(uint16_t *)val); + break; + case 3: + case 4: + snprintf(buf, bufsz, "%d", *(uint32_t *)val); + break; + case 5: + case 6: + case 7: + case 8: + snprintf(buf, bufsz, "%" PRIu64, *(uint64_t *)val); + break; + default: + IBWARN("bad int sz %d", valsz); + buf[0] = 0; + } +} + +void +mad_dump_uint(char *buf, int bufsz, void *val, int valsz) +{ + switch (valsz) { + case 1: + snprintf(buf, bufsz, "%u", *(uint8_t *)val); + break; + case 2: + snprintf(buf, bufsz, "%u", *(uint16_t *)val); + break; + case 3: + case 4: + snprintf(buf, bufsz, "%u", *(uint32_t *)val); + break; + case 5: + case 6: + case 7: + case 8: + snprintf(buf, bufsz, "%" PRIu64, *(uint64_t *)val); + break; + default: + IBWARN("bad int sz %u", valsz); + buf[0] = 0; + } +} + +void +mad_dump_hex(char *buf, int bufsz, void *val, int valsz) +{ + switch (valsz) { + case 1: + snprintf(buf, bufsz, "0x%02x", *(uint8_t *)val); + break; + case 2: + snprintf(buf, bufsz, "0x%04x", *(uint16_t *)val); + break; + case 3: + snprintf(buf, bufsz, "0x%06x", *(uint32_t *)val & 0xffffff); + break; + case 4: + snprintf(buf, bufsz, "0x%08x", *(uint32_t *)val); + break; + case 5: + snprintf(buf, bufsz, "0x%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffULL); + break; + case 6: + snprintf(buf, bufsz, "0x%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffULL); + break; + case 7: + snprintf(buf, bufsz, "0x%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffULL); + break; + case 8: + snprintf(buf, bufsz, "0x%016" PRIx64, *(uint64_t *)val); + break; + default: + IBWARN("bad int sz %d", valsz); + buf[0] = 0; + } +} + +void +mad_dump_rhex(char *buf, int bufsz, void *val, int valsz) +{ + switch (valsz) { + case 1: + snprintf(buf, bufsz, "%02x", *(uint8_t *)val); + break; + case 2: + snprintf(buf, bufsz, "%04x", *(uint16_t *)val); + break; + case 3: + snprintf(buf, bufsz, "%06x", *(uint32_t *)val & 0xffffff); + break; + case 4: + snprintf(buf, bufsz, "%08x", *(uint32_t *)val); + break; + case 5: + snprintf(buf, bufsz, "%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffULL); + break; + case 6: + snprintf(buf, bufsz, "%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffULL); + break; + case 7: + snprintf(buf, bufsz, "%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffULL); + break; + case 8: + snprintf(buf, bufsz, "%016" PRIx64, *(uint64_t *)val); + break; + default: + IBWARN("bad int sz %d", valsz); + buf[0] = 0; + } +} + +void +mad_dump_linkwidth(char *buf, int bufsz, void *val, int valsz) +{ + int width = *(int *)val; + + switch (width) { + case 1: + snprintf(buf, bufsz, "1X"); + break; + case 2: + snprintf(buf, bufsz, "4X"); + break; + case 4: + snprintf(buf, bufsz, "8X"); + break; + case 8: + snprintf(buf, bufsz, "12X"); + break; + default: + IBWARN("bad width %d", width); + buf[0] = 0; + } +} + +static void +dump_linkwidth(char *buf, int bufsz, int width) +{ + int n = 0; + + if (width & 0x1) + n += snprintf(buf + n, bufsz - n, "1X or "); + if (n < bufsz && (width & 0x2)) + n += snprintf(buf + n, bufsz - n, "4X or "); + if (n < bufsz && (width & 0x4)) + n += snprintf(buf + n, bufsz - n, "8X or "); + if (n < bufsz && (width & 0x8)) + n += snprintf(buf + n, bufsz - n, "12X or "); + + if (n >= bufsz) + return; + else if (width == 0 || (width >> 4)) + snprintf(buf + n, bufsz - n, "undefined (%d)", width); + else if (bufsz > 3) + buf[n-4] = '\0'; +} + +void +mad_dump_linkwidthsup(char *buf, int bufsz, void *val, int valsz) +{ + int width = *(int *)val; + + dump_linkwidth(buf, bufsz, width); + + switch(width) { + case 1: + case 3: + case 7: + case 11: + case 15: + break; + + default: + if (!(width >> 4)) + snprintf(buf + strlen(buf), bufsz - strlen(buf), + " (IBA extension)"); + break; + } +} + +void +mad_dump_linkwidthen(char *buf, int bufsz, void *val, int valsz) +{ + int width = *(int *)val; + + dump_linkwidth(buf, bufsz, width); +} + +void +mad_dump_linkspeed(char *buf, int bufsz, void *val, int valsz) +{ + int speed = *(int *)val; + + switch (speed) { + case 1: + snprintf(buf, bufsz, "2.5 Gbps"); + break; + case 2: + snprintf(buf, bufsz, "5.0 Gbps"); + break; + case 4: + snprintf(buf, bufsz, "10.0 Gbps"); + break; + default: + snprintf(buf, bufsz, "undefined (%d)", speed); + break; + } +} + +static void +dump_linkspeed(char *buf, int bufsz, int speed) +{ + int n = 0; + + if (speed & 0x1) + n += snprintf(buf + n, bufsz - n, "2.5 Gbps or "); + if (n < bufsz && (speed & 0x2)) + n += snprintf(buf + n, bufsz - n, "5.0 Gbps or "); + if (n < bufsz && (speed & 0x4)) + n += snprintf(buf + n, bufsz - n, "10.0 Gbps or "); + + if (n >= bufsz) + return; + else if (speed == 0 || (speed >> 3)) { + n += snprintf(buf + n, bufsz - n, "undefined (%d)", speed); + if (n >= bufsz) + return; + } else if (bufsz > 3) { + buf[n-4] = '\0'; + n -= 4; + } + + switch (speed) { + case 1: + case 3: + case 5: + case 7: + break; + default: + if (!(speed >> 3)) + snprintf(buf + n, bufsz - n, " (IBA extension)"); + break; + } +} + +void +mad_dump_linkspeedsup(char *buf, int bufsz, void *val, int valsz) +{ + int speed = *(int *)val; + + dump_linkspeed(buf, bufsz, speed); +} + +void +mad_dump_linkspeeden(char *buf, int bufsz, void *val, int valsz) +{ + int speed = *(int *)val; + + dump_linkspeed(buf, bufsz, speed); +} + +void +mad_dump_portstate(char *buf, int bufsz, void *val, int valsz) +{ + int state = *(int *)val; + + switch (state) { + case 0: + snprintf(buf, bufsz, "NoChange"); + break; + case 1: + snprintf(buf, bufsz, "Down"); + break; + case 2: + snprintf(buf, bufsz, "Initialize"); + break; + case 3: + snprintf(buf, bufsz, "Armed"); + break; + case 4: + snprintf(buf, bufsz, "Active"); + break; + default: + snprintf(buf, bufsz, "?(%d)", state); + } +} + +void +mad_dump_linkdowndefstate(char *buf, int bufsz, void *val, int valsz) +{ + int state = *(int *)val; + + switch(state) { + case 0: + snprintf(buf, bufsz, "NoChange"); + break; + case 1: + snprintf(buf, bufsz, "Sleep"); + break; + case 2: + snprintf(buf, bufsz, "Polling"); + break; + default: + snprintf(buf, bufsz, "?(%d)", state); + break; + } +} + +void +mad_dump_physportstate(char *buf, int bufsz, void *val, int valsz) +{ + int state = *(int *)val; + + switch (state) { + case 0: + snprintf(buf, bufsz, "NoChange"); + break; + case 1: + snprintf(buf, bufsz, "Sleep"); + break; + case 2: + snprintf(buf, bufsz, "Polling"); + break; + case 3: + snprintf(buf, bufsz, "Disabled"); + break; + case 4: + snprintf(buf, bufsz, "PortConfigurationTraining"); + break; + case 5: + snprintf(buf, bufsz, "LinkUp"); + break; + case 6: + snprintf(buf, bufsz, "LinkErrorRecovery"); + break; + case 7: + snprintf(buf, bufsz, "PhyTest"); + break; + default: + snprintf(buf, bufsz, "?(%d)", state); + } +} + +void +mad_dump_mtu(char *buf, int bufsz, void *val, int valsz) +{ + int mtu = *(int *)val; + + switch (mtu) { + case 1: + snprintf(buf, bufsz, "256"); + break; + case 2: + snprintf(buf, bufsz, "512"); + break; + case 3: + snprintf(buf, bufsz, "1024"); + break; + case 4: + snprintf(buf, bufsz, "2048"); + break; + case 5: + snprintf(buf, bufsz, "4096"); + break; + default: + snprintf(buf, bufsz, "?(%d)", mtu); + buf[0] = 0; + } +} + +void +mad_dump_vlcap(char *buf, int bufsz, void *val, int valsz) +{ + int vlcap = *(int *)val; + + switch (vlcap) { + case 1: + snprintf(buf, bufsz, "VL0"); + break; + case 2: + snprintf(buf, bufsz, "VL0-1"); + break; + case 3: + snprintf(buf, bufsz, "VL0-3"); + break; + case 4: + snprintf(buf, bufsz, "VL0-7"); + break; + case 5: + snprintf(buf, bufsz, "VL0-14"); + break; + default: + snprintf(buf, bufsz, "?(%d)", vlcap); + } +} + +void +mad_dump_opervls(char *buf, int bufsz, void *val, int valsz) +{ + int opervls = *(int *)val; + + switch (opervls) { + case 0: + snprintf(buf, bufsz, "No change"); + break; + case 1: + snprintf(buf, bufsz, "VL0"); + break; + case 2: + snprintf(buf, bufsz, "VL0-1"); + break; + case 3: + snprintf(buf, bufsz, "VL0-3"); + break; + case 4: + snprintf(buf, bufsz, "VL0-7"); + break; + case 5: + snprintf(buf, bufsz, "VL0-14"); + break; + default: + snprintf(buf, bufsz, "?(%d)", opervls); + } +} + +void +mad_dump_portcapmask(char *buf, int bufsz, void *val, int valsz) +{ + unsigned mask = *(unsigned *)val; + char *s = buf; + + s += sprintf(s, "0x%x\n", mask); + if (mask & (1 << 1)) + s += sprintf(s, "\t\t\t\tIsSM\n"); + if (mask & (1 << 2)) + s += sprintf(s, "\t\t\t\tIsNoticeSupported\n"); + if (mask & (1 << 3)) + s += sprintf(s, "\t\t\t\tIsTrapSupported\n"); + if (mask & (1 << 5)) + s += sprintf(s, "\t\t\t\tIsAutomaticMigrationSupported\n"); + if (mask & (1 << 6)) + s += sprintf(s, "\t\t\t\tIsSLMappingSupported\n"); + if (mask & (1 << 7)) + s += sprintf(s, "\t\t\t\tIsMKeyNVRAM\n"); + if (mask & (1 << 8)) + s += sprintf(s, "\t\t\t\tIsPKeyNVRAM\n"); + if (mask & (1 << 9)) + s += sprintf(s, "\t\t\t\tIsLedInfoSupported\n"); + if (mask & (1 << 10)) + s += sprintf(s, "\t\t\t\tIsSMdisabled\n"); + if (mask & (1 << 11)) + s += sprintf(s, "\t\t\t\tIsSystemImageGUIDsupported\n"); + if (mask & (1 << 12)) + s += sprintf(s, "\t\t\t\tIsPkeySwitchExternalPortTrapSupported\n"); + if (mask & (1 << 16)) + s += sprintf(s, "\t\t\t\tIsCommunicatonManagementSupported\n"); + if (mask & (1 << 17)) + s += sprintf(s, "\t\t\t\tIsSNMPTunnelingSupported\n"); + if (mask & (1 << 18)) + s += sprintf(s, "\t\t\t\tIsReinitSupported\n"); + if (mask & (1 << 19)) + s += sprintf(s, "\t\t\t\tIsDeviceManagementSupported\n"); + if (mask & (1 << 20)) + s += sprintf(s, "\t\t\t\tIsVendorClassSupported\n"); + if (mask & (1 << 21)) + s += sprintf(s, "\t\t\t\tIsDRNoticeSupported\n"); + if (mask & (1 << 22)) + s += sprintf(s, "\t\t\t\tIsCapabilityMaskNoticeSupported\n"); + if (mask & (1 << 23)) + s += sprintf(s, "\t\t\t\tIsBootManagementSupported\n"); + if (mask & (1 << 24)) + s += sprintf(s, "\t\t\t\tIsLinkRoundTripLatencySupported\n"); + if (mask & (1 << 25)) + s += sprintf(s, "\t\t\t\tIsClientRegistrationSupported\n"); + if (mask & (1 << 26)) + s += sprintf(s, "\t\t\t\tIsOtherLocalChangesNoticeSupported\n"); + if (mask & (1 << 27)) + s += sprintf(s, "\t\t\t\tIsLinkSpeedWidthPairsTableSupported\n"); + + if (s != buf) + *(--s) = 0; +} + +void +mad_dump_bitfield(char *buf, int bufsz, void *val, int valsz) +{ + snprintf(buf, bufsz, "0x%x", *(uint32_t *)val); +} + +void +mad_dump_array(char *buf, int bufsz, void *val, int valsz) +{ + uint8_t *p = val, *e; + char *s = buf; + + if (bufsz < valsz*2) + valsz = bufsz/2; + + for (p = val, e = p + valsz; p < e; p++, s += 2) + sprintf(s, "%02x", *p); +} + +void +mad_dump_string(char *buf, int bufsz, void *val, int valsz) +{ + if (bufsz < valsz) + valsz = bufsz; + + snprintf(buf, valsz, "'%s'", (char *)val); +} + +void +mad_dump_node_type(char *buf, int bufsz, void *val, int valsz) +{ + int nodetype = *(int*)val; + + switch (nodetype) { + case 1: + snprintf(buf, bufsz, "Channel Adapter"); + break; + case 2: + snprintf(buf, bufsz, "Switch"); + break; + case 3: + snprintf(buf, bufsz, "Router"); + break; + default: + snprintf(buf, bufsz, "?(%d)?", nodetype); + break; + } +} + +#define IB_MAX_NUM_VLS 16 +#define IB_MAX_NUM_VLS_TO_U8 ((IB_MAX_NUM_VLS)/2) + +typedef struct _ib_slvl_table { + uint8_t vl_by_sl_num[IB_MAX_NUM_VLS_TO_U8]; +} ib_slvl_table_t; + +static inline void +ib_slvl_get_i(ib_slvl_table_t *tbl, int i, uint8_t *vl) +{ + *vl = (tbl->vl_by_sl_num[i >> 1] >> ((!(i&1)) << 2)) & 0xf; +} + +#define IB_NUM_VL_ARB_ELEMENTS_IN_BLOCK 32 + +typedef struct _ib_vl_arb_table { + struct { + uint8_t res_vl; + uint8_t weight; + } vl_entry[IB_NUM_VL_ARB_ELEMENTS_IN_BLOCK]; +} ib_vl_arb_table_t; + +static inline void +ib_vl_arb_get_vl(uint8_t res_vl, uint8_t *const vl ) +{ + *vl = res_vl & 0x0F; +} + +void +mad_dump_sltovl(char *buf, int bufsz, void *val, int valsz) +{ + ib_slvl_table_t* p_slvl_tbl = val; + uint8_t vl; + int i, n = 0; + n = snprintf(buf, bufsz, "|"); + for (i = 0; i < 16; i++) { + ib_slvl_get_i(p_slvl_tbl, i, &vl); + n += snprintf(buf + n, bufsz - n, "%2u|", vl); + if (n >= bufsz) + break; + } + snprintf(buf + n, bufsz - n, "\n"); +} + +void +mad_dump_vlarbitration(char *buf, int bufsz, void *val, int num) +{ + ib_vl_arb_table_t* p_vla_tbl = val; + int i, n; + uint8_t vl; + + num /= sizeof(p_vla_tbl->vl_entry[0]); + + n = snprintf(buf, bufsz, "\nVL : |"); + if (n >= bufsz) + return; + for (i = 0; i < num; i++) { + ib_vl_arb_get_vl(p_vla_tbl->vl_entry[i].res_vl, &vl); + n += snprintf(buf + n, bufsz - n, "0x%-2X|", vl); + if (n >= bufsz) + return; + } + + n += snprintf(buf + n, bufsz - n, "\nWEIGHT: |"); + if (n >= bufsz) + return; + for (i = 0; i < num; i++) { + n += snprintf(buf + n, bufsz - n, "0x%-2X|", + p_vla_tbl->vl_entry[i].weight); + if (n >= bufsz) + return; + } + + snprintf(buf + n, bufsz - n, "\n"); +} + +static int +_dump_fields(char *buf, int bufsz, void *data, int start, int end) +{ + char val[64]; + char *s = buf; + int n, field; + + for (field = start; field < end && bufsz > 0; field++) { + mad_decode_field(data, field, val); + if (!mad_dump_field(field, s, bufsz, val)) + return -1; + n = strlen(s); + s += n; + *s++ = '\n'; + *s = 0; + n++; + bufsz -= n; + } + + return (int)(s - buf); +} + +void +mad_dump_nodedesc(char *buf, int bufsz, void *val, int valsz) +{ + strncpy(buf, val, bufsz); + + if (valsz < bufsz) + buf[valsz] = 0; +} + +void +mad_dump_nodeinfo(char *buf, int bufsz, void *val, int valsz) +{ + _dump_fields(buf, bufsz, val, IB_NODE_FIRST_F, IB_NODE_LAST_F); +} + +void +mad_dump_portinfo(char *buf, int bufsz, void *val, int valsz) +{ + _dump_fields(buf, bufsz, val, IB_PORT_FIRST_F, IB_PORT_LAST_F); +} + +void +mad_dump_portstates(char *buf, int bufsz, void *val, int valsz) +{ + _dump_fields(buf, bufsz, val, IB_PORT_STATE_F, IB_PORT_LINK_DOWN_DEF_F); +} + +void +mad_dump_switchinfo(char *buf, int bufsz, void *val, int valsz) +{ + _dump_fields(buf, bufsz, val, IB_SW_FIRST_F, IB_SW_LAST_F); +} + +void +mad_dump_perfcounters(char *buf, int bufsz, void *val, int valsz) +{ + _dump_fields(buf, bufsz, val, IB_PC_FIRST_F, IB_PC_LAST_F); +} + +void +mad_dump_perfcounters_ext(char *buf, int bufsz, void *val, int valsz) +{ + _dump_fields(buf, bufsz, val, IB_PC_EXT_FIRST_F, IB_PC_EXT_LAST_F); +} + +void xdump(FILE *file, char *msg, void *p, int size) +{ +#define HEX(x) ((x) < 10 ? '0' + (x) : 'a' + ((x) -10)) + uint8_t *cp = p; + int i; + + if (msg) + fputs(msg, file); + + for (i = 0; i < size;) { + fputc(HEX(*cp >> 4), file); + fputc(HEX(*cp & 0xf), file); + if (++i >= size) + break; + fputc(HEX(cp[1] >> 4), file); + fputc(HEX(cp[1] & 0xf), file); + if ((++i) % 16) + fputc(' ', file); + else + fputc('\n', file); + cp += 2; + } + if (i % 16) { + fputc('\n', file); + } +} diff --git a/trunk/ulp/libibmad/src/fields.c b/trunk/ulp/libibmad/src/fields.c index bbae49b1..f91c30a5 100644 --- a/trunk/ulp/libibmad/src/fields.c +++ b/trunk/ulp/libibmad/src/fields.c @@ -1,60 +1,57 @@ -/* - * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#else -#include -#include -#endif - -#include - -/* - * BITSOFFS and BE_OFFS are required due the fact that the bit offsets are inconsistently - * encoded in the IB spec - IB headers are encoded such that the bit offsets - * are in big endian convention (BE_OFFS), while the SMI/GSI queries data fields bit - * offsets are specified using real bit offset (?!) - * The following macros normalize everything to big endian offsets. - */ -#define BITSOFFS(o, w) (((o) & ~31) | ((32 - ((o) & 31) - (w)))), (w) -#define BE_OFFS(o, w) (o), (w) -#define BE_TO_BITSOFFS(o, w) (((o) & ~31) | ((32 - ((o) & 31) - (w)))) - +/* + * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include + +/* + * BITSOFFS and BE_OFFS are required due the fact that the bit offsets are inconsistently + * encoded in the IB spec - IB headers are encoded such that the bit offsets + * are in big endian convention (BE_OFFS), while the SMI/GSI queries data fields bit + * offsets are specified using real bit offset (?!) + * The following macros normalize everything to big endian offsets. + */ +#define BITSOFFS(o, w) (((o) & ~31) | ((32 - ((o) & 31) - (w)))), (w) +#define BE_OFFS(o, w) (o), (w) +#define BE_TO_BITSOFFS(o, w) (((o) & ~31) | ((32 - ((o) & 31) - (w)))) + ib_field_t ib_mad_f [] = { {0, 0}, /* IB_NO_FIELD - reserved as invalid */ @@ -378,103 +375,236 @@ ib_field_t ib_mad_f [] = { {0, 64, "GUID0", mad_dump_hex}, {0, 0} /* IB_FIELD_LAST_ */ -}; - -void -_set_field64(void *buf, int base_offs, ib_field_t *f, uint64_t val) -{ - uint64_t nval; - - nval = cl_hton64(val); - memcpy((char *)buf + base_offs + f->bitoffs / 8, &nval, sizeof(uint64_t)); -} - -uint64_t -_get_field64(void *buf, int base_offs, ib_field_t *f) -{ - uint64_t val; - memcpy(&val, ((char *)buf + base_offs + f->bitoffs / 8), sizeof(uint64_t)); - return cl_ntoh64(val); -} - -void -_set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val) -{ - int prebits = (8 - (f->bitoffs & 7)) & 7; - int postbits = (f->bitoffs + f->bitlen) & 7; - int bytelen = f->bitlen / 8; - unsigned idx = base_offs + f->bitoffs / 8; - char *p = (char *)buf; - - if (!bytelen && (f->bitoffs & 7) + f->bitlen < 8) { - p[3^idx] &= ~((((1 << f->bitlen) - 1)) << (f->bitoffs & 7)); - p[3^idx] |= (val & ((1 << f->bitlen) - 1)) << (f->bitoffs & 7); - return; - } - - if (prebits) { /* val lsb in byte msb */ - p[3^idx] &= (1 << (8 - prebits)) - 1; - p[3^idx++] |= (val & ((1 << prebits) - 1)) << (8 - prebits); - val >>= prebits; - } - - /* BIG endian byte order */ - for (; bytelen--; val >>= 8) - p[3^idx++] = val & 0xff; - - if (postbits) { /* val msb in byte lsb */ - p[3^idx] &= ~((1 << postbits) - 1); - p[3^idx] |= val; - } -} - -uint32_t -_get_field(void *buf, int base_offs, ib_field_t *f) -{ - int prebits = (8 - (f->bitoffs & 7)) & 7; - int postbits = (f->bitoffs + f->bitlen) & 7; - int bytelen = f->bitlen / 8; - unsigned idx = base_offs + f->bitoffs / 8; - uint8_t *p = (uint8_t *)buf; - uint32_t val = 0, v = 0, i; - - if (!bytelen && (f->bitoffs & 7) + f->bitlen < 8) - return (p[3^idx] >> (f->bitoffs & 7)) & ((1 << f->bitlen) - 1); - - if (prebits) /* val lsb from byte msb */ - v = p[3^idx++] >> (8 - prebits); - - if (postbits) { /* val msb from byte lsb */ - i = base_offs + (f->bitoffs + f->bitlen) / 8; - val = (p[3^i] & ((1 << postbits) - 1)); - } - - /* BIG endian byte order */ - for (idx += bytelen - 1; bytelen--; idx--) - val = (val << 8) | p[3^idx]; - - return (val << prebits) | v; -} - -/* field must be byte aligned */ -void -_set_array(void *buf, int base_offs, ib_field_t *f, void *val) -{ - int bitoffs = f->bitoffs; - - if (f->bitlen < 32) - bitoffs = BE_TO_BITSOFFS(bitoffs, f->bitlen); - - memcpy((uint8_t *)buf + base_offs + bitoffs / 8, val, f->bitlen / 8); -} - -void -_get_array(void *buf, int base_offs, ib_field_t *f, void *val) -{ - int bitoffs = f->bitoffs; - - if (f->bitlen < 32) - bitoffs = BE_TO_BITSOFFS(bitoffs, f->bitlen); - - memcpy(val, (uint8_t *)buf + base_offs + bitoffs / 8, f->bitlen / 8); -} +}; + +static void _set_field64(void *buf, int base_offs, const ib_field_t *f, uint64_t val) +{ + uint64_t nval; + + nval = htonll(val); + memcpy((char *)buf + base_offs + f->bitoffs / 8, &nval, sizeof(uint64_t)); +} + +static uint64_t _get_field64(void *buf, int base_offs, const ib_field_t *f) +{ + uint64_t val; + memcpy(&val, ((char *)buf + base_offs + f->bitoffs / 8), sizeof(uint64_t)); + return ntohll(val); +} + +static void _set_field(void *buf, int base_offs, const ib_field_t *f, uint32_t val) +{ + int prebits = (8 - (f->bitoffs & 7)) & 7; + int postbits = (f->bitoffs + f->bitlen) & 7; + int bytelen = f->bitlen / 8; + unsigned idx = base_offs + f->bitoffs / 8; + char *p = (char *)buf; + + if (!bytelen && (f->bitoffs & 7) + f->bitlen < 8) { + p[3^idx] &= ~((((1 << f->bitlen) - 1)) << (f->bitoffs & 7)); + p[3^idx] |= (val & ((1 << f->bitlen) - 1)) << (f->bitoffs & 7); + return; + } + + if (prebits) { /* val lsb in byte msb */ + p[3^idx] &= (1 << (8 - prebits)) - 1; + p[3^idx++] |= (val & ((1 << prebits) - 1)) << (8 - prebits); + val >>= prebits; + } + + /* BIG endian byte order */ + for (; bytelen--; val >>= 8) + p[3^idx++] = val & 0xff; + + if (postbits) { /* val msb in byte lsb */ + p[3^idx] &= ~((1 << postbits) - 1); + p[3^idx] |= val; + } +} + +static uint32_t _get_field(void *buf, int base_offs, const ib_field_t *f) +{ + int prebits = (8 - (f->bitoffs & 7)) & 7; + int postbits = (f->bitoffs + f->bitlen) & 7; + int bytelen = f->bitlen / 8; + unsigned idx = base_offs + f->bitoffs / 8; + uint8_t *p = (uint8_t *)buf; + uint32_t val = 0, v = 0, i; + + if (!bytelen && (f->bitoffs & 7) + f->bitlen < 8) + return (p[3^idx] >> (f->bitoffs & 7)) & ((1 << f->bitlen) - 1); + + if (prebits) /* val lsb from byte msb */ + v = p[3^idx++] >> (8 - prebits); + + if (postbits) { /* val msb from byte lsb */ + i = base_offs + (f->bitoffs + f->bitlen) / 8; + val = (p[3^i] & ((1 << postbits) - 1)); + } + + /* BIG endian byte order */ + for (idx += bytelen - 1; bytelen--; idx--) + val = (val << 8) | p[3^idx]; + + return (val << prebits) | v; +} + +/* field must be byte aligned */ +static void _set_array(void *buf, int base_offs, const ib_field_t *f, void *val) +{ + int bitoffs = f->bitoffs; + + if (f->bitlen < 32) + bitoffs = BE_TO_BITSOFFS(bitoffs, f->bitlen); + + memcpy((uint8_t *)buf + base_offs + bitoffs / 8, val, f->bitlen / 8); +} + +static void _get_array(void *buf, int base_offs, const ib_field_t *f, void *val) +{ + int bitoffs = f->bitoffs; + + if (f->bitlen < 32) + bitoffs = BE_TO_BITSOFFS(bitoffs, f->bitlen); + + memcpy(val, (uint8_t *)buf + base_offs + bitoffs / 8, f->bitlen / 8); +} + +uint32_t mad_get_field(void *buf, int base_offs, int field) +{ + return _get_field(buf, base_offs, ib_mad_f + field); +} + +void mad_set_field(void *buf, int base_offs, int field, uint32_t val) +{ + _set_field(buf, base_offs, ib_mad_f + field, val); +} + +uint64_t mad_get_field64(void *buf, int base_offs, int field) +{ + return _get_field64(buf, base_offs, ib_mad_f + field); +} + +void mad_set_field64(void *buf, int base_offs, int field, uint64_t val) +{ + _set_field64(buf, base_offs, ib_mad_f + field, val); +} + +void mad_set_array(void *buf, int base_offs, int field, void *val) +{ + _set_array(buf, base_offs, ib_mad_f + field, val); +} + +void mad_get_array(void *buf, int base_offs, int field, void *val) +{ + _get_array(buf, base_offs, ib_mad_f + field, val); +} + +void mad_decode_field(uint8_t *buf, int field, void *val) +{ + const ib_field_t *f = ib_mad_f + field; + + if (!field) { + *(int *)val = *(int *)buf; + return; + } + if (f->bitlen <= 32) { + *(uint32_t *)val = _get_field(buf, 0, f); + return; + } + if (f->bitlen == 64) { + *(uint64_t *)val = _get_field64(buf, 0, f); + return; + } + _get_array(buf, 0, f, val); +} + +void mad_encode_field(uint8_t *buf, int field, void *val) +{ + const ib_field_t *f = ib_mad_f + field; + + if (!field) { + *(int *)buf = *(int *)val; + return; + } + if (f->bitlen <= 32) { + _set_field(buf, 0, f, *(uint32_t *)val); + return; + } + if (f->bitlen == 64) { + _set_field64(buf, 0, f, *(uint64_t *)val); + return; + } + _set_array(buf, 0, f, val); +} + +/************************/ + +static char *_mad_dump_val(const ib_field_t *f, char *buf, int bufsz, void *val) +{ + f->def_dump_fn(buf, bufsz, val, ALIGN(f->bitlen, 8) / 8); + buf[bufsz - 1] = 0; + + return buf; +} + +static char *_mad_dump_field(const ib_field_t *f, const char *name, char *buf, int bufsz, void *val) +{ + char dots[128]; + int l, n; + + if (bufsz <= 32) + return 0; /* buf too small */ + + if (!name) + name = f->name; + + l = strlen(name); + if (l < 32) { + memset(dots, '.', 32 - l); + dots[32 - l] = 0; + } + + n = snprintf(buf, bufsz, "%s:%s", name, dots); + _mad_dump_val(f, buf + n, bufsz - n, val); + buf[bufsz - 1] = 0; + + return buf; +} + +static int _mad_dump(ib_mad_dump_fn *fn, const char *name, void *val, int valsz) +{ + ib_field_t f; + char buf[512]; + + f.def_dump_fn = fn; + f.bitlen = valsz * 8; + + return printf("%s\n", _mad_dump_field(&f, name, buf, sizeof buf, val)); +} + +static int _mad_print_field(const ib_field_t *f, const char *name, void *val, int valsz) +{ + return _mad_dump(f->def_dump_fn, name ? name : f->name, val, valsz ? valsz : ALIGN(f->bitlen, 8) / 8); +} + +int mad_print_field(int field, const char *name, void *val) +{ + if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_) + return -1; + return _mad_print_field(ib_mad_f + field, name, val, 0); +} + +char *mad_dump_field(int field, char *buf, int bufsz, void *val) +{ + if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_) + return 0; + return _mad_dump_field(ib_mad_f + field, 0, buf, bufsz, val); +} + +char *mad_dump_val(int field, char *buf, int bufsz, void *val) +{ + if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_) + return 0; + return _mad_dump_val(ib_mad_f + field, buf, bufsz, val); +} diff --git a/trunk/ulp/libibmad/src/gs.c b/trunk/ulp/libibmad/src/gs.c index 0a6bd8bf..3b6baef8 100644 --- a/trunk/ulp/libibmad/src/gs.c +++ b/trunk/ulp/libibmad/src/gs.c @@ -1,243 +1,234 @@ -/* - * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#else -#include -#include -#include -#include -#endif - -#include -#include "mad.h" - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -static uint8_t * -pma_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, unsigned id, const void *srcport) -{ - ib_rpc_t rpc = {0}; - int lid = dest->lid; - - DEBUG("lid %d port %d", lid, port); - - if (lid == -1) { - IBWARN("only lid routed is supported"); - return 0; - } - - rpc.mgtclass = IB_PERFORMANCE_CLASS; - rpc.method = IB_MAD_METHOD_GET; - rpc.attr.id = id; - - /* Same for attribute IDs */ - mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port); - rpc.attr.mod = 0; - rpc.timeout = timeout; - rpc.datasz = IB_PC_DATA_SZ; - rpc.dataoffs = IB_PC_DATA_OFFS; - - dest->qp = 1; - if (!dest->qkey) - dest->qkey = IB_DEFAULT_QP1_QKEY; - - if (srcport) { - return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf); - } else { - return madrpc(&rpc, dest, rcvbuf, rcvbuf); - } -} - -uint8_t * -pma_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout, unsigned id) -{ - return pma_query_via(rcvbuf, dest, port, timeout, id, NULL); -} - -uint8_t * -perf_classportinfo_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport) -{ - return pma_query_via(rcvbuf, dest, port, timeout, CLASS_PORT_INFO, - srcport); -} - -MAD_EXPORT uint8_t * -perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) -{ - return pma_query(rcvbuf, dest, port, timeout, CLASS_PORT_INFO); -} - -uint8_t * -port_performance_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport) -{ - return pma_query_via(rcvbuf, dest, port, timeout, - IB_GSI_PORT_COUNTERS, srcport); -} - -MAD_EXPORT uint8_t * -port_performance_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) -{ - return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS); -} - -static uint8_t * -performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, - unsigned timeout, unsigned id, const void *srcport) -{ - ib_rpc_t rpc = {0}; - int lid = dest->lid; - - DEBUG("lid %d port %d mask 0x%x", lid, port, mask); - - if (lid == -1) { - IBWARN("only lid routed is supported"); - return 0; - } - - if (!mask) - mask = ~0; - - rpc.mgtclass = IB_PERFORMANCE_CLASS; - rpc.method = IB_MAD_METHOD_SET; - rpc.attr.id = id; - - memset(rcvbuf, 0, IB_MAD_SIZE); - - /* Same for attribute IDs */ - mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port); - mad_set_field(rcvbuf, 0, IB_PC_COUNTER_SELECT_F, mask); - rpc.attr.mod = 0; - rpc.timeout = timeout; - rpc.datasz = IB_PC_DATA_SZ; - rpc.dataoffs = IB_PC_DATA_OFFS; - dest->qp = 1; - if (!dest->qkey) - dest->qkey = IB_DEFAULT_QP1_QKEY; - - if (srcport) { - return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf); - } else { - return madrpc(&rpc, dest, rcvbuf, rcvbuf); - } -} - -static uint8_t * -performance_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, - unsigned timeout, unsigned id) -{ - return performance_reset_via(rcvbuf, dest, port, mask, timeout, - id, NULL); -} - -uint8_t * -port_performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned mask, unsigned timeout, const void *srcport) -{ - return performance_reset_via(rcvbuf, dest, port, mask, timeout, - IB_GSI_PORT_COUNTERS, srcport); -} - -MAD_EXPORT uint8_t * -port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, - unsigned timeout) -{ - return performance_reset(rcvbuf, dest, port, mask, timeout, IB_GSI_PORT_COUNTERS); -} - -uint8_t * -port_performance_ext_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport) -{ - return pma_query_via(rcvbuf, dest, port, timeout, - IB_GSI_PORT_COUNTERS_EXT, srcport); -} - -MAD_EXPORT uint8_t * -port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) -{ - return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS_EXT); -} - -uint8_t * -port_performance_ext_reset_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned mask, unsigned timeout, - const void *srcport) -{ - return performance_reset_via(rcvbuf, dest, port, mask, timeout, - IB_GSI_PORT_COUNTERS_EXT, srcport); -} - -MAD_EXPORT uint8_t * -port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, - unsigned timeout) -{ - return performance_reset(rcvbuf, dest, port, mask, timeout, IB_GSI_PORT_COUNTERS_EXT); -} - -uint8_t * -port_samples_control_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport) -{ - return pma_query_via(rcvbuf, dest, port, timeout, - IB_GSI_PORT_SAMPLES_CONTROL, srcport); -} - -MAD_EXPORT uint8_t * -port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) -{ - return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_CONTROL); -} - -uint8_t * -port_samples_result_query_via(void *rcvbuf, ib_portid_t *dest, int port, - unsigned timeout, const void *srcport) -{ - return pma_query_via(rcvbuf, dest, port, timeout, - IB_GSI_PORT_SAMPLES_RESULT, srcport); -} - -MAD_EXPORT uint8_t * -port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) -{ - return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_RESULT); -} +/* + * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include "mad.h" + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +static uint8_t * +pma_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, unsigned id, const void *srcport) +{ + ib_rpc_t rpc = {0}; + int lid = dest->lid; + + DEBUG("lid %d port %d", lid, port); + + if (lid == -1) { + IBWARN("only lid routed is supported"); + return 0; + } + + rpc.mgtclass = IB_PERFORMANCE_CLASS; + rpc.method = IB_MAD_METHOD_GET; + rpc.attr.id = id; + + /* Same for attribute IDs */ + mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port); + rpc.attr.mod = 0; + rpc.timeout = timeout; + rpc.datasz = IB_PC_DATA_SZ; + rpc.dataoffs = IB_PC_DATA_OFFS; + + dest->qp = 1; + if (!dest->qkey) + dest->qkey = IB_DEFAULT_QP1_QKEY; + + if (srcport) { + return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf); + } else { + return madrpc(&rpc, dest, rcvbuf, rcvbuf); + } +} + +uint8_t * +pma_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout, unsigned id) +{ + return pma_query_via(rcvbuf, dest, port, timeout, id, NULL); +} + +uint8_t * +perf_classportinfo_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport) +{ + return pma_query_via(rcvbuf, dest, port, timeout, CLASS_PORT_INFO, + srcport); +} + +uint8_t * +perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) +{ + return pma_query(rcvbuf, dest, port, timeout, CLASS_PORT_INFO); +} + +uint8_t * +port_performance_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport) +{ + return pma_query_via(rcvbuf, dest, port, timeout, + IB_GSI_PORT_COUNTERS, srcport); +} + +uint8_t * +port_performance_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) +{ + return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS); +} + +static uint8_t * +performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, + unsigned timeout, unsigned id, const void *srcport) +{ + ib_rpc_t rpc = {0}; + int lid = dest->lid; + + DEBUG("lid %d port %d mask 0x%x", lid, port, mask); + + if (lid == -1) { + IBWARN("only lid routed is supported"); + return 0; + } + + if (!mask) + mask = ~0; + + rpc.mgtclass = IB_PERFORMANCE_CLASS; + rpc.method = IB_MAD_METHOD_SET; + rpc.attr.id = id; + + memset(rcvbuf, 0, IB_MAD_SIZE); + + /* Same for attribute IDs */ + mad_set_field(rcvbuf, 0, IB_PC_PORT_SELECT_F, port); + mad_set_field(rcvbuf, 0, IB_PC_COUNTER_SELECT_F, mask); + rpc.attr.mod = 0; + rpc.timeout = timeout; + rpc.datasz = IB_PC_DATA_SZ; + rpc.dataoffs = IB_PC_DATA_OFFS; + dest->qp = 1; + if (!dest->qkey) + dest->qkey = IB_DEFAULT_QP1_QKEY; + + if (srcport) { + return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf); + } else { + return madrpc(&rpc, dest, rcvbuf, rcvbuf); + } +} + +static uint8_t * +performance_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, + unsigned timeout, unsigned id) +{ + return performance_reset_via(rcvbuf, dest, port, mask, timeout, + id, NULL); +} + +uint8_t * +port_performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned mask, unsigned timeout, const void *srcport) +{ + return performance_reset_via(rcvbuf, dest, port, mask, timeout, + IB_GSI_PORT_COUNTERS, srcport); +} + +uint8_t * +port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, + unsigned timeout) +{ + return performance_reset(rcvbuf, dest, port, mask, timeout, IB_GSI_PORT_COUNTERS); +} + +uint8_t * +port_performance_ext_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport) +{ + return pma_query_via(rcvbuf, dest, port, timeout, + IB_GSI_PORT_COUNTERS_EXT, srcport); +} + +uint8_t * +port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) +{ + return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS_EXT); +} + +uint8_t * +port_performance_ext_reset_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned mask, unsigned timeout, + const void *srcport) +{ + return performance_reset_via(rcvbuf, dest, port, mask, timeout, + IB_GSI_PORT_COUNTERS_EXT, srcport); +} + +uint8_t * +port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask, + unsigned timeout) +{ + return performance_reset(rcvbuf, dest, port, mask, timeout, IB_GSI_PORT_COUNTERS_EXT); +} + +uint8_t * +port_samples_control_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport) +{ + return pma_query_via(rcvbuf, dest, port, timeout, + IB_GSI_PORT_SAMPLES_CONTROL, srcport); +} + +uint8_t * +port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) +{ + return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_CONTROL); +} + +uint8_t * +port_samples_result_query_via(void *rcvbuf, ib_portid_t *dest, int port, + unsigned timeout, const void *srcport) +{ + return pma_query_via(rcvbuf, dest, port, timeout, + IB_GSI_PORT_SAMPLES_RESULT, srcport); +} + +uint8_t * +port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout) +{ + return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_RESULT); +} diff --git a/trunk/ulp/libibmad/src/ibmad_export.def b/trunk/ulp/libibmad/src/ibmad_export.def index 8258d304..4a7e62ea 100644 --- a/trunk/ulp/libibmad/src/ibmad_export.def +++ b/trunk/ulp/libibmad/src/ibmad_export.def @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Intel Corporation. All rights reserved. + * Copyright (c) 2008-2009 Intel Corporation. All rights reserved. * * This software is available to you under the OpenIB.org BSD license * below: diff --git a/trunk/ulp/libibmad/src/ibmad_exports.src b/trunk/ulp/libibmad/src/ibmad_exports.src index 9fcb7594..cdc0aa08 100644 --- a/trunk/ulp/libibmad/src/ibmad_exports.src +++ b/trunk/ulp/libibmad/src/ibmad_exports.src @@ -37,7 +37,6 @@ EXPORTS ib_vendor_call; ib_path_query; ib_resolve_smlid; - ib_resolve_guid; ib_resolve_portid_str; ib_resolve_self; perf_classportinfo_query; diff --git a/trunk/ulp/libibmad/src/ibmad_main.cpp b/trunk/ulp/libibmad/src/ibmad_main.cpp index f57d13cf..7a48a480 100644 --- a/trunk/ulp/libibmad/src/ibmad_main.cpp +++ b/trunk/ulp/libibmad/src/ibmad_main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Intel Corporation. All rights reserved. + * Copyright (c) 2008-2009 Intel Corporation. All rights reserved. * * This software is available to you under the OpenIB.org BSD license * below: diff --git a/trunk/ulp/libibmad/src/mad.c b/trunk/ulp/libibmad/src/mad.c index fba21093..8ef61202 100644 --- a/trunk/ulp/libibmad/src/mad.c +++ b/trunk/ulp/libibmad/src/mad.c @@ -1,255 +1,168 @@ -/* - * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#include -#define getpid GetCurrentProcessId -#else -#include -#include -#include -#include -#endif - -#include -#include - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -MAD_EXPORT uint32_t -mad_get_field(void *buf, int base_offs, int field) -{ - return _get_field(buf, base_offs, ib_mad_f + field); -} - -MAD_EXPORT void -mad_set_field(void *buf, int base_offs, int field, uint32_t val) -{ - _set_field(buf, base_offs, ib_mad_f + field, val); -} - -/* field must be byte aligned */ -MAD_EXPORT uint64_t -mad_get_field64(void *buf, int base_offs, int field) -{ - return _get_field64(buf, base_offs, ib_mad_f + field); -} - -MAD_EXPORT void -mad_set_field64(void *buf, int base_offs, int field, uint64_t val) -{ - _set_field64(buf, base_offs, ib_mad_f + field, val); -} - -MAD_EXPORT void -mad_set_array(void *buf, int base_offs, int field, void *val) -{ - _set_array(buf, base_offs, ib_mad_f + field, val); -} - -MAD_EXPORT void -mad_get_array(void *buf, int base_offs, int field, void *val) -{ - _get_array(buf, base_offs, ib_mad_f + field, val); -} - -MAD_EXPORT void -mad_decode_field(uint8_t *buf, int field, void *val) -{ - ib_field_t *f = ib_mad_f + field; - - if (!field) { - *(int *)val = *(int *)buf; - return; - } - if (f->bitlen <= 32) { - *(uint32_t *)val = _get_field(buf, 0, f); - return; - } - if (f->bitlen == 64) { - *(uint64_t *)val = _get_field64(buf, 0, f); - return; - } - _get_array(buf, 0, f, val); -} - -MAD_EXPORT void -mad_encode_field(uint8_t *buf, int field, void *val) -{ - ib_field_t *f = ib_mad_f + field; - - if (!field) { - *(int *)buf = *(int *)val; - return; - } - if (f->bitlen <= 32) { - _set_field(buf, 0, f, *(uint32_t *)val); - return; - } - if (f->bitlen == 64) { - _set_field64(buf, 0, f, *(uint64_t *)val); - return; - } - _set_array(buf, 0, f, val); -} - -MAD_EXPORT uint64_t -mad_trid(void) -{ - static uint64_t base; - static uint64_t trid; - uint64_t next; - - if (!base) { - srand((int)time(0)*getpid()); - base = rand(); - trid = rand(); - } - next = ++trid | (base << 32); - return next; -} - -MAD_EXPORT void * -mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data) -{ - int is_resp = rpc->method & IB_MAD_RESPONSE; - - /* first word */ - mad_set_field(buf, 0, IB_MAD_METHOD_F, rpc->method); - mad_set_field(buf, 0, IB_MAD_RESPONSE_F, is_resp ? 1 : 0); - mad_set_field(buf, 0, IB_MAD_CLASSVER_F, rpc->mgtclass == IB_SA_CLASS ? 2 : 1); - mad_set_field(buf, 0, IB_MAD_MGMTCLASS_F, rpc->mgtclass); - mad_set_field(buf, 0, IB_MAD_BASEVER_F, 1); - - /* second word */ - if (rpc->mgtclass == IB_SMI_DIRECT_CLASS) { - if (!drpath) { - IBWARN("encoding dr mad without drpath (null)"); - return 0; - } - mad_set_field(buf, 0, IB_DRSMP_HOPCNT_F, drpath->cnt); - mad_set_field(buf, 0, IB_DRSMP_HOPPTR_F, is_resp ? drpath->cnt + 1 : 0x0); - mad_set_field(buf, 0, IB_DRSMP_STATUS_F, rpc->rstatus); - mad_set_field(buf, 0, IB_DRSMP_DIRECTION_F, is_resp ? 1 : 0); /* out */ - } else - mad_set_field(buf, 0, IB_MAD_STATUS_F, rpc->rstatus); - - /* words 3,4,5,6 */ - if (!rpc->trid) - rpc->trid = mad_trid(); - - mad_set_field64(buf, 0, IB_MAD_TRID_F, rpc->trid); - mad_set_field(buf, 0, IB_MAD_ATTRID_F, rpc->attr.id); - mad_set_field(buf, 0, IB_MAD_ATTRMOD_F, rpc->attr.mod); - - /* words 7,8 */ - mad_set_field(buf, 0, IB_MAD_MKEY_F, (uint32_t)(rpc->mkey >> 32)); - mad_set_field(buf, 4, IB_MAD_MKEY_F, (uint32_t)(rpc->mkey & 0xffffffff)); - - if (rpc->mgtclass == IB_SMI_DIRECT_CLASS) { - /* word 9 */ - mad_set_field(buf, 0, IB_DRSMP_DRDLID_F, drpath->drdlid ? drpath->drdlid : 0xffff); - mad_set_field(buf, 0, IB_DRSMP_DRSLID_F, drpath->drslid ? drpath->drslid : 0xffff); - - /* bytes 128 - 256 - by default should be zero due to memset*/ - if (is_resp) - mad_set_array(buf, 0, IB_DRSMP_RPATH_F, drpath->p); - else - mad_set_array(buf, 0, IB_DRSMP_PATH_F, drpath->p); - } - - if (rpc->mgtclass == IB_SA_CLASS) - mad_set_field64(buf, 0, IB_SA_COMPMASK_F, rpc->mask); - - if (data) - memcpy((char *)buf + rpc->dataoffs, data, rpc->datasz); - - /* vendor mads range 2 */ - if (mad_is_vendor_range2(rpc->mgtclass)) - mad_set_field(buf, 0, IB_VEND2_OUI_F, rpc->oui); - - return (uint8_t *)buf + IB_MAD_SIZE; -} - -MAD_EXPORT int -mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, - ib_rmpp_hdr_t *rmpp, void *data) -{ - uint8_t *p, *mad; - int lid_routed = rpc->mgtclass != IB_SMI_DIRECT_CLASS; - int is_smi = (rpc->mgtclass == IB_SMI_CLASS || - rpc->mgtclass == IB_SMI_DIRECT_CLASS); - struct ib_mad_addr addr; - - if (!is_smi) - umad_set_addr(umad, dport->lid, dport->qp, dport->sl, dport->qkey); - else if (lid_routed) - umad_set_addr(umad, dport->lid, dport->qp, 0, 0); - else - if ((dport->drpath.drslid != 0xffff) && (dport->lid > 0)) - umad_set_addr(umad, dport->lid, 0, 0, 0); - else - umad_set_addr(umad, 0xffff, 0, 0, 0); - - if (dport->grh_present && !is_smi) { - addr.grh_present = 1; - memcpy(addr.gid, dport->gid, 16); - addr.hop_limit = 0xff; - addr.traffic_class = 0; - addr.flow_label = 0; - umad_set_grh(umad, &addr); - } else - umad_set_grh(umad, 0); - umad_set_pkey(umad, is_smi ? 0 : dport->pkey_idx); - - mad = umad_get_mad(umad); - p = mad_encode(mad, rpc, lid_routed ? 0 : &dport->drpath, data); - - if (!is_smi && rmpp) { - mad_set_field(mad, 0, IB_SA_RMPP_VERS_F, 1); - mad_set_field(mad, 0, IB_SA_RMPP_TYPE_F, rmpp->type); - mad_set_field(mad, 0, IB_SA_RMPP_RESP_F, 0x3f); - mad_set_field(mad, 0, IB_SA_RMPP_FLAGS_F, rmpp->flags); - mad_set_field(mad, 0, IB_SA_RMPP_STATUS_F, rmpp->status); - mad_set_field(mad, 0, IB_SA_RMPP_D1_F, rmpp->d1.u); - mad_set_field(mad, 0, IB_SA_RMPP_D2_F, rmpp->d2.u); - } - - return ((int)(p - mad)); -} +/* + * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include + +#include +#include + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +uint64_t +mad_trid(void) +{ + static uint64_t base; + static uint64_t trid; + uint64_t next; + + if (!base) { + srandom((int)time(0)*getpid()); + base = random(); + trid = random(); + } + next = ++trid | (base << 32); + return next; +} + +void * +mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data) +{ + int is_resp = rpc->method & IB_MAD_RESPONSE; + + /* first word */ + mad_set_field(buf, 0, IB_MAD_METHOD_F, rpc->method); + mad_set_field(buf, 0, IB_MAD_RESPONSE_F, is_resp ? 1 : 0); + mad_set_field(buf, 0, IB_MAD_CLASSVER_F, rpc->mgtclass == IB_SA_CLASS ? 2 : 1); + mad_set_field(buf, 0, IB_MAD_MGMTCLASS_F, rpc->mgtclass); + mad_set_field(buf, 0, IB_MAD_BASEVER_F, 1); + + /* second word */ + if (rpc->mgtclass == IB_SMI_DIRECT_CLASS) { + if (!drpath) { + IBWARN("encoding dr mad without drpath (null)"); + return 0; + } + mad_set_field(buf, 0, IB_DRSMP_HOPCNT_F, drpath->cnt); + mad_set_field(buf, 0, IB_DRSMP_HOPPTR_F, is_resp ? drpath->cnt + 1 : 0x0); + mad_set_field(buf, 0, IB_DRSMP_STATUS_F, rpc->rstatus); + mad_set_field(buf, 0, IB_DRSMP_DIRECTION_F, is_resp ? 1 : 0); /* out */ + } else + mad_set_field(buf, 0, IB_MAD_STATUS_F, rpc->rstatus); + + /* words 3,4,5,6 */ + if (!rpc->trid) + rpc->trid = mad_trid(); + + mad_set_field64(buf, 0, IB_MAD_TRID_F, rpc->trid); + mad_set_field(buf, 0, IB_MAD_ATTRID_F, rpc->attr.id); + mad_set_field(buf, 0, IB_MAD_ATTRMOD_F, rpc->attr.mod); + + /* words 7,8 */ + mad_set_field(buf, 0, IB_MAD_MKEY_F, (uint32_t)(rpc->mkey >> 32)); + mad_set_field(buf, 4, IB_MAD_MKEY_F, (uint32_t)(rpc->mkey & 0xffffffff)); + + if (rpc->mgtclass == IB_SMI_DIRECT_CLASS) { + /* word 9 */ + mad_set_field(buf, 0, IB_DRSMP_DRDLID_F, drpath->drdlid ? drpath->drdlid : 0xffff); + mad_set_field(buf, 0, IB_DRSMP_DRSLID_F, drpath->drslid ? drpath->drslid : 0xffff); + + /* bytes 128 - 256 - by default should be zero due to memset*/ + if (is_resp) + mad_set_array(buf, 0, IB_DRSMP_RPATH_F, drpath->p); + else + mad_set_array(buf, 0, IB_DRSMP_PATH_F, drpath->p); + } + + if (rpc->mgtclass == IB_SA_CLASS) + mad_set_field64(buf, 0, IB_SA_COMPMASK_F, rpc->mask); + + if (data) + memcpy((char *)buf + rpc->dataoffs, data, rpc->datasz); + + /* vendor mads range 2 */ + if (mad_is_vendor_range2(rpc->mgtclass)) + mad_set_field(buf, 0, IB_VEND2_OUI_F, rpc->oui); + + return (uint8_t *)buf + IB_MAD_SIZE; +} + +int +mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, + ib_rmpp_hdr_t *rmpp, void *data) +{ + uint8_t *p, *mad; + int lid_routed = rpc->mgtclass != IB_SMI_DIRECT_CLASS; + int is_smi = (rpc->mgtclass == IB_SMI_CLASS || + rpc->mgtclass == IB_SMI_DIRECT_CLASS); + struct ib_mad_addr addr; + + if (!is_smi) + umad_set_addr(umad, dport->lid, dport->qp, dport->sl, dport->qkey); + else if (lid_routed) + umad_set_addr(umad, dport->lid, dport->qp, 0, 0); + else if ((dport->drpath.drslid != 0xffff) && (dport->lid > 0)) + umad_set_addr(umad, dport->lid, 0, 0, 0); + else + umad_set_addr(umad, 0xffff, 0, 0, 0); + + if (dport->grh_present && !is_smi) { + addr.grh_present = 1; + memcpy(addr.gid, dport->gid, 16); + addr.hop_limit = 0xff; + addr.traffic_class = 0; + addr.flow_label = 0; + umad_set_grh(umad, &addr); + } else + umad_set_grh(umad, 0); + umad_set_pkey(umad, is_smi ? 0 : dport->pkey_idx); + + mad = umad_get_mad(umad); + p = mad_encode(mad, rpc, lid_routed ? 0 : &dport->drpath, data); + + if (!is_smi && rmpp) { + mad_set_field(mad, 0, IB_SA_RMPP_VERS_F, 1); + mad_set_field(mad, 0, IB_SA_RMPP_TYPE_F, rmpp->type); + mad_set_field(mad, 0, IB_SA_RMPP_RESP_F, 0x3f); + mad_set_field(mad, 0, IB_SA_RMPP_FLAGS_F, rmpp->flags); + mad_set_field(mad, 0, IB_SA_RMPP_STATUS_F, rmpp->status); + mad_set_field(mad, 0, IB_SA_RMPP_D1_F, rmpp->d1.u); + mad_set_field(mad, 0, IB_SA_RMPP_D2_F, rmpp->d2.u); + } + + return ((int)(p - mad)); +} diff --git a/trunk/ulp/libibmad/src/portid.c b/trunk/ulp/libibmad/src/portid.c index 8751cfe4..83aabafb 100644 --- a/trunk/ulp/libibmad/src/portid.c +++ b/trunk/ulp/libibmad/src/portid.c @@ -1,175 +1,120 @@ -/* - * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved. - * Copyright (c) 2008 Intel Corporation. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#include -#define snprintf _snprintf -#else -#include -#include -#include -#include -#include -#include -#endif - -#include - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -#if defined(_WIN32) || defined(_WIN64) -const char * _inet_ntop(int family, const void *addr, char *dst, size_t len) -{ - if (family == AF_INET) - { - struct sockaddr_in in; - in.sin_family = AF_INET; - memcpy(&in.sin_addr, addr, 4); - if (getnameinfo((struct sockaddr *)&in, - (socklen_t) (sizeof(struct sockaddr_in)), - dst, len, NULL, 0, NI_NUMERICHOST)) - return NULL; - } - else if (family == AF_INET6) - { - struct sockaddr_in6 in6; - memset(&in6, 0, sizeof in6); - in6.sin6_family = AF_INET; - memcpy(&in6.sin6_addr, addr, sizeof(struct in_addr6)); - - /* if no ipv6 support return simple IPv6 format rule: - * A series of "0's in a 16bit block can be represented by "0" - */ - if (getnameinfo((struct sockaddr *)&in6, (socklen_t) (sizeof in6), - dst, len, NULL, 0, NI_NUMERICHOST)) - { - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; - int i, n=0; - - if (len < sizeof(tmp)) - return NULL; - - for (i = 0; i < 8; i++) - n += sprintf(tmp+n, "%s%x", - i?":":"", - ntohs(((unsigned short*)addr)[i])); - tmp[n]='\0'; - strcpy(dst, tmp); - } - } - return dst; -} -#define inet_ntop _inet_ntop -#endif - -MAD_EXPORT int -portid2portnum(ib_portid_t *portid) -{ - if (portid->lid > 0) - return -1; - - if (portid->drpath.cnt == 0) - return 0; - - return portid->drpath.p[(portid->drpath.cnt-1)]; -} - -MAD_EXPORT char * -portid2str(ib_portid_t *portid) -{ - static char buf[1024] = "local"; - int n = 0; - - if (portid->lid > 0) { - n += sprintf(buf + n, "Lid %d", portid->lid); - if (portid->grh_present) { - char gid[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; - if (inet_ntop(AF_INET6, portid->gid, gid, sizeof(gid))) - n += sprintf(buf + n, " Gid %s", gid); - } - if (portid->drpath.cnt) - n += sprintf(buf + n, " "); - else - return buf; - } - n += sprintf(buf + n, "DR path "); - drpath2str(&(portid->drpath), buf + n, sizeof(buf) - n); - - return buf; -} - -MAD_EXPORT int -str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid) -{ - char *s, *str = routepath; - - path->cnt = -1; - - DEBUG("DR str: %s", routepath); - while (str && *str) { - if ((s = strchr(str, ','))) - *s = 0; - path->p[++path->cnt] = (uint8_t)atoi(str); - if (!s) - break; - str = s+1; - } - - path->drdlid = drdlid ? drdlid : 0xffff; - path->drslid = drslid ? drslid : 0xffff; - - return path->cnt; -} - -MAD_EXPORT char * -drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size) -{ - int i = 0; - int rc = snprintf(dstr, dstr_size, "slid %d; dlid %d; %d", - path->drslid, path->drdlid, path->p[0]); - if (rc >= (int) dstr_size) - return dstr; - for (i = 1; i <= path->cnt; i++) { - rc += snprintf(dstr+rc, dstr_size-rc, ",%d", path->p[i]); - if (rc >= (int) dstr_size) - break; - } - return (dstr); -} +/* + * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +int +portid2portnum(ib_portid_t *portid) +{ + if (portid->lid > 0) + return -1; + + if (portid->drpath.cnt == 0) + return 0; + + return portid->drpath.p[(portid->drpath.cnt-1)]; +} + +char * +portid2str(ib_portid_t *portid) +{ + static char buf[1024] = "local"; + int n = 0; + + if (portid->lid > 0) { + n += sprintf(buf + n, "Lid %d", portid->lid); + if (portid->grh_present) { + char gid[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; + if (inet_ntop(AF_INET6, portid->gid, gid, sizeof(gid))) + n += sprintf(buf + n, " Gid %s", gid); + } + if (portid->drpath.cnt) + n += sprintf(buf + n, " "); + else + return buf; + } + n += sprintf(buf + n, "DR path "); + drpath2str(&(portid->drpath), buf + n, sizeof(buf) - n); + + return buf; +} + +int +str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid) +{ + char *s, *str = routepath; + + path->cnt = -1; + + DEBUG("DR str: %s", routepath); + while (str && *str) { + if ((s = strchr(str, ','))) + *s = 0; + path->p[++path->cnt] = (uint8_t)atoi(str); + if (!s) + break; + str = s+1; + } + + path->drdlid = drdlid ? drdlid : 0xffff; + path->drslid = drslid ? drslid : 0xffff; + + return path->cnt; +} + +char * +drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size) +{ + int i = 0; + int rc = snprintf(dstr, dstr_size, "slid %d; dlid %d; %d", + path->drslid, path->drdlid, path->p[0]); + if (rc >= (int) dstr_size) + return dstr; + for (i = 1; i <= path->cnt; i++) { + rc += snprintf(dstr+rc, dstr_size-rc, ",%d", path->p[i]); + if (rc >= (int) dstr_size) + break; + } + return (dstr); +} diff --git a/trunk/ulp/libibmad/src/register.c b/trunk/ulp/libibmad/src/register.c index 856c69cd..bb7cc4fd 100644 --- a/trunk/ulp/libibmad/src/register.c +++ b/trunk/ulp/libibmad/src/register.c @@ -1,203 +1,199 @@ -/* - * Copyright (c) 2004,2005 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#else -#include -#include -#include -#include -#include -#endif - -#include -#include "mad.h" - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -#define MAX_CLASS 256 -#define MAX_AGENTS 256 - -static int class_agent[MAX_CLASS]; -static int agent_class[MAX_AGENTS]; - -static int -register_agent(int agent, int mclass) -{ - static int initialized; - - if (!initialized) { - initialized++; - memset(class_agent, 0xff, sizeof class_agent); - memset(agent_class, 0xff, sizeof agent_class); - } - - if (mclass < 0 || mclass >= MAX_CLASS || - agent < 0 || agent >= MAX_AGENTS) { - DEBUG("bad mgmt class %d or agent %d", mclass, agent); - return -1; - } - - class_agent[mclass] = agent; - agent_class[agent] = mclass; - - return 0; -} - -static int -mgmt_class_vers(int mgmt_class) -{ - if ((mgmt_class >= IB_VENDOR_RANGE1_START_CLASS && - mgmt_class <= IB_VENDOR_RANGE1_END_CLASS) || - (mgmt_class >= IB_VENDOR_RANGE2_START_CLASS && - mgmt_class <= IB_VENDOR_RANGE2_END_CLASS)) - return 1; - - switch(mgmt_class) { - case IB_SMI_CLASS: - case IB_SMI_DIRECT_CLASS: - return 1; - case IB_SA_CLASS: - return 2; - case IB_PERFORMANCE_CLASS: - return 1; - case IB_DEVICE_MGMT_CLASS: - return 1; - case IB_CC_CLASS: - return 2; - } - - return 0; -} - -MAD_EXPORT int -mad_class_agent(int mgmt) -{ - if (mgmt < 1 || mgmt > MAX_CLASS) - return -1; - return class_agent[mgmt]; -} - -MAD_EXPORT int -mad_agent_class(int agent) -{ - if (agent < 1 || agent > MAX_AGENTS) - return -1; - return agent_class[agent]; -} - -MAD_EXPORT int -mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version) -{ - int vers, agent; - - if ((vers = mgmt_class_vers(mgmt)) <= 0) { - DEBUG("Unknown class %d mgmt_class", mgmt); - return -1; - } - if ((agent = umad_register(port_id, mgmt, - vers, rmpp_version, 0)) < 0) { - DEBUG("Can't register agent for class %d", mgmt); - return -1; - } - - if (mgmt < 0 || mgmt >= MAX_CLASS || agent >= MAX_AGENTS) { - DEBUG("bad mgmt class %d or agent %d", mgmt, agent); - return -1; - } - - return agent; -} - -MAD_EXPORT int -mad_register_client(int mgmt, uint8_t rmpp_version) -{ - int agent; - - agent = mad_register_port_client(madrpc_portid(), mgmt, rmpp_version); - if (agent < 0) - return agent; - - return register_agent(agent, mgmt); -} - -MAD_EXPORT int -mad_register_server(int mgmt, uint8_t rmpp_version, - long method_mask[], uint32_t class_oui) -{ - long class_method_mask[16/sizeof(long)]; - uint8_t oui[3]; - int agent, vers, mad_portid; - - if (method_mask) - memcpy(class_method_mask, method_mask, sizeof class_method_mask); - else - memset(class_method_mask, 0xff, sizeof(class_method_mask)); - - if ((mad_portid = madrpc_portid()) < 0) - return -1; - - if (class_agent[mgmt] >= 0) { - DEBUG("Class 0x%x already registered", mgmt); - return -1; - } - if ((vers = mgmt_class_vers(mgmt)) <= 0) { - DEBUG("Unknown class 0x%x mgmt_class", mgmt); - return -1; - } - if (mgmt >= IB_VENDOR_RANGE2_START_CLASS && - mgmt <= IB_VENDOR_RANGE2_END_CLASS) { - oui[0] = (class_oui >> 16) & 0xff; - oui[1] = (class_oui >> 8) & 0xff; - oui[2] = class_oui & 0xff; - if ((agent = umad_register_oui(mad_portid, mgmt, rmpp_version, - oui, class_method_mask)) < 0) { - DEBUG("Can't register agent for class %d", mgmt); - return -1; - } - } else if ((agent = umad_register(mad_portid, mgmt, vers, rmpp_version, - class_method_mask)) < 0) { - DEBUG("Can't register agent for class %d", mgmt); - return -1; - } - - if (register_agent(agent, mgmt) < 0) - return -1; - - return agent; -} +/* + * Copyright (c) 2004,2005 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +#include +#include "mad.h" + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +#define MAX_CLASS 256 +#define MAX_AGENTS 256 + +static int class_agent[MAX_CLASS]; +static int agent_class[MAX_AGENTS]; + +static int +register_agent(int agent, int mclass) +{ + static int initialized; + + if (!initialized) { + initialized++; + memset(class_agent, 0xff, sizeof class_agent); + memset(agent_class, 0xff, sizeof agent_class); + } + + if (mclass < 0 || mclass >= MAX_CLASS || + agent < 0 || agent >= MAX_AGENTS) { + DEBUG("bad mgmt class %d or agent %d", mclass, agent); + return -1; + } + + class_agent[mclass] = agent; + agent_class[agent] = mclass; + + return 0; +} + +static int +mgmt_class_vers(int mgmt_class) +{ + if ((mgmt_class >= IB_VENDOR_RANGE1_START_CLASS && + mgmt_class <= IB_VENDOR_RANGE1_END_CLASS) || + (mgmt_class >= IB_VENDOR_RANGE2_START_CLASS && + mgmt_class <= IB_VENDOR_RANGE2_END_CLASS)) + return 1; + + switch(mgmt_class) { + case IB_SMI_CLASS: + case IB_SMI_DIRECT_CLASS: + return 1; + case IB_SA_CLASS: + return 2; + case IB_PERFORMANCE_CLASS: + return 1; + case IB_DEVICE_MGMT_CLASS: + return 1; + case IB_CC_CLASS: + return 2; + } + + return 0; +} + +int +mad_class_agent(int mgmt) +{ + if (mgmt < 1 || mgmt > MAX_CLASS) + return -1; + return class_agent[mgmt]; +} + +int +mad_agent_class(int agent) +{ + if (agent < 1 || agent > MAX_AGENTS) + return -1; + return agent_class[agent]; +} + +int +mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version) +{ + int vers, agent; + + if ((vers = mgmt_class_vers(mgmt)) <= 0) { + DEBUG("Unknown class %d mgmt_class", mgmt); + return -1; + } + if ((agent = umad_register(port_id, mgmt, + vers, rmpp_version, 0)) < 0) { + DEBUG("Can't register agent for class %d", mgmt); + return -1; + } + + if (mgmt < 0 || mgmt >= MAX_CLASS || agent >= MAX_AGENTS) { + DEBUG("bad mgmt class %d or agent %d", mgmt, agent); + return -1; + } + + return agent; +} + +int +mad_register_client(int mgmt, uint8_t rmpp_version) +{ + int agent; + + agent = mad_register_port_client(madrpc_portid(), mgmt, rmpp_version); + if (agent < 0) + return agent; + + return register_agent(agent, mgmt); +} + +int +mad_register_server(int mgmt, uint8_t rmpp_version, + long method_mask[], uint32_t class_oui) +{ + long class_method_mask[16/sizeof(long)]; + uint8_t oui[3]; + int agent, vers, mad_portid; + + if (method_mask) + memcpy(class_method_mask, method_mask, sizeof class_method_mask); + else + memset(class_method_mask, 0xff, sizeof(class_method_mask)); + + if ((mad_portid = madrpc_portid()) < 0) + return -1; + + if (class_agent[mgmt] >= 0) { + DEBUG("Class 0x%x already registered", mgmt); + return -1; + } + if ((vers = mgmt_class_vers(mgmt)) <= 0) { + DEBUG("Unknown class 0x%x mgmt_class", mgmt); + return -1; + } + if (mgmt >= IB_VENDOR_RANGE2_START_CLASS && + mgmt <= IB_VENDOR_RANGE2_END_CLASS) { + oui[0] = (class_oui >> 16) & 0xff; + oui[1] = (class_oui >> 8) & 0xff; + oui[2] = class_oui & 0xff; + if ((agent = umad_register_oui(mad_portid, mgmt, rmpp_version, + oui, class_method_mask)) < 0) { + DEBUG("Can't register agent for class %d", mgmt); + return -1; + } + } else if ((agent = umad_register(mad_portid, mgmt, vers, rmpp_version, + class_method_mask)) < 0) { + DEBUG("Can't register agent for class %d", mgmt); + return -1; + } + + if (register_agent(agent, mgmt) < 0) + return -1; + + return agent; +} diff --git a/trunk/ulp/libibmad/src/resolve.c b/trunk/ulp/libibmad/src/resolve.c index d5675575..6a79831e 100644 --- a/trunk/ulp/libibmad/src/resolve.c +++ b/trunk/ulp/libibmad/src/resolve.c @@ -1,193 +1,182 @@ -/* - * Copyright (c) 2004-2006 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#define strtoull _strtoui64 -#else -#include -#include -#include -#include -#endif - -#include -#include - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -int -ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout, const void *srcport) -{ - ib_portid_t self = {0}; - uint8_t portinfo[64]; - int lid; - - memset(sm_id, 0, sizeof(*sm_id)); - - if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, - 0, 0, srcport)) - return -1; - - mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid); - - return ib_portid_set(sm_id, lid, 0, 0); -} - -MAD_EXPORT int -ib_resolve_smlid(ib_portid_t *sm_id, int timeout) -{ - return ib_resolve_smlid_via(sm_id, timeout, NULL); -} - -int -ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout, const void *srcport) -{ - ib_portid_t sm_portid; - char buf[IB_SA_DATA_SIZE] = {0}; - - if (!sm_id) { - sm_id = &sm_portid; - if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0) - return -1; - } - if (*(uint64_t*)&portid->gid == 0) - mad_set_field64(portid->gid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX); - if (guid) - mad_set_field64(portid->gid, 0, IB_GID_GUID_F, *guid); - - if ((portid->lid = ib_path_query_via(srcport, portid->gid, portid->gid, sm_id, buf)) < 0) - return -1; - - return 0; -} - -MAD_EXPORT int -ib_resolve_guid(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout) -{ - return ib_resolve_guid_via(portid, guid, sm_id, timeout, NULL); -} - -int -ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id, const void *srcport) -{ - uint64_t guid; - int lid; - char *routepath; - ib_portid_t selfportid = {0}; - int selfport = 0; - - switch (dest_type) { - case IB_DEST_LID: - lid = strtol(addr_str, 0, 0); - if (!IB_LID_VALID(lid)) - return -1; - return ib_portid_set(portid, lid, 0, 0); - - case IB_DEST_DRPATH: - if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0) - return -1; - return 0; - - case IB_DEST_GUID: - if (!(guid = strtoull(addr_str, 0, 0))) - return -1; - - /* keep guid in portid? */ - return ib_resolve_guid_via(portid, &guid, sm_id, 0, srcport); - - case IB_DEST_DRSLID: - lid = strtol(addr_str, &routepath, 0); - routepath++; - if (!IB_LID_VALID(lid)) - return -1; - ib_portid_set(portid, lid, 0, 0); - - /* handle DR parsing and set DrSLID to local lid */ - if (ib_resolve_self_via(&selfportid, &selfport, 0, srcport) < 0) - return -1; - if (str2drpath(&portid->drpath, routepath, selfportid.lid, 0) < 0) - return -1; - return 0; - - default: - IBWARN("bad dest_type %d", dest_type); - } - - return -1; -} - -MAD_EXPORT int -ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id) -{ - return ib_resolve_portid_str_via(portid, addr_str, dest_type, - sm_id, NULL); -} - -int -ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid, - const void *srcport) -{ - ib_portid_t self = {0}; - uint8_t portinfo[64]; - uint8_t nodeinfo[64]; - uint64_t guid, prefix; - - if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport)) - return -1; - - if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport)) - return -1; - - mad_decode_field(portinfo, IB_PORT_LID_F, &portid->lid); - mad_decode_field(portinfo, IB_PORT_GID_PREFIX_F, &prefix); - mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &guid); - - if (portnum) - mad_decode_field(nodeinfo, IB_NODE_LOCAL_PORT_F, portnum); - if (gid) { - mad_encode_field(*gid, IB_GID_PREFIX_F, &prefix); - mad_encode_field(*gid, IB_GID_GUID_F, &guid); - } - return 0; -} - -MAD_EXPORT int -ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid) -{ - return ib_resolve_self_via (portid, portnum, gid, NULL); -} +/* + * Copyright (c) 2004-2006 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include +#include + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +int +ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout, const void *srcport) +{ + ib_portid_t self = {0}; + uint8_t portinfo[64]; + int lid; + + memset(sm_id, 0, sizeof(*sm_id)); + + if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, + 0, 0, srcport)) + return -1; + + mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid); + + return ib_portid_set(sm_id, lid, 0, 0); +} + +int +ib_resolve_smlid(ib_portid_t *sm_id, int timeout) +{ + return ib_resolve_smlid_via(sm_id, timeout, NULL); +} + +int +ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout, const void *srcport) +{ + ib_portid_t sm_portid; + char buf[IB_SA_DATA_SIZE] = {0}; + + if (!sm_id) { + sm_id = &sm_portid; + if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0) + return -1; + } + if (*(uint64_t*)&portid->gid == 0) + mad_set_field64(portid->gid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX); + if (guid) + mad_set_field64(portid->gid, 0, IB_GID_GUID_F, *guid); + + if ((portid->lid = ib_path_query_via(srcport, portid->gid, portid->gid, sm_id, buf)) < 0) + return -1; + + return 0; +} + +int +ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id, const void *srcport) +{ + uint64_t guid; + int lid; + char *routepath; + ib_portid_t selfportid = {0}; + int selfport = 0; + + switch (dest_type) { + case IB_DEST_LID: + lid = strtol(addr_str, 0, 0); + if (!IB_LID_VALID(lid)) + return -1; + return ib_portid_set(portid, lid, 0, 0); + + case IB_DEST_DRPATH: + if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0) + return -1; + return 0; + + case IB_DEST_GUID: + if (!(guid = strtoull(addr_str, 0, 0))) + return -1; + + /* keep guid in portid? */ + return ib_resolve_guid_via(portid, &guid, sm_id, 0, srcport); + + case IB_DEST_DRSLID: + lid = strtol(addr_str, &routepath, 0); + routepath++; + if (!IB_LID_VALID(lid)) + return -1; + ib_portid_set(portid, lid, 0, 0); + + /* handle DR parsing and set DrSLID to local lid */ + if (ib_resolve_self_via(&selfportid, &selfport, 0, srcport) < 0) + return -1; + if (str2drpath(&portid->drpath, routepath, selfportid.lid, 0) < 0) + return -1; + return 0; + + default: + IBWARN("bad dest_type %d", dest_type); + } + + return -1; +} + +int +ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id) +{ + return ib_resolve_portid_str_via(portid, addr_str, dest_type, + sm_id, NULL); +} + +int +ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid, + const void *srcport) +{ + ib_portid_t self = {0}; + uint8_t portinfo[64]; + uint8_t nodeinfo[64]; + uint64_t guid, prefix; + + if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport)) + return -1; + + if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport)) + return -1; + + mad_decode_field(portinfo, IB_PORT_LID_F, &portid->lid); + mad_decode_field(portinfo, IB_PORT_GID_PREFIX_F, &prefix); + mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &guid); + + if (portnum) + mad_decode_field(nodeinfo, IB_NODE_LOCAL_PORT_F, portnum); + if (gid) { + mad_encode_field(*gid, IB_GID_PREFIX_F, &prefix); + mad_encode_field(*gid, IB_GID_GUID_F, &guid); + } + return 0; +} + +int +ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid) +{ + return ib_resolve_self_via (portid, portnum, gid, NULL); +} diff --git a/trunk/ulp/libibmad/src/rpc.c b/trunk/ulp/libibmad/src/rpc.c index aa01f54c..17313787 100644 --- a/trunk/ulp/libibmad/src/rpc.c +++ b/trunk/ulp/libibmad/src/rpc.c @@ -1,406 +1,385 @@ -/* - * Copyright (c) 2004-2006 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#else -#include -#include -#include -#include -#include -#endif - -#include -#include "mad.h" -#include - -#define MAX_CLASS 256 - -struct ibmad_port { - int port_id; /* file descriptor returned by umad_open() */ - int class_agents[MAX_CLASS]; /* class2agent mapper */ -}; - -int ibdebug; - -static int mad_portid = -1; -static int iberrs; - -static int madrpc_retries = MAD_DEF_RETRIES; -static int def_madrpc_timeout = MAD_DEF_TIMEOUT_MS; -static void *save_mad; -static int save_mad_len = 256; - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN -#define ERRS if (iberrs || ibdebug) IBWARN - -#define MAD_TID(mad) (*((uint64_t *)((char *)(mad) + 8))) - -MAD_EXPORT void -madrpc_show_errors(int set) -{ - iberrs = set; -} - -void -madrpc_save_mad(void *madbuf, int len) -{ - save_mad = madbuf; - save_mad_len = len; -} - -MAD_EXPORT int -madrpc_set_retries(int retries) -{ - if (retries > 0) - madrpc_retries = retries; - return madrpc_retries; -} - -MAD_EXPORT int -madrpc_set_timeout(int timeout) -{ - def_madrpc_timeout = timeout; - return 0; -} - -int -madrpc_def_timeout(void) -{ - return def_madrpc_timeout; -} - -MAD_EXPORT int -madrpc_portid(void) -{ - return mad_portid; -} - -static int -_do_madrpc(int port_id, void *sndbuf, void *rcvbuf, int agentid, int len, - int timeout) -{ - uint32_t trid; /* only low 32 bits */ - int retries; - int length, status; - - if (!timeout) - timeout = def_madrpc_timeout; - - if (ibdebug > 1) { - IBWARN(">>> sending: len %d pktsz %zu", len, umad_size() + len); - xdump(stderr, "send buf\n", sndbuf, umad_size() + len); - } - - if (save_mad) { - memcpy(save_mad, umad_get_mad(sndbuf), - save_mad_len < len ? save_mad_len : len); - save_mad = 0; - } - - trid = (uint32_t)mad_get_field64(umad_get_mad(sndbuf), 0, IB_MAD_TRID_F); - - for (retries = 0; retries < madrpc_retries; retries++) { - if (retries) { - ERRS("retry %d (timeout %d ms)", retries, timeout); - } - - length = len; - if (umad_send(port_id, agentid, sndbuf, length, timeout, 0) < 0) { - IBWARN("send failed; %m"); - return -1; - } - - /* Use same timeout on receive side just in case */ - /* send packet is lost somewhere. */ - do { - if (umad_recv(port_id, rcvbuf, &length, timeout) < 0) { - IBWARN("recv failed: %m"); - return -1; - } - - if (ibdebug > 1) { - IBWARN("rcv buf:"); - xdump(stderr, "rcv buf\n", umad_get_mad(rcvbuf), IB_MAD_SIZE); - } - } while ((uint32_t)mad_get_field64(umad_get_mad(rcvbuf), 0, IB_MAD_TRID_F) != trid); - - status = umad_status(rcvbuf); - if (!status) - return length; /* done */ - if (status == ENOMEM) - return length; - } - - ERRS("timeout after %d retries, %d ms", retries, timeout * retries); - return -1; -} - -void * -mad_rpc(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport, void *payload, - void *rcvdata) -{ - const struct ibmad_port *p = port_id; - int status, len; - uint8_t sndbuf[1024], rcvbuf[1024], *mad; - - len = 0; - memset(sndbuf, 0, umad_size() + IB_MAD_SIZE); - - if ((len = mad_build_pkt(sndbuf, rpc, dport, 0, payload)) < 0) - return 0; - - if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf, - p->class_agents[rpc->mgtclass], - len, rpc->timeout)) < 0) { - IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport)); - return 0; - } - - mad = umad_get_mad(rcvbuf); - - if ((status = mad_get_field(mad, 0, IB_DRSMP_STATUS_F)) != 0) { - ERRS("MAD completed with error status 0x%x; dport (%s)", - status, portid2str(dport)); - return 0; - } - - if (ibdebug) { - IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz); - xdump(stderr, "mad data\n", mad + rpc->dataoffs, rpc->datasz); - } - - if (rcvdata) - memcpy(rcvdata, mad + rpc->dataoffs, rpc->datasz); - - return rcvdata; -} - -void * -mad_rpc_rmpp(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport, - ib_rmpp_hdr_t *rmpp, void *data) -{ - const struct ibmad_port *p = port_id; - int status, len; - uint8_t sndbuf[1024], rcvbuf[1024], *mad; - - memset(sndbuf, 0, umad_size() + IB_MAD_SIZE); - - DEBUG("rmpp %p data %p", rmpp, data); - - if ((len = mad_build_pkt(sndbuf, rpc, dport, rmpp, data)) < 0) - return 0; - - if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf, - p->class_agents[rpc->mgtclass], - len, rpc->timeout)) < 0) { - IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport)); - return 0; - } - - mad = umad_get_mad(rcvbuf); - - if ((status = mad_get_field(mad, 0, IB_MAD_STATUS_F)) != 0) { - ERRS("MAD completed with error status 0x%x; dport (%s)", - status, portid2str(dport)); - return 0; - } - - if (ibdebug) { - IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz); - xdump(stderr, "rmpp mad data\n", mad + rpc->dataoffs, - rpc->datasz); - } - - if (rmpp) { - rmpp->flags = mad_get_field(mad, 0, IB_SA_RMPP_FLAGS_F); - if ((rmpp->flags & 0x3) && - mad_get_field(mad, 0, IB_SA_RMPP_VERS_F) != 1) { - IBWARN("bad rmpp version"); - return 0; - } - rmpp->type = mad_get_field(mad, 0, IB_SA_RMPP_TYPE_F); - rmpp->status = mad_get_field(mad, 0, IB_SA_RMPP_STATUS_F); - DEBUG("rmpp type %d status %d", rmpp->type, rmpp->status); - rmpp->d1.u = mad_get_field(mad, 0, IB_SA_RMPP_D1_F); - rmpp->d2.u = mad_get_field(mad, 0, IB_SA_RMPP_D2_F); - } - - if (data) - memcpy(data, mad + rpc->dataoffs, rpc->datasz); - - rpc->recsz = mad_get_field(mad, 0, IB_SA_ATTROFFS_F); - - return data; -} - -void * -madrpc(ib_rpc_t *rpc, ib_portid_t *dport, void *payload, void *rcvdata) -{ - struct ibmad_port port; - - port.port_id = mad_portid; - port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass); - return mad_rpc(&port, rpc, dport, payload, rcvdata); -} - -void * -madrpc_rmpp(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data) -{ - struct ibmad_port port; - - port.port_id = mad_portid; - port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass); - return mad_rpc_rmpp(&port, rpc, dport, rmpp, data); -} - -static cl_plock_t rpclock; - -void -madrpc_lock(void) -{ - cl_plock_acquire(&rpclock); -} - -void -madrpc_unlock(void) -{ - cl_plock_release(&rpclock); -} - -MAD_EXPORT void -madrpc_init(char *dev_name, int dev_port, int *mgmt_classes, int num_classes) -{ - if (umad_init() < 0) - IBPANIC("can't init UMAD library"); - - if ((mad_portid = umad_open_port(dev_name, dev_port)) < 0) - IBPANIC("can't open UMAD port (%s:%d)", dev_name, dev_port); - - if (num_classes >= MAX_CLASS) - IBPANIC("too many classes %d requested", num_classes); - - while (num_classes--) { - uint8_t rmpp_version = 0; - int mgmt = *mgmt_classes++; - - if (mgmt == IB_SA_CLASS) - rmpp_version = 1; - if (mad_register_client(mgmt, rmpp_version) < 0) - IBPANIC("client_register for mgmt class %d failed", mgmt); - } - cl_plock_init(&rpclock); -} - -void * -mad_rpc_open_port(char *dev_name, int dev_port, - int *mgmt_classes, int num_classes) -{ - struct ibmad_port *p; - int port_id; - - if (num_classes >= MAX_CLASS) { - IBWARN("too many classes %d requested", num_classes); - errno = EINVAL; - return NULL; - } - - if (umad_init() < 0) { - IBWARN("can't init UMAD library"); - errno = ENODEV; - return NULL; - } - - p = malloc(sizeof(*p)); - if (!p) { - errno = ENOMEM; - return NULL; - } - memset(p, 0, sizeof(*p)); - - if ((port_id = umad_open_port(dev_name, dev_port)) < 0) { - IBWARN("can't open UMAD port (%s:%d)", dev_name, dev_port); - if (!errno) - errno = EIO; - free(p); - return NULL; - } - - while (num_classes--) { - uint8_t rmpp_version = 0; - int mgmt = *mgmt_classes++; - int agent; - - if (mgmt == IB_SA_CLASS) - rmpp_version = 1; - if (mgmt < 0 || mgmt >= MAX_CLASS || - (agent = mad_register_port_client(port_id, mgmt, - rmpp_version)) < 0) { - IBWARN("client_register for mgmt %d failed", mgmt); - if(!errno) - errno = EINVAL; - umad_close_port(port_id); - free(p); - return NULL; - } - p->class_agents[mgmt] = agent; - } - - p->port_id = port_id; - return p; -} - -void -mad_rpc_close_port(void *port_id) -{ - struct ibmad_port *p = port_id; - - umad_close_port(p->port_id); - free(p); -} - -uint8_t * -sa_call(void *rcvbuf, ib_portid_t *portid, ib_sa_call_t *sa, unsigned timeout) -{ - struct ibmad_port port; - - port.port_id = mad_portid; - port.class_agents[IB_SA_CLASS] = mad_class_agent(IB_SA_CLASS); - return sa_rpc_call(&port, rcvbuf, portid, sa, timeout); -} +/* + * Copyright (c) 2004-2006 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +#include +#include "mad.h" + +#define MAX_CLASS 256 + +struct ibmad_port { + int port_id; /* file descriptor returned by umad_open() */ + int class_agents[MAX_CLASS]; /* class2agent mapper */ +}; + +int ibdebug; + +static int mad_portid = -1; +static int iberrs; + +static int madrpc_retries = MAD_DEF_RETRIES; +static int def_madrpc_timeout = MAD_DEF_TIMEOUT_MS; +static void *save_mad; +static int save_mad_len = 256; + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN +#define ERRS if (iberrs || ibdebug) IBWARN + +#define MAD_TID(mad) (*((uint64_t *)((char *)(mad) + 8))) + +void +madrpc_show_errors(int set) +{ + iberrs = set; +} + +void +madrpc_save_mad(void *madbuf, int len) +{ + save_mad = madbuf; + save_mad_len = len; +} + +int +madrpc_set_retries(int retries) +{ + if (retries > 0) + madrpc_retries = retries; + return madrpc_retries; +} + +int +madrpc_set_timeout(int timeout) +{ + def_madrpc_timeout = timeout; + return 0; +} + +int +madrpc_def_timeout(void) +{ + return def_madrpc_timeout; +} + +int +madrpc_portid(void) +{ + return mad_portid; +} + +static int +_do_madrpc(int port_id, void *sndbuf, void *rcvbuf, int agentid, int len, + int timeout) +{ + uint32_t trid; /* only low 32 bits */ + int retries; + int length, status; + + if (!timeout) + timeout = def_madrpc_timeout; + + if (ibdebug > 1) { + IBWARN(">>> sending: len %d pktsz %zu", len, umad_size() + len); + xdump(stderr, "send buf\n", sndbuf, umad_size() + len); + } + + if (save_mad) { + memcpy(save_mad, umad_get_mad(sndbuf), + save_mad_len < len ? save_mad_len : len); + save_mad = 0; + } + + trid = (uint32_t)mad_get_field64(umad_get_mad(sndbuf), 0, IB_MAD_TRID_F); + + for (retries = 0; retries < madrpc_retries; retries++) { + if (retries) { + ERRS("retry %d (timeout %d ms)", retries, timeout); + } + + length = len; + if (umad_send(port_id, agentid, sndbuf, length, timeout, 0) < 0) { + IBWARN("send failed; %m"); + return -1; + } + + /* Use same timeout on receive side just in case */ + /* send packet is lost somewhere. */ + do { + if (umad_recv(port_id, rcvbuf, &length, timeout) < 0) { + IBWARN("recv failed: %m"); + return -1; + } + + if (ibdebug > 1) { + IBWARN("rcv buf:"); + xdump(stderr, "rcv buf\n", umad_get_mad(rcvbuf), IB_MAD_SIZE); + } + } while ((uint32_t)mad_get_field64(umad_get_mad(rcvbuf), 0, IB_MAD_TRID_F) != trid); + + status = umad_status(rcvbuf); + if (!status) + return length; /* done */ + if (status == ENOMEM) + return length; + } + + ERRS("timeout after %d retries, %d ms", retries, timeout * retries); + return -1; +} + +void * +mad_rpc(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport, void *payload, + void *rcvdata) +{ + const struct ibmad_port *p = port_id; + int status, len; + uint8_t sndbuf[1024], rcvbuf[1024], *mad; + + len = 0; + memset(sndbuf, 0, umad_size() + IB_MAD_SIZE); + + if ((len = mad_build_pkt(sndbuf, rpc, dport, 0, payload)) < 0) + return 0; + + if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf, + p->class_agents[rpc->mgtclass], + len, rpc->timeout)) < 0) { + IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport)); + return 0; + } + + mad = umad_get_mad(rcvbuf); + + if ((status = mad_get_field(mad, 0, IB_DRSMP_STATUS_F)) != 0) { + ERRS("MAD completed with error status 0x%x; dport (%s)", + status, portid2str(dport)); + return 0; + } + + if (ibdebug) { + IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz); + xdump(stderr, "mad data\n", mad + rpc->dataoffs, rpc->datasz); + } + + if (rcvdata) + memcpy(rcvdata, mad + rpc->dataoffs, rpc->datasz); + + return rcvdata; +} + +void * +mad_rpc_rmpp(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport, + ib_rmpp_hdr_t *rmpp, void *data) +{ + const struct ibmad_port *p = port_id; + int status, len; + uint8_t sndbuf[1024], rcvbuf[1024], *mad; + + memset(sndbuf, 0, umad_size() + IB_MAD_SIZE); + + DEBUG("rmpp %p data %p", rmpp, data); + + if ((len = mad_build_pkt(sndbuf, rpc, dport, rmpp, data)) < 0) + return 0; + + if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf, + p->class_agents[rpc->mgtclass], + len, rpc->timeout)) < 0) { + IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport)); + return 0; + } + + mad = umad_get_mad(rcvbuf); + + if ((status = mad_get_field(mad, 0, IB_MAD_STATUS_F)) != 0) { + ERRS("MAD completed with error status 0x%x; dport (%s)", + status, portid2str(dport)); + return 0; + } + + if (ibdebug) { + IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz); + xdump(stderr, "rmpp mad data\n", mad + rpc->dataoffs, + rpc->datasz); + } + + if (rmpp) { + rmpp->flags = mad_get_field(mad, 0, IB_SA_RMPP_FLAGS_F); + if ((rmpp->flags & 0x3) && + mad_get_field(mad, 0, IB_SA_RMPP_VERS_F) != 1) { + IBWARN("bad rmpp version"); + return 0; + } + rmpp->type = mad_get_field(mad, 0, IB_SA_RMPP_TYPE_F); + rmpp->status = mad_get_field(mad, 0, IB_SA_RMPP_STATUS_F); + DEBUG("rmpp type %d status %d", rmpp->type, rmpp->status); + rmpp->d1.u = mad_get_field(mad, 0, IB_SA_RMPP_D1_F); + rmpp->d2.u = mad_get_field(mad, 0, IB_SA_RMPP_D2_F); + } + + if (data) + memcpy(data, mad + rpc->dataoffs, rpc->datasz); + + rpc->recsz = mad_get_field(mad, 0, IB_SA_ATTROFFS_F); + + return data; +} + +void * +madrpc(ib_rpc_t *rpc, ib_portid_t *dport, void *payload, void *rcvdata) +{ + struct ibmad_port port; + + port.port_id = mad_portid; + port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass); + return mad_rpc(&port, rpc, dport, payload, rcvdata); +} + +void * +madrpc_rmpp(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data) +{ + struct ibmad_port port; + + port.port_id = mad_portid; + port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass); + return mad_rpc_rmpp(&port, rpc, dport, rmpp, data); +} + +void +madrpc_init(char *dev_name, int dev_port, int *mgmt_classes, int num_classes) +{ + if (umad_init() < 0) + IBPANIC("can't init UMAD library"); + + if ((mad_portid = umad_open_port(dev_name, dev_port)) < 0) + IBPANIC("can't open UMAD port (%s:%d)", dev_name, dev_port); + + if (num_classes >= MAX_CLASS) + IBPANIC("too many classes %d requested", num_classes); + + while (num_classes--) { + uint8_t rmpp_version = 0; + int mgmt = *mgmt_classes++; + + if (mgmt == IB_SA_CLASS) + rmpp_version = 1; + if (mad_register_client(mgmt, rmpp_version) < 0) + IBPANIC("client_register for mgmt class %d failed", mgmt); + } +} + +void * +mad_rpc_open_port(char *dev_name, int dev_port, + int *mgmt_classes, int num_classes) +{ + struct ibmad_port *p; + int port_id; + + if (num_classes >= MAX_CLASS) { + IBWARN("too many classes %d requested", num_classes); + errno = EINVAL; + return NULL; + } + + if (umad_init() < 0) { + IBWARN("can't init UMAD library"); + errno = ENODEV; + return NULL; + } + + p = malloc(sizeof(*p)); + if (!p) { + errno = ENOMEM; + return NULL; + } + memset(p, 0, sizeof(*p)); + + if ((port_id = umad_open_port(dev_name, dev_port)) < 0) { + IBWARN("can't open UMAD port (%s:%d)", dev_name, dev_port); + if (!errno) + errno = EIO; + free(p); + return NULL; + } + + while (num_classes--) { + uint8_t rmpp_version = 0; + int mgmt = *mgmt_classes++; + int agent; + + if (mgmt == IB_SA_CLASS) + rmpp_version = 1; + if (mgmt < 0 || mgmt >= MAX_CLASS || + (agent = mad_register_port_client(port_id, mgmt, + rmpp_version)) < 0) { + IBWARN("client_register for mgmt %d failed", mgmt); + if(!errno) + errno = EINVAL; + umad_close_port(port_id); + free(p); + return NULL; + } + p->class_agents[mgmt] = agent; + } + + p->port_id = port_id; + return p; +} + +void +mad_rpc_close_port(void *port_id) +{ + struct ibmad_port *p = port_id; + + umad_close_port(p->port_id); + free(p); +} + +uint8_t * +sa_call(void *rcvbuf, ib_portid_t *portid, ib_sa_call_t *sa, unsigned timeout) +{ + struct ibmad_port port; + + port.port_id = mad_portid; + port.class_agents[IB_SA_CLASS] = mad_class_agent(IB_SA_CLASS); + return sa_rpc_call(&port, rcvbuf, portid, sa, timeout); +} diff --git a/trunk/ulp/libibmad/src/sa.c b/trunk/ulp/libibmad/src/sa.c index ae973e11..c08a3921 100644 --- a/trunk/ulp/libibmad/src/sa.c +++ b/trunk/ulp/libibmad/src/sa.c @@ -1,153 +1,149 @@ -/* - * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#else -#include -#include -#include -#include -#endif - -#include - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -uint8_t * -sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid, - ib_sa_call_t *sa, unsigned timeout) -{ - ib_rpc_t rpc = {0}; - uint8_t *p; - - DEBUG("attr 0x%x mod 0x%x route %s", sa->attrid, sa->mod, - portid2str(portid)); - - if (portid->lid <= 0) { - IBWARN("only lid routes are supported"); - return 0; - } - - rpc.mgtclass = IB_SA_CLASS; - rpc.method = sa->method; - rpc.attr.id = sa->attrid; - rpc.attr.mod = sa->mod; - rpc.mask = sa->mask; - rpc.timeout = timeout; - rpc.datasz = IB_SA_DATA_SIZE; - rpc.dataoffs = IB_SA_DATA_OFFS; - rpc.trid = sa->trid; - - portid->qp = 1; - if (!portid->qkey) - portid->qkey = IB_DEFAULT_QP1_QKEY; - - p = mad_rpc_rmpp(ibmad_port, &rpc, portid, 0/*&sa->rmpp*/, rcvbuf); /* TODO: RMPP */ - - sa->recsz = rpc.recsz; - - return p; -} - -/* PathRecord */ -#define IB_PR_COMPMASK_DGID (1ull<<2) -#define IB_PR_COMPMASK_SGID (1ull<<3) -#define IB_PR_COMPMASK_DLID (1ull<<4) -#define IB_PR_COMPMASK_SLID (1ull<<5) -#define IB_PR_COMPMASK_RAWTRAFIC (1ull<<6) -#define IB_PR_COMPMASK_RESV0 (1ull<<7) -#define IB_PR_COMPMASK_FLOWLABEL (1ull<<8) -#define IB_PR_COMPMASK_HOPLIMIT (1ull<<9) -#define IB_PR_COMPMASK_TCLASS (1ull<<10) -#define IB_PR_COMPMASK_REVERSIBLE (1ull<<11) -#define IB_PR_COMPMASK_NUMBPATH (1ull<<12) -#define IB_PR_COMPMASK_PKEY (1ull<<13) -#define IB_PR_COMPMASK_RESV1 (1ull<<14) -#define IB_PR_COMPMASK_SL (1ull<<15) -#define IB_PR_COMPMASK_MTUSELEC (1ull<<16) -#define IB_PR_COMPMASK_MTU (1ull<<17) -#define IB_PR_COMPMASK_RATESELEC (1ull<<18) -#define IB_PR_COMPMASK_RATE (1ull<<19) -#define IB_PR_COMPMASK_PKTLIFETIMESELEC (1ull<<20) -#define IB_PR_COMPMASK_PKTLIFETIME (1ull<<21) -#define IB_PR_COMPMASK_PREFERENCE (1ull<<22) - -#define IB_PR_DEF_MASK (IB_PR_COMPMASK_DGID |\ - IB_PR_COMPMASK_SGID |\ - IB_PR_COMPMASK_NUMBPATH) - -int -ib_path_query_via(const void *srcport, ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf) -{ - int npath; - ib_sa_call_t sa = {0}; - uint8_t *p; - int dlid; - - npath = 1; /* only MAD_METHOD_GET is supported */ - memset(&sa, 0, sizeof sa); - sa.method = IB_MAD_METHOD_GET; - sa.attrid = IB_SA_ATTR_PATHRECORD; - sa.mask = IB_PR_DEF_MASK; - sa.trid = mad_trid(); - - memset(buf, 0, IB_SA_PR_RECSZ); - - mad_encode_field(buf, IB_SA_PR_NPATH_F, &npath); - mad_encode_field(buf, IB_SA_PR_DGID_F, destgid); - mad_encode_field(buf, IB_SA_PR_SGID_F, srcgid); - - if (srcport) { - p = sa_rpc_call (srcport, buf, sm_id, &sa, 0); - } else { - p = safe_sa_call(buf, sm_id, &sa, 0); - } - if (!p) { - IBWARN("sa call path_query failed"); - return -1; - } - - mad_decode_field(p, IB_SA_PR_DLID_F, &dlid); - return dlid; -} - -MAD_EXPORT int -ib_path_query(ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf) -{ - return ib_path_query_via (NULL, srcgid, destgid, sm_id, buf); -} +/* + * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +uint8_t * +sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid, + ib_sa_call_t *sa, unsigned timeout) +{ + ib_rpc_t rpc = {0}; + uint8_t *p; + + DEBUG("attr 0x%x mod 0x%x route %s", sa->attrid, sa->mod, + portid2str(portid)); + + if (portid->lid <= 0) { + IBWARN("only lid routes are supported"); + return 0; + } + + rpc.mgtclass = IB_SA_CLASS; + rpc.method = sa->method; + rpc.attr.id = sa->attrid; + rpc.attr.mod = sa->mod; + rpc.mask = sa->mask; + rpc.timeout = timeout; + rpc.datasz = IB_SA_DATA_SIZE; + rpc.dataoffs = IB_SA_DATA_OFFS; + rpc.trid = sa->trid; + + portid->qp = 1; + if (!portid->qkey) + portid->qkey = IB_DEFAULT_QP1_QKEY; + + p = mad_rpc_rmpp(ibmad_port, &rpc, portid, 0/*&sa->rmpp*/, rcvbuf); /* TODO: RMPP */ + + sa->recsz = rpc.recsz; + + return p; +} + +/* PathRecord */ +#define IB_PR_COMPMASK_DGID (1ull<<2) +#define IB_PR_COMPMASK_SGID (1ull<<3) +#define IB_PR_COMPMASK_DLID (1ull<<4) +#define IB_PR_COMPMASK_SLID (1ull<<5) +#define IB_PR_COMPMASK_RAWTRAFIC (1ull<<6) +#define IB_PR_COMPMASK_RESV0 (1ull<<7) +#define IB_PR_COMPMASK_FLOWLABEL (1ull<<8) +#define IB_PR_COMPMASK_HOPLIMIT (1ull<<9) +#define IB_PR_COMPMASK_TCLASS (1ull<<10) +#define IB_PR_COMPMASK_REVERSIBLE (1ull<<11) +#define IB_PR_COMPMASK_NUMBPATH (1ull<<12) +#define IB_PR_COMPMASK_PKEY (1ull<<13) +#define IB_PR_COMPMASK_RESV1 (1ull<<14) +#define IB_PR_COMPMASK_SL (1ull<<15) +#define IB_PR_COMPMASK_MTUSELEC (1ull<<16) +#define IB_PR_COMPMASK_MTU (1ull<<17) +#define IB_PR_COMPMASK_RATESELEC (1ull<<18) +#define IB_PR_COMPMASK_RATE (1ull<<19) +#define IB_PR_COMPMASK_PKTLIFETIMESELEC (1ull<<20) +#define IB_PR_COMPMASK_PKTLIFETIME (1ull<<21) +#define IB_PR_COMPMASK_PREFERENCE (1ull<<22) + +#define IB_PR_DEF_MASK (IB_PR_COMPMASK_DGID |\ + IB_PR_COMPMASK_SGID |\ + IB_PR_COMPMASK_NUMBPATH) + +int +ib_path_query_via(const void *srcport, ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf) +{ + int npath; + ib_sa_call_t sa = {0}; + uint8_t *p; + int dlid; + + npath = 1; /* only MAD_METHOD_GET is supported */ + memset(&sa, 0, sizeof sa); + sa.method = IB_MAD_METHOD_GET; + sa.attrid = IB_SA_ATTR_PATHRECORD; + sa.mask = IB_PR_DEF_MASK; + sa.trid = mad_trid(); + + memset(buf, 0, IB_SA_PR_RECSZ); + + mad_encode_field(buf, IB_SA_PR_NPATH_F, &npath); + mad_encode_field(buf, IB_SA_PR_DGID_F, destgid); + mad_encode_field(buf, IB_SA_PR_SGID_F, srcgid); + + if (srcport) { + p = sa_rpc_call (srcport, buf, sm_id, &sa, 0); + } else { + p = sa_call(buf, sm_id, &sa, 0); + } + if (!p) { + IBWARN("sa call path_query failed"); + return -1; + } + + mad_decode_field(p, IB_SA_PR_DLID_F, &dlid); + return dlid; +} + +int +ib_path_query(ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf) +{ + return ib_path_query_via(NULL, srcgid, destgid, sm_id, buf); +} diff --git a/trunk/ulp/libibmad/src/serv.c b/trunk/ulp/libibmad/src/serv.c index 54377205..d55286c8 100644 --- a/trunk/ulp/libibmad/src/serv.c +++ b/trunk/ulp/libibmad/src/serv.c @@ -1,184 +1,178 @@ -/* - * Copyright (c) 2004,2005 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#else -#include -#include -#include -#include -#include -#endif - -#include -#include - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -MAD_EXPORT int -mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data) -{ - uint8_t pktbuf[1024]; - void *umad = pktbuf; - - memset(pktbuf, 0, umad_size()); - - DEBUG("rmpp %p data %p", rmpp, data); - - if (mad_build_pkt(umad, rpc, dport, rmpp, data) < 0) - return 0; - - if (ibdebug) { - IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz); - xdump(stderr, "mad send data\n", - (char *)umad_get_mad(umad) + rpc->dataoffs, rpc->datasz); - } - - if (umad_send(madrpc_portid(), mad_class_agent(rpc->mgtclass), - umad, IB_MAD_SIZE, rpc->timeout, 0) < 0) { - IBWARN("send failed; %m"); - return -1; - } - - return 0; -} - -MAD_EXPORT int -mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus) -{ - uint8_t *mad = umad_get_mad(umad); - ib_mad_addr_t *mad_addr; - ib_rpc_t rpc = {0}; - ib_portid_t rport; - int is_smi; - - if (!portid) { - if (!(mad_addr = umad_get_mad_addr(umad))) - return -1; - - memset(&rport, 0, sizeof(rport)); - - rport.lid = ntohs(mad_addr->lid); - rport.qp = ntohl(mad_addr->qpn); - rport.qkey = ntohl(mad_addr->qkey); - rport.sl = mad_addr->sl; - - portid = &rport; - } - - DEBUG("dest %s", portid2str(portid)); - - rpc.mgtclass = mad_get_field(mad, 0, IB_MAD_MGMTCLASS_F); - - rpc.method = mad_get_field(mad, 0, IB_MAD_METHOD_F); - if (rpc.method == IB_MAD_METHOD_SET) - rpc.method = IB_MAD_METHOD_GET; - if (rpc.method != IB_MAD_METHOD_SEND) - rpc.method |= IB_MAD_RESPONSE; - - rpc.attr.id = mad_get_field(mad, 0, IB_MAD_ATTRID_F); - rpc.attr.mod = mad_get_field(mad, 0, IB_MAD_ATTRMOD_F); - if (rpc.mgtclass == IB_SA_CLASS) - rpc.recsz = mad_get_field(mad, 0, IB_SA_ATTROFFS_F); - if (mad_is_vendor_range2(rpc.mgtclass)) - rpc.oui = mad_get_field(mad, 0, IB_VEND2_OUI_F); - - rpc.trid = mad_get_field64(mad, 0, IB_MAD_TRID_F); - - /* cleared by default: timeout, datasz, dataoffs, mkey, mask */ - - is_smi = rpc.mgtclass == IB_SMI_CLASS || - rpc.mgtclass == IB_SMI_DIRECT_CLASS; - - if (is_smi) - portid->qp = 0; - else if (!portid->qp) - portid->qp = 1; - - if (!portid->qkey && portid->qp == 1) - portid->qkey = IB_DEFAULT_QP1_QKEY; - - DEBUG("qp 0x%x class 0x%x method %d attr 0x%x mod 0x%x datasz %d off %d qkey %x", - portid->qp, rpc.mgtclass, rpc.method, rpc.attr.id, rpc.attr.mod, - rpc.datasz, rpc.dataoffs, portid->qkey); - - if (mad_build_pkt(umad, &rpc, portid, 0, 0) < 0) - return -1; - - if (ibdebug > 1) - xdump(stderr, "mad respond pkt\n", mad, IB_MAD_SIZE); - - if (umad_send(madrpc_portid(), mad_class_agent(rpc.mgtclass), umad, - IB_MAD_SIZE, rpc.timeout, 0) < 0) { - DEBUG("send failed; %m"); - return -1; - } - - return 0; -} - -MAD_EXPORT void * -mad_receive(void *umad, int timeout) -{ - void *mad = umad ? umad : umad_alloc(1, umad_size() + IB_MAD_SIZE); - int agent; - int length = IB_MAD_SIZE; - - if ((agent = umad_recv(madrpc_portid(), mad, - &length, timeout)) < 0) { - if (!umad) - umad_free(mad); - DEBUG("recv failed: %m"); - return 0; - } - - return mad; -} - -MAD_EXPORT void * -mad_alloc(void) -{ - return umad_alloc(1, umad_size() + IB_MAD_SIZE); -} - -MAD_EXPORT void -mad_free(void *umad) -{ - umad_free(umad); -} +/* + * Copyright (c) 2004,2005 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include +#include + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +int +mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data) +{ + uint8_t pktbuf[1024]; + void *umad = pktbuf; + + memset(pktbuf, 0, umad_size()); + + DEBUG("rmpp %p data %p", rmpp, data); + + if (mad_build_pkt(umad, rpc, dport, rmpp, data) < 0) + return 0; + + if (ibdebug) { + IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz); + xdump(stderr, "mad send data\n", + (char *)umad_get_mad(umad) + rpc->dataoffs, rpc->datasz); + } + + if (umad_send(madrpc_portid(), mad_class_agent(rpc->mgtclass), + umad, IB_MAD_SIZE, rpc->timeout, 0) < 0) { + IBWARN("send failed; %m"); + return -1; + } + + return 0; +} + +int +mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus) +{ + uint8_t *mad = umad_get_mad(umad); + ib_mad_addr_t *mad_addr; + ib_rpc_t rpc = {0}; + ib_portid_t rport; + int is_smi; + + if (!portid) { + if (!(mad_addr = umad_get_mad_addr(umad))) + return -1; + + memset(&rport, 0, sizeof(rport)); + + rport.lid = ntohs(mad_addr->lid); + rport.qp = ntohl(mad_addr->qpn); + rport.qkey = ntohl(mad_addr->qkey); + rport.sl = mad_addr->sl; + + portid = &rport; + } + + DEBUG("dest %s", portid2str(portid)); + + rpc.mgtclass = mad_get_field(mad, 0, IB_MAD_MGMTCLASS_F); + + rpc.method = mad_get_field(mad, 0, IB_MAD_METHOD_F); + if (rpc.method == IB_MAD_METHOD_SET) + rpc.method = IB_MAD_METHOD_GET; + if (rpc.method != IB_MAD_METHOD_SEND) + rpc.method |= IB_MAD_RESPONSE; + + rpc.attr.id = mad_get_field(mad, 0, IB_MAD_ATTRID_F); + rpc.attr.mod = mad_get_field(mad, 0, IB_MAD_ATTRMOD_F); + if (rpc.mgtclass == IB_SA_CLASS) + rpc.recsz = mad_get_field(mad, 0, IB_SA_ATTROFFS_F); + if (mad_is_vendor_range2(rpc.mgtclass)) + rpc.oui = mad_get_field(mad, 0, IB_VEND2_OUI_F); + + rpc.trid = mad_get_field64(mad, 0, IB_MAD_TRID_F); + + /* cleared by default: timeout, datasz, dataoffs, mkey, mask */ + + is_smi = rpc.mgtclass == IB_SMI_CLASS || + rpc.mgtclass == IB_SMI_DIRECT_CLASS; + + if (is_smi) + portid->qp = 0; + else if (!portid->qp) + portid->qp = 1; + + if (!portid->qkey && portid->qp == 1) + portid->qkey = IB_DEFAULT_QP1_QKEY; + + DEBUG("qp 0x%x class 0x%x method %d attr 0x%x mod 0x%x datasz %d off %d qkey %x", + portid->qp, rpc.mgtclass, rpc.method, rpc.attr.id, rpc.attr.mod, + rpc.datasz, rpc.dataoffs, portid->qkey); + + if (mad_build_pkt(umad, &rpc, portid, 0, 0) < 0) + return -1; + + if (ibdebug > 1) + xdump(stderr, "mad respond pkt\n", mad, IB_MAD_SIZE); + + if (umad_send(madrpc_portid(), mad_class_agent(rpc.mgtclass), umad, + IB_MAD_SIZE, rpc.timeout, 0) < 0) { + DEBUG("send failed; %m"); + return -1; + } + + return 0; +} + +void * +mad_receive(void *umad, int timeout) +{ + void *mad = umad ? umad : umad_alloc(1, umad_size() + IB_MAD_SIZE); + int agent; + int length = IB_MAD_SIZE; + + if ((agent = umad_recv(madrpc_portid(), mad, + &length, timeout)) < 0) { + if (!umad) + umad_free(mad); + DEBUG("recv failed: %m"); + return 0; + } + + return mad; +} + +void * +mad_alloc(void) +{ + return umad_alloc(1, umad_size() + IB_MAD_SIZE); +} + +void +mad_free(void *umad) +{ + umad_free(umad); +} diff --git a/trunk/ulp/libibmad/src/smp.c b/trunk/ulp/libibmad/src/smp.c index 6cadbb11..e872602b 100644 --- a/trunk/ulp/libibmad/src/smp.c +++ b/trunk/ulp/libibmad/src/smp.c @@ -1,124 +1,119 @@ -/* - * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#else -#include -#include -#include -#include -#endif - -#include - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -uint8_t * -smp_set_via(void *data, ib_portid_t *portid, unsigned attrid, unsigned mod, unsigned timeout, const void *srcport) -{ - ib_rpc_t rpc = {0}; - - DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid)); - if ((portid->lid <= 0) || - (portid->drpath.drslid == 0xffff) || - (portid->drpath.drdlid == 0xffff)) - rpc.mgtclass = IB_SMI_DIRECT_CLASS; /* direct SMI */ - else - rpc.mgtclass = IB_SMI_CLASS; /* Lid routed SMI */ - - rpc.method = IB_MAD_METHOD_SET; - rpc.attr.id = attrid; - rpc.attr.mod = mod; - rpc.timeout = timeout; - rpc.datasz = IB_SMP_DATA_SIZE; - rpc.dataoffs = IB_SMP_DATA_OFFS; - - portid->sl = 0; - portid->qp = 0; - - if (srcport) { - return mad_rpc(srcport, &rpc, portid, data, data); - } else { - return madrpc(&rpc, portid, data, data); - } -} - -MAD_EXPORT uint8_t * -smp_set(void *data, ib_portid_t *portid, unsigned attrid, unsigned mod, unsigned timeout) -{ - return smp_set_via(data, portid, attrid, mod, timeout, NULL); -} - -uint8_t * -smp_query_via(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod, - unsigned timeout, const void *srcport) -{ - ib_rpc_t rpc = {0}; - - DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid)); - rpc.method = IB_MAD_METHOD_GET; - rpc.attr.id = attrid; - rpc.attr.mod = mod; - rpc.timeout = timeout; - rpc.datasz = IB_SMP_DATA_SIZE; - rpc.dataoffs = IB_SMP_DATA_OFFS; - - if ((portid->lid <= 0) || - (portid->drpath.drslid == 0xffff) || - (portid->drpath.drdlid == 0xffff)) - rpc.mgtclass = IB_SMI_DIRECT_CLASS; /* direct SMI */ - else - rpc.mgtclass = IB_SMI_CLASS; /* Lid routed SMI */ - - portid->sl = 0; - portid->qp = 0; - - if (srcport) { - return mad_rpc(srcport, &rpc, portid, 0, rcvbuf); - } else { - return madrpc(&rpc, portid, 0, rcvbuf); - } -} - -MAD_EXPORT uint8_t * -smp_query(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod, - unsigned timeout) -{ - return smp_query_via(rcvbuf, portid, attrid, mod, timeout, NULL); -} +/* + * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +uint8_t * +smp_set_via(void *data, ib_portid_t *portid, unsigned attrid, unsigned mod, unsigned timeout, const void *srcport) +{ + ib_rpc_t rpc = {0}; + + DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid)); + if ((portid->lid <= 0) || + (portid->drpath.drslid == 0xffff) || + (portid->drpath.drdlid == 0xffff)) + rpc.mgtclass = IB_SMI_DIRECT_CLASS; /* direct SMI */ + else + rpc.mgtclass = IB_SMI_CLASS; /* Lid routed SMI */ + + rpc.method = IB_MAD_METHOD_SET; + rpc.attr.id = attrid; + rpc.attr.mod = mod; + rpc.timeout = timeout; + rpc.datasz = IB_SMP_DATA_SIZE; + rpc.dataoffs = IB_SMP_DATA_OFFS; + + portid->sl = 0; + portid->qp = 0; + + if (srcport) { + return mad_rpc(srcport, &rpc, portid, data, data); + } else { + return madrpc(&rpc, portid, data, data); + } +} + +uint8_t * +smp_set(void *data, ib_portid_t *portid, unsigned attrid, unsigned mod, unsigned timeout) +{ + return smp_set_via(data, portid, attrid, mod, timeout, NULL); +} + +uint8_t * +smp_query_via(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod, + unsigned timeout, const void *srcport) +{ + ib_rpc_t rpc = {0}; + + DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid)); + rpc.method = IB_MAD_METHOD_GET; + rpc.attr.id = attrid; + rpc.attr.mod = mod; + rpc.timeout = timeout; + rpc.datasz = IB_SMP_DATA_SIZE; + rpc.dataoffs = IB_SMP_DATA_OFFS; + + if ((portid->lid <= 0) || + (portid->drpath.drslid == 0xffff) || + (portid->drpath.drdlid == 0xffff)) + rpc.mgtclass = IB_SMI_DIRECT_CLASS; /* direct SMI */ + else + rpc.mgtclass = IB_SMI_CLASS; /* Lid routed SMI */ + + portid->sl = 0; + portid->qp = 0; + + if (srcport) { + return mad_rpc(srcport, &rpc, portid, 0, rcvbuf); + } else { + return madrpc(&rpc, portid, 0, rcvbuf); + } +} + +uint8_t * +smp_query(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod, + unsigned timeout) +{ + return smp_query_via(rcvbuf, portid, attrid, mod, timeout, NULL); +} diff --git a/trunk/ulp/libibmad/src/vendor.c b/trunk/ulp/libibmad/src/vendor.c index cc2357b5..7928a581 100644 --- a/trunk/ulp/libibmad/src/vendor.c +++ b/trunk/ulp/libibmad/src/vendor.c @@ -1,100 +1,95 @@ -/* - * Copyright (c) 2004,2005 Voltaire Inc. All rights reserved. - * - * This software is available to you under the OpenFabrics.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#if HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#else -#include -#include -#include -#include -#endif - -#include - -#undef DEBUG -#define DEBUG if (ibdebug) IBWARN - -static inline int -response_expected(int method) -{ - return method == IB_MAD_METHOD_GET || - method == IB_MAD_METHOD_SET || - method == IB_MAD_METHOD_TRAP; -} - -MAD_EXPORT uint8_t * -ib_vendor_call(void *data, ib_portid_t *portid, ib_vendor_call_t *call) -{ - ib_rpc_t rpc = {0}; - int range1 = 0, resp_expected; - - DEBUG("route %s data %p", portid2str(portid), data); - if (portid->lid <= 0) - return 0; /* no direct SMI */ - - if (!(range1 = mad_is_vendor_range1(call->mgmt_class)) && - !(mad_is_vendor_range2(call->mgmt_class))) - return 0; - - resp_expected = response_expected(call->method); - - rpc.mgtclass = call->mgmt_class; - - rpc.method = call->method; - rpc.attr.id = call->attrid; - rpc.attr.mod = call->mod; - rpc.timeout = resp_expected ? call->timeout : 0; - rpc.datasz = range1 ? IB_VENDOR_RANGE1_DATA_SIZE : IB_VENDOR_RANGE2_DATA_SIZE; - rpc.dataoffs = range1 ? IB_VENDOR_RANGE1_DATA_OFFS : IB_VENDOR_RANGE2_DATA_OFFS; - - if (!range1) - rpc.oui = call->oui; - - DEBUG("class 0x%x method 0x%x attr 0x%x mod 0x%x datasz %d off %d res_ex %d", - rpc.mgtclass, rpc.method, rpc.attr.id, rpc.attr.mod, - rpc.datasz, rpc.dataoffs, resp_expected); - - portid->qp = 1; - if (!portid->qkey) - portid->qkey = IB_DEFAULT_QP1_QKEY; - - if (resp_expected) - return madrpc_rmpp(&rpc, portid, 0, data); /* FIXME: no RMPP for now */ - - return mad_send(&rpc, portid, 0, data) < 0 ? 0 : data; /* FIXME: no RMPP for now */ -} +/* + * Copyright (c) 2004,2005 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include + +#undef DEBUG +#define DEBUG if (ibdebug) IBWARN + +static inline int +response_expected(int method) +{ + return method == IB_MAD_METHOD_GET || + method == IB_MAD_METHOD_SET || + method == IB_MAD_METHOD_TRAP; +} + +uint8_t * +ib_vendor_call(void *data, ib_portid_t *portid, ib_vendor_call_t *call) +{ + ib_rpc_t rpc = {0}; + int range1 = 0, resp_expected; + + DEBUG("route %s data %p", portid2str(portid), data); + if (portid->lid <= 0) + return 0; /* no direct SMI */ + + if (!(range1 = mad_is_vendor_range1(call->mgmt_class)) && + !(mad_is_vendor_range2(call->mgmt_class))) + return 0; + + resp_expected = response_expected(call->method); + + rpc.mgtclass = call->mgmt_class; + + rpc.method = call->method; + rpc.attr.id = call->attrid; + rpc.attr.mod = call->mod; + rpc.timeout = resp_expected ? call->timeout : 0; + rpc.datasz = range1 ? IB_VENDOR_RANGE1_DATA_SIZE : IB_VENDOR_RANGE2_DATA_SIZE; + rpc.dataoffs = range1 ? IB_VENDOR_RANGE1_DATA_OFFS : IB_VENDOR_RANGE2_DATA_OFFS; + + if (!range1) + rpc.oui = call->oui; + + DEBUG("class 0x%x method 0x%x attr 0x%x mod 0x%x datasz %d off %d res_ex %d", + rpc.mgtclass, rpc.method, rpc.attr.id, rpc.attr.mod, + rpc.datasz, rpc.dataoffs, resp_expected); + + portid->qp = 1; + if (!portid->qkey) + portid->qkey = IB_DEFAULT_QP1_QKEY; + + if (resp_expected) + return madrpc_rmpp(&rpc, portid, 0, data); /* FIXME: no RMPP for now */ + + return mad_send(&rpc, portid, 0, data) < 0 ? 0 : data; /* FIXME: no RMPP for now */ +} -- 2.46.0