[TOOLS] add link speed and width to vstat
authorsleybo <sleybo@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 5 Mar 2007 07:33:00 +0000 (07:33 +0000)
committersleybo <sleybo@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 5 Mar 2007 07:33:00 +0000 (07:33 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@604 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

tools/vstat/user/vstat_main.c

index 9e219b5..2a8579c 100644 (file)
@@ -119,6 +119,40 @@ void printPortLinkState(int portState){ //TODO: check that these are all the opt
        }\r
 }\r
 \r
+void printPortRate(int speed, int width){ \r
+       switch(speed){\r
+               case 1:\r
+                       printf("\t\tlink_speed=2.5Gbps (%d)\n",speed);\r
+                       break;\r
+               case 2:\r
+                       printf("\t\tlink_speed=5Gbps (%d)\n",speed);\r
+                       break;\r
+               case 4:\r
+                       printf("\t\tlink_speed=10Gbps (%d)\n",speed);\r
+                       break;\r
+               default:\r
+                       printf("\t\tlink_speed=UNKNOWN (%d)\n",speed); \r
+       }\r
+\r
+       switch (width){\r
+               case 1:\r
+                       printf("\t\tlink_width=1x (%d) \n\t\trate=%d\n",width,1*speed);\r
+                       break;\r
+               case 2:\r
+                       printf("\t\tlink_width=4x (%d) \n\t\trate=%d\n",width,10*speed);\r
+                       break;\r
+               case 4:\r
+                       printf("\t\tlink_width=8x (%d) \n\t\trate=%d\n",width,20*speed);\r
+                       break;\r
+               case 8:\r
+                       printf("\t\tlink_width=12x (%d) \n\t\trate=%d\n",width,30*speed);\r
+                       break;\r
+               default:\r
+                       printf("\t\tlink_width=UNKNOWN (%d)\n",width);\r
+       }\r
+               \r
+\r
+}\r
 \r
 \r
 void printPortMTU(int mtu){ //TODO: check that these are all the options and that they are correct\r
@@ -170,9 +204,10 @@ void printPortCaps(ib_port_cap_t *ibal_port_cap_p)
        PRINT_CAP(pkey_nvram, PKEY_NVRAM);\r
        printf("\n");\r
 }\r
-void printPortInfo(ib_port_attr_t* portPtr, BOOLEAN fullPrint){\r
+void printPortInfo(ib_port_attr_t* portPtr, ib_port_info_t portInfo, BOOLEAN fullPrint){\r
        printf("\t\tport=%d\n", portPtr->port_num);\r
        printPortLinkState(portPtr->link_state);\r
+       printPortRate(portInfo.link_speed>>4,portInfo.link_width_active);\r
        printf("\t\tsm_lid=0x%04x\n", cl_ntoh16(portPtr->sm_lid));\r
        printf("\t\tport_lid=0x%04x\n", cl_ntoh16(portPtr->lid));\r
        printf("\t\tport_lmc=0x%x\n", portPtr->lmc);\r
@@ -233,7 +268,7 @@ void print_uplink_info(ib_ca_attr_t* ca_attr)
        }\r
 }\r
 \r
-void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, BOOLEAN fullPrint){\r
+void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, ib_port_info_t* vstat_port_info, BOOLEAN fullPrint){\r
        int i;\r
 \r
        printf("\n\thca_idx=%d\n", idx);\r
@@ -294,7 +329,7 @@ void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, BOOLEAN fullPrint){
                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, fullPrint);\r
+               printPortInfo(ca_attr->p_port_attr+i, vstat_port_info[i], fullPrint);\r
        }       \r
 }\r
 /* Internal Functions */\r
@@ -351,6 +386,42 @@ void vstat_get_counters(ib_ca_handle_t h_ca,uint8_t port_num)
        \r
 }\r
 \r
+\r
+void vstat_get_port_info(ib_ca_handle_t h_ca,uint8_t port_num, ib_port_info_t* vstat_port_info)\r
+{\r
+       ib_mad_t                        *mad_in = NULL;\r
+       ib_mad_t                        *mad_out = NULL;\r
+       ib_api_status_t         ib_status = IB_SUCCESS;\r
+       int i;\r
+       \r
+       mad_out = (ib_mad_t*)cl_zalloc(256);\r
+       CL_ASSERT(mad_out);\r
+\r
+       mad_in = (ib_mad_t*)cl_zalloc(256);\r
+       CL_ASSERT(mad_in);\r
+\r
+\r
+       mad_in->attr_id = IB_MAD_ATTR_PORT_INFO;\r
+       mad_in->method = IB_MAD_METHOD_GET;\r
+       mad_in->base_ver = 1;\r
+       mad_in->class_ver =1;\r
+       mad_in->mgmt_class = IB_MCLASS_SUBN_LID;\r
+       \r
+\r
+\r
+       ib_status = ib_local_mad(h_ca ,port_num ,mad_in ,mad_out);\r
+       if(ib_status != IB_SUCCESS &&  0 != mad_in->status )\r
+       {\r
+               printf("ib_local_mad failed with status = %d mad status = %d\n", ib_status,mad_in->status);\r
+               return;\r
+       }\r
+\r
+       cl_memcpy(vstat_port_info,(ib_port_info_t*)(((ib_smp_t*)mad_out)->data),sizeof(ib_port_info_t));\r
+\r
+       \r
+}\r
+\r
+\r
 ib_api_status_t\r
 vstat_ca_attr(\r
        boolean_t modify_attr,\r
@@ -364,6 +435,7 @@ vstat_ca_attr(
        size_t                  guid_count;\r
        ib_net64_t              *ca_guid_array;\r
        ib_ca_attr_t            *vstat_ca_attr;\r
+       ib_port_info_t          vstat_port_info[2];\r
        size_t                  i;\r
        ib_ca_handle_t  h_ca = NULL;\r
        uint32_t                        bsize;\r
@@ -473,10 +545,11 @@ vstat_ca_attr(
                                goto Cleanup2;\r
                        }\r
 \r
+                       for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r
+                               vstat_get_port_info(h_ca ,port_idx+1,&vstat_port_info[port_idx]);\r
+                       }\r
 \r
-                       \r
-\r
-                       vstat_print_ca_attr((int)i, vstat_ca_attr, fullPrint);\r
+                       vstat_print_ca_attr((int)i, vstat_ca_attr, vstat_port_info, fullPrint);\r
                        if(getCounters)\r
                        {\r
                                for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r