[ofa-general] [PATCH] libibmad: remove hidden _set/_get_field*() API

Sasha Khapyorsky sashak at voltaire.com
Sun Dec 21 14:05:20 PST 2008


Remove hidden _set/_get_field*() API - instead export and use
mad_set/get_field*() API directly.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---

On 11:00 Fri 19 Dec     , Sean Hefty wrote:
> 
> 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.

Ok, let's just do it.

Sasha

 libibmad/include/infiniband/mad.h |   93 ++++-------------------
 libibmad/src/dump.c               |   51 ------------
 libibmad/src/fields.c             |  156 +++++++++++++++++++++++++++++++++---
 libibmad/src/libibmad.map         |   20 ++---
 libibmad/src/mad.c                |   40 ----------
 5 files changed, 166 insertions(+), 194 deletions(-)

diff --git a/libibmad/include/infiniband/mad.h b/libibmad/include/infiniband/mad.h
index c2ad148..fd0deff 100644
--- a/libibmad/include/infiniband/mad.h
+++ b/libibmad/include/infiniband/mad.h
@@ -637,58 +637,23 @@ ib_portid_set(ib_portid_t *portid, int lid, int qp, int qkey)
 }
 
 /* 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 */
-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);
-}
-
+uint32_t mad_get_field(void *buf, int base_offs, int field);
+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);
-}
+uint64_t mad_get_field64(void *buf, int base_offs, int field);
+void mad_set_field64(void *buf, int base_offs, int field, uint64_t val);
+void mad_set_array(void *buf, int base_offs, int field, void *val);
+void mad_get_array(void *buf, int base_offs, int field, void *val);
+void mad_decode_field(uint8_t *buf, int field, void *val);
+void mad_encode_field(uint8_t *buf, int field, void *val);
+int mad_print_field(int field, const char *name, void *val);
+char *mad_dump_field(int field, char *buf, int bufsz, void *val);
+char *mad_dump_val(int field, char *buf, int bufsz, void *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);
+/* mad.c */
+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);
+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);
@@ -868,36 +833,6 @@ ib_mad_dump_fn
 	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;
 
 END_C_DECLS
diff --git a/libibmad/src/dump.c b/libibmad/src/dump.c
index 052127f..49bb34b 100644
--- a/libibmad/src/dump.c
+++ b/libibmad/src/dump.c
@@ -729,54 +729,3 @@ 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 = { .def_dump_fn = fn, .bitlen = valsz * 8};
-	char buf[512];
-
-	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);
-}
diff --git a/libibmad/src/fields.c b/libibmad/src/fields.c
index 6942e85..ffbfc76 100644
--- a/libibmad/src/fields.c
+++ b/libibmad/src/fields.c
@@ -54,7 +54,7 @@
 #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 [] = {
+static const ib_field_t ib_mad_f [] = {
 	[0]	{0, 0},		/* IB_NO_FIELD - reserved as invalid */
 
 	[IB_GID_PREFIX_F]		{0, 64, "GidPrefix", mad_dump_rhex},
@@ -363,8 +363,7 @@ ib_field_t ib_mad_f [] = {
 
 };
 
-void
-_set_field64(void *buf, int base_offs, ib_field_t *f, uint64_t val)
+static void _set_field64(void *buf, int base_offs, const ib_field_t *f, uint64_t val)
 {
 	uint64_t nval;
 
@@ -372,16 +371,14 @@ _set_field64(void *buf, int base_offs, ib_field_t *f, uint64_t 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)
+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);
 }
 
-void
-_set_field(void *buf, int base_offs, ib_field_t *f, uint32_t 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;
@@ -411,8 +408,7 @@ _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)
+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;
@@ -440,8 +436,7 @@ _get_field(void *buf, int base_offs, ib_field_t *f)
 }
 
 /* field must be byte aligned */
-void
-_set_array(void *buf, int base_offs, ib_field_t *f, void *val)
+static void _set_array(void *buf, int base_offs, const ib_field_t *f, void *val)
 {
 	int bitoffs = f->bitoffs;
 
@@ -451,8 +446,7 @@ _set_array(void *buf, int base_offs, ib_field_t *f, void *val)
 	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)
+static void _get_array(void *buf, int base_offs, const ib_field_t *f, void *val)
 {
 	int bitoffs = f->bitoffs;
 
@@ -461,3 +455,139 @@ _get_array(void *buf, int base_offs, ib_field_t *f, void *val)
 
 	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 = { .def_dump_fn = fn, .bitlen = valsz * 8};
+	char buf[512];
+
+	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/libibmad/src/libibmad.map b/libibmad/src/libibmad.map
index f26d28d..ea1ed4b 100644
--- a/libibmad/src/libibmad.map
+++ b/libibmad/src/libibmad.map
@@ -1,9 +1,8 @@
 IBMAD_1.3 {
 	global:
-		_mad_dump;
-		_mad_dump_field;
-		_mad_dump_val;
-		_mad_print_field;
+		mad_dump_field;
+		mad_dump_val;
+		mad_print_field;
 		mad_dump_array;
 		mad_dump_bitfield;
 		mad_dump_hex;
@@ -34,13 +33,12 @@ IBMAD_1.3 {
 		mad_dump_uint;
 		mad_dump_vlarbitration;
 		mad_dump_vlcap;
-		_get_array;
-		_get_field;
-		_get_field64;
-		_set_array;
-		_set_field;
-		_set_field64;
-		ib_mad_f;
+		mad_get_field;
+		mad_set_field;
+		mad_get_field64;
+		mad_set_field64;
+		mad_get_array;
+		mad_set_array;
 		perf_classportinfo_query;
 		port_performance_query;
 		port_performance_reset;
diff --git a/libibmad/src/mad.c b/libibmad/src/mad.c
index 1367ecd..fc73a7a 100644
--- a/libibmad/src/mad.c
+++ b/libibmad/src/mad.c
@@ -49,46 +49,6 @@
 #undef DEBUG
 #define DEBUG	if (ibdebug)	IBWARN
 
-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);
-}
-
-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);
-}
-
 uint64_t
 mad_trid(void)
 {
-- 
1.6.0.4.766.g6fc4a




More information about the general mailing list