netdirect: add winverbs ND provider
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 10 Jul 2009 17:56:19 +0000 (17:56 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 10 Jul 2009 17:56:19 +0000 (17:56 +0000)
Initial implementation.  Compiles, but otherwise untested.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2283 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

24 files changed:
ulp/netdirect/dirs [new file with mode: 0644]
ulp/netdirect/user/SOURCES [new file with mode: 0644]
ulp/netdirect/user/makefile [new file with mode: 0644]
ulp/netdirect/user/nd_adapter.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_adapter.h [new file with mode: 0644]
ulp/netdirect/user/nd_base.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_base.h [new file with mode: 0644]
ulp/netdirect/user/nd_connect.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_connect.h [new file with mode: 0644]
ulp/netdirect/user/nd_cq.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_cq.h [new file with mode: 0644]
ulp/netdirect/user/nd_ep.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_ep.h [new file with mode: 0644]
ulp/netdirect/user/nd_export.def [new file with mode: 0644]
ulp/netdirect/user/nd_exports.src [new file with mode: 0644]
ulp/netdirect/user/nd_listen.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_listen.h [new file with mode: 0644]
ulp/netdirect/user/nd_main.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_main.h [new file with mode: 0644]
ulp/netdirect/user/nd_mw.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_mw.h [new file with mode: 0644]
ulp/netdirect/user/nd_provider.cpp [new file with mode: 0644]
ulp/netdirect/user/nd_provider.h [new file with mode: 0644]
ulp/netdirect/user/netdirect.rc [new file with mode: 0644]

diff --git a/ulp/netdirect/dirs b/ulp/netdirect/dirs
new file mode 100644 (file)
index 0000000..0e61a79
--- /dev/null
@@ -0,0 +1 @@
+DIRS = user\r
diff --git a/ulp/netdirect/user/SOURCES b/ulp/netdirect/user/SOURCES
new file mode 100644 (file)
index 0000000..e58168a
--- /dev/null
@@ -0,0 +1,42 @@
+!if $(FREEBUILD)\r
+TARGETNAME = wvndprov\r
+!else\r
+TARGETNAME = wvndprovd\r
+!endif\r
+\r
+TARGETPATH = ..\..\..\bin\user\obj$(BUILD_ALT_DIR)\r
+TARGETTYPE = DYNLINK\r
+\r
+!if $(_NT_TOOLS_VERSION) == 0x700\r
+DLLDEF = $O\nd_exports.def\r
+!else\r
+DLLDEF = $(OBJ_PATH)\$O\nd_exports.def\r
+!endif\r
+\r
+DLLENTRY = DllMain\r
+USE_MSVCRT = 1\r
+\r
+SOURCES =                      \\r
+       nd_main.cpp             \\r
+       nd_base.cpp             \\r
+       nd_provider.cpp \\r
+       nd_adapter.cpp  \\r
+       nd_listen.cpp   \\r
+       nd_connect.cpp  \\r
+       nd_ep.cpp               \\r
+       nd_mw.cpp               \\r
+       nd_cq.cpp\r
+\r
+INCLUDES = ..\..\..\inc;..\..\..\inc\user;\\r
+                  ..\..\..\inc\user\linux;$(ND_SDK_PATH)\include;\r
+\r
+TARGETLIBS =                                           \\r
+       $(SDK_LIB_PATH)\kernel32.lib    \\r
+       $(SDK_LIB_PATH)\uuid.lib                \\r
+       $(SDK_LIB_PATH)\ws2_32.lib              \\r
+       $(SDK_LIB_PATH)\iphlpapi.lib    \\r
+!if $(FREEBUILD)\r
+       $(TARGETPATH)\*\winverbs.lib\r
+!else\r
+       $(TARGETPATH)\*\winverbsd.lib\r
+!endif\r
diff --git a/ulp/netdirect/user/makefile b/ulp/netdirect/user/makefile
new file mode 100644 (file)
index 0000000..c43884f
--- /dev/null
@@ -0,0 +1,14 @@
+#\r
+# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
+# file to this component.  This file merely indirects to the real make file\r
+# that is shared by all the driver components of the OpenIB Windows project.\r
+#\r
+\r
+!IFNDEF ND_SDK_PATH\r
+!MESSAGE Skipping wvndprov.dll build: ND_SD_PATH not set.\r
+DDK_BLOCK_ON_X86   = 1\r
+DDK_BLOCK_ON_AMD64 = 1\r
+DDK_BLOCK_ON_IA64  = 1\r
+!ENDIF\r
+\r
+!INCLUDE ..\..\..\inc\openib.def\r
diff --git a/ulp/netdirect/user/nd_adapter.cpp b/ulp/netdirect/user/nd_adapter.cpp
new file mode 100644 (file)
index 0000000..fc9f45d
--- /dev/null
@@ -0,0 +1,301 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_adapter.h"\r
+#include "nd_cq.h"\r
+#include "nd_listen.h"\r
+#include "nd_connect.h"\r
+#include "nd_mw.h"\r
+#include "nd_ep.h"\r
+\r
+\r
+CNDAdapter::CNDAdapter(CNDProvider *pProvider)\r
+{\r
+       pProvider->AddRef();\r
+       m_pProvider = pProvider;\r
+       m_pWvProvider = NULL;\r
+       m_pWvDevice = NULL;\r
+       m_pWvPd = NULL;\r
+       DListInit(&m_MrList);\r
+       InitializeCriticalSection(&m_Lock);\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+Init(const struct sockaddr *pAddress, SIZE_T AddressLength)\r
+{\r
+       HRESULT hr;\r
+\r
+       hr = WvGetObject(IID_IWVProvider, (LPVOID *) &m_pWvProvider);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       hr = m_pWvProvider->TranslateAddress(pAddress, &m_DevAddress);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       hr = m_pWvProvider->OpenDevice(m_DevAddress.DeviceGuid, &m_pWvDevice);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       hr = m_pWvDevice->AllocateProtectionDomain(&m_pWvPd);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       RtlCopyMemory(&m_Address, pAddress, AddressLength);\r
+       return ND_SUCCESS;\r
+}\r
+\r
+CNDAdapter::~CNDAdapter(void)\r
+{\r
+       ND_MR   *mr;\r
+\r
+       while (!DListEmpty(&m_MrList)) {\r
+               mr = CONTAINING_RECORD(m_MrList.Next, ND_MR, Entry);\r
+               DListRemove(&mr->Entry);\r
+               m_pWvPd->DeregisterMemory(mr->Keys.Lkey, NULL);\r
+               delete mr;\r
+       }\r
+\r
+       if (m_pWvPd != NULL) {\r
+               m_pWvPd->Release();\r
+       }\r
+       if (m_pWvDevice != NULL) {\r
+               m_pWvDevice->Release();\r
+       }\r
+       if (m_pWvProvider != NULL) {\r
+               m_pWvProvider->Release();\r
+       }\r
+       m_pProvider->Release();\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_INDAdapter) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDAdapter::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDAdapter::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+CancelOverlappedRequests(void)\r
+{\r
+       m_pWvPd->CancelOverlappedRequests();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                       SIZE_T *pNumberOfBytesTransferred, BOOL bWait)\r
+{\r
+       DLIST_ENTRY *entry;\r
+       ND_MR *mr;\r
+       HRESULT hr;\r
+\r
+       ::GetOverlappedResult(GetFileHandle(), pOverlapped,\r
+                                                 (LPDWORD) pNumberOfBytesTransferred, bWait);\r
+       hr = (HRESULT) pOverlapped->Internal;\r
+\r
+       if (FAILED(hr)) {\r
+               EnterCriticalSection(&m_Lock);\r
+               for (entry = m_MrList.Next; entry != &m_MrList; entry = entry->Next) {\r
+                       mr = CONTAINING_RECORD(entry, ND_MR, Entry);\r
+                       if (mr->Context == pOverlapped) {\r
+                               DListRemove(entry);\r
+                               delete mr;\r
+                               break;\r
+                       }\r
+               }\r
+               LeaveCriticalSection(&m_Lock);\r
+       }\r
+\r
+       return hr;\r
+}\r
+\r
+STDMETHODIMP_(HANDLE) CNDAdapter::\r
+GetFileHandle(void)\r
+{\r
+       return m_pWvProvider->GetFileHandle();\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+Query(DWORD VersionRequested, ND_ADAPTER_INFO* pInfo, SIZE_T* pBufferSize)\r
+{\r
+       WV_DEVICE_ATTRIBUTES attr;\r
+       HRESULT hr;\r
+\r
+       if (VersionRequested != 1) {\r
+               return ND_NOT_SUPPORTED;\r
+       }\r
+\r
+       if (*pBufferSize < sizeof(ND_ADAPTER_INFO)) {\r
+               hr = ND_BUFFER_OVERFLOW;\r
+               goto out;\r
+       }\r
+\r
+       hr = m_pWvDevice->Query(&attr);\r
+       if (FAILED(hr)) {\r
+               goto out;\r
+       }\r
+\r
+       pInfo->VendorId                                 = attr.VendorId;\r
+       pInfo->DeviceId                                 = attr.VendorPartId;\r
+       pInfo->MaxInboundSge                    = min(attr.MaxSge, ND_MAX_SGE);\r
+       pInfo->MaxInboundRequests               = attr.MaxQpWr;\r
+       pInfo->MaxInboundLength                 = 1 << 31;\r
+       pInfo->MaxOutboundSge                   = min(attr.MaxSge, ND_MAX_SGE);\r
+       pInfo->MaxOutboundRequests              = attr.MaxQpWr;\r
+       pInfo->MaxOutboundLength                = 1 << 31;\r
+       pInfo->MaxInlineData                    = attr.MaxInlineSend;\r
+       pInfo->MaxInboundReadLimit              = attr.MaxQpResponderResources;\r
+       pInfo->MaxOutboundReadLimit             = attr.MaxQpInitiatorDepth;\r
+       pInfo->MaxCqEntries                             = attr.MaxCqEntries;\r
+       pInfo->MaxRegistrationSize              = attr.MaxMrSize;\r
+       pInfo->MaxWindowSize                    = attr.MaxMrSize;\r
+       pInfo->LargeRequestThreshold    = 0;\r
+       pInfo->MaxCallerData                    = ND_PRIVATE_DATA_SIZE;\r
+       pInfo->MaxCalleeData                    = ND_PRIVATE_DATA_SIZE;\r
+\r
+out:\r
+       *pBufferSize = sizeof(ND_ADAPTER_INFO);\r
+       return hr;\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+Control(DWORD IoControlCode, const void* pInBuffer, SIZE_T InBufferSize,\r
+               void* pOutBuffer, SIZE_T OutBufferSize, SIZE_T* pBytesReturned,\r
+               OVERLAPPED* pOverlapped)\r
+{\r
+       return DeviceIoControl(GetFileHandle(), IoControlCode,\r
+                                                  (LPVOID) pInBuffer, (DWORD) InBufferSize,\r
+                                                  pOutBuffer, (DWORD) OutBufferSize,\r
+                                                  (LPDWORD) pBytesReturned, pOverlapped) ?\r
+                                                  ND_SUCCESS : HRESULT_FROM_WIN32(GetLastError());\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+CreateCompletionQueue(SIZE_T nEntries, INDCompletionQueue** ppCq)\r
+{\r
+       return CNDCompletionQueue::CreateInstance(this, nEntries, ppCq);\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+RegisterMemory(const void* pBuffer, SIZE_T BufferSize,\r
+                          OVERLAPPED* pOverlapped, ND_MR_HANDLE* phMr)\r
+{\r
+       ND_MR *mr;\r
+       HRESULT hr;\r
+       DWORD flags;\r
+\r
+       mr = new ND_MR;\r
+       if (mr == NULL) {\r
+               return ND_NO_MEMORY;\r
+       }\r
+\r
+       mr->Context = pOverlapped;\r
+       EnterCriticalSection(&m_Lock);\r
+       DListInsertHead(&mr->Entry, &m_MrList);\r
+       LeaveCriticalSection(&m_Lock);\r
+\r
+       // TODO: restrict access when MWs are implemented\r
+       flags = WV_ACCESS_REMOTE_READ | WV_ACCESS_REMOTE_WRITE |\r
+                       WV_ACCESS_REMOTE_ATOMIC | WV_ACCESS_LOCAL_WRITE | WV_ACCESS_MW_BIND;\r
+       hr = m_pWvPd->RegisterMemory(pBuffer, BufferSize, flags, pOverlapped, &mr->Keys);\r
+       if (FAILED(hr)) {\r
+               CleanupMr(mr);\r
+       } else {\r
+               *phMr = (ND_MR_HANDLE) mr;\r
+       }\r
+\r
+       return hr;\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+DeregisterMemory(ND_MR_HANDLE hMr, OVERLAPPED* pOverlapped)\r
+{\r
+       ND_MR *mr;\r
+       HRESULT hr;\r
+\r
+       mr = (ND_MR *) hMr;\r
+       hr = m_pWvPd->DeregisterMemory(mr->Keys.Lkey, pOverlapped);\r
+       if (SUCCEEDED(hr) || hr == WV_IO_PENDING) {\r
+               CleanupMr(mr);\r
+       }\r
+       return hr;\r
+}\r
+\r
+void CNDAdapter::\r
+CleanupMr(ND_MR *pMr)\r
+{\r
+       EnterCriticalSection(&m_Lock);\r
+       DListRemove(&pMr->Entry);\r
+       LeaveCriticalSection(&m_Lock);\r
+       delete pMr;\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+CreateMemoryWindow(ND_RESULT* pInvalidateResult, INDMemoryWindow** ppMw)\r
+{\r
+       // TODO: do something with pInvalidateResult\r
+       return CNDMemoryWindow::CreateInstance(this, ppMw);\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+CreateConnector(INDConnector** ppConnector)\r
+{\r
+       return CNDConnector::CreateInstance(this, ppConnector);\r
+}\r
+\r
+STDMETHODIMP CNDAdapter::\r
+Listen(SIZE_T Backlog, INT Protocol, USHORT Port,\r
+          USHORT* pAssignedPort, INDListen** ppListen)\r
+{\r
+       return CNDListen::CreateInstance(this, Backlog, Protocol, Port,\r
+                                                                        pAssignedPort, ppListen);\r
+}\r
diff --git a/ulp/netdirect/user/nd_adapter.h b/ulp/netdirect/user/nd_adapter.h
new file mode 100644 (file)
index 0000000..0191958
--- /dev/null
@@ -0,0 +1,127 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_ADAPTER_H_\r
+#define _ND_ADAPTER_H_\r
+\r
+#include <ndspi.h>\r
+#include "nd_base.h"\r
+#include "nd_provider.h"\r
+#include <dlist.h>\r
+\r
+\r
+typedef struct _ND_MR\r
+{\r
+       DLIST_ENTRY                     Entry;\r
+       WV_MEMORY_KEYS          Keys;\r
+       void                            *Context;\r
+\r
+}      ND_MR;\r
+\r
+\r
+class CNDAdapter : public INDAdapter, public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       // INDOverlapped methods\r
+       STDMETHODIMP CancelOverlappedRequests();\r
+       STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                                                        SIZE_T *pNumberOfBytesTransferred, BOOL bWait);\r
+\r
+       // INDDevice methods\r
+       STDMETHODIMP_(HANDLE) GetFileHandle();\r
+       STDMETHODIMP Query(DWORD VersionRequested, ND_ADAPTER_INFO* pInfo,\r
+                                          SIZE_T* pBufferSize);\r
+       STDMETHODIMP Control(DWORD IoControlCode,\r
+                                                const void* pInBuffer, SIZE_T InBufferSize,\r
+                                                void* pOutBuffer, SIZE_T OutBufferSize,\r
+                                                SIZE_T* pBytesReturned, OVERLAPPED* pOverlapped);\r
+       STDMETHODIMP CreateCompletionQueue(SIZE_T nEntries, INDCompletionQueue** ppCq);\r
+       STDMETHODIMP RegisterMemory(const void* pBuffer, SIZE_T BufferSize,\r
+                                                               OVERLAPPED* pOverlapped, ND_MR_HANDLE* phMr);\r
+       STDMETHODIMP DeregisterMemory(ND_MR_HANDLE hMr, OVERLAPPED* pOverlapped);\r
+       STDMETHODIMP CreateMemoryWindow(ND_RESULT* pInvalidateResult,\r
+                                                                       INDMemoryWindow** ppMw);\r
+       STDMETHODIMP CreateConnector(INDConnector** ppConnector);\r
+       STDMETHODIMP Listen(SIZE_T Backlog, INT Protocol, USHORT Port,\r
+                                               USHORT* pAssignedPort, INDListen** ppListen);\r
+\r
+       CNDAdapter(CNDProvider *pProvider);\r
+       ~CNDAdapter();\r
+       void Delete() {delete this;}\r
+       static STDMETHODIMP\r
+       CreateInstance(CNDProvider *pProvider, const struct sockaddr *pAddress,\r
+                                  SIZE_T AddressLength, INDAdapter** ppAdapter)\r
+       {\r
+               HRESULT hr;\r
+               CNDAdapter *adapter;\r
+\r
+               adapter = new CNDAdapter(pProvider);\r
+               if (adapter == NULL) {\r
+                       hr = ND_NO_MEMORY;\r
+                       goto err1;\r
+               }\r
+\r
+               hr = adapter->Init(pAddress, AddressLength);\r
+               if (FAILED(hr)) {\r
+                       goto err2;\r
+               }\r
+\r
+               *ppAdapter = adapter;\r
+               return ND_SUCCESS;\r
+\r
+       err2:\r
+               adapter->Release();\r
+       err1:\r
+               *ppAdapter = NULL;\r
+               return hr;\r
+       }\r
+\r
+       IWVProvider                     *m_pWvProvider;\r
+       IWVDevice                       *m_pWvDevice;\r
+       IWVProtectionDomain     *m_pWvPd;\r
+       SOCKADDR_STORAGE        m_Address;\r
+       WV_DEVICE_ADDRESS       m_DevAddress;\r
+\r
+protected:\r
+       CNDProvider                     *m_pProvider;\r
+       DLIST_ENTRY                     m_MrList;\r
+       CRITICAL_SECTION        m_Lock;\r
+\r
+       STDMETHODIMP            Init(const struct sockaddr *pAddress, SIZE_T AddressLength);\r
+       void                            CleanupMr(ND_MR *pMr);\r
+};\r
+\r
+#endif // _ND_ADAPTER_H_\r
diff --git a/ulp/netdirect/user/nd_base.cpp b/ulp/netdirect/user/nd_base.cpp
new file mode 100644 (file)
index 0000000..6390f60
--- /dev/null
@@ -0,0 +1,53 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_base.h"\r
+\r
+CNDBase::CNDBase()\r
+{\r
+       m_nRef = 1;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDBase::\r
+AddRef(void)\r
+{\r
+       return InterlockedIncrement(&m_nRef);\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDBase::\r
+Release(void)\r
+{\r
+       ULONG ref;\r
+\r
+       ref = (ULONG) InterlockedDecrement(&m_nRef);\r
+       if (ref == 0) {\r
+               Delete();\r
+       }\r
+       return ref;\r
+}\r
diff --git a/ulp/netdirect/user/nd_base.h b/ulp/netdirect/user/nd_base.h
new file mode 100644 (file)
index 0000000..da84e6a
--- /dev/null
@@ -0,0 +1,63 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_BASE_H_\r
+#define _ND_BASE_H_\r
+\r
+#include <windows.h>\r
+#include <rdma\winverbs.h>\r
+\r
+class CNDBase\r
+{\r
+public:\r
+       CNDBase();\r
+       ~CNDBase() {};\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       virtual void Delete() {};\r
+\r
+       volatile LONG                   m_nRef;\r
+\r
+protected:\r
+};\r
+\r
+__inline void* __cdecl operator new(size_t size)\r
+{\r
+       return HeapAlloc(GetProcessHeap(), 0, size);\r
+}\r
+\r
+__inline void __cdecl operator delete(void *pObj)\r
+{\r
+       HeapFree(GetProcessHeap(), 0, pObj);\r
+}\r
+\r
+#endif // _ND_BASE_H_\r
diff --git a/ulp/netdirect/user/nd_connect.cpp b/ulp/netdirect/user/nd_connect.cpp
new file mode 100644 (file)
index 0000000..22d12e4
--- /dev/null
@@ -0,0 +1,259 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_connect.h"\r
+#include "nd_ep.h"\r
+\r
+\r
+CNDConnector::CNDConnector(CNDAdapter *pAdapter)\r
+{\r
+       pAdapter->AddRef();\r
+       m_pAdapter = pAdapter;\r
+       m_pWvConnEp = NULL;\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+Init(void)\r
+{\r
+       return m_pAdapter->m_pWvProvider->CreateConnectEndpoint(&m_pWvConnEp);\r
+}\r
+\r
+CNDConnector::~CNDConnector()\r
+{\r
+       if (m_pWvConnEp != NULL) {\r
+               m_pWvConnEp->Release();\r
+       }\r
+       m_pAdapter->Release();\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_INDConnector) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDConnector::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDConnector::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+CancelOverlappedRequests(void)\r
+{\r
+       return m_pWvConnEp->CancelOverlappedRequests();\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                       SIZE_T *pNumberOfBytesTransferred, BOOL bWait)\r
+{\r
+       return m_pWvConnEp->GetOverlappedResult(pOverlapped,\r
+                                                                                       (DWORD *) pNumberOfBytesTransferred,\r
+                                                                                       bWait);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+CreateEndpoint(INDCompletionQueue* pInboundCq, INDCompletionQueue* pOutboundCq,\r
+                          SIZE_T nInboundEntries, SIZE_T nOutboundEntries,\r
+                          SIZE_T nInboundSge, SIZE_T nOutboundSge,\r
+                          SIZE_T InboundReadLimit, SIZE_T OutboundReadLimit,\r
+                          SIZE_T* pMaxInlineData, INDEndpoint** ppEndpoint)\r
+{\r
+       CNDCompletionQueue *incq = (CNDCompletionQueue *) pInboundCq;\r
+       CNDCompletionQueue *outcq = (CNDCompletionQueue *) pOutboundCq;\r
+\r
+       return CNDEndpoint::CreateInstance(this, incq, outcq,\r
+                                                                          nInboundEntries, nOutboundEntries,\r
+                                                                          nInboundSge, nOutboundSge,\r
+                                                                          InboundReadLimit, OutboundReadLimit,\r
+                                                                          pMaxInlineData, ppEndpoint);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+Connect(INDEndpoint* pEndpoint,\r
+               const struct sockaddr* pAddress, SIZE_T AddressLength,\r
+               INT Protocol, USHORT LocalPort,\r
+               const void* pPrivateData, SIZE_T PrivateDataLength,\r
+               OVERLAPPED* pOverlapped)\r
+{\r
+       CNDEndpoint                     *ep = (CNDEndpoint *) pEndpoint;\r
+       WV_SOCKADDR                     addr;\r
+       WV_CONNECT_PARAM        attr;\r
+\r
+       RtlCopyMemory(&addr, pAddress, AddressLength);\r
+       if (addr.Sa.sa_family == AF_INET) {\r
+               addr.Sin.sin_port = LocalPort;\r
+       } else {\r
+               addr.Sin6.sin6_port = LocalPort;\r
+       }\r
+\r
+       RtlZeroMemory(&attr, sizeof attr);\r
+       if ((attr.DataLength = PrivateDataLength)) {\r
+               RtlCopyMemory(attr.Data, pPrivateData, PrivateDataLength);\r
+       }\r
+       attr.ResponderResources = ep->m_ResponderResources;\r
+       attr.InitiatorDepth = ep->m_InitiatorDepth;\r
+       attr.RetryCount = 7;\r
+\r
+       return m_pWvConnEp->Connect(ep->m_pWvQp, &addr.Sa, &attr, pOverlapped);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+CompleteConnect(OVERLAPPED* pOverlapped)\r
+{\r
+       WV_CONNECT_PARAM        attr;\r
+\r
+       RtlZeroMemory(&attr, sizeof attr);\r
+       return m_pWvConnEp->Accept(NULL, &attr, pOverlapped);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+Accept(INDEndpoint* pEndpoint,\r
+          const void* pPrivateData, SIZE_T PrivateDataLength,\r
+          OVERLAPPED* pOverlapped)\r
+{\r
+       CNDEndpoint                     *ep = (CNDEndpoint *) pEndpoint;\r
+       WV_CONNECT_PARAM        attr;\r
+\r
+       RtlZeroMemory(&attr, sizeof attr);\r
+       if ((attr.DataLength = PrivateDataLength)) {\r
+               RtlCopyMemory(attr.Data, pPrivateData, PrivateDataLength);\r
+       }\r
+       attr.ResponderResources = ep->m_ResponderResources;\r
+       attr.InitiatorDepth = ep->m_InitiatorDepth;\r
+\r
+       return m_pWvConnEp->Accept(ep->m_pWvQp, &attr, pOverlapped);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+Reject(const void* pPrivateData, SIZE_T PrivateDataLength)\r
+{\r
+       return m_pWvConnEp->Reject(pPrivateData, PrivateDataLength);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+GetConnectionData(SIZE_T* pInboundReadLimit, SIZE_T* pOutboundReadLimit,\r
+                                 void* pPrivateData, SIZE_T* pPrivateDataLength)\r
+{\r
+       WV_CONNECT_ATTRIBUTES attr;\r
+       HRESULT hr;\r
+       \r
+       if (pPrivateDataLength && *pPrivateDataLength < ND_PRIVATE_DATA_SIZE) {\r
+               *pPrivateDataLength = ND_PRIVATE_DATA_SIZE;\r
+               return ND_BUFFER_OVERFLOW;\r
+       }\r
+\r
+       hr = m_pWvConnEp->Query(&attr);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       *pInboundReadLimit = attr.Param.ResponderResources;\r
+       *pOutboundReadLimit = attr.Param.InitiatorDepth;\r
+       if (pPrivateDataLength) {\r
+               RtlCopyMemory(pPrivateData, attr.Param.Data, ND_PRIVATE_DATA_SIZE);\r
+               *pPrivateDataLength = ND_PRIVATE_DATA_SIZE;\r
+       }\r
+       return ND_SUCCESS;\r
+}\r
+\r
+static SIZE_T GetAddressSize(WV_SOCKADDR *addr)\r
+{\r
+       return (addr->Sa.sa_family == AF_INET) ? sizeof(addr->Sin) : sizeof(addr->Sin6);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+GetLocalAddress(struct sockaddr* pAddress, SIZE_T* pAddressLength)\r
+{\r
+       WV_CONNECT_ATTRIBUTES attr;\r
+       HRESULT hr;\r
+       \r
+       hr = m_pWvConnEp->Query(&attr);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       if (*pAddressLength < GetAddressSize(&attr.LocalAddress)) {\r
+               hr = ND_BUFFER_OVERFLOW;\r
+               goto out;\r
+       }\r
+\r
+       RtlCopyMemory(pAddress, &attr.LocalAddress, GetAddressSize(&attr.LocalAddress));\r
+out:\r
+       *pAddressLength = GetAddressSize(&attr.LocalAddress);\r
+       return hr;\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+GetPeerAddress(struct sockaddr* pAddress, SIZE_T* pAddressLength)\r
+{\r
+       WV_CONNECT_ATTRIBUTES attr;\r
+       HRESULT hr;\r
+       \r
+       hr = m_pWvConnEp->Query(&attr);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       if (*pAddressLength < GetAddressSize(&attr.PeerAddress)) {\r
+               hr = ND_BUFFER_OVERFLOW;\r
+               goto out;\r
+       }\r
+\r
+       RtlCopyMemory(pAddress, &attr.PeerAddress, GetAddressSize(&attr.PeerAddress));\r
+out:\r
+       *pAddressLength = GetAddressSize(&attr.PeerAddress);\r
+       return hr;\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+NotifyDisconnect(OVERLAPPED* pOverlapped)\r
+{\r
+       return m_pWvConnEp->NotifyDisconnect(pOverlapped);\r
+}\r
+\r
+STDMETHODIMP CNDConnector::\r
+Disconnect(OVERLAPPED* pOverlapped)\r
+{\r
+       return m_pWvConnEp->Disconnect(pOverlapped);\r
+}\r
diff --git a/ulp/netdirect/user/nd_connect.h b/ulp/netdirect/user/nd_connect.h
new file mode 100644 (file)
index 0000000..2da2f22
--- /dev/null
@@ -0,0 +1,119 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_CONNECTOR_H_\r
+#define _ND_CONNECTOR_H_\r
+\r
+#include <initguid.h>\r
+#include <ndspi.h>\r
+#include "nd_base.h"\r
+#include "nd_adapter.h"\r
+\r
+\r
+#define ND_PRIVATE_DATA_SIZE   56\r
+\r
+\r
+class CNDConnector : public INDConnector, public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       // INDOverlapped methods\r
+       STDMETHODIMP CancelOverlappedRequests();\r
+       STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                                                        SIZE_T *pNumberOfBytesTransferred, BOOL bWait);\r
+\r
+       // INDConnector methods\r
+       STDMETHODIMP CreateEndpoint(INDCompletionQueue* pInboundCq,\r
+                                                               INDCompletionQueue* pOutboundCq,\r
+                                                               SIZE_T nInboundEntries, SIZE_T nOutboundEntries,\r
+                                                               SIZE_T nInboundSge, SIZE_T nOutboundSge,\r
+                                                               SIZE_T InboundReadLimit, SIZE_T OutboundReadLimit,\r
+                                                               SIZE_T* pMaxInlineData, INDEndpoint** ppEndpoint);\r
+       STDMETHODIMP Connect(INDEndpoint* pEndpoint, \r
+                                                const struct sockaddr* pAddress, SIZE_T AddressLength,\r
+                                                INT Protocol, USHORT LocalPort,\r
+                                                const void* pPrivateData, SIZE_T PrivateDataLength,\r
+                                                OVERLAPPED* pOverlapped);\r
+       STDMETHODIMP CompleteConnect(OVERLAPPED* pOverlapped);\r
+       STDMETHODIMP Accept(INDEndpoint* pEndpoint,\r
+                                               const void* pPrivateData, SIZE_T PrivateDataLength,\r
+                                               OVERLAPPED* pOverlapped);\r
+       STDMETHODIMP Reject(const void* pPrivateData, SIZE_T PrivateDataLength);\r
+       STDMETHODIMP GetConnectionData(SIZE_T* pInboundReadLimit,\r
+                                                                  SIZE_T* pOutboundReadLimit,\r
+                                                                  void* pPrivateData, SIZE_T* pPrivateDataLength);\r
+       STDMETHODIMP GetLocalAddress(struct sockaddr* pAddress, SIZE_T* pAddressLength);\r
+       STDMETHODIMP GetPeerAddress(struct sockaddr* pAddress, SIZE_T* pAddressLength);\r
+       STDMETHODIMP NotifyDisconnect(OVERLAPPED* pOverlapped);\r
+       STDMETHODIMP Disconnect(OVERLAPPED* pOverlapped);\r
+\r
+       CNDConnector(CNDAdapter *pAdapter);\r
+       ~CNDConnector();\r
+       void Delete() {delete this;}\r
+       static STDMETHODIMP\r
+       CreateInstance(CNDAdapter *pAdapter, INDConnector** ppConnector)\r
+       {\r
+               HRESULT hr;\r
+               CNDConnector *conn;\r
+\r
+               conn = new CNDConnector(pAdapter);\r
+               if (conn == NULL) {\r
+                       hr = ND_NO_MEMORY;\r
+                       goto err1;\r
+               }\r
+\r
+               hr = conn->Init();\r
+               if (FAILED(hr)) {\r
+                       goto err2;\r
+               }\r
+\r
+               *ppConnector = conn;\r
+               return ND_SUCCESS;\r
+\r
+       err2:\r
+               conn->Release();\r
+       err1:\r
+               *ppConnector = NULL;\r
+               return hr;\r
+       }\r
+\r
+       IWVConnectEndpoint      *m_pWvConnEp;\r
+       CNDAdapter                      *m_pAdapter;\r
+\r
+protected:\r
+       STDMETHODIMP            Init();\r
+};\r
+\r
+#endif // _ND_CONNECTOR_H_\r
diff --git a/ulp/netdirect/user/nd_cq.cpp b/ulp/netdirect/user/nd_cq.cpp
new file mode 100644 (file)
index 0000000..0324ed1
--- /dev/null
@@ -0,0 +1,124 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_cq.h"\r
+\r
+CNDCompletionQueue::CNDCompletionQueue(CNDAdapter *pAdapter)\r
+{\r
+       pAdapter->AddRef();\r
+       m_pAdapter = pAdapter;\r
+       m_pWvCq = NULL;\r
+}\r
+\r
+STDMETHODIMP CNDCompletionQueue::\r
+Init(SIZE_T nEntries)\r
+{\r
+       return m_pAdapter->m_pWvDevice->CreateCompletionQueue(&nEntries, &m_pWvCq);\r
+}\r
+\r
+CNDCompletionQueue::~CNDCompletionQueue()\r
+{\r
+       if (m_pWvCq != NULL) {\r
+               m_pWvCq->Release();\r
+       }\r
+       m_pAdapter->Release();\r
+}\r
+\r
+STDMETHODIMP CNDCompletionQueue::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_INDCompletionQueue) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDCompletionQueue::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDCompletionQueue::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
+\r
+STDMETHODIMP CNDCompletionQueue::\r
+CancelOverlappedRequests(void)\r
+{\r
+       return m_pWvCq->CancelOverlappedRequests();\r
+}\r
+\r
+STDMETHODIMP CNDCompletionQueue::\r
+GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                       SIZE_T *pNumberOfBytesTransferred, BOOL bWait)\r
+{\r
+       return m_pWvCq->GetOverlappedResult(pOverlapped,\r
+                                                                               (DWORD *) pNumberOfBytesTransferred, bWait);\r
+}\r
+\r
+STDMETHODIMP CNDCompletionQueue::\r
+Resize(SIZE_T nEntries)\r
+{\r
+       return m_pWvCq->Resize(&nEntries);\r
+}\r
+\r
+STDMETHODIMP CNDCompletionQueue::\r
+Notify(DWORD Type, OVERLAPPED* pOverlapped)\r
+{\r
+       return m_pWvCq->Notify((WV_CQ_NOTIFY_TYPE) Type, pOverlapped);\r
+}\r
+\r
+STDMETHODIMP_(SIZE_T) CNDCompletionQueue::\r
+GetResults(ND_RESULT* pResults[], SIZE_T nResults)\r
+{\r
+       WV_COMPLETION   comp[8];\r
+       SIZE_T                  cnt, total, i;\r
+\r
+       for (total = 0; nResults; nResults -= cnt) {\r
+               cnt = min(8, nResults);\r
+               cnt = m_pWvCq->Poll(comp, cnt);\r
+               if (cnt == 0) {\r
+                       break;\r
+               }\r
+\r
+               for (i = 0; i < cnt; i++) {\r
+                       pResults[total] = (ND_RESULT *) comp[i].WrId;\r
+                       pResults[total]->Status = comp[i].Status;\r
+                       pResults[total++]->BytesTransferred = comp[i].Length;\r
+               }\r
+       }\r
+       return total;\r
+}\r
diff --git a/ulp/netdirect/user/nd_cq.h b/ulp/netdirect/user/nd_cq.h
new file mode 100644 (file)
index 0000000..ba1c91a
--- /dev/null
@@ -0,0 +1,95 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_CQ_H_\r
+#define _ND_CQ_H_\r
+\r
+#include <initguid.h>\r
+#include <ndspi.h>\r
+#include "nd_base.h"\r
+#include "nd_adapter.h"\r
+\r
+class CNDCompletionQueue : public INDCompletionQueue, public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       // INDOverlapped methods\r
+       STDMETHODIMP CancelOverlappedRequests();\r
+       STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                                                        SIZE_T *pNumberOfBytesTransferred, BOOL bWait);\r
+\r
+       // INDCompletionQueue methods\r
+       STDMETHODIMP Resize(SIZE_T nEntries);\r
+       STDMETHODIMP Notify(DWORD Type, OVERLAPPED* pOverlapped);\r
+       STDMETHODIMP_(SIZE_T) GetResults(ND_RESULT* pResults[], SIZE_T nResults);\r
+\r
+       CNDCompletionQueue(CNDAdapter *pAdapter);\r
+       ~CNDCompletionQueue();\r
+       void Delete() {delete this;}\r
+       static STDMETHODIMP\r
+       CreateInstance(CNDAdapter *pAdapter, SIZE_T nEntries, INDCompletionQueue** ppCq)\r
+       {\r
+               HRESULT hr;\r
+               CNDCompletionQueue *cq;\r
+\r
+               cq = new CNDCompletionQueue(pAdapter);\r
+               if (cq == NULL) {\r
+                       hr = ND_NO_MEMORY;\r
+                       goto err1;\r
+               }\r
+\r
+               hr = cq->Init(nEntries);\r
+               if (FAILED(hr)) {\r
+                       goto err2;\r
+               }\r
+\r
+               *ppCq = cq;\r
+               return ND_SUCCESS;\r
+\r
+       err2:\r
+               cq->Release();\r
+       err1:\r
+               *ppCq = NULL;\r
+               return hr;\r
+       }\r
+\r
+       IWVCompletionQueue      *m_pWvCq;\r
+\r
+protected:\r
+       CNDAdapter                      *m_pAdapter;\r
+       STDMETHODIMP            Init(SIZE_T nEntries);\r
+};\r
+\r
+#endif // _ND_CQ_H_\r
diff --git a/ulp/netdirect/user/nd_ep.cpp b/ulp/netdirect/user/nd_ep.cpp
new file mode 100644 (file)
index 0000000..07383f2
--- /dev/null
@@ -0,0 +1,282 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_ep.h"\r
+#include "nd_adapter.h"\r
+#include "nd_connect.h"\r
+#include "nd_cq.h"\r
+#include "nd_mw.h"\r
+#include <netinet/in.h>\r
+\r
+\r
+CNDEndpoint::CNDEndpoint(CNDConnector *pConnector)\r
+{\r
+       pConnector->AddRef();\r
+       m_pConnector = pConnector;\r
+       m_pWvQp = NULL;\r
+       m_pInboundCq = NULL;\r
+       m_pOutboundCq = NULL;\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Init(CNDCompletionQueue* pInboundCq, CNDCompletionQueue* pOutboundCq,\r
+        SIZE_T nInboundEntries, SIZE_T nOutboundEntries,\r
+        SIZE_T nInboundSge, SIZE_T nOutboundSge,\r
+        SIZE_T InboundReadLimit, SIZE_T OutboundReadLimit,\r
+        SIZE_T* pMaxInlineData)\r
+{\r
+       WV_QP_CREATE create;\r
+       WV_QP_ATTRIBUTES attr;\r
+       WV_DEVICE_ADDRESS *addr;\r
+       DWORD opts;\r
+       HRESULT hr;\r
+\r
+       m_pInboundCq->AddRef();\r
+       m_pOutboundCq->AddRef();\r
+       m_InitiatorDepth = OutboundReadLimit;\r
+       m_ResponderResources = InboundReadLimit;\r
+\r
+       RtlZeroMemory(&create, sizeof create);\r
+       create.pSendCq = pOutboundCq->m_pWvCq;\r
+       create.pReceiveCq = pInboundCq->m_pWvCq;\r
+       create.Context = this;\r
+       create.SendDepth = nOutboundEntries;\r
+       create.SendSge = nOutboundSge;\r
+       create.ReceiveDepth = nInboundEntries;\r
+       create.ReceiveSge = nInboundSge;\r
+       create.InitiatorDepth = OutboundReadLimit;\r
+       create.ResponderResources = InboundReadLimit;\r
+       create.QpType = WvQpTypeRc;\r
+       \r
+       hr = m_pConnector->m_pAdapter->m_pWvPd->CreateConnectQueuePair(&create, &m_pWvQp);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       opts = WV_QP_ATTR_STATE | WV_QP_ATTR_PORT_NUMBER | WV_QP_ATTR_PKEY_INDEX;\r
+       attr.QpState = WvQpStateInit;\r
+       addr = &m_pConnector->m_pAdapter->m_DevAddress;\r
+       attr.AddressVector.PortNumber = addr->PortNumber;\r
+       hr = m_pConnector->m_pAdapter->m_pWvDevice->FindPkey(addr->PortNumber, addr->Pkey,\r
+                                                                                                                &attr.PkeyIndex);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       hr = m_pWvQp->Modify(&attr, opts, NULL);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       *pMaxInlineData = 0;\r
+       return ND_SUCCESS;\r
+}\r
+\r
+CNDEndpoint::~CNDEndpoint()\r
+{\r
+       if (m_pWvQp != NULL) {\r
+               m_pWvQp->Release();\r
+       }\r
+       if (m_pInboundCq != NULL) {\r
+               m_pInboundCq->Release();\r
+       }\r
+       if (m_pOutboundCq != NULL) {\r
+               m_pOutboundCq->Release();\r
+       }\r
+       m_pConnector->Release();\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_INDEndpoint) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDEndpoint::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDEndpoint::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Flush(void)\r
+{\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(void) CNDEndpoint::\r
+StartRequestBatch(void)\r
+{\r
+       // no-op\r
+}\r
+\r
+STDMETHODIMP_(void) CNDEndpoint::\r
+SubmitRequestBatch(void)\r
+{\r
+       // no-op\r
+}\r
+\r
+STDMETHODIMP_(void) CNDEndpoint::\r
+ConvertSgl(const ND_SGE* pSgl, SIZE_T nSge, WV_SGE* pWvSgl)\r
+{\r
+       SIZE_T i;\r
+\r
+       for (i = 0; i < nSge; i++) {\r
+               pWvSgl[i].pAddress = pSgl[i].pAddr;\r
+               pWvSgl[i].Length = (UINT32) pSgl[i].Length;\r
+               pWvSgl[i].Lkey = pSgl[i].hMr ? ((ND_MR *) pSgl[i].hMr)->Keys.Lkey : 0;\r
+       }\r
+}\r
+\r
+STDMETHODIMP_(DWORD) CNDEndpoint::\r
+ConvertSendFlags(DWORD Flags)\r
+{\r
+       DWORD opts = 0;\r
+\r
+       if (!(Flags & ND_OP_FLAG_SILENT_SUCCESS)) {\r
+               opts |= WV_SEND_SIGNALED;\r
+       }\r
+       if (Flags & ND_OP_FLAG_READ_FENCE) {\r
+               opts |= WV_SEND_FENCE;\r
+       }\r
+       if (Flags & ND_OP_FLAG_SEND_AND_SOLICIT_EVENT) {\r
+               opts |= WV_SEND_SOLICITED;\r
+       }\r
+       return opts;\r
+}\r
+\r
+STDMETHODIMP_(DWORD) CNDEndpoint::\r
+ConvertAccessFlags(DWORD Flags)\r
+{\r
+       DWORD opts = 0;\r
+\r
+       if (!(Flags & ND_OP_FLAG_ALLOW_READ)) {\r
+               opts |= WV_ACCESS_REMOTE_READ;\r
+       }\r
+       if (Flags & ND_OP_FLAG_ALLOW_WRITE) {\r
+               opts |= WV_ACCESS_REMOTE_WRITE;\r
+       }\r
+       return opts;\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Send(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge, DWORD Flags)\r
+{\r
+       WV_SGE sgl[ND_MAX_SGE];\r
+       DWORD opts;\r
+\r
+       ConvertSgl(pSgl, nSge, sgl);\r
+       opts = ConvertSendFlags(Flags) | (pSgl[0].hMr ? 0 : WV_SEND_INLINE);\r
+       return m_pWvQp->Send((UINT64) pResult, sgl, nSge, opts, 0);\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+SendAndInvalidate(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge,\r
+                                 const ND_MW_DESCRIPTOR* pRemoteMwDescriptor, DWORD Flags)\r
+{\r
+       return Send(pResult, pSgl, nSge, Flags);\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Receive(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge)\r
+{\r
+       WV_SGE sgl[ND_MAX_SGE];\r
+\r
+       ConvertSgl(pSgl, nSge, sgl);\r
+       return m_pWvQp->PostReceive((UINT64) pResult, sgl, nSge);\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Bind(ND_RESULT* pResult, ND_MR_HANDLE hMr, INDMemoryWindow* pMw,\r
+        const void* pBuffer, SIZE_T BufferSize, DWORD Flags,\r
+        ND_MW_DESCRIPTOR* pMwDescriptor)\r
+{\r
+       CNDMemoryWindow *mw = (CNDMemoryWindow *) pMw;\r
+       ND_MR *mr = (ND_MR *) hMr;\r
+       WV_SGE sge;\r
+\r
+       pMwDescriptor->Base = htonll((UINT64) (ULONG_PTR) pBuffer);\r
+       pMwDescriptor->Length = htonll(BufferSize);\r
+       pMwDescriptor->Token = mr->Keys.Rkey;\r
+\r
+       RtlZeroMemory(&sge, sizeof sge);\r
+       return m_pWvQp->Write((UINT64) pResult, &sge, 1, ConvertSendFlags(Flags),\r
+                                                 0, NULL, 0);\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Invalidate(ND_RESULT* pResult, INDMemoryWindow* pMw, DWORD Flags)\r
+{\r
+       WV_SGE sge;\r
+\r
+       RtlZeroMemory(&sge, sizeof sge);\r
+       return m_pWvQp->Write((UINT64) pResult, &sge, 1, ConvertSendFlags(Flags),\r
+                                                 0, NULL, 0);\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Read(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge,\r
+        const ND_MW_DESCRIPTOR* pRemoteMwDescriptor, ULONGLONG Offset, DWORD Flags)\r
+{\r
+       WV_SGE sgl[ND_MAX_SGE];\r
+       DWORD opts;\r
+\r
+       ConvertSgl(pSgl, nSge, sgl);\r
+       opts = ConvertSendFlags(Flags) | (pSgl[0].hMr ? 0 : WV_SEND_INLINE);\r
+       return m_pWvQp->Read((UINT64) pResult, sgl, nSge, opts,\r
+                                                pRemoteMwDescriptor->Base + htonll(Offset),\r
+                                                pRemoteMwDescriptor->Token);\r
+}\r
+\r
+STDMETHODIMP CNDEndpoint::\r
+Write(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge,\r
+         const ND_MW_DESCRIPTOR* pRemoteMwDescriptor, ULONGLONG Offset, DWORD Flags)\r
+{\r
+       WV_SGE sgl[ND_MAX_SGE];\r
+       DWORD opts;\r
+\r
+       ConvertSgl(pSgl, nSge, sgl);\r
+       opts = ConvertSendFlags(Flags) | (pSgl[0].hMr ? 0 : WV_SEND_INLINE);\r
+       return m_pWvQp->Write((UINT64) pResult, sgl, nSge, opts, 0,\r
+                                                 pRemoteMwDescriptor->Base + htonll(Offset),\r
+                                                 pRemoteMwDescriptor->Token);\r
+}\r
diff --git a/ulp/netdirect/user/nd_ep.h b/ulp/netdirect/user/nd_ep.h
new file mode 100644 (file)
index 0000000..8e60d00
--- /dev/null
@@ -0,0 +1,130 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_ENDPOINT_H_\r
+#define _ND_ENDPOINT_H_\r
+\r
+#include <initguid.h>\r
+#include <ndspi.h>\r
+#include "nd_base.h"\r
+#include "nd_connect.h"\r
+#include "nd_cq.h"\r
+#include "nd_adapter.h"\r
+\r
+\r
+#define ND_MAX_SGE     8\r
+\r
+\r
+class CNDEndpoint : public INDEndpoint, public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       // INDEndpoint methods\r
+       STDMETHODIMP Flush();\r
+       STDMETHODIMP_(void) StartRequestBatch();\r
+       STDMETHODIMP_(void) SubmitRequestBatch();\r
+       STDMETHODIMP Send(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge, DWORD Flags);\r
+       STDMETHODIMP SendAndInvalidate(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge,\r
+                                                                  const ND_MW_DESCRIPTOR* pRemoteMwDescriptor,\r
+                                                                  DWORD Flags);\r
+       STDMETHODIMP Receive(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge);\r
+       STDMETHODIMP Bind(ND_RESULT* pResult, ND_MR_HANDLE hMr, INDMemoryWindow* pMw,\r
+                                         const void* pBuffer, SIZE_T BufferSize, DWORD Flags,\r
+                                         ND_MW_DESCRIPTOR* pMwDescriptor);\r
+       STDMETHODIMP Invalidate(ND_RESULT* pResult, INDMemoryWindow* pMw, DWORD Flags);\r
+       STDMETHODIMP Read(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge,\r
+                                         const ND_MW_DESCRIPTOR* pRemoteMwDescriptor,\r
+                                         ULONGLONG Offset, DWORD Flags);\r
+       STDMETHODIMP Write(ND_RESULT* pResult, const ND_SGE* pSgl, SIZE_T nSge,\r
+                                          const ND_MW_DESCRIPTOR* pRemoteMwDescriptor,\r
+                                          ULONGLONG Offset, DWORD Flags);\r
+       \r
+       CNDEndpoint(CNDConnector *pConnector);\r
+       ~CNDEndpoint();\r
+       void Delete() {delete this;}\r
+       static STDMETHODIMP\r
+       CreateInstance(CNDConnector *pConnector,\r
+                                  CNDCompletionQueue* pInboundCq, CNDCompletionQueue* pOutboundCq,\r
+                                  SIZE_T nInboundEntries, SIZE_T nOutboundEntries,\r
+                                  SIZE_T nInboundSge, SIZE_T nOutboundSge,\r
+                                  SIZE_T InboundReadLimit, SIZE_T OutboundReadLimit,\r
+                                  SIZE_T* pMaxInlineData, INDEndpoint** ppEndpoint)\r
+       {\r
+               HRESULT hr;\r
+               CNDEndpoint *ep;\r
+\r
+               ep = new CNDEndpoint(pConnector);\r
+               if (ep == NULL) {\r
+                       hr = ND_NO_MEMORY;\r
+                       goto err1;\r
+               }\r
+\r
+               hr = ep->Init(pInboundCq, pOutboundCq, nInboundEntries, nOutboundEntries,\r
+                                         nInboundSge, nOutboundSge, InboundReadLimit, OutboundReadLimit,\r
+                                         pMaxInlineData);\r
+               if (FAILED(hr)) {\r
+                       goto err2;\r
+               }\r
+\r
+               *ppEndpoint = ep;\r
+               return ND_SUCCESS;\r
+\r
+       err2:\r
+               ep->Release();\r
+       err1:\r
+               *ppEndpoint = NULL;\r
+               return hr;\r
+       }\r
+\r
+       IWVConnectQueuePair     *m_pWvQp;\r
+       SIZE_T                          m_InitiatorDepth;\r
+       SIZE_T                          m_ResponderResources;\r
+\r
+protected:\r
+       CNDConnector            *m_pConnector;\r
+       CNDCompletionQueue      *m_pInboundCq;\r
+       CNDCompletionQueue      *m_pOutboundCq;\r
+\r
+       STDMETHODIMP Init(CNDCompletionQueue* pInboundCq, CNDCompletionQueue* pOutboundCq,\r
+                                         SIZE_T nInboundEntries, SIZE_T nOutboundEntries,\r
+                                         SIZE_T nInboundSge, SIZE_T nOutboundSge,\r
+                                         SIZE_T InboundReadLimit, SIZE_T OutboundReadLimit,\r
+                                         SIZE_T* pMaxInlineData);\r
+       STDMETHODIMP_(void)     ConvertSgl(const ND_SGE* pSgl, SIZE_T nSge, WV_SGE *pWvSgl);\r
+       STDMETHODIMP_(DWORD) ConvertSendFlags(DWORD Flags);\r
+       STDMETHODIMP_(DWORD) ConvertAccessFlags(DWORD Flags);\r
+};\r
+\r
+#endif // _ND_ENDPOINT_H_\r
diff --git a/ulp/netdirect/user/nd_export.def b/ulp/netdirect/user/nd_export.def
new file mode 100644 (file)
index 0000000..920a72b
--- /dev/null
@@ -0,0 +1,35 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+LIBRARY        WVNDPROV.DLL\r
+\r
+EXPORTS\r
+       DllCanUnloadNow         PRIVATE\r
+       DllGetClassObject       PRIVATE\r
+       WSPStartup\r
diff --git a/ulp/netdirect/user/nd_exports.src b/ulp/netdirect/user/nd_exports.src
new file mode 100644 (file)
index 0000000..042f3cd
--- /dev/null
@@ -0,0 +1,12 @@
+#if DBG\r
+LIBRARY wvndprov.dll\r
+#else\r
+LIBRARY wvndprov.dll\r
+#endif\r
+\r
+#ifndef _WIN64\r
+EXPORTS\r
+       DllCanUnloadNow         PRIVATE\r
+       DllGetClassObject       PRIVATE\r
+       WSPStartup\r
+#endif\r
diff --git a/ulp/netdirect/user/nd_listen.cpp b/ulp/netdirect/user/nd_listen.cpp
new file mode 100644 (file)
index 0000000..ab50589
--- /dev/null
@@ -0,0 +1,145 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_listen.h"\r
+#include "nd_adapter.h"\r
+#include "nd_connect.h"\r
+\r
+\r
+CNDListen::CNDListen(CNDAdapter *pAdapter)\r
+{\r
+       pAdapter->AddRef();\r
+       m_pAdapter = pAdapter;\r
+       m_pWvConnEp = NULL;\r
+}\r
+\r
+STDMETHODIMP CNDListen::\r
+Init(SIZE_T Backlog, INT Protocol, USHORT *pPort)\r
+{\r
+       WV_CONNECT_ATTRIBUTES attr;\r
+       WV_SOCKADDR addr;\r
+       HRESULT hr;\r
+\r
+       if (Protocol != 6) {\r
+               return ND_NOT_SUPPORTED;\r
+       }\r
+\r
+       hr = m_pAdapter->m_pWvProvider->CreateConnectEndpoint(&m_pWvConnEp);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       if (m_pAdapter->m_Address.ss_family == AF_INET) {\r
+               RtlCopyMemory(&addr.Sin, &m_pAdapter->m_Address, sizeof(addr.Sin));\r
+               addr.Sin.sin_port = *pPort;\r
+       } else {\r
+               RtlCopyMemory(&addr.Sin6, &m_pAdapter->m_Address, sizeof(addr.Sin6));\r
+               addr.Sin6.sin6_port = *pPort;\r
+       }\r
+\r
+       hr = m_pWvConnEp->BindAddress(&addr.Sa);\r
+       if (FAILED(hr)) {\r
+               goto err;\r
+       }\r
+\r
+       hr = m_pWvConnEp->Listen(Backlog);\r
+       if (FAILED(hr)) {\r
+               goto err;\r
+       }\r
+\r
+       if (*pPort == 0) {\r
+               hr = m_pWvConnEp->Query(&attr);\r
+               if (FAILED(hr)) {\r
+                       goto err;\r
+               }\r
+               *pPort = (addr.Sa.sa_family == AF_INET) ?\r
+                                attr.LocalAddress.Sin.sin_port : attr.LocalAddress.Sin6.sin6_port;\r
+       }\r
+\r
+       return ND_SUCCESS;\r
+err:\r
+       m_pWvConnEp->Release();\r
+       return hr;\r
+}\r
+\r
+CNDListen::~CNDListen()\r
+{\r
+       if (m_pWvConnEp != NULL) {\r
+               m_pWvConnEp->Release();\r
+       }\r
+       m_pAdapter->Release();\r
+}\r
+\r
+STDMETHODIMP CNDListen::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_INDListen) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDListen::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDListen::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
+\r
+STDMETHODIMP CNDListen::\r
+CancelOverlappedRequests(void)\r
+{\r
+       return m_pWvConnEp->CancelOverlappedRequests();\r
+}\r
+\r
+STDMETHODIMP CNDListen::\r
+GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                       SIZE_T *pNumberOfBytesTransferred, BOOL bWait)\r
+{\r
+       return m_pWvConnEp->GetOverlappedResult(pOverlapped,\r
+                                                                                       (DWORD *) pNumberOfBytesTransferred,\r
+                                                                                       bWait);\r
+}\r
+\r
+STDMETHODIMP CNDListen::\r
+GetConnectionRequest(INDConnector* pConnector, OVERLAPPED* pOverlapped)\r
+{\r
+       CNDConnector *conn = (CNDConnector *) pConnector;\r
+\r
+       return m_pWvConnEp->GetRequest(conn->m_pWvConnEp, pOverlapped);\r
+}\r
diff --git a/ulp/netdirect/user/nd_listen.h b/ulp/netdirect/user/nd_listen.h
new file mode 100644 (file)
index 0000000..15526fb
--- /dev/null
@@ -0,0 +1,98 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_LISTEN_H_\r
+#define _ND_LISTEN_H_\r
+\r
+#include <initguid.h>\r
+#include <ndspi.h>\r
+#include "nd_base.h"\r
+#include "nd_adapter.h"\r
+\r
+class CNDListen : public INDListen, public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       // INDOverlapped methods\r
+       STDMETHODIMP CancelOverlappedRequests();\r
+       STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
+                                                                        SIZE_T *pNumberOfBytesTransferred, BOOL bWait);\r
+\r
+       // INDListen methods\r
+       STDMETHODIMP GetConnectionRequest(INDConnector* pConnector,\r
+                                                                         OVERLAPPED* pOverlapped);\r
+\r
+       CNDListen(CNDAdapter *pAdapter);\r
+       ~CNDListen();\r
+       void Delete() {delete this;}\r
+       static STDMETHODIMP\r
+       CreateInstance(CNDAdapter *pAdapter, SIZE_T Backlog, INT Protocol, USHORT Port,\r
+                                  USHORT* pAssignedPort, INDListen** ppListen)\r
+       {\r
+               HRESULT hr;\r
+               CNDListen *listener;\r
+\r
+               listener = new CNDListen(pAdapter);\r
+               if (listener == NULL) {\r
+                       hr = ND_NO_MEMORY;\r
+                       goto err1;\r
+               }\r
+\r
+               hr = listener->Init(Backlog, Protocol, &Port);\r
+               if (FAILED(hr)) {\r
+                       goto err2;\r
+               }\r
+\r
+               if (pAssignedPort) {\r
+                       *pAssignedPort = Port;\r
+               }\r
+               *ppListen = listener;\r
+               return ND_SUCCESS;\r
+\r
+       err2:\r
+               listener->Release();\r
+       err1:\r
+               *ppListen = NULL;\r
+               return hr;\r
+       }\r
+\r
+protected:\r
+       CNDAdapter                      *m_pAdapter;\r
+       IWVConnectEndpoint      *m_pWvConnEp;\r
+\r
+       STDMETHODIMP            Init(SIZE_T Backlog, INT Protocol, USHORT *pPort);\r
+};\r
+\r
+#endif // _ND_LISTEN_H_\r
diff --git a/ulp/netdirect/user/nd_main.cpp b/ulp/netdirect/user/nd_main.cpp
new file mode 100644 (file)
index 0000000..6ffe16a
--- /dev/null
@@ -0,0 +1,88 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include <windows.h>\r
+#include <ws2spi.h>\r
+#include <stdio.h>\r
+#include "nd_provider.h"\r
+\r
+\r
+extern "C" {\r
+\r
+extern BOOL APIENTRY\r
+_DllMainCRTStartupForGS(HINSTANCE h_module, DWORD ul_reason_for_call,\r
+                                               LPVOID lp_reserved);\r
+\r
+\r
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
+{\r
+       switch (dwReason) {\r
+       case DLL_PROCESS_ATTACH:\r
+       case DLL_PROCESS_DETACH:\r
+               return _DllMainCRTStartupForGS(hInstance, dwReason, lpReserved);\r
+       default:\r
+               return TRUE;\r
+       }\r
+}\r
+\r
+STDAPI DllCanUnloadNow(void)\r
+{\r
+       return S_OK;\r
+}\r
+\r
+STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv)\r
+{\r
+       UNREFERENCED_PARAMETER(rclsid);\r
+\r
+       if (riid != IID_IClassFactory) {\r
+               *ppv = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppv = new CNDClassFactory();\r
+       if (*ppv == NULL) {\r
+               return E_OUTOFMEMORY;\r
+       }\r
+\r
+       return S_OK;\r
+}\r
+\r
+int /*WSPAPI*/ WSPStartup(WORD wVersionRequested, LPWSPDATA lpWSPData,\r
+                                         LPWSAPROTOCOL_INFOW lpProtocolInfo,\r
+                                         WSPUPCALLTABLE UpcallTable, LPWSPPROC_TABLE lpProcTable)\r
+{\r
+       UNREFERENCED_PARAMETER(wVersionRequested);\r
+       UNREFERENCED_PARAMETER(lpWSPData);\r
+       UNREFERENCED_PARAMETER(lpProtocolInfo);\r
+       UNREFERENCED_PARAMETER(UpcallTable);\r
+       UNREFERENCED_PARAMETER(lpProcTable);\r
+       return WSASYSNOTREADY;\r
+}\r
+\r
+} // extern "C"
\ No newline at end of file
diff --git a/ulp/netdirect/user/nd_main.h b/ulp/netdirect/user/nd_main.h
new file mode 100644 (file)
index 0000000..9a89272
--- /dev/null
@@ -0,0 +1,37 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_MAIN_H_\r
+#define _ND_MAIN_H_\r
+\r
+#include <rdma\winverbs.h>\r
+\r
+#endif // _ND_MAIN_H_\r
diff --git a/ulp/netdirect/user/nd_mw.cpp b/ulp/netdirect/user/nd_mw.cpp
new file mode 100644 (file)
index 0000000..64a8feb
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_mw.h"\r
+\r
+CNDMemoryWindow::CNDMemoryWindow(CNDAdapter *pAdapter)\r
+{\r
+       pAdapter->AddRef();\r
+       m_pAdapter = pAdapter;\r
+       m_pWvMw = NULL;\r
+}\r
+\r
+STDMETHODIMP CNDMemoryWindow::\r
+Init(void)\r
+{\r
+       return m_pAdapter->m_pWvPd->AllocateMemoryWindow(&m_pWvMw);\r
+}\r
+\r
+CNDMemoryWindow::~CNDMemoryWindow()\r
+{\r
+       if (m_pWvMw != NULL) {\r
+               m_pWvMw->Release();\r
+       }\r
+       m_pAdapter->Release();\r
+}\r
+\r
+STDMETHODIMP CNDMemoryWindow::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_INDMemoryWindow) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDMemoryWindow::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDMemoryWindow::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
diff --git a/ulp/netdirect/user/nd_mw.h b/ulp/netdirect/user/nd_mw.h
new file mode 100644 (file)
index 0000000..b7e42bc
--- /dev/null
@@ -0,0 +1,85 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_MW_H_\r
+#define _ND_MW_H_\r
+\r
+#include <initguid.h>\r
+#include <ndspi.h>\r
+#include "nd_base.h"\r
+#include "nd_adapter.h"\r
+\r
+class CNDMemoryWindow : public INDMemoryWindow , public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+       \r
+       CNDMemoryWindow(CNDAdapter *m_pAdapter);\r
+       ~CNDMemoryWindow();\r
+       void Delete() {delete this;}\r
+       static STDMETHODIMP\r
+       CreateInstance(CNDAdapter *pAdapter, INDMemoryWindow** ppMw)\r
+       {\r
+               HRESULT hr;\r
+               CNDMemoryWindow *mw;\r
+\r
+               mw = new CNDMemoryWindow(pAdapter);\r
+               if (mw == NULL) {\r
+                       hr = ND_NO_MEMORY;\r
+                       goto err1;\r
+               }\r
+\r
+               hr = mw->Init();\r
+               if (FAILED(hr)) {\r
+                       goto err2;\r
+               }\r
+\r
+               *ppMw = mw;\r
+               return ND_SUCCESS;\r
+\r
+       err2:\r
+               mw->Release();\r
+       err1:\r
+               *ppMw = NULL;\r
+               return hr;\r
+       }\r
+\r
+       IWVMemoryWindow         *m_pWvMw;\r
+protected:\r
+       CNDAdapter                      *m_pAdapter;\r
+\r
+       STDMETHODIMP            Init();\r
+};\r
+\r
+#endif // _ND_MW_H_\r
diff --git a/ulp/netdirect/user/nd_provider.cpp b/ulp/netdirect/user/nd_provider.cpp
new file mode 100644 (file)
index 0000000..8f6f138
--- /dev/null
@@ -0,0 +1,180 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include "nd_provider.h"\r
+#include "nd_adapter.h"\r
+#include <ws2tcpip.h>\r
+\r
+STDMETHODIMP CNDProvider::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_INDProvider) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDProvider::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDProvider::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
+\r
+STDMETHODIMP CNDProvider::\r
+QueryAddressList(SOCKET_ADDRESS_LIST* pAddressList, SIZE_T* pBufferSize)\r
+{\r
+       WV_DEVICE_ADDRESS devaddr;\r
+       IWVProvider *prov;\r
+       struct addrinfo *res, *ai;\r
+       HRESULT hr;\r
+       int cnt = 0;\r
+       size_t addrlen = 0, size;\r
+       UINT8 *offset;\r
+\r
+       hr = WvGetObject(IID_IWVProvider, (LPVOID *) &prov);\r
+       if (FAILED(hr)) {\r
+               return hr;\r
+       }\r
+\r
+       hr = getaddrinfo("..localmachine", NULL, NULL, &res);\r
+       if (hr) {\r
+               goto release;\r
+       }\r
+\r
+       for (ai = res; ai; ai = ai->ai_next) {\r
+               ai->ai_flags = prov->TranslateAddress(ai->ai_addr, &devaddr);\r
+               if (SUCCEEDED(ai->ai_flags)) {\r
+                       cnt++;\r
+                       addrlen += ai->ai_addrlen;\r
+               }\r
+       }\r
+\r
+       if (cnt == 0) {\r
+               *pBufferSize = 0;\r
+               goto free;\r
+       }\r
+\r
+       size = sizeof(SOCKET_ADDRESS_LIST) + sizeof(SOCKET_ADDRESS) * (cnt - 1);\r
+       if (size + addrlen > *pBufferSize) {\r
+               *pBufferSize = size + addrlen;\r
+               hr = ND_BUFFER_OVERFLOW;\r
+               goto free;\r
+       }\r
+\r
+       pAddressList->iAddressCount = cnt;\r
+       offset = (UINT8 *) pAddressList + size;\r
+       for (cnt = 0, ai = res; ai; ai = ai->ai_next) {\r
+               if (SUCCEEDED(ai->ai_flags)) {\r
+                       pAddressList->Address[cnt].iSockaddrLength = ai->ai_addrlen;\r
+                       pAddressList->Address[cnt].lpSockaddr = (LPSOCKADDR) offset;\r
+                       RtlCopyMemory(offset, ai->ai_addr, ai->ai_addrlen);\r
+                       offset += ai->ai_addrlen;\r
+               }\r
+       }\r
+\r
+free:\r
+       freeaddrinfo(res);\r
+release:\r
+       prov->Release();\r
+       return hr;\r
+}\r
+\r
+STDMETHODIMP CNDProvider::\r
+OpenAdapter(const struct sockaddr* pAddress, SIZE_T AddressLength,\r
+                       INDAdapter** ppAdapter)\r
+{\r
+       return CNDAdapter::CreateInstance(this, pAddress, AddressLength, ppAdapter);\r
+}\r
+\r
+\r
+//-------------------------\r
+// CNDClassFactory routines\r
+//-------------------------\r
+\r
+STDMETHODIMP CNDClassFactory::\r
+QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
+{\r
+       if (riid != IID_IUnknown && riid != IID_IClassFactory) {\r
+               *ppvObj = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppvObj = this;\r
+       AddRef();\r
+       return ND_SUCCESS;\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDClassFactory::\r
+AddRef(void)\r
+{\r
+       return CNDBase::AddRef();\r
+}\r
+\r
+STDMETHODIMP_(ULONG) CNDClassFactory::\r
+Release(void)\r
+{\r
+       return CNDBase::Release();\r
+}\r
+\r
+STDMETHODIMP CNDClassFactory::\r
+CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppObject)\r
+{\r
+       if (pUnkOuter != NULL) {\r
+               return CLASS_E_NOAGGREGATION;\r
+       }\r
+\r
+       if (riid != IID_INDProvider) {\r
+               *ppObject = NULL;\r
+               return E_NOINTERFACE;\r
+       }\r
+\r
+       *ppObject = new CNDProvider();\r
+       if (*ppObject == NULL) {\r
+               return E_OUTOFMEMORY;\r
+       }\r
+\r
+       return S_OK;\r
+}\r
+\r
+STDMETHODIMP CNDClassFactory::\r
+LockServer(BOOL fLock)\r
+{\r
+       UNREFERENCED_PARAMETER(fLock);\r
+       return S_OK;\r
+}\r
diff --git a/ulp/netdirect/user/nd_provider.h b/ulp/netdirect/user/nd_provider.h
new file mode 100644 (file)
index 0000000..63278c8
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _ND_PROVIDER_H_\r
+#define _ND_PROVIDER_H_\r
+\r
+#include <initguid.h>\r
+#include <ndspi.h>\r
+#include "nd_base.h"\r
+\r
+class CNDProvider : public INDProvider, public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       // INDProvider methods\r
+       STDMETHODIMP QueryAddressList(SOCKET_ADDRESS_LIST* pAddressList,\r
+                                                                 SIZE_T* pBufferSize);\r
+       STDMETHODIMP OpenAdapter(const struct sockaddr* pAddress,\r
+                                                        SIZE_T AddressLength, INDAdapter** ppAdapter);\r
+\r
+       CNDProvider() {};\r
+       ~CNDProvider() {};\r
+       void Delete() {delete this;}\r
+};\r
+\r
+\r
+class CNDClassFactory : public IClassFactory, public CNDBase\r
+{\r
+public:\r
+       // IUnknown methods\r
+       STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
+       STDMETHODIMP_(ULONG) AddRef();\r
+       STDMETHODIMP_(ULONG) Release();\r
+\r
+       // IClassFactory methods\r
+       STDMETHODIMP CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppObject);\r
+       STDMETHODIMP LockServer(BOOL fLock);\r
+\r
+       CNDClassFactory() {};\r
+       ~CNDClassFactory() {};\r
+       void Delete() {delete this;}\r
+};\r
+\r
+#endif // _ND_PROVIDER_H_
\ No newline at end of file
diff --git a/ulp/netdirect/user/netdirect.rc b/ulp/netdirect/user/netdirect.rc
new file mode 100644 (file)
index 0000000..7ed0d78
--- /dev/null
@@ -0,0 +1,46 @@
+/*\r
+ * Copyright (c) 2008 Intel Corporation.  All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+\r
+#include <oib_ver.h>\r
+\r
+#define VER_FILETYPE                   VFT_DLL\r
+#define VER_FILESUBTYPE                        VFT2_UNKNOWN\r
+\r
+#ifdef _DEBUG_\r
+#define VER_FILEDESCRIPTION_STR                "OpenFabrics Winverbs Network Direct Provider (Debug)"\r
+#define VER_INTERNALNAME_STR           "wvndprovd.dll"\r
+#define VER_ORIGINALFILENAME_STR       "wvndprovd.dll"\r
+#else\r
+#define VER_FILEDESCRIPTION_STR                "OpenFabrics Winverbs Network Direct Provider"\r
+#define VER_INTERNALNAME_STR           "wvndprov.dll"\r
+#define VER_ORIGINALFILENAME_STR       "wvndprov.dll"\r
+#endif\r
+\r
+#include <common.ver>\r