winverbs/netdirect: add support for inline sends
[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         HRESULT hr;\r
43 \r
44         hr = m_pAdapter->m_pWvDevice->CreateCompletionQueue(&nEntries, &m_pWvCq);\r
45         return NDConvertWVStatus(hr);\r
46 }\r
47 \r
48 CNDCompletionQueue::~CNDCompletionQueue()\r
49 {\r
50         if (m_pWvCq != NULL) {\r
51                 m_pWvCq->Release();\r
52         }\r
53         m_pAdapter->Release();\r
54 }\r
55 \r
56 STDMETHODIMP CNDCompletionQueue::\r
57 QueryInterface(REFIID riid, LPVOID FAR* ppvObj)\r
58 {\r
59         if (riid != IID_IUnknown && riid != IID_INDCompletionQueue) {\r
60                 *ppvObj = NULL;\r
61                 return E_NOINTERFACE;\r
62         }\r
63 \r
64         *ppvObj = this;\r
65         AddRef();\r
66         return ND_SUCCESS;\r
67 }\r
68 \r
69 STDMETHODIMP_(ULONG) CNDCompletionQueue::\r
70 AddRef(void)\r
71 {\r
72         return CNDBase::AddRef();\r
73 }\r
74 \r
75 STDMETHODIMP_(ULONG) CNDCompletionQueue::\r
76 Release(void)\r
77 {\r
78         return CNDBase::Release();\r
79 }\r
80 \r
81 STDMETHODIMP CNDCompletionQueue::\r
82 CancelOverlappedRequests(void)\r
83 {\r
84         HRESULT hr;\r
85 \r
86         hr = m_pWvCq->CancelOverlappedRequests();\r
87         return NDConvertWVStatus(hr);\r
88 }\r
89 \r
90 STDMETHODIMP CNDCompletionQueue::\r
91 GetOverlappedResult(OVERLAPPED *pOverlapped,\r
92                                         SIZE_T *pNumberOfBytesTransferred, BOOL bWait)\r
93 {\r
94         HRESULT hr;\r
95 \r
96         hr = m_pWvCq->GetOverlappedResult(pOverlapped,\r
97                                                                           (DWORD *) pNumberOfBytesTransferred, bWait);\r
98         return NDConvertWVStatus(hr);\r
99 }\r
100 \r
101 STDMETHODIMP CNDCompletionQueue::\r
102 Resize(SIZE_T nEntries)\r
103 {\r
104         HRESULT hr;\r
105 \r
106         hr = m_pWvCq->Resize(&nEntries);\r
107         return NDConvertWVStatus(hr);\r
108 }\r
109 \r
110 STDMETHODIMP CNDCompletionQueue::\r
111 Notify(DWORD Type, OVERLAPPED* pOverlapped)\r
112 {\r
113         HRESULT hr;\r
114 \r
115         hr = m_pWvCq->Notify((WV_CQ_NOTIFY_TYPE) Type, pOverlapped);\r
116         return NDConvertWVStatus(hr);\r
117 }\r
118 \r
119 STDMETHODIMP_(SIZE_T) CNDCompletionQueue::\r
120 GetResults(ND_RESULT* pResults[], SIZE_T nResults)\r
121 {\r
122         WV_COMPLETION   comp[8];\r
123         SIZE_T                  cnt, total, i;\r
124 \r
125         for (total = 0; nResults; nResults -= cnt) {\r
126                 cnt = min(8, nResults);\r
127                 cnt = m_pWvCq->Poll(comp, cnt);\r
128                 if (cnt == 0) {\r
129                         break;\r
130                 }\r
131 \r
132                 for (i = 0; i < cnt; i++) {\r
133                         pResults[total] = (ND_RESULT *) comp[i].WrId;\r
134                         if (comp[i].Opcode & WvReceive) {\r
135                                 pResults[total]->BytesTransferred = comp[i].Length;\r
136                         }\r
137                         pResults[total++]->Status = comp[i].Status;\r
138                 }\r
139         }\r
140         return total;\r
141 }\r