--- /dev/null
+Bottom: b937ed604e0f514a53056550ac39de031e204f3d
+Top: 02d34126680ab0fe5b80784d79d0d5bdbf9ff7bf
+Author: U-AMR\MSHEFTY <MSHEFTY@mshefty-MOBL2.amr.corp.intel.com>
+Date: 2010-01-06 12:49:09 -0800
+
+Refresh of cm_poll
+
+---
+
+diff --git a/trunk/core/al/kernel/al_cm.c b/trunk/core/al/kernel/al_cm.c
+index 10860c4..40eb65a 100644
+--- a/trunk/core/al/kernel/al_cm.c
++++ b/trunk/core/al/kernel/al_cm.c
+@@ -109,35 +109,34 @@ cm_listen_handler(const ib_al_handle_t h_al, const net32_t cid)
+ }\r
+ \r
+ static NTSTATUS\r
+-cm_get_reqeust(iba_cm_id *p_id, iba_cm_event *p_event)\r
++cm_get_request(iba_cm_id *p_listen_id, iba_cm_id **pp_id, iba_cm_event *p_event)\r
+ {\r
+ void *context;\r
+ net32_t new_cid;\r
+ ib_mad_element_t *mad;\r
+- iba_cm_id *id, *listen_id;\r
+- iba_cm_event event;\r
+ ib_api_status_t ib_status;\r
++ NTSTATUS status;\r
+ \r
+- status = al_cep_poll(gh_al, p_id->cid, &context, &new_cid, &mad);\r
++ status = al_cep_poll(gh_al, p_listen_id->cid, &context, &new_cid, &mad);\r
+ if (ib_status != IB_SUCCESS) {\r
+ return ib_to_ntstatus(ib_status);\r
+ }\r
+ \r
+- listen_id = (iba_cm_id *) context;\r
+-\r
+- id = cm_alloc_id(listen_id->callback, listen_id);\r
+- if (id == NULL) {\r
++ *pp_id = cm_alloc_id(p_listen_id->callback, p_listen_id);\r
++ if (*pp_id == NULL) {\r
+ kal_cep_destroy(gh_al, new_cid, STATUS_NO_MORE_ENTRIES);\r
+- ib_put_mad(mad);\r
+- return STATUS_NO_MEMORY;\r
++ status = STATUS_NO_MEMORY;\r
++ goto out;\r
+ }\r
+ \r
+- kal_cep_config(gh_al, new_cid, cm_cep_handler, id, cm_destroy_handler);\r
+- id->cid = new_cid;\r
++ kal_cep_config(gh_al, new_cid, cm_cep_handler, *pp_id, cm_destroy_handler);\r
++ (*pp_id)->cid = new_cid;\r
++ kal_cep_format_event(gh_al, new_cid, mad, p_event);\r
++ status = STATUS_SUCCESS;\r
+ \r
+- kal_cep_format_event(gh_al, id->cid, mad, &event);\r
++out:\r
+ ib_put_mad(mad);\r
+- return STATUS_SUCCESS;\r
++ return status;\r
+ }\r
+ \r
+ static NTSTATUS\r
+@@ -376,6 +375,7 @@ void cm_get_interface(iba_cm_interface *p_ifc)
+ p_ifc->create_id = cm_create_id;\r
+ p_ifc->destroy_id = cm_destroy_id;\r
+ p_ifc->listen = cm_listen;\r
++ p_ifc->get_reqeust = cm_get_request;\r
+ p_ifc->send_req = cm_send_req;\r
+ p_ifc->send_rep = cm_send_rep;\r
+ p_ifc->send_rtu = cm_send_rtu;\r
+diff --git a/trunk/core/winverbs/kernel/wv_ep.c b/trunk/core/winverbs/kernel/wv_ep.c
+index 3d5c6ce..47baba1 100644
+--- a/trunk/core/winverbs/kernel/wv_ep.c
++++ b/trunk/core/winverbs/kernel/wv_ep.c
+@@ -1110,24 +1110,30 @@ complete:
+ WdfRequestComplete(Request, status);\r
+ }\r
+ \r
+-static NTSTATUS WvEpIbListenHandler(iba_cm_id *pId, iba_cm_event *pEvent)\r
++static void WvEpGetIbRequest(WV_ENDPOINT *pListen)\r
+ {\r
+- WV_ENDPOINT *listen, *ep;\r
++ WV_ENDPOINT *ep;\r
+ WDFREQUEST request;\r
+ NTSTATUS status;\r
+ IB_CMA_HEADER *hdr;\r
++ iba_cm_id *id;\r
++ iba_cm_event *event;\r
+ \r
+- listen = ((iba_cm_id *) pId->context)->context;\r
++ WdfObjectAcquireLock(pListen->Queue);\r
++ status = WdfIoQueueRetrieveNextRequest(pListen->Queue, &request);\r
++ if (!NT_SUCCESS(status)) {\r
++ goto release;\r
++ }\r
+ \r
+- WdfObjectAcquireLock(listen->Queue);\r
+- status = WdfIoQueueRetrieveNextRequest(listen->Queue, &request);\r
++ status = IbCmInterface.CM.get_request(pListen->pIbCmId, &id, &event);\r
+ if (!NT_SUCCESS(status)) {\r
++ WdfIoRequestRequeue(request);\r
+ goto release;\r
+ }\r
+ \r
+- ASSERT(!IsListEmpty(&listen->Entry));\r
+- ep = CONTAINING_RECORD(RemoveHeadList(&listen->Entry), WV_ENDPOINT, Entry);\r
+- ep->pIbCmId = pId;\r
++ ASSERT(!IsListEmpty(&pListen->Entry));\r
++ ep = CONTAINING_RECORD(RemoveHeadList(&pListen->Entry), WV_ENDPOINT, Entry);\r
++ ep->pIbCmId = id;\r
+ pId->callback = WvEpIbCmHandler;\r
+ pId->context = ep;\r
+ \r
+@@ -1162,10 +1168,68 @@ static NTSTATUS WvEpIbListenHandler(iba_cm_id *pId, iba_cm_event *pEvent)
+ \r
+ WdfRequestComplete(request, STATUS_SUCCESS);\r
+ release:\r
+- WdfObjectReleaseLock(listen->Queue);\r
++ WdfObjectReleaseLock(pListen->Queue);\r
+ return status;\r
+ }\r
+ \r
++static NTSTATUS WvEpIbListenHandler(iba_cm_id *pId, iba_cm_event *pEvent)\r
++{\r
++ WV_ENDPOINT *listen;\r
++//, *ep;\r
++// WDFREQUEST request;\r
++// NTSTATUS status;\r
++// IB_CMA_HEADER *hdr;\r
++\r
++ listen = pId->context; //((iba_cm_id *) pId->context)->context;\r
++ WvEpGetIbRequest(listen);\r
++ return STATUS_SUCCESS;\r
++// WdfObjectAcquireLock(listen->Queue);\r
++// status = WdfIoQueueRetrieveNextRequest(listen->Queue, &request);\r
++// if (!NT_SUCCESS(status)) {\r
++// goto release;\r
++// }\r
++//\r
++// ASSERT(!IsListEmpty(&listen->Entry));\r
++// ep = CONTAINING_RECORD(RemoveHeadList(&listen->Entry), WV_ENDPOINT, Entry);\r
++// ep->pIbCmId = pId;\r
++// pId->callback = WvEpIbCmHandler;\r
++// pId->context = ep;\r
++//\r
++// hdr = pEvent->data.req.req.p_pdata;\r
++// if ((hdr->IpVersion >> 4) == 4) {\r
++// ep->Attributes.LocalAddress.SockAddr.In.SinFamily = WV_AF_INET;\r
++// ep->Attributes.LocalAddress.SockAddr.In.SinAddr = hdr->DstAddress.Ip4.Address;\r
++// ep->Attributes.PeerAddress.SockAddr.In.SinFamily = WV_AF_INET;\r
++// ep->Attributes.PeerAddress.SockAddr.In.SinAddr = hdr->SrcAddress.Ip4.Address;\r
++// } else {\r
++// ep->Attributes.LocalAddress.SockAddr.In6.Sin6Family = WV_AF_INET6; \r
++// RtlCopyMemory(ep->Attributes.LocalAddress.SockAddr.In6.Sin6Addr,\r
++// hdr->DstAddress.Ip6Address, 16);\r
++// ep->Attributes.PeerAddress.SockAddr.In6.Sin6Family = WV_AF_INET6;\r
++// RtlCopyMemory(ep->Attributes.PeerAddress.SockAddr.In6.Sin6Addr,\r
++// hdr->SrcAddress.Ip6Address, 16);\r
++// }\r
++// ep->Attributes.Device.DeviceGuid = pEvent->data.req.local_ca_guid;\r
++// ep->Attributes.Device.Pkey = pEvent->data.req.req.p_primary_path->pkey;\r
++// ep->Attributes.Device.PortNumber = pEvent->data.req.port_num;\r
++// ep->Attributes.Param.Connect.ResponderResources = pEvent->data.req.req.resp_res;\r
++// ep->Attributes.Param.Connect.InitiatorDepth = pEvent->data.req.req.init_depth;\r
++// ep->Attributes.Param.Connect.RetryCount = pEvent->data.req.req.retry_cnt;\r
++// ep->Attributes.Param.Connect.RnrRetryCount = pEvent->data.req.req.rnr_retry_cnt;\r
++// ep->Attributes.Param.Connect.DataLength = sizeof(ep->Attributes.Param.Connect.Data);\r
++// RtlCopyMemory(ep->Attributes.Param.Connect.Data, hdr + 1,\r
++// sizeof(ep->Attributes.Param.Connect.Data));\r
++// ep->Route = *pEvent->data.req.req.p_primary_path;\r
++//\r
++// ep->State = WvEpPassiveConnect;\r
++// WvEpPut(ep);\r
++//\r
++// WdfRequestComplete(request, STATUS_SUCCESS);\r
++//release:\r
++// WdfObjectReleaseLock(listen->Queue);\r
++// return status;\r
++}\r
++\r
+ void WvEpListen(WV_PROVIDER *pProvider, WDFREQUEST Request)\r
+ {\r
+ WV_ENDPOINT *ep;\r
+@@ -1235,24 +1299,24 @@ void WvEpGetRequest(WV_PROVIDER *pProvider, WDFREQUEST Request)
+ status = WdfRequestRetrieveInputBuffer(Request, sizeof(WV_IO_EP_GET_REQUEST),\r
+ &req, NULL);\r
+ if (!NT_SUCCESS(status)) {\r
+- goto complete;\r
++ goto err1;\r
+ }\r
+ \r
+ listen = WvEpAcquire(pProvider, req->Id);\r
+ if (listen == NULL) {\r
+ status = STATUS_NOT_FOUND;\r
+- goto complete;\r
++ goto err1;\r
+ }\r
+ \r
+ if (listen->State != WvEpListening) {\r
+ status = STATUS_NOT_SUPPORTED;\r
+- goto release1;\r
++ goto err2;\r
+ }\r
+ \r
+ ep = WvEpAcquire(pProvider, req->EpId);\r
+ if (ep == NULL) {\r
+ status = STATUS_NOT_FOUND;\r
+- goto release1;\r
++ goto err2;\r
+ }\r
+ \r
+ WdfObjectAcquireLock(ep->Queue);\r
+@@ -1262,9 +1326,8 @@ void WvEpGetRequest(WV_PROVIDER *pProvider, WDFREQUEST Request)
+ status = STATUS_CONNECTION_IN_USE;\r
+ }\r
+ WdfObjectReleaseLock(ep->Queue);\r
+-\r
+ if (!NT_SUCCESS(status)) {\r
+- goto release2;\r
++ goto err3;\r
+ }\r
+ \r
+ WdfObjectAcquireLock(listen->Queue);\r
+@@ -1274,15 +1337,21 @@ void WvEpGetRequest(WV_PROVIDER *pProvider, WDFREQUEST Request)
+ WvEpGet(ep);\r
+ }\r
+ WdfObjectReleaseLock(listen->Queue);\r
++ if (!NT_SUCCESS(status)) {\r
++ goto err3;\r
++ }\r
+ \r
+-release2:\r
+ WvEpRelease(ep);\r
+-release1:\r
++ WvEpGetIbRequest(listen);\r
+ WvEpRelease(listen);\r
+-complete:\r
+- if (!NT_SUCCESS(status)) {\r
+- WdfRequestComplete(Request, status);\r
+- }\r
++ return;\r
++\r
++err3:\r
++ WvEpRelease(ep);\r
++err2:\r
++ WvEpRelease(listen);\r
++err1:\r
++ WdfRequestComplete(Request, status);\r
+ }\r
+ \r
+ void WvEpLookup(WV_PROVIDER *pProvider, WDFREQUEST Request)\r
+diff --git a/trunk/inc/kernel/iba/ib_cm_ifc.h b/trunk/inc/kernel/iba/ib_cm_ifc.h
+index 07626e5..5cc2d07 100644
+--- a/trunk/inc/kernel/iba/ib_cm_ifc.h
++++ b/trunk/inc/kernel/iba/ib_cm_ifc.h
+@@ -239,7 +239,8 @@ typedef struct _iba_cm_interface
+ \r
+ NTSTATUS (*listen)(iba_cm_id *p_id, net64_t service_id, void *p_compare_buf,\r
+ uint8_t compare_len, uint8_t compare_offset);\r
+- NTSTATUS (*get_reqeust)(iba_cm_id *p_id, iba_cm_event *p_event);\r
++ NTSTATUS (*get_request)(iba_cm_id *p_listen_id, iba_cm_id **pp_id,\r
++ iba_cm_event *p_event);\r
+ \r
+ NTSTATUS (*send_req)(iba_cm_id *p_id, iba_cm_req *p_req);\r
+ NTSTATUS (*send_rep)(iba_cm_id *p_id, iba_cm_rep *p_rep);