@@ -36,6 +36,98 @@ int xsc_query_port(struct ibv_context *context, u8 port,
36
36
return ibv_cmd_query_port (context , port , attr , & cmd , sizeof (cmd ));
37
37
}
38
38
39
+ struct ibv_pd * xsc_alloc_pd (struct ibv_context * context )
40
+ {
41
+ struct ibv_alloc_pd cmd ;
42
+ struct xsc_alloc_pd_resp resp ;
43
+ struct xsc_pd * pd ;
44
+
45
+ pd = calloc (1 , sizeof (* pd ));
46
+ if (!pd )
47
+ return NULL ;
48
+
49
+ if (ibv_cmd_alloc_pd (context , & pd -> ibv_pd , & cmd , sizeof (cmd ),
50
+ & resp .ibv_resp , sizeof (resp ))) {
51
+ free (pd );
52
+ return NULL ;
53
+ }
54
+
55
+ atomic_init (& pd -> refcount , 1 );
56
+ pd -> pdn = resp .pdn ;
57
+ xsc_dbg (to_xctx (context )-> dbg_fp , XSC_DBG_PD , "pd number:%u\n" ,
58
+ pd -> pdn );
59
+
60
+ return & pd -> ibv_pd ;
61
+ }
62
+
63
+ int xsc_free_pd (struct ibv_pd * pd )
64
+ {
65
+ int ret ;
66
+ struct xsc_pd * xpd = to_xpd (pd );
67
+
68
+ if (atomic_load (& xpd -> refcount ) > 1 )
69
+ return EBUSY ;
70
+
71
+ ret = ibv_cmd_dealloc_pd (pd );
72
+ if (ret )
73
+ return ret ;
74
+
75
+ xsc_dbg (to_xctx (pd -> context )-> dbg_fp , XSC_DBG_PD , "dealloc pd\n" );
76
+ free (xpd );
77
+
78
+ return 0 ;
79
+ }
80
+
81
+ struct ibv_mr * xsc_reg_mr (struct ibv_pd * pd , void * addr , size_t length ,
82
+ u64 hca_va , int acc )
83
+ {
84
+ struct xsc_mr * mr ;
85
+ struct ibv_reg_mr cmd ;
86
+ int ret ;
87
+ enum ibv_access_flags access = (enum ibv_access_flags )acc ;
88
+ struct ib_uverbs_reg_mr_resp resp ;
89
+
90
+ mr = calloc (1 , sizeof (* mr ));
91
+ if (!mr )
92
+ return NULL ;
93
+
94
+ ret = ibv_cmd_reg_mr (pd , addr , length , hca_va , access , & mr -> vmr , & cmd ,
95
+ sizeof (cmd ), & resp , sizeof (resp ));
96
+ if (ret ) {
97
+ xsc_free_buf (& mr -> buf );
98
+ free (mr );
99
+ return NULL ;
100
+ }
101
+ mr -> alloc_flags = acc ;
102
+
103
+ xsc_dbg (to_xctx (pd -> context )-> dbg_fp , XSC_DBG_MR , "lkey:%u, rkey:%u\n" ,
104
+ mr -> vmr .ibv_mr .lkey , mr -> vmr .ibv_mr .rkey );
105
+
106
+ return & mr -> vmr .ibv_mr ;
107
+ }
108
+
109
+ void xsc_free_buf (struct xsc_buf * buf )
110
+ {
111
+ ibv_dofork_range (buf -> buf , buf -> length );
112
+ free (buf -> buf );
113
+ }
114
+
115
+ int xsc_dereg_mr (struct verbs_mr * vmr )
116
+ {
117
+ int ret ;
118
+
119
+ if (vmr -> mr_type == IBV_MR_TYPE_NULL_MR )
120
+ goto free ;
121
+
122
+ ret = ibv_cmd_dereg_mr (vmr );
123
+ if (ret )
124
+ return ret ;
125
+
126
+ free :
127
+ free (vmr );
128
+ return 0 ;
129
+ }
130
+
39
131
static void xsc_set_fw_version (struct ibv_device_attr * attr ,
40
132
union xsc_ib_fw_ver * fw_ver )
41
133
{
0 commit comments