[etc] Fix a build break (the build it self would simply die)
[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 printPortRate(int speed, int width, int portState){ \r
123         if (portState == 1){ /* In case the port is in Down state */\r
124                 printf("\t\tlink_speed=NA\n");\r
125                 printf("\t\tlink_width=NA \n\t\trate=NA\n");            \r
126         }else{  \r
127                 switch(speed){\r
128                         case 1:\r
129                                 printf("\t\tlink_speed=2.5Gbps (%d)\n",speed);\r
130                                 break;\r
131                         case 2:\r
132                                 printf("\t\tlink_speed=5Gbps (%d)\n",speed);\r
133                                 break;\r
134                         \r
135                         case 4:\r
136                                 printf("\t\tlink_speed=10Gbps (%d)\n",speed);\r
137                                 break;\r
138                         default:\r
139                                 printf("\t\tlink_speed=UNKNOWN (%d)\n",speed); \r
140                 }\r
141 \r
142                 switch (width){\r
143                         case 1:\r
144                                 printf("\t\tlink_width=1x (%d) \n\t\trate=%d\n",width,1*speed);\r
145                                 break;\r
146                         case 2:\r
147                                 printf("\t\tlink_width=4x (%d) \n\t\trate=%d\n",width,10*speed);\r
148                                 break;\r
149                         case 4:\r
150                                 printf("\t\tlink_width=8x (%d) \n\t\trate=%d\n",width,20*speed);\r
151                                 break;\r
152                         case 8:\r
153                                 printf("\t\tlink_width=12x (%d) \n\t\trate=%d\n",width,30*speed);\r
154                                 break;\r
155                         default:\r
156                                 printf("\t\tlink_width=UNKNOWN (%d)\n",width);\r
157                 }\r
158         }\r
159                 \r
160 \r
161 }\r
162 \r
163 \r
164 void printPortMTU(int mtu){ //TODO: check that these are all the options and that they are correct\r
165         switch(mtu){\r
166                 case 1:\r
167                         printf("\t\tmax_mtu=256 (%d)\n",mtu);\r
168                         break;\r
169                 case 2:\r
170                         printf("\t\tmax_mtu=512 (%d)\n",mtu);\r
171                         break;\r
172                 case 3:\r
173                         printf("\t\tmax_mtu=1024 (%d)\n",mtu);\r
174                         break;\r
175                 case 4:\r
176                         printf("\t\tmax_mtu=2048 (%d)\n",mtu);\r
177                         break;\r
178                 case 5:\r
179                         printf("\t\tmax_mtu=4096 (%d)\n",mtu);\r
180                         break;\r
181                 default:\r
182                         printf("\t\tmax_mtu=UNKNOWN (%d)\n",mtu); \r
183         }\r
184 }\r
185 \r
186 void printPortCaps(ib_port_cap_t *ibal_port_cap_p)\r
187 {\r
188 #define PRINT_CAP(cap, name)    if (ibal_port_cap_p->cap) printf( #name "," )\r
189         \r
190         printf("\t\tcapabilities: ");\r
191         PRINT_CAP(cm, CM);\r
192         PRINT_CAP(snmp, SNMP_TUNNEL);\r
193         PRINT_CAP(dev_mgmt, DEVICE_MGMT);\r
194         PRINT_CAP(sm_disable, SM_DISABLED);\r
195         PRINT_CAP(sm, SM);\r
196         PRINT_CAP(vend, VENDOR_CLASS);\r
197         PRINT_CAP(notice, NOTICE);\r
198         PRINT_CAP(trap, TRAP);\r
199         PRINT_CAP(apm, APM);\r
200         PRINT_CAP(slmap, SL_MAP);\r
201         PRINT_CAP(ledinfo, LED_INFO);\r
202         PRINT_CAP(client_reregister, CLIENT_REG);\r
203         PRINT_CAP(sysguid, SYSGUID);\r
204         PRINT_CAP(boot_mgmt, BOOT_MGMT);\r
205         PRINT_CAP(pkey_switch_ext_port, PKEY_SW_EXT_PORT_TRAP);\r
206         PRINT_CAP(link_rtl, LINK_LATENCY);\r
207         PRINT_CAP(reinit, REINIT);\r
208         PRINT_CAP(ipd, OPT_IPD);\r
209         PRINT_CAP(mkey_nvram, MKEY_NVRAM);\r
210         PRINT_CAP(pkey_nvram, PKEY_NVRAM);\r
211         printf("\n");\r
212 }\r
213 void printPortInfo(ib_port_attr_t* portPtr, ib_port_info_t portInfo, BOOLEAN fullPrint){\r
214         printf("\t\tport=%d\n", portPtr->port_num);\r
215         printPortLinkState(portPtr->link_state);\r
216         printPortRate(portInfo.link_speed>>4,portInfo.link_width_active, portPtr->link_state);\r
217         printf("\t\tsm_lid=0x%04x\n", cl_ntoh16(portPtr->sm_lid));\r
218         printf("\t\tport_lid=0x%04x\n", cl_ntoh16(portPtr->lid));\r
219         printf("\t\tport_lmc=0x%x\n", portPtr->lmc);\r
220         printPortMTU(portPtr->mtu);\r
221         if(fullPrint){\r
222                 printf("\t\tmax_msg_sz=0x%x     (Max message size)\n", portPtr->max_msg_size);\r
223                 printPortCaps( &portPtr->cap );\r
224                 printf("\t\tmax_vl_num=0x%x             (Maximum number of VL supported by this port)\n", portPtr->max_vls);\r
225                 printf("\t\tbad_pkey_counter=0x%x       (Bad PKey counter)\n", portPtr->pkey_ctr);\r
226                 printf("\t\tqkey_viol_counter=0x%x      (QKey violation counter)\n", portPtr->qkey_ctr);\r
227                 printf("\t\tsm_sl=0x%x          (IB_SL to be used in communication with subnet manager)\n", portPtr->sm_sl);\r
228                 printf("\t\tpkey_tbl_len=0x%x   (Current size of pkey table)\n", portPtr->num_pkeys);\r
229                 printf("\t\tgid_tbl_len=0x%x    (Current size of GID table)\n", portPtr->num_gids);\r
230                 printf("\t\tsubnet_timeout=0x%x (Subnet Timeout for this port (see PortInfo))\n", portPtr->subnet_timeout);\r
231                 printf("\t\tinitTypeReply=0x%x  (optional InitTypeReply value. 0 if not supported)\n", portPtr->init_type_reply);\r
232                 printPortGID(portPtr->p_gid_table->unicast.prefix, portPtr->p_gid_table->unicast.interface_id);\r
233         }\r
234         printf("\n");\r
235 }\r
236 \r
237 \r
238 void print_uplink_info(ib_ca_attr_t* ca_attr)\r
239 {\r
240         uplink_info_t*p_uplink_info = mthca_get_uplink_info(ca_attr);\r
241         char *bus_type, *link_speed, cap;\r
242         int freq;\r
243 \r
244         switch (p_uplink_info->bus_type) {\r
245                 case UPLINK_BUS_PCI: bus_type = "PCI"; break;\r
246                 case UPLINK_BUS_PCIX: bus_type = "PCI_X"; break;\r
247                 case UPLINK_BUS_PCIE: bus_type = "PCI_E"; break;\r
248                 default: printf("\tuplink={BUS=UNRECOGNIZED (%d)}\n", p_uplink_info->bus_type); return;\r
249         }\r
250 \r
251         switch (p_uplink_info->bus_type) {\r
252                 case UPLINK_BUS_PCI: \r
253                 case UPLINK_BUS_PCIX:\r
254                         if (p_uplink_info->u.pci_x.capabilities == UPLINK_BUS_PCIX_133)\r
255                                 freq = 133;\r
256                         else\r
257                                 freq = 66;\r
258                         printf("\tuplink={BUS=%s, CAPS=%d MHz}\n", bus_type, freq ); \r
259                         return;\r
260 \r
261                 case UPLINK_BUS_PCIE:\r
262                         cap = p_uplink_info->u.pci_e.capabilities;\r
263                         if (p_uplink_info->u.pci_e.link_speed == UPLINK_BUS_PCIE_SDR)\r
264                                 link_speed = "2.5 Gbps";\r
265                         else\r
266                         if (p_uplink_info->u.pci_e.link_speed == UPLINK_BUS_PCIE_DDR)\r
267                                 link_speed = "5.0 Gbps";\r
268                         else\r
269                                 link_speed = "unknown";\r
270                         printf("\tuplink={BUS=%s, SPEED=%s, WIDTH=x%d, CAPS=%s*x%d}\n",\r
271                                 bus_type, link_speed, p_uplink_info->u.pci_e.link_width,\r
272                                 (cap&1) ? "2.5" : "5", cap>>2 ); \r
273                         return;\r
274         }\r
275 }\r
276 \r
277 void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, ib_port_info_t* vstat_port_info, BOOLEAN fullPrint){\r
278         int i;\r
279 \r
280         printf("\n\thca_idx=%d\n", idx);\r
281         if (ca_attr->dev_id & 1)\r
282                 printf("\tATTENTION! \n\t    The device is in 'Flash Recovery' mode, probably due to an incorrect firmware."\r
283                         "\n\t    Use firmware tools to solve the problem.\n",idx);\r
284         /*printf("\tpci_location={BUS=NA,DEV/FUNC=NA}\n");*/\r
285         print_uplink_info(ca_attr);\r
286         printf("\tvendor_id=0x%04x\n", ca_attr->vend_id);\r
287         printf("\tvendor_part_id=0x%04x\n", ca_attr->dev_id);\r
288         printf("\thw_ver=0x%x\n", ca_attr->revision); //TODO: ???\r
289         if(ca_attr->vend_id == VEND_ID_MELLNOX || ca_attr->vend_id == VEND_ID_VOLTAIRE) {\r
290                 printf("\tfw_ver=%d.%.2d.%.4d\n",\r
291                 (uint16_t )(ca_attr->fw_ver>>32),\r
292                 (uint16_t)(ca_attr->fw_ver>>16),\r
293                 (uint16_t )(ca_attr->fw_ver));\r
294                 printf("\tPSID=%s\n",mthca_get_board_id(ca_attr));\r
295         }else{\r
296                 printf("\tfw_ver=0x%I64x\n",ca_attr->fw_ver);\r
297         }\r
298         printGUID(ca_attr->ca_guid);\r
299         if(fullPrint){\r
300                 printf("\tnum_phys_ports = %d\n",ca_attr->num_ports);\r
301                 printf("\tmax_num_qp = 0x%x             (Maximum Number of QPs supported)\n", ca_attr->max_qps);\r
302                 printf("\tmax_qp_ous_wr = 0x%x          (Maximum Number of outstanding WR on any WQ)\n", ca_attr->max_wrs);\r
303                 printf("\tmax_num_sg_ent = 0x%x         (Max num of scatter/gather entries for WQE other than RD)\n", ca_attr->max_sges);\r
304                 printf("\tmax_num_sg_ent_rd = 0x%x              (Max num of scatter/gather entries for RD WQE)\n",  ca_attr->max_rd_sges);\r
305                 printf("\tmax_num_srq = 0x%x            (Maximum Number of SRQs supported)\n", ca_attr->max_srq);\r
306                 printf("\tmax_wqe_per_srq = 0x%x        (Maximum Number of outstanding WR on any SRQ)\n", ca_attr->max_srq_wrs);\r
307                 printf("\tmax_srq_sentries = 0x%x               (Maximum Number of scatter/gather entries for SRQ WQE)\n", ca_attr->max_srq_sges);\r
308                 printf("\tsrq_resize_supported = %d     (SRQ resize supported)\n", ca_attr->modify_srq_depth);\r
309                 printf("\tmax_num_cq = 0x%x             (Max num of supported CQs)\n", ca_attr->max_cqs);\r
310                 printf("\tmax_num_ent_cq = 0x%x (Max num of supported entries per CQ)\n", ca_attr->max_cqes);\r
311                 printf("\tmax_num_mr = 0x%x             (Maximum number of memory region supported)\n", ca_attr->init_regions);\r
312                 printf("\tmax_mr_size = 0x%x    (Largest contiguous block of memory region in bytes)\n", ca_attr->init_region_size);\r
313                 printf("\tmax_pd_num = 0x%x             (Maximum number of protection domains supported)\n", ca_attr->max_pds);\r
314                 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
315 \r
316                 printf("\tlocal_ca_ack_delay = 0x%x     (Log2 4.096usec Max. RX to ACK or NAK delay)\n", ca_attr->local_ack_delay);\r
317                 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
318                 printf("\tmax_ee_ous_rd_atom = 0                (EE Maximum number of outs. RDMA read/atomic as target)\n");\r
319                 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
320                 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
321                 printf("\tmax_ee_init_rd_atom = 0               (EE Max. Num. of outs. RDMA read/atomic as initiator)\n");\r
322                 printf("\tatomic_cap = %s               (Level of Atomicity supported)\n",ca_attr->atomicity == IB_ATOMIC_GLOBAL?"GLOBAL":\r
323                                                                                                                                         ca_attr->atomicity == IB_ATOMIC_LOCAL?"LOCAL":"NORMAL");\r
324                 printf("\tmax_ee_num = 0x0              (Maximum number of EEC supported)\n");\r
325                 printf("\tmax_rdd_num = 0x0             (Maximum number of IB_RDD supported)\n");\r
326                 printf("\tmax_mw_num = 0x%x             (Maximum Number of memory windows supported)\n", ca_attr->init_windows);\r
327                 printf("\tmax_raw_ipv6_qp = 0x%x                (Maximum number of Raw IPV6 QPs supported)\n", ca_attr->max_ipv6_qps);\r
328                 printf("\tmax_raw_ethy_qp = 0x%x                (Maximum number of Raw Ethertypes QPs supported)\n", ca_attr->max_ether_qps);\r
329                 printf("\tmax_mcast_grp_num = 0x%x      (Maximum Number of multicast groups)\n", ca_attr->max_mcast_grps);\r
330                 printf("\tmax_mcast_qp_attach_num = 0x%x        (Maximum number of QP per multicast group)\n", ca_attr->max_qps_per_mcast_grp);\r
331                 printf("\tmax_ah_num = 0x%x             (Maximum number of address handles)\n", ca_attr->max_addr_handles);\r
332                 printf("\tmax_num_fmr = 0x%x            (Maximum number FMRs)\n", ca_attr->max_fmr);\r
333                 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
334         }else{\r
335                 printf("\tnum_phys_ports=%d\n",         ca_attr->num_ports);\r
336         }\r
337         for (i = 0; i<ca_attr->num_ports; i++){\r
338                 printPortInfo(ca_attr->p_port_attr+i, vstat_port_info[i], fullPrint);\r
339         }       \r
340 }\r
341 /* Internal Functions */\r
342 \r
343 void vstat_get_counters(ib_ca_handle_t VOID_PTR64 h_ca,uint8_t port_num)\r
344 {\r
345         ib_mad_t                        *mad_in = NULL;\r
346         ib_mad_t                        *mad_out = NULL;\r
347         ib_port_counters_t      *port_counters;\r
348         ib_api_status_t         ib_status = IB_SUCCESS;\r
349         int i;\r
350         \r
351         mad_out = (ib_mad_t*)cl_zalloc(256);\r
352         CL_ASSERT(mad_out);\r
353 \r
354         mad_in = (ib_mad_t*)cl_zalloc(256);\r
355         CL_ASSERT(mad_in);\r
356 \r
357 \r
358         mad_in->attr_id = IB_MAD_ATTR_PORT_CNTRS;\r
359         mad_in->method = IB_MAD_METHOD_GET;\r
360         mad_in->base_ver = 1;\r
361         mad_in->class_ver =1;\r
362         mad_in->mgmt_class = IB_MCLASS_PERF;\r
363 \r
364         port_counters = (ib_port_counters_t*)(((ib_gmp_t*)mad_in)->data);\r
365 \r
366         port_counters->port_select= port_num;\r
367         port_counters->counter_select= 0xff;\r
368 \r
369         ib_status = ib_local_mad(h_ca ,port_num ,mad_in ,mad_out);\r
370         if(ib_status != IB_SUCCESS)\r
371         {\r
372                 printf("ib_local_mad failed with status = %d\n", ib_status);\r
373                 return;\r
374         }\r
375         \r
376         port_counters = (ib_port_counters_t*)(((ib_gmp_t*)mad_out)->data);\r
377 \r
378         printf("\n\tport counters for port %d\n",port_num);\r
379         printf("\t\tlink_error_recovery_counter\t0x%x \n",port_counters->link_error_recovery_counter);\r
380         printf("\t\tlink_down_counter\t\t0x%x \n",port_counters->link_down_counter);\r
381         printf("\t\tport_rcv_errors\t\t\t0x%x \n",CL_NTOH16(port_counters->port_rcv_errors));\r
382         printf("\t\tport_rcv_remote_physical_errors\t0x%x \n",CL_NTOH16(port_counters->port_rcv_remote_physical_errors));\r
383         printf("\t\tport_rcv_switch_relay_errors\t0x%x \n",CL_NTOH16(port_counters->port_rcv_switch_relay_errors));\r
384         printf("\t\tport_xmit_discard\t\t0x%x \n",CL_NTOH16(port_counters->port_xmit_discard));\r
385         printf("\t\tport_xmit_constraint_errors\t0x%x \n",port_counters->port_xmit_constraint_errors);\r
386         printf("\t\tport_rcv_constraint_errors\t0x%x \n",port_counters->port_rcv_constraint_errors);\r
387         printf("\t\tvl15_dropped\t\t\t0x%x \n",CL_NTOH16(port_counters->vl15_dropped));\r
388         printf("\t\tport_rcv_data\t\t\t0x%x \n",CL_NTOH32(port_counters->port_rcv_data));\r
389         printf("\t\tport_xmit_data\t\t\t0x%x \n",CL_NTOH32(port_counters->port_xmit_data));\r
390         printf("\t\tport_rcv_pkts\t\t\t0x%x \n",CL_NTOH32(port_counters->port_rcv_pkts));\r
391         printf("\t\tport_xmit_pkts\t\t\t0x%x \n\n",CL_NTOH32(port_counters->port_xmit_pkts));\r
392         \r
393 }\r
394 \r
395 \r
396 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
397 {\r
398         ib_mad_t                        *mad_in = NULL;\r
399         ib_mad_t                        *mad_out = NULL;\r
400         ib_api_status_t         ib_status = IB_SUCCESS;\r
401         int i;\r
402         \r
403         mad_out = (ib_mad_t*)cl_zalloc(256);\r
404         CL_ASSERT(mad_out);\r
405 \r
406         mad_in = (ib_mad_t*)cl_zalloc(256);\r
407         CL_ASSERT(mad_in);\r
408 \r
409 \r
410         mad_in->attr_id = IB_MAD_ATTR_PORT_INFO;\r
411         mad_in->method = IB_MAD_METHOD_GET;\r
412         mad_in->base_ver = 1;\r
413         mad_in->class_ver =1;\r
414         mad_in->mgmt_class = IB_MCLASS_SUBN_LID;\r
415         \r
416 \r
417 \r
418         ib_status = ib_local_mad(h_ca ,port_num ,mad_in ,mad_out);\r
419         if(ib_status != IB_SUCCESS &&  0 != mad_in->status )\r
420         {\r
421                 printf("ib_local_mad failed with status = %d mad status = %d\n", ib_status,mad_in->status);\r
422                 return;\r
423         }\r
424 \r
425         cl_memcpy(vstat_port_info,(ib_port_info_t*)(((ib_smp_t*)mad_out)->data),sizeof(ib_port_info_t));\r
426 \r
427         \r
428 }\r
429 \r
430 \r
431 ib_api_status_t\r
432 vstat_ca_attr(\r
433         boolean_t modify_attr,\r
434         BOOLEAN fullPrint,\r
435         BOOLEAN getCounters\r
436         )\r
437 {\r
438         ib_al_handle_t VOID_PTR64               h_al = NULL;\r
439         ib_api_status_t         ib_status = IB_SUCCESS;\r
440         ib_api_status_t         ret_status = IB_SUCCESS;\r
441         size_t                  guid_count;\r
442         ib_net64_t              *ca_guid_array;\r
443         ib_ca_attr_t            *vstat_ca_attr;\r
444         ib_port_info_t          vstat_port_info[2];\r
445         size_t                  i;\r
446         ib_ca_handle_t VOID_PTR64       h_ca = NULL;\r
447         uint32_t                        bsize;\r
448         ib_port_attr_mod_t port_attr_mod;\r
449         uint8_t                 port_idx;\r
450 \r
451         while(1)\r
452         {\r
453                 /*\r
454                  * Open the AL instance\r
455                  */\r
456                 ib_status = ib_open_al(&h_al);\r
457                 if(ib_status != IB_SUCCESS)\r
458                 {\r
459                         printf("ib_open_al failed status = %d\n", ib_status);\r
460                         ret_status = ib_status;                 \r
461                         break;\r
462                 }\r
463                 //xxxx\r
464                 //printf("ib_open_al PASSED.\n");\r
465                 //xxx\r
466                 CL_ASSERT(h_al);\r
467 \r
468                 /*\r
469                  * Get the Local CA Guids\r
470                  */\r
471                 ib_status = ib_get_ca_guids(h_al, NULL, &guid_count);\r
472                 if(ib_status != IB_INSUFFICIENT_MEMORY)\r
473                 {\r
474                         printf("ib_get_ca_guids1 failed status = %d\n", (uint32_t)ib_status);\r
475                         ret_status = ib_status;                 \r
476                         goto Cleanup1;\r
477                 }\r
478 \r
479                 \r
480 \r
481                 /*\r
482                  * If no CA's Present then return\r
483                  */\r
484 \r
485                 if(guid_count == 0)\r
486                         goto Cleanup1;\r
487 \r
488                 \r
489                 ca_guid_array = (ib_net64_t*)cl_malloc(sizeof(ib_net64_t) * guid_count);\r
490                 CL_ASSERT(ca_guid_array);\r
491                 \r
492                 ib_status = ib_get_ca_guids(h_al, ca_guid_array, &guid_count);\r
493                 if(ib_status != IB_SUCCESS)\r
494                 {\r
495                         printf("ib_get_ca_guids2 failed with status = %d\n", ib_status);\r
496                         ret_status = ib_status;                 \r
497                         goto Cleanup1;\r
498                 }\r
499 \r
500                 \r
501 \r
502                 /*\r
503                  * For Each CA Guid found Open the CA,\r
504                  * Query the CA Attribute and close the CA\r
505                  */\r
506                 for(i=0; i < guid_count; i++)\r
507                 {\r
508 \r
509                         /* Open the CA */\r
510                         ib_status = ib_open_ca(h_al,\r
511                                 ca_guid_array[i],\r
512                                 NULL,\r
513                                 NULL,   //ca_context\r
514                                 &h_ca);\r
515 \r
516                         if(ib_status != IB_SUCCESS)\r
517                         {\r
518                                 printf("ib_open_ca failed with status = %d\n", ib_status);\r
519                                 ret_status = ib_status;                         \r
520                                 goto Cleanup1;\r
521                         }\r
522 \r
523                         //xxx\r
524                         //printf("ib_open_ca passed i=%d\n",i); \r
525                         //xxx\r
526 \r
527 \r
528                         /* Query the CA */\r
529                         bsize = 0;\r
530                         ib_status = ib_query_ca(h_ca, NULL, &bsize);\r
531                         if(ib_status != IB_INSUFFICIENT_MEMORY)\r
532                         {\r
533                                 printf("ib_query_ca failed with status = %d\n", ib_status);\r
534                                 ret_status = ib_status;\r
535                                 goto Cleanup2;\r
536                         }\r
537                         CL_ASSERT(bsize);\r
538                         //xxxx\r
539                         //printf("ib_query_ca PASSED bsize = 0x%x.\n",bsize);\r
540                         //xxx\r
541                         /* Allocate the memory needed for query_ca */\r
542 \r
543                         vstat_ca_attr = (ib_ca_attr_t *)cl_zalloc(bsize);\r
544                         CL_ASSERT(vstat_ca_attr);\r
545 \r
546                         ib_status = ib_query_ca(h_ca, vstat_ca_attr, &bsize);\r
547                         if(ib_status != IB_SUCCESS)\r
548                         {\r
549                                 printf("ib_query_ca failed with status = %d\n", ib_status);\r
550                                 ret_status = ib_status;\r
551                                 goto Cleanup2;\r
552                         }\r
553 \r
554                         for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r
555                                 vstat_get_port_info(h_ca ,port_idx+1,&vstat_port_info[port_idx]);\r
556                         }\r
557 \r
558                         vstat_print_ca_attr((int)i, vstat_ca_attr, vstat_port_info, fullPrint);\r
559                         if(getCounters)\r
560                         {\r
561                                 for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r
562                                         vstat_get_counters(h_ca ,port_idx+1);\r
563                                 }\r
564                         }\r
565                         \r
566                         /* Free the memory */\r
567                         cl_free(vstat_ca_attr);\r
568                         vstat_ca_attr = NULL;\r
569                         /* Close the current open CA */\r
570                         ib_status = ib_close_ca(h_ca, NULL);\r
571                         if(ib_status != IB_SUCCESS)\r
572                         {\r
573                                 printf("ib_close_ca failed status = %d", ib_status);\r
574                                 ret_status = ib_status;\r
575                         }\r
576                         h_ca = NULL;\r
577 \r
578                 }\r
579 \r
580 Cleanup2:\r
581                 if(h_ca != NULL)\r
582                 {\r
583                         ib_status = ib_close_ca(h_ca, NULL);\r
584                         if(ib_status != IB_SUCCESS)\r
585                         {\r
586                                 printf("ib_close_ca failed status = %d", ib_status);\r
587                         }\r
588                 }\r
589 \r
590 Cleanup1:\r
591                 cl_free(ca_guid_array);\r
592                 ib_status = ib_close_al(h_al);\r
593 \r
594                 if(ib_status != IB_SUCCESS)\r
595                 {\r
596                         printf("ib_close_al failed status = %d", ib_status);\r
597                 }\r
598 \r
599                 break;\r
600 \r
601         } //End of while(1)\r
602 \r
603         \r
604         return ret_status;\r
605 }\r
606 \r
607 void vstat_help()\r
608 {\r
609         printf("\n\tUsage: vstat [-v] [-c]\n");\r
610         printf("\t\t -v - verbose mode\n");\r
611         printf("\t\t -c - HCA error/statistic counters\n");\r
612 }\r
613 \r
614 int32_t __cdecl\r
615 main(\r
616         int32_t argc,\r
617         char* argv[])\r
618 {\r
619         ib_api_status_t ib_status;\r
620         BOOLEAN fullPrint = FALSE;\r
621         BOOLEAN getCounters = FALSE;\r
622         BOOLEAN showHelp = FALSE;\r
623         if(argc>1){\r
624                 int i = 2;\r
625                 while(i<=argc){\r
626                         if(!_stricmp(argv[i-1], "-v")){\r
627                                 fullPrint = TRUE;\r
628                                 i+=1;\r
629                         }else if(!_stricmp(argv[i-1], "-h") || \r
630                                 !_stricmp(argv[i-1], "-help")){\r
631                                 showHelp = TRUE;\r
632                                 i+=1;\r
633                         }else if(!_stricmp(argv[i-1], "-c")){\r
634                                 getCounters = TRUE;\r
635                                 i+=1;\r
636                         }else{\r
637                                 i+=2;\r
638                         }\r
639                 }\r
640         }\r
641         if (showHelp)\r
642                 vstat_help();\r
643         else\r
644                 ib_status = vstat_ca_attr(FALSE, fullPrint,getCounters);\r
645 \r
646         return 0;\r
647 }\r
648 \r