2 * IBM eServer eHCA Infiniband device driver for Linux on POWER
6 * Authors: Dietmar Decker <ddecker@de.ibm.com>
7 * Christoph Raisch <raisch@de.ibm.com>
9 * Copyright (c) 2005 IBM Corporation
11 * All rights reserved.
13 * This source code is distributed under a dual license of GPL v2.0 and OpenIB
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are met:
21 * Redistributions of source code must retain the above copyright notice, this
22 * list of conditions and the following disclaimer.
24 * Redistributions in binary form must reproduce the above copyright notice,
25 * this list of conditions and the following disclaimer in the documentation
26 * and/or other materials
27 * provided with the distribution.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
36 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
37 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
42 #include <asm/current.h>
44 #include "ehca_iverbs.h"
45 #include "ehca_mrmw.h"
49 static struct kmem_cache *mr_cache;
50 static struct kmem_cache *mw_cache;
52 static struct ehca_mr *ehca_mr_new(void)
56 me = kmem_cache_zalloc(mr_cache, GFP_KERNEL);
58 spin_lock_init(&me->mrlock);
60 ehca_gen_err("alloc failed");
65 static void ehca_mr_delete(struct ehca_mr *me)
67 kmem_cache_free(mr_cache, me);
70 static struct ehca_mw *ehca_mw_new(void)
74 me = kmem_cache_zalloc(mw_cache, GFP_KERNEL);
76 spin_lock_init(&me->mwlock);
78 ehca_gen_err("alloc failed");
83 static void ehca_mw_delete(struct ehca_mw *me)
85 kmem_cache_free(mw_cache, me);
88 /*----------------------------------------------------------------------*/
90 struct ib_mr *ehca_get_dma_mr(struct ib_pd *pd, int mr_access_flags)
94 struct ehca_mr *e_maxmr;
95 struct ehca_pd *e_pd = container_of(pd, struct ehca_pd, ib_pd);
96 struct ehca_shca *shca =
97 container_of(pd->device, struct ehca_shca, ib_device);
100 e_maxmr = ehca_mr_new();
102 ehca_err(&shca->ib_device, "out of memory");
103 ib_mr = ERR_PTR(-ENOMEM);
104 goto get_dma_mr_exit0;
107 ret = ehca_reg_maxmr(shca, e_maxmr, (u64*)KERNELBASE,
108 mr_access_flags, e_pd,
109 &e_maxmr->ib.ib_mr.lkey,
110 &e_maxmr->ib.ib_mr.rkey);
112 ib_mr = ERR_PTR(ret);
113 goto get_dma_mr_exit0;
115 ib_mr = &e_maxmr->ib.ib_mr;
117 ehca_err(&shca->ib_device, "no internal max-MR exist!");
118 ib_mr = ERR_PTR(-EINVAL);
119 goto get_dma_mr_exit0;
124 ehca_err(&shca->ib_device, "rc=%lx pd=%p mr_access_flags=%x ",
125 PTR_ERR(ib_mr), pd, mr_access_flags);
127 } /* end ehca_get_dma_mr() */
129 /*----------------------------------------------------------------------*/
131 struct ib_mr *ehca_reg_phys_mr(struct ib_pd *pd,
132 struct ib_phys_buf *phys_buf_array,
139 struct ehca_mr *e_mr;
140 struct ehca_shca *shca =
141 container_of(pd->device, struct ehca_shca, ib_device);
142 struct ehca_pd *e_pd = container_of(pd, struct ehca_pd, ib_pd);
145 struct ehca_mr_pginfo pginfo={0,0,0,0,0,0,0,NULL,0,NULL,NULL,0,NULL,0};
147 u32 num_pages_4k; /* 4k portion "pages" */
149 if ((num_phys_buf <= 0) || !phys_buf_array) {
150 ehca_err(pd->device, "bad input values: num_phys_buf=%x "
151 "phys_buf_array=%p", num_phys_buf, phys_buf_array);
152 ib_mr = ERR_PTR(-EINVAL);
153 goto reg_phys_mr_exit0;
155 if (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) &&
156 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) ||
157 ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) &&
158 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE))) {
160 * Remote Write Access requires Local Write Access
161 * Remote Atomic Access requires Local Write Access
163 ehca_err(pd->device, "bad input values: mr_access_flags=%x",
165 ib_mr = ERR_PTR(-EINVAL);
166 goto reg_phys_mr_exit0;
169 /* check physical buffer list and calculate size */
170 ret = ehca_mr_chk_buf_and_calc_size(phys_buf_array, num_phys_buf,
173 ib_mr = ERR_PTR(ret);
174 goto reg_phys_mr_exit0;
177 (((u64)iova_start + size) < (u64)iova_start)) {
178 ehca_err(pd->device, "bad input values: size=%lx iova_start=%p",
180 ib_mr = ERR_PTR(-EINVAL);
181 goto reg_phys_mr_exit0;
184 e_mr = ehca_mr_new();
186 ehca_err(pd->device, "out of memory");
187 ib_mr = ERR_PTR(-ENOMEM);
188 goto reg_phys_mr_exit0;
191 /* determine number of MR pages */
192 num_pages_mr = ((((u64)iova_start % PAGE_SIZE) + size +
193 PAGE_SIZE - 1) / PAGE_SIZE);
194 num_pages_4k = ((((u64)iova_start % EHCA_PAGESIZE) + size +
195 EHCA_PAGESIZE - 1) / EHCA_PAGESIZE);
197 /* register MR on HCA */
198 if (ehca_mr_is_maxmr(size, iova_start)) {
199 e_mr->flags |= EHCA_MR_FLAG_MAXMR;
200 ret = ehca_reg_maxmr(shca, e_mr, iova_start, mr_access_flags,
201 e_pd, &e_mr->ib.ib_mr.lkey,
202 &e_mr->ib.ib_mr.rkey);
204 ib_mr = ERR_PTR(ret);
205 goto reg_phys_mr_exit1;
208 pginfo.type = EHCA_MR_PGI_PHYS;
209 pginfo.num_pages = num_pages_mr;
210 pginfo.num_4k = num_pages_4k;
211 pginfo.num_phys_buf = num_phys_buf;
212 pginfo.phys_buf_array = phys_buf_array;
213 pginfo.next_4k = (((u64)iova_start & ~PAGE_MASK) /
216 ret = ehca_reg_mr(shca, e_mr, iova_start, size, mr_access_flags,
217 e_pd, &pginfo, &e_mr->ib.ib_mr.lkey,
218 &e_mr->ib.ib_mr.rkey);
220 ib_mr = ERR_PTR(ret);
221 goto reg_phys_mr_exit1;
225 /* successful registration of all pages */
226 return &e_mr->ib.ib_mr;
229 ehca_mr_delete(e_mr);
232 ehca_err(pd->device, "rc=%lx pd=%p phys_buf_array=%p "
233 "num_phys_buf=%x mr_access_flags=%x iova_start=%p",
234 PTR_ERR(ib_mr), pd, phys_buf_array,
235 num_phys_buf, mr_access_flags, iova_start);
237 } /* end ehca_reg_phys_mr() */
239 /*----------------------------------------------------------------------*/
241 struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd,
242 struct ib_umem *region,
244 struct ib_udata *udata)
247 struct ehca_mr *e_mr;
248 struct ehca_shca *shca =
249 container_of(pd->device, struct ehca_shca, ib_device);
250 struct ehca_pd *e_pd = container_of(pd, struct ehca_pd, ib_pd);
251 struct ehca_mr_pginfo pginfo={0,0,0,0,0,0,0,NULL,0,NULL,NULL,0,NULL,0};
254 u32 num_pages_4k; /* 4k portion "pages" */
257 ehca_gen_err("bad pd=%p", pd);
258 return ERR_PTR(-EFAULT);
261 ehca_err(pd->device, "bad input values: region=%p", region);
262 ib_mr = ERR_PTR(-EINVAL);
263 goto reg_user_mr_exit0;
265 if (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) &&
266 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) ||
267 ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) &&
268 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE))) {
270 * Remote Write Access requires Local Write Access
271 * Remote Atomic Access requires Local Write Access
273 ehca_err(pd->device, "bad input values: mr_access_flags=%x",
275 ib_mr = ERR_PTR(-EINVAL);
276 goto reg_user_mr_exit0;
278 if (region->page_size != PAGE_SIZE) {
279 ehca_err(pd->device, "page size not supported, "
280 "region->page_size=%x", region->page_size);
281 ib_mr = ERR_PTR(-EINVAL);
282 goto reg_user_mr_exit0;
285 if ((region->length == 0) ||
286 ((region->virt_base + region->length) < region->virt_base)) {
287 ehca_err(pd->device, "bad input values: length=%lx "
288 "virt_base=%lx", region->length, region->virt_base);
289 ib_mr = ERR_PTR(-EINVAL);
290 goto reg_user_mr_exit0;
293 e_mr = ehca_mr_new();
295 ehca_err(pd->device, "out of memory");
296 ib_mr = ERR_PTR(-ENOMEM);
297 goto reg_user_mr_exit0;
300 /* determine number of MR pages */
301 num_pages_mr = (((region->virt_base % PAGE_SIZE) + region->length +
302 PAGE_SIZE - 1) / PAGE_SIZE);
303 num_pages_4k = (((region->virt_base % EHCA_PAGESIZE) + region->length +
304 EHCA_PAGESIZE - 1) / EHCA_PAGESIZE);
306 /* register MR on HCA */
307 pginfo.type = EHCA_MR_PGI_USER;
308 pginfo.num_pages = num_pages_mr;
309 pginfo.num_4k = num_pages_4k;
310 pginfo.region = region;
311 pginfo.next_4k = region->offset / EHCA_PAGESIZE;
312 pginfo.next_chunk = list_prepare_entry(pginfo.next_chunk,
313 (®ion->chunk_list),
316 ret = ehca_reg_mr(shca, e_mr, (u64*)region->virt_base,
317 region->length, mr_access_flags, e_pd, &pginfo,
318 &e_mr->ib.ib_mr.lkey, &e_mr->ib.ib_mr.rkey);
320 ib_mr = ERR_PTR(ret);
321 goto reg_user_mr_exit1;
324 /* successful registration of all pages */
325 return &e_mr->ib.ib_mr;
328 ehca_mr_delete(e_mr);
331 ehca_err(pd->device, "rc=%lx pd=%p region=%p mr_access_flags=%x"
333 PTR_ERR(ib_mr), pd, region, mr_access_flags, udata);
335 } /* end ehca_reg_user_mr() */
337 /*----------------------------------------------------------------------*/
339 int ehca_rereg_phys_mr(struct ib_mr *mr,
342 struct ib_phys_buf *phys_buf_array,
349 struct ehca_shca *shca =
350 container_of(mr->device, struct ehca_shca, ib_device);
351 struct ehca_mr *e_mr = container_of(mr, struct ehca_mr, ib.ib_mr);
352 struct ehca_pd *my_pd = container_of(mr->pd, struct ehca_pd, ib_pd);
356 struct ehca_pd *new_pd;
357 u32 tmp_lkey, tmp_rkey;
358 unsigned long sl_flags;
359 u32 num_pages_mr = 0;
360 u32 num_pages_4k = 0; /* 4k portion "pages" */
361 struct ehca_mr_pginfo pginfo={0,0,0,0,0,0,0,NULL,0,NULL,NULL,0,NULL,0};
362 u32 cur_pid = current->tgid;
364 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
365 (my_pd->ownpid != cur_pid)) {
366 ehca_err(mr->device, "Invalid caller pid=%x ownpid=%x",
367 cur_pid, my_pd->ownpid);
369 goto rereg_phys_mr_exit0;
372 if (!(mr_rereg_mask & IB_MR_REREG_TRANS)) {
373 /* TODO not supported, because PHYP rereg hCall needs pages */
374 ehca_err(mr->device, "rereg without IB_MR_REREG_TRANS not "
375 "supported yet, mr_rereg_mask=%x", mr_rereg_mask);
377 goto rereg_phys_mr_exit0;
380 if (mr_rereg_mask & IB_MR_REREG_PD) {
382 ehca_err(mr->device, "rereg with bad pd, pd=%p "
383 "mr_rereg_mask=%x", pd, mr_rereg_mask);
385 goto rereg_phys_mr_exit0;
390 ~(IB_MR_REREG_TRANS | IB_MR_REREG_PD | IB_MR_REREG_ACCESS)) ||
391 (mr_rereg_mask == 0)) {
393 goto rereg_phys_mr_exit0;
396 /* check other parameters */
397 if (e_mr == shca->maxmr) {
398 /* should be impossible, however reject to be sure */
399 ehca_err(mr->device, "rereg internal max-MR impossible, mr=%p "
400 "shca->maxmr=%p mr->lkey=%x",
401 mr, shca->maxmr, mr->lkey);
403 goto rereg_phys_mr_exit0;
405 if (mr_rereg_mask & IB_MR_REREG_TRANS) { /* transl., i.e. addr/size */
406 if (e_mr->flags & EHCA_MR_FLAG_FMR) {
407 ehca_err(mr->device, "not supported for FMR, mr=%p "
408 "flags=%x", mr, e_mr->flags);
410 goto rereg_phys_mr_exit0;
412 if (!phys_buf_array || num_phys_buf <= 0) {
413 ehca_err(mr->device, "bad input values: mr_rereg_mask=%x"
414 " phys_buf_array=%p num_phys_buf=%x",
415 mr_rereg_mask, phys_buf_array, num_phys_buf);
417 goto rereg_phys_mr_exit0;
420 if ((mr_rereg_mask & IB_MR_REREG_ACCESS) && /* change ACL */
421 (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) &&
422 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) ||
423 ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) &&
424 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)))) {
426 * Remote Write Access requires Local Write Access
427 * Remote Atomic Access requires Local Write Access
429 ehca_err(mr->device, "bad input values: mr_rereg_mask=%x "
430 "mr_access_flags=%x", mr_rereg_mask, mr_access_flags);
432 goto rereg_phys_mr_exit0;
435 /* set requested values dependent on rereg request */
436 spin_lock_irqsave(&e_mr->mrlock, sl_flags);
437 new_start = e_mr->start; /* new == old address */
438 new_size = e_mr->size; /* new == old length */
439 new_acl = e_mr->acl; /* new == old access control */
440 new_pd = container_of(mr->pd,struct ehca_pd,ib_pd); /*new == old PD*/
442 if (mr_rereg_mask & IB_MR_REREG_TRANS) {
443 new_start = iova_start; /* change address */
444 /* check physical buffer list and calculate size */
445 ret = ehca_mr_chk_buf_and_calc_size(phys_buf_array,
446 num_phys_buf, iova_start,
449 goto rereg_phys_mr_exit1;
450 if ((new_size == 0) ||
451 (((u64)iova_start + new_size) < (u64)iova_start)) {
452 ehca_err(mr->device, "bad input values: new_size=%lx "
453 "iova_start=%p", new_size, iova_start);
455 goto rereg_phys_mr_exit1;
457 num_pages_mr = ((((u64)new_start % PAGE_SIZE) + new_size +
458 PAGE_SIZE - 1) / PAGE_SIZE);
459 num_pages_4k = ((((u64)new_start % EHCA_PAGESIZE) + new_size +
460 EHCA_PAGESIZE - 1) / EHCA_PAGESIZE);
461 pginfo.type = EHCA_MR_PGI_PHYS;
462 pginfo.num_pages = num_pages_mr;
463 pginfo.num_4k = num_pages_4k;
464 pginfo.num_phys_buf = num_phys_buf;
465 pginfo.phys_buf_array = phys_buf_array;
466 pginfo.next_4k = (((u64)iova_start & ~PAGE_MASK) /
469 if (mr_rereg_mask & IB_MR_REREG_ACCESS)
470 new_acl = mr_access_flags;
471 if (mr_rereg_mask & IB_MR_REREG_PD)
472 new_pd = container_of(pd, struct ehca_pd, ib_pd);
474 ret = ehca_rereg_mr(shca, e_mr, new_start, new_size, new_acl,
475 new_pd, &pginfo, &tmp_lkey, &tmp_rkey);
477 goto rereg_phys_mr_exit1;
479 /* successful reregistration */
480 if (mr_rereg_mask & IB_MR_REREG_PD)
486 spin_unlock_irqrestore(&e_mr->mrlock, sl_flags);
489 ehca_err(mr->device, "ret=%x mr=%p mr_rereg_mask=%x pd=%p "
490 "phys_buf_array=%p num_phys_buf=%x mr_access_flags=%x "
492 ret, mr, mr_rereg_mask, pd, phys_buf_array,
493 num_phys_buf, mr_access_flags, iova_start);
495 } /* end ehca_rereg_phys_mr() */
497 /*----------------------------------------------------------------------*/
499 int ehca_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr)
503 struct ehca_shca *shca =
504 container_of(mr->device, struct ehca_shca, ib_device);
505 struct ehca_mr *e_mr = container_of(mr, struct ehca_mr, ib.ib_mr);
506 struct ehca_pd *my_pd = container_of(mr->pd, struct ehca_pd, ib_pd);
507 u32 cur_pid = current->tgid;
508 unsigned long sl_flags;
509 struct ehca_mr_hipzout_parms hipzout = {{0},0,0,0,0,0};
511 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
512 (my_pd->ownpid != cur_pid)) {
513 ehca_err(mr->device, "Invalid caller pid=%x ownpid=%x",
514 cur_pid, my_pd->ownpid);
519 if ((e_mr->flags & EHCA_MR_FLAG_FMR)) {
520 ehca_err(mr->device, "not supported for FMR, mr=%p e_mr=%p "
521 "e_mr->flags=%x", mr, e_mr, e_mr->flags);
526 memset(mr_attr, 0, sizeof(struct ib_mr_attr));
527 spin_lock_irqsave(&e_mr->mrlock, sl_flags);
529 h_ret = hipz_h_query_mr(shca->ipz_hca_handle, e_mr, &hipzout);
530 if (h_ret != H_SUCCESS) {
531 ehca_err(mr->device, "hipz_mr_query failed, h_ret=%lx mr=%p "
532 "hca_hndl=%lx mr_hndl=%lx lkey=%x",
533 h_ret, mr, shca->ipz_hca_handle.handle,
534 e_mr->ipz_mr_handle.handle, mr->lkey);
535 ret = ehca_mrmw_map_hrc_query_mr(h_ret);
538 mr_attr->pd = mr->pd;
539 mr_attr->device_virt_addr = hipzout.vaddr;
540 mr_attr->size = hipzout.len;
541 mr_attr->lkey = hipzout.lkey;
542 mr_attr->rkey = hipzout.rkey;
543 ehca_mrmw_reverse_map_acl(&hipzout.acl, &mr_attr->mr_access_flags);
546 spin_unlock_irqrestore(&e_mr->mrlock, sl_flags);
549 ehca_err(mr->device, "ret=%x mr=%p mr_attr=%p",
552 } /* end ehca_query_mr() */
554 /*----------------------------------------------------------------------*/
556 int ehca_dereg_mr(struct ib_mr *mr)
560 struct ehca_shca *shca =
561 container_of(mr->device, struct ehca_shca, ib_device);
562 struct ehca_mr *e_mr = container_of(mr, struct ehca_mr, ib.ib_mr);
563 struct ehca_pd *my_pd = container_of(mr->pd, struct ehca_pd, ib_pd);
564 u32 cur_pid = current->tgid;
566 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
567 (my_pd->ownpid != cur_pid)) {
568 ehca_err(mr->device, "Invalid caller pid=%x ownpid=%x",
569 cur_pid, my_pd->ownpid);
574 if ((e_mr->flags & EHCA_MR_FLAG_FMR)) {
575 ehca_err(mr->device, "not supported for FMR, mr=%p e_mr=%p "
576 "e_mr->flags=%x", mr, e_mr, e_mr->flags);
579 } else if (e_mr == shca->maxmr) {
580 /* should be impossible, however reject to be sure */
581 ehca_err(mr->device, "dereg internal max-MR impossible, mr=%p "
582 "shca->maxmr=%p mr->lkey=%x",
583 mr, shca->maxmr, mr->lkey);
588 /* TODO: BUSY: MR still has bound window(s) */
589 h_ret = hipz_h_free_resource_mr(shca->ipz_hca_handle, e_mr);
590 if (h_ret != H_SUCCESS) {
591 ehca_err(mr->device, "hipz_free_mr failed, h_ret=%lx shca=%p "
592 "e_mr=%p hca_hndl=%lx mr_hndl=%lx mr->lkey=%x",
593 h_ret, shca, e_mr, shca->ipz_hca_handle.handle,
594 e_mr->ipz_mr_handle.handle, mr->lkey);
595 ret = ehca_mrmw_map_hrc_free_mr(h_ret);
599 /* successful deregistration */
600 ehca_mr_delete(e_mr);
604 ehca_err(mr->device, "ret=%x mr=%p", ret, mr);
606 } /* end ehca_dereg_mr() */
608 /*----------------------------------------------------------------------*/
610 struct ib_mw *ehca_alloc_mw(struct ib_pd *pd)
614 struct ehca_mw *e_mw;
615 struct ehca_pd *e_pd = container_of(pd, struct ehca_pd, ib_pd);
616 struct ehca_shca *shca =
617 container_of(pd->device, struct ehca_shca, ib_device);
618 struct ehca_mw_hipzout_parms hipzout = {{0},0};
620 e_mw = ehca_mw_new();
622 ib_mw = ERR_PTR(-ENOMEM);
626 h_ret = hipz_h_alloc_resource_mw(shca->ipz_hca_handle, e_mw,
627 e_pd->fw_pd, &hipzout);
628 if (h_ret != H_SUCCESS) {
629 ehca_err(pd->device, "hipz_mw_allocate failed, h_ret=%lx "
630 "shca=%p hca_hndl=%lx mw=%p",
631 h_ret, shca, shca->ipz_hca_handle.handle, e_mw);
632 ib_mw = ERR_PTR(ehca_mrmw_map_hrc_alloc(h_ret));
635 /* successful MW allocation */
636 e_mw->ipz_mw_handle = hipzout.handle;
637 e_mw->ib_mw.rkey = hipzout.rkey;
641 ehca_mw_delete(e_mw);
644 ehca_err(pd->device, "rc=%lx pd=%p", PTR_ERR(ib_mw), pd);
646 } /* end ehca_alloc_mw() */
648 /*----------------------------------------------------------------------*/
650 int ehca_bind_mw(struct ib_qp *qp,
652 struct ib_mw_bind *mw_bind)
654 /* TODO: not supported up to now */
655 ehca_gen_err("bind MW currently not supported by HCAD");
658 } /* end ehca_bind_mw() */
660 /*----------------------------------------------------------------------*/
662 int ehca_dealloc_mw(struct ib_mw *mw)
665 struct ehca_shca *shca =
666 container_of(mw->device, struct ehca_shca, ib_device);
667 struct ehca_mw *e_mw = container_of(mw, struct ehca_mw, ib_mw);
669 h_ret = hipz_h_free_resource_mw(shca->ipz_hca_handle, e_mw);
670 if (h_ret != H_SUCCESS) {
671 ehca_err(mw->device, "hipz_free_mw failed, h_ret=%lx shca=%p "
672 "mw=%p rkey=%x hca_hndl=%lx mw_hndl=%lx",
673 h_ret, shca, mw, mw->rkey, shca->ipz_hca_handle.handle,
674 e_mw->ipz_mw_handle.handle);
675 return ehca_mrmw_map_hrc_free_mw(h_ret);
677 /* successful deallocation */
678 ehca_mw_delete(e_mw);
680 } /* end ehca_dealloc_mw() */
682 /*----------------------------------------------------------------------*/
684 struct ib_fmr *ehca_alloc_fmr(struct ib_pd *pd,
686 struct ib_fmr_attr *fmr_attr)
688 struct ib_fmr *ib_fmr;
689 struct ehca_shca *shca =
690 container_of(pd->device, struct ehca_shca, ib_device);
691 struct ehca_pd *e_pd = container_of(pd, struct ehca_pd, ib_pd);
692 struct ehca_mr *e_fmr;
694 u32 tmp_lkey, tmp_rkey;
695 struct ehca_mr_pginfo pginfo={0,0,0,0,0,0,0,NULL,0,NULL,NULL,0,NULL,0};
697 /* check other parameters */
698 if (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) &&
699 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) ||
700 ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) &&
701 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE))) {
703 * Remote Write Access requires Local Write Access
704 * Remote Atomic Access requires Local Write Access
706 ehca_err(pd->device, "bad input values: mr_access_flags=%x",
708 ib_fmr = ERR_PTR(-EINVAL);
709 goto alloc_fmr_exit0;
711 if (mr_access_flags & IB_ACCESS_MW_BIND) {
712 ehca_err(pd->device, "bad input values: mr_access_flags=%x",
714 ib_fmr = ERR_PTR(-EINVAL);
715 goto alloc_fmr_exit0;
717 if ((fmr_attr->max_pages == 0) || (fmr_attr->max_maps == 0)) {
718 ehca_err(pd->device, "bad input values: fmr_attr->max_pages=%x "
719 "fmr_attr->max_maps=%x fmr_attr->page_shift=%x",
720 fmr_attr->max_pages, fmr_attr->max_maps,
721 fmr_attr->page_shift);
722 ib_fmr = ERR_PTR(-EINVAL);
723 goto alloc_fmr_exit0;
725 if (((1 << fmr_attr->page_shift) != EHCA_PAGESIZE) &&
726 ((1 << fmr_attr->page_shift) != PAGE_SIZE)) {
727 ehca_err(pd->device, "unsupported fmr_attr->page_shift=%x",
728 fmr_attr->page_shift);
729 ib_fmr = ERR_PTR(-EINVAL);
730 goto alloc_fmr_exit0;
733 e_fmr = ehca_mr_new();
735 ib_fmr = ERR_PTR(-ENOMEM);
736 goto alloc_fmr_exit0;
738 e_fmr->flags |= EHCA_MR_FLAG_FMR;
740 /* register MR on HCA */
741 ret = ehca_reg_mr(shca, e_fmr, NULL,
742 fmr_attr->max_pages * (1 << fmr_attr->page_shift),
743 mr_access_flags, e_pd, &pginfo,
744 &tmp_lkey, &tmp_rkey);
746 ib_fmr = ERR_PTR(ret);
747 goto alloc_fmr_exit1;
751 e_fmr->fmr_page_size = 1 << fmr_attr->page_shift;
752 e_fmr->fmr_max_pages = fmr_attr->max_pages;
753 e_fmr->fmr_max_maps = fmr_attr->max_maps;
754 e_fmr->fmr_map_cnt = 0;
755 return &e_fmr->ib.ib_fmr;
758 ehca_mr_delete(e_fmr);
761 ehca_err(pd->device, "rc=%lx pd=%p mr_access_flags=%x "
762 "fmr_attr=%p", PTR_ERR(ib_fmr), pd,
763 mr_access_flags, fmr_attr);
765 } /* end ehca_alloc_fmr() */
767 /*----------------------------------------------------------------------*/
769 int ehca_map_phys_fmr(struct ib_fmr *fmr,
775 struct ehca_shca *shca =
776 container_of(fmr->device, struct ehca_shca, ib_device);
777 struct ehca_mr *e_fmr = container_of(fmr, struct ehca_mr, ib.ib_fmr);
778 struct ehca_pd *e_pd = container_of(fmr->pd, struct ehca_pd, ib_pd);
779 struct ehca_mr_pginfo pginfo={0,0,0,0,0,0,0,NULL,0,NULL,NULL,0,NULL,0};
780 u32 tmp_lkey, tmp_rkey;
782 if (!(e_fmr->flags & EHCA_MR_FLAG_FMR)) {
783 ehca_err(fmr->device, "not a FMR, e_fmr=%p e_fmr->flags=%x",
784 e_fmr, e_fmr->flags);
786 goto map_phys_fmr_exit0;
788 ret = ehca_fmr_check_page_list(e_fmr, page_list, list_len);
790 goto map_phys_fmr_exit0;
791 if (iova % e_fmr->fmr_page_size) {
792 /* only whole-numbered pages */
793 ehca_err(fmr->device, "bad iova, iova=%lx fmr_page_size=%x",
794 iova, e_fmr->fmr_page_size);
796 goto map_phys_fmr_exit0;
798 if (e_fmr->fmr_map_cnt >= e_fmr->fmr_max_maps) {
799 /* HCAD does not limit the maps, however trace this anyway */
800 ehca_info(fmr->device, "map limit exceeded, fmr=%p "
801 "e_fmr->fmr_map_cnt=%x e_fmr->fmr_max_maps=%x",
802 fmr, e_fmr->fmr_map_cnt, e_fmr->fmr_max_maps);
805 pginfo.type = EHCA_MR_PGI_FMR;
806 pginfo.num_pages = list_len;
807 pginfo.num_4k = list_len * (e_fmr->fmr_page_size / EHCA_PAGESIZE);
808 pginfo.page_list = page_list;
809 pginfo.next_4k = ((iova & (e_fmr->fmr_page_size-1)) /
812 ret = ehca_rereg_mr(shca, e_fmr, (u64*)iova,
813 list_len * e_fmr->fmr_page_size,
814 e_fmr->acl, e_pd, &pginfo, &tmp_lkey, &tmp_rkey);
816 goto map_phys_fmr_exit0;
818 /* successful reregistration */
819 e_fmr->fmr_map_cnt++;
820 e_fmr->ib.ib_fmr.lkey = tmp_lkey;
821 e_fmr->ib.ib_fmr.rkey = tmp_rkey;
826 ehca_err(fmr->device, "ret=%x fmr=%p page_list=%p list_len=%x "
828 ret, fmr, page_list, list_len, iova);
830 } /* end ehca_map_phys_fmr() */
832 /*----------------------------------------------------------------------*/
834 int ehca_unmap_fmr(struct list_head *fmr_list)
837 struct ib_fmr *ib_fmr;
838 struct ehca_shca *shca = NULL;
839 struct ehca_shca *prev_shca;
840 struct ehca_mr *e_fmr;
842 u32 unmap_fmr_cnt = 0;
844 /* check all FMR belong to same SHCA, and check internal flag */
845 list_for_each_entry(ib_fmr, fmr_list, list) {
848 ehca_gen_err("bad fmr=%p in list", ib_fmr);
850 goto unmap_fmr_exit0;
852 shca = container_of(ib_fmr->device, struct ehca_shca,
854 e_fmr = container_of(ib_fmr, struct ehca_mr, ib.ib_fmr);
855 if ((shca != prev_shca) && prev_shca) {
856 ehca_err(&shca->ib_device, "SHCA mismatch, shca=%p "
857 "prev_shca=%p e_fmr=%p",
858 shca, prev_shca, e_fmr);
860 goto unmap_fmr_exit0;
862 if (!(e_fmr->flags & EHCA_MR_FLAG_FMR)) {
863 ehca_err(&shca->ib_device, "not a FMR, e_fmr=%p "
864 "e_fmr->flags=%x", e_fmr, e_fmr->flags);
866 goto unmap_fmr_exit0;
871 /* loop over all FMRs to unmap */
872 list_for_each_entry(ib_fmr, fmr_list, list) {
874 e_fmr = container_of(ib_fmr, struct ehca_mr, ib.ib_fmr);
875 shca = container_of(ib_fmr->device, struct ehca_shca,
877 ret = ehca_unmap_one_fmr(shca, e_fmr);
879 /* unmap failed, stop unmapping of rest of FMRs */
880 ehca_err(&shca->ib_device, "unmap of one FMR failed, "
881 "stop rest, e_fmr=%p num_fmr=%x "
882 "unmap_fmr_cnt=%x lkey=%x", e_fmr, num_fmr,
883 unmap_fmr_cnt, e_fmr->ib.ib_fmr.lkey);
884 goto unmap_fmr_exit0;
890 ehca_gen_err("ret=%x fmr_list=%p num_fmr=%x unmap_fmr_cnt=%x",
891 ret, fmr_list, num_fmr, unmap_fmr_cnt);
893 } /* end ehca_unmap_fmr() */
895 /*----------------------------------------------------------------------*/
897 int ehca_dealloc_fmr(struct ib_fmr *fmr)
901 struct ehca_shca *shca =
902 container_of(fmr->device, struct ehca_shca, ib_device);
903 struct ehca_mr *e_fmr = container_of(fmr, struct ehca_mr, ib.ib_fmr);
905 if (!(e_fmr->flags & EHCA_MR_FLAG_FMR)) {
906 ehca_err(fmr->device, "not a FMR, e_fmr=%p e_fmr->flags=%x",
907 e_fmr, e_fmr->flags);
912 h_ret = hipz_h_free_resource_mr(shca->ipz_hca_handle, e_fmr);
913 if (h_ret != H_SUCCESS) {
914 ehca_err(fmr->device, "hipz_free_mr failed, h_ret=%lx e_fmr=%p "
915 "hca_hndl=%lx fmr_hndl=%lx fmr->lkey=%x",
916 h_ret, e_fmr, shca->ipz_hca_handle.handle,
917 e_fmr->ipz_mr_handle.handle, fmr->lkey);
918 ret = ehca_mrmw_map_hrc_free_mr(h_ret);
921 /* successful deregistration */
922 ehca_mr_delete(e_fmr);
927 ehca_err(&shca->ib_device, "ret=%x fmr=%p", ret, fmr);
929 } /* end ehca_dealloc_fmr() */
931 /*----------------------------------------------------------------------*/
933 int ehca_reg_mr(struct ehca_shca *shca,
934 struct ehca_mr *e_mr,
938 struct ehca_pd *e_pd,
939 struct ehca_mr_pginfo *pginfo,
946 struct ehca_mr_hipzout_parms hipzout = {{0},0,0,0,0,0};
948 ehca_mrmw_map_acl(acl, &hipz_acl);
949 ehca_mrmw_set_pgsize_hipz_acl(&hipz_acl);
950 if (ehca_use_hp_mr == 1)
951 hipz_acl |= 0x00000001;
953 h_ret = hipz_h_alloc_resource_mr(shca->ipz_hca_handle, e_mr,
954 (u64)iova_start, size, hipz_acl,
955 e_pd->fw_pd, &hipzout);
956 if (h_ret != H_SUCCESS) {
957 ehca_err(&shca->ib_device, "hipz_alloc_mr failed, h_ret=%lx "
958 "hca_hndl=%lx", h_ret, shca->ipz_hca_handle.handle);
959 ret = ehca_mrmw_map_hrc_alloc(h_ret);
960 goto ehca_reg_mr_exit0;
963 e_mr->ipz_mr_handle = hipzout.handle;
965 ret = ehca_reg_mr_rpages(shca, e_mr, pginfo);
967 goto ehca_reg_mr_exit1;
969 /* successful registration */
970 e_mr->num_pages = pginfo->num_pages;
971 e_mr->num_4k = pginfo->num_4k;
972 e_mr->start = iova_start;
975 *lkey = hipzout.lkey;
976 *rkey = hipzout.rkey;
980 h_ret = hipz_h_free_resource_mr(shca->ipz_hca_handle, e_mr);
981 if (h_ret != H_SUCCESS) {
982 ehca_err(&shca->ib_device, "h_ret=%lx shca=%p e_mr=%p "
983 "iova_start=%p size=%lx acl=%x e_pd=%p lkey=%x "
984 "pginfo=%p num_pages=%lx num_4k=%lx ret=%x",
985 h_ret, shca, e_mr, iova_start, size, acl, e_pd,
986 hipzout.lkey, pginfo, pginfo->num_pages,
987 pginfo->num_4k, ret);
988 ehca_err(&shca->ib_device, "internal error in ehca_reg_mr, "
993 ehca_err(&shca->ib_device, "ret=%x shca=%p e_mr=%p "
994 "iova_start=%p size=%lx acl=%x e_pd=%p pginfo=%p "
995 "num_pages=%lx num_4k=%lx",
996 ret, shca, e_mr, iova_start, size, acl, e_pd, pginfo,
997 pginfo->num_pages, pginfo->num_4k);
999 } /* end ehca_reg_mr() */
1001 /*----------------------------------------------------------------------*/
1003 int ehca_reg_mr_rpages(struct ehca_shca *shca,
1004 struct ehca_mr *e_mr,
1005 struct ehca_mr_pginfo *pginfo)
1014 kpage = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1016 ehca_err(&shca->ib_device, "kpage alloc failed");
1018 goto ehca_reg_mr_rpages_exit0;
1021 /* max 512 pages per shot */
1022 for (i = 0; i < ((pginfo->num_4k + 512 - 1) / 512); i++) {
1024 if (i == ((pginfo->num_4k + 512 - 1) / 512) - 1) {
1025 rnum = pginfo->num_4k % 512; /* last shot */
1027 rnum = 512; /* last shot is full */
1032 ret = ehca_set_pagebuf(e_mr, pginfo, rnum, kpage);
1034 ehca_err(&shca->ib_device, "ehca_set_pagebuf "
1035 "bad rc, ret=%x rnum=%x kpage=%p",
1038 goto ehca_reg_mr_rpages_exit1;
1040 rpage = virt_to_abs(kpage);
1042 ehca_err(&shca->ib_device, "kpage=%p i=%x",
1045 goto ehca_reg_mr_rpages_exit1;
1047 } else { /* rnum==1 */
1048 ret = ehca_set_pagebuf_1(e_mr, pginfo, &rpage);
1050 ehca_err(&shca->ib_device, "ehca_set_pagebuf_1 "
1051 "bad rc, ret=%x i=%x", ret, i);
1053 goto ehca_reg_mr_rpages_exit1;
1057 h_ret = hipz_h_register_rpage_mr(shca->ipz_hca_handle, e_mr,
1058 0, /* pagesize 4k */
1061 if (i == ((pginfo->num_4k + 512 - 1) / 512) - 1) {
1063 * check for 'registration complete'==H_SUCCESS
1064 * and for 'page registered'==H_PAGE_REGISTERED
1066 if (h_ret != H_SUCCESS) {
1067 ehca_err(&shca->ib_device, "last "
1068 "hipz_reg_rpage_mr failed, h_ret=%lx "
1069 "e_mr=%p i=%x hca_hndl=%lx mr_hndl=%lx"
1070 " lkey=%x", h_ret, e_mr, i,
1071 shca->ipz_hca_handle.handle,
1072 e_mr->ipz_mr_handle.handle,
1073 e_mr->ib.ib_mr.lkey);
1074 ret = ehca_mrmw_map_hrc_rrpg_last(h_ret);
1078 } else if (h_ret != H_PAGE_REGISTERED) {
1079 ehca_err(&shca->ib_device, "hipz_reg_rpage_mr failed, "
1080 "h_ret=%lx e_mr=%p i=%x lkey=%x hca_hndl=%lx "
1081 "mr_hndl=%lx", h_ret, e_mr, i,
1082 e_mr->ib.ib_mr.lkey,
1083 shca->ipz_hca_handle.handle,
1084 e_mr->ipz_mr_handle.handle);
1085 ret = ehca_mrmw_map_hrc_rrpg_notlast(h_ret);
1092 ehca_reg_mr_rpages_exit1:
1093 ehca_free_fw_ctrlblock(kpage);
1094 ehca_reg_mr_rpages_exit0:
1096 ehca_err(&shca->ib_device, "ret=%x shca=%p e_mr=%p pginfo=%p "
1097 "num_pages=%lx num_4k=%lx", ret, shca, e_mr, pginfo,
1098 pginfo->num_pages, pginfo->num_4k);
1100 } /* end ehca_reg_mr_rpages() */
1102 /*----------------------------------------------------------------------*/
1104 inline int ehca_rereg_mr_rereg1(struct ehca_shca *shca,
1105 struct ehca_mr *e_mr,
1109 struct ehca_pd *e_pd,
1110 struct ehca_mr_pginfo *pginfo,
1119 struct ehca_mr_pginfo pginfo_save;
1120 struct ehca_mr_hipzout_parms hipzout = {{0},0,0,0,0,0};
1122 ehca_mrmw_map_acl(acl, &hipz_acl);
1123 ehca_mrmw_set_pgsize_hipz_acl(&hipz_acl);
1125 kpage = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1127 ehca_err(&shca->ib_device, "kpage alloc failed");
1129 goto ehca_rereg_mr_rereg1_exit0;
1132 pginfo_save = *pginfo;
1133 ret = ehca_set_pagebuf(e_mr, pginfo, pginfo->num_4k, kpage);
1135 ehca_err(&shca->ib_device, "set pagebuf failed, e_mr=%p "
1136 "pginfo=%p type=%x num_pages=%lx num_4k=%lx kpage=%p",
1137 e_mr, pginfo, pginfo->type, pginfo->num_pages,
1138 pginfo->num_4k,kpage);
1139 goto ehca_rereg_mr_rereg1_exit1;
1141 rpage = virt_to_abs(kpage);
1143 ehca_err(&shca->ib_device, "kpage=%p", kpage);
1145 goto ehca_rereg_mr_rereg1_exit1;
1147 h_ret = hipz_h_reregister_pmr(shca->ipz_hca_handle, e_mr,
1148 (u64)iova_start, size, hipz_acl,
1149 e_pd->fw_pd, rpage, &hipzout);
1150 if (h_ret != H_SUCCESS) {
1152 * reregistration unsuccessful, try it again with the 3 hCalls,
1153 * e.g. this is required in case H_MR_CONDITION
1154 * (MW bound or MR is shared)
1156 ehca_warn(&shca->ib_device, "hipz_h_reregister_pmr failed "
1157 "(Rereg1), h_ret=%lx e_mr=%p", h_ret, e_mr);
1158 *pginfo = pginfo_save;
1160 } else if ((u64*)hipzout.vaddr != iova_start) {
1161 ehca_err(&shca->ib_device, "PHYP changed iova_start in "
1162 "rereg_pmr, iova_start=%p iova_start_out=%lx e_mr=%p "
1163 "mr_handle=%lx lkey=%x lkey_out=%x", iova_start,
1164 hipzout.vaddr, e_mr, e_mr->ipz_mr_handle.handle,
1165 e_mr->ib.ib_mr.lkey, hipzout.lkey);
1169 * successful reregistration
1170 * note: start and start_out are identical for eServer HCAs
1172 e_mr->num_pages = pginfo->num_pages;
1173 e_mr->num_4k = pginfo->num_4k;
1174 e_mr->start = iova_start;
1177 *lkey = hipzout.lkey;
1178 *rkey = hipzout.rkey;
1181 ehca_rereg_mr_rereg1_exit1:
1182 ehca_free_fw_ctrlblock(kpage);
1183 ehca_rereg_mr_rereg1_exit0:
1184 if ( ret && (ret != -EAGAIN) )
1185 ehca_err(&shca->ib_device, "ret=%x lkey=%x rkey=%x "
1186 "pginfo=%p num_pages=%lx num_4k=%lx",
1187 ret, *lkey, *rkey, pginfo, pginfo->num_pages,
1190 } /* end ehca_rereg_mr_rereg1() */
1192 /*----------------------------------------------------------------------*/
1194 int ehca_rereg_mr(struct ehca_shca *shca,
1195 struct ehca_mr *e_mr,
1199 struct ehca_pd *e_pd,
1200 struct ehca_mr_pginfo *pginfo,
1206 int rereg_1_hcall = 1; /* 1: use hipz_h_reregister_pmr directly */
1207 int rereg_3_hcall = 0; /* 1: use 3 hipz calls for reregistration */
1209 /* first determine reregistration hCall(s) */
1210 if ((pginfo->num_4k > 512) || (e_mr->num_4k > 512) ||
1211 (pginfo->num_4k > e_mr->num_4k)) {
1212 ehca_dbg(&shca->ib_device, "Rereg3 case, pginfo->num_4k=%lx "
1213 "e_mr->num_4k=%x", pginfo->num_4k, e_mr->num_4k);
1218 if (e_mr->flags & EHCA_MR_FLAG_MAXMR) { /* check for max-MR */
1221 e_mr->flags &= ~EHCA_MR_FLAG_MAXMR;
1222 ehca_err(&shca->ib_device, "Rereg MR for max-MR! e_mr=%p",
1226 if (rereg_1_hcall) {
1227 ret = ehca_rereg_mr_rereg1(shca, e_mr, iova_start, size,
1228 acl, e_pd, pginfo, lkey, rkey);
1233 goto ehca_rereg_mr_exit0;
1237 if (rereg_3_hcall) {
1238 struct ehca_mr save_mr;
1240 /* first deregister old MR */
1241 h_ret = hipz_h_free_resource_mr(shca->ipz_hca_handle, e_mr);
1242 if (h_ret != H_SUCCESS) {
1243 ehca_err(&shca->ib_device, "hipz_free_mr failed, "
1244 "h_ret=%lx e_mr=%p hca_hndl=%lx mr_hndl=%lx "
1246 h_ret, e_mr, shca->ipz_hca_handle.handle,
1247 e_mr->ipz_mr_handle.handle,
1248 e_mr->ib.ib_mr.lkey);
1249 ret = ehca_mrmw_map_hrc_free_mr(h_ret);
1250 goto ehca_rereg_mr_exit0;
1252 /* clean ehca_mr_t, without changing struct ib_mr and lock */
1254 ehca_mr_deletenew(e_mr);
1256 /* set some MR values */
1257 e_mr->flags = save_mr.flags;
1258 e_mr->fmr_page_size = save_mr.fmr_page_size;
1259 e_mr->fmr_max_pages = save_mr.fmr_max_pages;
1260 e_mr->fmr_max_maps = save_mr.fmr_max_maps;
1261 e_mr->fmr_map_cnt = save_mr.fmr_map_cnt;
1263 ret = ehca_reg_mr(shca, e_mr, iova_start, size, acl,
1264 e_pd, pginfo, lkey, rkey);
1266 u32 offset = (u64)(&e_mr->flags) - (u64)e_mr;
1267 memcpy(&e_mr->flags, &(save_mr.flags),
1268 sizeof(struct ehca_mr) - offset);
1269 goto ehca_rereg_mr_exit0;
1273 ehca_rereg_mr_exit0:
1275 ehca_err(&shca->ib_device, "ret=%x shca=%p e_mr=%p "
1276 "iova_start=%p size=%lx acl=%x e_pd=%p pginfo=%p "
1277 "num_pages=%lx lkey=%x rkey=%x rereg_1_hcall=%x "
1278 "rereg_3_hcall=%x", ret, shca, e_mr, iova_start, size,
1279 acl, e_pd, pginfo, pginfo->num_pages, *lkey, *rkey,
1280 rereg_1_hcall, rereg_3_hcall);
1282 } /* end ehca_rereg_mr() */
1284 /*----------------------------------------------------------------------*/
1286 int ehca_unmap_one_fmr(struct ehca_shca *shca,
1287 struct ehca_mr *e_fmr)
1291 int rereg_1_hcall = 1; /* 1: use hipz_mr_reregister directly */
1292 int rereg_3_hcall = 0; /* 1: use 3 hipz calls for unmapping */
1293 struct ehca_pd *e_pd =
1294 container_of(e_fmr->ib.ib_fmr.pd, struct ehca_pd, ib_pd);
1295 struct ehca_mr save_fmr;
1296 u32 tmp_lkey, tmp_rkey;
1297 struct ehca_mr_pginfo pginfo={0,0,0,0,0,0,0,NULL,0,NULL,NULL,0,NULL,0};
1298 struct ehca_mr_hipzout_parms hipzout = {{0},0,0,0,0,0};
1300 /* first check if reregistration hCall can be used for unmap */
1301 if (e_fmr->fmr_max_pages > 512) {
1306 if (rereg_1_hcall) {
1308 * note: after using rereg hcall with len=0,
1309 * rereg hcall must be used again for registering pages
1311 h_ret = hipz_h_reregister_pmr(shca->ipz_hca_handle, e_fmr, 0,
1312 0, 0, e_pd->fw_pd, 0, &hipzout);
1313 if (h_ret != H_SUCCESS) {
1315 * should not happen, because length checked above,
1316 * FMRs are not shared and no MW bound to FMRs
1318 ehca_err(&shca->ib_device, "hipz_reregister_pmr failed "
1319 "(Rereg1), h_ret=%lx e_fmr=%p hca_hndl=%lx "
1320 "mr_hndl=%lx lkey=%x lkey_out=%x",
1321 h_ret, e_fmr, shca->ipz_hca_handle.handle,
1322 e_fmr->ipz_mr_handle.handle,
1323 e_fmr->ib.ib_fmr.lkey, hipzout.lkey);
1326 /* successful reregistration */
1327 e_fmr->start = NULL;
1329 tmp_lkey = hipzout.lkey;
1330 tmp_rkey = hipzout.rkey;
1334 if (rereg_3_hcall) {
1335 struct ehca_mr save_mr;
1337 /* first free old FMR */
1338 h_ret = hipz_h_free_resource_mr(shca->ipz_hca_handle, e_fmr);
1339 if (h_ret != H_SUCCESS) {
1340 ehca_err(&shca->ib_device, "hipz_free_mr failed, "
1341 "h_ret=%lx e_fmr=%p hca_hndl=%lx mr_hndl=%lx "
1343 h_ret, e_fmr, shca->ipz_hca_handle.handle,
1344 e_fmr->ipz_mr_handle.handle,
1345 e_fmr->ib.ib_fmr.lkey);
1346 ret = ehca_mrmw_map_hrc_free_mr(h_ret);
1347 goto ehca_unmap_one_fmr_exit0;
1349 /* clean ehca_mr_t, without changing lock */
1351 ehca_mr_deletenew(e_fmr);
1353 /* set some MR values */
1354 e_fmr->flags = save_fmr.flags;
1355 e_fmr->fmr_page_size = save_fmr.fmr_page_size;
1356 e_fmr->fmr_max_pages = save_fmr.fmr_max_pages;
1357 e_fmr->fmr_max_maps = save_fmr.fmr_max_maps;
1358 e_fmr->fmr_map_cnt = save_fmr.fmr_map_cnt;
1359 e_fmr->acl = save_fmr.acl;
1361 pginfo.type = EHCA_MR_PGI_FMR;
1362 pginfo.num_pages = 0;
1364 ret = ehca_reg_mr(shca, e_fmr, NULL,
1365 (e_fmr->fmr_max_pages * e_fmr->fmr_page_size),
1366 e_fmr->acl, e_pd, &pginfo, &tmp_lkey,
1369 u32 offset = (u64)(&e_fmr->flags) - (u64)e_fmr;
1370 memcpy(&e_fmr->flags, &(save_mr.flags),
1371 sizeof(struct ehca_mr) - offset);
1372 goto ehca_unmap_one_fmr_exit0;
1376 ehca_unmap_one_fmr_exit0:
1378 ehca_err(&shca->ib_device, "ret=%x tmp_lkey=%x tmp_rkey=%x "
1379 "fmr_max_pages=%x rereg_1_hcall=%x rereg_3_hcall=%x",
1380 ret, tmp_lkey, tmp_rkey, e_fmr->fmr_max_pages,
1381 rereg_1_hcall, rereg_3_hcall);
1383 } /* end ehca_unmap_one_fmr() */
1385 /*----------------------------------------------------------------------*/
1387 int ehca_reg_smr(struct ehca_shca *shca,
1388 struct ehca_mr *e_origmr,
1389 struct ehca_mr *e_newmr,
1392 struct ehca_pd *e_pd,
1399 struct ehca_mr_hipzout_parms hipzout = {{0},0,0,0,0,0};
1401 ehca_mrmw_map_acl(acl, &hipz_acl);
1402 ehca_mrmw_set_pgsize_hipz_acl(&hipz_acl);
1404 h_ret = hipz_h_register_smr(shca->ipz_hca_handle, e_newmr, e_origmr,
1405 (u64)iova_start, hipz_acl, e_pd->fw_pd,
1407 if (h_ret != H_SUCCESS) {
1408 ehca_err(&shca->ib_device, "hipz_reg_smr failed, h_ret=%lx "
1409 "shca=%p e_origmr=%p e_newmr=%p iova_start=%p acl=%x "
1410 "e_pd=%p hca_hndl=%lx mr_hndl=%lx lkey=%x",
1411 h_ret, shca, e_origmr, e_newmr, iova_start, acl, e_pd,
1412 shca->ipz_hca_handle.handle,
1413 e_origmr->ipz_mr_handle.handle,
1414 e_origmr->ib.ib_mr.lkey);
1415 ret = ehca_mrmw_map_hrc_reg_smr(h_ret);
1416 goto ehca_reg_smr_exit0;
1418 /* successful registration */
1419 e_newmr->num_pages = e_origmr->num_pages;
1420 e_newmr->num_4k = e_origmr->num_4k;
1421 e_newmr->start = iova_start;
1422 e_newmr->size = e_origmr->size;
1424 e_newmr->ipz_mr_handle = hipzout.handle;
1425 *lkey = hipzout.lkey;
1426 *rkey = hipzout.rkey;
1431 ehca_err(&shca->ib_device, "ret=%x shca=%p e_origmr=%p "
1432 "e_newmr=%p iova_start=%p acl=%x e_pd=%p",
1433 ret, shca, e_origmr, e_newmr, iova_start, acl, e_pd);
1435 } /* end ehca_reg_smr() */
1437 /*----------------------------------------------------------------------*/
1439 /* register internal max-MR to internal SHCA */
1440 int ehca_reg_internal_maxmr(
1441 struct ehca_shca *shca,
1442 struct ehca_pd *e_pd,
1443 struct ehca_mr **e_maxmr) /*OUT*/
1446 struct ehca_mr *e_mr;
1449 struct ehca_mr_pginfo pginfo={0,0,0,0,0,0,0,NULL,0,NULL,NULL,0,NULL,0};
1450 struct ib_phys_buf ib_pbuf;
1452 u32 num_pages_4k; /* 4k portion "pages" */
1454 e_mr = ehca_mr_new();
1456 ehca_err(&shca->ib_device, "out of memory");
1458 goto ehca_reg_internal_maxmr_exit0;
1460 e_mr->flags |= EHCA_MR_FLAG_MAXMR;
1462 /* register internal max-MR on HCA */
1463 size_maxmr = (u64)high_memory - PAGE_OFFSET;
1464 iova_start = (u64*)KERNELBASE;
1466 ib_pbuf.size = size_maxmr;
1467 num_pages_mr = ((((u64)iova_start % PAGE_SIZE) + size_maxmr +
1468 PAGE_SIZE - 1) / PAGE_SIZE);
1469 num_pages_4k = ((((u64)iova_start % EHCA_PAGESIZE) + size_maxmr +
1470 EHCA_PAGESIZE - 1) / EHCA_PAGESIZE);
1472 pginfo.type = EHCA_MR_PGI_PHYS;
1473 pginfo.num_pages = num_pages_mr;
1474 pginfo.num_4k = num_pages_4k;
1475 pginfo.num_phys_buf = 1;
1476 pginfo.phys_buf_array = &ib_pbuf;
1478 ret = ehca_reg_mr(shca, e_mr, iova_start, size_maxmr, 0, e_pd,
1479 &pginfo, &e_mr->ib.ib_mr.lkey,
1480 &e_mr->ib.ib_mr.rkey);
1482 ehca_err(&shca->ib_device, "reg of internal max MR failed, "
1483 "e_mr=%p iova_start=%p size_maxmr=%lx num_pages_mr=%x "
1484 "num_pages_4k=%x", e_mr, iova_start, size_maxmr,
1485 num_pages_mr, num_pages_4k);
1486 goto ehca_reg_internal_maxmr_exit1;
1489 /* successful registration of all pages */
1490 e_mr->ib.ib_mr.device = e_pd->ib_pd.device;
1491 e_mr->ib.ib_mr.pd = &e_pd->ib_pd;
1492 e_mr->ib.ib_mr.uobject = NULL;
1493 atomic_inc(&(e_pd->ib_pd.usecnt));
1494 atomic_set(&(e_mr->ib.ib_mr.usecnt), 0);
1498 ehca_reg_internal_maxmr_exit1:
1499 ehca_mr_delete(e_mr);
1500 ehca_reg_internal_maxmr_exit0:
1502 ehca_err(&shca->ib_device, "ret=%x shca=%p e_pd=%p e_maxmr=%p",
1503 ret, shca, e_pd, e_maxmr);
1505 } /* end ehca_reg_internal_maxmr() */
1507 /*----------------------------------------------------------------------*/
1509 int ehca_reg_maxmr(struct ehca_shca *shca,
1510 struct ehca_mr *e_newmr,
1513 struct ehca_pd *e_pd,
1518 struct ehca_mr *e_origmr = shca->maxmr;
1520 struct ehca_mr_hipzout_parms hipzout = {{0},0,0,0,0,0};
1522 ehca_mrmw_map_acl(acl, &hipz_acl);
1523 ehca_mrmw_set_pgsize_hipz_acl(&hipz_acl);
1525 h_ret = hipz_h_register_smr(shca->ipz_hca_handle, e_newmr, e_origmr,
1526 (u64)iova_start, hipz_acl, e_pd->fw_pd,
1528 if (h_ret != H_SUCCESS) {
1529 ehca_err(&shca->ib_device, "hipz_reg_smr failed, h_ret=%lx "
1530 "e_origmr=%p hca_hndl=%lx mr_hndl=%lx lkey=%x",
1531 h_ret, e_origmr, shca->ipz_hca_handle.handle,
1532 e_origmr->ipz_mr_handle.handle,
1533 e_origmr->ib.ib_mr.lkey);
1534 return ehca_mrmw_map_hrc_reg_smr(h_ret);
1536 /* successful registration */
1537 e_newmr->num_pages = e_origmr->num_pages;
1538 e_newmr->num_4k = e_origmr->num_4k;
1539 e_newmr->start = iova_start;
1540 e_newmr->size = e_origmr->size;
1542 e_newmr->ipz_mr_handle = hipzout.handle;
1543 *lkey = hipzout.lkey;
1544 *rkey = hipzout.rkey;
1546 } /* end ehca_reg_maxmr() */
1548 /*----------------------------------------------------------------------*/
1550 int ehca_dereg_internal_maxmr(struct ehca_shca *shca)
1553 struct ehca_mr *e_maxmr;
1554 struct ib_pd *ib_pd;
1557 ehca_err(&shca->ib_device, "bad call, shca=%p", shca);
1559 goto ehca_dereg_internal_maxmr_exit0;
1562 e_maxmr = shca->maxmr;
1563 ib_pd = e_maxmr->ib.ib_mr.pd;
1564 shca->maxmr = NULL; /* remove internal max-MR indication from SHCA */
1566 ret = ehca_dereg_mr(&e_maxmr->ib.ib_mr);
1568 ehca_err(&shca->ib_device, "dereg internal max-MR failed, "
1569 "ret=%x e_maxmr=%p shca=%p lkey=%x",
1570 ret, e_maxmr, shca, e_maxmr->ib.ib_mr.lkey);
1571 shca->maxmr = e_maxmr;
1572 goto ehca_dereg_internal_maxmr_exit0;
1575 atomic_dec(&ib_pd->usecnt);
1577 ehca_dereg_internal_maxmr_exit0:
1579 ehca_err(&shca->ib_device, "ret=%x shca=%p shca->maxmr=%p",
1580 ret, shca, shca->maxmr);
1582 } /* end ehca_dereg_internal_maxmr() */
1584 /*----------------------------------------------------------------------*/
1587 * check physical buffer array of MR verbs for validness and
1588 * calculates MR size
1590 int ehca_mr_chk_buf_and_calc_size(struct ib_phys_buf *phys_buf_array,
1595 struct ib_phys_buf *pbuf = phys_buf_array;
1599 if (num_phys_buf == 0) {
1600 ehca_gen_err("bad phys buf array len, num_phys_buf=0");
1603 /* check first buffer */
1604 if (((u64)iova_start & ~PAGE_MASK) != (pbuf->addr & ~PAGE_MASK)) {
1605 ehca_gen_err("iova_start/addr mismatch, iova_start=%p "
1606 "pbuf->addr=%lx pbuf->size=%lx",
1607 iova_start, pbuf->addr, pbuf->size);
1610 if (((pbuf->addr + pbuf->size) % PAGE_SIZE) &&
1611 (num_phys_buf > 1)) {
1612 ehca_gen_err("addr/size mismatch in 1st buf, pbuf->addr=%lx "
1613 "pbuf->size=%lx", pbuf->addr, pbuf->size);
1617 for (i = 0; i < num_phys_buf; i++) {
1618 if ((i > 0) && (pbuf->addr % PAGE_SIZE)) {
1619 ehca_gen_err("bad address, i=%x pbuf->addr=%lx "
1621 i, pbuf->addr, pbuf->size);
1624 if (((i > 0) && /* not 1st */
1625 (i < (num_phys_buf - 1)) && /* not last */
1626 (pbuf->size % PAGE_SIZE)) || (pbuf->size == 0)) {
1627 ehca_gen_err("bad size, i=%x pbuf->size=%lx",
1631 size_count += pbuf->size;
1637 } /* end ehca_mr_chk_buf_and_calc_size() */
1639 /*----------------------------------------------------------------------*/
1641 /* check page list of map FMR verb for validness */
1642 int ehca_fmr_check_page_list(struct ehca_mr *e_fmr,
1649 if ((list_len == 0) || (list_len > e_fmr->fmr_max_pages)) {
1650 ehca_gen_err("bad list_len, list_len=%x "
1651 "e_fmr->fmr_max_pages=%x fmr=%p",
1652 list_len, e_fmr->fmr_max_pages, e_fmr);
1656 /* each page must be aligned */
1658 for (i = 0; i < list_len; i++) {
1659 if (*page % e_fmr->fmr_page_size) {
1660 ehca_gen_err("bad page, i=%x *page=%lx page=%p fmr=%p "
1661 "fmr_page_size=%x", i, *page, page, e_fmr,
1662 e_fmr->fmr_page_size);
1669 } /* end ehca_fmr_check_page_list() */
1671 /*----------------------------------------------------------------------*/
1673 /* setup page buffer from page info */
1674 int ehca_set_pagebuf(struct ehca_mr *e_mr,
1675 struct ehca_mr_pginfo *pginfo,
1680 struct ib_umem_chunk *prev_chunk;
1681 struct ib_umem_chunk *chunk;
1682 struct ib_phys_buf *pbuf;
1684 u64 num4k, pgaddr, offs4k;
1688 if (pginfo->type == EHCA_MR_PGI_PHYS) {
1689 /* loop over desired phys_buf_array entries */
1690 while (i < number) {
1691 pbuf = pginfo->phys_buf_array + pginfo->next_buf;
1692 num4k = ((pbuf->addr % EHCA_PAGESIZE) + pbuf->size +
1693 EHCA_PAGESIZE - 1) / EHCA_PAGESIZE;
1694 offs4k = (pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE;
1695 while (pginfo->next_4k < offs4k + num4k) {
1697 if ((pginfo->page_cnt >= pginfo->num_pages) ||
1698 (pginfo->page_4k_cnt >= pginfo->num_4k)) {
1699 ehca_gen_err("page_cnt >= num_pages, "
1706 pginfo->page_4k_cnt,
1709 goto ehca_set_pagebuf_exit0;
1711 *kpage = phys_to_abs(
1712 (pbuf->addr & EHCA_PAGEMASK)
1713 + (pginfo->next_4k * EHCA_PAGESIZE));
1714 if ( !(*kpage) && pbuf->addr ) {
1715 ehca_gen_err("pbuf->addr=%lx "
1717 "next_4k=%lx", pbuf->addr,
1721 goto ehca_set_pagebuf_exit0;
1723 (pginfo->page_4k_cnt)++;
1724 (pginfo->next_4k)++;
1725 if (pginfo->next_4k %
1726 (PAGE_SIZE / EHCA_PAGESIZE) == 0)
1727 (pginfo->page_cnt)++;
1730 if (i >= number) break;
1732 if (pginfo->next_4k >= offs4k + num4k) {
1733 (pginfo->next_buf)++;
1734 pginfo->next_4k = 0;
1737 } else if (pginfo->type == EHCA_MR_PGI_USER) {
1738 /* loop over desired chunk entries */
1739 chunk = pginfo->next_chunk;
1740 prev_chunk = pginfo->next_chunk;
1741 list_for_each_entry_continue(chunk,
1742 (&(pginfo->region->chunk_list)),
1744 for (i = pginfo->next_nmap; i < chunk->nmap; ) {
1745 pgaddr = ( page_to_pfn(chunk->page_list[i].page)
1747 *kpage = phys_to_abs(pgaddr +
1751 ehca_gen_err("pgaddr=%lx "
1752 "chunk->page_list[i]=%lx "
1753 "i=%x next_4k=%lx mr=%p",
1755 (u64)sg_dma_address(
1758 i, pginfo->next_4k, e_mr);
1760 goto ehca_set_pagebuf_exit0;
1762 (pginfo->page_4k_cnt)++;
1763 (pginfo->next_4k)++;
1765 if (pginfo->next_4k %
1766 (PAGE_SIZE / EHCA_PAGESIZE) == 0) {
1767 (pginfo->page_cnt)++;
1768 (pginfo->next_nmap)++;
1769 pginfo->next_4k = 0;
1773 if (j >= number) break;
1775 if ((pginfo->next_nmap >= chunk->nmap) &&
1777 pginfo->next_nmap = 0;
1780 } else if (pginfo->next_nmap >= chunk->nmap) {
1781 pginfo->next_nmap = 0;
1783 } else if (j >= number)
1788 pginfo->next_chunk =
1789 list_prepare_entry(prev_chunk,
1790 (&(pginfo->region->chunk_list)),
1792 } else if (pginfo->type == EHCA_MR_PGI_FMR) {
1793 /* loop over desired page_list entries */
1794 fmrlist = pginfo->page_list + pginfo->next_listelem;
1795 for (i = 0; i < number; i++) {
1796 *kpage = phys_to_abs((*fmrlist & EHCA_PAGEMASK) +
1797 pginfo->next_4k * EHCA_PAGESIZE);
1799 ehca_gen_err("*fmrlist=%lx fmrlist=%p "
1800 "next_listelem=%lx next_4k=%lx",
1802 pginfo->next_listelem,
1805 goto ehca_set_pagebuf_exit0;
1807 (pginfo->page_4k_cnt)++;
1808 (pginfo->next_4k)++;
1810 if (pginfo->next_4k %
1811 (e_mr->fmr_page_size / EHCA_PAGESIZE) == 0) {
1812 (pginfo->page_cnt)++;
1813 (pginfo->next_listelem)++;
1815 pginfo->next_4k = 0;
1819 ehca_gen_err("bad pginfo->type=%x", pginfo->type);
1821 goto ehca_set_pagebuf_exit0;
1824 ehca_set_pagebuf_exit0:
1826 ehca_gen_err("ret=%x e_mr=%p pginfo=%p type=%x num_pages=%lx "
1827 "num_4k=%lx next_buf=%lx next_4k=%lx number=%x "
1828 "kpage=%p page_cnt=%lx page_4k_cnt=%lx i=%x "
1829 "next_listelem=%lx region=%p next_chunk=%p "
1830 "next_nmap=%lx", ret, e_mr, pginfo, pginfo->type,
1831 pginfo->num_pages, pginfo->num_4k,
1832 pginfo->next_buf, pginfo->next_4k, number, kpage,
1833 pginfo->page_cnt, pginfo->page_4k_cnt, i,
1834 pginfo->next_listelem, pginfo->region,
1835 pginfo->next_chunk, pginfo->next_nmap);
1837 } /* end ehca_set_pagebuf() */
1839 /*----------------------------------------------------------------------*/
1841 /* setup 1 page from page info page buffer */
1842 int ehca_set_pagebuf_1(struct ehca_mr *e_mr,
1843 struct ehca_mr_pginfo *pginfo,
1847 struct ib_phys_buf *tmp_pbuf;
1849 struct ib_umem_chunk *chunk;
1850 struct ib_umem_chunk *prev_chunk;
1851 u64 pgaddr, num4k, offs4k;
1853 if (pginfo->type == EHCA_MR_PGI_PHYS) {
1855 if ((pginfo->page_cnt >= pginfo->num_pages) ||
1856 (pginfo->page_4k_cnt >= pginfo->num_4k)) {
1857 ehca_gen_err("page_cnt >= num_pages, page_cnt=%lx "
1858 "num_pages=%lx page_4k_cnt=%lx num_4k=%lx",
1859 pginfo->page_cnt, pginfo->num_pages,
1860 pginfo->page_4k_cnt, pginfo->num_4k);
1862 goto ehca_set_pagebuf_1_exit0;
1864 tmp_pbuf = pginfo->phys_buf_array + pginfo->next_buf;
1865 num4k = ((tmp_pbuf->addr % EHCA_PAGESIZE) + tmp_pbuf->size +
1866 EHCA_PAGESIZE - 1) / EHCA_PAGESIZE;
1867 offs4k = (tmp_pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE;
1868 *rpage = phys_to_abs((tmp_pbuf->addr & EHCA_PAGEMASK) +
1869 (pginfo->next_4k * EHCA_PAGESIZE));
1870 if ( !(*rpage) && tmp_pbuf->addr ) {
1871 ehca_gen_err("tmp_pbuf->addr=%lx"
1872 " tmp_pbuf->size=%lx next_4k=%lx",
1873 tmp_pbuf->addr, tmp_pbuf->size,
1876 goto ehca_set_pagebuf_1_exit0;
1878 (pginfo->page_4k_cnt)++;
1879 (pginfo->next_4k)++;
1880 if (pginfo->next_4k % (PAGE_SIZE / EHCA_PAGESIZE) == 0)
1881 (pginfo->page_cnt)++;
1882 if (pginfo->next_4k >= offs4k + num4k) {
1883 (pginfo->next_buf)++;
1884 pginfo->next_4k = 0;
1886 } else if (pginfo->type == EHCA_MR_PGI_USER) {
1887 chunk = pginfo->next_chunk;
1888 prev_chunk = pginfo->next_chunk;
1889 list_for_each_entry_continue(chunk,
1890 (&(pginfo->region->chunk_list)),
1892 pgaddr = ( page_to_pfn(chunk->page_list[
1893 pginfo->next_nmap].page)
1895 *rpage = phys_to_abs(pgaddr +
1896 (pginfo->next_4k * EHCA_PAGESIZE));
1898 ehca_gen_err("pgaddr=%lx chunk->page_list[]=%lx"
1899 " next_nmap=%lx next_4k=%lx mr=%p",
1900 pgaddr, (u64)sg_dma_address(
1904 pginfo->next_nmap, pginfo->next_4k,
1907 goto ehca_set_pagebuf_1_exit0;
1909 (pginfo->page_4k_cnt)++;
1910 (pginfo->next_4k)++;
1911 if (pginfo->next_4k %
1912 (PAGE_SIZE / EHCA_PAGESIZE) == 0) {
1913 (pginfo->page_cnt)++;
1914 (pginfo->next_nmap)++;
1915 pginfo->next_4k = 0;
1917 if (pginfo->next_nmap >= chunk->nmap) {
1918 pginfo->next_nmap = 0;
1923 pginfo->next_chunk =
1924 list_prepare_entry(prev_chunk,
1925 (&(pginfo->region->chunk_list)),
1927 } else if (pginfo->type == EHCA_MR_PGI_FMR) {
1928 fmrlist = pginfo->page_list + pginfo->next_listelem;
1929 *rpage = phys_to_abs((*fmrlist & EHCA_PAGEMASK) +
1930 pginfo->next_4k * EHCA_PAGESIZE);
1932 ehca_gen_err("*fmrlist=%lx fmrlist=%p "
1933 "next_listelem=%lx next_4k=%lx",
1934 *fmrlist, fmrlist, pginfo->next_listelem,
1937 goto ehca_set_pagebuf_1_exit0;
1939 (pginfo->page_4k_cnt)++;
1940 (pginfo->next_4k)++;
1941 if (pginfo->next_4k %
1942 (e_mr->fmr_page_size / EHCA_PAGESIZE) == 0) {
1943 (pginfo->page_cnt)++;
1944 (pginfo->next_listelem)++;
1945 pginfo->next_4k = 0;
1948 ehca_gen_err("bad pginfo->type=%x", pginfo->type);
1950 goto ehca_set_pagebuf_1_exit0;
1953 ehca_set_pagebuf_1_exit0:
1955 ehca_gen_err("ret=%x e_mr=%p pginfo=%p type=%x num_pages=%lx "
1956 "num_4k=%lx next_buf=%lx next_4k=%lx rpage=%p "
1957 "page_cnt=%lx page_4k_cnt=%lx next_listelem=%lx "
1958 "region=%p next_chunk=%p next_nmap=%lx", ret, e_mr,
1959 pginfo, pginfo->type, pginfo->num_pages,
1960 pginfo->num_4k, pginfo->next_buf, pginfo->next_4k,
1961 rpage, pginfo->page_cnt, pginfo->page_4k_cnt,
1962 pginfo->next_listelem, pginfo->region,
1963 pginfo->next_chunk, pginfo->next_nmap);
1965 } /* end ehca_set_pagebuf_1() */
1967 /*----------------------------------------------------------------------*/
1970 * check MR if it is a max-MR, i.e. uses whole memory
1971 * in case it's a max-MR 1 is returned, else 0
1973 int ehca_mr_is_maxmr(u64 size,
1976 /* a MR is treated as max-MR only if it fits following: */
1977 if ((size == ((u64)high_memory - PAGE_OFFSET)) &&
1978 (iova_start == (void*)KERNELBASE)) {
1979 ehca_gen_dbg("this is a max-MR");
1983 } /* end ehca_mr_is_maxmr() */
1985 /*----------------------------------------------------------------------*/
1987 /* map access control for MR/MW. This routine is used for MR and MW. */
1988 void ehca_mrmw_map_acl(int ib_acl,
1992 if (ib_acl & IB_ACCESS_REMOTE_READ)
1993 *hipz_acl |= HIPZ_ACCESSCTRL_R_READ;
1994 if (ib_acl & IB_ACCESS_REMOTE_WRITE)
1995 *hipz_acl |= HIPZ_ACCESSCTRL_R_WRITE;
1996 if (ib_acl & IB_ACCESS_REMOTE_ATOMIC)
1997 *hipz_acl |= HIPZ_ACCESSCTRL_R_ATOMIC;
1998 if (ib_acl & IB_ACCESS_LOCAL_WRITE)
1999 *hipz_acl |= HIPZ_ACCESSCTRL_L_WRITE;
2000 if (ib_acl & IB_ACCESS_MW_BIND)
2001 *hipz_acl |= HIPZ_ACCESSCTRL_MW_BIND;
2002 } /* end ehca_mrmw_map_acl() */
2004 /*----------------------------------------------------------------------*/
2006 /* sets page size in hipz access control for MR/MW. */
2007 void ehca_mrmw_set_pgsize_hipz_acl(u32 *hipz_acl) /*INOUT*/
2009 return; /* HCA supports only 4k */
2010 } /* end ehca_mrmw_set_pgsize_hipz_acl() */
2012 /*----------------------------------------------------------------------*/
2015 * reverse map access control for MR/MW.
2016 * This routine is used for MR and MW.
2018 void ehca_mrmw_reverse_map_acl(const u32 *hipz_acl,
2019 int *ib_acl) /*OUT*/
2022 if (*hipz_acl & HIPZ_ACCESSCTRL_R_READ)
2023 *ib_acl |= IB_ACCESS_REMOTE_READ;
2024 if (*hipz_acl & HIPZ_ACCESSCTRL_R_WRITE)
2025 *ib_acl |= IB_ACCESS_REMOTE_WRITE;
2026 if (*hipz_acl & HIPZ_ACCESSCTRL_R_ATOMIC)
2027 *ib_acl |= IB_ACCESS_REMOTE_ATOMIC;
2028 if (*hipz_acl & HIPZ_ACCESSCTRL_L_WRITE)
2029 *ib_acl |= IB_ACCESS_LOCAL_WRITE;
2030 if (*hipz_acl & HIPZ_ACCESSCTRL_MW_BIND)
2031 *ib_acl |= IB_ACCESS_MW_BIND;
2032 } /* end ehca_mrmw_reverse_map_acl() */
2035 /*----------------------------------------------------------------------*/
2038 * map HIPZ rc to IB retcodes for MR/MW allocations
2039 * Used for hipz_mr_reg_alloc and hipz_mw_alloc.
2041 int ehca_mrmw_map_hrc_alloc(const u64 hipz_rc)
2044 case H_SUCCESS: /* successful completion */
2046 case H_ADAPTER_PARM: /* invalid adapter handle */
2047 case H_RT_PARM: /* invalid resource type */
2048 case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */
2049 case H_MLENGTH_PARM: /* invalid memory length */
2050 case H_MEM_ACCESS_PARM: /* invalid access controls */
2051 case H_CONSTRAINED: /* resource constraint */
2053 case H_BUSY: /* long busy */
2058 } /* end ehca_mrmw_map_hrc_alloc() */
2060 /*----------------------------------------------------------------------*/
2063 * map HIPZ rc to IB retcodes for MR register rpage
2064 * Used for hipz_h_register_rpage_mr at registering last page
2066 int ehca_mrmw_map_hrc_rrpg_last(const u64 hipz_rc)
2069 case H_SUCCESS: /* registration complete */
2071 case H_PAGE_REGISTERED: /* page registered */
2072 case H_ADAPTER_PARM: /* invalid adapter handle */
2073 case H_RH_PARM: /* invalid resource handle */
2074 /* case H_QT_PARM: invalid queue type */
2075 case H_PARAMETER: /*
2076 * invalid logical address,
2077 * or count zero or greater 512
2079 case H_TABLE_FULL: /* page table full */
2080 case H_HARDWARE: /* HCA not operational */
2082 case H_BUSY: /* long busy */
2087 } /* end ehca_mrmw_map_hrc_rrpg_last() */
2089 /*----------------------------------------------------------------------*/
2092 * map HIPZ rc to IB retcodes for MR register rpage
2093 * Used for hipz_h_register_rpage_mr at registering one page, but not last page
2095 int ehca_mrmw_map_hrc_rrpg_notlast(const u64 hipz_rc)
2098 case H_PAGE_REGISTERED: /* page registered */
2100 case H_SUCCESS: /* registration complete */
2101 case H_ADAPTER_PARM: /* invalid adapter handle */
2102 case H_RH_PARM: /* invalid resource handle */
2103 /* case H_QT_PARM: invalid queue type */
2104 case H_PARAMETER: /*
2105 * invalid logical address,
2106 * or count zero or greater 512
2108 case H_TABLE_FULL: /* page table full */
2109 case H_HARDWARE: /* HCA not operational */
2111 case H_BUSY: /* long busy */
2116 } /* end ehca_mrmw_map_hrc_rrpg_notlast() */
2118 /*----------------------------------------------------------------------*/
2120 /* map HIPZ rc to IB retcodes for MR query. Used for hipz_mr_query. */
2121 int ehca_mrmw_map_hrc_query_mr(const u64 hipz_rc)
2124 case H_SUCCESS: /* successful completion */
2126 case H_ADAPTER_PARM: /* invalid adapter handle */
2127 case H_RH_PARM: /* invalid resource handle */
2129 case H_BUSY: /* long busy */
2134 } /* end ehca_mrmw_map_hrc_query_mr() */
2136 /*----------------------------------------------------------------------*/
2137 /*----------------------------------------------------------------------*/
2140 * map HIPZ rc to IB retcodes for freeing MR resource
2141 * Used for hipz_h_free_resource_mr
2143 int ehca_mrmw_map_hrc_free_mr(const u64 hipz_rc)
2146 case H_SUCCESS: /* resource freed */
2148 case H_ADAPTER_PARM: /* invalid adapter handle */
2149 case H_RH_PARM: /* invalid resource handle */
2150 case H_R_STATE: /* invalid resource state */
2151 case H_HARDWARE: /* HCA not operational */
2153 case H_RESOURCE: /* Resource in use */
2154 case H_BUSY: /* long busy */
2159 } /* end ehca_mrmw_map_hrc_free_mr() */
2161 /*----------------------------------------------------------------------*/
2164 * map HIPZ rc to IB retcodes for freeing MW resource
2165 * Used for hipz_h_free_resource_mw
2167 int ehca_mrmw_map_hrc_free_mw(const u64 hipz_rc)
2170 case H_SUCCESS: /* resource freed */
2172 case H_ADAPTER_PARM: /* invalid adapter handle */
2173 case H_RH_PARM: /* invalid resource handle */
2174 case H_R_STATE: /* invalid resource state */
2175 case H_HARDWARE: /* HCA not operational */
2177 case H_RESOURCE: /* Resource in use */
2178 case H_BUSY: /* long busy */
2183 } /* end ehca_mrmw_map_hrc_free_mw() */
2185 /*----------------------------------------------------------------------*/
2188 * map HIPZ rc to IB retcodes for SMR registrations
2189 * Used for hipz_h_register_smr.
2191 int ehca_mrmw_map_hrc_reg_smr(const u64 hipz_rc)
2194 case H_SUCCESS: /* successful completion */
2196 case H_ADAPTER_PARM: /* invalid adapter handle */
2197 case H_RH_PARM: /* invalid resource handle */
2198 case H_MEM_PARM: /* invalid MR virtual address */
2199 case H_MEM_ACCESS_PARM: /* invalid access controls */
2200 case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */
2202 case H_BUSY: /* long busy */
2207 } /* end ehca_mrmw_map_hrc_reg_smr() */
2209 /*----------------------------------------------------------------------*/
2212 * MR destructor and constructor
2213 * used in Reregister MR verb, sets all fields in ehca_mr_t to 0,
2214 * except struct ib_mr and spinlock
2216 void ehca_mr_deletenew(struct ehca_mr *mr)
2223 mr->fmr_page_size = 0;
2224 mr->fmr_max_pages = 0;
2225 mr->fmr_max_maps = 0;
2226 mr->fmr_map_cnt = 0;
2227 memset(&mr->ipz_mr_handle, 0, sizeof(mr->ipz_mr_handle));
2228 memset(&mr->galpas, 0, sizeof(mr->galpas));
2229 mr->nr_of_pages = 0;
2230 mr->pagearray = NULL;
2231 } /* end ehca_mr_deletenew() */
2233 int ehca_init_mrmw_cache(void)
2235 mr_cache = kmem_cache_create("ehca_cache_mr",
2236 sizeof(struct ehca_mr), 0,
2241 mw_cache = kmem_cache_create("ehca_cache_mw",
2242 sizeof(struct ehca_mw), 0,
2246 kmem_cache_destroy(mr_cache);
2253 void ehca_cleanup_mrmw_cache(void)
2256 kmem_cache_destroy(mr_cache);
2258 kmem_cache_destroy(mw_cache);