[ofw] [RFC v2] winverbs implementation approach

Sean Hefty sean.hefty at intel.com
Thu Mar 13 13:55:08 PDT 2008


Here's an updated version of the IWVCompletionQueue::Create routine
taking in some of the feedback.

The coding style has been updated to match the style used in the MS toaster
samples.  The post() call is always invoked if pre() succeeds.  And a
stack buffer can be used in place of memory allocation for the IOCTL.
If someone has a clever idea on how to support this, please chime in.

If this approach looks okay with everyone, I will update the rest of the
code and submit patches for review.

- Sean
---

STDMETHODIMP CWVCompletionQueue::
Create(SIZE_T *pEntries)
{
	UINT8			buf[sizeof WV_IO_ID + 128];
	WV_IO_ID		*pId;
	DWORD			bytes;
	ib_api_status_t	stat;
	HRESULT		hr;
	ci_umv_buf_t	verbsData;
	BOOL			alloc;

	stat = m_pVerbs->pre_create_cq(m_pDevice->m_hVerbsDevice, (UINT32 *) pEntries,
						 &verbsData, &m_hVerbsCq);
	if (stat != IB_SUCCESS) {
		return WvConvertIbStatus(stat);
	}

	bytes = sizeof WV_IO_ID + max(verbsData.input_size, verbsData.output_size);
	alloc = (bytes < sizeof buf);
	if (alloc) {
		pId = (WV_IO_ID *) HeapAlloc(GetProcessHeap(), 0, bytes);
		if (pId == NULL) {
			hr = WV_NO_MEMORY;
			goto post;
		}
	} else {
		pId = (WV_IO_ID *) buf;
	}

	pId->Id = m_pDevice->m_Id;
	pId->VerbInfo = verbsData.command;
	pId->Data = (UINT32) *pEntries;
	RtlCopyMemory(pId + 1, verbsData.p_inout_buf, verbsData.input_size);

	if (DeviceIoControl(m_hFile, WV_IOCTL_CQ_CREATE,
				  pId, sizeof WV_IO_ID + verbsData.input_size,
				  pId, sizeof WV_IO_ID + verbsData.output_size,
				  &bytes, NULL)) {
		hr = WV_SUCCESS;
		m_Id = pId->Id;
		*pEntries = pId->Data;
	} else {
		hr = HRESULT_FROM_WIN32(GetLastError());
	}

	verbsData.status = pId->VerbInfo;
	RtlCopyMemory(verbsData.p_inout_buf, pId + 1, verbsData.output_size);
	if (alloc) {
		HeapFree(GetProcessHeap(), 0, pId);
	}

post:
	m_pVerbs->post_create_cq(m_pDevice->m_hVerbsDevice, (ib_api_status_t) hr,
					 (UINT32) *pEntries, &m_hVerbsCq, &verbsData);
	return hr;
}




More information about the ofw mailing list