609a38dc8f6eed93d1813e6433d7fb5ce6300f0e
[mirror/winof/.git] / tools / vstat / user / vstat_querycaattr.c
1 /*
2  * Copyright (c) 2005 Mellanox Technologies.  All rights reserved.
3  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 
4  *
5  * This software is available to you under the OpenIB.org BSD license
6  * below:
7  *
8  *     Redistribution and use in source and binary forms, with or
9  *     without modification, are permitted provided that the following
10  *     conditions are met:
11  *
12  *      - Redistributions of source code must retain the above
13  *        copyright notice, this list of conditions and the following
14  *        disclaimer.
15  *
16  *      - Redistributions in binary form must reproduce the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer in the documentation and/or other materials
19  *        provided with the distribution.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  * $Id: vstat_querycaattr.c 01 2005-07-11 14:55:53Z dafna $
31  */
32
33 #include <iba/ib_types.h>
34 #include <iba/ib_al.h>
35 #include <complib/cl_memory.h>
36 #include "..\..\..\tests\alts\alts_debug.h"
37 #include "..\..\..\tests\alts\alts_common.h"
38
39 /*
40  * Function prototypes
41  */
42
43 ib_api_status_t
44 alts_ca_attr(
45         boolean_t modify_attr,
46         BOOLEAN fullPrint
47         );
48
49 /*
50  * Test Case QueryCaAttributes
51  */
52
53 ib_api_status_t
54 al_test_modifycaattr(void)
55 {
56         boolean_t modify_ca_attr = TRUE;
57
58         return alts_ca_attr(modify_ca_attr, FALSE);
59 }
60
61 ib_api_status_t
62 al_test_querycaattr(void)
63 {
64         boolean_t modify_ca_attr = FALSE;
65
66         return alts_ca_attr(modify_ca_attr, FALSE);
67 }
68
69 void print64bit(ib_net64_t u64, BOOLEAN hexFormat){
70         ib_net64_t mask = 255;
71         ib_net64_t tmp;
72         int i;
73         for(i=0;i<8;i++){
74                 tmp = (short)(u64>>(i*8)) & mask;
75                 if(hexFormat){
76                         printf("%02x", tmp);
77                         if(i<7){
78                                 printf(":");
79                         }
80                 }else{
81                         if(tmp<100){
82                                 printf("%02d", tmp);
83                         }else{
84                                 printf("%03d", tmp);
85                         }
86                         if(i<7){
87                                 printf(".");
88                         }
89                 }
90         }
91 }       
92
93 void printGUID(ib_net64_t guid){
94         printf("\tnode_guid=");
95         print64bit(guid, TRUE);
96         printf("        (Node GUID for this hca)\n");
97 }
98
99 void printPortGID(ib_net64_t subnetPrefix, ib_net64_t portGuid){
100         printf("\t\tGID[  0]= ");
101         print64bit(subnetPrefix, FALSE);
102         printf(".");
103         print64bit(portGuid, FALSE);
104         printf("\n");
105 }
106
107
108 void printPortLinkState(int portState){ //TODO: check that these are all the options and that they are correct
109         switch(portState){
110                 case 1:
111                         printf("\t\tport_state=PORT_DOWN\n");
112                         break;
113                 case 2:
114                         printf("\t\tport_state=PORT_INITIALIZE\n");
115                         break;
116                 case 4:
117                         printf("\t\tport_state=PORT_ACTIVE\n");
118                         break;
119                 default:
120                         printf("\t\tport_state=UNKNOWN\n"); 
121         }
122 }
123
124
125 void printPortInfo(ib_port_attr_t* portPtr, BOOLEAN fullPrint){
126         printf("\t\tport=%d\n", portPtr->port_num);
127         printPortLinkState(portPtr->link_state);
128         printf("\t\tsm_lid=0x%04x\n", cl_ntoh16(portPtr->sm_lid));
129         printf("\t\tport_lid=0x%04x\n", cl_ntoh16(portPtr->lid));
130         printf("\t\tport_lmc=0x%x\n", portPtr->lmc);
131         printf("\t\tmax_mtu=%d\n", portPtr->mtu);
132         if(fullPrint){
133                 printf("\t\tmax_msg_sz=0x%x     (Max message size)\n", portPtr->max_msg_size);
134                 printf("\t\tcapability_mask=TBD\n");
135                 printf("\t\tmax_vl_num=0x%x     (Maximum number of VL supported by this port)\n", portPtr->max_vls);
136                 printf("\t\tbad_pkey_counter=0x%x       (Bad PKey counter)\n", portPtr->pkey_ctr);
137                 printf("\t\tqkey_viol_counter=0x%x      (QKey violation counter)\n", portPtr->qkey_ctr);
138                 printf("\t\tsm_sl=0x%x  (IB_SL to be used in communication with subnet manager)\n", portPtr->sm_sl);
139                 printf("\t\tpkey_tbl_len=0x%x   (Current size of pkey table)\n", portPtr->num_pkeys);
140                 printf("\t\tgid_tbl_len=0x%x    (Current size of GID table)\n", portPtr->num_gids);
141                 printf("\t\tsubnet_timeout=0x%x (Subnet Timeout for this port (see PortInfo))\n", portPtr->subnet_timeout);
142                 printf("\t\tinitTypeReply=0x%x  (optional InitTypeReply value. 0 if not supported)\n", portPtr->init_type_reply);
143                 printPortGID(portPtr->p_gid_table->unicast.prefix, portPtr->p_gid_table->unicast.interface_id);
144         }
145         printf("\n");
146 }
147
148
149
150
151 void vstat_print_ca_attr(ib_ca_attr_t* ca_attr, BOOLEAN fullPrint){
152         int i;
153         
154         printf("\thca_id=%s\n", ca_attr->dev_id==0x5a44?"InfiniHost0":"TBD"); //TODO: all HCAs and hadle multi HCAs 
155         printf("\tpci_location={BUS=TBD,DEV/FUNC=TBD}\n");
156         printf("\tvendor_id=0x%04x\n", ca_attr->vend_id);
157         printf("\tvendor_part_id=0x%04x\n", ca_attr->dev_id);
158         printf("\thw_ver=0x%x\n", ca_attr->revision); //TODO: ???
159         printf("\tfw_ver=TBD\n");
160         printf("\tPSID=TBD\n");
161         if(fullPrint){
162                 printf("\tnum_phys_ports=TBD\n");
163                 printf("\tmax_num_qp=0x%x       (Maximum Number of QPs supported)\n", ca_attr->max_qps);
164                 printf("\tmax_qp_ous_wr=0x%x    (Maximum Number of oustanding WR on any WQ)\n", ca_attr->max_wrs);
165                 printf("\tflags==TBD\n");
166                 printf("\tmax_num_sg_ent=0x%x   (Max num of scatter/gather entries for WQE other than RD)\n", ca_attr->max_sges);
167                 printf("\tmax_num_sg_ent_rd=0x%x        (Max num of scatter/gather entries for RD WQE)\n",  ca_attr->max_rd_sges);
168                 printf("\tmax_num_srq=TBD       (Maximum Number of SRQs supported)\n");
169                 printf("\tmax_wqe_per_srq=TBD   (Maximum Number of oustanding WR on any SRQ)\n");
170                 printf("\tmax_srq_sentries=TDB  (Maximum Number of scatter entries for SRQ WQE)\n");
171                 printf("\tsrq_resize_supported=TBD      (SRQ resize supported)\n");
172                 printf("\tmax_num_cq=0x%x       (Max num of supported CQs)\n", ca_attr->max_cqs);
173                 printf("\tmax_num_ent_cq=0x%x   (Max num of supported entries per CQ)\n", ca_attr->max_cqes);
174                 printf("\tmax_num_mr=0x%x       (Maximum number of memory region supported)\n", ca_attr->init_regions);
175                 printf("\tmax_mr_size=0x%x      (Largest contigous block of memory region in bytes)\n", ca_attr->init_region_size);
176                 printf("\tmax_pd_num=0x%x       (Maximum number of protection domains supported)\n", ca_attr->max_pds);
177                 printf("\tpage_size_cap=TBD     (Largest page size supported by this HCA)\n");
178                 printf("\tmax_pkeys=TBD (Maximum number of partitions supported)\n");
179                 printGUID(ca_attr->ca_guid);
180                 printf("\tlocal_ca_ack_delay=0x%x       (Log2 4.096usec Max. RX to ACK or NAK delay)\n", ca_attr->local_ack_delay);
181                 printf("\tmax_qp_ous_rd_atom=TBD        (Maximum number of oust. RDMA read/atomic as target)\n");
182                 printf("\tmax_ee_ous_rd_atom=TBD        (EE Maximum number of outs. RDMA read/atomic as target)\n");
183                 printf("\tmax_res_rd_atom=TBD   (Max. Num. of resources used for RDMA read/atomic as target)\n");
184                 printf("\tmax_qp_init_rd_atom=TBD       (Max. Num. of outs. RDMA read/atomic as initiator)\n");
185                 printf("\tmax_ee_init_rd_atom=TBD       (EE Max. Num. of outs. RDMA read/atomic as initiator)\n");
186                 printf("\tatomic_cap=TBD        (Level of Atomicity supported)\n");
187                 printf("\tmax_ee_num=0x0        (Maximum number of EEC supported)\n");
188                 printf("\tmax_rdd_num=0x0       (Maximum number of IB_RDD supported)\n");
189                 printf("\tmax_mw_num=0x%x       (Maximum Number of memory windows supported)\n", ca_attr->init_windows);
190                 printf("\tmax_raw_ipv6_qp=0x%x  (Maximum number of Raw IPV6 QPs supported)\n", ca_attr->max_ipv6_qps);
191                 printf("\tmax_raw_ethy_qp=0x%x  (Maximum number of Raw Ethertypes QPs supported)\n", ca_attr->max_ether_qps);
192                 printf("\tmax_mcast_grp_num=0x%x        (Maximum Number of multicast groups)\n", ca_attr->max_mcast_grps);
193                 printf("\tmax_mcast_qp_attach_num=0x%x  (Maximum number of QP per multicast group)\n", ca_attr->max_qps_per_mcast_grp);
194                 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);
195                 printf("\tmax_ah_num=0x%x       (Maximum number of address handles)\n", ca_attr->max_addr_handles);
196                 printf("\tmax_num_fmr=TBD       (maximum number FMRs)\n");
197                 printf("\tmax_num_map_per_fmr=TBD       (Maximum number of (re)maps per FMR before an unmap operation in required)\n");
198         }else{
199                 printf("\tnum_phys_ports=%d\n",         ca_attr->num_ports);
200         }
201         for (i = 0; i<ca_attr->num_ports; i++){
202                 printPortInfo(ca_attr->p_port_attr+i, fullPrint);
203         }       
204 }
205 /* Internal Functions */
206
207
208
209 ib_api_status_t
210 alts_ca_attr(
211         boolean_t modify_attr,
212         BOOLEAN fullPrint
213         )
214 {
215         ib_al_handle_t  h_al = NULL;
216         ib_api_status_t ib_status = IB_SUCCESS;
217         ib_api_status_t ret_status = IB_SUCCESS;
218         size_t guid_count;
219         ib_net64_t ca_guid_array[ALTS_MAX_CA];
220         ib_ca_attr_t *alts_ca_attr;
221         uintn_t i;
222         ib_ca_handle_t h_ca = NULL;
223         uint32_t bsize;
224         ib_port_attr_mod_t port_attr_mod;
225
226
227         ALTS_ENTER( ALTS_DBG_VERBOSE );
228
229         while(1)
230         {
231                 /*
232                  * Open the AL instance
233                  */
234                 ib_status = ib_open_al(&h_al);
235                 if(ib_status != IB_SUCCESS)
236                 {
237                         ALTS_PRINT( ALTS_DBG_ERROR,
238                                 ("ib_open_al failed status = %d\n", ib_status) );
239                         ret_status = ib_status;
240                         break;
241                 }
242
243                 //ALTS_PRINT( ALTS_DBG_INFO, ("ib_open_al PASSED.\n") );//xxx
244                 CL_ASSERT(h_al);
245
246                 /*
247                  * Get the Local CA Guids
248                  */
249                 ib_status = ib_get_ca_guids(h_al, NULL, &guid_count);
250                 if(ib_status != IB_INSUFFICIENT_MEMORY)
251                 {
252                         ALTS_PRINT( ALTS_DBG_ERROR,
253                                 ("ib_get_ca_guids failed status = %d\n", (uint32_t)ib_status) );
254                         ret_status = ib_status;
255                         goto Cleanup1;
256                 }
257
258                 ALTS_PRINT(ALTS_DBG_INFO,
259                         ("%d HCA found:\n",(uint32_t)guid_count)); //xxx
260
261                 /*
262                  * If no CA's Present then return
263                  */
264
265                 if(guid_count == 0)
266                         goto Cleanup1;
267
268                 // ca_guid_array holds ALTS_MAX_CA
269                 ib_status = ib_get_ca_guids(h_al, ca_guid_array, &guid_count);
270                 if(ib_status != IB_SUCCESS)
271                 {
272                         ALTS_PRINT( ALTS_DBG_ERROR,
273                                 ("ib_get_ca_guids failed with status = %d\n", ib_status) );
274                         ret_status = ib_status;
275                         goto Cleanup1;
276                 }
277
278                 
279
280                 /*
281                  * For Each CA Guid found Open the CA,
282                  * Query the CA Attribute and close the CA
283                  */
284                 for(i=0; i < guid_count; i++)
285                 {
286                         /*
287                         node_guid=00:02:c9:00:01:2b:72:a0       (Node GUID for this hca) //xxx
288                         */
289                         //printGUID(ca_guid_array[i]);
290                         //xxx
291                         //ALTS_PRINT(ALTS_DBG_INFO, 
292                         //      ("CA[%d] GUID IS 0x%" PRIx64 "\n",i,_byteswap_uint64(ca_guid_array[i])) );
293                         //xxx
294
295
296
297
298                         /* Open the CA */
299                         ib_status = ib_open_ca(h_al,
300                                 ca_guid_array[i],
301                                 alts_ca_err_cb,
302                                 NULL,   //ca_context
303                                 &h_ca);
304
305                         if(ib_status != IB_SUCCESS)
306                         {
307                                 ALTS_PRINT( ALTS_DBG_ERROR,     ("ib_open_ca failed with status = %d\n", ib_status) );
308                                 ret_status = ib_status;
309                                 goto Cleanup1;
310                         }
311
312                         //xxx
313                         //ALTS_PRINT(ALTS_DBG_INFO,
314                         //("ib_open_ca passed\n")); 
315                         //xxx
316
317
318                         /* Query the CA */
319                         bsize = 0;
320                         ib_status = ib_query_ca(h_ca, NULL, &bsize);
321                         if(ib_status != IB_INSUFFICIENT_MEMORY)
322                         {
323                                 ALTS_PRINT(ALTS_DBG_ERROR, ("ib_query_ca failed with status = %d\n", ib_status) );
324                                 ret_status = ib_status;
325                                 goto Cleanup2;
326                         }
327                         CL_ASSERT(bsize);
328
329                         /* Allocate the memory needed for query_ca */
330
331                         alts_ca_attr = (ib_ca_attr_t *)cl_zalloc(bsize);
332                         CL_ASSERT(alts_ca_attr);
333
334                         ib_status = ib_query_ca(h_ca, alts_ca_attr, &bsize);
335                         if(ib_status != IB_SUCCESS)
336                         {
337                                 ALTS_PRINT( ALTS_DBG_ERROR,
338                                         ("ib_query_ca failed with status = %d\n", ib_status) );
339                                 ret_status = ib_status;
340                                 goto Cleanup2;
341                         }
342
343                         /* Print_ca_attributes */
344
345                         vstat_print_ca_attr(alts_ca_attr, fullPrint);
346
347                         if(modify_attr)
348                         {
349                                 port_attr_mod.pkey_ctr = 10;
350                                 port_attr_mod.qkey_ctr = 10;
351
352                                 ib_status = ib_modify_ca(h_ca,alts_ca_attr->p_port_attr->port_num,
353                                         IB_CA_MOD_QKEY_CTR | IB_CA_MOD_PKEY_CTR ,
354                                         &port_attr_mod);
355
356                                 if(ib_status != IB_SUCCESS)
357                                 {
358                                         ALTS_PRINT( ALTS_DBG_ERROR,
359                                         ("ib_modify_ca failed with status = %d\n", ib_status) );
360                                         ret_status = ib_status;
361                                 }
362
363                                 ib_status = ib_query_ca(h_ca, alts_ca_attr, &bsize);
364
365                                 if(ib_status != IB_SUCCESS)
366                                 {
367                                         ALTS_PRINT( ALTS_DBG_ERROR,
368                                         ("ib_query_ca failed with status = %d\n", ib_status) );
369                                         goto Cleanup2;
370                                 }
371
372                                 CL_ASSERT(port_attr_mod.pkey_ctr != \
373                                         alts_ca_attr->p_port_attr->pkey_ctr);
374                                 CL_ASSERT(port_attr_mod.qkey_ctr != \
375                                         alts_ca_attr->p_port_attr->qkey_ctr);
376
377                         }
378
379                         /* Free the memory */
380                         cl_free(alts_ca_attr);
381                         alts_ca_attr = NULL;
382                         /* Close the current open CA */
383                         ib_status = ib_close_ca(h_ca, alts_ca_destroy_cb);
384                         if(ib_status != IB_SUCCESS)
385                         {
386                                 ALTS_PRINT( ALTS_DBG_ERROR,
387                                 ("ib_close_ca failed status = %d", ib_status));
388                         }
389                         h_ca = NULL;
390
391                 }
392
393 Cleanup2:
394                 if(h_ca != NULL)
395                 {
396                         ib_status = ib_close_ca(h_ca, alts_ca_destroy_cb);
397                         if(ib_status != IB_SUCCESS)
398                         {
399                                 ALTS_PRINT( ALTS_DBG_ERROR,
400                                 ("ib_close_ca failed status = %d", ib_status));
401                         }
402                 }
403
404 Cleanup1:
405                 ib_status = ib_close_al(h_al);
406
407                 if(ib_status != IB_SUCCESS)
408                 {
409                         ALTS_PRINT( ALTS_DBG_ERROR,
410                                 ("ib_close_al failed status = %d", ib_status));
411                 }
412
413                 break;
414
415         } //End of while(1)
416
417         ALTS_EXIT( ALTS_DBG_VERBOSE );
418         return ret_status;
419 }
420