[ofa-general] [PATCHv2] libibmad/dump.c: Use bit mask approach to decoding LinkWidth/Speed Enabled/Supported
Hal Rosenstock
hrosenstock at xsigo.com
Sun Dec 2 04:48:41 PST 2007
libibmad/dump.c: Use bit mask approach to decoding LinkWidth/Speed
Enabled/Supported
Based on email from Jason Gunthorpe <jgunthorpe at obsidianresearch.com>
Signed-off-by: Hal Rosenstock <hal at xsigo.com>
diff --git a/libibmad/src/dump.c b/libibmad/src/dump.c
index 9628eba..aa88582 100644
--- a/libibmad/src/dump.c
+++ b/libibmad/src/dump.c
@@ -227,39 +227,46 @@ mad_dump_linkwidth(char *buf, int bufsz, void *val, int valsz)
}
}
+static void
+dump_linkwidth(char *buf, int bufsz, int width)
+{
+ char *s = buf, *e = s + bufsz;
+
+ if (width & 0x1)
+ s += snprintf(s, e - s, "1X or ");
+ if (s < e && (width & 0x2))
+ s += snprintf(s, e - s, "4X or ");
+ if (s < e && (width & 0x4))
+ s += snprintf(s, e - s, "8X or ");
+ if (s < e && (width & 0x8))
+ s += snprintf(s, e - s, "12X or ");
+
+ if ((width >> 4) || s == buf)
+ s += snprintf(s, e - s, "undefined (%d)", width);
+ else
+ s[-4] = 0;
+}
+
void
mad_dump_linkwidthsup(char *buf, int bufsz, void *val, int valsz)
{
int width = *(int *)val;
- switch (width) {
+ dump_linkwidth(buf, bufsz, width);
+
+ switch(width) {
case 1:
- snprintf(buf, bufsz, "1X");
- break;
- case 2:
- snprintf(buf, bufsz, "4X (IBA extension)");
- break;
case 3:
- snprintf(buf, bufsz, "1X or 4X");
- break;
- case 4:
- snprintf(buf, bufsz, "8X (IBA extension)");
- break;
case 7:
- snprintf(buf, bufsz, "1X or 4X or 8X");
- break;
- case 8:
- snprintf(buf, bufsz, "12X (IBA extension)");
- break;
case 11:
- snprintf(buf, bufsz, "1X or 4X or 12X");
- break;
case 15:
- snprintf(buf, bufsz, "1X or 4X or 8X or 12X");
break;
+
default:
- IBWARN("bad width %d", width);
- buf[0] = 0;
+ if (!(width >> 4))
+ snprintf(buf + strlen(buf), bufsz - strlen(buf),
+ " (IBA extension)");
+ break;
}
}
@@ -267,21 +274,8 @@ void
mad_dump_linkwidthen(char *buf, int bufsz, void *val, int valsz)
{
int width = *(int *)val;
- char *s = buf, *e = s + bufsz;
- if (width & 0x1)
- s += snprintf(s, e - s, "1X or ");
- if (s < e && (width & 0x2))
- s += snprintf(s, e - s, "4X or ");
- if (s < e && (width & 0x4))
- s += snprintf(s, e - s, "8X or ");
- if (s < e && (width & 0x8))
- s += snprintf(s, e - s, "12X or ");
-
- if ((width >> 4) || s == buf)
- s += snprintf(s, e - s, "?(%d)", width);
- else
- s[-3] = 0;
+ dump_linkwidth(buf, bufsz, width);
}
void
@@ -300,75 +294,55 @@ mad_dump_linkspeed(char *buf, int bufsz, void *val, int valsz)
snprintf(buf, bufsz, "10.0 Gbps");
break;
default:
- snprintf(buf, bufsz, "?(%d)", speed);
+ snprintf(buf, bufsz, "undefined (%d)", speed);
break;
}
}
-void
-mad_dump_linkspeedsup(char *buf, int bufsz, void *val, int valsz)
+static void
+dump_linkspeed(char *buf, int bufsz, int speed)
{
- int speed = *(int *)val;
+ char *s = buf, *e = s + bufsz;
+
+ if (speed & 0x1)
+ s += snprintf(s, e - s, "2.5 Gbps or ");
+ if (s < e && (speed & 0x2))
+ s += snprintf(s, e - s, "5.0 Gbps or ");
+ if (s < e && (speed & 0x4))
+ s += snprintf(s, e - s, "10.0 Gbps or ");
+
+ if ((speed >> 3) || s == buf)
+ s += snprintf(s, e - s, "undefined (%d)", speed);
+ else
+ s[-4] = 0;
switch (speed) {
case 1:
- snprintf(buf, bufsz, "2.5 Gbps");
- break;
- case 2:
- snprintf(buf, bufsz, "5.0 Gbps (IBA extension)");
- break;
case 3:
- snprintf(buf, bufsz, "2.5 or 5.0 Gbps");
- break;
- case 4:
- snprintf(buf, bufsz, "10.0 Gbps (IBA extension)");
- break;
case 5:
- snprintf(buf, bufsz, "2.5 or 10.0 Gbps");
- break;
case 7:
- snprintf(buf, bufsz, "2.5 or 5.0 or 10.0 Gbps");
break;
default:
- snprintf(buf, bufsz, "?(%d)", speed);
+ if (!(speed >> 3))
+ snprintf(s, e - s, " (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;
- switch (speed) {
- case 1:
- snprintf(buf, bufsz, "2.5 Gbps");
- break;
- case 2:
- snprintf(buf, bufsz, "5.0 Gbps (IBA extension)");
- break;
- case 3:
- snprintf(buf, bufsz, "2.5 or 5.0 Gbps");
- break;
- case 4:
- snprintf(buf, bufsz, "10.0 Gbps (IBA extension)");
- break;
- case 5:
- snprintf(buf, bufsz, "2.5 or 10.0 Gbps");
- break;
- case 6:
- snprintf(buf, bufsz, "5.0 or 10.0 Gbps");
- break;
- case 7:
- snprintf(buf, bufsz, "2.5 or 5.0 or 10.0 Gbps");
- break;
- case 15:
- snprintf(buf, bufsz, "SpeedSupported");
- break;
- default:
- snprintf(buf, bufsz, "?(%d)", speed);
- break;
- }
+ dump_linkspeed(buf, bufsz, speed);
}
void
More information about the general
mailing list