1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/ib/ibtl/impl/ibtl.h>
/*
* ibtl_mem.c
* These routines implement all of the Memory Region verbs and the alloc/
* query/free Memory Window verbs at the TI interface.
*/
static char ibtl_mem[] = "ibtl_mem";
/*
* Function:
* ibt_register_mr()
* Input:
* hca_hdl - HCA Handle.
* pd - Protection Domain Handle.
* mem_attr - Requested memory region attributes.
* Output:
* mr_hdl_p - The returned IBT memory region handle.
* mem_desc - Returned memory descriptor.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MR_VA_INVALID
* IBT_MR_LEN_INVALID
* IBT_MR_ACCESS_REQ_INVALID
* IBT_PD_HDL_INVALID
* IBT_INSUFF_RESOURCE
* Description:
* Prepares a virtually addressed memory region for use by a HCA. A
* description of the registered memory suitable for use in Work Requests
* (WRs) is returned in the ibt_mr_desc_t parameter.
*/
ibt_status_t
ibt_register_mr(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd, ibt_mr_attr_t *mem_attr,
ibt_mr_hdl_t *mr_hdl_p, ibt_mr_desc_t *mem_desc)
{
ib_vaddr_t vaddr;
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_register_mr(%p, %p, %p)",
hca_hdl, pd, mem_attr);
vaddr = mem_attr->mr_vaddr;
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_register_mr(
IBTL_HCA2CIHCA(hca_hdl), pd, mem_attr, IBTL_HCA2CLNT(hca_hdl),
mr_hdl_p, mem_desc);
if (status == IBT_SUCCESS) {
mem_desc->md_vaddr = vaddr;
atomic_inc_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_register_buf()
* Input:
* hca_hdl HCA Handle.
* pd Protection Domain Handle.
* mem_bpattr Memory Registration attributes (IOVA and flags).
* bp A pointer to a buf(9S) struct.
* Output:
* mr_hdl_p The returned IBT memory region handle.
* mem_desc Returned memory descriptor.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MR_VA_INVALID
* IBT_MR_LEN_INVALID
* IBT_MR_ACCESS_REQ_INVALID
* IBT_PD_HDL_INVALID
* IBT_INSUFF_RESOURCE
* Description:
* Prepares a memory region described by a buf(9S) struct for use by a HCA.
* A description of the registered memory suitable for use in
* Work Requests (WRs) is returned in the ibt_mr_desc_t parameter.
*/
ibt_status_t
ibt_register_buf(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
ibt_smr_attr_t *mem_bpattr, struct buf *bp, ibt_mr_hdl_t *mr_hdl_p,
ibt_mr_desc_t *mem_desc)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_register_buf(%p, %p, %p, %p)",
hca_hdl, pd, mem_bpattr, bp);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_register_buf(
IBTL_HCA2CIHCA(hca_hdl), pd, mem_bpattr, bp, IBTL_HCA2CLNT(hca_hdl),
mr_hdl_p, mem_desc);
if (status == IBT_SUCCESS) {
atomic_inc_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_query_mr()
* Input:
* hca_hdl - HCA Handle.
* mr_hdl - The IBT Memory Region handle.
* Output:
* attr - The pointer to Memory region attributes structure.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MR_HDL_INVALID
* Description:
* Retrieves information about a specified memory region.
*/
ibt_status_t
ibt_query_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
ibt_mr_query_attr_t *attr)
{
IBTF_DPRINTF_L3(ibtl_mem, "ibt_query_mr(%p, %p)", hca_hdl, mr_hdl);
return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_query_mr(
IBTL_HCA2CIHCA(hca_hdl), mr_hdl, attr));
}
/*
* Function:
* ibt_deregister_mr()
* Input:
* hca_hdl - HCA Handle.
* mr_hdl - The IBT Memory Region handle.
* Output:
* none.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MR_HDL_INVALID
* IBT_MR_IN_USE
* Description:
* De-register the registered memory region. Remove a memory region from a
* HCA translation table, and free all resources associated with the
* memory region.
*/
ibt_status_t
ibt_deregister_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_deregister_mr(%p, %p)", hca_hdl, mr_hdl);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_deregister_mr(
IBTL_HCA2CIHCA(hca_hdl), mr_hdl);
if (status == IBT_SUCCESS) {
atomic_dec_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_reregister_mr()
* Input:
* hca_hdl - HCA Handle.
* mr_hdl - The IBT Memory Region handle.
* pd - Optional Protection Domain Handle.
* mem_attr - Requested memory region attributes.
* Output:
* mr_hdl_p - The reregistered IBT memory region handle.
* mem_desc - Returned memory descriptor for the new memory region.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MR_HDL_INVALID
* IBT_MR_VA_INVALID
* IBT_MR_LEN_INVALID
* IBT_MR_ACCESS_REQ_INVALID
* IBT_PD_HDL_INVALID
* IBT_INSUFF_RESOURCE
* IBT_MR_IN_USE
* Description:
* Modify the attributes of an existing memory region.
*/
ibt_status_t
ibt_reregister_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl, ibt_pd_hdl_t pd,
ibt_mr_attr_t *mem_attr, ibt_mr_hdl_t *mr_hdl_p, ibt_mr_desc_t *mem_desc)
{
ibt_status_t status;
ib_vaddr_t vaddr = mem_attr->mr_vaddr;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_reregister_mr(%p, %p, %p, %p)",
hca_hdl, mr_hdl, pd, mem_attr);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_reregister_mr(
IBTL_HCA2CIHCA(hca_hdl), mr_hdl, pd, mem_attr,
IBTL_HCA2CLNT(hca_hdl), mr_hdl_p, mem_desc);
if (status == IBT_SUCCESS)
mem_desc->md_vaddr = vaddr;
else if (!(status == IBT_MR_IN_USE || status == IBT_HCA_HDL_INVALID ||
status == IBT_MR_HDL_INVALID)) {
IBTF_DPRINTF_L2(ibtl_mem, "ibt_reregister_mr: "
"Re-registration Failed: %d", status);
/* we lost one memory region resource */
atomic_dec_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_reregister_buf()
* Input:
* hca_hdl HCA Handle.
* mr_hdl The IBT Memory Region handle.
* pd Optional Protection Domain Handle.
* mem_bpattr Memory Registration attributes (IOVA and flags).
* bp A pointer to a buf(9S) struct.
* Output:
* mr_hdl_p The reregistered IBT memory region handle.
* mem_desc Returned memory descriptor for the new memory region.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MR_HDL_INVALID
* IBT_MR_VA_INVALID
* IBT_MR_LEN_INVALID
* IBT_MR_ACCESS_REQ_INVALID
* IBT_PD_HDL_INVALID
* IBT_INSUFF_RESOURCE
* IBT_MR_IN_USE
* Description:
* Modify the attributes of an existing memory region as described by a
* buf(9S) struct for use by a HCA. A description of the registered
* memory suitable for use in Work Requests (WRs) is returned in the
* ibt_mr_desc_t parameter.
*/
ibt_status_t
ibt_reregister_buf(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
ibt_pd_hdl_t pd, ibt_smr_attr_t *mem_bpattr, struct buf *bp,
ibt_mr_hdl_t *mr_hdl_p, ibt_mr_desc_t *mem_desc)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_reregister_buf(%p, %p, %p, %p, %p)",
hca_hdl, mr_hdl, pd, mem_bpattr, bp);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_reregister_buf(
IBTL_HCA2CIHCA(hca_hdl), mr_hdl, pd, mem_bpattr, bp,
IBTL_HCA2CLNT(hca_hdl), mr_hdl_p, mem_desc);
if (!(status == IBT_SUCCESS || status == IBT_MR_IN_USE ||
status == IBT_HCA_HDL_INVALID || status == IBT_MR_HDL_INVALID)) {
IBTF_DPRINTF_L2(ibtl_mem, "ibt_reregister_buf: "
"Re-registration Mem Failed: %d", status);
/* we lost one memory region resource */
atomic_dec_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_register_shared_mr()
* Input:
* hca_hdl - HCA Handle.
* mr_hdl - The IBT Memory Region handle.
* pd - Protection Domain Handle.
* mem_sattr - Requested memory region shared attributes.
* Output:
* mr_hdl_p - The reregistered IBT memory region handle.
* mem_desc - Returned memory descriptor for the new memory region.
* Returns:
* IBT_SUCCESS
* IBT_INSUFF_RESOURCE
* IBT_CHAN_HDL_INVALID
* IBT_MR_HDL_INVALID
* IBT_PD_HDL_INVALID
* IBT_MR_ACCESS_REQ_INVALID
* Description:
* Given an existing memory region, a new memory region associated with
* the same physical locations is created.
*/
ibt_status_t
ibt_register_shared_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
ibt_pd_hdl_t pd, ibt_smr_attr_t *mem_sattr, ibt_mr_hdl_t *mr_hdl_p,
ibt_mr_desc_t *mem_desc)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_register_shared_mr(%p, %p, %p, %p)",
hca_hdl, mr_hdl, pd, mem_sattr);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_register_shared_mr(
IBTL_HCA2CIHCA(hca_hdl), mr_hdl, pd, mem_sattr,
IBTL_HCA2CLNT(hca_hdl), mr_hdl_p, mem_desc);
if (status == IBT_SUCCESS) {
atomic_inc_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_sync_mr()
* Input:
* hca_hdl - HCA Handle.
* mr_segments - A pointer to an array of ibt_mr_sync_t that describes
* the memory regions to sync.
* num_segments - The length of the mr_segments array.
* Output:
* NONE
* Returns:
* IBT_SUCCESS
* IBT_HCA_HDL_INVALID
* IBT_MR_HDL_INVALID
* IBT_INVALID_PARAM
* IBT_MR_VA_INVALID
* IBT_MR_LEN_INVALID
* Description:
* Make memory changes visible to incoming RDMA reads, or make the affects
* of an incoming RDMA writes visible to the consumer.
*/
ibt_status_t
ibt_sync_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_sync_t *mr_segments,
size_t num_segments)
{
IBTF_DPRINTF_L3(ibtl_mem, "ibt_sync_mr(%p, %p, %d)", hca_hdl,
mr_segments, num_segments);
return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_sync_mr(
IBTL_HCA2CIHCA(hca_hdl), mr_segments, num_segments));
}
/*
* Function:
* ibt_alloc_mw()
* Input:
* hca_hdl - HCA Handle.
* pd - Protection Domain Handle.
* flags - Memory Window alloc flags.
* Output:
* mw_hdl_p - The returned IBT Memory Window handle.
* rkey - The IBT R_Key handle.
* Returns:
* IBT_SUCCESS
* IBT_INSUFF_RESOURCE
* IBT_CHAN_HDL_INVALID
* IBT_PD_HDL_INVALID
* Description:
* Allocate a memory window from the HCA.
*/
ibt_status_t
ibt_alloc_mw(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd, ibt_mw_flags_t flags,
ibt_mw_hdl_t *mw_hdl_p, ibt_rkey_t *rkey)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_alloc_mw(%p, %p, 0x%x)",
hca_hdl, pd, flags);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_alloc_mw(
IBTL_HCA2CIHCA(hca_hdl), pd, flags, mw_hdl_p, rkey);
/*
* XXX - We should be able to allocate state and have a IBTF Memory
* Window Handle. Memory Windows are meant to be rebound on the fly
* (using a post) to make them fast. It is expected that alloc memory
* window will be done in a relatively static manner. But, we don't have
* a good reason to have local MW state at this point, so we won't.
*/
if (status == IBT_SUCCESS) {
atomic_inc_32(&hca_hdl->ha_mw_cnt);
}
return (status);
}
/*
* Function:
* ibt_query_mw()
* Input:
* hca_hdl - HCA Handle.
* mw_hdl - The IBT Memory Window handle.
* Output:
* pd - Protection Domain Handle.
* rkey - The IBT R_Key handle.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MW_HDL_INVALID
* Description:
* Retrieves information about a specified memory region.
*/
ibt_status_t
ibt_query_mw(ibt_hca_hdl_t hca_hdl, ibt_mw_hdl_t mw_hdl,
ibt_mw_query_attr_t *mw_attr_p)
{
IBTF_DPRINTF_L3(ibtl_mem, "ibt_query_mw(%p, %p)", hca_hdl, mw_hdl);
return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_query_mw(
IBTL_HCA2CIHCA(hca_hdl), mw_hdl, mw_attr_p));
}
/*
* Function:
* ibt_free_mw()
* Input:
* hca_hdl - HCA Handle
* mw_hdl - The IBT Memory Window handle.
* Output:
* none.
* Returns:
* IBT_SUCCESS
* IBT_CHAN_HDL_INVALID
* IBT_MW_HDL_INVALID
* Description:
* De-allocate the Memory Window.
*/
ibt_status_t
ibt_free_mw(ibt_hca_hdl_t hca_hdl, ibt_mw_hdl_t mw_hdl)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_free_mw(%p, %p)", hca_hdl, mw_hdl);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_free_mw(
IBTL_HCA2CIHCA(hca_hdl), mw_hdl);
if (status == IBT_SUCCESS) {
atomic_dec_32(&hca_hdl->ha_mw_cnt);
}
return (status);
}
/*
* Function:
* ibt_map_mem_area()
* Input:
* hca_hdl HCA Handle
* va_attrs A pointer to an ibt_va_attr_t that describes the
* VA to be translated.
* paddr_list_len The number of entries in the 'paddr_list_p' array.
* Output:
* paddr_list_p Array of ibt_phys_buf_t (allocated by the caller),
* in which the physical buffers that map the virtual
* buffer are returned.
* num_paddr_p The actual number of ibt_phys_buf_t that were
* returned in the 'paddr_list_p' array.
* ma_hdl_p Memory Area Handle.
* Returns:
* IBT_SUCCESS
* Description:
* Translate a kernel virtual address range into HCA physical addresses.
* A set of physical addresses, that can be used with "Reserved L_Key",
* register physical, and "Fast Registration Work Request" operations
* is returned.
*/
ibt_status_t
ibt_map_mem_area(ibt_hca_hdl_t hca_hdl, ibt_va_attr_t *va_attrs,
uint_t paddr_list_len, ibt_reg_req_t *reg_req, ibt_ma_hdl_t *ma_hdl_p)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_map_mem_area(%p, %p, %d)",
hca_hdl, va_attrs, paddr_list_len);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_map_mem_area(
IBTL_HCA2CIHCA(hca_hdl), va_attrs,
NULL, /* IBTL_HCA2MODI_P(hca_hdl)->mi_reserved */
paddr_list_len, reg_req, ma_hdl_p);
/* Not doing reference counting, which adversely effects performance */
return (status);
}
/*
* Function:
* ibt_unmap_mem_area()
* Input:
* hca_hdl HCA Handle
* ma_hdl Memory Area Handle.
* Output:
* None.
* Returns:
* IBT_SUCCESS
* Description:
* Un pin physical pages pinned during an ibt_map_mem_area() call.
*/
ibt_status_t
ibt_unmap_mem_area(ibt_hca_hdl_t hca_hdl, ibt_ma_hdl_t ma_hdl)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_unmap_mem_area(%p, %p)",
hca_hdl, ma_hdl);
status = (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_unmap_mem_area(
IBTL_HCA2CIHCA(hca_hdl), ma_hdl));
/* Not doing reference counting, which adversely effects performance */
return (status);
}
/*
* Function:
* ibt_map_mem_iov()
* Input:
* hca_hdl HCA Handle
* iov_attr A pointer to an ibt_iov_attr_t that describes the
* virtual ranges to be translated.
* Output:
* wr A pointer to the work request where the output
* sgl (reserved_lkey, size, paddr) will be written.
* mi_hdl_p Memory IOV Handle.
* Returns:
* IBT_SUCCESS
* Description:
* Translate an array of virtual address ranges into HCA physical
* addresses, sizes, and reserved_lkey.
*/
ibt_status_t
ibt_map_mem_iov(ibt_hca_hdl_t hca_hdl, ibt_iov_attr_t *iov_attr,
ibt_all_wr_t *wr, ibt_mi_hdl_t *mi_hdl_p)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_map_mem_iov(%p, %p, %p)",
hca_hdl, iov_attr, wr);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_map_mem_iov(
IBTL_HCA2CIHCA(hca_hdl), iov_attr, wr, mi_hdl_p);
/* Not doing reference counting, which adversely effects performance */
return (status);
}
/*
* Function:
* ibt_unmap_mem_iov()
* Input:
* hca_hdl HCA Handle
* mi_hdl Memory IOV Handle.
* Output:
* None.
* Returns:
* IBT_SUCCESS
* Description:
* Un pin physical pages pinned during an ibt_map_mem_iov() call.
*/
ibt_status_t
ibt_unmap_mem_iov(ibt_hca_hdl_t hca_hdl, ibt_mi_hdl_t mi_hdl)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_unmap_mem_iov(%p, %p)",
hca_hdl, mi_hdl);
status = (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_unmap_mem_iov(
IBTL_HCA2CIHCA(hca_hdl), mi_hdl));
/* Not doing reference counting, which adversely effects performance */
return (status);
}
/*
* Function:
* ibt_alloc_io_mem()
* Input:
* hca_hdl HCA Handle
* size Number of bytes to allocate
* mr_flag Possible values: IBT_MR_SLEEP, IBT_MR_NONCOHERENT
* Output:
* kaddrp Contains pointer to the virtual address of the
* memory allocated by this call. (Set to NULL if
* memory allocation fails).
* mem_alloc_hdl Memory access handle returned by ibt_mem_alloc()
*
* Returns:
* IBT_SUCCESS
* IBT_INSUFF_RESOURCE
* IBT_HCA_HDL_INVALID
* IBT_MR_ACCESS_REQ_INVALID
* IBT_INVALID_PARAM
* Description:
* Wrapper for ddi_dma_mem_alloc()
*/
ibt_status_t
ibt_alloc_io_mem(ibt_hca_hdl_t hca_hdl, size_t size, ibt_mr_flags_t mr_flag,
caddr_t *kaddrp, ibt_mem_alloc_hdl_t *mem_alloc_hdl)
{
return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_alloc_io_mem(
IBTL_HCA2CIHCA(hca_hdl), size, mr_flag, kaddrp,
(ibc_mem_alloc_hdl_t *)mem_alloc_hdl));
}
/*
* Function:
* ibt_free_io_mem()
* Input:
* hca_hdl HCA Handle
* mem_alloc_hdl Memory access handle returned by ibt_mem_alloc()
* Output:
* None
*
* Returns:
* IBT_SUCCESS
* Description:
* Wrapper for ddi_dma_mem_free()
*/
ibt_status_t
ibt_free_io_mem(ibt_hca_hdl_t hca_hdl, ibt_mem_alloc_hdl_t mem_alloc_hdl)
{
return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_free_io_mem(
IBTL_HCA2CIHCA(hca_hdl), (ibc_mem_alloc_hdl_t)mem_alloc_hdl));
}
/*
* Function:
* ibt_alloc_lkey()
* Input:
* hca_hdl HCA Handle
* pd A protection domain handle.
* flags Access control.
* phys_buf_list_sz Requested size of Physical Buffer List (PBL)
* resources to be allocated.
* Output:
* mr_hdl_p The returned IBT memory region handle.
* mem_desc_p Returned memory descriptor.
* Returns:
* IBT_SUCCESS
* Description:
* Allocates physical buffer list resources for use in memory
* registrations.
*/
ibt_status_t
ibt_alloc_lkey(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd, ibt_lkey_flags_t flags,
uint_t phys_buf_list_sz, ibt_mr_hdl_t *mr_hdl_p,
ibt_pmr_desc_t *mem_desc_p)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_alloc_lkey(%p, %p, 0x%X, %d)",
hca_hdl, pd, flags, phys_buf_list_sz);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_alloc_lkey(
IBTL_HCA2CIHCA(hca_hdl), pd, flags, phys_buf_list_sz, mr_hdl_p,
mem_desc_p);
if (status == IBT_SUCCESS) {
atomic_inc_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_register_phys_mr()
* Input:
* hca_hdl HCA Handle
* pd A protection domain handle.
* mem_pattr Requested memory region physical attributes.
* Output:
* mr_hdl_p The returned IBT memory region handle.
* mem_desc_p Returned memory descriptor.
* Returns:
* IBT_SUCCESS
* Description:
* Prepares a physically addressed memory region for use by a HCA.
*/
ibt_status_t
ibt_register_phys_mr(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
ibt_pmr_attr_t *mem_pattr, ibt_mr_hdl_t *mr_hdl_p,
ibt_pmr_desc_t *mem_desc_p)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_register_phys_mr(%p, %p, %p)",
hca_hdl, pd, mem_pattr);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_register_physical_mr(
IBTL_HCA2CIHCA(hca_hdl), pd, mem_pattr,
NULL, /* IBTL_HCA2MODI_P(hca_hdl)->mi_reserved */
mr_hdl_p, mem_desc_p);
if (status == IBT_SUCCESS) {
atomic_inc_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Function:
* ibt_reregister_phys_mr()
* Input:
* hca_hdl HCA Handle
* mr_hdl The IBT memory region handle.
* pd A protection domain handle.
* mem_pattr Requested memory region physical attributes.
* Output:
* mr_hdl_p The returned IBT memory region handle.
* mem_desc_p Returned memory descriptor.
* Returns:
* IBT_SUCCESS
* Description:
* Prepares a physically addressed memory region for use by a HCA.
*/
ibt_status_t
ibt_reregister_phys_mr(ibt_hca_hdl_t hca_hdl, ibt_mr_hdl_t mr_hdl,
ibt_pd_hdl_t pd, ibt_pmr_attr_t *mem_pattr, ibt_mr_hdl_t *mr_hdl_p,
ibt_pmr_desc_t *mem_desc_p)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_reregister_phys_mr(%p, %p, %p, %p)",
hca_hdl, mr_hdl, pd, mem_pattr);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_reregister_physical_mr(
IBTL_HCA2CIHCA(hca_hdl), mr_hdl, pd, mem_pattr,
NULL, /* IBTL_HCA2MODI_P(hca_hdl)->mi_reserved */
mr_hdl_p, mem_desc_p);
if (!(status == IBT_SUCCESS || status == IBT_MR_IN_USE ||
status == IBT_HCA_HDL_INVALID || status == IBT_MR_HDL_INVALID)) {
IBTF_DPRINTF_L2(ibtl_mem, "ibt_reregister_phys_mr: "
"Re-registration Mem Failed: %d", status);
/* we lost one memory region resource */
atomic_dec_32(&hca_hdl->ha_mr_cnt);
}
return (status);
}
/*
* Fast Memory Registration (FMR).
*
* ibt_create_fmr_pool
* Not fast-path.
* ibt_create_fmr_pool() verifies that the HCA supports FMR and allocates
* and initializes an "FMR pool". This pool contains state specific to
* this registration, including the watermark setting to determine when
* to sync, and the total number of FMR regions available within this pool.
*
*/
ibt_status_t
ibt_create_fmr_pool(ibt_hca_hdl_t hca_hdl, ibt_pd_hdl_t pd,
ibt_fmr_pool_attr_t *fmr_params, ibt_fmr_pool_hdl_t *fmr_pool_p)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_create_fmr_pool(%p, %p, %p)",
hca_hdl, pd, fmr_params);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_create_fmr_pool(
IBTL_HCA2CIHCA(hca_hdl), pd, fmr_params, fmr_pool_p);
if (status != IBT_SUCCESS) {
*fmr_pool_p = NULL;
return (status);
}
/* Update the FMR resource count */
atomic_inc_32(&hca_hdl->ha_fmr_pool_cnt);
return (status);
}
/*
* ibt_destroy_fmr_pool
* ibt_destroy_fmr_pool() deallocates all of the FMR regions in a specific
* pool. All state and information regarding the pool are destroyed and
* returned as free space once again. No more use of FMR regions in this
* pool are possible without a subsequent call to ibt_create_fmr_pool().
*/
ibt_status_t
ibt_destroy_fmr_pool(ibt_hca_hdl_t hca_hdl, ibt_fmr_pool_hdl_t fmr_pool)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_destroy_fmr_pool(%p, %p)",
hca_hdl, fmr_pool);
status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_destroy_fmr_pool(
IBTL_HCA2CIHCA(hca_hdl), fmr_pool);
if (status != IBT_SUCCESS) {
IBTF_DPRINTF_L2(ibtl_mem, "ibt_destroy_fmr_pool: "
"CI FMR Pool destroy failed (%d)", status);
return (status);
}
atomic_dec_32(&hca_hdl->ha_fmr_pool_cnt);
return (status);
}
/*
* ibt_flush_fmr_pool
* ibt_flush_fmr_pool forces a flush to occur. At the client's request,
* any unmapped FMR regions (See 'ibt_deregister_mr())') are returned to
* a free state. This function allows for an asynchronous cleanup of
* formerly used FMR regions. Sync operation is also performed internally
* by HCA driver, when 'watermark' settings for the number of free FMR
* regions left in the "pool" is reached.
*/
ibt_status_t
ibt_flush_fmr_pool(ibt_hca_hdl_t hca_hdl, ibt_fmr_pool_hdl_t fmr_pool)
{
IBTF_DPRINTF_L3(ibtl_mem, "ibt_flush_fmr_pool(%p, %p)",
hca_hdl, fmr_pool);
return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_flush_fmr_pool(
IBTL_HCA2CIHCA(hca_hdl), fmr_pool));
}
/*
* ibt_register_physical_fmr
* ibt_register_physical_fmr() assigns a "free" entry from the FMR Pool.
* It first consults the "FMR cache" to see if this is a duplicate memory
* registration to something already in use. If not, then a free entry
* in the "pool" is marked used.
*/
ibt_status_t
ibt_register_physical_fmr(ibt_hca_hdl_t hca_hdl, ibt_fmr_pool_hdl_t fmr_pool,
ibt_pmr_attr_t *mem_pattr, ibt_mr_hdl_t *mr_hdl_p,
ibt_pmr_desc_t *mem_desc_p)
{
IBTF_DPRINTF_L3(ibtl_mem, "ibt_register_physical_fmr(%p, %p, %p, %p)",
hca_hdl, fmr_pool, mem_pattr, mem_desc_p);
return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_register_physical_fmr(
IBTL_HCA2CIHCA(hca_hdl), fmr_pool, mem_pattr,
NULL, /* IBTL_HCA2MODI_P(hca_hdl)->mi_reserved */
mr_hdl_p, mem_desc_p));
}
/*
* ibt_deregister_fmr
* The ibt_deregister_fmr un-maps the resources reserved from the FMR
* pool by ibt_register_physical_fmr(). The ibt_deregister_fmr() will
* mark the region as free in the FMR Pool.
*/
ibt_status_t
ibt_deregister_fmr(ibt_hca_hdl_t hca, ibt_mr_hdl_t mr_hdl)
{
IBTF_DPRINTF_L3(ibtl_mem, "ibt_deregister_fmr(%p, %p)", hca, mr_hdl);
return (IBTL_HCA2CIHCAOPS_P(hca)->ibc_deregister_fmr(
IBTL_HCA2CIHCA(hca), mr_hdl));
}
/*
* ibt_register_dma_mr
*/
ibt_status_t
ibt_register_dma_mr(ibt_hca_hdl_t hca, ibt_pd_hdl_t pd,
ibt_dmr_attr_t *mem_attr, ibt_mr_hdl_t *mr_hdl_p, ibt_mr_desc_t *mem_desc)
{
ibt_status_t status;
IBTF_DPRINTF_L3(ibtl_mem, "ibt_register_dma_mr(%p, %p, %p)",
hca, pd, mem_attr);
status = IBTL_HCA2CIHCAOPS_P(hca)->ibc_register_dma_mr(
IBTL_HCA2CIHCA(hca), pd, mem_attr, NULL, mr_hdl_p, mem_desc);
if (status == IBT_SUCCESS) {
atomic_inc_32(&hca->ha_mr_cnt);
}
return (status);
}
|