[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:33:47 PST 2007
On 13:13 Mon 26 Nov , Hal Rosenstock wrote:
> On Mon, 2007-11-26 at 20:46 +0000, Sasha Khapyorsky wrote:
> > On 07:33 Mon 26 Nov , Hal Rosenstock wrote:
> > > 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..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);
> > > + else
> > > + s[-3] = 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;
> > > + snprintf(buf + strlen(buf), bufsz - strlen(buf),
> > > + "(IBA extension)");
> > > + break;
> > > }
> > > }
> > >
> > > @@ -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;
> >
> > What should be if something like speed = 9 is passed? Probably you meant
> > (speed >> 3) here?
>
> Yes, this was a cut and paste error. Do you want a new patch or will you
> just fix this up ?
Will fix.
Sasha
More information about the general
mailing list