Commit 2492398e authored by Hoang-Nam Nguyen's avatar Hoang-Nam Nguyen Committed by Roland Dreier

IB/ehca: Use macro to calculate number of chunks in a mem block

Signed-off-by: default avatarJoachim Fenkes <fenkes@de.ibm.com>
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent 4e4e74ca
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
#include "hcp_if.h" #include "hcp_if.h"
#include "hipz_hw.h" #include "hipz_hw.h"
#define NUM_CHUNKS(length, chunk_size) \
(((length) + (chunk_size - 1)) / (chunk_size))
/* max number of rpages (per hcall register_rpages) */ /* max number of rpages (per hcall register_rpages) */
#define MAX_RPAGES 512 #define MAX_RPAGES 512
...@@ -195,10 +197,10 @@ struct ib_mr *ehca_reg_phys_mr(struct ib_pd *pd, ...@@ -195,10 +197,10 @@ struct ib_mr *ehca_reg_phys_mr(struct ib_pd *pd,
} }
/* determine number of MR pages */ /* determine number of MR pages */
num_pages_mr = ((((u64)iova_start % PAGE_SIZE) + size + num_pages_mr = NUM_CHUNKS(((u64)iova_start % PAGE_SIZE) + size,
PAGE_SIZE - 1) / PAGE_SIZE); PAGE_SIZE);
num_pages_4k = ((((u64)iova_start % EHCA_PAGESIZE) + size + num_pages_4k = NUM_CHUNKS(((u64)iova_start % EHCA_PAGESIZE) + size,
EHCA_PAGESIZE - 1) / EHCA_PAGESIZE); EHCA_PAGESIZE);
/* register MR on HCA */ /* register MR on HCA */
if (ehca_mr_is_maxmr(size, iova_start)) { 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,10 +307,9 @@ struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, u64 virt
} }
/* determine number of MR pages */ /* determine number of MR pages */
num_pages_mr = (((virt % PAGE_SIZE) + length + PAGE_SIZE - 1) / num_pages_mr = NUM_CHUNKS((virt % PAGE_SIZE) + length, PAGE_SIZE);
PAGE_SIZE); num_pages_4k = NUM_CHUNKS((virt % EHCA_PAGESIZE) + length,
num_pages_4k = (((virt % EHCA_PAGESIZE) + length + EHCA_PAGESIZE - 1) / EHCA_PAGESIZE);
EHCA_PAGESIZE);
/* register MR on HCA */ /* register MR on HCA */
pginfo.type = EHCA_MR_PGI_USER; pginfo.type = EHCA_MR_PGI_USER;
...@@ -462,10 +463,10 @@ int ehca_rereg_phys_mr(struct ib_mr *mr, ...@@ -462,10 +463,10 @@ int ehca_rereg_phys_mr(struct ib_mr *mr,
ret = -EINVAL; ret = -EINVAL;
goto rereg_phys_mr_exit1; goto rereg_phys_mr_exit1;
} }
num_pages_mr = ((((u64)new_start % PAGE_SIZE) + new_size + num_pages_mr = NUM_CHUNKS(((u64)new_start % PAGE_SIZE) +
PAGE_SIZE - 1) / PAGE_SIZE); new_size, PAGE_SIZE);
num_pages_4k = ((((u64)new_start % EHCA_PAGESIZE) + new_size + num_pages_4k = NUM_CHUNKS(((u64)new_start % EHCA_PAGESIZE) +
EHCA_PAGESIZE - 1) / EHCA_PAGESIZE); new_size, EHCA_PAGESIZE);
pginfo.type = EHCA_MR_PGI_PHYS; pginfo.type = EHCA_MR_PGI_PHYS;
pginfo.num_pages = num_pages_mr; pginfo.num_pages = num_pages_mr;
pginfo.num_4k = num_pages_4k; pginfo.num_4k = num_pages_4k;
...@@ -1030,9 +1031,9 @@ int ehca_reg_mr_rpages(struct ehca_shca *shca, ...@@ -1030,9 +1031,9 @@ int ehca_reg_mr_rpages(struct ehca_shca *shca,
} }
/* max 512 pages per shot */ /* max 512 pages per shot */
for (i = 0; i < ((pginfo->num_4k + MAX_RPAGES - 1) / MAX_RPAGES); i++) { for (i = 0; i < NUM_CHUNKS(pginfo->num_4k, MAX_RPAGES); i++) {
if (i == ((pginfo->num_4k + MAX_RPAGES - 1) / MAX_RPAGES) - 1) { if (i == NUM_CHUNKS(pginfo->num_4k, MAX_RPAGES) - 1) {
rnum = pginfo->num_4k % MAX_RPAGES; /* last shot */ rnum = pginfo->num_4k % MAX_RPAGES; /* last shot */
if (rnum == 0) if (rnum == 0)
rnum = MAX_RPAGES; /* last shot is full */ rnum = MAX_RPAGES; /* last shot is full */
...@@ -1069,7 +1070,7 @@ int ehca_reg_mr_rpages(struct ehca_shca *shca, ...@@ -1069,7 +1070,7 @@ int ehca_reg_mr_rpages(struct ehca_shca *shca,
0, /* pagesize 4k */ 0, /* pagesize 4k */
0, rpage, rnum); 0, rpage, rnum);
if (i == ((pginfo->num_4k + MAX_RPAGES - 1) / MAX_RPAGES) - 1) { if (i == NUM_CHUNKS(pginfo->num_4k, MAX_RPAGES) - 1) {
/* /*
* check for 'registration complete'==H_SUCCESS * check for 'registration complete'==H_SUCCESS
* and for 'page registered'==H_PAGE_REGISTERED * and for 'page registered'==H_PAGE_REGISTERED
...@@ -1475,10 +1476,10 @@ int ehca_reg_internal_maxmr( ...@@ -1475,10 +1476,10 @@ int ehca_reg_internal_maxmr(
iova_start = (u64*)KERNELBASE; iova_start = (u64*)KERNELBASE;
ib_pbuf.addr = 0; ib_pbuf.addr = 0;
ib_pbuf.size = size_maxmr; ib_pbuf.size = size_maxmr;
num_pages_mr = ((((u64)iova_start % PAGE_SIZE) + size_maxmr + num_pages_mr = NUM_CHUNKS(((u64)iova_start % PAGE_SIZE) + size_maxmr,
PAGE_SIZE - 1) / PAGE_SIZE); PAGE_SIZE);
num_pages_4k = ((((u64)iova_start % EHCA_PAGESIZE) + size_maxmr + num_pages_4k = NUM_CHUNKS(((u64)iova_start % EHCA_PAGESIZE)
EHCA_PAGESIZE - 1) / EHCA_PAGESIZE); + size_maxmr, EHCA_PAGESIZE);
pginfo.type = EHCA_MR_PGI_PHYS; pginfo.type = EHCA_MR_PGI_PHYS;
pginfo.num_pages = num_pages_mr; pginfo.num_pages = num_pages_mr;
...@@ -1700,8 +1701,8 @@ int ehca_set_pagebuf(struct ehca_mr *e_mr, ...@@ -1700,8 +1701,8 @@ int ehca_set_pagebuf(struct ehca_mr *e_mr,
/* loop over desired phys_buf_array entries */ /* loop over desired phys_buf_array entries */
while (i < number) { while (i < number) {
pbuf = pginfo->phys_buf_array + pginfo->next_buf; pbuf = pginfo->phys_buf_array + pginfo->next_buf;
num4k = ((pbuf->addr % EHCA_PAGESIZE) + pbuf->size + num4k = NUM_CHUNKS((pbuf->addr % EHCA_PAGESIZE)
EHCA_PAGESIZE - 1) / EHCA_PAGESIZE; + pbuf->size, EHCA_PAGESIZE);
offs4k = (pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE; offs4k = (pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE;
while (pginfo->next_4k < offs4k + num4k) { while (pginfo->next_4k < offs4k + num4k) {
/* sanity check */ /* sanity check */
...@@ -1873,8 +1874,8 @@ int ehca_set_pagebuf_1(struct ehca_mr *e_mr, ...@@ -1873,8 +1874,8 @@ int ehca_set_pagebuf_1(struct ehca_mr *e_mr,
goto ehca_set_pagebuf_1_exit0; goto ehca_set_pagebuf_1_exit0;
} }
tmp_pbuf = pginfo->phys_buf_array + pginfo->next_buf; tmp_pbuf = pginfo->phys_buf_array + pginfo->next_buf;
num4k = ((tmp_pbuf->addr % EHCA_PAGESIZE) + tmp_pbuf->size + num4k = NUM_CHUNKS((tmp_pbuf->addr % EHCA_PAGESIZE) +
EHCA_PAGESIZE - 1) / EHCA_PAGESIZE; tmp_pbuf->size, EHCA_PAGESIZE);
offs4k = (tmp_pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE; offs4k = (tmp_pbuf->addr & ~PAGE_MASK) / EHCA_PAGESIZE;
*rpage = phys_to_abs((tmp_pbuf->addr & EHCA_PAGEMASK) + *rpage = phys_to_abs((tmp_pbuf->addr & EHCA_PAGEMASK) +
(pginfo->next_4k * EHCA_PAGESIZE)); (pginfo->next_4k * EHCA_PAGESIZE));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment