[ALTS] Fix missing parameters to debug output to fix build error.
[mirror/winof/.git] / tests / alts / registermemregion.c
1 /*\r
2  * Copyright (c) 2005 SilverStorm 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 #include <iba/ib_types.h>\r
35 #include <iba/ib_al.h>\r
36 #include <complib/cl_memory.h>\r
37 #include <alts_debug.h>\r
38 #include <alts_common.h>\r
39 \r
40 \r
41 /* Test case PARAMETERS */\r
42 \r
43 #define MEM_ALLIGN 32\r
44 #define MEM_SIZE 1024\r
45 \r
46 \r
47 /*\r
48  * Function prototypes\r
49  */\r
50 \r
51 \r
52 /*\r
53  * Test Case RegisterMemRegion\r
54  */\r
55 \r
56 ib_api_status_t\r
57 al_test_register_mem(\r
58         void\r
59         )\r
60 {\r
61         ib_api_status_t ib_status = IB_SUCCESS;\r
62         ib_al_handle_t h_al = NULL;\r
63         ib_ca_handle_t h_ca = NULL;\r
64         ib_pd_handle_t h_pd = NULL;\r
65 \r
66         ib_mr_create_t virt_mem;\r
67         char *ptr = NULL, *ptr_align;\r
68         size_t mask; \r
69         uint32_t        lkey;\r
70         uint32_t        rkey;\r
71         ib_mr_handle_t  h_mr = NULL;\r
72         ib_mr_attr_t    alts_mr_attr;\r
73 \r
74         ALTS_ENTER( ALTS_DBG_VERBOSE );\r
75 \r
76         while(1)\r
77         {\r
78                 /* Open AL */\r
79                 ib_status = alts_open_al(&h_al);\r
80 \r
81                 if(ib_status != IB_SUCCESS)\r
82                         break;\r
83 \r
84                 CL_ASSERT(h_al);\r
85 \r
86                 /* Open CA */\r
87                 ib_status = alts_open_ca(h_al,&h_ca);\r
88                 if(ib_status != IB_SUCCESS)\r
89                         break;\r
90 \r
91                 CL_ASSERT(h_ca);\r
92 \r
93                 /*\r
94                  * Allocate a PD here\r
95                  */\r
96                 ib_status = ib_alloc_pd(h_ca, IB_PDT_NORMAL, NULL, &h_pd); //passing null context\r
97 \r
98                 if(ib_status != IB_SUCCESS)\r
99                 {\r
100                         ALTS_PRINT( ALTS_DBG_ERROR,\r
101                                 ("ib_alloc_pd failed status = %s\n", ib_get_err_str(ib_status)) );\r
102                         alts_close_ca(h_ca);\r
103                         break;\r
104                 }\r
105 \r
106                 /*\r
107                  * Allocate the virtual memory which needs to be registered\r
108                  */\r
109 \r
110                 mask = MEM_ALLIGN - 1;\r
111 \r
112                 ptr = cl_malloc(MEM_SIZE + MEM_ALLIGN - 1);\r
113 \r
114                 CL_ASSERT(ptr);\r
115 \r
116                 ptr_align = ptr;\r
117 \r
118                 if(((size_t)ptr & mask) != 0)\r
119                         ptr_align = (char *)(((size_t)ptr+mask)& ~mask);\r
120 \r
121                 virt_mem.vaddr = ptr_align;\r
122                 virt_mem.length = MEM_SIZE;\r
123                 virt_mem.access_ctrl = (IB_AC_LOCAL_WRITE | IB_AC_MW_BIND);\r
124 \r
125                 /*\r
126                  * Register the memory region\r
127                  */\r
128 \r
129                 ib_status = ib_reg_mem(h_pd, &virt_mem, &lkey, &rkey, &h_mr);\r
130                 if(ib_status != IB_SUCCESS)\r
131                 {\r
132                         ALTS_PRINT( ALTS_DBG_ERROR,\r
133                                 ("ib_reg_mem failed status = %s\n", ib_get_err_str(ib_status)) );\r
134                         alts_close_ca(h_ca);\r
135                         break;\r
136                 }\r
137 \r
138                 /*\r
139                  * Query the memory region\r
140                  */\r
141                 ib_status = ib_query_mr(h_mr, &alts_mr_attr);\r
142                 if(ib_status != IB_SUCCESS)\r
143                 {\r
144                         ALTS_PRINT( ALTS_DBG_ERROR,\r
145                                 ("ib_query_mr failed status = %s\n", ib_get_err_str(ib_status)) );\r
146                         alts_close_ca(h_ca);\r
147                         break;\r
148                 }\r
149 \r
150                 if(alts_mr_attr.lkey !=  lkey || alts_mr_attr.rkey !=  rkey)\r
151                 {\r
152                         \r
153                         ALTS_PRINT( ALTS_DBG_ERROR,\r
154                                 ("ib_query_mr failed lkey rkey different from reg\n"));\r
155                         ALTS_PRINT( ALTS_DBG_ERROR,\r
156                                 ("\t\t reg-lkey = %x  query-lkey %x reg-rkey%x query-rkey%x\n" ,\r
157                                 alts_mr_attr.lkey , lkey , alts_mr_attr.rkey ,  rkey));\r
158                         alts_close_ca(h_ca);\r
159                         ib_status = IB_INVALID_LKEY;\r
160                         break;\r
161                         \r
162                 }\r
163 \r
164                 ALTS_PRINT( ALTS_DBG_ERROR,\r
165                         ("ib_query_mr passed\n"\r
166                         "\t\t lkey = %x    rkey%x query-rkey%x\n" ,\r
167                          lkey, rkey, alts_mr_attr.rkey) );\r
168                 /*\r
169                  * Re-register the memeory region\r
170                  */\r
171                 virt_mem.access_ctrl |= (IB_AC_RDMA_WRITE );\r
172 \r
173                 ib_status = ib_rereg_mem(h_mr,IB_MR_MOD_ACCESS,\r
174                         &virt_mem,&lkey,&rkey,NULL);\r
175                 if(ib_status != IB_SUCCESS)\r
176                 {\r
177                         ALTS_PRINT( ALTS_DBG_ERROR,\r
178                                 ("ib_rereg_mem failed status = %s\n", ib_get_err_str(ib_status)) );\r
179                         alts_close_ca(h_ca);\r
180                         break;\r
181                 }\r
182 \r
183                 ALTS_PRINT( ALTS_DBG_ERROR,\r
184                                 ("ib_rereg_mr passed with status = %s\n",ib_get_err_str(ib_status)));\r
185 \r
186                 /*\r
187                  * De-register the memory region\r
188                  */\r
189                 ib_status = ib_dereg_mr(h_mr);\r
190                 if(ib_status != IB_SUCCESS)\r
191                 {\r
192                         ALTS_PRINT( ALTS_DBG_ERROR,\r
193                                 ("ib_dereg_mr failed status = %s\n", ib_get_err_str(ib_status)) );\r
194                         alts_close_ca(h_ca);\r
195                         break;\r
196                 }\r
197 \r
198                 /*\r
199                  * Deallocate the PD\r
200                  */\r
201 \r
202                 ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
203                 if(ib_status != IB_SUCCESS)\r
204                 {\r
205                         ALTS_PRINT( ALTS_DBG_ERROR,\r
206                                 ("ib_dealloc_pd failed status = %s\n",ib_get_err_str(ib_status)) );\r
207                         alts_close_ca(h_ca);\r
208                         break;\r
209                 }\r
210 \r
211                 break; //End of while\r
212         }\r
213 \r
214         if ( ptr )\r
215                 cl_free ( ptr );\r
216         /* Close AL */\r
217         if(h_al)\r
218                 alts_close_al(h_al);\r
219 \r
220         ALTS_EXIT( ALTS_DBG_VERBOSE);\r
221         return ib_status;\r
222 }\r
223 \r
224 /*\r
225  * Test Case RegisterPhyMemRegion\r
226  */\r
227 \r
228 #ifdef CL_KERNEL\r
229 \r
230 ib_api_status_t\r
231 al_test_register_phys_mem(\r
232         void\r
233         )\r
234 {\r
235         ib_api_status_t ib_status = IB_SUCCESS;\r
236         ib_al_handle_t h_al = NULL;\r
237         ib_ca_handle_t h_ca = NULL;\r
238         ib_pd_handle_t h_pd = NULL;\r
239 \r
240         ib_phys_range_t phys_range;\r
241         ib_phys_create_t phys_mem;\r
242         uint64_t                reg_va;\r
243         void                    *virt_addr = NULL;\r
244         uint32_t                lkey;\r
245         uint32_t                rkey;\r
246         ib_mr_handle_t  h_mr = NULL;\r
247         ib_mr_attr_t    alts_mr_attr;\r
248 \r
249         ALTS_ENTER( ALTS_DBG_VERBOSE );\r
250 \r
251         do\r
252         {\r
253                 /* Open AL */\r
254                 ib_status = alts_open_al(&h_al);\r
255 \r
256                 if(ib_status != IB_SUCCESS)\r
257                         break;\r
258 \r
259                 CL_ASSERT(h_al);\r
260 \r
261                 /* Open CA */\r
262                 ib_status = alts_open_ca(h_al,&h_ca);\r
263                 if(ib_status != IB_SUCCESS)\r
264                         break;\r
265 \r
266                 CL_ASSERT(h_ca);\r
267 \r
268                 /*\r
269                  * Allocate a PD here\r
270                  */\r
271                 ib_status = ib_alloc_pd(h_ca, IB_PDT_NORMAL, NULL, &h_pd); //passing null context\r
272 \r
273                 if(ib_status != IB_SUCCESS)\r
274                 {\r
275                         ALTS_PRINT( ALTS_DBG_ERROR,\r
276                                 ("ib_alloc_pd failed status = %s\n", ib_get_err_str(ib_status)) );\r
277                         alts_close_ca(h_ca);\r
278                         break;\r
279                 }\r
280 \r
281                 /*\r
282                  * Allocate the virtual memory which needs to be registered\r
283                  */\r
284 \r
285                 virt_addr = cl_zalloc( cl_get_pagesize() );\r
286                 phys_range.base_addr = cl_get_physaddr( virt_addr );\r
287                 phys_range.size = PAGE_SIZE;\r
288                 phys_mem.length = PAGE_SIZE;\r
289                 phys_mem.num_ranges = 1;\r
290                 phys_mem.range_array = &phys_range;\r
291                 phys_mem.buf_offset = 0;\r
292                 phys_mem.hca_page_size = cl_get_pagesize();\r
293                 phys_mem.access_ctrl = (IB_AC_LOCAL_WRITE | IB_AC_RDMA_READ);\r
294                 reg_va = (uintn_t)virt_addr;\r
295 \r
296                 /*\r
297                  * Register the memory region\r
298                  */\r
299                 ib_status = ib_reg_phys(h_pd, &phys_mem, &reg_va, &lkey, &rkey, &h_mr);\r
300                 if(ib_status != IB_SUCCESS)\r
301                 {\r
302                         ALTS_PRINT( ALTS_DBG_ERROR,\r
303                                 ("ib_reg_phys failed status = %s\n", ib_get_err_str(ib_status)) );\r
304                         alts_close_ca(h_ca);\r
305                         break;\r
306                 }\r
307 \r
308                 /*\r
309                  * Query the memory region\r
310                  */\r
311                 ib_status = ib_query_mr(h_mr, &alts_mr_attr);\r
312                 if(ib_status != IB_SUCCESS)\r
313                 {\r
314                         ALTS_PRINT( ALTS_DBG_ERROR,\r
315                                 ("ib_query_mr failed status = %s\n", ib_get_err_str(ib_status)) );\r
316                         alts_close_ca(h_ca);\r
317                         break;\r
318                 }\r
319 \r
320                 /*\r
321                  * Re-register the memeory region\r
322                  */\r
323                 phys_mem.access_ctrl |= (IB_AC_RDMA_WRITE );\r
324 \r
325                 ib_status = ib_rereg_phys(h_mr,IB_MR_MOD_ACCESS,\r
326                         &phys_mem, &reg_va, &lkey,&rkey,NULL);\r
327                 if(ib_status != IB_SUCCESS)\r
328                 {\r
329                         ALTS_PRINT( ALTS_DBG_ERROR,\r
330                                 ("ib_rereg_phys failed status = %s\n", ib_get_err_str(ib_status)) );\r
331                 }\r
332 \r
333                 ALTS_PRINT( ALTS_DBG_ERROR,\r
334                                 ("ib_rereg_phys passed with status = %s\n",ib_get_err_str(ib_status)));\r
335 \r
336                 /*\r
337                  * De-register the memory region\r
338                  */\r
339                 ib_status = ib_dereg_mr(h_mr);\r
340                 if(ib_status != IB_SUCCESS)\r
341                 {\r
342                         ALTS_PRINT( ALTS_DBG_ERROR,\r
343                                 ("ib_dereg_mr failed status = %s\n", ib_get_err_str(ib_status)) );\r
344                         alts_close_ca(h_ca);\r
345                         break;\r
346                 }\r
347 \r
348                 /*\r
349                  * Deallocate the PD\r
350                  */\r
351 \r
352                 ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
353                 if(ib_status != IB_SUCCESS)\r
354                 {\r
355                         ALTS_PRINT( ALTS_DBG_ERROR,\r
356                                 ("ib_dealloc_pd failed status = %s\n",ib_get_err_str(ib_status)) );\r
357                         alts_close_ca(h_ca);\r
358                         break;\r
359                 }\r
360 \r
361         } while (0);\r
362 \r
363         if ( virt_addr )\r
364         {\r
365                 cl_free ( virt_addr );\r
366         }\r
367         /* Close AL */\r
368         if(h_al)\r
369                 alts_close_al(h_al);\r
370 \r
371         ALTS_EXIT( ALTS_DBG_VERBOSE);\r
372         return ib_status;\r
373 }\r
374 #endif\r
375 \r
376 /*\r
377  * Test Case RegisterSharedMemRegion\r
378  */\r
379 \r
380 ib_api_status_t\r
381 al_test_register_shared_mem(\r
382         void\r
383         )\r
384 {\r
385         ib_api_status_t ib_status = IB_SUCCESS;\r
386         ib_al_handle_t h_al = NULL;\r
387         ib_ca_handle_t h_ca = NULL;\r
388         ib_pd_handle_t h_pd = NULL;\r
389 \r
390         ib_mr_create_t virt_mem;\r
391         uint64_t virt_ptr = 0;\r
392         char *ptr = NULL, *ptr_align;\r
393         size_t mask; \r
394         uint32_t        lkey;\r
395         uint32_t        rkey;\r
396         ib_mr_handle_t  h_base_mr = NULL;\r
397         ib_mr_handle_t  h_mr = NULL;\r
398         ib_mr_attr_t    alts_mr_attr;\r
399 \r
400         ALTS_ENTER( ALTS_DBG_VERBOSE );\r
401 \r
402         do\r
403         {\r
404                 /* Open AL */\r
405                 ib_status = alts_open_al(&h_al);\r
406 \r
407                 if(ib_status != IB_SUCCESS)\r
408                         break;\r
409 \r
410                 CL_ASSERT(h_al);\r
411 \r
412                 /* Open CA */\r
413                 ib_status = alts_open_ca(h_al,&h_ca);\r
414                 if(ib_status != IB_SUCCESS)\r
415                         break;\r
416 \r
417                 CL_ASSERT(h_ca);\r
418 \r
419                 /*\r
420                  * Allocate a PD here\r
421                  */\r
422                 ib_status = ib_alloc_pd(h_ca, IB_PDT_NORMAL, NULL, &h_pd); //passing null context\r
423 \r
424                 if(ib_status != IB_SUCCESS)\r
425                 {\r
426                         ALTS_PRINT( ALTS_DBG_ERROR,\r
427                                 ("ib_alloc_pd failed status = %s\n", ib_get_err_str(ib_status)) );\r
428                         alts_close_ca(h_ca);\r
429                         break;\r
430                 }\r
431 \r
432                 /*\r
433                  * Allocate the virtual memory which needs to be registered\r
434                  */\r
435 \r
436                 mask = MEM_ALLIGN - 1;\r
437 \r
438                 ptr = cl_malloc(MEM_SIZE + MEM_ALLIGN - 1);\r
439 \r
440                 CL_ASSERT(ptr);\r
441 \r
442                 ptr_align = ptr;\r
443 \r
444                 if(((size_t)ptr & mask) != 0)\r
445                         ptr_align = (char *)(((size_t)ptr+mask)& ~mask);\r
446 \r
447                 virt_mem.vaddr = ptr_align;\r
448                 virt_mem.length = MEM_SIZE;\r
449                 virt_mem.access_ctrl = (IB_AC_LOCAL_WRITE | IB_AC_MW_BIND);\r
450 \r
451                 /*\r
452                  * Register the memory region\r
453                  */\r
454 \r
455                 ib_status = ib_reg_mem(h_pd, &virt_mem, &lkey, &rkey, &h_base_mr);\r
456                 if(ib_status != IB_SUCCESS)\r
457                 {\r
458                         ALTS_PRINT( ALTS_DBG_ERROR,\r
459                                 ("ib_reg_mem failed status = %s\n", ib_get_err_str(ib_status)) );\r
460                         alts_close_ca(h_ca);\r
461                         break;\r
462                 }\r
463 \r
464                 /*\r
465                  * Register the same region as shared\r
466                  */\r
467                 virt_ptr = (uintn_t)ptr_align;\r
468                 ib_status = ib_reg_shared(h_base_mr, h_pd, virt_mem.access_ctrl, &virt_ptr, &lkey, &rkey, &h_mr);\r
469                 if(ib_status != IB_SUCCESS)\r
470                 {\r
471                         ALTS_PRINT( ALTS_DBG_ERROR,\r
472                                 ("ib_reg_shared failed status = %s\n", ib_get_err_str(ib_status)) );\r
473                         alts_close_ca(h_ca);\r
474                         break;\r
475                 }\r
476 \r
477                 /*\r
478                  * De-register the base memory region\r
479                  */\r
480                 ib_status = ib_dereg_mr(h_base_mr);\r
481                 if(ib_status != IB_SUCCESS)\r
482                 {\r
483                         ALTS_PRINT( ALTS_DBG_ERROR,\r
484                                 ("ib_dereg_mr (base) failed status = %s\n", ib_get_err_str(ib_status)) );\r
485                         alts_close_ca(h_ca);\r
486                         break;\r
487                 }\r
488 \r
489                 /*\r
490                  * Query the memory region\r
491                  */\r
492                 ib_status = ib_query_mr(h_mr, &alts_mr_attr);\r
493                 if(ib_status != IB_SUCCESS)\r
494                 {\r
495                         ALTS_PRINT( ALTS_DBG_ERROR,\r
496                                 ("ib_query_mr failed status = %s\n", ib_get_err_str(ib_status)) );\r
497                         alts_close_ca(h_ca);\r
498                         break;\r
499                 }\r
500 \r
501                 /*\r
502                  * Re-register the memeory region\r
503                  */\r
504                 virt_mem.access_ctrl |= (IB_AC_RDMA_WRITE );\r
505 \r
506                 ib_status = ib_rereg_mem(h_mr,IB_MR_MOD_ACCESS,\r
507                         &virt_mem,&lkey,&rkey,NULL);\r
508                 if(ib_status != IB_SUCCESS)\r
509                 {\r
510                         ALTS_PRINT( ALTS_DBG_ERROR,\r
511                                 ("ib_rereg_shared failed status = %s\n", ib_get_err_str(ib_status)) );\r
512                 }\r
513 \r
514                 ALTS_PRINT( ALTS_DBG_ERROR,\r
515                                 ("ib_rereg_mr passed with status = %s\n",ib_get_err_str(ib_status)));\r
516 \r
517                 /*\r
518                  * De-register the shared memory region\r
519                  */\r
520                 ib_status = ib_dereg_mr(h_mr);\r
521                 if(ib_status != IB_SUCCESS)\r
522                 {\r
523                         ALTS_PRINT( ALTS_DBG_ERROR,\r
524                                 ("ib_dereg_mr (shared) failed status = %s\n", ib_get_err_str(ib_status)) );\r
525                         alts_close_ca(h_ca);\r
526                         break;\r
527                 }\r
528 \r
529                 /*\r
530                  * Deallocate the PD\r
531                  */\r
532 \r
533                 ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
534                 if(ib_status != IB_SUCCESS)\r
535                 {\r
536                         ALTS_PRINT( ALTS_DBG_ERROR,\r
537                                 ("ib_dealloc_pd failed status = %s\n",ib_get_err_str(ib_status)) );\r
538                         alts_close_ca(h_ca);\r
539                         break;\r
540                 }\r
541 \r
542         } while(0);\r
543 \r
544         if( ptr )\r
545                 cl_free( ptr );\r
546 \r
547         /* Close AL */\r
548         if(h_al)\r
549                 alts_close_al(h_al);\r
550 \r
551         ALTS_EXIT( ALTS_DBG_VERBOSE);\r
552         return ib_status;\r
553 }\r