Discussion:
PATCH[1/6] Windows port of libibmad - mad.h
(too old to reply)
Davis, Arlin R
2008-12-18 23:37:57 UTC
Permalink
Port of libibmad to windows. Dependencies on libibumad port and complib (in lieu of libcommon). Removed dependency on libibcommon.

Intent is to allow common mad code base for Windows and Linux to simplify maintainablity across OFED and WinOF. This patch set was built and tested on Windows and built on Linux (not tested yet).

Patches separated as follow:

1/6 - mad.h
2/6 - dump.c
3/6 - fields.c
4/6 - gs.c, mad.c, portid.c, register.c, resolve.c
5/6 - rpc.c, sa.c, serv.c, smp.c, vendor.c
6/6 - new files for windows: dirs, src/Sources, src/ibmad_export.def, src/ibmad_exports.src, ibmad_main.cpp

Signed-off by: Arlin Davis <***@ichips.intel.com>

diff -aur libibmad-1.2.2/include/infiniband/mad.h libibmad/include/infiniband/mad.h
--- libibmad-1.2.2/include/infiniband/mad.h 2008-08-31 07:15:05.000000000 -0700
+++ libibmad/include/infiniband/mad.h 2008-12-17 17:02:54.873046600 -0800
@@ -33,8 +33,10 @@
#ifndef _MAD_H_
#define _MAD_H_

-#include <stdint.h>
-#include <string.h>
+/* use complib for portability */
+#include <complib/cl_types.h>
+#include <complib/cl_byteswap.h>
+#include <complib/cl_debug.h>

#ifdef __cplusplus
# define BEGIN_C_DECLS extern "C" {
@@ -46,8 +48,14 @@

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 0xfe80000000000000llu
+#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL
#define IB_DEFAULT_QP1_QKEY 0x80010000

#define IB_MAD_SIZE 256
@@ -620,10 +628,10 @@
/******************************************************************************/

/* portid.c */
-char * portid2str(ib_portid_t *portid);
-int portid2portnum(ib_portid_t *portid);
-int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid);
-char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size);
+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)
@@ -639,77 +647,49 @@
/* fields.c */
extern ib_field_t ib_mad_f[];

-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+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);
+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 */
-static inline uint32_t
-mad_get_field(void *buf, int base_offs, int field)
-{
- return _get_field(buf, base_offs, ib_mad_f + field);
-}
-
-static inline void
-mad_set_field(void *buf, int base_offs, int field, uint32_t val)
-{
- _set_field(buf, base_offs, ib_mad_f + field, val);
-}
-
+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 */
-static inline uint64_t
-mad_get_field64(void *buf, int base_offs, int field)
-{
- return _get_field64(buf, base_offs, ib_mad_f + field);
-}
-
-static inline void
-mad_set_field64(void *buf, int base_offs, int field, uint64_t val)
-{
- _set_field64(buf, base_offs, ib_mad_f + field, val);
-}
-
-static inline void
-mad_set_array(void *buf, int base_offs, int field, void *val)
-{
- _set_array(buf, base_offs, ib_mad_f + field, val);
-}
-
-static inline 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);
-void mad_encode_field(uint8_t *buf, int field, void *val);
-void * mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data);
-uint64_t mad_trid(void);
-int mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data);
+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 */
-int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version);
-int mad_register_client(int mgmt, uint8_t rmpp_version);
-int mad_register_server(int mgmt, uint8_t rmpp_version,
- long method_mask[16/sizeof(long)],
- uint32_t class_oui);
-int mad_class_agent(int mgmt);
-int mad_agent_class(int agent);
+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 */
-int mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp,
- void *data);
-void * mad_receive(void *umad, int timeout);
-int mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus);
-void * mad_alloc(void);
-void mad_free(void *umad);
+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 */
-uint8_t *ib_vendor_call(void *data, ib_portid_t *portid,
- ib_vendor_call_t *call);
+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)
@@ -718,38 +698,41 @@
}

static inline int
-mad_is_vendor_range2(int mgmt)
+mad_is_vendor_range2(int mgmt)
{
return mgmt >= 0x30 && mgmt <= 0x4f;
}

