2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/module.h>
34 #include <linux/moduleparam.h>
35 #include <rdma/ib_umem.h>
36 #include <linux/atomic.h>
37 #include <rdma/ib_user_verbs.h>
42 module_param(use_dsgl
, int, 0644);
43 MODULE_PARM_DESC(use_dsgl
, "Use DSGL for PBL/FastReg (default=0)");
45 #define T4_ULPTX_MIN_IO 32
46 #define C4IW_MAX_INLINE_SIZE 96
47 #define T4_ULPTX_MAX_DMA 1024
48 #define C4IW_INLINE_THRESHOLD 128
50 static int inline_threshold
= C4IW_INLINE_THRESHOLD
;
51 module_param(inline_threshold
, int, 0644);
52 MODULE_PARM_DESC(inline_threshold
, "inline vs dsgl threshold (default=128)");
54 static int mr_exceeds_hw_limits(struct c4iw_dev
*dev
, u64 length
)
56 return (is_t4(dev
->rdev
.lldi
.adapter_type
) ||
57 is_t5(dev
->rdev
.lldi
.adapter_type
)) &&
58 length
>= 8*1024*1024*1024ULL;
61 static int _c4iw_write_mem_dma_aligned(struct c4iw_rdev
*rdev
, u32 addr
,
62 u32 len
, dma_addr_t data
, int wait
)
65 struct ulp_mem_io
*req
;
66 struct ulptx_sgl
*sgl
;
69 struct c4iw_wr_wait wr_wait
;
74 c4iw_init_wr_wait(&wr_wait
);
75 wr_len
= roundup(sizeof(*req
) + sizeof(*sgl
), 16);
77 skb
= alloc_skb(wr_len
, GFP_KERNEL
);
80 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, 0);
82 req
= (struct ulp_mem_io
*)__skb_put(skb
, wr_len
);
83 memset(req
, 0, wr_len
);
84 INIT_ULPTX_WR(req
, wr_len
, 0, 0);
85 req
->wr
.wr_hi
= cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR
) |
86 (wait
? FW_WR_COMPL_F
: 0));
87 req
->wr
.wr_lo
= wait
? (__force __be64
)(unsigned long) &wr_wait
: 0L;
88 req
->wr
.wr_mid
= cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(wr_len
, 16)));
89 req
->cmd
= cpu_to_be32(ULPTX_CMD_V(ULP_TX_MEM_WRITE
));
90 req
->cmd
|= cpu_to_be32(T5_ULP_MEMIO_ORDER_V(1));
91 req
->dlen
= cpu_to_be32(ULP_MEMIO_DATA_LEN_V(len
>>5));
92 req
->len16
= cpu_to_be32(DIV_ROUND_UP(wr_len
-sizeof(req
->wr
), 16));
93 req
->lock_addr
= cpu_to_be32(ULP_MEMIO_ADDR_V(addr
));
95 sgl
= (struct ulptx_sgl
*)(req
+ 1);
96 sgl
->cmd_nsge
= cpu_to_be32(ULPTX_CMD_V(ULP_TX_SC_DSGL
) |
98 sgl
->len0
= cpu_to_be32(len
);
99 sgl
->addr0
= cpu_to_be64(data
);
101 ret
= c4iw_ofld_send(rdev
, skb
);
105 ret
= c4iw_wait_for_reply(rdev
, &wr_wait
, 0, 0, __func__
);
109 static int _c4iw_write_mem_inline(struct c4iw_rdev
*rdev
, u32 addr
, u32 len
,
113 struct ulp_mem_io
*req
;
114 struct ulptx_idata
*sc
;
115 u8 wr_len
, *to_dp
, *from_dp
;
116 int copy_len
, num_wqe
, i
, ret
= 0;
117 struct c4iw_wr_wait wr_wait
;
118 __be32 cmd
= cpu_to_be32(ULPTX_CMD_V(ULP_TX_MEM_WRITE
));
120 if (is_t4(rdev
->lldi
.adapter_type
))
121 cmd
|= cpu_to_be32(ULP_MEMIO_ORDER_F
);
123 cmd
|= cpu_to_be32(T5_ULP_MEMIO_IMM_F
);
126 PDBG("%s addr 0x%x len %u\n", __func__
, addr
, len
);
127 num_wqe
= DIV_ROUND_UP(len
, C4IW_MAX_INLINE_SIZE
);
128 c4iw_init_wr_wait(&wr_wait
);
129 for (i
= 0; i
< num_wqe
; i
++) {
131 copy_len
= len
> C4IW_MAX_INLINE_SIZE
? C4IW_MAX_INLINE_SIZE
:
133 wr_len
= roundup(sizeof *req
+ sizeof *sc
+
134 roundup(copy_len
, T4_ULPTX_MIN_IO
), 16);
136 skb
= alloc_skb(wr_len
, GFP_KERNEL
);
139 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, 0);
141 req
= (struct ulp_mem_io
*)__skb_put(skb
, wr_len
);
142 memset(req
, 0, wr_len
);
143 INIT_ULPTX_WR(req
, wr_len
, 0, 0);
145 if (i
== (num_wqe
-1)) {
146 req
->wr
.wr_hi
= cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR
) |
148 req
->wr
.wr_lo
= (__force __be64
)(unsigned long)&wr_wait
;
150 req
->wr
.wr_hi
= cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR
));
151 req
->wr
.wr_mid
= cpu_to_be32(
152 FW_WR_LEN16_V(DIV_ROUND_UP(wr_len
, 16)));
155 req
->dlen
= cpu_to_be32(ULP_MEMIO_DATA_LEN_V(
156 DIV_ROUND_UP(copy_len
, T4_ULPTX_MIN_IO
)));
157 req
->len16
= cpu_to_be32(DIV_ROUND_UP(wr_len
-sizeof(req
->wr
),
159 req
->lock_addr
= cpu_to_be32(ULP_MEMIO_ADDR_V(addr
+ i
* 3));
161 sc
= (struct ulptx_idata
*)(req
+ 1);
162 sc
->cmd_more
= cpu_to_be32(ULPTX_CMD_V(ULP_TX_SC_IMM
));
163 sc
->len
= cpu_to_be32(roundup(copy_len
, T4_ULPTX_MIN_IO
));
165 to_dp
= (u8
*)(sc
+ 1);
166 from_dp
= (u8
*)data
+ i
* C4IW_MAX_INLINE_SIZE
;
168 memcpy(to_dp
, from_dp
, copy_len
);
170 memset(to_dp
, 0, copy_len
);
171 if (copy_len
% T4_ULPTX_MIN_IO
)
172 memset(to_dp
+ copy_len
, 0, T4_ULPTX_MIN_IO
-
173 (copy_len
% T4_ULPTX_MIN_IO
));
174 ret
= c4iw_ofld_send(rdev
, skb
);
177 len
-= C4IW_MAX_INLINE_SIZE
;
180 ret
= c4iw_wait_for_reply(rdev
, &wr_wait
, 0, 0, __func__
);
184 static int _c4iw_write_mem_dma(struct c4iw_rdev
*rdev
, u32 addr
, u32 len
, void *data
)
192 daddr
= dma_map_single(&rdev
->lldi
.pdev
->dev
, data
, len
, DMA_TO_DEVICE
);
193 if (dma_mapping_error(&rdev
->lldi
.pdev
->dev
, daddr
))
197 while (remain
> inline_threshold
) {
198 if (remain
< T4_ULPTX_MAX_DMA
) {
199 if (remain
& ~T4_ULPTX_MIN_IO
)
200 dmalen
= remain
& ~(T4_ULPTX_MIN_IO
-1);
204 dmalen
= T4_ULPTX_MAX_DMA
;
206 ret
= _c4iw_write_mem_dma_aligned(rdev
, addr
, dmalen
, daddr
,
215 ret
= _c4iw_write_mem_inline(rdev
, addr
, remain
, data
);
217 dma_unmap_single(&rdev
->lldi
.pdev
->dev
, save
, len
, DMA_TO_DEVICE
);
222 * write len bytes of data into addr (32B aligned address)
223 * If data is NULL, clear len byte of memory to zero.
225 static int write_adapter_mem(struct c4iw_rdev
*rdev
, u32 addr
, u32 len
,
228 if (is_t5(rdev
->lldi
.adapter_type
) && use_dsgl
) {
229 if (len
> inline_threshold
) {
230 if (_c4iw_write_mem_dma(rdev
, addr
, len
, data
)) {
231 printk_ratelimited(KERN_WARNING
233 " failure (non fatal)\n",
234 pci_name(rdev
->lldi
.pdev
));
235 return _c4iw_write_mem_inline(rdev
, addr
, len
,
240 return _c4iw_write_mem_inline(rdev
, addr
, len
, data
);
242 return _c4iw_write_mem_inline(rdev
, addr
, len
, data
);
246 * Build and write a TPT entry.
247 * IN: stag key, pdid, perm, bind_enabled, zbva, to, len, page_size,
248 * pbl_size and pbl_addr
251 static int write_tpt_entry(struct c4iw_rdev
*rdev
, u32 reset_tpt_entry
,
252 u32
*stag
, u8 stag_state
, u32 pdid
,
253 enum fw_ri_stag_type type
, enum fw_ri_mem_perms perm
,
254 int bind_enabled
, u32 zbva
, u64 to
,
255 u64 len
, u8 page_size
, u32 pbl_size
, u32 pbl_addr
)
258 struct fw_ri_tpte tpt
;
262 if (c4iw_fatal_error(rdev
))
265 stag_state
= stag_state
> 0;
266 stag_idx
= (*stag
) >> 8;
268 if ((!reset_tpt_entry
) && (*stag
== T4_STAG_UNSET
)) {
269 stag_idx
= c4iw_get_resource(&rdev
->resource
.tpt_table
);
271 mutex_lock(&rdev
->stats
.lock
);
272 rdev
->stats
.stag
.fail
++;
273 mutex_unlock(&rdev
->stats
.lock
);
276 mutex_lock(&rdev
->stats
.lock
);
277 rdev
->stats
.stag
.cur
+= 32;
278 if (rdev
->stats
.stag
.cur
> rdev
->stats
.stag
.max
)
279 rdev
->stats
.stag
.max
= rdev
->stats
.stag
.cur
;
280 mutex_unlock(&rdev
->stats
.lock
);
281 *stag
= (stag_idx
<< 8) | (atomic_inc_return(&key
) & 0xff);
283 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
284 __func__
, stag_state
, type
, pdid
, stag_idx
);
286 /* write TPT entry */
288 memset(&tpt
, 0, sizeof(tpt
));
290 tpt
.valid_to_pdid
= cpu_to_be32(FW_RI_TPTE_VALID_F
|
291 FW_RI_TPTE_STAGKEY_V((*stag
& FW_RI_TPTE_STAGKEY_M
)) |
292 FW_RI_TPTE_STAGSTATE_V(stag_state
) |
293 FW_RI_TPTE_STAGTYPE_V(type
) | FW_RI_TPTE_PDID_V(pdid
));
294 tpt
.locread_to_qpid
= cpu_to_be32(FW_RI_TPTE_PERM_V(perm
) |
295 (bind_enabled
? FW_RI_TPTE_MWBINDEN_F
: 0) |
296 FW_RI_TPTE_ADDRTYPE_V((zbva
? FW_RI_ZERO_BASED_TO
:
298 FW_RI_TPTE_PS_V(page_size
));
299 tpt
.nosnoop_pbladdr
= !pbl_size
? 0 : cpu_to_be32(
300 FW_RI_TPTE_PBLADDR_V(PBL_OFF(rdev
, pbl_addr
)>>3));
301 tpt
.len_lo
= cpu_to_be32((u32
)(len
& 0xffffffffUL
));
302 tpt
.va_hi
= cpu_to_be32((u32
)(to
>> 32));
303 tpt
.va_lo_fbo
= cpu_to_be32((u32
)(to
& 0xffffffffUL
));
304 tpt
.dca_mwbcnt_pstag
= cpu_to_be32(0);
305 tpt
.len_hi
= cpu_to_be32((u32
)(len
>> 32));
307 err
= write_adapter_mem(rdev
, stag_idx
+
308 (rdev
->lldi
.vr
->stag
.start
>> 5),
311 if (reset_tpt_entry
) {
312 c4iw_put_resource(&rdev
->resource
.tpt_table
, stag_idx
);
313 mutex_lock(&rdev
->stats
.lock
);
314 rdev
->stats
.stag
.cur
-= 32;
315 mutex_unlock(&rdev
->stats
.lock
);
320 static int write_pbl(struct c4iw_rdev
*rdev
, __be64
*pbl
,
321 u32 pbl_addr
, u32 pbl_size
)
325 PDBG("%s *pdb_addr 0x%x, pbl_base 0x%x, pbl_size %d\n",
326 __func__
, pbl_addr
, rdev
->lldi
.vr
->pbl
.start
,
329 err
= write_adapter_mem(rdev
, pbl_addr
>> 5, pbl_size
<< 3, pbl
);
333 static int dereg_mem(struct c4iw_rdev
*rdev
, u32 stag
, u32 pbl_size
,
336 return write_tpt_entry(rdev
, 1, &stag
, 0, 0, 0, 0, 0, 0, 0UL, 0, 0,
340 static int allocate_window(struct c4iw_rdev
*rdev
, u32
* stag
, u32 pdid
)
342 *stag
= T4_STAG_UNSET
;
343 return write_tpt_entry(rdev
, 0, stag
, 0, pdid
, FW_RI_STAG_MW
, 0, 0, 0,
347 static int deallocate_window(struct c4iw_rdev
*rdev
, u32 stag
)
349 return write_tpt_entry(rdev
, 1, &stag
, 0, 0, 0, 0, 0, 0, 0UL, 0, 0, 0,
353 static int allocate_stag(struct c4iw_rdev
*rdev
, u32
*stag
, u32 pdid
,
354 u32 pbl_size
, u32 pbl_addr
)
356 *stag
= T4_STAG_UNSET
;
357 return write_tpt_entry(rdev
, 0, stag
, 0, pdid
, FW_RI_STAG_NSMR
, 0, 0, 0,
358 0UL, 0, 0, pbl_size
, pbl_addr
);
361 static int finish_mem_reg(struct c4iw_mr
*mhp
, u32 stag
)
366 mhp
->attr
.stag
= stag
;
368 mhp
->ibmr
.rkey
= mhp
->ibmr
.lkey
= stag
;
369 PDBG("%s mmid 0x%x mhp %p\n", __func__
, mmid
, mhp
);
370 return insert_handle(mhp
->rhp
, &mhp
->rhp
->mmidr
, mhp
, mmid
);
373 static int register_mem(struct c4iw_dev
*rhp
, struct c4iw_pd
*php
,
374 struct c4iw_mr
*mhp
, int shift
)
376 u32 stag
= T4_STAG_UNSET
;
379 ret
= write_tpt_entry(&rhp
->rdev
, 0, &stag
, 1, mhp
->attr
.pdid
,
380 FW_RI_STAG_NSMR
, mhp
->attr
.len
?
382 mhp
->attr
.mw_bind_enable
, mhp
->attr
.zbva
,
383 mhp
->attr
.va_fbo
, mhp
->attr
.len
?
384 mhp
->attr
.len
: -1, shift
- 12,
385 mhp
->attr
.pbl_size
, mhp
->attr
.pbl_addr
);
389 ret
= finish_mem_reg(mhp
, stag
);
391 dereg_mem(&rhp
->rdev
, mhp
->attr
.stag
, mhp
->attr
.pbl_size
,
396 static int alloc_pbl(struct c4iw_mr
*mhp
, int npages
)
398 mhp
->attr
.pbl_addr
= c4iw_pblpool_alloc(&mhp
->rhp
->rdev
,
401 if (!mhp
->attr
.pbl_addr
)
404 mhp
->attr
.pbl_size
= npages
;
409 struct ib_mr
*c4iw_get_dma_mr(struct ib_pd
*pd
, int acc
)
411 struct c4iw_dev
*rhp
;
415 u32 stag
= T4_STAG_UNSET
;
417 PDBG("%s ib_pd %p\n", __func__
, pd
);
418 php
= to_c4iw_pd(pd
);
421 mhp
= kzalloc(sizeof(*mhp
), GFP_KERNEL
);
423 return ERR_PTR(-ENOMEM
);
426 mhp
->attr
.pdid
= php
->pdid
;
427 mhp
->attr
.perms
= c4iw_ib_to_tpt_access(acc
);
428 mhp
->attr
.mw_bind_enable
= (acc
&IB_ACCESS_MW_BIND
) == IB_ACCESS_MW_BIND
;
430 mhp
->attr
.va_fbo
= 0;
431 mhp
->attr
.page_size
= 0;
432 mhp
->attr
.len
= ~0ULL;
433 mhp
->attr
.pbl_size
= 0;
435 ret
= write_tpt_entry(&rhp
->rdev
, 0, &stag
, 1, php
->pdid
,
436 FW_RI_STAG_NSMR
, mhp
->attr
.perms
,
437 mhp
->attr
.mw_bind_enable
, 0, 0, ~0ULL, 0, 0, 0);
441 ret
= finish_mem_reg(mhp
, stag
);
446 dereg_mem(&rhp
->rdev
, mhp
->attr
.stag
, mhp
->attr
.pbl_size
,
453 struct ib_mr
*c4iw_reg_user_mr(struct ib_pd
*pd
, u64 start
, u64 length
,
454 u64 virt
, int acc
, struct ib_udata
*udata
)
460 struct scatterlist
*sg
;
461 struct c4iw_dev
*rhp
;
465 PDBG("%s ib_pd %p\n", __func__
, pd
);
468 return ERR_PTR(-EINVAL
);
470 if ((length
+ start
) < start
)
471 return ERR_PTR(-EINVAL
);
473 php
= to_c4iw_pd(pd
);
476 if (mr_exceeds_hw_limits(rhp
, length
))
477 return ERR_PTR(-EINVAL
);
479 mhp
= kzalloc(sizeof(*mhp
), GFP_KERNEL
);
481 return ERR_PTR(-ENOMEM
);
485 mhp
->umem
= ib_umem_get(pd
->uobject
->context
, start
, length
, acc
, 0);
486 if (IS_ERR(mhp
->umem
)) {
487 err
= PTR_ERR(mhp
->umem
);
492 shift
= ffs(mhp
->umem
->page_size
) - 1;
495 err
= alloc_pbl(mhp
, n
);
499 pages
= (__be64
*) __get_free_page(GFP_KERNEL
);
507 for_each_sg(mhp
->umem
->sg_head
.sgl
, sg
, mhp
->umem
->nmap
, entry
) {
508 len
= sg_dma_len(sg
) >> shift
;
509 for (k
= 0; k
< len
; ++k
) {
510 pages
[i
++] = cpu_to_be64(sg_dma_address(sg
) +
511 mhp
->umem
->page_size
* k
);
512 if (i
== PAGE_SIZE
/ sizeof *pages
) {
513 err
= write_pbl(&mhp
->rhp
->rdev
,
515 mhp
->attr
.pbl_addr
+ (n
<< 3), i
);
525 err
= write_pbl(&mhp
->rhp
->rdev
, pages
,
526 mhp
->attr
.pbl_addr
+ (n
<< 3), i
);
529 free_page((unsigned long) pages
);
533 mhp
->attr
.pdid
= php
->pdid
;
535 mhp
->attr
.perms
= c4iw_ib_to_tpt_access(acc
);
536 mhp
->attr
.va_fbo
= virt
;
537 mhp
->attr
.page_size
= shift
- 12;
538 mhp
->attr
.len
= length
;
540 err
= register_mem(rhp
, php
, mhp
, shift
);
547 c4iw_pblpool_free(&mhp
->rhp
->rdev
, mhp
->attr
.pbl_addr
,
548 mhp
->attr
.pbl_size
<< 3);
551 ib_umem_release(mhp
->umem
);
556 struct ib_mw
*c4iw_alloc_mw(struct ib_pd
*pd
, enum ib_mw_type type
,
557 struct ib_udata
*udata
)
559 struct c4iw_dev
*rhp
;
566 if (type
!= IB_MW_TYPE_1
)
567 return ERR_PTR(-EINVAL
);
569 php
= to_c4iw_pd(pd
);
571 mhp
= kzalloc(sizeof(*mhp
), GFP_KERNEL
);
573 return ERR_PTR(-ENOMEM
);
574 ret
= allocate_window(&rhp
->rdev
, &stag
, php
->pdid
);
580 mhp
->attr
.pdid
= php
->pdid
;
581 mhp
->attr
.type
= FW_RI_STAG_MW
;
582 mhp
->attr
.stag
= stag
;
584 mhp
->ibmw
.rkey
= stag
;
585 if (insert_handle(rhp
, &rhp
->mmidr
, mhp
, mmid
)) {
586 deallocate_window(&rhp
->rdev
, mhp
->attr
.stag
);
588 return ERR_PTR(-ENOMEM
);
590 PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __func__
, mmid
, mhp
, stag
);
594 int c4iw_dealloc_mw(struct ib_mw
*mw
)
596 struct c4iw_dev
*rhp
;
600 mhp
= to_c4iw_mw(mw
);
602 mmid
= (mw
->rkey
) >> 8;
603 remove_handle(rhp
, &rhp
->mmidr
, mmid
);
604 deallocate_window(&rhp
->rdev
, mhp
->attr
.stag
);
606 PDBG("%s ib_mw %p mmid 0x%x ptr %p\n", __func__
, mw
, mmid
, mhp
);
610 struct ib_mr
*c4iw_alloc_mr(struct ib_pd
*pd
,
611 enum ib_mr_type mr_type
,
614 struct c4iw_dev
*rhp
;
620 int length
= roundup(max_num_sg
* sizeof(u64
), 32);
622 php
= to_c4iw_pd(pd
);
625 if (mr_type
!= IB_MR_TYPE_MEM_REG
||
626 max_num_sg
> t4_max_fr_depth(&rhp
->rdev
.lldi
.ulptx_memwrite_dsgl
&&
628 return ERR_PTR(-EINVAL
);
630 mhp
= kzalloc(sizeof(*mhp
), GFP_KERNEL
);
636 mhp
->mpl
= dma_alloc_coherent(&rhp
->rdev
.lldi
.pdev
->dev
,
637 length
, &mhp
->mpl_addr
, GFP_KERNEL
);
642 mhp
->max_mpl_len
= length
;
645 ret
= alloc_pbl(mhp
, max_num_sg
);
648 mhp
->attr
.pbl_size
= max_num_sg
;
649 ret
= allocate_stag(&rhp
->rdev
, &stag
, php
->pdid
,
650 mhp
->attr
.pbl_size
, mhp
->attr
.pbl_addr
);
653 mhp
->attr
.pdid
= php
->pdid
;
654 mhp
->attr
.type
= FW_RI_STAG_NSMR
;
655 mhp
->attr
.stag
= stag
;
658 mhp
->ibmr
.rkey
= mhp
->ibmr
.lkey
= stag
;
659 if (insert_handle(rhp
, &rhp
->mmidr
, mhp
, mmid
)) {
664 PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __func__
, mmid
, mhp
, stag
);
667 dereg_mem(&rhp
->rdev
, stag
, mhp
->attr
.pbl_size
,
670 c4iw_pblpool_free(&mhp
->rhp
->rdev
, mhp
->attr
.pbl_addr
,
671 mhp
->attr
.pbl_size
<< 3);
673 dma_free_coherent(&mhp
->rhp
->rdev
.lldi
.pdev
->dev
,
674 mhp
->max_mpl_len
, mhp
->mpl
, mhp
->mpl_addr
);
681 static int c4iw_set_page(struct ib_mr
*ibmr
, u64 addr
)
683 struct c4iw_mr
*mhp
= to_c4iw_mr(ibmr
);
685 if (unlikely(mhp
->mpl_len
== mhp
->max_mpl_len
))
688 mhp
->mpl
[mhp
->mpl_len
++] = addr
;
693 int c4iw_map_mr_sg(struct ib_mr
*ibmr
,
694 struct scatterlist
*sg
,
697 struct c4iw_mr
*mhp
= to_c4iw_mr(ibmr
);
701 return ib_sg_to_pages(ibmr
, sg
, sg_nents
, c4iw_set_page
);
704 int c4iw_dereg_mr(struct ib_mr
*ib_mr
)
706 struct c4iw_dev
*rhp
;
710 PDBG("%s ib_mr %p\n", __func__
, ib_mr
);
712 mhp
= to_c4iw_mr(ib_mr
);
714 mmid
= mhp
->attr
.stag
>> 8;
715 remove_handle(rhp
, &rhp
->mmidr
, mmid
);
717 dma_free_coherent(&mhp
->rhp
->rdev
.lldi
.pdev
->dev
,
718 mhp
->max_mpl_len
, mhp
->mpl
, mhp
->mpl_addr
);
719 dereg_mem(&rhp
->rdev
, mhp
->attr
.stag
, mhp
->attr
.pbl_size
,
721 if (mhp
->attr
.pbl_size
)
722 c4iw_pblpool_free(&mhp
->rhp
->rdev
, mhp
->attr
.pbl_addr
,
723 mhp
->attr
.pbl_size
<< 3);
725 kfree((void *) (unsigned long) mhp
->kva
);
727 ib_umem_release(mhp
->umem
);
728 PDBG("%s mmid 0x%x ptr %p\n", __func__
, mmid
, mhp
);