diff options
author | Hoang-Nam Nguyen <hnguyen@de.ibm.com> | 2007-07-12 11:51:43 -0400 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2007-07-17 21:37:39 -0400 |
commit | 2492398e616451788bc7c7905cadb8734b082bc7 (patch) | |
tree | f07cd91ab7e25d9688c087e62fe6ccfaf4a2fc9b /drivers/infiniband | |
parent | 4e4e74cae73325c9f8513fae3a5bd9f79458f4a7 (diff) |
IB/ehca: Use macro to calculate number of chunks in a mem block
Signed-off-by: Joachim Fenkes <fenkes@de.ibm.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/hw/ehca/ehca_mrmw.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c index 1fe4f726cee9..58e8b33d030b 100644 --- a/drivers/infiniband/hw/ehca/ehca_mrmw.c +++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c | |||
@@ -48,6 +48,8 @@ | |||
48 | #include "hcp_if.h" | 48 | #include "hcp_if.h" |
49 | #include "hipz_hw.h" | 49 | #include "hipz_hw.h" |
50 | 50 | ||
51 | #define NUM_CHUNKS(length, chunk_size) \ | ||
52 | (((length) + (chunk_size - 1)) / (chunk_size)) | ||
51 | /* max number of rpages (per hcall register_rpages) */ | 53 | /* max number of rpages (per hcall register_rpages) */ |
52 | #define MAX_RPAGES 512 | 54 | #define MAX_RPAGES 512 |
53 | 55 | ||
@@ -195,10 +197,10 @@ struct ib_mr *ehca_reg_phys_mr(struct ib_pd *pd, | |||
195 | } | 197 | } |
196 | 198 | ||
197 | /* determine number of MR pages */ | 199 | /* determine number of MR pages */ |
198 | num_pages_mr = ((((u64)iova_start % PAGE_SIZE) + size + | 200 | num_pages_mr = NUM_CHUNKS(((u64)iova_start % PAGE_SIZE) + size, |
199 | PAGE_SIZE - 1) / PAGE_SIZE); | 201 | PAGE_SIZE); |
200 | num_pages_4k = ((((u64)iova_start % EHCA_PAGESIZE) + size + | 202 | num_pages_4k = NUM_CHUNKS(((u64)iova_start % EHCA_PAGESIZE) + size, |
201 | EHCA_PAGESIZE - 1) / EHCA_PAGESIZE); | 203 | EHCA_PAGESIZE); |
202 | 204 | ||
203 | /* register MR on HCA */ | 205 | /* register MR on HCA */ |
204 | if (ehca_mr_is_maxmr(size, iova_start)) { | 206 | if (ehca_mr_is_maxmr(size, iova_start)) { |
@@ -305,10 +307,9 @@ struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, u64 virt | |||
305 | } | 307 | } |
306 | 308 | ||
307 | /* determine number of MR pages */ | 309 | /* determine number of MR pages */ |
308 | num_pages_mr = (((virt % PAGE_SIZE) + length + PAGE_SIZE - 1) / | 310 | num_pages_mr = NUM_CHUNKS((virt % PAGE_SIZE) + length, PAGE_SIZE); |
309 | PAGE_SIZE); | 311 | num_pages_4k = NUM_CHUNKS((virt % EHCA_PAGESIZE) + length, |
310 | num_pages_4k = (((virt % EHCA_PAGESIZE) + length + EHCA_PAGESIZE - 1) / | 312 | EHCA_PAGESIZE); |
311 | EHCA_PAGESIZE); | ||
312 | 313 | ||
313 | /* register MR on HCA */ | 314 | /* register MR on HCA */ |
314 | pginfo.type = EHCA_MR_PGI_USER; | 315 | pginfo.type = EHCA_MR_PGI_USER; |
@@ -462,10 +463,10 @@ int ehca_rereg_phys_mr(struct ib_mr *mr, | |||
462 | ret = -EINVAL; | 463 | ret = -EINVAL; |
463 | goto rereg_phys_mr_exit1; | 464 | goto rereg_phys_mr_exit1; |
464 | } | 465 | } |
465 | num_pages_mr = ((((u64)new_start % PAGE_SIZE) + new_size + | 466 | num_pages_mr = NUM_CHUNKS(((u64)new_start % PAGE_SIZE) + |
466 | PAGE_SIZE - 1) / PAGE_SIZE); | 467 | new_size, PAGE_SIZE); |
467 | num_pages_4k = ((((u64)new_start % EHCA_PAGESIZE) + new_size + | 468 | num_pages_4k = NUM_CHUNKS(((u64)new_start % EHCA_PAGESIZE) + |
468 | EHCA_PAGESIZE - 1) / EHCA_PAGESIZE); | 469 | new_size, EHCA_PAGESIZE); |
469 | pginfo.type = EHCA_MR_PGI_PHYS; | 470 | pginfo.type = EHCA_MR_PGI_PHYS; |
470 | pginfo.num_pages = num_pages_mr; | 471 | pginfo.num_pages = num_pages_mr; |
471 | pginfo.num_4k = num_pages_4k; | 472 | pginfo.num_4k = num_pages_4k; |
@@ -1030,9 +1031,9 @@ int ehca_reg_mr_rpages(struct ehca_shca *shca, | |||
1030 | } | 1031 | } |
1031 | 1032 | ||
1032 | /* max 512 pages per shot */ | 1033 | /* max 512 pages per shot */ |
1033 | for (i = 0; i < ((pginfo->num_4k + MAX_RPAGES - 1) / MAX_RPAGES); i++) { | 1034 | for (i = 0; i < NUM_CHUNKS(pginfo->num_4k, MAX_RPAGES); i++) { |
1034 | 1035 | ||
1035 | if (i == ((pginfo->num_4k + MAX_RPAGES - 1) / MAX_RPAGES) - 1) { | 1036 | if (i == NUM_CHUNKS(pginfo->num_4k, MAX_RPAGES) - 1) { |
1036 | rnum = pginfo->num_4k % MAX_RPAGES; /* last shot */ | 1037 | rnum = pginfo->num_4k % MAX_RPAGES; /* last shot */ |
1037 | if (rnum == 0) | 1038 | if (rnum == 0) |
1038 | rnum = MAX_RPAGES; /* last shot is full */ | 1039 | rnum = MAX_RPAGES; /* last shot is full */ |
@@ -1069,7 +1070,7 @@ int ehca_reg_mr_rpages(struct ehca_shca *shca, | |||
1069 | 0, /* pagesize 4k */ | 1070 | 0, /* pagesize 4k */ |
1070 | 0, rpage, rnum); | 1071 | 0, rpage, rnum); |
1071 | 1072 | ||
1072 | if (i == ((pginfo->num_4k + MAX_RPAGES - 1) / MAX_RPAGES) - 1) { | 1073 | if (i == NUM_CHUNKS(pginfo->num_4k, MAX_RPAGES) - 1) { |
1073 | /* | 1074 | /* |
1074 | * check for 'registration complete'==H_SUCCESS | 1075 | * check for 'registration complete'==H_SUCCESS |
1075 | * and for 'page registered'==H_PAGE_REGISTERED | 1076 | * and for 'page registered'==H_PAGE_REGISTERED |
@@ -1475,10 +1476,10 @@ int ehca_reg_internal_maxmr( | |||
1475 | iova_start = (u64*)KERNELBASE; | 1476 | iova_start = (u64*)KERNELBASE; |
1476 | ib_pbuf.addr = 0; | 1477 | ib_pbuf.addr = 0; |
1477 | ib_pbuf.size = size_maxmr; | 1478 | ib_pbuf.size = size_maxmr; |
1478 | num_pages_mr = ((((u64)iova_start % PAGE_SIZE) + size_maxmr + | 1479 | num_pages_mr = NUM_CHUNKS(((u64)iova_start % PAGE_SIZE) + size_maxmr, |
1479 | PAGE_SIZE - 1) / PAGE_SIZE); | 1480 | PAGE_SIZE); |
1480 | num_pages_4k = ((((u64)iova_start % EHCA_PAGESIZE) + size_maxmr + | 1481 | num_pages_4k = NUM_CHUNKS(((u64)iova_start % EHCA_PAGESIZE) |
1481 | EHCA_PAGESIZE - 1) / EHCA_PAGESIZE); | 1482 | + size_maxmr, EHCA_PAGESIZE); |
1482 | 1483 | ||
1483 | pginfo.type = EHCA_MR_PGI_PHYS; | 1484 | pginfo.type = EHCA_MR_PGI_PHYS; |
1484 | pginfo.num_pages = num_pages_mr; | 1485 | pginfo.num_pages = num_pages_mr; |
@@ -1700,8 +1701,8 @@ int ehca_set_pagebuf(struct ehca_mr *e_mr, | |||
1700 | /* loop over desired phys_buf_array entries */ | 1701 | /* loop over desired phys_buf_array entries */ |
1701 | while (i < number) { | 1702 | while (i < number) { |
1702 | pbuf = pginfo->phys_buf_array + pginfo->next_buf; | 1703 | pbuf = pginfo->phys_buf_array + pginfo->next_buf; |
1703 | num4k = ((pbuf->addr % EHCA_PAGESIZE) + pbuf->size + | 1704 | num4k = NUM_CHUNKS((pbuf->addr % EHCA_PAGESIZE) |
1704 | EHCA_PAGESIZE - 1) / EHCA_PAGESIZE; | 1705 | + pbuf->size, EHCA_PAGESIZE); |
1705 | offs4k = (pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE; | 1706 | offs4k = (pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE; |
1706 | while (pginfo->next_4k < offs4k + num4k) { | 1707 | while (pginfo->next_4k < offs4k + num4k) { |
1707 | /* sanity check */ | 1708 | /* sanity check */ |
@@ -1873,8 +1874,8 @@ int ehca_set_pagebuf_1(struct ehca_mr *e_mr, | |||
1873 | goto ehca_set_pagebuf_1_exit0; | 1874 | goto ehca_set_pagebuf_1_exit0; |
1874 | } | 1875 | } |
1875 | tmp_pbuf = pginfo->phys_buf_array + pginfo->next_buf; | 1876 | tmp_pbuf = pginfo->phys_buf_array + pginfo->next_buf; |
1876 | num4k = ((tmp_pbuf->addr % EHCA_PAGESIZE) + tmp_pbuf->size + | 1877 | num4k = NUM_CHUNKS((tmp_pbuf->addr % EHCA_PAGESIZE) + |
1877 | EHCA_PAGESIZE - 1) / EHCA_PAGESIZE; | 1878 | tmp_pbuf->size, EHCA_PAGESIZE); |
1878 | offs4k = (tmp_pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE; | 1879 | offs4k = (tmp_pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE; |
1879 | *rpage = phys_to_abs((tmp_pbuf->addr & EHCA_PAGEMASK) + | 1880 | *rpage = phys_to_abs((tmp_pbuf->addr & EHCA_PAGEMASK) + |
1880 | (pginfo->next_4k * EHCA_PAGESIZE)); | 1881 | (pginfo->next_4k * EHCA_PAGESIZE)); |