OpenIB branding
[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 \r
46 \r
47 \r
48 \r
49 /*******************************************************************\r
50 *******************************************************************/\r
51 \r
52 \r
53 void print64bit(ib_net64_t u64, BOOLEAN hexFormat){\r
54         ib_net64_t mask = 255;\r
55         ib_net64_t tmp;\r
56         int i;\r
57         for(i=0;i<8;i++){\r
58                 tmp = (short)(u64>>(i*8)) & mask;\r
59                 if(hexFormat){\r
60                         printf("%02x", tmp);\r
61                         if(i<7){\r
62                                 printf(":");\r
63                         }\r
64                 }else{\r
65                         if(tmp<100){\r
66                                 printf("%02d", tmp);\r
67                         }else{\r
68                                 printf("%03d", tmp);\r
69                         }\r
70                         if(i<7){\r
71                                 printf(".");\r
72                         }\r
73                 }\r
74         }\r
75 }       \r
76 \r
77 void printGUID(ib_net64_t guid){\r
78         printf("\tnode_guid=");\r
79         print64bit(guid, TRUE);\r
80         printf("        (Node GUID for this hca)\n");\r
81 }\r
82 \r
83 void printPortGID(ib_net64_t subnetPrefix, ib_net64_t portGuid){\r
84         printf("\t\tGID[  0]= ");\r
85         print64bit(subnetPrefix, FALSE);\r
86         printf(".");\r
87         print64bit(portGuid, FALSE);\r
88         printf("\n");\r
89 }\r
90 \r
91 \r
92 void printPortLinkState(int portState){ //TODO: check that these are all the options and that they are correct\r
93         switch(portState){\r
94                 case 1:\r
95                         printf("\t\tport_state=PORT_DOWN\n");\r
96                         break;\r
97                 case 2:\r
98                         printf("\t\tport_state=PORT_INITIALIZE\n");\r
99                         break;\r
100                 case 4:\r
101                         printf("\t\tport_state=PORT_ACTIVE\n");\r
102                         break;\r
103                 default:\r
104                         printf("\t\tport_state=UNKNOWN\n"); \r
105         }\r
106 }\r
107 \r
108 \r
109 \r
110 void printPortMTU(int mtu){ //TODO: check that these are all the options and that they are correct\r
111         switch(mtu){\r
112                 case 1:\r
113                         printf("\t\tmax_mtu=256\n");\r
114                         break;\r
115                 case 2:\r
116                         printf("\t\tmax_mtu=512\n");\r
117                         break;\r
118                 case 3:\r
119                         printf("\t\tmax_mtu=1024\n");\r
120                         break;\r
121                 case 4:\r
122                         printf("\t\tmax_mtu=2048\n");\r
123                         break;\r
124                 case 5:\r
125                         printf("\t\tmax_mtu=4096\n");\r
126                         break;\r
127                 default:\r
128                         printf("\t\tmax_mtu=UNKNOWN\n"); \r
129         }\r
130 }\r
131 \r
132 void printPortInfo(ib_port_attr_t* portPtr, BOOLEAN fullPrint){\r
133         printf("\t\tport=%d\n", portPtr->port_num);\r
134         printPortLinkState(portPtr->link_state);\r
135         printf("\t\tsm_lid=0x%04x\n", cl_ntoh16(portPtr->sm_lid));\r
136         printf("\t\tport_lid=0x%04x\n", cl_ntoh16(portPtr->lid));\r
137         printf("\t\tport_lmc=0x%x\n", portPtr->lmc);\r
138         printPortMTU(portPtr->mtu);\r
139         if(fullPrint){\r
140                 printf("\t\tmax_msg_sz=0x%x     (Max message size)\n", portPtr->max_msg_size);\r
141                 printf("\t\tcapability_mask=TBD\n");\r
142                 printf("\t\tmax_vl_num=0x%x     (Maximum number of VL supported by this port)\n", portPtr->max_vls);\r
143                 printf("\t\tbad_pkey_counter=0x%x       (Bad PKey counter)\n", portPtr->pkey_ctr);\r
144                 printf("\t\tqkey_viol_counter=0x%x      (QKey violation counter)\n", portPtr->qkey_ctr);\r
145                 printf("\t\tsm_sl=0x%x  (IB_SL to be used in communication with subnet manager)\n", portPtr->sm_sl);\r
146                 printf("\t\tpkey_tbl_len=0x%x   (Current size of pkey table)\n", portPtr->num_pkeys);\r
147                 printf("\t\tgid_tbl_len=0x%x    (Current size of GID table)\n", portPtr->num_gids);\r
148                 printf("\t\tsubnet_timeout=0x%x (Subnet Timeout for this port (see PortInfo))\n", portPtr->subnet_timeout);\r
149                 printf("\t\tinitTypeReply=0x%x  (optional InitTypeReply value. 0 if not supported)\n", portPtr->init_type_reply);\r
150                 printPortGID(portPtr->p_gid_table->unicast.prefix, portPtr->p_gid_table->unicast.interface_id);\r
151         }\r
152         printf("\n");\r
153 }\r
154 \r
155 \r
156 \r
157 \r
158 void vstat_print_ca_attr(ib_ca_attr_t* ca_attr, BOOLEAN fullPrint){\r
159         int i;\r
160         \r
161         printf("\thca_id=%s\n", ca_attr->dev_id==0x5a44?"InfiniHost0":"TBD"); //TODO: all HCAs and hadle multi HCAs \r
162         printf("\tpci_location={BUS=TBD,DEV/FUNC=TBD}\n");\r
163         printf("\tvendor_id=0x%04x\n", ca_attr->vend_id);\r
164         printf("\tvendor_part_id=0x%04x\n", ca_attr->dev_id);\r
165         printf("\thw_ver=0x%x\n", ca_attr->revision); //TODO: ???\r
166         printf("\tfw_ver=TBD\n");\r
167         printf("\tPSID=TBD\n");\r
168         if(fullPrint){\r
169                 printf("\tnum_phys_ports =      TBD\n");\r
170                 printf("\tmax_num_qp = 0x%x             (Maximum Number of QPs supported)\n", ca_attr->max_qps);\r
171                 printf("\tmax_qp_ous_wr = 0x%x  (Maximum Number of oustanding WR on any WQ)\n", ca_attr->max_wrs);\r
172                 printf("\tflags== TBD\n");\r
173                 printf("\tmax_num_sg_ent = 0x%x         (Max num of scatter/gather entries for WQE other than RD)\n", ca_attr->max_sges);\r
174                 printf("\tmax_num_sg_ent_rd =   0x%x    (Max num of scatter/gather entries for RD WQE)\n",  ca_attr->max_rd_sges);\r
175                 printf("\tmax_num_srq = TBD             (Maximum Number of SRQs supported)\n");\r
176                 printf("\tmax_wqe_per_srq = TBD (Maximum Number of oustanding WR on any SRQ)\n");\r
177                 printf("\tmax_srq_sentries = TBD        (Maximum Number of scatter entries for SRQ WQE)\n");\r
178                 printf("\tsrq_resize_supported = TBD    (SRQ resize supported)\n");\r
179                 printf("\tmax_num_cq = 0x%x     (Max num of supported CQs)\n", ca_attr->max_cqs);\r
180                 printf("\tmax_num_ent_cq = 0x%x (Max num of supported entries per CQ)\n", ca_attr->max_cqes);\r
181                 printf("\tmax_num_mr = 0x%x     (Maximum number of memory region supported)\n", ca_attr->init_regions);\r
182                 printf("\tmax_mr_size = 0x%x    (Largest contigous block of memory region in bytes)\n", ca_attr->init_region_size);\r
183                 printf("\tmax_pd_num = 0x%x     (Maximum number of protection domains supported)\n", ca_attr->max_pds);\r
184                 printf("\tpage_size_cap = TBD   (Largest page size supported by this HCA)\n");\r
185                 printf("\tmax_pkeys = TBD               (Maximum number of partitions supported)\n");\r
186                 printGUID(ca_attr->ca_guid);\r
187                 printf("\tlocal_ca_ack_delay = 0x%x     (Log2 4.096usec Max. RX to ACK or NAK delay)\n", ca_attr->local_ack_delay);\r
188                 printf("\tmax_qp_ous_rd_atom = TBD      (Maximum number of oust. RDMA read/atomic as target)\n");\r
189                 printf("\tmax_ee_ous_rd_atom = TBD      (EE Maximum number of outs. RDMA read/atomic as target)\n");\r
190                 printf("\tmax_res_rd_atom = TBD (Max. Num. of resources used for RDMA read/atomic as target)\n");\r
191                 printf("\tmax_qp_init_rd_atom = TBD     (Max. Num. of outs. RDMA read/atomic as initiator)\n");\r
192                 printf("\tmax_ee_init_rd_atom = TBD     (EE Max. Num. of outs. RDMA read/atomic as initiator)\n");\r
193                 printf("\tatomic_cap = TBD              (Level of Atomicity supported)\n");\r
194                 printf("\tmax_ee_num = 0x0              (Maximum number of EEC supported)\n");\r
195                 printf("\tmax_rdd_num = 0x0             (Maximum number of IB_RDD supported)\n");\r
196                 printf("\tmax_mw_num = 0x%x     (Maximum Number of memory windows supported)\n", ca_attr->init_windows);\r
197                 printf("\tmax_raw_ipv6_qp = 0x%x        (Maximum number of Raw IPV6 QPs supported)\n", ca_attr->max_ipv6_qps);\r
198                 printf("\tmax_raw_ethy_qp = 0x%x        (Maximum number of Raw Ethertypes QPs supported)\n", ca_attr->max_ether_qps);\r
199                 printf("\tmax_mcast_grp_num = 0x%x      (Maximum Number of multicast groups)\n", ca_attr->max_mcast_grps);\r
200                 printf("\tmax_mcast_qp_attach_num = 0x%x(Maximum number of QP per multicast group)\n", ca_attr->max_qps_per_mcast_grp);\r
201                 printf("\tmax_total_mcast_qp_attach_num = 0x%x(Maximum number of QPs which can be attached to a mcast grp)\n", ca_attr->max_mcast_qps);\r
202                 printf("\tmax_ah_num = 0x%x     (Maximum number of address handles)\n", ca_attr->max_addr_handles);\r
203                 printf("\tmax_num_fmr = TBD             (maximum number FMRs)\n");\r
204                 printf("\tmax_num_map_per_fmr = TBD     (Maximum number of (re)maps per FMR before an unmap operation in required)\n");\r
205         }else{\r
206                 printf("\tnum_phys_ports=%d\n",         ca_attr->num_ports);\r
207         }\r
208         for (i = 0; i<ca_attr->num_ports; i++){\r
209                 printPortInfo(ca_attr->p_port_attr+i, fullPrint);\r
210         }       \r
211 }\r
212 /* Internal Functions */\r
213 \r
214 \r
215 \r
216 ib_api_status_t\r
217 vstat_ca_attr(\r
218         boolean_t modify_attr,\r
219         BOOLEAN fullPrint\r
220         )\r
221 {\r
222         ib_al_handle_t          h_al = NULL;\r
223         ib_api_status_t         ib_status = IB_SUCCESS;\r
224         ib_api_status_t         ret_status = IB_SUCCESS;\r
225         size_t                  guid_count;\r
226         ib_net64_t              *ca_guid_array;\r
227         ib_ca_attr_t            *vstat_ca_attr;\r
228         uintn_t                         i;\r
229         ib_ca_handle_t  h_ca = NULL;\r
230         uint32_t                        bsize;\r
231         ib_port_attr_mod_t port_attr_mod;\r
232 \r
233 \r
234 \r
235 \r
236         while(1)\r
237         {\r
238                 /*\r
239                  * Open the AL instance\r
240                  */\r
241                 ib_status = ib_open_al(&h_al);\r
242                 if(ib_status != IB_SUCCESS)\r
243                 {\r
244                         printf("ib_open_al failed status = %d\n", ib_status);\r
245                         ret_status = ib_status;                 \r
246                         break;\r
247                 }\r
248                 //xxxx\r
249                 //printf("ib_open_al PASSED.\n");\r
250                 //xxx\r
251                 CL_ASSERT(h_al);\r
252 \r
253                 /*\r
254                  * Get the Local CA Guids\r
255                  */\r
256                 ib_status = ib_get_ca_guids(h_al, NULL, &guid_count);\r
257                 if(ib_status != IB_INSUFFICIENT_MEMORY)\r
258                 {\r
259                         printf("ib_get_ca_guids1 failed status = %d\n", (uint32_t)ib_status);\r
260                         ret_status = ib_status;                 \r
261                         goto Cleanup1;\r
262                 }\r
263 \r
264                 \r
265 \r
266                 /*\r
267                  * If no CA's Present then return\r
268                  */\r
269 \r
270                 if(guid_count == 0)\r
271                         goto Cleanup1;\r
272 \r
273                 \r
274                 ca_guid_array = (ib_net64_t*)cl_malloc(sizeof(ib_net64_t) * guid_count);\r
275                 CL_ASSERT(ca_guid_array);\r
276                 \r
277                 ib_status = ib_get_ca_guids(h_al, ca_guid_array, &guid_count);\r
278                 if(ib_status != IB_SUCCESS)\r
279                 {\r
280                         printf("ib_get_ca_guids2 failed with status = %d\n", ib_status);\r
281                         ret_status = ib_status;                 \r
282                         goto Cleanup1;\r
283                 }\r
284 \r
285                 \r
286 \r
287                 /*\r
288                  * For Each CA Guid found Open the CA,\r
289                  * Query the CA Attribute and close the CA\r
290                  */\r
291                 for(i=0; i < guid_count; i++)\r
292                 {\r
293 \r
294                         /* Open the CA */\r
295                         ib_status = ib_open_ca(h_al,\r
296                                 ca_guid_array[i],\r
297                                 NULL,\r
298                                 NULL,   //ca_context\r
299                                 &h_ca);\r
300 \r
301                         if(ib_status != IB_SUCCESS)\r
302                         {\r
303                                 printf("ib_open_ca failed with status = %d\n", ib_status);\r
304                                 ret_status = ib_status;                         \r
305                                 goto Cleanup1;\r
306                         }\r
307 \r
308                         //xxx\r
309                         //printf("ib_open_ca passed i=%d\n",i); \r
310                         //xxx\r
311 \r
312 \r
313                         /* Query the CA */\r
314                         bsize = 0;\r
315                         ib_status = ib_query_ca(h_ca, NULL, &bsize);\r
316                         if(ib_status != IB_INSUFFICIENT_MEMORY)\r
317                         {\r
318                                 printf("ib_query_ca failed with status = %d\n", ib_status);\r
319                                 ret_status = ib_status;\r
320                                 goto Cleanup2;\r
321                         }\r
322                         CL_ASSERT(bsize);\r
323                         //xxxx\r
324                         //printf("ib_query_ca PASSED bsize = 0x%x.\n",bsize);\r
325                         //xxx\r
326                         /* Allocate the memory needed for query_ca */\r
327 \r
328                         vstat_ca_attr = (ib_ca_attr_t *)cl_zalloc(bsize);\r
329                         CL_ASSERT(vstat_ca_attr);\r
330 \r
331                         ib_status = ib_query_ca(h_ca, vstat_ca_attr, &bsize);\r
332                         if(ib_status != IB_SUCCESS)\r
333                         {\r
334                                 printf("ib_query_ca failed with status = %d\n", ib_status);\r
335                                 ret_status = ib_status;\r
336                                 goto Cleanup2;\r
337                         }\r
338 \r
339                         /* Print_ca_attributes */\r
340 \r
341                         vstat_print_ca_attr(vstat_ca_attr, fullPrint);\r
342 \r
343 \r
344                         /* Free the memory */\r
345                         cl_free(vstat_ca_attr);\r
346                         vstat_ca_attr = NULL;\r
347                         /* Close the current open CA */\r
348                         ib_status = ib_close_ca(h_ca, NULL);\r
349                         if(ib_status != IB_SUCCESS)\r
350                         {\r
351                                 printf("ib_close_ca failed status = %d", ib_status);\r
352                                 ret_status = ib_status;\r
353                         }\r
354                         h_ca = NULL;\r
355 \r
356                 }\r
357 \r
358 Cleanup2:\r
359                 if(h_ca != NULL)\r
360                 {\r
361                         ib_status = ib_close_ca(h_ca, NULL);\r
362                         if(ib_status != IB_SUCCESS)\r
363                         {\r
364                                 printf("ib_close_ca failed status = %d", ib_status);\r
365                         }\r
366                 }\r
367 \r
368 Cleanup1:\r
369                 ib_status = ib_close_al(h_al);\r
370 \r
371                 if(ib_status != IB_SUCCESS)\r
372                 {\r
373                         printf("ib_close_al failed status = %d", ib_status);\r
374                 }\r
375 \r
376                 break;\r
377 \r
378         } //End of while(1)\r
379 \r
380         \r
381         return ret_status;\r
382 }\r
383 \r
384 \r
385 \r
386 int32_t __cdecl\r
387 main(\r
388         int32_t argc,\r
389         char* argv[])\r
390 {\r
391         ib_api_status_t ib_status;\r
392         BOOLEAN fullPrint = FALSE;\r
393         if(argc>1){\r
394                 int i = 2;\r
395                 while(i<=argc){\r
396                         if(!_stricmp(argv[i-1], "-v")){\r
397                                 fullPrint = TRUE;\r
398                                 i+=1;\r
399                         }else{\r
400                                 i+=2;\r
401                         }\r
402                 }\r
403         }\r
404         ib_status = vstat_ca_attr(FALSE, fullPrint);\r
405         return 0;\r
406 }\r
407 \r