Skip to content
Browse files

fcoeadm: Support multiple values for PortSpeed/PortSupportedSpeed

PortSpeed and PortSupportedSpeed attributes can support multiple
speeds as bitmasks.
This patch allows decoding of these attributes value such that all
the specified speeds can be displayed in the port information
output.

Signed-off-by: Neerav Parikh <Neerav.Parikh@intel.com>
Tested-by: Ross Brattain <ross.b.brattain@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
  • Loading branch information...
1 parent 8b5b43e commit d9d8973825d953829dc8f1280b4457eff64bb798 Neerav Parikh committed with Robert Love Jun 25, 2011
Showing with 39 additions and 5 deletions.
  1. +39 −5 fcoeadm_display.c
View
44 fcoeadm_display.c
@@ -107,11 +107,11 @@ struct sa_nameval port_states[] = {
* table of /sys port speed strings to HBA-API values.
*/
struct sa_nameval port_speeds[] = {
- { "10 Gbit", HBA_PORTSPEED_10GBIT },
- { "2 Gbit", HBA_PORTSPEED_2GBIT },
+ { "Unknown", HBA_PORTSPEED_UNKNOWN },
{ "1 Gbit", HBA_PORTSPEED_1GBIT },
+ { "2 Gbit", HBA_PORTSPEED_2GBIT },
+ { "10 Gbit", HBA_PORTSPEED_10GBIT },
{ "Not Negotiated", HBA_PORTSPEED_NOT_NEGOTIATED },
- { "Unknown", HBA_PORTSPEED_UNKNOWN },
{ NULL, 0 }
};
@@ -137,6 +137,38 @@ sa_enum_decode(char *buf, size_t len,
return buf;
}
+/** sa_enum_decode_speed(buf, len, val)
+ *
+ * @param buf buffer for result (may be used or not).
+ * @param len size of buffer (at least 32 bytes recommended).
+ * @param val value to be decoded into a name.
+ * @returns pointer to name string. Unknown values are put into buffer in hex.
+ * Uses the port_speeds table to decode speed from value
+ */
+static const char *
+sa_enum_decode_speed(char *buf, size_t buflen,
+ u_int32_t val)
+{
+ char *prefix = "";
+ ssize_t len = 0;
+ struct sa_nameval *tp = port_speeds;
+ char *cp = buf;
+
+ snprintf(buf, buflen, "Unknown");
+ for (; tp->nv_name != NULL; tp++) {
+ if (tp->nv_val & val) {
+ len = snprintf(cp, buflen, "%s%s", prefix, tp->nv_name);
+ if (len <= 0 || len >= buflen)
+ break;
+ cp += len;
+ buflen -= len;
+ prefix = ", ";
+ }
+ }
+
+ return buf;
+}
+
static void
sa_dump_wwn(void *Data, int Length, int Break)
{
@@ -290,10 +322,12 @@ static void show_port_info(HBA_ADAPTERATTRIBUTES *hba_info,
show_wwn(lp_info->FabricName.wwn);
printf("\n");
- sa_enum_decode(buf, len, port_speeds, lp_info->PortSpeed);
+ memset(buf, '\0', len);
+ sa_enum_decode_speed(buf, len, lp_info->PortSpeed);
printf(" Speed: %s\n", buf);
- sa_enum_decode(buf, len, port_speeds, lp_info->PortSupportedSpeed);
+ memset(buf, '\0', len);
+ sa_enum_decode_speed(buf, len, lp_info->PortSupportedSpeed);
printf(" Supported Speed: %s\n", buf);
printf(" MaxFrameSize: %d\n",

0 comments on commit d9d8973

Please sign in to comment.
Something went wrong with that request. Please try again.