--- C:/Documents and Settings/scsmith/Local Settings/Temp/ipoib_port.cpp-revBASE.svn000.tmp.cpp	Tue Jul 13 10:54:33 2010
+++ C:/Documents and Settings/scsmith/My Documents/openIB-windows/SVN/gen1/trunk/ulp/ipoib_NDIS6_CM/kernel/ipoib_port.cpp	Tue Jul 13 10:57:06 2010
@@ -786,12 +786,12 @@
 		return status;
 	}
 
-	 KeInitializeDpc(&p_port->recv_dpc,(PKDEFERRED_ROUTINE)__recv_cb_dpc,p_port);
+	KeInitializeDpc(&p_port->recv_dpc,(PKDEFERRED_ROUTINE)__recv_cb_dpc,p_port);
 
 
 	 /* Initialize multicast garbage collector timer and DPC object */
-	 KeInitializeDpc(&p_port->gc_dpc,(PKDEFERRED_ROUTINE)__port_mcast_garbage_dpc,p_port);
-	 KeInitializeTimerEx(&p_port->gc_timer,SynchronizationTimer);
+	KeInitializeDpc(&p_port->gc_dpc,(PKDEFERRED_ROUTINE)__port_mcast_garbage_dpc,p_port);
+	KeInitializeTimerEx(&p_port->gc_timer,SynchronizationTimer);
 
 	/* We only ever destroy from the PnP callback thread. */
 	cl_status = cl_obj_init( &p_port->obj, CL_DESTROY_SYNC,
@@ -1028,8 +1028,10 @@
 #endif
 
 	/* Allocate the PD. */
-	status = p_port->p_adapter->p_ifc->alloc_pd(
-		p_port->ib_mgr.h_ca, IB_PDT_UD, p_port, &p_port->ib_mgr.h_pd );
+	status = p_port->p_adapter->p_ifc->alloc_pd( p_port->ib_mgr.h_ca,
+												 IB_PDT_UD,
+												 p_port,
+												 &p_port->ib_mgr.h_pd );
 	if( status != IB_SUCCESS )
 	{
 		NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
@@ -1045,9 +1047,11 @@
 	cq_create.pfn_comp_cb = __recv_cb;
 	cq_create.h_wait_obj = NULL;
 
-	status = p_port->p_adapter->p_ifc->create_cq(
-		p_port->ib_mgr.h_ca, &cq_create, p_port,
-		__cq_event, &p_port->ib_mgr.h_recv_cq );
+	status = p_port->p_adapter->p_ifc->create_cq( p_port->ib_mgr.h_ca,
+												  &cq_create,
+												  p_port,
+												  __cq_event,
+												  &p_port->ib_mgr.h_recv_cq );
 	if( status != IB_SUCCESS )
 	{
 		NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
@@ -1062,9 +1066,11 @@
 	cq_create.size = p_port->p_adapter->params.sq_depth;
 	cq_create.pfn_comp_cb = __send_cb;
 
-	status = p_port->p_adapter->p_ifc->create_cq(
-		p_port->ib_mgr.h_ca, &cq_create, p_port,
-		__cq_event, &p_port->ib_mgr.h_send_cq );
+	status = p_port->p_adapter->p_ifc->create_cq( p_port->ib_mgr.h_ca,
+												  &cq_create,
+												  p_port,
+												  __cq_event,
+												  &p_port->ib_mgr.h_send_cq );
 	if( status != IB_SUCCESS )
 	{
 		NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
@@ -1105,15 +1111,15 @@
 		!! (p_port->p_adapter->params.send_chksum_offload);
 	p_port->p_adapter->offload_cap.recv_chksum_offload = 
 		!! (p_port->p_adapter->params.recv_chksum_offload);
-	
-	
-	
-	
+
 	qp_create.h_sq_cq = p_port->ib_mgr.h_send_cq;
 	qp_create.sq_signaled = FALSE;
-	status = p_port->p_adapter->p_ifc->create_qp(
-		p_port->ib_mgr.h_pd, &qp_create, p_port,
-		__qp_event, &p_port->ib_mgr.h_qp );
+
+	status = p_port->p_adapter->p_ifc->create_qp( p_port->ib_mgr.h_pd,
+												  &qp_create,
+												  p_port,
+												  __qp_event,
+												  &p_port->ib_mgr.h_qp );
 	if( status != IB_SUCCESS )
 	{
 		NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
@@ -1124,8 +1130,7 @@
 		return status;
 	}
 	/* Query the QP so we can get our QPN. */
-	status = p_port->p_adapter->p_ifc->query_qp(
-		p_port->ib_mgr.h_qp, &qp_attr );
+	status = p_port->p_adapter->p_ifc->query_qp( p_port->ib_mgr.h_qp, &qp_attr );
 	if( status != IB_SUCCESS )
 	{
 		NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
@@ -1147,9 +1152,12 @@
 	phys_range.base_addr = 0;
 	phys_range.size = MEM_REG_SIZE;
 	vaddr = 0;
-	status = p_port->p_adapter->p_ifc->reg_phys(
-		p_port->ib_mgr.h_pd, &phys_create, &vaddr,
-		&p_port->ib_mgr.lkey, &rkey, &p_port->ib_mgr.h_mr );
+	status = p_port->p_adapter->p_ifc->reg_phys( p_port->ib_mgr.h_pd,
+												 &phys_create,
+												 &vaddr,
+												 &p_port->ib_mgr.lkey,
+												 &rkey,
+												 &p_port->ib_mgr.h_mr );
 	if( status != IB_SUCCESS )
 	{
 		NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
@@ -1393,6 +1401,7 @@
 	cl_status_t		cl_status;
 	ipoib_params_t	*p_params;
 	NET_BUFFER_LIST_POOL_PARAMETERS pool_parameters;
+
 	IPOIB_ENTER(IPOIB_DBG_INIT );
 
 	CL_ASSERT( p_port );
@@ -1453,7 +1462,8 @@
 		NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
 			EVENT_IPOIB_SEND_PKT_POOL, 1, NDIS_STATUS_RESOURCES );
 		IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-			("NdisAllocatePacketPool returned %08X\n", (UINT)NDIS_STATUS_RESOURCES) );
+			("NdisAllocatePacketPool returned %08X\n",
+			(UINT)NDIS_STATUS_RESOURCES) );
 		return IB_INSUFFICIENT_RESOURCES;
 	}
 
@@ -1859,8 +1869,7 @@
 
 inline ULONG __free_received_NBL (
 	IN ipoib_port_t		*p_port,
-	IN NET_BUFFER_LIST 	*p_net_buffer_lists
-	) 
+	IN NET_BUFFER_LIST 	*p_net_buffer_lists ) 
 {
 
 	ipoib_recv_desc_t	*p_desc;
@@ -1970,11 +1979,8 @@
 	UNREFERENCED_PARAMETER(s_arg1);
 	UNREFERENCED_PARAMETER(s_arg2);
 
-
 	__recv_cb(NULL, p_port);
 	ipoib_port_deref( p_port, ref_recv_cb );
-
-
 }
 
 
@@ -3110,10 +3116,8 @@
 
 	chksum.Value = 0;
 
-
 	PNET_BUFFER NetBuffer = NET_BUFFER_LIST_FIRST_NB(*pp_net_buffer_list);
 	NET_BUFFER_DATA_LENGTH(NetBuffer) = p_desc->len;
-
 	
 	switch( p_port->p_adapter->params.recv_chksum_offload )
 	{
@@ -3233,7 +3237,6 @@
 	cl_qpool_construct( &p_port->send_mgr.send_pool );
 	p_port->p_desc = NULL;
 	IPOIB_EXIT( IPOIB_DBG_SEND );
-	
 }
 
 static ib_api_status_t
@@ -3250,9 +3253,15 @@
 	static const ULONG 	MaxNumBuffers(16384);
 	
 	/* Allocate the pool for async NETBUF flow (process_sg_list) */
-	cl_status = cl_qpool_init( &p_port->send_mgr.sg_pool,
-		MaxNumBuffers,
-		0, cPoolDeltaSize, sizeof(cl_pool_item_t) + p_port->p_adapter->sg_list_size, NULL, NULL, p_port );
+	cl_status = cl_qpool_init(
+					&p_port->send_mgr.sg_pool,
+					MaxNumBuffers,
+					0,
+					cPoolDeltaSize,
+					sizeof(cl_pool_item_t) + p_port->p_adapter->sg_list_size,
+					NULL,
+					NULL,
+					p_port );
 	
 	if( cl_status != CL_SUCCESS )
 	{
@@ -3265,8 +3274,13 @@
 	}
 
 	cl_status = cl_qpool_init( &p_port->send_mgr.send_pool,
-		MaxNumBuffers,
-		0, cPoolDeltaSize, sizeof(ipoib_send_NB_SG), NULL, NULL, p_port );
+							   MaxNumBuffers,
+							   0,
+							   cPoolDeltaSize,
+							   sizeof(ipoib_send_NB_SG),
+							   NULL,
+							   NULL,
+							   p_port );
 	
 	if( cl_status != CL_SUCCESS )
 	{
@@ -3291,9 +3305,7 @@
 		cl_qpool_destroy(&p_port->send_mgr.sg_pool);
 		return IB_INSUFFICIENT_MEMORY;
 	}