/* rpc.c */
-int madrpc_portid(void);
-int madrpc_set_retries(int retries);
-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,
+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);
-void madrpc_init(char *dev_name, int dev_port, int *mgmt_classes,
- int num_classes);
-void madrpc_save_mad(void *madbuf, int len);
-void madrpc_lock(void);
-void madrpc_unlock(void);
-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 */
-uint8_t * smp_query(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
- unsigned timeout);
-uint8_t * smp_set(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
- unsigned timeout);
+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,
@@ -786,9 +769,9 @@
unsigned timeout);
uint8_t * sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid,
ib_sa_call_t *sa, unsigned timeout);
-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,
+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 *
@@ -805,38 +788,38 @@
}

/* resolve.c */
-int ib_resolve_smlid(ib_portid_t *sm_id, int timeout);
-int ib_resolve_guid(ib_portid_t *portid, uint64_t *guid,
- ib_portid_t *sm_id, int timeout);
-int ib_resolve_portid_str(ib_portid_t *portid, char *addr_str,
- int dest_type, ib_portid_t *sm_id);
-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);
+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 */
-uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port,
unsigned mask, unsigned timeout);
-uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port,
unsigned mask, unsigned timeout);
-uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port,
+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,
@@ -855,7 +838,7 @@
unsigned timeout, const void *srcport);
/* dump.c */
ib_mad_dump_fn
- mad_dump_int, mad_dump_uint, mad_dump_hex, mad_dump_rhex,
+ 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,
@@ -900,6 +883,34 @@

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_ */
Sean Hefty
2008-12-19 00:10:13 UTC
Permalink
Post by Davis, Arlin R
Port of libibmad to windows. Dependencies on libibumad port and complib (in
lieu of libcommon). Removed dependency on libibcommon.
Intent is to allow common mad code base for Windows and Linux to simplify
maintainablity across OFED and WinOF. This patch set was built and tested on
Windows and built on Linux (not tested yet).
Thanks for posting this. Seeing the actual changes helps understand the impact
better.

Note that the libib_u_mad implementations are not shared. Only the interface is
maintained to simplify porting.

