[ofa-general] Re: [PATCH] libibmad/dump.c: Use bit mask approach to decoding LinkWidth/Speed Enabled/Supported
Sasha Khapyorsky
sashak at voltaire.com
Mon Nov 26 13:44:52 PST 2007
On 07:33 Mon 26 Nov , Hal Rosenstock wrote:
> libibmad/dump.c: Use bit mask approach to decoding LinkWidth/Speed
> Enabled/Supported
Another note...
>
> 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..05efdca 100644
> --- a/libibmad/src/dump.c
> +++ b/libibmad/src/dump.c
> @@ -227,39 +227,45 @@ 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, "?(%d)", width);
This prints "?(99)"
> + else
> + s[-3] = 0;
and this leaves the blank at end - "SX "
> +}
> +
> 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;
> + snprintf(buf + strlen(buf), bufsz - strlen(buf),
> + "(IBA extension)");
> + break;
Here "(IBA extention)" is printed w/out leading blank. So in the case of
unknown width code it will be "?(99)(IBA extension)". Right?
If so isn't it better to drop the blank at end of dump_linkwidth() and
add it here unconditionally?
Also wouldn't it be better to print "(IBA extension)" only for known
codes?
Sasha
> }
> }
>
> @@ -267,21 +273,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
> @@ -305,70 +298,49 @@ mad_dump_linkspeed(char *buf, int bufsz, void *val, int valsz)
> }
> }
>
> -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 >> 4) || s == buf)
> + s += snprintf(s, e - s, "?(%d)", speed);
> + else
> + s[-3] = 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);
> + 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