-
 	return IB_SUCCESS;
-
 }
 
 
@@ -3733,20 +3745,20 @@
 
 
 // returns true if buffer was sent
+
 bool 
 ipoib_process_sg_list_real(
     IN  PDEVICE_OBJECT          pDO,
     IN  PVOID                   pIrp,
     IN  PSCATTER_GATHER_LIST    p_sgl,
-    IN  PVOID                   context
-    )
+    IN  PVOID                   context )
 {	
 	NDIS_STATUS				status;
 	ipoib_port_t			*p_port;
 	MDL						*p_mdl;
 	eth_hdr_t				*p_eth_hdr;
 	UINT					mdl_len;
-	bool ret = false;
+	bool					ret = false;
 
 	ib_send_wr_t			*p_wr_failed;
 	NET_BUFFER_LIST			*p_net_buffer_list;
@@ -3770,7 +3782,6 @@
 	PERF_DECLARE( PostSend );
 	PERF_DECLARE( ProcessFailedSends );
 	PERF_DECLARE( GetEndpt );
-
 	
 	++g_ipoib_send_SG_real;
 
@@ -3784,12 +3795,10 @@
 	IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_SEND,
 				("Processing netbuffer list: %p \n", p_net_buffer_list) );
 
-
 	//TODO Define this function as void if we are not in DBG mode
 	//cl_qlist_check_validity(&p_port->send_mgr.pending_list);
 	NDIS_SET_SEND_COMPLETE_FLAG(complete_flags, NDIS_SEND_COMPLETE_FLAGS_DISPATCH_LEVEL);
 	CL_ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
