netdirect: add winverbs ND provider
[mirror/winof/.git] / ulp / netdirect / user / nd_adapter.h
1 /*\r
2  * Copyright (c) 2009 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 AND\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 _ND_ADAPTER_H_\r
33 #define _ND_ADAPTER_H_\r
34 \r
35 #include <ndspi.h>\r
36 #include "nd_base.h"\r
37 #include "nd_provider.h"\r
38 #include <dlist.h>\r
39 \r
40 \r
41 typedef struct _ND_MR\r
42 {\r
43         DLIST_ENTRY                     Entry;\r
44         WV_MEMORY_KEYS          Keys;\r
45         void                            *Context;\r
46 \r
47 }       ND_MR;\r
48 \r
49 \r
50 class CNDAdapter : public INDAdapter, public CNDBase\r
51 {\r
52 public:\r
53         // IUnknown methods\r
54         STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
55         STDMETHODIMP_(ULONG) AddRef();\r
56         STDMETHODIMP_(ULONG) Release();\r
57 \r
58         // INDOverlapped methods\r
59         STDMETHODIMP CancelOverlappedRequests();\r
60         STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
61                                                                          SIZE_T *pNumberOfBytesTransferred, BOOL bWait);\r
62 \r
63         // INDDevice methods\r
64         STDMETHODIMP_(HANDLE) GetFileHandle();\r
65         STDMETHODIMP Query(DWORD VersionRequested, ND_ADAPTER_INFO* pInfo,\r
66                                            SIZE_T* pBufferSize);\r
67         STDMETHODIMP Control(DWORD IoControlCode,\r
68                                                  const void* pInBuffer, SIZE_T InBufferSize,\r
69                                                  void* pOutBuffer, SIZE_T OutBufferSize,\r
70                                                  SIZE_T* pBytesReturned, OVERLAPPED* pOverlapped);\r
71         STDMETHODIMP CreateCompletionQueue(SIZE_T nEntries, INDCompletionQueue** ppCq);\r
72         STDMETHODIMP RegisterMemory(const void* pBuffer, SIZE_T BufferSize,\r
73                                                                 OVERLAPPED* pOverlapped, ND_MR_HANDLE* phMr);\r
74         STDMETHODIMP DeregisterMemory(ND_MR_HANDLE hMr, OVERLAPPED* pOverlapped);\r
75         STDMETHODIMP CreateMemoryWindow(ND_RESULT* pInvalidateResult,\r
76                                                                         INDMemoryWindow** ppMw);\r
77         STDMETHODIMP CreateConnector(INDConnector** ppConnector);\r
78         STDMETHODIMP Listen(SIZE_T Backlog, INT Protocol, USHORT Port,\r
79                                                 USHORT* pAssignedPort, INDListen** ppListen);\r
80 \r
81         CNDAdapter(CNDProvider *pProvider);\r
82         ~CNDAdapter();\r
83         void Delete() {delete this;}\r
84         static STDMETHODIMP\r
85         CreateInstance(CNDProvider *pProvider, const struct sockaddr *pAddress,\r
86                                    SIZE_T AddressLength, INDAdapter** ppAdapter)\r
87         {\r
88                 HRESULT hr;\r
89                 CNDAdapter *adapter;\r
90 \r
91                 adapter = new CNDAdapter(pProvider);\r
92                 if (adapter == NULL) {\r
93                         hr = ND_NO_MEMORY;\r
94                         goto err1;\r
95                 }\r
96 \r
97                 hr = adapter->Init(pAddress, AddressLength);\r
98                 if (FAILED(hr)) {\r
99                         goto err2;\r
100                 }\r
101 \r
102                 *ppAdapter = adapter;\r
103                 return ND_SUCCESS;\r
104 \r
105         err2:\r
106                 adapter->Release();\r
107         err1:\r
108                 *ppAdapter = NULL;\r
109                 return hr;\r
110         }\r
111 \r
112         IWVProvider                     *m_pWvProvider;\r
113         IWVDevice                       *m_pWvDevice;\r
114         IWVProtectionDomain     *m_pWvPd;\r
115         SOCKADDR_STORAGE        m_Address;\r
116         WV_DEVICE_ADDRESS       m_DevAddress;\r
117 \r
118 protected:\r
119         CNDProvider                     *m_pProvider;\r
120         DLIST_ENTRY                     m_MrList;\r
121         CRITICAL_SECTION        m_Lock;\r
122 \r
123         STDMETHODIMP            Init(const struct sockaddr *pAddress, SIZE_T AddressLength);\r
124         void                            CleanupMr(ND_MR *pMr);\r
125 };\r
126 \r
127 #endif // _ND_ADAPTER_H_\r