Looking at the changes, do the management developers think that it makes sense
to share the libibmad implementation, or should separate implementations be
maintained, similar to libibumad? If the implementations are not shared, can
the Linux side treat the API as an external interface, rather than a private
interface?
Post by Davis, Arlin R
+#if defined(_WIN32) || defined(_WIN64)
+#define MAD_EXPORT __declspec(dllexport)
+#else
+#define MAD_EXPORT extern
I don't know that 'extern' is appropriate here.
Post by Davis, Arlin R
+#endif
+
#define IB_SUBNET_PATH_HOPS_MAX 64
-#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000llu
+#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL
#define IB_DEFAULT_QP1_QKEY 0x80010000
#define IB_MAD_SIZE 256
@@ -620,10 +628,10 @@
/******************************************************************************
/
/* portid.c */
-char * portid2str(ib_portid_t *portid);
-int portid2portnum(ib_portid_t *portid);
-int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int
drdlid);
-char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size);
+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)
@@ -639,77 +647,49 @@
/* fields.c */
extern ib_field_t ib_mad_f[];
-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+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);
+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);
Are these really the functions that should be exported from the library or in
the header file? (I'm probably missing some history here.)

- Sean
Hal Rosenstock
2008-12-19 18:56:56 UTC
Permalink
Post by Sean Hefty
Post by Davis, Arlin R
Port of libibmad to windows. Dependencies on libibumad port and complib (in
lieu of libcommon). Removed dependency on libibcommon.
Intent is to allow common mad code base for Windows and Linux to simplify
maintainablity across OFED and WinOF. This patch set was built and tested on
Windows and built on Linux (not tested yet).
Thanks for posting this. Seeing the actual changes helps understand the impact
better.
Note that the libib_u_mad implementations are not shared. Only the interface is
maintained to simplify porting.
Looking at the changes, do the management developers think that it makes sense
to share the libibmad implementation, or should separate implementations be
maintained, similar to libibumad? If the implementations are not shared, can
the Linux side treat the API as an external interface, rather than a private
interface?
Post by Davis, Arlin R
+#if defined(_WIN32) || defined(_WIN64)
+#define MAD_EXPORT __declspec(dllexport)
+#else
+#define MAD_EXPORT extern
I don't know that 'extern' is appropriate here.
Post by Davis, Arlin R
+#endif
+
#define IB_SUBNET_PATH_HOPS_MAX 64
-#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000llu
+#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL
#define IB_DEFAULT_QP1_QKEY 0x80010000
#define IB_MAD_SIZE 256
@@ -620,10 +628,10 @@
/******************************************************************************
/
/* portid.c */
-char * portid2str(ib_portid_t *portid);
-int portid2portnum(ib_portid_t *portid);
-int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int
drdlid);
-char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size);
+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)
@@ -639,77 +647,49 @@
/* fields.c */
extern ib_field_t ib_mad_f[];
-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+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);
+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);
Are these really the functions that should be exported from the library or in
the header file? (I'm probably missing some history here.)
For one thing, mad.h currently inlines a number of functions used by
(diag) applications which invoke these.

I think it's largely historical; libibmad is the most non standard of
the management libraries in terms of the conventions and a cleanup
hasn't yet occurred.

-- Hal
Post by Sean Hefty
- Sean
_______________________________________________
ofw mailing list
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw
Sean Hefty
2008-12-19 19:00:04 UTC
Permalink
Post by Hal Rosenstock
Post by Sean Hefty
Post by Davis, Arlin R
-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+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);
+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);
Are these really the functions that should be exported from the library or in
the header file? (I'm probably missing some history here.)
For one thing, mad.h currently inlines a number of functions used by
(diag) applications which invoke these.
I did see that. I was thinking more of renaming _set_field to mad_set_field and
removing the existing implementation of mad_set_field.

- Sean
Sasha Khapyorsky
2008-12-21 21:00:50 UTC
Permalink
Post by Sean Hefty
Looking at the changes, do the management developers think that it makes sense
to share the libibmad implementation, or should separate implementations be
maintained, similar to libibumad? If the implementations are not shared, can
the Linux side treat the API as an external interface, rather than a private
interface?
I think libibmad implementations could be shared - unlike libibumad it is
almost system independent.

And again, it would be really nice if such porting will not introduce a
lot of changes, #ifdef WIN, etc.. C99 stuff looks like a problem for me
(could this be solved somehow with VC?), the rest seems doable.

Sasha
Post by Sean Hefty
Post by Davis, Arlin R
+#if defined(_WIN32) || defined(_WIN64)
+#define MAD_EXPORT __declspec(dllexport)
+#else
+#define MAD_EXPORT extern
I don't know that 'extern' is appropriate here.
Post by Davis, Arlin R
+#endif
+
#define IB_SUBNET_PATH_HOPS_MAX 64
-#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000llu
+#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL
#define IB_DEFAULT_QP1_QKEY 0x80010000
#define IB_MAD_SIZE 256
@@ -620,10 +628,10 @@
/******************************************************************************
/
/* portid.c */
-char * portid2str(ib_portid_t *portid);
-int portid2portnum(ib_portid_t *portid);
-int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int
drdlid);
-char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size);
+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)
@@ -639,77 +647,49 @@
/* fields.c */
extern ib_field_t ib_mad_f[];
-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+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);
+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);
Are these really the functions that should be exported from the library or in
the header file? (I'm probably missing some history here.)
- Sean
_______________________________________________
general mailing list
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general
To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
Ira Weiny
2008-12-19 01:21:53 UTC
Permalink
On Thu, 18 Dec 2008 15:37:57 -0800
Post by Davis, Arlin R
Port of libibmad to windows. Dependencies on libibumad port and complib (in lieu of libcommon). Removed dependency on libibcommon.
Intent is to allow common mad code base for Windows and Linux to simplify maintainablity across OFED and WinOF. This patch set was built and tested on Windows and built on Linux (not tested yet).
1/6 - mad.h
2/6 - dump.c
3/6 - fields.c
4/6 - gs.c, mad.c, portid.c, register.c, resolve.c
5/6 - rpc.c, sa.c, serv.c, smp.c, vendor.c
6/6 - new files for windows: dirs, src/Sources, src/ibmad_export.def, src/ibmad_exports.src, ibmad_main.cpp
diff -aur libibmad-1.2.2/include/infiniband/mad.h libibmad/include/infiniband/mad.h
--- libibmad-1.2.2/include/infiniband/mad.h 2008-08-31 07:15:05.000000000 -0700
+++ libibmad/include/infiniband/mad.h 2008-12-17 17:02:54.873046600 -0800
@@ -33,8 +33,10 @@
#ifndef _MAD_H_
#define _MAD_H_
-#include <stdint.h>
-#include <string.h>
+/* use complib for portability */
+#include <complib/cl_types.h>
+#include <complib/cl_byteswap.h>
+#include <complib/cl_debug.h>
#ifdef __cplusplus
# define BEGIN_C_DECLS extern "C" {
@@ -46,8 +48,14 @@
BEGIN_C_DECLS
+#if defined(_WIN32) || defined(_WIN64)
+#define MAD_EXPORT __declspec(dllexport)
+#else
+#define MAD_EXPORT extern
+#endif
+
Could this be put in the cl_ headers somewhere and be called CL_EXPORT
or CL_EXTERN (my preference if this is going to cause functions on the
Linux side to be declared extern)?
Post by Davis, Arlin R
#define IB_SUBNET_PATH_HOPS_MAX 64
-#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000llu
+#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL
#define IB_DEFAULT_QP1_QKEY 0x80010000
#define IB_MAD_SIZE 256
@@ -620,10 +628,10 @@
/******************************************************************************/
/* portid.c */
-char * portid2str(ib_portid_t *portid);
-int portid2portnum(ib_portid_t *portid);
-int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid);
-char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size);
+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)
@@ -639,77 +647,49 @@
/* fields.c */
extern ib_field_t ib_mad_f[];
-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+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);
+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 */
-static inline uint32_t
-mad_get_field(void *buf, int base_offs, int field)
-{
- return _get_field(buf, base_offs, ib_mad_f + field);
-}
-
-static inline void
-mad_set_field(void *buf, int base_offs, int field, uint32_t val)
-{
- _set_field(buf, base_offs, ib_mad_f + field, val);
-}
-
+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 */
-static inline uint64_t
-mad_get_field64(void *buf, int base_offs, int field)
-{
- return _get_field64(buf, base_offs, ib_mad_f + field);
-}
-
-static inline void
-mad_set_field64(void *buf, int base_offs, int field, uint64_t val)
-{
- _set_field64(buf, base_offs, ib_mad_f + field, val);
-}
-
-static inline void
-mad_set_array(void *buf, int base_offs, int field, void *val)
-{
- _set_array(buf, base_offs, ib_mad_f + field, val);
-}
-
-static inline 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);
-void mad_encode_field(uint8_t *buf, int field, void *val);
-void * mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data);
-uint64_t mad_trid(void);
-int mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data);
+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 */
-int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version);
-int mad_register_client(int mgmt, uint8_t rmpp_version);
-int mad_register_server(int mgmt, uint8_t rmpp_version,
- long method_mask[16/sizeof(long)],
- uint32_t class_oui);
-int mad_class_agent(int mgmt);
-int mad_agent_class(int agent);
+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 */
-int mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp,
- void *data);
-void * mad_receive(void *umad, int timeout);
-int mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus);
-void * mad_alloc(void);
-void mad_free(void *umad);
+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 */
-uint8_t *ib_vendor_call(void *data, ib_portid_t *portid,
- ib_vendor_call_t *call);
+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)
@@ -718,38 +698,41 @@
}
static inline int
-mad_is_vendor_range2(int mgmt)
+mad_is_vendor_range2(int mgmt)
{
return mgmt >= 0x30 && mgmt <= 0x4f;
}
/* rpc.c */
-int madrpc_portid(void);
-int madrpc_set_retries(int retries);
-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,
+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);
-void madrpc_init(char *dev_name, int dev_port, int *mgmt_classes,
- int num_classes);
-void madrpc_save_mad(void *madbuf, int len);
-void madrpc_lock(void);
-void madrpc_unlock(void);
-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 */
-uint8_t * smp_query(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
- unsigned timeout);
-uint8_t * smp_set(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
- unsigned timeout);
+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,
@@ -786,9 +769,9 @@
unsigned timeout);
uint8_t * sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid,
ib_sa_call_t *sa, unsigned timeout);
-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,
+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 *
@@ -805,38 +788,38 @@
}
/* resolve.c */
-int ib_resolve_smlid(ib_portid_t *sm_id, int timeout);
-int ib_resolve_guid(ib_portid_t *portid, uint64_t *guid,
- ib_portid_t *sm_id, int timeout);
-int ib_resolve_portid_str(ib_portid_t *portid, char *addr_str,
- int dest_type, ib_portid_t *sm_id);
-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);
+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 */
-uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port,
unsigned mask, unsigned timeout);
-uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port,
unsigned mask, unsigned timeout);
-uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port,
+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,
@@ -855,7 +838,7 @@
unsigned timeout, const void *srcport);
/* dump.c */
ib_mad_dump_fn
- mad_dump_int, mad_dump_uint, mad_dump_hex, mad_dump_rhex,
+ 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,
Is this a mistake? Should it be:

MAD_EXPORT ib_mad_dump_fn
...

Ira
Post by Davis, Arlin R
@@ -900,6 +883,34 @@
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_ */
_______________________________________________
general mailing list
http:// lists.openfabrics.org/cgi-bin/mailman/listinfo/general
To unsubscribe, please visit http:// openib.org/mailman/listinfo/openib-general
Sean Hefty
2008-12-19 01:26:50 UTC
Permalink
Post by Ira Weiny
Could this be put in the cl_ headers somewhere and be called CL_EXPORT
or CL_EXTERN (my preference if this is going to cause functions on the
Linux side to be declared extern)?
That's a good point, there's already a CL_EXPORT that's defined.

- Sean
Davis, Arlin R
2008-12-19 03:01:50 UTC
Permalink
Post by Davis, Arlin R
Post by Davis, Arlin R
/* dump.c */
ib_mad_dump_fn
- mad_dump_int, mad_dump_uint, mad_dump_hex, mad_dump_rhex,
+ MAD_EXPORT mad_dump_int, mad_dump_uint, mad_dump_hex,
mad_dump_rhex,
Post by Davis, Arlin R
mad_dump_bitfield, mad_dump_array, mad_dump_string,
mad_dump_linkwidth, mad_dump_linkwidthsup, mad_dump_linkwidthen,
mad_dump_linkdowndefstate,
MAD_EXPORT ib_mad_dump_fn
Yes, good catch.
Sasha Khapyorsky
2008-12-21 20:51:24 UTC
Permalink
Hi Arlin,
Post by Davis, Arlin R
Port of libibmad to windows. Dependencies on libibumad port and complib (in lieu of libcommon). Removed dependency on libibcommon.
Intent is to allow common mad code base for Windows and Linux to simplify maintainablity across OFED and WinOF. This patch set was built and tested on Windows and built on Linux (not tested yet).
1/6 - mad.h
2/6 - dump.c
3/6 - fields.c
4/6 - gs.c, mad.c, portid.c, register.c, resolve.c
5/6 - rpc.c, sa.c, serv.c, smp.c, vendor.c
6/6 - new files for windows: dirs, src/Sources, src/ibmad_export.def, src/ibmad_exports.src, ibmad_main.cpp
What is the purpose of those patches? RFC? Inclusion to a main stream?

Then applying this patch I'm getting:

warning: squelched 20 whitespace errors
warning: 25 lines applied after fixing whitespace errors.

, and it even doesn't compile (I have complib installed in this case):

./include/infiniband/mad.h:37:30: error: complib/cl_types.h: No such file or directory
./include/infiniband/mad.h:38:33: error: complib/cl_byteswap.h: No such file or directory
./include/infiniband/mad.h:39:30: error: complib/cl_debug.h: No such file or directory

Some porting comments are below.
Post by Davis, Arlin R
diff -aur libibmad-1.2.2/include/infiniband/mad.h libibmad/include/infiniband/mad.h
--- libibmad-1.2.2/include/infiniband/mad.h 2008-08-31 07:15:05.000000000 -0700
+++ libibmad/include/infiniband/mad.h 2008-12-17 17:02:54.873046600 -0800
@@ -33,8 +33,10 @@
#ifndef _MAD_H_
#define _MAD_H_
-#include <stdint.h>
-#include <string.h>
+/* use complib for portability */
+#include <complib/cl_types.h>
+#include <complib/cl_byteswap.h>
+#include <complib/cl_debug.h>
Currently libibmad doesn't depend from complib. It would be really nice
to not new dependencies (normally we build libibmad before complib,
which is part of OpenSM).