-
 	
 	p_port->p_desc->p_netbuf_list = p_net_buffer_list;
 	p_port->p_desc->p_endpt = NULL;
@@ -3797,18 +3806,21 @@
 	p_port->p_desc->num_wrs = 1;
 
 	IPOIB_PRINT( TRACE_LEVEL_VERBOSE, IPOIB_DBG_SEND,
-						("\nRECEIVED NB= %p with SG= %p\n********\n", p_netbuf, p_sgl) );
+			("\nRECEIVED NB= %p with SG= %p\n********\n", p_netbuf, p_sgl) );
+
 	/* Get the ethernet header so we can find the endpoint. */
 	cl_perf_start( GetEthHdr );
-	status = __send_mgr_get_eth_hdr(
-		p_netbuf, &p_mdl, &p_eth_hdr, &mdl_len );
+
+	status = __send_mgr_get_eth_hdr( p_netbuf, &p_mdl, &p_eth_hdr, &mdl_len );
+
 	cl_perf_stop( &p_port->p_adapter->perf, GetEthHdr );
 
 	if( status != NDIS_STATUS_SUCCESS )
 	{
 		cl_perf_start( ProcessFailedSends );
 		/* fail  net buffer */
-		IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,("Failed send inside process SG list\n"));
+		IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
+					("Failed to get Eth hdr - send inside process SG list\n"));
 		__send_complete_net_buffer(s_buf, status, complete_flags, TRUE);
 		
 		cl_perf_stop( &p_port->p_adapter->perf, ProcessFailedSends );
