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=1) (DEPRECATED)");
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
,
64 struct c4iw_wr_wait
*wr_waitp
)
66 struct ulp_mem_io
*req
;
67 struct ulptx_sgl
*sgl
;
74 c4iw_init_wr_wait(wr_waitp
);
75 wr_len
= roundup(sizeof(*req
) + sizeof(*sgl
), 16);
78 skb
= alloc_skb(wr_len
, GFP_KERNEL
| __GFP_NOFAIL
);
82 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, 0);
84 req
= __skb_put_zero(skb
, wr_len
);
85 INIT_ULPTX_WR(req
, wr_len
, 0, 0);
86 req
->wr
.wr_hi
= cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR
) |
87 (wr_waitp
? FW_WR_COMPL_F
: 0));
88 req
->wr
.wr_lo
= wr_waitp
? (__force __be64
)(unsigned long)wr_waitp
: 0L;
89 req
->wr
.wr_mid
= cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(wr_len
, 16)));
90 req
->cmd
= cpu_to_be32(ULPTX_CMD_V(ULP_TX_MEM_WRITE
) |
91 T5_ULP_MEMIO_ORDER_V(1) |
92 T5_ULP_MEMIO_FID_V(rdev
->lldi
.rxq_ids
[0]));
93 req
->dlen
= cpu_to_be32(ULP_MEMIO_DATA_LEN_V(len
>>5));
94 req
->len16
= cpu_to_be32(DIV_ROUND_UP(wr_len
-sizeof(req
->wr
), 16));
95 req
->lock_addr
= cpu_to_be32(ULP_MEMIO_ADDR_V(addr
));
97 sgl
= (struct ulptx_sgl
*)(req
+ 1);
98 sgl
->cmd_nsge
= cpu_to_be32(ULPTX_CMD_V(ULP_TX_SC_DSGL
) |
100 sgl
->len0
= cpu_to_be32(len
);
101 sgl
->addr0
= cpu_to_be64(data
);
104 ret
= c4iw_ref_send_wait(rdev
, skb
, wr_waitp
, 0, 0, __func__
);
106 ret
= c4iw_ofld_send(rdev
, skb
);
110 static int _c4iw_write_mem_inline(struct c4iw_rdev
*rdev
, u32 addr
, u32 len
,
111 void *data
, struct sk_buff
*skb
,
112 struct c4iw_wr_wait
*wr_waitp
)
114 struct ulp_mem_io
*req
;
115 struct ulptx_idata
*sc
;
116 u8 wr_len
, *to_dp
, *from_dp
;
117 int copy_len
, num_wqe
, i
, ret
= 0;
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 pr_debug("addr 0x%x len %u\n", addr
, len
);
127 num_wqe
= DIV_ROUND_UP(len
, C4IW_MAX_INLINE_SIZE
);
128 c4iw_init_wr_wait(wr_waitp
);
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
),
138 skb
= alloc_skb(wr_len
, GFP_KERNEL
| __GFP_NOFAIL
);
142 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, 0);
144 req
= __skb_put_zero(skb
, wr_len
);
145 INIT_ULPTX_WR(req
, wr_len
, 0, 0);
147 if (i
== (num_wqe
-1)) {
148 req
->wr
.wr_hi
= cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR
) |
150 req
->wr
.wr_lo
= (__force __be64
)(unsigned long)wr_waitp
;
152 req
->wr
.wr_hi
= cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR
));
153 req
->wr
.wr_mid
= cpu_to_be32(
154 FW_WR_LEN16_V(DIV_ROUND_UP(wr_len
, 16)));
157 req
->dlen
= cpu_to_be32(ULP_MEMIO_DATA_LEN_V(
158 DIV_ROUND_UP(copy_len
, T4_ULPTX_MIN_IO
)));
159 req
->len16
= cpu_to_be32(DIV_ROUND_UP(wr_len
-sizeof(req
->wr
),
161 req
->lock_addr
= cpu_to_be32(ULP_MEMIO_ADDR_V(addr
+ i
* 3));
163 sc
= (struct ulptx_idata
*)(req
+ 1);
164 sc
->cmd_more
= cpu_to_be32(ULPTX_CMD_V(ULP_TX_SC_IMM
));
165 sc
->len
= cpu_to_be32(roundup(copy_len
, T4_ULPTX_MIN_IO
));
167 to_dp
= (u8
*)(sc
+ 1);
168 from_dp
= (u8
*)data
+ i
* C4IW_MAX_INLINE_SIZE
;
170 memcpy(to_dp
, from_dp
, copy_len
);
172 memset(to_dp
, 0, copy_len
);
173 if (copy_len
% T4_ULPTX_MIN_IO
)
174 memset(to_dp
+ copy_len
, 0, T4_ULPTX_MIN_IO
-
175 (copy_len
% T4_ULPTX_MIN_IO
));
176 if (i
== (num_wqe
-1))
177 ret
= c4iw_ref_send_wait(rdev
, skb
, wr_waitp
, 0, 0,
180 ret
= c4iw_ofld_send(rdev
, skb
);
184 len
-= C4IW_MAX_INLINE_SIZE
;
190 static int _c4iw_write_mem_dma(struct c4iw_rdev
*rdev
, u32 addr
, u32 len
,
191 void *data
, struct sk_buff
*skb
,
192 struct c4iw_wr_wait
*wr_waitp
)
200 daddr
= dma_map_single(&rdev
->lldi
.pdev
->dev
, data
, len
, DMA_TO_DEVICE
);
201 if (dma_mapping_error(&rdev
->lldi
.pdev
->dev
, daddr
))
205 while (remain
> inline_threshold
) {
206 if (remain
< T4_ULPTX_MAX_DMA
) {
207 if (remain
& ~T4_ULPTX_MIN_IO
)
208 dmalen
= remain
& ~(T4_ULPTX_MIN_IO
-1);
212 dmalen
= T4_ULPTX_MAX_DMA
;
214 ret
= _c4iw_write_mem_dma_aligned(rdev
, addr
, dmalen
, daddr
,
215 skb
, remain
? NULL
: wr_waitp
);
223 ret
= _c4iw_write_mem_inline(rdev
, addr
, remain
, data
, skb
,
226 dma_unmap_single(&rdev
->lldi
.pdev
->dev
, save
, len
, DMA_TO_DEVICE
);
231 * write len bytes of data into addr (32B aligned address)
232 * If data is NULL, clear len byte of memory to zero.
234 static int write_adapter_mem(struct c4iw_rdev
*rdev
, u32 addr
, u32 len
,
235 void *data
, struct sk_buff
*skb
,
236 struct c4iw_wr_wait
*wr_waitp
)
240 if (!rdev
->lldi
.ulptx_memwrite_dsgl
|| !use_dsgl
) {
241 ret
= _c4iw_write_mem_inline(rdev
, addr
, len
, data
, skb
,
246 if (len
<= inline_threshold
) {
247 ret
= _c4iw_write_mem_inline(rdev
, addr
, len
, data
, skb
,
252 ret
= _c4iw_write_mem_dma(rdev
, addr
, len
, data
, skb
, wr_waitp
);
254 pr_warn_ratelimited("%s: dma map failure (non fatal)\n",
255 pci_name(rdev
->lldi
.pdev
));
256 ret
= _c4iw_write_mem_inline(rdev
, addr
, len
, data
, skb
,
265 * Build and write a TPT entry.
266 * IN: stag key, pdid, perm, bind_enabled, zbva, to, len, page_size,
267 * pbl_size and pbl_addr
270 static int write_tpt_entry(struct c4iw_rdev
*rdev
, u32 reset_tpt_entry
,
271 u32
*stag
, u8 stag_state
, u32 pdid
,
272 enum fw_ri_stag_type type
, enum fw_ri_mem_perms perm
,
273 int bind_enabled
, u32 zbva
, u64 to
,
274 u64 len
, u8 page_size
, u32 pbl_size
, u32 pbl_addr
,
275 struct sk_buff
*skb
, struct c4iw_wr_wait
*wr_waitp
)
278 struct fw_ri_tpte
*tpt
;
282 if (c4iw_fatal_error(rdev
))
285 tpt
= kmalloc(sizeof(*tpt
), GFP_KERNEL
);
289 stag_state
= stag_state
> 0;
290 stag_idx
= (*stag
) >> 8;
292 if ((!reset_tpt_entry
) && (*stag
== T4_STAG_UNSET
)) {
293 stag_idx
= c4iw_get_resource(&rdev
->resource
.tpt_table
);
295 mutex_lock(&rdev
->stats
.lock
);
296 rdev
->stats
.stag
.fail
++;
297 mutex_unlock(&rdev
->stats
.lock
);
301 mutex_lock(&rdev
->stats
.lock
);
302 rdev
->stats
.stag
.cur
+= 32;
303 if (rdev
->stats
.stag
.cur
> rdev
->stats
.stag
.max
)
304 rdev
->stats
.stag
.max
= rdev
->stats
.stag
.cur
;
305 mutex_unlock(&rdev
->stats
.lock
);
306 *stag
= (stag_idx
<< 8) | (atomic_inc_return(&key
) & 0xff);
308 pr_debug("stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
309 stag_state
, type
, pdid
, stag_idx
);
311 /* write TPT entry */
313 memset(tpt
, 0, sizeof(*tpt
));
315 tpt
->valid_to_pdid
= cpu_to_be32(FW_RI_TPTE_VALID_F
|
316 FW_RI_TPTE_STAGKEY_V((*stag
& FW_RI_TPTE_STAGKEY_M
)) |
317 FW_RI_TPTE_STAGSTATE_V(stag_state
) |
318 FW_RI_TPTE_STAGTYPE_V(type
) | FW_RI_TPTE_PDID_V(pdid
));
319 tpt
->locread_to_qpid
= cpu_to_be32(FW_RI_TPTE_PERM_V(perm
) |
320 (bind_enabled
? FW_RI_TPTE_MWBINDEN_F
: 0) |
321 FW_RI_TPTE_ADDRTYPE_V((zbva
? FW_RI_ZERO_BASED_TO
:
323 FW_RI_TPTE_PS_V(page_size
));
324 tpt
->nosnoop_pbladdr
= !pbl_size
? 0 : cpu_to_be32(
325 FW_RI_TPTE_PBLADDR_V(PBL_OFF(rdev
, pbl_addr
)>>3));
326 tpt
->len_lo
= cpu_to_be32((u32
)(len
& 0xffffffffUL
));
327 tpt
->va_hi
= cpu_to_be32((u32
)(to
>> 32));
328 tpt
->va_lo_fbo
= cpu_to_be32((u32
)(to
& 0xffffffffUL
));
329 tpt
->dca_mwbcnt_pstag
= cpu_to_be32(0);
330 tpt
->len_hi
= cpu_to_be32((u32
)(len
>> 32));
332 err
= write_adapter_mem(rdev
, stag_idx
+
333 (rdev
->lldi
.vr
->stag
.start
>> 5),
334 sizeof(*tpt
), tpt
, skb
, wr_waitp
);
336 if (reset_tpt_entry
) {
337 c4iw_put_resource(&rdev
->resource
.tpt_table
, stag_idx
);
338 mutex_lock(&rdev
->stats
.lock
);
339 rdev
->stats
.stag
.cur
-= 32;
340 mutex_unlock(&rdev
->stats
.lock
);
346 static int write_pbl(struct c4iw_rdev
*rdev
, __be64
*pbl
,
347 u32 pbl_addr
, u32 pbl_size
, struct c4iw_wr_wait
*wr_waitp
)
351 pr_debug("*pdb_addr 0x%x, pbl_base 0x%x, pbl_size %d\n",
352 pbl_addr
, rdev
->lldi
.vr
->pbl
.start
,
355 err
= write_adapter_mem(rdev
, pbl_addr
>> 5, pbl_size
<< 3, pbl
, NULL
,
360 static int dereg_mem(struct c4iw_rdev
*rdev
, u32 stag
, u32 pbl_size
,
361 u32 pbl_addr
, struct sk_buff
*skb
,
362 struct c4iw_wr_wait
*wr_waitp
)
364 return write_tpt_entry(rdev
, 1, &stag
, 0, 0, 0, 0, 0, 0, 0UL, 0, 0,
365 pbl_size
, pbl_addr
, skb
, wr_waitp
);
368 static int allocate_stag(struct c4iw_rdev
*rdev
, u32
*stag
, u32 pdid
,
369 u32 pbl_size
, u32 pbl_addr
,
370 struct c4iw_wr_wait
*wr_waitp
)
372 *stag
= T4_STAG_UNSET
;
373 return write_tpt_entry(rdev
, 0, stag
, 0, pdid
, FW_RI_STAG_NSMR
, 0, 0, 0,
374 0UL, 0, 0, pbl_size
, pbl_addr
, NULL
, wr_waitp
);
377 static int finish_mem_reg(struct c4iw_mr
*mhp
, u32 stag
)
382 mhp
->attr
.stag
= stag
;
384 mhp
->ibmr
.rkey
= mhp
->ibmr
.lkey
= stag
;
385 mhp
->ibmr
.length
= mhp
->attr
.len
;
386 mhp
->ibmr
.page_size
= 1U << (mhp
->attr
.page_size
+ 12);
387 pr_debug("mmid 0x%x mhp %p\n", mmid
, mhp
);
388 return xa_insert_irq(&mhp
->rhp
->mrs
, mmid
, mhp
, GFP_KERNEL
);
391 static int register_mem(struct c4iw_dev
*rhp
, struct c4iw_pd
*php
,
392 struct c4iw_mr
*mhp
, int shift
)
394 u32 stag
= T4_STAG_UNSET
;
397 ret
= write_tpt_entry(&rhp
->rdev
, 0, &stag
, 1, mhp
->attr
.pdid
,
398 FW_RI_STAG_NSMR
, mhp
->attr
.len
?
400 mhp
->attr
.mw_bind_enable
, mhp
->attr
.zbva
,
401 mhp
->attr
.va_fbo
, mhp
->attr
.len
?
402 mhp
->attr
.len
: -1, shift
- 12,
403 mhp
->attr
.pbl_size
, mhp
->attr
.pbl_addr
, NULL
,
408 ret
= finish_mem_reg(mhp
, stag
);
410 dereg_mem(&rhp
->rdev
, mhp
->attr
.stag
, mhp
->attr
.pbl_size
,
411 mhp
->attr
.pbl_addr
, mhp
->dereg_skb
, mhp
->wr_waitp
);
412 mhp
->dereg_skb
= NULL
;
417 static int alloc_pbl(struct c4iw_mr
*mhp
, int npages
)
419 mhp
->attr
.pbl_addr
= c4iw_pblpool_alloc(&mhp
->rhp
->rdev
,
422 if (!mhp
->attr
.pbl_addr
)
425 mhp
->attr
.pbl_size
= npages
;
430 struct ib_mr
*c4iw_get_dma_mr(struct ib_pd
*pd
, int acc
)
432 struct c4iw_dev
*rhp
;
436 u32 stag
= T4_STAG_UNSET
;
438 pr_debug("ib_pd %p\n", pd
);
439 php
= to_c4iw_pd(pd
);
442 mhp
= kzalloc(sizeof(*mhp
), GFP_KERNEL
);
444 return ERR_PTR(-ENOMEM
);
445 mhp
->wr_waitp
= c4iw_alloc_wr_wait(GFP_KERNEL
);
446 if (!mhp
->wr_waitp
) {
450 c4iw_init_wr_wait(mhp
->wr_waitp
);
452 mhp
->dereg_skb
= alloc_skb(SGE_MAX_WR_LEN
, GFP_KERNEL
);
453 if (!mhp
->dereg_skb
) {
455 goto err_free_wr_wait
;
459 mhp
->attr
.pdid
= php
->pdid
;
460 mhp
->attr
.perms
= c4iw_ib_to_tpt_access(acc
);
461 mhp
->attr
.mw_bind_enable
= (acc
&IB_ACCESS_MW_BIND
) == IB_ACCESS_MW_BIND
;
463 mhp
->attr
.va_fbo
= 0;
464 mhp
->attr
.page_size
= 0;
465 mhp
->attr
.len
= ~0ULL;
466 mhp
->attr
.pbl_size
= 0;
468 ret
= write_tpt_entry(&rhp
->rdev
, 0, &stag
, 1, php
->pdid
,
469 FW_RI_STAG_NSMR
, mhp
->attr
.perms
,
470 mhp
->attr
.mw_bind_enable
, 0, 0, ~0ULL, 0, 0, 0,
471 NULL
, mhp
->wr_waitp
);
475 ret
= finish_mem_reg(mhp
, stag
);
480 dereg_mem(&rhp
->rdev
, mhp
->attr
.stag
, mhp
->attr
.pbl_size
,
481 mhp
->attr
.pbl_addr
, mhp
->dereg_skb
, mhp
->wr_waitp
);
483 kfree_skb(mhp
->dereg_skb
);
485 c4iw_put_wr_wait(mhp
->wr_waitp
);
491 struct ib_mr
*c4iw_reg_user_mr(struct ib_pd
*pd
, u64 start
, u64 length
,
492 u64 virt
, int acc
, struct ib_udata
*udata
)
497 struct ib_block_iter biter
;
498 struct c4iw_dev
*rhp
;
502 pr_debug("ib_pd %p\n", pd
);
505 return ERR_PTR(-EINVAL
);
507 if ((length
+ start
) < start
)
508 return ERR_PTR(-EINVAL
);
510 php
= to_c4iw_pd(pd
);
513 if (mr_exceeds_hw_limits(rhp
, length
))
514 return ERR_PTR(-EINVAL
);
516 mhp
= kzalloc(sizeof(*mhp
), GFP_KERNEL
);
518 return ERR_PTR(-ENOMEM
);
519 mhp
->wr_waitp
= c4iw_alloc_wr_wait(GFP_KERNEL
);
523 mhp
->dereg_skb
= alloc_skb(SGE_MAX_WR_LEN
, GFP_KERNEL
);
525 goto err_free_wr_wait
;
529 mhp
->umem
= ib_umem_get(pd
->device
, start
, length
, acc
);
530 if (IS_ERR(mhp
->umem
))
535 n
= ib_umem_num_dma_blocks(mhp
->umem
, 1 << shift
);
536 err
= alloc_pbl(mhp
, n
);
538 goto err_umem_release
;
540 pages
= (__be64
*) __get_free_page(GFP_KERNEL
);
548 rdma_umem_for_each_dma_block(mhp
->umem
, &biter
, 1 << shift
) {
549 pages
[i
++] = cpu_to_be64(rdma_block_iter_dma_address(&biter
));
550 if (i
== PAGE_SIZE
/ sizeof(*pages
)) {
551 err
= write_pbl(&mhp
->rhp
->rdev
, pages
,
552 mhp
->attr
.pbl_addr
+ (n
<< 3), i
,
562 err
= write_pbl(&mhp
->rhp
->rdev
, pages
,
563 mhp
->attr
.pbl_addr
+ (n
<< 3), i
,
567 free_page((unsigned long) pages
);
571 mhp
->attr
.pdid
= php
->pdid
;
573 mhp
->attr
.perms
= c4iw_ib_to_tpt_access(acc
);
574 mhp
->attr
.va_fbo
= virt
;
575 mhp
->attr
.page_size
= shift
- 12;
576 mhp
->attr
.len
= length
;
578 err
= register_mem(rhp
, php
, mhp
, shift
);
585 c4iw_pblpool_free(&mhp
->rhp
->rdev
, mhp
->attr
.pbl_addr
,
586 mhp
->attr
.pbl_size
<< 3);
588 ib_umem_release(mhp
->umem
);
590 kfree_skb(mhp
->dereg_skb
);
592 c4iw_put_wr_wait(mhp
->wr_waitp
);
598 struct ib_mr
*c4iw_alloc_mr(struct ib_pd
*pd
, enum ib_mr_type mr_type
,
601 struct c4iw_dev
*rhp
;
607 int length
= roundup(max_num_sg
* sizeof(u64
), 32);
609 php
= to_c4iw_pd(pd
);
612 if (mr_type
!= IB_MR_TYPE_MEM_REG
||
613 max_num_sg
> t4_max_fr_depth(rhp
->rdev
.lldi
.ulptx_memwrite_dsgl
&&
615 return ERR_PTR(-EINVAL
);
617 mhp
= kzalloc(sizeof(*mhp
), GFP_KERNEL
);
623 mhp
->wr_waitp
= c4iw_alloc_wr_wait(GFP_KERNEL
);
624 if (!mhp
->wr_waitp
) {
628 c4iw_init_wr_wait(mhp
->wr_waitp
);
630 mhp
->mpl
= dma_alloc_coherent(&rhp
->rdev
.lldi
.pdev
->dev
,
631 length
, &mhp
->mpl_addr
, GFP_KERNEL
);
634 goto err_free_wr_wait
;
636 mhp
->max_mpl_len
= length
;
639 ret
= alloc_pbl(mhp
, max_num_sg
);
642 mhp
->attr
.pbl_size
= max_num_sg
;
643 ret
= allocate_stag(&rhp
->rdev
, &stag
, php
->pdid
,
644 mhp
->attr
.pbl_size
, mhp
->attr
.pbl_addr
,
648 mhp
->attr
.pdid
= php
->pdid
;
649 mhp
->attr
.type
= FW_RI_STAG_NSMR
;
650 mhp
->attr
.stag
= stag
;
653 mhp
->ibmr
.rkey
= mhp
->ibmr
.lkey
= stag
;
654 if (xa_insert_irq(&rhp
->mrs
, mmid
, mhp
, GFP_KERNEL
)) {
659 pr_debug("mmid 0x%x mhp %p stag 0x%x\n", mmid
, mhp
, stag
);
662 dereg_mem(&rhp
->rdev
, stag
, mhp
->attr
.pbl_size
,
663 mhp
->attr
.pbl_addr
, mhp
->dereg_skb
, mhp
->wr_waitp
);
665 c4iw_pblpool_free(&mhp
->rhp
->rdev
, mhp
->attr
.pbl_addr
,
666 mhp
->attr
.pbl_size
<< 3);
668 dma_free_coherent(&mhp
->rhp
->rdev
.lldi
.pdev
->dev
,
669 mhp
->max_mpl_len
, mhp
->mpl
, mhp
->mpl_addr
);
671 c4iw_put_wr_wait(mhp
->wr_waitp
);
678 static int c4iw_set_page(struct ib_mr
*ibmr
, u64 addr
)
680 struct c4iw_mr
*mhp
= to_c4iw_mr(ibmr
);
682 if (unlikely(mhp
->mpl_len
== mhp
->attr
.pbl_size
))
685 mhp
->mpl
[mhp
->mpl_len
++] = addr
;
690 int c4iw_map_mr_sg(struct ib_mr
*ibmr
, struct scatterlist
*sg
, int sg_nents
,
691 unsigned int *sg_offset
)
693 struct c4iw_mr
*mhp
= to_c4iw_mr(ibmr
);
697 return ib_sg_to_pages(ibmr
, sg
, sg_nents
, sg_offset
, c4iw_set_page
);
700 int c4iw_dereg_mr(struct ib_mr
*ib_mr
, struct ib_udata
*udata
)
702 struct c4iw_dev
*rhp
;
706 pr_debug("ib_mr %p\n", ib_mr
);
708 mhp
= to_c4iw_mr(ib_mr
);
710 mmid
= mhp
->attr
.stag
>> 8;
711 xa_erase_irq(&rhp
->mrs
, mmid
);
713 dma_free_coherent(&mhp
->rhp
->rdev
.lldi
.pdev
->dev
,
714 mhp
->max_mpl_len
, mhp
->mpl
, mhp
->mpl_addr
);
715 dereg_mem(&rhp
->rdev
, mhp
->attr
.stag
, mhp
->attr
.pbl_size
,
716 mhp
->attr
.pbl_addr
, mhp
->dereg_skb
, mhp
->wr_waitp
);
717 if (mhp
->attr
.pbl_size
)
718 c4iw_pblpool_free(&mhp
->rhp
->rdev
, mhp
->attr
.pbl_addr
,
719 mhp
->attr
.pbl_size
<< 3);
721 kfree((void *) (unsigned long) mhp
->kva
);
722 ib_umem_release(mhp
->umem
);
723 pr_debug("mmid 0x%x ptr %p\n", mmid
, mhp
);
724 c4iw_put_wr_wait(mhp
->wr_waitp
);
729 void c4iw_invalidate_mr(struct c4iw_dev
*rhp
, u32 rkey
)
734 xa_lock_irqsave(&rhp
->mrs
, flags
);
735 mhp
= xa_load(&rhp
->mrs
, rkey
>> 8);
738 xa_unlock_irqrestore(&rhp
->mrs
, flags
);