Also what is wrong with <string.h> and <stdint.h> (or <inttypes.h>) in
Win?
Post by Davis, Arlin R
#ifdef __cplusplus
# define BEGIN_C_DECLS extern "C" {
@@ -46,8 +48,14 @@
BEGIN_C_DECLS
+#if defined(_WIN32) || defined(_WIN64)
+#define MAD_EXPORT __declspec(dllexport)
+#else
+#define MAD_EXPORT extern
+#endif
+
I wrote in another email. It would be nice to minimize a number of
needed changes and number of #ifdef introduced.

If we will add "extern" keyword for exported symbols and somewhere in
windows-specific header file it will be redefined as

#define extern __declspec(dllexport)

? Could this help?
Post by Davis, Arlin R
#define IB_SUBNET_PATH_HOPS_MAX 64
-#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000llu
+#define IB_DEFAULT_SUBN_PREFIX 0xfe80000000000000ULL
#define IB_DEFAULT_QP1_QKEY 0x80010000
#define IB_MAD_SIZE 256
@@ -620,10 +628,10 @@
/******************************************************************************/
/* portid.c */
-char * portid2str(ib_portid_t *portid);
-int portid2portnum(ib_portid_t *portid);
-int str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid);
-char * drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size);
+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)
@@ -639,77 +647,49 @@
/* fields.c */
extern ib_field_t ib_mad_f[];
-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
What is the change here? Maybe whitespaces which were added/stripped by
mailer, but I don't see this.
Post by Davis, Arlin R
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);
+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 */
-static inline uint32_t
-mad_get_field(void *buf, int base_offs, int field)
-{
- return _get_field(buf, base_offs, ib_mad_f + field);
-}
-
-static inline void
-mad_set_field(void *buf, int base_offs, int field, uint32_t val)
-{
- _set_field(buf, base_offs, ib_mad_f + field, val);
-}
-
+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);
Windows don't like "inline"?

Maybe we just need to strip _set/get_field*() functions?

