[HW, VSTAT] Added more attributes to query CA: RESIZE_MAX_WR, CHANGE_PHYSICAL_PORT...
[mirror/winof/.git] / tools / vstat / user / vstat_main.c
1 /*\r
2  * Copyright (c) 2005 Mellanox Technologies.  All rights reserved.\r
3  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. \r
4  *\r
5  * This software is available to you under the OpenIB.org BSD license\r
6  * below:\r
7  *\r
8  *     Redistribution and use in source and binary forms, with or\r
9  *     without modification, are permitted provided that the following\r
10  *     conditions are met:\r
11  *\r
12  *      - Redistributions of source code must retain the above\r
13  *        copyright notice, this list of conditions and the following\r
14  *        disclaimer.\r
15  *\r
16  *      - Redistributions in binary form must reproduce the above\r
17  *        copyright notice, this list of conditions and the following\r
18  *        disclaimer in the documentation and/or other materials\r
19  *        provided with the distribution.\r
20  *\r
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
25  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
26  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
27  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
28  * SOFTWARE.\r
29  *\r
30  * $Id$\r
31  */\r
32 \r
33 \r
34 \r
35 #include "stdio.h"\r
36 #include "string.h"\r
37 #include "stdlib.h"\r
38 \r
39 \r
40 #include <iba/ib_types.h>\r
41 #include <iba/ib_al.h>\r
42 #ifndef WIN32\r
43 #include <complib/cl_device.h>\r
44 #endif\r
45 #include <mthca/mthca_vc.h>\r
46 \r
47 \r
48 #define VEND_ID_MELLNOX 0x02c9\r
49 #define VEND_ID_VOLTAIRE        0x08f1\r
50 \r
51 \r
52 /*******************************************************************\r
53 *******************************************************************/\r
54 \r
55 \r
56 void print64bit(ib_net64_t u64, BOOLEAN hexFormat){\r
57         ib_net64_t mask = (1<<16)-1;\r
58         ib_net16_t tmp;\r
59         int i;\r
60         for(i=0;i<4;i++){\r
61                 tmp = (uint16_t)((u64>>(i*16))& mask);\r
62                 if(hexFormat){\r
63                         printf("%04x",cl_hton16(tmp));\r
64                         if(i<3){\r
65                                 printf(":");\r
66                         }\r
67                 }else{\r
68                         \r
69                         if((tmp>>8)<100){\r
70                                 printf("%02d", tmp>>8);\r
71                         }else{\r
72                                 printf("%03d", tmp>>8);\r
73                         }\r
74                         printf(".");\r
75                         if((tmp&(mask<<8)) <100){\r
76                                 printf("%02d", tmp&(mask<<8));\r
77                         }else{\r
78                                 printf("%03d", tmp&(mask<<8));\r
79                         }\r
80                         \r
81                 }\r
82         }\r
83 }       \r
84 \r
85 void printGUID(ib_net64_t guid){\r
86         printf("\tnode_guid=");\r
87         print64bit(guid, TRUE);\r
88         printf("\n");\r
89 }\r
90 \r
91 void printPortGID(ib_net64_t subnetPrefix, ib_net64_t portGuid){\r
92         printf("\t\tGID[0]=");\r
93         print64bit(subnetPrefix, TRUE);\r
94         printf(":");\r
95         print64bit(portGuid, TRUE);\r
96         printf("\n");\r
97 }\r
98 \r
99 \r
100 void printPortLinkState(int portState){ //TODO: check that these are all the options and that they are correct\r
101         switch(portState){\r
102                 case 1:\r
103                         printf("\t\tport_state=PORT_DOWN (%d)\n",portState);\r
104                         break;\r
105                 case 2:\r
106                         printf("\t\tport_state=PORT_INITIALIZE (%d)\n",portState);\r
107                         break;\r
108                 case 3:\r
109                         printf("\t\tport_state=PORT_ARMED (%d)\n",portState);\r
110                         break;\r
111                 case 4:\r
112                         printf("\t\tport_state=PORT_ACTIVE (%d)\n",portState);\r
113                         break;\r
114                 case 5:\r
115                         printf("\t\tport_state=PORT_ACTDEFER (%d)\n",portState);\r
116                         break;\r
117                 default:\r
118                         printf("\t\tport_state=UNKNOWN (%d)\n",portState); \r
119         }\r
120 }\r
121 \r
122 void printPortPhysState(uint8_t physState){ \r
123         switch(physState){\r
124                 case 1:\r
125                         printf("\t\tport_phys_state=SLEEP (%d)\n",physState);\r
126                         break;\r
127                 case 2:\r
128                         printf("\t\tport_phys_state=POLLING (%d)\n",physState);\r
129                         break;\r
130                 case 3:\r
131                         printf("\t\tport_phys_state=DISABLED (%d)\n",physState);\r
132                         break;\r
133                 case 4:\r
134                         printf("\t\tport_phys_state=CFG_TRAINING (%d)\n",physState);\r
135                         break;\r
136                 case 5:\r
137                         printf("\t\tport_phys_state=LINK_UP (%d)\n",physState);\r
138                         break;\r
139                 case 6:\r
140                         printf("\t\tport_phys_state=LINK_ERROR_RECOVERY (%d)\n",physState);\r
141                         break;\r
142                 case 7:\r
143                         printf("\t\tport_phys_state=PHY_TEST (%d)\n",physState);\r
144                         break;\r
145                 default:\r
146                         printf("\t\tport_phys_state=UNKNOWN (%d)\n",physState); \r
147         }\r
148 }\r
149 \r
150 void printPortRate(int speed, int width, int portState){ \r
151         if (portState == 1){ /* In case the port is in Down state */\r
152                 printf("\t\tlink_speed=NA\n");\r
153                 printf("\t\tlink_width=NA \n\t\trate=NA\n");            \r
154         }else{  \r
155                 switch(speed){\r
156                         case 1:\r
157                                 printf("\t\tlink_speed=2.5 Gbps (%d)\n",speed);\r
158                                 break;\r
159                         case 2:\r
160                                 printf("\t\tlink_speed=5.0 Gbps (%d)\n",speed);\r
161                                 break;\r
162                         case 4:\r
163                                 printf("\t\tlink_speed=10.0 Gbps (%d)\n",speed);\r
164                                 break;\r
165                         default:\r
166                                 printf("\t\tlink_speed=UNKNOWN (%d)\n",speed); \r
167                 }\r
168 \r
169                 switch (width){\r
170                         case 1:\r
171                                 printf("\t\tlink_width=1x (%f) \n\t\trate=%d Gbps\n",width,2.5*speed);\r
172                                 break;\r
173                         case 2:\r
174                                 printf("\t\tlink_width=4x (%d) \n\t\trate=%d Gbps\n",width,10*speed);\r
175                                 break;\r
176                         case 4:\r
177                                 printf("\t\tlink_width=8x (%d) \n\t\trate=%d Gbps\n",width,20*speed);\r
178                                 break;\r
179                         case 8:\r
180                                 printf("\t\tlink_width=12x (%d) \n\t\trate=%d Gbps\n",width,30*speed);\r
181                                 break;\r
182                         default:\r
183                                 printf("\t\tlink_width=UNKNOWN (%d)\n",width);\r
184                 }\r
185         }\r
186                 \r
187 \r
188 }\r
189 \r
190 \r
191 void printPortMTU(int mtu){ //TODO: check that these are all the options and that they are correct\r
192         switch(mtu){\r
193                 case 1:\r
194                         printf("\t\tmax_mtu=256 (%d)\n",mtu);\r
195                         break;\r
196                 case 2:\r
197                         printf("\t\tmax_mtu=512 (%d)\n",mtu);\r
198                         break;\r
199                 case 3:\r
200                         printf("\t\tmax_mtu=1024 (%d)\n",mtu);\r
201                         break;\r
202                 case 4:\r
203                         printf("\t\tmax_mtu=2048 (%d)\n",mtu);\r
204                         break;\r
205                 case 5:\r
206                         printf("\t\tmax_mtu=4096 (%d)\n",mtu);\r
207                         break;\r
208                 default:\r
209                         printf("\t\tmax_mtu=UNKNOWN (%d)\n",mtu); \r
210         }\r
211 }\r
212 \r
213 void printPortCaps(ib_port_cap_t *ibal_port_cap_p)\r
214 {\r
215 #define PRINT_CAP(cap, name)    if (ibal_port_cap_p->cap) printf( #name "," )\r
216         \r
217         printf("\t\tcapabilities: ");\r
218         PRINT_CAP(cm, CM);\r
219         PRINT_CAP(snmp, SNMP_TUNNEL);\r
220         PRINT_CAP(dev_mgmt, DEVICE_MGMT);\r
221         PRINT_CAP(sm_disable, SM_DISABLED);\r
222         PRINT_CAP(sm, SM);\r
223         PRINT_CAP(vend, VENDOR_CLASS);\r
224         PRINT_CAP(notice, NOTICE);\r
225         PRINT_CAP(trap, TRAP);\r
226         PRINT_CAP(apm, APM);\r
227         PRINT_CAP(slmap, SL_MAP);\r
228         PRINT_CAP(ledinfo, LED_INFO);\r
229         PRINT_CAP(client_reregister, CLIENT_REG);\r
230         PRINT_CAP(sysguid, SYSGUID);\r
231         PRINT_CAP(boot_mgmt, BOOT_MGMT);\r
232         PRINT_CAP(pkey_switch_ext_port, PKEY_SW_EXT_PORT_TRAP);\r
233         PRINT_CAP(link_rtl, LINK_LATENCY);\r
234         PRINT_CAP(reinit, REINIT);\r
235         PRINT_CAP(ipd, OPT_IPD);\r
236         PRINT_CAP(mkey_nvram, MKEY_NVRAM);\r
237         PRINT_CAP(pkey_nvram, PKEY_NVRAM);\r
238         printf("\n");\r
239 }\r
240 \r
241 void printPortActiveSpeed(uint8_t speed){ \r
242         switch(speed){\r
243                 case 1:\r
244                         printf("\t\tactive_speed=2.5 Gbps (%d)\n",speed);\r
245                         break;\r
246                 case 2:\r
247                         printf("\t\tactive_speed=5.0 Gbps (%d)\n",speed);\r
248                         break;\r
249                 case 4:\r
250                         printf("\t\tactive_speed=10.0 Gbps (%d)\n",speed);\r
251                         break;\r
252                 default:\r
253                         printf("\t\tactive_speed=UNKNOWN (%d)\n",speed); \r
254         }\r
255 }\r
256 \r
257 void printPortInfo(ib_port_attr_t* portPtr, ib_port_info_t portInfo, BOOLEAN fullPrint){\r
258         printf("\t\tport=%d\n", portPtr->port_num);\r
259         printPortLinkState(portPtr->link_state);\r
260         printPortRate(portInfo.link_speed>>4,portInfo.link_width_active, portPtr->link_state);\r
261         printPortPhysState(portPtr->phys_state);\r
262         printPortActiveSpeed(portPtr->active_speed);\r
263         printf("\t\tsm_lid=0x%04x\n", cl_ntoh16(portPtr->sm_lid));\r
264         printf("\t\tport_lid=0x%04x\n", cl_ntoh16(portPtr->lid));\r
265         printf("\t\tport_lmc=0x%x\n", portPtr->lmc);\r
266         printPortMTU(portPtr->mtu);\r
267         if(fullPrint){\r
268                 printf("\t\tmax_msg_sz=0x%x     (Max message size)\n", portPtr->max_msg_size);\r
269                 printPortCaps( &portPtr->cap );\r
270                 printf("\t\tmax_vl_num=0x%x             (Maximum number of VL supported by this port)\n", portPtr->max_vls);\r
271                 printf("\t\tbad_pkey_counter=0x%x       (Bad PKey counter)\n", portPtr->pkey_ctr);\r
272                 printf("\t\tqkey_viol_counter=0x%x      (QKey violation counter)\n", portPtr->qkey_ctr);\r
273                 printf("\t\tsm_sl=0x%x          (IB_SL to be used in communication with subnet manager)\n", portPtr->sm_sl);\r
274                 printf("\t\tpkey_tbl_len=0x%x   (Current size of pkey table)\n", portPtr->num_pkeys);\r
275                 printf("\t\tgid_tbl_len=0x%x    (Current size of GID table)\n", portPtr->num_gids);\r
276                 printf("\t\tsubnet_timeout=0x%x (Subnet Timeout for this port (see PortInfo))\n", portPtr->subnet_timeout);\r
277                 printf("\t\tinitTypeReply=0x%x  (optional InitTypeReply value. 0 if not supported)\n", portPtr->init_type_reply);\r
278                 printPortGID(portPtr->p_gid_table->unicast.prefix, portPtr->p_gid_table->unicast.interface_id);\r
279         }\r
280         printf("\n");\r
281 }\r
282 \r
283 void print_uplink_info(ib_ca_attr_t* ca_attr)\r
284 {\r
285         uplink_info_t*p_uplink_info = mthca_get_uplink_info(ca_attr);\r
286         char *bus_type, *link_speed, cap;\r
287         int freq;\r
288 \r
289         switch (p_uplink_info->bus_type) {\r
290                 case UPLINK_BUS_PCI: bus_type = "PCI"; break;\r
291                 case UPLINK_BUS_PCIX: bus_type = "PCI_X"; break;\r
292                 case UPLINK_BUS_PCIE: bus_type = "PCI_E"; break;\r
293                 default: printf("\tuplink={BUS=UNRECOGNIZED (%d)}\n", p_uplink_info->bus_type); return;\r
294         }\r
295 \r
296         switch (p_uplink_info->bus_type) {\r
297                 case UPLINK_BUS_PCI: \r
298                 case UPLINK_BUS_PCIX:\r
299                         if (p_uplink_info->u.pci_x.capabilities == UPLINK_BUS_PCIX_133)\r
300                                 freq = 133;\r
301                         else\r
302                                 freq = 66;\r
303                         printf("\tuplink={BUS=%s, CAPS=%d MHz}\n", bus_type, freq ); \r
304                         return;\r
305 \r
306                 case UPLINK_BUS_PCIE:\r
307                         cap = p_uplink_info->u.pci_e.capabilities;\r
308                         if (p_uplink_info->u.pci_e.link_speed == UPLINK_BUS_PCIE_SDR)\r
309                                 link_speed = "2.5 Gbps";\r
310                         else\r
311                         if (p_uplink_info->u.pci_e.link_speed == UPLINK_BUS_PCIE_DDR)\r
312                                 link_speed = "5.0 Gbps";\r
313                         else\r
314                                 link_speed = "unknown";\r
315                         printf("\tuplink={BUS=%s, SPEED=%s, WIDTH=x%d, CAPS=%s*x%d}\n",\r
316                                 bus_type, link_speed, p_uplink_info->u.pci_e.link_width,\r
317                                 (cap&1) ? "2.5" : "5", cap>>2 ); \r
318                         return;\r
319         }\r
320 }\r
321 \r
322 void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, ib_port_info_t* vstat_port_info, BOOLEAN fullPrint){\r
323         int i;\r
324 \r
325         printf("\n\thca_idx=%d\n", idx);\r
326         if (ca_attr->dev_id & 1)\r
327                 printf("\tATTENTION! \n\t    The device is in 'Flash Recovery' mode, probably due to an incorrect firmware."\r
328                         "\n\t    Use firmware tools to solve the problem.\n",idx);\r
329         /*printf("\tpci_location={BUS=NA,DEV/FUNC=NA}\n");*/\r
330         print_uplink_info(ca_attr);\r
331         printf("\tvendor_id=0x%04x\n", ca_attr->vend_id);\r
332         printf("\tvendor_part_id=0x%04x\n", ca_attr->dev_id);\r
333         printf("\thw_ver=0x%x\n", ca_attr->revision); //TODO: ???\r
334         if(ca_attr->vend_id == VEND_ID_MELLNOX || ca_attr->vend_id == VEND_ID_VOLTAIRE) {\r
335                 printf("\tfw_ver=%d.%.2d.%.4d\n",\r
336                 (uint16_t )(ca_attr->fw_ver>>32),\r
337                 (uint16_t)(ca_attr->fw_ver>>16),\r
338                 (uint16_t )(ca_attr->fw_ver));\r
339                 printf("\tPSID=%s\n",mthca_get_board_id(ca_attr));\r
340         }else{\r
341                 printf("\tfw_ver=0x%I64x\n",ca_attr->fw_ver);\r
342         }\r
343         printGUID(ca_attr->ca_guid);\r
344         if(fullPrint){\r
345                 printf("\tnum_phys_ports = %d\n",ca_attr->num_ports);\r
346                 printf("\tmax_num_qp = 0x%x             (Maximum Number of QPs supported)\n", ca_attr->max_qps);\r
347                 printf("\tmax_qp_ous_wr = 0x%x          (Maximum Number of outstanding WR on any WQ)\n", ca_attr->max_wrs);\r
348                 printf("\tmax_num_sg_ent = 0x%x         (Max num of scatter/gather entries for WQE other than RD)\n", ca_attr->max_sges);\r
349                 printf("\tmax_num_sg_ent_rd = 0x%x              (Max num of scatter/gather entries for RD WQE)\n",  ca_attr->max_rd_sges);\r
350                 printf("\tmax_num_srq = 0x%x            (Maximum Number of SRQs supported)\n", ca_attr->max_srq);\r
351                 printf("\tmax_wqe_per_srq = 0x%x        (Maximum Number of outstanding WR on any SRQ)\n", ca_attr->max_srq_wrs);\r
352                 printf("\tmax_srq_sentries = 0x%x               (Maximum Number of scatter/gather entries for SRQ WQE)\n", ca_attr->max_srq_sges);\r
353                 printf("\tsrq_resize_supported = %d     (SRQ resize supported)\n", ca_attr->modify_srq_depth);\r
354                 printf("\tmax_num_cq = 0x%x             (Max num of supported CQs)\n", ca_attr->max_cqs);\r
355                 printf("\tmax_num_ent_cq = 0x%x (Max num of supported entries per CQ)\n", ca_attr->max_cqes);\r
356                 printf("\tmax_num_mr = 0x%x             (Maximum number of memory region supported)\n", ca_attr->init_regions);\r
357                 printf("\tmax_mr_size = 0x%x    (Largest contiguous block of memory region in bytes)\n", ca_attr->init_region_size);\r
358                 printf("\tmax_pd_num = 0x%x             (Maximum number of protection domains supported)\n", ca_attr->max_pds);\r
359                 printf("\tpage_size_cap = 0x%x          (Largest page size supported by this HCA)\n",ca_attr->p_page_size[ca_attr->num_page_sizes-1]);\r
360 \r
361                 printf("\tlocal_ca_ack_delay = 0x%x     (Log2 4.096usec Max. RX to ACK or NAK delay)\n", ca_attr->local_ack_delay);\r
362                 printf("\tmax_qp_ous_rd_atom = 0x%x     (Maximum number of oust. RDMA read/atomic as target)\n",ca_attr->max_qp_resp_res);\r
363                 printf("\tmax_ee_ous_rd_atom = 0                (EE Maximum number of outs. RDMA read/atomic as target)\n");\r
364                 printf("\tmax_res_rd_atom = 0x%x                (Max. Num. of resources used for RDMA read/atomic as target)\n",ca_attr->max_resp_res);\r
365                 printf("\tmax_qp_init_rd_atom = 0x%x    (Max. Num. of outs. RDMA read/atomic as initiator)\n",ca_attr->max_qp_init_depth);\r
366                 printf("\tmax_ee_init_rd_atom = 0               (EE Max. Num. of outs. RDMA read/atomic as initiator)\n");\r
367                 printf("\tatomic_cap = %s               (Level of Atomicity supported)\n",ca_attr->atomicity == IB_ATOMIC_GLOBAL?"GLOBAL":\r
368                                                                                                                                         ca_attr->atomicity == IB_ATOMIC_LOCAL?"LOCAL":"NORMAL");\r
369                 printf("\tmax_ee_num = 0x0              (Maximum number of EEC supported)\n");\r
370                 printf("\tmax_rdd_num = 0x0             (Maximum number of IB_RDD supported)\n");\r
371                 printf("\tmax_mw_num = 0x%x             (Maximum Number of memory windows supported)\n", ca_attr->init_windows);\r
372                 printf("\tmax_raw_ipv6_qp = 0x%x                (Maximum number of Raw IPV6 QPs supported)\n", ca_attr->max_ipv6_qps);\r
373                 printf("\tmax_raw_ethy_qp = 0x%x                (Maximum number of Raw Ethertypes QPs supported)\n", ca_attr->max_ether_qps);\r
374                 printf("\tmax_mcast_grp_num = 0x%x      (Maximum Number of multicast groups)\n", ca_attr->max_mcast_grps);\r
375                 printf("\tmax_mcast_qp_attach_num = 0x%x        (Maximum number of QP per multicast group)\n", ca_attr->max_qps_per_mcast_grp);\r
376                 printf("\tmax_ah_num = 0x%x             (Maximum number of address handles)\n", ca_attr->max_addr_handles);\r
377                 printf("\tmax_num_fmr = 0x%x            (Maximum number FMRs)\n", ca_attr->max_fmr);\r
378                 printf("\tmax_num_map_per_fmr = 0x%x    (Maximum number of (re)maps per FMR before an unmap operation in required)\n", ca_attr->max_map_per_fmr);\r
379                 printf("\tmodify_wr_depth = %d          (Capabilities: change QP depth during a modify QP)\n", !!ca_attr->modify_wr_depth);\r
380                 printf("\tmodify_srq_depth = %d                 (Capabilities: change SRQ depth - Not supported by driver!)\n", !!ca_attr->modify_srq_depth);\r
381                 printf("\tchange_primary_port = %d              (Capabilities: change primary port for a QP during a SQD->RTS transition)\n", !!ca_attr->change_primary_port);\r
382                 printf("\tav_port_check = %d            (Capabilities: check port number in address handles)\n", !!ca_attr->av_port_check);\r
383                 printf("\tinit_type_support = %d                (Capabilities: set init_type)\n", !!ca_attr->init_type_support);\r
384                 printf("\tshutdown_port = %d            (Capabilities: shutdown port support)\n", !!ca_attr->shutdown_port_capability);\r
385         }else{\r
386                 printf("\tnum_phys_ports=%d\n",         ca_attr->num_ports);\r
387         }\r
388         for (i = 0; i<ca_attr->num_ports; i++){\r
389                 printPortInfo(ca_attr->p_port_attr+i, vstat_port_info[i], fullPrint);\r
390         }       \r
391 }\r
392 /* Internal Functions */\r
393 \r
394 void vstat_get_counters(ib_ca_handle_t VOID_PTR64 h_ca,uint8_t port_num)\r
395 {\r
396         ib_mad_t                        *mad_in = NULL;\r
397         ib_mad_t                        *mad_out = NULL;\r
398         ib_port_counters_t      *port_counters;\r
399         ib_api_status_t         ib_status = IB_SUCCESS;\r
400         int i;\r
401         \r
402         mad_out = (ib_mad_t*)cl_zalloc(256);\r
403         CL_ASSERT(mad_out);\r
404 \r
405         mad_in = (ib_mad_t*)cl_zalloc(256);\r
406         CL_ASSERT(mad_in);\r
407 \r
408 \r
409         mad_in->attr_id = IB_MAD_ATTR_PORT_CNTRS;\r
410         mad_in->method = IB_MAD_METHOD_GET;\r
411         mad_in->base_ver = 1;\r
412         mad_in->class_ver =1;\r
413         mad_in->mgmt_class = IB_MCLASS_PERF;\r
414 \r
415         port_counters = (ib_port_counters_t*)(((ib_gmp_t*)mad_in)->data);\r
416 \r
417         port_counters->port_select= port_num;\r
418         port_counters->counter_select= 0xff;\r
419 \r
420         ib_status = ib_local_mad(h_ca ,port_num ,mad_in ,mad_out);\r
421         if(ib_status != IB_SUCCESS)\r
422         {\r
423                 printf("ib_local_mad failed with status = %d\n", ib_status);\r
424                 return;\r
425         }\r
426         \r
427         port_counters = (ib_port_counters_t*)(((ib_gmp_t*)mad_out)->data);\r
428 \r
429         printf("\n\tport counters for port %d\n",port_num);\r
430         printf("\t\tlink_error_recovery_counter\t0x%x \n",port_counters->link_error_recovery_counter);\r
431         printf("\t\tlink_down_counter\t\t0x%x \n",port_counters->link_down_counter);\r
432         printf("\t\tport_rcv_errors\t\t\t0x%x \n",CL_NTOH16(port_counters->port_rcv_errors));\r
433         printf("\t\tport_rcv_remote_physical_errors\t0x%x \n",CL_NTOH16(port_counters->port_rcv_remote_physical_errors));\r
434         printf("\t\tport_rcv_switch_relay_errors\t0x%x \n",CL_NTOH16(port_counters->port_rcv_switch_relay_errors));\r
435         printf("\t\tport_xmit_discard\t\t0x%x \n",CL_NTOH16(port_counters->port_xmit_discard));\r
436         printf("\t\tport_xmit_constraint_errors\t0x%x \n",port_counters->port_xmit_constraint_errors);\r
437         printf("\t\tport_rcv_constraint_errors\t0x%x \n",port_counters->port_rcv_constraint_errors);\r
438         printf("\t\tvl15_dropped\t\t\t0x%x \n",CL_NTOH16(port_counters->vl15_dropped));\r
439         printf("\t\tport_rcv_data\t\t\t0x%x \n",CL_NTOH32(port_counters->port_rcv_data));\r
440         printf("\t\tport_xmit_data\t\t\t0x%x \n",CL_NTOH32(port_counters->port_xmit_data));\r
441         printf("\t\tport_rcv_pkts\t\t\t0x%x \n",CL_NTOH32(port_counters->port_rcv_pkts));\r
442         printf("\t\tport_xmit_pkts\t\t\t0x%x \n\n",CL_NTOH32(port_counters->port_xmit_pkts));\r
443         \r
444 }\r
445 \r
446 \r
447 void vstat_get_port_info(ib_ca_handle_t VOID_PTR64 h_ca,uint8_t port_num, ib_port_info_t* vstat_port_info)\r
448 {\r
449         ib_mad_t                        *mad_in = NULL;\r
450         ib_mad_t                        *mad_out = NULL;\r
451         ib_api_status_t         ib_status = IB_SUCCESS;\r
452         int i;\r
453         \r
454         mad_out = (ib_mad_t*)cl_zalloc(256);\r
455         CL_ASSERT(mad_out);\r
456 \r
457         mad_in = (ib_mad_t*)cl_zalloc(256);\r
458         CL_ASSERT(mad_in);\r
459 \r
460 \r
461         mad_in->attr_id = IB_MAD_ATTR_PORT_INFO;\r
462         mad_in->method = IB_MAD_METHOD_GET;\r
463         mad_in->base_ver = 1;\r
464         mad_in->class_ver =1;\r
465         mad_in->mgmt_class = IB_MCLASS_SUBN_LID;\r
466         \r
467 \r
468 \r
469         ib_status = ib_local_mad(h_ca ,port_num ,mad_in ,mad_out);\r
470         if(ib_status != IB_SUCCESS &&  0 != mad_in->status )\r
471         {\r
472                 printf("ib_local_mad failed with status = %d mad status = %d\n", ib_status,mad_in->status);\r
473                 return;\r
474         }\r
475 \r
476         cl_memcpy(vstat_port_info,(ib_port_info_t*)(((ib_smp_t*)mad_out)->data),sizeof(ib_port_info_t));\r
477 \r
478         \r
479 }\r
480 \r
481 \r
482 ib_api_status_t\r
483 vstat_ca_attr(\r
484         boolean_t modify_attr,\r
485         BOOLEAN fullPrint,\r
486         BOOLEAN getCounters\r
487         )\r
488 {\r
489         ib_al_handle_t VOID_PTR64               h_al = NULL;\r
490         ib_api_status_t         ib_status = IB_SUCCESS;\r
491         ib_api_status_t         ret_status = IB_SUCCESS;\r
492         size_t                  guid_count;\r
493         ib_net64_t              *ca_guid_array;\r
494         ib_ca_attr_t            *vstat_ca_attr;\r
495         ib_port_info_t          vstat_port_info[2];\r
496         size_t                  i;\r
497         ib_ca_handle_t VOID_PTR64       h_ca = NULL;\r
498         uint32_t                        bsize;\r
499         ib_port_attr_mod_t port_attr_mod;\r
500         uint8_t                 port_idx;\r
501 \r
502         while(1)\r
503         {\r
504                 /*\r
505                  * Open the AL instance\r
506                  */\r
507                 ib_status = ib_open_al(&h_al);\r
508                 if(ib_status != IB_SUCCESS)\r
509                 {\r
510                         printf("ib_open_al failed status = %d\n", ib_status);\r
511                         ret_status = ib_status;                 \r
512                         break;\r
513                 }\r
514                 //xxxx\r
515                 //printf("ib_open_al PASSED.\n");\r
516                 //xxx\r
517                 CL_ASSERT(h_al);\r
518 \r
519                 /*\r
520                  * Get the Local CA Guids\r
521                  */\r
522                 ib_status = ib_get_ca_guids(h_al, NULL, &guid_count);\r
523                 if(ib_status != IB_INSUFFICIENT_MEMORY)\r
524                 {\r
525                         printf("ib_get_ca_guids1 failed status = %d\n", (uint32_t)ib_status);\r
526                         ret_status = ib_status;                 \r
527                         goto Cleanup1;\r
528                 }\r
529 \r
530                 \r
531 \r
532                 /*\r
533                  * If no CA's Present then return\r
534                  */\r
535 \r
536                 if(guid_count == 0)\r
537                         goto Cleanup1;\r
538 \r
539                 \r
540                 ca_guid_array = (ib_net64_t*)cl_malloc(sizeof(ib_net64_t) * guid_count);\r
541                 CL_ASSERT(ca_guid_array);\r
542                 \r
543                 ib_status = ib_get_ca_guids(h_al, ca_guid_array, &guid_count);\r
544                 if(ib_status != IB_SUCCESS)\r
545                 {\r
546                         printf("ib_get_ca_guids2 failed with status = %d\n", ib_status);\r
547                         ret_status = ib_status;                 \r
548                         goto Cleanup1;\r
549                 }\r
550 \r
551                 \r
552 \r
553                 /*\r
554                  * For Each CA Guid found Open the CA,\r
555                  * Query the CA Attribute and close the CA\r
556                  */\r
557                 for(i=0; i < guid_count; i++)\r
558                 {\r
559 \r
560                         /* Open the CA */\r
561                         ib_status = ib_open_ca(h_al,\r
562                                 ca_guid_array[i],\r
563                                 NULL,\r
564                                 NULL,   //ca_context\r
565                                 &h_ca);\r
566 \r
567                         if(ib_status != IB_SUCCESS)\r
568                         {\r
569                                 printf("ib_open_ca failed with status = %d\n", ib_status);\r
570                                 ret_status = ib_status;                         \r
571                                 goto Cleanup1;\r
572                         }\r
573 \r
574                         //xxx\r
575                         //printf("ib_open_ca passed i=%d\n",i); \r
576                         //xxx\r
577 \r
578 \r
579                         /* Query the CA */\r
580                         bsize = 0;\r
581                         ib_status = ib_query_ca(h_ca, NULL, &bsize);\r
582                         if(ib_status != IB_INSUFFICIENT_MEMORY)\r
583                         {\r
584                                 printf("ib_query_ca failed with status = %d\n", ib_status);\r
585                                 ret_status = ib_status;\r
586                                 goto Cleanup2;\r
587                         }\r
588                         CL_ASSERT(bsize);\r
589                         //xxxx\r
590                         //printf("ib_query_ca PASSED bsize = 0x%x.\n",bsize);\r
591                         //xxx\r
592                         /* Allocate the memory needed for query_ca */\r
593 \r
594                         vstat_ca_attr = (ib_ca_attr_t *)cl_zalloc(bsize);\r
595                         CL_ASSERT(vstat_ca_attr);\r
596 \r
597                         ib_status = ib_query_ca(h_ca, vstat_ca_attr, &bsize);\r
598                         if(ib_status != IB_SUCCESS)\r
599                         {\r
600                                 printf("ib_query_ca failed with status = %d\n", ib_status);\r
601                                 ret_status = ib_status;\r
602                                 goto Cleanup2;\r
603                         }\r
604 \r
605                         for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r
606                                 vstat_get_port_info(h_ca ,port_idx+1,&vstat_port_info[port_idx]);\r
607                         }\r
608 \r
609                         vstat_print_ca_attr((int)i, vstat_ca_attr, vstat_port_info, fullPrint);\r
610                         if(getCounters)\r
611                         {\r
612                                 for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r
613                                         vstat_get_counters(h_ca ,port_idx+1);\r
614                                 }\r
615                         }\r
616                         \r
617                         /* Free the memory */\r
618                         cl_free(vstat_ca_attr);\r
619                         vstat_ca_attr = NULL;\r
620                         /* Close the current open CA */\r
621                         ib_status = ib_close_ca(h_ca, NULL);\r
622                         if(ib_status != IB_SUCCESS)\r
623                         {\r
624                                 printf("ib_close_ca failed status = %d", ib_status);\r
625                                 ret_status = ib_status;\r
626                         }\r
627                         h_ca = NULL;\r
628 \r
629                 }\r
630 \r
631 Cleanup2:\r
632                 if(h_ca != NULL)\r
633                 {\r
634                         ib_status = ib_close_ca(h_ca, NULL);\r
635                         if(ib_status != IB_SUCCESS)\r
636                         {\r
637                                 printf("ib_close_ca failed status = %d", ib_status);\r
638                         }\r
639                 }\r
640 \r
641 Cleanup1:\r
642                 cl_free(ca_guid_array);\r
643                 ib_status = ib_close_al(h_al);\r
644 \r
645                 if(ib_status != IB_SUCCESS)\r
646                 {\r
647                         printf("ib_close_al failed status = %d", ib_status);\r
648                 }\r
649 \r
650                 break;\r
651 \r
652         } //End of while(1)\r
653 \r
654         \r
655         return ret_status;\r
656 }\r
657 \r
658 void vstat_help()\r
659 {\r
660         printf("\n\tUsage: vstat [-v] [-c]\n");\r
661         printf("\t\t -v - verbose mode\n");\r
662         printf("\t\t -c - HCA error/statistic counters\n");\r
663 }\r
664 \r
665 int32_t __cdecl\r
666 main(\r
667         int32_t argc,\r
668         char* argv[])\r
669 {\r
670         ib_api_status_t ib_status;\r
671         BOOLEAN fullPrint = FALSE;\r
672         BOOLEAN getCounters = FALSE;\r
673         BOOLEAN showHelp = FALSE;\r
674         if(argc>1){\r
675                 int i = 2;\r
676                 while(i<=argc){\r
677                         if(!_stricmp(argv[i-1], "-v")){\r
678                                 fullPrint = TRUE;\r
679                                 i+=1;\r
680                         }else if(!_stricmp(argv[i-1], "-h") || \r
681                                 !_stricmp(argv[i-1], "-help")){\r
682                                 showHelp = TRUE;\r
683                                 i+=1;\r
684                         }else if(!_stricmp(argv[i-1], "-c")){\r
685                                 getCounters = TRUE;\r
686                                 i+=1;\r
687                         }else{\r
688                                 i+=2;\r
689                         }\r
690                 }\r
691         }\r
692         if (showHelp)\r
693                 vstat_help();\r
694         else\r
695                 ib_status = vstat_ca_attr(FALSE, fullPrint,getCounters);\r
696 \r
697         return 0;\r
698 }\r
699 \r