@@ -3816,6 +3828,7 @@
 		goto send_end;
 	}
 	from_queue = (boolean_t)(s_buf->p_sgl != NULL);
+
 	if (from_queue)
 	{
 		cl_perf_start( GetEndpt );
@@ -3827,7 +3840,9 @@
 			s_buf->p_sgl = p_sgl;
 			cl_qlist_insert_head( &p_port->send_mgr.pending_list,
 				(cl_list_item_t*)s_buf  );
-			IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_MCAST, ("We insert this item back to the pending list: %p \n", p_net_buffer_list));
+			IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_MCAST,
+				("We insert this item back to the pending list: %p \n",
+				p_net_buffer_list));
 			ret = false;
 			goto send_end;
 		}
@@ -3923,7 +3938,11 @@
 
 mc_end:
 		ASSERT(s_buf->p_sgl);
-		status = __send_mgr_queue( p_port, p_eth_hdr, &(p_port->p_desc->p_endpt) );
+
+		status = __send_mgr_queue( p_port,
+								   p_eth_hdr,
+								   &(p_port->p_desc->p_endpt) );
+
 		cl_perf_stop( &p_port->p_adapter->perf, SendMgrQueue );
 		if( status == NDIS_STATUS_PENDING )
 		{
@@ -3938,6 +3957,7 @@
 			ret = false;
 			goto send_end;
 		}
+
 		if( status != NDIS_STATUS_SUCCESS )
 		{
 			ASSERT( status == NDIS_STATUS_NO_ROUTE_TO_DESTINATION );
@@ -3947,14 +3967,20 @@
 			 */
 			 //TODO - check previous comment !
 			cl_perf_start( ProcessFailedSends );
-			__send_complete_net_buffer(s_buf, NDIS_STATUS_SUCCESS, complete_flags, TRUE);
+			__send_complete_net_buffer( s_buf, NDIS_STATUS_SUCCESS,
+										complete_flags, TRUE);
 			cl_perf_stop( &p_port->p_adapter->perf, ProcessFailedSends );
 			ret = true;
 			goto send_end;
 		}
 	}
 	cl_perf_start( BuildSendDesc );
-	status = __build_send_desc( p_eth_hdr, p_mdl, mdl_len, s_buf );
+	status = __build_send_desc( p_eth_hdr,
+								p_mdl,
+								mdl_len,
+								s_buf,
+								p_desc );
+
 	cl_perf_stop( &p_port->p_adapter->perf, BuildSendDesc );
 
 	if( status != NDIS_STATUS_SUCCESS )
@@ -4003,27 +4029,24 @@
     IN  PDEVICE_OBJECT          pDO,
     IN  PVOID                   pIrp,
     IN  PSCATTER_GATHER_LIST    p_sgl,
-    IN  PVOID                   context
-    )
+    IN  PVOID                   context )
 {
-
-
 	ipoib_send_NB_SG *  s_buf = (ipoib_send_NB_SG *)context;
-	ipoib_port_t* p_port = 			s_buf->p_port;
-
+	ipoib_port_t*		p_port = s_buf->p_port;
 
 	cl_spinlock_acquire( &p_port->send_lock );
+
 	++g_ipoib_send_SG;
 	if (g_ipoib_send_SG > 2) {
 		//ASSERT(g_ipoib_send_SG-2 <= g_ipoib_send + g_ipoib_send_mcast+p_port->send_mgr.pending_list.count+ g_ipoib_send_SG_failed);
 	}
+
 	ipoib_process_sg_list_real(pDO, pIrp, p_sgl, context);
+
 	if (g_ipoib_send_SG > 1) {
 		//ASSERT(g_ipoib_send_SG-1 <= g_ipoib_send + g_ipoib_send_mcast+p_port->send_mgr.pending_list.count + g_ipoib_send_SG_failed);
 	}
 	cl_spinlock_release( &p_port->send_lock );
-
-	
 }
 
 
