winverbs: make PD derive from IWVOverlapped
[mirror/winof/.git] / core / winverbs / user / wv_pd.h
1 /*\r
2  * Copyright (c) 2008 Intel Corporation. All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  */\r
29 \r
30 #pragma once\r
31 \r
32 #ifndef _WV_PD_H_\r
33 #define _WV_PD_H_\r
34 \r
35 #include <rdma\winverbs.h>\r
36 #include "wv_device.h"\r
37 #include "wv_ioctl.h"\r
38 #include "wv_base.h"\r
39 \r
40 class CWVProtectionDomain : IWVProtectionDomain, public CWVBase\r
41 {\r
42 public:\r
43         // IUnknown methods\r
44         STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
45         STDMETHODIMP_(ULONG) AddRef();\r
46         STDMETHODIMP_(ULONG) Release();\r
47 \r
48         // IWVOverlapped methods\r
49         STDMETHODIMP CancelOverlappedRequests();\r
50         STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
51                                                                          DWORD *pNumberOfBytesTransferred, BOOL bWait);\r
52 \r
53         // IWVProtectionDomain methods\r
54         STDMETHODIMP CreateSharedReceiveQueue(SIZE_T MaxWr, SIZE_T MaxSge, SIZE_T SrqLimit,\r
55                                                                                   IWVSharedReceiveQueue** ppSrq);\r
56         STDMETHODIMP CreateConnectQueuePair(WV_QP_CREATE* pAttributes,\r
57                                                                                 IWVConnectQueuePair** ppQp);\r
58         STDMETHODIMP CreateDatagramQueuePair(WV_QP_CREATE* pAttributes,\r
59                                                                                  IWVDatagramQueuePair** ppQp);\r
60         STDMETHODIMP RegisterMemory(const VOID* pBuffer, SIZE_T BufferLength,\r
61                                                                 DWORD AccessFlags, OVERLAPPED* pOverlapped,\r
62                                                                 WV_MEMORY_KEYS *pKeys);\r
63         STDMETHODIMP DeregisterMemory(UINT32 Lkey, OVERLAPPED* pOverlapped);\r
64         STDMETHODIMP AllocateMemoryWindow(IWVMemoryWindow** ppMw);\r
65         STDMETHODIMP CreateAddressHandle(WV_ADDRESS_VECTOR* pAddress,\r
66                                                                          IWVAddressHandle** ppAh, ULONG_PTR *pAhKey);\r
67 \r
68         CWVProtectionDomain(CWVDevice *pDevice);\r
69         ~CWVProtectionDomain();\r
70         void Delete() {delete this;}\r
71         static STDMETHODIMP\r
72         CreateInstance(CWVDevice *pDevice, IWVProtectionDomain** ppPd)\r
73         {\r
74                 HRESULT hr;\r
75                 CWVProtectionDomain *pd;\r
76 \r
77                 pd = new CWVProtectionDomain(pDevice);\r
78                 if (pd == NULL) {\r
79                         hr = WV_NO_MEMORY;\r
80                         goto err1;\r
81                 }\r
82 \r
83                 hr = pd->Init();\r
84                 if (FAILED(hr)) {\r
85                         goto err2;\r
86                 }\r
87 \r
88                 hr = pd->Allocate();\r
89                 if (FAILED(hr)) {\r
90                         goto err2;\r
91                 }\r
92 \r
93                 *ppPd = pd;\r
94                 return WV_SUCCESS;\r
95 \r
96         err2:\r
97                 pd->Release();\r
98         err1:\r
99                 *ppPd = NULL;\r
100                 return hr;\r
101         }\r
102 \r
103         CWVDevice               *m_pDevice;\r
104         uvp_interface_t *m_pVerbs;\r
105         ib_pd_handle_t  m_hVerbsPd;\r
106 \r
107 protected:\r
108         STDMETHODIMP Allocate();\r
109 };\r
110 \r
111 \r
112 class CWVMemoryWindow : IWVMemoryWindow, public CWVBase\r
113 {\r
114 public:\r
115         // IUnknown methods\r
116         STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
117         STDMETHODIMP_(ULONG) AddRef();\r
118         STDMETHODIMP_(ULONG) Release();\r
119 \r
120         CWVMemoryWindow(CWVProtectionDomain *pPd);\r
121         ~CWVMemoryWindow();\r
122         void Delete() {delete this;}\r
123         static STDMETHODIMP\r
124         CreateInstance(CWVProtectionDomain *pPd, IWVMemoryWindow** ppMw)\r
125         {\r
126                 HRESULT hr;\r
127                 CWVMemoryWindow *mw;\r
128 \r
129                 mw = new CWVMemoryWindow(pPd);\r
130                 if (mw == NULL) {\r
131                         hr = WV_NO_MEMORY;\r
132                         goto err1;\r
133                 }\r
134 \r
135                 hr = mw->Init();\r
136                 if (FAILED(hr)) {\r
137                         goto err2;\r
138                 }\r
139 \r
140                 hr = mw->Allocate();\r
141                 if (FAILED(hr)) {\r
142                         goto err2;\r
143                 }\r
144 \r
145                 *ppMw = mw;\r
146                 return WV_SUCCESS;\r
147 \r
148         err2:\r
149                 mw->Release();\r
150         err1:\r
151                 *ppMw = NULL;\r
152                 return hr;\r
153         }\r
154 \r
155         CWVProtectionDomain     *m_pPd;\r
156         uvp_interface_t         *m_pVerbs;\r
157         ib_mw_handle_t          m_hVerbsMw;\r
158         NET32                           m_Rkey;\r
159 \r
160 protected:\r
161         STDMETHODIMP Allocate();\r
162 };\r
163 \r
164 \r
165 class CWVAddressHandle : IWVAddressHandle, public CWVBase\r
166 {\r
167 public:\r
168         // IUnknown methods\r
169         STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
170         STDMETHODIMP_(ULONG) AddRef();\r
171         STDMETHODIMP_(ULONG) Release();\r
172 \r
173         CWVAddressHandle(CWVProtectionDomain *pPd);\r
174         ~CWVAddressHandle();\r
175         void Delete() {delete this;}\r
176         static STDMETHODIMP\r
177         CreateInstance(CWVProtectionDomain *pPd, WV_ADDRESS_VECTOR* pAddress,\r
178                                    IWVAddressHandle** ppAh, ULONG_PTR* pAhKey)\r
179         {\r
180                 HRESULT hr;\r
181                 CWVAddressHandle *ah;\r
182 \r
183                 ah = new CWVAddressHandle(pPd);\r
184                 if (ah == NULL) {\r
185                         hr = WV_NO_MEMORY;\r
186                         goto err1;\r
187                 }\r
188 \r
189                 hr = ah->Init();\r
190                 if (FAILED(hr)) {\r
191                         goto err2;\r
192                 }\r
193 \r
194                 hr = ah->Create(pAddress);\r
195                 if (FAILED(hr)) {\r
196                         goto err2;\r
197                 }\r
198 \r
199                 *ppAh = ah;\r
200                 *pAhKey = (ULONG_PTR) ah->m_hVerbsAh;\r
201                 return WV_SUCCESS;\r
202 \r
203         err2:\r
204                 ah->Release();\r
205         err1:\r
206                 *ppAh = NULL;\r
207                 return hr;\r
208         }\r
209 \r
210         CWVProtectionDomain     *m_pPd;\r
211         uvp_interface_t         *m_pVerbs;\r
212         ib_av_handle_t          m_hVerbsAh;\r
213 \r
214 protected:\r
215         STDMETHODIMP Create(WV_ADDRESS_VECTOR* pAddress);\r
216         STDMETHODIMP ConvertAv(ib_av_attr_t *pVerbsAv, WV_ADDRESS_VECTOR *pAv);\r
217 };\r
218 \r
219 #endif // _WV_PD_H_