[VSTAT] added more information under new '-m' flag.
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 13 May 2009 12:11:23 +0000 (12:11 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 13 May 2009 12:11:23 +0000 (12:11 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2181 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

tools/vstat/user/vstat_main.c

index c351b39..3f1e4a4 100644 (file)
 #define VEND_ID_MELLNOX        0x02c9\r
 #define VEND_ID_VOLTAIRE       0x08f1\r
 \r
+enum link_speed_type_e {\r
+       LINK_SPEED_SUPPORTED = 0,\r
+       LINK_SPEED_ENABLED,\r
+       LINK_SPEED_ACTIVE\r
+};\r
 \r
 /*******************************************************************\r
 *******************************************************************/\r
@@ -148,12 +153,56 @@ void printPortPhysState(uint8_t physState){
        }\r
 }\r
 \r
-void printPortRate(int speed, int width, int portState){ \r
-       if (portState == 1){ /* In case the port is in Down state */\r
+void printPortRate(enum link_speed_type_e link_speed_type, int speed, int width, int portState, BOOLEAN moreVerbose){\r
+       char *link_speed_type_str[] = { "Supported", "Enabled", "Active" };\r
+\r
+       if ((portState == 1) && (link_speed_type == LINK_SPEED_ACTIVE)){ /* In case the port is in Down state */\r
                printf("\t\tlink_speed=NA\n");\r
-               printf("\t\tlink_width=NA \n\t\trate=NA\n");            \r
-       }else{  \r
-               switch(speed){\r
+               printf("\t\tlink_width=NA \n\t\trate=NA\n");\r
+       }else{\r
+               if (moreVerbose) {\r
+                       int link_width_arr[4] = { 1, 4, 8, 12 };\r
+                       float link_rate_arr[4] = { 2.5, 10.0, 20.0, 30.0 };\r
+                       int i, link_flag;\r
+                       float base_speed = 2.5;\r
+\r
+                       link_flag = 0;\r
+                       printf("\t\t%s_link_speed=", link_speed_type_str[link_speed_type]);\r
+                       for (i=1; i <= 4; i*=2)\r
+                               if (speed & i) {\r
+                                       printf("%2.1f Gbps (%d), ", base_speed*i, i);\r
+                                       link_flag = 1;\r
+                               }\r
+                       if (!link_flag)\r
+                               printf("UNKNOWN (%d)",speed);\r
+                       printf("\n");\r
+\r
+                       link_flag = 0;\r
+                       printf("\t\t%s_link_width=", link_speed_type_str[link_speed_type]);\r
+                       for (i=0; i < 4; i++)\r
+                               if ((width >> i) & 1) {\r
+                                       printf("%dx (%d), ", link_width_arr[i], 1<<i);\r
+                                       link_flag = 1;\r
+                               }\r
+                       if (!link_flag)\r
+                               printf("UNKNOWN (%d)",width);\r
+                       printf("\n");\r
+\r
+                       if (link_speed_type == LINK_SPEED_ACTIVE) {\r
+                               link_flag = 0;\r
+                               printf("\t\t%s_rate=", link_speed_type_str[link_speed_type]);\r
+                               for (i=0; i < 4; i++)\r
+                                       if ((width >> i) & 1) {\r
+                                               printf("%2.1f Gbps, ", (i+1)*link_rate_arr[i]);\r
+                                               link_flag = 1;\r
+                                       }\r
+                               if (!link_flag)\r
+                                       printf("UNKNOWN (%d)",speed);\r
+                               printf("\n");\r
+                       }\r
+               }\r
+               else {\r
+                       switch(speed){\r
                        case 1:\r
                                printf("\t\tlink_speed=2.5 Gbps (%d)\n",speed);\r
                                break;\r
@@ -167,7 +216,7 @@ void printPortRate(int speed, int width, int portState){
                                printf("\t\tlink_speed=UNKNOWN (%d)\n",speed); \r
                }\r
 \r
-               switch (width){\r
+                       switch (width){\r
                        case 1:\r
                                printf("\t\tlink_width=1x (%f) \n\t\trate=%d Gbps\n",width,2.5*speed);\r
                                break;\r
@@ -183,9 +232,9 @@ void printPortRate(int speed, int width, int portState){
                        default:\r
                                printf("\t\tlink_width=UNKNOWN (%d)\n",width);\r
                }\r
-       }\r
-               \r
 \r
+               }\r
+       }\r
 }\r
 \r
 \r
@@ -255,10 +304,14 @@ void printPortActiveSpeed(uint8_t speed){
        }\r
 }\r
 \r
-void printPortInfo(ib_port_attr_t* portPtr, ib_port_info_t portInfo, BOOLEAN fullPrint){\r
+void printPortInfo(ib_port_attr_t* portPtr, ib_port_info_t portInfo, BOOLEAN fullPrint, BOOLEAN moreVerbose){\r
        printf("\t\tport=%d\n", portPtr->port_num);\r
        printPortLinkState(portPtr->link_state);\r
-       printPortRate(portInfo.link_speed>>4,portInfo.link_width_active, portPtr->link_state);\r
+       if (moreVerbose) {\r
+               printPortRate(LINK_SPEED_SUPPORTED, portInfo.state_info1>>4, portInfo.link_width_supported, portPtr->link_state, moreVerbose);\r
+               printPortRate(LINK_SPEED_ENABLED, (portInfo.link_speed & 0xF), portInfo.link_width_enabled, portPtr->link_state, moreVerbose);\r
+       }\r
+       printPortRate(LINK_SPEED_ACTIVE, portInfo.link_speed>>4, portInfo.link_width_active, portPtr->link_state, moreVerbose);\r
        printPortPhysState(portPtr->phys_state);\r
        printPortActiveSpeed(portPtr->active_speed);\r
        printf("\t\tsm_lid=0x%04x\n", cl_ntoh16(portPtr->sm_lid));\r
@@ -326,13 +379,17 @@ void print_uplink_info(ib_ca_attr_t* ca_attr)
                        p_uplink_info->x.granted, p_uplink_info->x.masked ? "Y" : "N"); \r
 }\r
 \r
-void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, ib_port_info_t* vstat_port_info, BOOLEAN fullPrint){\r
+void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, ib_port_info_t* vstat_port_info, \r
+                        BOOLEAN fullPrint, BOOLEAN moreVerbose){\r
        int i;\r
 \r
        printf("\n\thca_idx=%d\n", idx);\r
        print_uplink_info(ca_attr);\r
        printf("\tvendor_id=0x%04x\n", ca_attr->vend_id);\r
-       printf("\tvendor_part_id=0x%04x\n", ca_attr->dev_id);\r
+       if(moreVerbose)\r
+               printf("\tvendor_part_id=0x%04x (%d)\n", ca_attr->dev_id, ca_attr->dev_id);\r
+       else\r
+               printf("\tvendor_part_id=%hu\n", ca_attr->dev_id);\r
 \r
        if (!ca_attr->num_ports) {\r
                printf("\n\tATTENTION! \n\t    The driver has reported zero physical ports. "\r
@@ -401,7 +458,7 @@ void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, ib_port_info_t* vstat_
                printf("\tnum_phys_ports=%d\n",         ca_attr->num_ports);\r
        }\r
        for (i = 0; i<ca_attr->num_ports; i++){\r
-               printPortInfo(ca_attr->p_port_attr+i, vstat_port_info[i], fullPrint);\r
+               printPortInfo(ca_attr->p_port_attr+i, vstat_port_info[i], fullPrint, moreVerbose);\r
        }       \r
 }\r
 /* Internal Functions */\r
@@ -498,7 +555,8 @@ ib_api_status_t
 vstat_ca_attr(\r
        boolean_t modify_attr,\r
        BOOLEAN fullPrint,\r
-       BOOLEAN getCounters\r
+       BOOLEAN getCounters,\r
+       BOOLEAN moreVerbose\r
        )\r
 {\r
        ib_al_handle_t          h_al = NULL;\r
@@ -621,7 +679,7 @@ vstat_ca_attr(
                                vstat_get_port_info(h_ca ,port_idx+1,&vstat_port_info[port_idx]);\r
                        }\r
 \r
-                       vstat_print_ca_attr((int)i, vstat_ca_attr, vstat_port_info, fullPrint);\r
+                       vstat_print_ca_attr((int)i, vstat_ca_attr, vstat_port_info, fullPrint, moreVerbose);\r
                        if(getCounters)\r
                        {\r
                                for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r
@@ -672,9 +730,11 @@ Cleanup1:
 \r
 void vstat_help()\r
 {\r
-       printf("\n\tUsage: vstat [-v] [-c]\n");\r
+       printf("\n\tUsage: vstat [-v] [-c] [-m]\n");\r
        printf("\t\t -v - verbose mode\n");\r
        printf("\t\t -c - HCA error/statistic counters\n");\r
+       printf("\t\t -m - more verbose mode\n");\r
+       \r
 }\r
 \r
 int32_t __cdecl\r
@@ -686,6 +746,7 @@ main(
        BOOLEAN fullPrint = FALSE;\r
        BOOLEAN getCounters = FALSE;\r
        BOOLEAN showHelp = FALSE;\r
+       BOOLEAN moreVerbose = FALSE;\r
        if(argc>1){\r
                int i = 2;\r
                while(i<=argc){\r
@@ -699,6 +760,10 @@ main(
                        }else if(!_stricmp(argv[i-1], "-c")){\r
                                getCounters = TRUE;\r
                                i+=1;\r
+                       }else if(!_stricmp(argv[i-1], "-m")){\r
+                               fullPrint = TRUE;\r
+                               moreVerbose = TRUE;\r
+                               i+=1;\r
                        }else{\r
                                i+=2;\r
                        }\r
@@ -707,7 +772,7 @@ main(
        if (showHelp)\r
                vstat_help();\r
        else\r
-               ib_status = vstat_ca_attr(FALSE, fullPrint,getCounters);\r
+               ib_status = vstat_ca_attr(FALSE, fullPrint,getCounters, moreVerbose);\r
 \r
        return 0;\r
 }\r