@@ -4353,8 +4376,8 @@
 	case IGMP_V2_MEMBERSHIP_REPORT:
 		/* 
 			This mean that some body open listener on this group 
-			Change type of mcast endpt to SEND_RECV endpt. So mcast garbage collector 
-			will not delete this mcast endpt.
+			Change type of mcast endpt to SEND_RECV endpt. So mcast garbage
+			collector will not delete this mcast endpt.
 		*/
 		IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_MCAST,
 			("Catched IGMP_V2_MEMBERSHIP_REPORT message\n") );
@@ -4970,8 +4993,6 @@
 	        ASSERT(mss == p_lso_info->LsoV2Transmit.MSS);
 	        ASSERT(p_lso_info->LsoV1Transmit.TcpHeaderOffset == p_lso_info->LsoV2Transmit.TcpHeaderOffset);
 	    }
-			
-			
 	}
 			
 	/* Format the send descriptor. */
@@ -5003,10 +5024,10 @@
 			return status;
 		}
 	}
-	
 	else
 	{
 		uint32_t	i;
+
 		cl_perf_start( SendMgrFilter );
 		status = __send_mgr_filter( p_eth_hdr, p_mdl, mdl_len, s_buf );
 		cl_perf_stop( &p_port->p_adapter->perf, SendMgrFilter );
@@ -5063,12 +5084,9 @@
 		}
 		
 		p_desc->send_wr[p_desc->num_wrs - 1].wr.wr_id = (uintn_t)s_buf ;
-
 		p_desc->send_wr[p_desc->num_wrs - 1].wr.send_opt |= IB_SEND_OPT_SIGNALED;
 		p_desc->send_wr[p_desc->num_wrs - 1].wr.p_next = NULL;
 	}
-
-
 	
 	IPOIB_EXIT( IPOIB_DBG_SEND );
 	return NDIS_STATUS_SUCCESS;
@@ -5322,8 +5340,6 @@
 }
 
 
-
-
 void
 ipoib_port_send(
 	IN				ipoib_port_t* const			p_port,
@@ -5360,8 +5376,6 @@
 	cl_obj_lock( &p_port->obj );
 	if( p_port->state != IB_QPS_RTS )
 	{
-		
-		
 		cl_obj_unlock( &p_port->obj );
 		
 		IPOIB_PRINT( TRACE_LEVEL_VERBOSE, IPOIB_DBG_SEND,
@@ -5399,6 +5413,7 @@
 				("Processing netbuffer list: %p buf_cnt = %d\n", p_net_buffer_list, buf_cnt));
 
 	ASSERT(buf_cnt);
+
 	// Raise reference count of the NBL to the number of its NBs
 	IPOIB_GET_NET_BUFFER_LIST_REF_COUNT(p_net_buffer_list) = (PVOID)(ULONG_PTR)buf_cnt;
 
@@ -5419,7 +5434,6 @@
 				break;
 		}
 			
-
 		//Set all the data needed for process_sg_list
 		s_buf->p_port = p_port;
 		s_buf->p_sgl = NULL;
@@ -5429,10 +5443,10 @@
 		//TODO remove this line from process_sg_real
 		s_buf->p_send_buf = NULL;
 		
-
 		//We can also define p_sg_buf as a static member of send_buf,
 		// But the problem is that we don't know it's size
-		if (s_buf->p_sg_buf == NULL) {
+		if (s_buf->p_sg_buf == NULL)
+		{
 			s_buf->p_sg_buf = (PVOID) cl_qpool_get(&p_port->send_mgr.sg_pool);
 		}
 		
@@ -5440,8 +5454,6 @@
 		
 		IPOIB_PRINT( TRACE_LEVEL_VERBOSE, IPOIB_DBG_SEND,
 				("Netbuf to send = %p\n", p_netbuf) );
-
-
 #if 0
 			CHAR *pTemp = (CHAR *) ExAllocatePoolWithTag(NonPagedPool , p_port->p_adapter->sg_list_size, 'abcd');
 			CL_ASSERT(pTemp != NULL);
@@ -5497,7 +5509,10 @@
 	}
 		
 	cl_spinlock_release( &p_port->send_lock );
+
 	NDIS_LOWER_IRQL(old_irql, DISPATCH_LEVEL);
+
+	IPOIB_EXIT( IPOIB_DBG_SEND );
 }
 
 static inline void 
