[ofw] Re: [ofa-general] PATCH[1/6] Windows port of libibmad - mad.h

Ira Weiny weiny2 at llnl.gov
Thu Dec 18 17:21:53 PST 2008


On Thu, 18 Dec 2008 15:37:57 -0800
"Davis, Arlin R" <arlin.r.davis at intel.com> wrote:

> 
> 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 <ardavis at 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
> +

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)?


>  #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


> @@ -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
> general at lists.openfabrics.org
> http:// lists.openfabrics.org/cgi-bin/mailman/listinfo/general
> 
> To unsubscribe, please visit http:// openib.org/mailman/listinfo/openib-general
> 



More information about the ofw mailing list