Re: [PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2010-01-13 Thread Hal Rosenstock
On Tue, Jan 12, 2010 at 5:11 AM, Sasha Khapyorsky  wrote:
> Hi Ralph,
>
> On 13:43 Mon 11 Jan , Ralph Campbell wrote:
>> Its been 2 months since I posted this.
>> What is the current status? Last comment I saw was from Ira
>> saying either add this functionality to ibportstate or
>> rename ibportstate but don't split it off into a new command.
>
> You are right, it seems that an idea about universal and potentially
> extendable new tool didn't find many fans :)
>
>> My preference is to go with the original patch. I haven't
>> seen any strong objection to it.

I understand Ralph's use case motivating this but it is also a
potentially dangerous tool in the wrong person's hands.

-- Hal

>
> I will go over original patch.
>
> Sasha
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2010-01-12 Thread Sasha Khapyorsky
On 11:56 Thu 05 Nov , Ralph Campbell wrote:
> This patch adds new commands to ibportstate to support initializing
> the link for CAs connected back-to-back. It also allows more than
> one field to be changed at the same time such as "lid 23 arm" or
> "width 1 speed 3 enable".
> 
> Signed-off-by: Ralph Campbell 

Applied. Thanks.

Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2010-01-12 Thread Sasha Khapyorsky
Hi Ralph,

On 13:43 Mon 11 Jan , Ralph Campbell wrote:
> Its been 2 months since I posted this.
> What is the current status? Last comment I saw was from Ira
> saying either add this functionality to ibportstate or
> rename ibportstate but don't split it off into a new command.

You are right, it seems that an idea about universal and potentially
extendable new tool didn't find many fans :)

> My preference is to go with the original patch. I haven't
> seen any strong objection to it.

I will go over original patch.

Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2010-01-11 Thread Ralph Campbell
Its been 2 months since I posted this.
What is the current status? Last comment I saw was from Ira
saying either add this functionality to ibportstate or
rename ibportstate but don't split it off into a new command.
My preference is to go with the original patch. I haven't
seen any strong objection to it.

On Thu, 2009-11-05 at 11:56 -0800, Ralph Campbell wrote:
> This patch adds new commands to ibportstate to support initializing
> the link for CAs connected back-to-back. It also allows more than
> one field to be changed at the same time such as "lid 23 arm" or
> "width 1 speed 3 enable".
> 
> Signed-off-by: Ralph Campbell 
> ---
> 
> diff --git a/infiniband-diags/src/ibportstate.c 
> b/infiniband-diags/src/ibportstate.c
> index e631bfd..192b14e 100644
> --- a/infiniband-diags/src/ibportstate.c
> +++ b/infiniband-diags/src/ibportstate.c
> @@ -46,93 +46,133 @@
> 
>  #include "ibdiag_common.h"
> 
> +enum port_ops {
> +   QUERY,
> +   ENABLE,
> +   RESET,
> +   DISABLE,
> +   SPEED,
> +   WIDTH,
> +   DOWN,
> +   ARM,
> +   ACTIVE,
> +   VLS,
> +   MTU,
> +   LID,
> +   SMLID,
> +   LMC,
> +};
> +
>  struct ibmad_port *srcport;
> +int speed = 15;
> +int width = 255;
> +int lid;
> +int smlid;
> +int lmc;
> +int mtu;
> +int vls;
> +
> +struct {
> +   const char *name;
> +   int *val;
> +   int set;
> +} port_args[] = {
> +   { "query", NULL, 0 },   /* QUERY */
> +   { "enable", NULL, 0 },  /* ENABLE */
> +   { "reset", NULL, 0 },   /* RESET */
> +   { "disable", NULL, 0 }, /* DISABLE */
> +   { "speed", &speed, 0 }, /* SPEED */
> +   { "width", &width, 0 }, /* WIDTH */
> +   { "down", NULL, 0 },/* DOWN */
> +   { "arm", NULL, 0 }, /* ARM */
> +   { "active", NULL, 0 },  /* ACTIVE */
> +   { "vls", &vls, 0 }, /* VLS */
> +   { "mtu", &mtu, 0 }, /* MTU */
> +   { "lid", &lid, 0 }, /* LID */
> +   { "smlid", &smlid, 0 }, /* SMLID */
> +   { "lmc", &lmc, 0 }, /* LMC */
> +};
> +
> +#define NPORT_ARGS (sizeof(port_args) / sizeof(port_args[0]))
> 
>  /***/
> 
> +/*
> + * Return 1 if port is a switch, else zero.
> + */
>  static int get_node_info(ib_portid_t * dest, uint8_t * data)
>  {
> int node_type;
> 
> if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
> -   return -1;
> +   IBERROR("smp query nodeinfo failed");
> 
> node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
> if (node_type == IB_NODE_SWITCH)/* Switch NodeType ? */
> -   return 0;
> -   else
> return 1;
> +   else
> +   return 0;
>  }
> 
> -static int get_port_info(ib_portid_t * dest, uint8_t * data, int portnum,
> -int port_op)
> +static void get_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
> +{
> +   if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, 
> srcport))
> +   IBERROR("smp query portinfo failed");
> +}
> +
> +static void show_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
>  {
> char buf[2048];
> char val[64];
> 
> -   if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, 
> srcport))
> -   return -1;
> -
> -   if (port_op != 4) {
> -   mad_dump_portstates(buf, sizeof buf, data, sizeof data);
> -   mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, val);
> -   mad_dump_field(IB_PORT_LINK_WIDTH_SUPPORTED_F,
> -  buf + strlen(buf), sizeof buf - strlen(buf),
> -  val);
> -   sprintf(buf + strlen(buf), "%s", "\n");
> -   mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, val);
> -   mad_dump_field(IB_PORT_LINK_WIDTH_ENABLED_F, buf + 
> strlen(buf),
> -  sizeof buf - strlen(buf), val);
> -   sprintf(buf + strlen(buf), "%s", "\n");
> -   mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, val);
> -   mad_dump_field(IB_PORT_LINK_WIDTH_ACTIVE_F, buf + strlen(buf),
> -  sizeof buf - strlen(buf), val);
> -   sprintf(buf + strlen(buf), "%s", "\n");
> -   mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, val);
> -   mad_dump_field(IB_PORT_LINK_SPEED_SUPPORTED_F,
> -  buf + strlen(buf), sizeof buf - strlen(buf),
> -  val);
> -   sprintf(buf + strlen(buf), "%s", "\n");
> -   mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, val);
> -   mad_dump_field(IB_PORT_LINK_SPEED_ENABLED_F, buf + 
> strlen(buf),
> -  sizeof buf - strlen(buf), val);
> -   sprintf(buf + strlen(buf), "%s", "\n");
> -   mad_decode_field(data, IB_PORT_

Re: [PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2009-12-01 Thread Ira Weiny
On Tue, 1 Dec 2009 05:17:22 +0200
Sasha Khapyorsky  wrote:

> Hi Ralph,
> 
> On 11:56 Thu 05 Nov , Ralph Campbell wrote:
> > This patch adds new commands to ibportstate to support initializing
> > the link for CAs connected back-to-back. It also allows more than
> > one field to be changed at the same time such as "lid 23 arm" or
> > "width 1 speed 3 enable".
> 
> As far as I can see this changes a functionality of ibportstate
> dramatically. Actually it makes it more like to 'ibportset' than just
> 'ibportstate', correct?

Yes it adds "set" functionality but ibportstate still reports the state by
default.

> 
> If so, wouldn't it be better to introduce a new tool - let's say
> 'ibportset' (or like this)?

_If_ we make "ibportset" then we should do so by changing "ibportstate" to
"ibportset" and removing the old tool. (Or just leave this as ibportstate)  My
reasoning is that we already have a lot of diags.  This can cause confusion
among some users as to which tools do what.  I am not advocating a kitchen
sink app but I think we should be careful about adding new tools when the
functionality is closely related to something that exists as it does here.

Also, a minor nit on the patch below.

> 
> (Or even wider 'smpset' - however such 'smpset' can be done later
> following a real needs by extending ibportset or so).
> 
> Don't understand me wrong I'm not disagree at all, just trying to find
> the best way to add such functionality to infiniband-diags.
> 
> Sasha
> 
> > 
> > Signed-off-by: Ralph Campbell 
> > ---
> > 
> > diff --git a/infiniband-diags/src/ibportstate.c 
> > b/infiniband-diags/src/ibportstate.c
> > index e631bfd..192b14e 100644
> > --- a/infiniband-diags/src/ibportstate.c
> > +++ b/infiniband-diags/src/ibportstate.c
> > @@ -46,93 +46,133 @@
> >  
> >  #include "ibdiag_common.h"
> >  
> > +enum port_ops {
> > +   QUERY,
> > +   ENABLE,
> > +   RESET,
> > +   DISABLE,
> > +   SPEED,
> > +   WIDTH,
> > +   DOWN,
> > +   ARM,
> > +   ACTIVE,
> > +   VLS,
> > +   MTU,
> > +   LID,
> > +   SMLID,
> > +   LMC,
> > +};
> > +
> >  struct ibmad_port *srcport;
> > +int speed = 15;
> > +int width = 255;
> > +int lid;
> > +int smlid;
> > +int lmc;
> > +int mtu;
> > +int vls;
> > +
> > +struct {
> > +   const char *name;
> > +   int *val;
> > +   int set;
> > +} port_args[] = {
> > +   { "query", NULL, 0 },   /* QUERY */
> > +   { "enable", NULL, 0 },  /* ENABLE */
> > +   { "reset", NULL, 0 },   /* RESET */
> > +   { "disable", NULL, 0 }, /* DISABLE */
> > +   { "speed", &speed, 0 }, /* SPEED */
> > +   { "width", &width, 0 }, /* WIDTH */
> > +   { "down", NULL, 0 },/* DOWN */
> > +   { "arm", NULL, 0 }, /* ARM */
> > +   { "active", NULL, 0 },  /* ACTIVE */
> > +   { "vls", &vls, 0 }, /* VLS */
> > +   { "mtu", &mtu, 0 }, /* MTU */
> > +   { "lid", &lid, 0 }, /* LID */
> > +   { "smlid", &smlid, 0 }, /* SMLID */
> > +   { "lmc", &lmc, 0 }, /* LMC */
> > +};
> > +
> > +#define NPORT_ARGS (sizeof(port_args) / sizeof(port_args[0]))
> >  
> >  /***/
> >  
> > +/*
> > + * Return 1 if port is a switch, else zero.
> > + */
> >  static int get_node_info(ib_portid_t * dest, uint8_t * data)
> >  {
> > int node_type;
> >  
> > if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
> > -   return -1;
> > +   IBERROR("smp query nodeinfo failed");
> >  
> > node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
> > if (node_type == IB_NODE_SWITCH)/* Switch NodeType ? */
> > -   return 0;
> > -   else
> > return 1;
> > +   else
> > +   return 0;
> >  }
> >  
> > -static int get_port_info(ib_portid_t * dest, uint8_t * data, int portnum,
> > -int port_op)
> > +static void get_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
> > +{
> > +   if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
> > +   IBERROR("smp query portinfo failed");
> > +}
> > +
> > +static void show_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
> >  {
> > char buf[2048];
> > char val[64];
> >  
> > -   if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
> > -   return -1;
> > -
> > -   if (port_op != 4) {
> > -   mad_dump_portstates(buf, sizeof buf, data, sizeof data);
> > -   mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, val);
> > -   mad_dump_field(IB_PORT_LINK_WIDTH_SUPPORTED_F,
> > -  buf + strlen(buf), sizeof buf - strlen(buf),
> > -  val);
> > -   sprintf(buf + strlen(buf), "%s", "\n");
> > -   mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, val);
> > -   mad_dump_field(IB_PORT_LINK_WIDTH_ENABLED_F, buf + strlen(buf),
> > -  sizeof buf - strlen(buf), val);
> > -   sprintf(buf + strlen(buf), "%s", "\n");
> > -   mad_decode_field(data, IB_PORT_LINK_WIDTH

Re: [PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2009-12-01 Thread Ralph Campbell
I don't mind introducing a new command. I just thought
that since iportstate already supported some changes
it was logical to extend it. Note that I haven't changed
any of the original commands so scripts which rely on
the old behavior should still work.

You are the maintainer. I'm willing to go with what you
think is best.

On Mon, 2009-11-30 at 19:17 -0800, Sasha Khapyorsky wrote:
> Hi Ralph,
> 
> On 11:56 Thu 05 Nov , Ralph Campbell wrote:
> > This patch adds new commands to ibportstate to support initializing
> > the link for CAs connected back-to-back. It also allows more than
> > one field to be changed at the same time such as "lid 23 arm" or
> > "width 1 speed 3 enable".
> 
> As far as I can see this changes a functionality of ibportstate
> dramatically. Actually it makes it more like to 'ibportset' than just
> 'ibportstate', correct?
> 
> If so, wouldn't it be better to introduce a new tool - let's say
> 'ibportset' (or like this)?
> 
> (Or even wider 'smpset' - however such 'smpset' can be done later
> following a real needs by extending ibportset or so).
> 
> Don't understand me wrong I'm not disagree at all, just trying to find
> the best way to add such functionality to infiniband-diags.
> 
> Sasha
> 
> >
> > Signed-off-by: Ralph Campbell 
> > ---
> >
> > diff --git a/infiniband-diags/src/ibportstate.c 
> > b/infiniband-diags/src/ibportstate.c
> > index e631bfd..192b14e 100644
> > --- a/infiniband-diags/src/ibportstate.c
> > +++ b/infiniband-diags/src/ibportstate.c
> > @@ -46,93 +46,133 @@
> >
> >  #include "ibdiag_common.h"
> >
> > +enum port_ops {
> > + QUERY,
> > + ENABLE,
> > + RESET,
> > + DISABLE,
> > + SPEED,
> > + WIDTH,
> > + DOWN,
> > + ARM,
> > + ACTIVE,
> > + VLS,
> > + MTU,
> > + LID,
> > + SMLID,
> > + LMC,
> > +};
> > +
> >  struct ibmad_port *srcport;
> > +int speed = 15;
> > +int width = 255;
> > +int lid;
> > +int smlid;
> > +int lmc;
> > +int mtu;
> > +int vls;
> > +
> > +struct {
> > + const char *name;
> > + int *val;
> > + int set;
> > +} port_args[] = {
> > + { "query", NULL, 0 },   /* QUERY */
> > + { "enable", NULL, 0 },  /* ENABLE */
> > + { "reset", NULL, 0 },   /* RESET */
> > + { "disable", NULL, 0 }, /* DISABLE */
> > + { "speed", &speed, 0 }, /* SPEED */
> > + { "width", &width, 0 }, /* WIDTH */
> > + { "down", NULL, 0 },/* DOWN */
> > + { "arm", NULL, 0 }, /* ARM */
> > + { "active", NULL, 0 },  /* ACTIVE */
> > + { "vls", &vls, 0 }, /* VLS */
> > + { "mtu", &mtu, 0 }, /* MTU */
> > + { "lid", &lid, 0 }, /* LID */
> > + { "smlid", &smlid, 0 }, /* SMLID */
> > + { "lmc", &lmc, 0 }, /* LMC */
> > +};
> > +
> > +#define NPORT_ARGS (sizeof(port_args) / sizeof(port_args[0]))
> >
> >  /***/
> >
> > +/*
> > + * Return 1 if port is a switch, else zero.
> > + */
> >  static int get_node_info(ib_portid_t * dest, uint8_t * data)
> >  {
> >   int node_type;
> >
> >   if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
> > - return -1;
> > + IBERROR("smp query nodeinfo failed");
> >
> >   node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
> >   if (node_type == IB_NODE_SWITCH)/* Switch NodeType ? */
> > - return 0;
> > - else
> >   return 1;
> > + else
> > + return 0;
> >  }
> >
> > -static int get_port_info(ib_portid_t * dest, uint8_t * data, int portnum,
> > -  int port_op)
> > +static void get_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
> > +{
> > + if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, 
> > srcport))
> > + IBERROR("smp query portinfo failed");
> > +}
> > +
> > +static void show_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
> >  {
> >   char buf[2048];
> >   char val[64];
> >
> > - if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, 
> > srcport))
> > - return -1;
> > -
> > - if (port_op != 4) {
> > - mad_dump_portstates(buf, sizeof buf, data, sizeof data);
> > - mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, val);
> > - mad_dump_field(IB_PORT_LINK_WIDTH_SUPPORTED_F,
> > -buf + strlen(buf), sizeof buf - strlen(buf),
> > -val);
> > - sprintf(buf + strlen(buf), "%s", "\n");
> > - mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, val);
> > - mad_dump_field(IB_PORT_LINK_WIDTH_ENABLED_F, buf + 
> > strlen(buf),
> > -sizeof buf - strlen(buf), val);
> > - sprintf(buf + strlen(buf), "%s", "\n");
> > - mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, val);
> > - mad_dump_field(IB_PORT_LINK_WIDTH_ACTIVE_F, buf + strlen(buf),
> > -size

Re: [PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2009-11-30 Thread Sasha Khapyorsky
Hi Ralph,

On 11:56 Thu 05 Nov , Ralph Campbell wrote:
> This patch adds new commands to ibportstate to support initializing
> the link for CAs connected back-to-back. It also allows more than
> one field to be changed at the same time such as "lid 23 arm" or
> "width 1 speed 3 enable".

As far as I can see this changes a functionality of ibportstate
dramatically. Actually it makes it more like to 'ibportset' than just
'ibportstate', correct?

If so, wouldn't it be better to introduce a new tool - let's say
'ibportset' (or like this)?

(Or even wider 'smpset' - however such 'smpset' can be done later
following a real needs by extending ibportset or so).

Don't understand me wrong I'm not disagree at all, just trying to find
the best way to add such functionality to infiniband-diags.

Sasha

> 
> Signed-off-by: Ralph Campbell 
> ---
> 
> diff --git a/infiniband-diags/src/ibportstate.c 
> b/infiniband-diags/src/ibportstate.c
> index e631bfd..192b14e 100644
> --- a/infiniband-diags/src/ibportstate.c
> +++ b/infiniband-diags/src/ibportstate.c
> @@ -46,93 +46,133 @@
>  
>  #include "ibdiag_common.h"
>  
> +enum port_ops {
> + QUERY,
> + ENABLE,
> + RESET,
> + DISABLE,
> + SPEED,
> + WIDTH,
> + DOWN,
> + ARM,
> + ACTIVE,
> + VLS,
> + MTU,
> + LID,
> + SMLID,
> + LMC,
> +};
> +
>  struct ibmad_port *srcport;
> +int speed = 15;
> +int width = 255;
> +int lid;
> +int smlid;
> +int lmc;
> +int mtu;
> +int vls;
> +
> +struct {
> + const char *name;
> + int *val;
> + int set;
> +} port_args[] = {
> + { "query", NULL, 0 },   /* QUERY */
> + { "enable", NULL, 0 },  /* ENABLE */
> + { "reset", NULL, 0 },   /* RESET */
> + { "disable", NULL, 0 }, /* DISABLE */
> + { "speed", &speed, 0 }, /* SPEED */
> + { "width", &width, 0 }, /* WIDTH */
> + { "down", NULL, 0 },/* DOWN */
> + { "arm", NULL, 0 }, /* ARM */
> + { "active", NULL, 0 },  /* ACTIVE */
> + { "vls", &vls, 0 }, /* VLS */
> + { "mtu", &mtu, 0 }, /* MTU */
> + { "lid", &lid, 0 }, /* LID */
> + { "smlid", &smlid, 0 }, /* SMLID */
> + { "lmc", &lmc, 0 }, /* LMC */
> +};
> +
> +#define NPORT_ARGS (sizeof(port_args) / sizeof(port_args[0]))
>  
>  /***/
>  
> +/*
> + * Return 1 if port is a switch, else zero.
> + */
>  static int get_node_info(ib_portid_t * dest, uint8_t * data)
>  {
>   int node_type;
>  
>   if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
> - return -1;
> + IBERROR("smp query nodeinfo failed");
>  
>   node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
>   if (node_type == IB_NODE_SWITCH)/* Switch NodeType ? */
> - return 0;
> - else
>   return 1;
> + else
> + return 0;
>  }
>  
> -static int get_port_info(ib_portid_t * dest, uint8_t * data, int portnum,
> -  int port_op)
> +static void get_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
> +{
> + if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
> + IBERROR("smp query portinfo failed");
> +}
> +
> +static void show_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
>  {
>   char buf[2048];
>   char val[64];
>  
> - if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
> - return -1;
> -
> - if (port_op != 4) {
> - mad_dump_portstates(buf, sizeof buf, data, sizeof data);
> - mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, val);
> - mad_dump_field(IB_PORT_LINK_WIDTH_SUPPORTED_F,
> -buf + strlen(buf), sizeof buf - strlen(buf),
> -val);
> - sprintf(buf + strlen(buf), "%s", "\n");
> - mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, val);
> - mad_dump_field(IB_PORT_LINK_WIDTH_ENABLED_F, buf + strlen(buf),
> -sizeof buf - strlen(buf), val);
> - sprintf(buf + strlen(buf), "%s", "\n");
> - mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, val);
> - mad_dump_field(IB_PORT_LINK_WIDTH_ACTIVE_F, buf + strlen(buf),
> -sizeof buf - strlen(buf), val);
> - sprintf(buf + strlen(buf), "%s", "\n");
> - mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, val);
> - mad_dump_field(IB_PORT_LINK_SPEED_SUPPORTED_F,
> -buf + strlen(buf), sizeof buf - strlen(buf),
> -val);
> - sprintf(buf + strlen(buf), "%s", "\n");
> - mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, val);
> - mad_dump_field(IB_PORT_LINK_SPEED_ENABLED_F, buf + strlen(buf),
> -sizeof buf - strlen(buf), val);
> - sprintf(buf + strlen(buf), "%s"

[PATCH] infiniband-diags/ibportstate: allow changes to CA portinfo parameters

2009-11-05 Thread Ralph Campbell
This patch adds new commands to ibportstate to support initializing
the link for CAs connected back-to-back. It also allows more than
one field to be changed at the same time such as "lid 23 arm" or
"width 1 speed 3 enable".

Signed-off-by: Ralph Campbell 
---

diff --git a/infiniband-diags/src/ibportstate.c 
b/infiniband-diags/src/ibportstate.c
index e631bfd..192b14e 100644
--- a/infiniband-diags/src/ibportstate.c
+++ b/infiniband-diags/src/ibportstate.c
@@ -46,93 +46,133 @@
 
 #include "ibdiag_common.h"
 
+enum port_ops {
+   QUERY,
+   ENABLE,
+   RESET,
+   DISABLE,
+   SPEED,
+   WIDTH,
+   DOWN,
+   ARM,
+   ACTIVE,
+   VLS,
+   MTU,
+   LID,
+   SMLID,
+   LMC,
+};
+
 struct ibmad_port *srcport;
+int speed = 15;
+int width = 255;
+int lid;
+int smlid;
+int lmc;
+int mtu;
+int vls;
+
+struct {
+   const char *name;
+   int *val;
+   int set;
+} port_args[] = {
+   { "query", NULL, 0 },   /* QUERY */
+   { "enable", NULL, 0 },  /* ENABLE */
+   { "reset", NULL, 0 },   /* RESET */
+   { "disable", NULL, 0 }, /* DISABLE */
+   { "speed", &speed, 0 }, /* SPEED */
+   { "width", &width, 0 }, /* WIDTH */
+   { "down", NULL, 0 },/* DOWN */
+   { "arm", NULL, 0 }, /* ARM */
+   { "active", NULL, 0 },  /* ACTIVE */
+   { "vls", &vls, 0 }, /* VLS */
+   { "mtu", &mtu, 0 }, /* MTU */
+   { "lid", &lid, 0 }, /* LID */
+   { "smlid", &smlid, 0 }, /* SMLID */
+   { "lmc", &lmc, 0 }, /* LMC */
+};
+
+#define NPORT_ARGS (sizeof(port_args) / sizeof(port_args[0]))
 
 /***/
 
+/*
+ * Return 1 if port is a switch, else zero.
+ */
 static int get_node_info(ib_portid_t * dest, uint8_t * data)
 {
int node_type;
 
if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
-   return -1;
+   IBERROR("smp query nodeinfo failed");
 
node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
if (node_type == IB_NODE_SWITCH)/* Switch NodeType ? */
-   return 0;
-   else
return 1;
+   else
+   return 0;
 }
 
-static int get_port_info(ib_portid_t * dest, uint8_t * data, int portnum,
-int port_op)
+static void get_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
+{
+   if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
+   IBERROR("smp query portinfo failed");
+}
+
+static void show_port_info(ib_portid_t * dest, uint8_t * data, int portnum)
 {
char buf[2048];
char val[64];
 
-   if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
-   return -1;
-
-   if (port_op != 4) {
-   mad_dump_portstates(buf, sizeof buf, data, sizeof data);
-   mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, val);
-   mad_dump_field(IB_PORT_LINK_WIDTH_SUPPORTED_F,
-  buf + strlen(buf), sizeof buf - strlen(buf),
-  val);
-   sprintf(buf + strlen(buf), "%s", "\n");
-   mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, val);
-   mad_dump_field(IB_PORT_LINK_WIDTH_ENABLED_F, buf + strlen(buf),
-  sizeof buf - strlen(buf), val);
-   sprintf(buf + strlen(buf), "%s", "\n");
-   mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, val);
-   mad_dump_field(IB_PORT_LINK_WIDTH_ACTIVE_F, buf + strlen(buf),
-  sizeof buf - strlen(buf), val);
-   sprintf(buf + strlen(buf), "%s", "\n");
-   mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, val);
-   mad_dump_field(IB_PORT_LINK_SPEED_SUPPORTED_F,
-  buf + strlen(buf), sizeof buf - strlen(buf),
-  val);
-   sprintf(buf + strlen(buf), "%s", "\n");
-   mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, val);
-   mad_dump_field(IB_PORT_LINK_SPEED_ENABLED_F, buf + strlen(buf),
-  sizeof buf - strlen(buf), val);
-   sprintf(buf + strlen(buf), "%s", "\n");
-   mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, val);
-   mad_dump_field(IB_PORT_LINK_SPEED_ACTIVE_F, buf + strlen(buf),
-  sizeof buf - strlen(buf), val);
-   sprintf(buf + strlen(buf), "%s", "\n");
-   } else {
-   mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, val);
-   mad_dump_field(IB_PORT_LINK_SPEED_ENABLED_F, buf, sizeof buf,
-  val);
-   sprintf(buf + strlen(buf), "%s", "\n");
-   }
+   mad_dump_portstates(buf, sizeof buf, data, sizeof data);
+   mad_decode_field(data, IB_PORT_LID_F, val);
+   mad_