@@ -5507,13 +5522,10 @@
 	IN	ULONG				compl_flags,
 	IN	boolean_t			bLock	) 
 {
-
 	CL_ASSERT( s_buf );
 	
-	
 	IPOIB_PRINT(TRACE_LEVEL_VERBOSE, IPOIB_DBG_SEND,
-		("Processing send completion for NBL=0x%p .\n",  s_buf->p_nbl ));
-	
+		("Processing send completion for NBL=0x%p .\n", s_buf->p_nbl ));
 	
 	// Free SGL element allocated by NDIS
 	// We should do it before freeing the whole NBL
@@ -5522,7 +5534,8 @@
 							s_buf->p_sgl,
 							s_buf->p_curr_nb);
 	
-	// No need to delete p_sg_buf at this state, we will destroy the whole list at the end of the execution
+	// No need to delete p_sg_buf at this state, we will destroy the whole list
+	// at the end of the execution
 	//NET_BUFFER_LIST_NEXT_NBL(p_desc->p_netbuf_list) = NULL;
 #if 0
 	if (NET_BUFFER_LIST_STATUS(s_buf->p_nbl) != NDIS_STATUS_FAILURE) {
@@ -5588,7 +5601,6 @@
 		}
 	} 
 
-								
 	if( s_buf->p_send_buf )
 	{
 		cl_perf_start( FreeSendBuf );
@@ -5617,7 +5629,6 @@
 }
 
 
-
 void
 ipoib_port_resume(
 	IN				ipoib_port_t* const			p_port,
@@ -5668,7 +5679,6 @@
 			/* Check the send queue and pend the request if not empty. */
 			if( p_port->send_mgr.depth == p_port->p_adapter->params.sq_depth )
 			{
-			    
 				IPOIB_PRINT( TRACE_LEVEL_WARNING, IPOIB_DBG_SEND,
 					("No available WQEs.\n") );
 				cl_qlist_insert_head( &p_port->send_mgr.pending_list, p_item  );
@@ -5718,7 +5728,6 @@
  
 	IPOIB_ENTER( IPOIB_DBG_SEND );
 
-
 	ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
 
 	cl_perf_clr( SendCompBundle );
@@ -5727,9 +5736,7 @@
 
 	UNUSED_PARAM( h_cq );
 
-	
 	cl_qlist_init( &done_list );
-	
 
 	p_port = (ipoib_port_t*)cq_context;
 	cl_spinlock_acquire( &p_port->send_lock );
@@ -5836,7 +5843,6 @@
 	//cl_qlist_check_validity(&p_port->send_mgr.pending_list);
 	cl_spinlock_release( &p_port->send_lock );
 	IPOIB_EXIT( IPOIB_DBG_SEND );
-	
 }
 
 
@@ -6159,7 +6165,7 @@
 		
 	}
 #endif
-		cl_obj_unlock( &p_port->obj );
+	cl_obj_unlock( &p_port->obj );
 
 	//TODO CM
 	/*while( cl_qlist_count( &conn_list ) )