Sasha
Post by Davis, Arlin R
/* field must be byte aligned */
-static inline uint64_t
-mad_get_field64(void *buf, int base_offs, int field)
-{
- return _get_field64(buf, base_offs, ib_mad_f + field);
-}
-
-static inline void
-mad_set_field64(void *buf, int base_offs, int field, uint64_t val)
-{
- _set_field64(buf, base_offs, ib_mad_f + field, val);
-}
-
-static inline void
-mad_set_array(void *buf, int base_offs, int field, void *val)
-{
- _set_array(buf, base_offs, ib_mad_f + field, val);
-}
-
-static inline 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);
-void mad_encode_field(uint8_t *buf, int field, void *val);
-void * mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data);
-uint64_t mad_trid(void);
-int mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data);
+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 */
-int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version);
-int mad_register_client(int mgmt, uint8_t rmpp_version);
-int mad_register_server(int mgmt, uint8_t rmpp_version,
- long method_mask[16/sizeof(long)],
- uint32_t class_oui);
-int mad_class_agent(int mgmt);
-int mad_agent_class(int agent);
+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 */
-int mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp,
- void *data);
-void * mad_receive(void *umad, int timeout);
-int mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus);
-void * mad_alloc(void);
-void mad_free(void *umad);
+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 */
-uint8_t *ib_vendor_call(void *data, ib_portid_t *portid,
- ib_vendor_call_t *call);
+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)
@@ -718,38 +698,41 @@
}
static inline int
-mad_is_vendor_range2(int mgmt)
+mad_is_vendor_range2(int mgmt)
{
return mgmt >= 0x30 && mgmt <= 0x4f;
}
/* rpc.c */
-int madrpc_portid(void);
-int madrpc_set_retries(int retries);
-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,
+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);
-void madrpc_init(char *dev_name, int dev_port, int *mgmt_classes,
- int num_classes);
-void madrpc_save_mad(void *madbuf, int len);
-void madrpc_lock(void);
-void madrpc_unlock(void);
-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 */
-uint8_t * smp_query(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
- unsigned timeout);
-uint8_t * smp_set(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
- unsigned timeout);
+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,
@@ -786,9 +769,9 @@
unsigned timeout);
uint8_t * sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid,
ib_sa_call_t *sa, unsigned timeout);
-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,
+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 *
@@ -805,38 +788,38 @@
}
/* resolve.c */
-int ib_resolve_smlid(ib_portid_t *sm_id, int timeout);
-int ib_resolve_guid(ib_portid_t *portid, uint64_t *guid,
- ib_portid_t *sm_id, int timeout);
-int ib_resolve_portid_str(ib_portid_t *portid, char *addr_str,
- int dest_type, ib_portid_t *sm_id);
-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);
+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 */
-uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port,
unsigned mask, unsigned timeout);
-uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port,
unsigned mask, unsigned timeout);
-uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port,
+MAD_EXPORT uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port,
unsigned timeout);
-uint8_t *port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port,
+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,
@@ -855,7 +838,7 @@
unsigned timeout, const void *srcport);
/* dump.c */
ib_mad_dump_fn
- mad_dump_int, mad_dump_uint, mad_dump_hex, mad_dump_rhex,
+ 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,
@@ -900,6 +883,34 @@
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_ */
_______________________________________________
general mailing list
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general
To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
Sean Hefty
2008-12-23 06:44:35 UTC
Permalink
Post by Sasha Khapyorsky
What is the purpose of those patches? RFC? Inclusion to a main stream?
The goal is inclusion to the mainline, but giving a more concrete view of the
changes invovled.
Post by Sasha Khapyorsky
Post by Davis, Arlin R
diff -aur libibmad-1.2.2/include/infiniband/mad.h
libibmad/include/infiniband/mad.h
Post by Davis, Arlin R
--- libibmad-1.2.2/include/infiniband/mad.h 2008-08-31 07:15:05.000000000 -
0700
Post by Davis, Arlin R
+++ libibmad/include/infiniband/mad.h 2008-12-17 17:02:54.873046600 -0800
@@ -33,8 +33,10 @@
#ifndef _MAD_H_
#define _MAD_H_
-#include <stdint.h>
-#include <string.h>
+/* use complib for portability */
+#include <complib/cl_types.h>
+#include <complib/cl_byteswap.h>
+#include <complib/cl_debug.h>
Currently libibmad doesn't depend from complib. It would be really nice
to not new dependencies (normally we build libibmad before complib,
which is part of OpenSM).
The management stack does depend on complib, so I'm not sure that we buy much by
avoiding this dependency. To avoid it, we need an alternate solution for
problems that complib is alreading solving. (Arlin wrote these patches, so my
list may be off or incomplete.)

cl_types.h - provides the definitions for uint32_t and similar definitions
cl_byteswap.h - provides ntohll typdef
cl_debug - added cl_msg_out and CL_ASSERT defs
Post by Sasha Khapyorsky
I wrote in another email. It would be nice to minimize a number of
needed changes and number of #ifdef introduced.
Use of complib is probably the best alternative to minimizing #ifdefs.
Post by Sasha Khapyorsky
If we will add "extern" keyword for exported symbols and somewhere in
windows-specific header file it will be redefined as
#define extern __declspec(dllexport)
I don't think we want to get into redefining keywords.
Post by Sasha Khapyorsky
Post by Davis, Arlin R
-void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
+void _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
What is the change here? Maybe whitespaces which were added/stripped by
mailer, but I don't see this.
It looks like the whitespace was changed from a tab to a space, but you removed
these anyway.
Post by Sasha Khapyorsky
Post by Davis, Arlin R
+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);
Windows don't like "inline"?
The compiler doesn't allow it in the header file.

- Sean
Sean Hefty
2008-12-24 06:20:20 UTC
Permalink
Post by Sean Hefty
Post by Sasha Khapyorsky
Windows don't like "inline"?
The compiler doesn't allow it in the header file.
Not even static inline? Inline functions in header should all be
static inline or extern inline to avoid comdefs..
I'm wrong. I thought this was the problem, but it's more likely that the issue
was that the _set_field type calls weren't exported. So trying to make
mad_set_field inline failed, since all it did was call _set_field.

- Sean

Continue reading on narkive:
Loading...