netdirect: add winverbs ND provider
[mirror/winof/.git] / ulp / netdirect / user / nd_cq.cpp
1 /*\r
2  * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  */\r
29 \r
30 #include "nd_cq.h"\r
31 \r
32 CNDCompletionQueue::CNDCompletionQueue(CNDAdapter *pAdapter)\r
33 {\r
34         pAdapter->AddRef();\r
35         m_pAdapter = pAdapter;\r
36         m_pWvCq = NULL;\r
37 }\r
38 \r
39 STDMETHODIMP CNDCompletionQueue::\r
40 Init(SIZE_T nEntries)\r
41 {\r
42         return m_pAdapter->m_pWvDevice->CreateCompletionQueue(&nEntries, &m_pWvCq);\r
43 }\r
44 \r
45 CNDCompletionQueue::~CNDCompletionQueue()\r
46 {\r
47         if (m_pWvCq != NULL) {\r
48                 m_pWvCq->Release();\r
49         }\r
50         m_pAdapter->Release();\r
51 }\r
52 \r
53 STDMETHODIMP CNDCompletionQueue::\r
54 QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
55 {\r
56         if (riid != IID_IUnknown && riid != IID_INDCompletionQueue) {\r
57                 *ppvObj = NULL;\r
58                 return E_NOINTERFACE;\r
59         }\r
60 \r
61         *ppvObj = this;\r
62         AddRef();\r
63         return ND_SUCCESS;\r
64 }\r
65 \r
66 STDMETHODIMP_(ULONG) CNDCompletionQueue::\r
67 AddRef(void)\r
68 {\r
69         return CNDBase::AddRef();\r
70 }\r
71 \r
72 STDMETHODIMP_(ULONG) CNDCompletionQueue::\r
73 Release(void)\r
74 {\r
75         return CNDBase::Release();\r
76 }\r
77 \r
78 STDMETHODIMP CNDCompletionQueue::\r
79 CancelOverlappedRequests(void)\r
80 {\r
81         return m_pWvCq->CancelOverlappedRequests();\r
82 }\r
83 \r
84 STDMETHODIMP CNDCompletionQueue::\r
85 GetOverlappedResult(OVERLAPPED *pOverlapped,\r
86                                         SIZE_T *pNumberOfBytesTransferred, BOOL bWait)\r
87 {\r
88         return m_pWvCq->GetOverlappedResult(pOverlapped,\r
89                                                                                 (DWORD *) pNumberOfBytesTransferred, bWait);\r
90 }\r
91 \r
92 STDMETHODIMP CNDCompletionQueue::\r
93 Resize(SIZE_T nEntries)\r
94 {\r
95         return m_pWvCq->Resize(&nEntries);\r
96 }\r
97 \r
98 STDMETHODIMP CNDCompletionQueue::\r
99 Notify(DWORD Type, OVERLAPPED* pOverlapped)\r
100 {\r
101         return m_pWvCq->Notify((WV_CQ_NOTIFY_TYPE) Type, pOverlapped);\r
102 }\r
103 \r
104 STDMETHODIMP_(SIZE_T) CNDCompletionQueue::\r
105 GetResults(ND_RESULT* pResults[], SIZE_T nResults)\r
106 {\r
107         WV_COMPLETION   comp[8];\r
108         SIZE_T                  cnt, total, i;\r
109 \r
110         for (total = 0; nResults; nResults -= cnt) {\r
111                 cnt = min(8, nResults);\r
112                 cnt = m_pWvCq->Poll(comp, cnt);\r
113                 if (cnt == 0) {\r
114                         break;\r
115                 }\r
116 \r
117                 for (i = 0; i < cnt; i++) {\r
118                         pResults[total] = (ND_RESULT *) comp[i].WrId;\r
119                         pResults[total]->Status = comp[i].Status;\r
120                         pResults[total++]->BytesTransferred = comp[i].Length;\r
121                 }\r
122         }\r
123         return total;\r
124 }\r