[ofw] [PATCH] ipoib-CM 8 of 13

Smith, Stan stan.smith at intel.com
Tue Jan 11 18:31:41 PST 2011


signed-off-by: stan smith <stan.smith at intel.com>

--- A/ulp/ipoib_NDIS6_CM/kernel/ipoib_endpoint.cpp      Tue Jan 11 17:57:08 2011
+++ B/ulp/ipoib_NDIS6_CM/kernel/ipoib_endpoint.cpp      Tue Jan 11 12:45:31 2011
@@ -33,13 +33,12 @@

 #include <precompile.h>

-
 #if defined(EVENT_TRACING)
 #ifdef offsetof
 #undef offsetof
-#endif
 #include "ipoib_endpoint.tmh"
 #endif
+#endif
 #include <complib/cl_atomic.h>
 #include <complib/cl_math.h>

@@ -75,74 +74,6 @@
 __endpt_resolve(
        IN                              ipoib_endpt_t* const            p_endpt );

-static void
-__endpt_cm_send_cb(
-       IN              const   ib_cq_handle_t                  h_cq,
-       IN                              void                                    *cq_context );
-static void
-__endpt_cm_recv_cb(
-       IN              const   ib_cq_handle_t                  h_cq,
-       IN                              void                                    *cq_context );
-
-static void
-__endpt_cm_buf_mgr_construct(
-       IN              endpt_buf_mgr_t * const         p_buf_mgr );
-static void
-__conn_reply_cb(
-       IN              ib_cm_rep_rec_t                 *p_cm_rep );
-
-static void
-__conn_mra_cb(
-       IN              ib_cm_mra_rec_t                 *p_mra_rec );
-
-static void
-__conn_rej_cb(
-       IN              ib_cm_rej_rec_t                 *p_rej_rec );
-
-static void
-__conn_dreq_cb(
-        IN     ib_cm_dreq_rec_t                        *p_dreq_rec );
-
-#if 0 //CM
-static cl_status_t
-__cm_recv_desc_ctor(
-       IN              void* const                                     p_object,
-       IN              void*                                           context,
-       OUT             cl_pool_item_t** const          pp_pool_item );
-
-static void
-__cm_recv_desc_dtor(
-       IN              const   cl_pool_item_t* const           p_pool_item,
-       IN                              void                                            *context );
-
-static NDIS_PACKET*
-__endpt_cm_get_ndis_pkt(
-       IN              ipoib_port_t* const                     p_port,
-       IN              ipoib_cm_desc_t* const          p_desc );
-
-static inline ipoib_cm_desc_t*
-__endpt_cm_buf_mgr_get_recv(
-       IN              endpt_buf_mgr_t * const         p_buf_mgr );
-
-static boolean_t
-__cm_recv_is_dhcp(
-       IN              const ipoib_pkt_t* const        p_ipoib );
-
-static ib_api_status_t
-__endpt_cm_recv_arp(
-       IN              ipoib_port_t* const                     p_port,
-       IN              const   ipoib_pkt_t* const      p_ipoib,
-       OUT             eth_pkt_t* const                        p_eth,
-       IN              ipoib_endpt_t* const            p_src_endpt );
-
-static ib_api_status_t
-__endpt_cm_recv_udp(
-       IN              ipoib_port_t* const                     p_port,
-       IN              ib_wc_t* const                          p_wc,
-       IN              const   ipoib_pkt_t* const      p_ipoib,
-       OUT             eth_pkt_t* const                        p_eth,
-       IN              ipoib_endpt_t* const            p_src_endpt );
-#endif

 ipoib_endpt_t*
 ipoib_endpt_create(
@@ -173,15 +104,33 @@
                                                  __endpt_cleanup,
                                                  __endpt_free );

-       IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_ENDPT,
-               ("Created EndPoint %p DLID: %#x QPN: %#x \n",
-                       p_endpt, cl_ntoh16(dlid), cl_ntoh32(qpn) ) );
-
        p_endpt->dgid = *p_dgid;
        p_endpt->dlid = dlid;
        p_endpt->qpn = qpn;
        p_endpt->p_ifc = p_port->p_adapter->p_ifc;

+       if( dlid == 0 && qpn == CL_HTON32(0x00FFFFFF) )
+       {
+               // see ipoib_port_join_mcast()
+               StringCbCopy(p_endpt->tag,sizeof(p_endpt->tag),"<MCast>");
+       }
+       else
+       {
+               StringCchPrintf( p_endpt->tag,
+                                                sizeof(p_endpt->tag),
+                                                "<lid-%#x>",
+                                                cl_ntoh16(dlid) );
+       }
+
+       DIPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_ENDPT,
+               ("Created EndPoint %p %s DLID: %#x QPN: %#x\n",
+                       p_endpt, p_endpt->tag, cl_ntoh16(dlid), cl_ntoh32(qpn) ) );
+
+       p_endpt->tx_mtu = p_port->p_adapter->params.payload_mtu; // start with UD mtu
+
+       if( p_port->p_adapter->params.cm_enabled )
+               cl_qlist_init( &p_endpt->cm_recv.done_list );
+
        IPOIB_EXIT( IPOIB_DBG_ENDPT );
        return p_endpt;
 }
@@ -245,10 +194,7 @@
        IPOIB_ENTER( IPOIB_DBG_ENDPT );

        IPOIB_PRINT(TRACE_LEVEL_INFORMATION, IPOIB_DBG_ENDPT,
-               ("Create av for MAC: %02X-%02X-%02X-%02X-%02X-%02X\n",
-               p_endpt->mac.addr[0], p_endpt->mac.addr[1],
-               p_endpt->mac.addr[2], p_endpt->mac.addr[3],
-               p_endpt->mac.addr[4], p_endpt->mac.addr[5]) );
+               ("Create av for MAC: %s\n", mk_mac_str(&p_endpt->mac)) );

        status = __create_mcast_av( h_pd, port_num, p_mcast_rec->p_member_rec,
                &p_endpt->h_av );
@@ -282,29 +228,42 @@
        cl_obj_lock( p_obj );
        if( p_endpt->h_query )
        {
-               p_port->p_adapter->p_ifc->cancel_query( p_port->p_adapter->h_al,
-                                                                                               p_endpt->h_query );
+               p_endpt->p_ifc->cancel_query( p_port->p_adapter->h_al, p_endpt->h_query );
                p_endpt->h_query = NULL;
        }

        /* Leave the multicast group if it exists. */
        if( p_endpt->h_mcast )
        {
-               IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_ENDPT,
-                       ("Leaving MCast group\n") );
+               IPOIB_PRINT( TRACE_LEVEL_VERBOSE, IPOIB_DBG_ENDPT,
+                       ("Port[%d] EP %s Leaving MCast group\n",
+                               p_port->port_num, p_endpt->tag) );
+
                ipoib_port_ref(p_port, ref_leave_mcast);
-               p_port->p_adapter->p_ifc->leave_mcast( p_endpt->h_mcast,
-                                                                                          ipoib_leave_mcast_cb );
+               p_endpt->p_ifc->leave_mcast( p_endpt->h_mcast,
+                                                                        ipoib_leave_mcast_cb );
+               p_endpt->h_mcast = NULL;
        }
-#if 0
-       else if( p_port->p_adapter->params.cm_enabled )
+
+       if( p_port->p_adapter->params.cm_enabled )
        {
+               cm_state_t      cstate = endpt_cm_get_state( p_endpt );
+
+               if( cstate != IPOIB_CM_DISCONNECTED && !p_endpt->cm_ep_destroy )
+               {
+                       IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
+                               ("Port[%d] EP %s %s != CM_DISCONNECTED?\n",
+                                       p_port->port_num, p_endpt->tag, cm_get_state_str(cstate)) );
+               }
                p_endpt->cm_flag = 0;
-               CL_ASSERT( endpt_cm_get_state( p_endpt ) == IPOIB_CM_DISCONNECTED );
        }
-#endif

        cl_obj_unlock( p_obj );
+
+#if DBG
+       ipoib_port_deref( p_port, ref_endpt_track );
+       dmp_ipoib_port_refs( p_port, "endpt_destroying()" );
+#endif

        IPOIB_EXIT( IPOIB_DBG_ENDPT );
 }
@@ -324,7 +283,7 @@

        /* Destroy the AV if it exists. */
        if( p_endpt->h_av )
-               p_port->p_adapter->p_ifc->destroy_av( p_endpt->h_av );
+               p_endpt->p_ifc->destroy_av( p_endpt->h_av );

        IPOIB_EXIT( IPOIB_DBG_ENDPT );
 }
@@ -374,11 +333,11 @@
        ib_av_attr_t    av_attr;
        net32_t                 flow_lbl;

-       IPOIB_ENTER( IPOIB_DBG_ENDPT );
+       IPOIB_ENTER( IPOIB_DBG_MCAST );

        if( p_endpt->h_av )
        {
-               IPOIB_EXIT( IPOIB_DBG_ENDPT );
+               IPOIB_EXIT( IPOIB_DBG_MCAST );
                return NDIS_STATUS_SUCCESS;
        }

@@ -395,7 +354,8 @@
                IPOIB_PRINT( TRACE_LEVEL_WARNING, IPOIB_DBG_SEND ,
                        ("Got the race between the mcast callback and a receive/send\n"));
                ipoib_endpt_deref( p_endpt );
-               IPOIB_EXIT( IPOIB_DBG_ENDPT );
+
+               IPOIB_EXIT( IPOIB_DBG_MCAST );
                return NDIS_STATUS_PENDING;
        }

@@ -420,8 +380,8 @@
         * using LIDs only.
         */
        av_attr.grh_valid = TRUE;
-       av_attr.grh.ver_class_flow = ib_grh_set_ver_class_flow(
-               6, p_port->ib_mgr.bcast_rec.tclass, flow_lbl );
+       av_attr.grh.ver_class_flow =
+               ib_grh_set_ver_class_flow( 6, p_port->ib_mgr.bcast_rec.tclass, flow_lbl );
        av_attr.grh.resv1 = 0;
        av_attr.grh.resv2 = 0;
        ib_gid_set_default( &av_attr.grh.src_gid,
@@ -432,9 +392,9 @@
        av_attr.path_bits = 0;

        /* Create the AV. */
-       status = p_port->p_adapter->p_ifc->create_av( p_port->ib_mgr.h_pd,
-                                                                                                 &av_attr,
-                                                                                                 &p_endpt->h_av );
+       status = p_endpt->p_ifc->create_av( p_port->ib_mgr.h_pd,
+                                                                               &av_attr,
+                                                                               &p_endpt->h_av );
        if( status != IB_SUCCESS )
        {
                p_port->p_adapter->hung = TRUE;
@@ -442,7 +402,7 @@
                cl_obj_unlock( &p_endpt->obj );
                IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
                        ("ib_create_av failed with %s\n",
-                       p_port->p_adapter->p_ifc->get_err_str( status )) );
+                       p_endpt->p_ifc->get_err_str( status )) );
                return NDIS_STATUS_FAILURE;
        }

@@ -450,734 +410,136 @@
        return NDIS_STATUS_SUCCESS;
 }

-#if 0
-
-static void
-__endpt_cm_buf_mgr_construct(
-       IN              endpt_buf_mgr_t * const         p_buf_mgr )
-{
-       IPOIB_ENTER( IPOIB_DBG_INIT );
-
-       cl_qpool_construct( &p_buf_mgr->recv_pool );
-
-       p_buf_mgr->h_packet_pool = NULL;
-       p_buf_mgr->h_buffer_pool = NULL;
-
-       IPOIB_EXIT( IPOIB_DBG_INIT );
-}
-
-ib_api_status_t
-endpt_cm_buf_mgr_init(
-       IN                              ipoib_port_t* const                             p_port )
-{
-       cl_status_t             cl_status;
-       NDIS_STATUS             ndis_status;
-       ib_api_status_t ib_status = IB_SUCCESS;
-
-       IPOIB_ENTER( IPOIB_DBG_INIT );
-
-       if( p_port->cm_buf_mgr.pool_init )
-               return ib_status;
-
-       cl_qlist_init( &p_port->cm_buf_mgr.posted_list );
-
-       __endpt_cm_buf_mgr_construct( &p_port->cm_buf_mgr );
-       p_port->cm_recv_mgr.rq_depth =
-               min( (uint32_t)p_port->p_adapter->params.rq_depth * 8,
-                               p_port->p_ca_attrs->max_srq_wrs/2 );
-       p_port->cm_recv_mgr.depth = 0;
-       /* Allocate the receive descriptors pool */
-       cl_status = cl_qpool_init( &p_port->cm_buf_mgr.recv_pool,
-               p_port->cm_recv_mgr.rq_depth ,
-               0,
-               0,
-               sizeof( ipoib_cm_desc_t ),
-               __cm_recv_desc_ctor,
-               __cm_recv_desc_dtor,
-               p_port );
-
-       if( cl_status != CL_SUCCESS )
-       {
-               NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
-                       EVENT_IPOIB_RECV_POOL, 1, cl_status );
-               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("cl_qpool_init(cm_buf_mgr.recv_pool) returned %#x\n", cl_status) );
-               return IB_INSUFFICIENT_MEMORY;
-       }
-
-       /* Allocate the NDIS buffer and packet pools for receive indication. */
-       NdisAllocatePacketPool( &ndis_status,
-                                                       &p_port->cm_buf_mgr.h_packet_pool,
-                                                       p_port->cm_recv_mgr.rq_depth,
-                                                       PROTOCOL_RESERVED_SIZE_IN_PACKET );
-       if( ndis_status != NDIS_STATUS_SUCCESS )
-       {
-               NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
-                       EVENT_IPOIB_RECV_PKT_POOL, 1, ndis_status );
-
-               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("NdisAllocatePacketPool returned %08X\n", ndis_status) );
-
-               ib_status = IB_INSUFFICIENT_RESOURCES;
-               goto pkt_pool_failed;
-       }
-
-       NdisAllocateBufferPool( &ndis_status,
-                                                       &p_port->cm_buf_mgr.h_buffer_pool,
-                                                       p_port->cm_recv_mgr.rq_depth );
-       if( ndis_status != NDIS_STATUS_SUCCESS )
-       {
-               NdisWriteErrorLogEntry( p_port->p_adapter->h_adapter,
-                       EVENT_IPOIB_RECV_BUF_POOL, 1, ndis_status );
-
-               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("NdisAllocateBufferPool returned %08X\n", ndis_status) );
-
-               ib_status = IB_INSUFFICIENT_RESOURCES;
-               goto buf_pool_failed;
-       }
-       //NDIS60
-       //p_port->cm_recv_mgr.recv_pkt_array =
-               //cl_zalloc( sizeof(NDIS_PACKET*) * p_port->cm_recv_mgr.rq_depth );
-       p_port->cm_recv_mgr.recv_lst_array =
-               cl_zalloc( sizeof(NET_BUFFER_LIST*) * p_port->cm_recv_mgr.rq_depth );
-
-
-
-       if( !p_port->cm_recv_mgr.recv_NBL_array )
-       {
-               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("cl_zalloc for cm_recv_mgr NET_BUFFER_LIST array failed.\n") );
-
-               ib_status = IB_INSUFFICIENT_MEMORY;
-               goto pkt_array_failed;
-       }
-
-       p_port->cm_buf_mgr.pool_init = TRUE;
-       return IB_SUCCESS;
-
-
-pkt_array_failed:
-       if( p_port->cm_buf_mgr.h_buffer_pool )
-               NdisFreeBufferPool( p_port->cm_buf_mgr.h_buffer_pool );
-buf_pool_failed:
-       if( p_port->cm_buf_mgr.h_packet_pool )
-               NdisFreePacketPool( p_port->cm_buf_mgr.h_packet_pool );
-pkt_pool_failed:
-               cl_qpool_destroy( &p_port->cm_buf_mgr.recv_pool );
-
-       IPOIB_EXIT( IPOIB_DBG_INIT );
-       return ib_status;
-}
-
+/* port obj is locked */

 void
-endpt_cm_buf_mgr_reset(
-       IN              ipoib_port_t* const             p_port )
+endpt_unmap_conn_dgid(
+       IN              ipoib_port_t* const                     p_port,
+       IN              ipoib_endpt_t* const            p_endpt )
 {
-       cl_list_item_t          *p_item;
-
-       if( !p_port->cm_buf_mgr.pool_init )
-               return;
+       cl_fmap_item_t* p_fmap_item;

-       if( cl_qlist_count( &p_port->cm_buf_mgr.posted_list ) )
+       if( p_port->p_adapter->params.cm_enabled )
        {
-               for( p_item = cl_qlist_remove_head( &p_port->cm_buf_mgr.posted_list );
-                       p_item != cl_qlist_end( &p_port->cm_buf_mgr.posted_list );
-                       p_item =  cl_qlist_remove_head( &p_port->cm_buf_mgr.posted_list ) )
+               p_fmap_item = cl_fmap_get( &p_port->endpt_mgr.conn_endpts, &p_endpt->dgid );
+
+               if( p_fmap_item != cl_fmap_end( &p_port->endpt_mgr.conn_endpts ) )
                {
-                       cl_qpool_put( &p_port->cm_buf_mgr.recv_pool,
-                               &( PARENT_STRUCT( p_item, ipoib_cm_desc_t, list_item ))->item );
+                       cl_fmap_remove_item( &p_port->endpt_mgr.conn_endpts,
+                                                                &p_endpt->conn_item );
+                       DIPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_CM_DCONN,
+                               ("Port[%u] EP %s %s\n",
+                                       p_port->port_num, p_endpt->tag,
+                                       cm_get_state_str(endpt_cm_get_state(p_endpt))) );
                }
        }
 }

-void
-endpt_cm_buf_mgr_destroy(
-       IN              ipoib_port_t* const             p_port )
-{
-
-       IPOIB_ENTER(IPOIB_DBG_INIT );
-
-       CL_ASSERT( p_port );
-
-       /* Free the receive descriptors. */
-       if( !p_port->cm_buf_mgr.pool_init )
-               return;
-
-       endpt_cm_buf_mgr_reset( p_port );
-
-       p_port->cm_buf_mgr.pool_init = FALSE;
-
-       if( p_port->cm_recv_mgr.recv_NBL_array )
-       {
-               cl_free( p_port->cm_recv_mgr.recv_NBL_array );
-       }
-
-       /* Destroy the receive packet and buffer pools. */
-       if( p_port->cm_buf_mgr.h_buffer_pool )
-               NdisFreeBufferPool( p_port->cm_buf_mgr.h_buffer_pool );
-       if( p_port->cm_buf_mgr.h_packet_pool )
-               NdisFreePacketPool( p_port->cm_buf_mgr.h_packet_pool );
-
-       cl_qpool_destroy( &p_port->cm_buf_mgr.recv_pool );
-
-       IPOIB_EXIT(  IPOIB_DBG_INIT );
-}
-
-static cl_status_t
-__cm_recv_desc_ctor(
-       IN                              void* const                                     p_object,
-       IN                              void*                                           context,
-               OUT                     cl_pool_item_t** const          pp_pool_item )
-{
-       ipoib_cm_desc_t*        p_desc;
-       ipoib_port_t*           p_port;
-       ib_mr_create_t          create_mr;
-       net32_t                         rkey;
-
-       CL_ASSERT( p_object );
-       CL_ASSERT( context );
-
-       p_desc = (ipoib_cm_desc_t*)p_object;
-       p_port = (ipoib_port_t*)context;
-
-#define BUF_ALIGN              (16)
-
-       p_desc->alloc_buf_size =
-               ROUNDUP( p_port->p_adapter->params.cm_xfer_block_size, BUF_ALIGN );
-
-       p_desc->p_alloc_buf = (uint8_t *)ExAllocatePoolWithTag(
-               NonPagedPool, p_desc->alloc_buf_size, 'DOMC' );
-
-       if( p_desc->p_alloc_buf == NULL )
-       {
-               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("Failed to allocate CM recv buffer size %d bytes.\n",
-                       p_desc->alloc_buf_size ) );
-               return CL_INSUFFICIENT_MEMORY;
-       }
-
-       create_mr.vaddr  = p_desc->p_alloc_buf;
-       create_mr.length  = p_desc->alloc_buf_size;
-       create_mr.access_ctrl = IB_AC_LOCAL_WRITE;
-
-       if( p_port->p_adapter->p_ifc->reg_mem( p_port->ib_mgr.h_pd,
-                                                                                  &create_mr,
-                                                                                  &p_desc->lkey,
-                                                                                  &rkey,
-                                                                                  &p_desc->h_mr ) != IB_SUCCESS )
-       {
-               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("Failed to create Memory Region size %d bytes.\n",
-                       p_desc->alloc_buf_size ) );
-               goto ctor_failed;
-       }
-       p_desc->p_buf = p_desc->p_alloc_buf + (BUF_ALIGN - sizeof( ipoib_hdr_t));
-       p_desc->buf_size = p_desc->alloc_buf_size - (BUF_ALIGN - sizeof( ipoib_hdr_t));
-
-       /* Setup the local data segment. */
-       p_desc->local_ds[0].vaddr = (uint64_t)(uintn_t)p_desc->p_buf;
-       p_desc->local_ds[0].length = p_desc->buf_size;
-       p_desc->local_ds[0].lkey = p_desc->lkey;
-
-       /* Setup the work request. */
-       p_desc->wr.wr_id = (uintn_t)p_desc;
-       p_desc->wr.ds_array = p_desc->local_ds;
-       p_desc->wr.num_ds = 1;
-
-       p_desc->type = PKT_TYPE_CM_UCAST;
-
-       *pp_pool_item = &p_desc->item;
-
-       return CL_SUCCESS;
-
-ctor_failed:
-       ExFreePoolWithTag( p_desc->p_alloc_buf, 'DOMC' );
-       return CL_INSUFFICIENT_MEMORY;
-}
-
-static void
-__cm_recv_desc_dtor(
-       IN              const   cl_pool_item_t* const           p_pool_item,
-       IN                              void                                            *context )
-{
-       ipoib_cm_desc_t *p_desc;
-       ipoib_port_t*   p_port;
-
-       if( p_pool_item == NULL || context == NULL )
-               return;
-
-       p_port = (ipoib_port_t*)context;
-       p_desc = PARENT_STRUCT( p_pool_item, ipoib_cm_desc_t, item );
-
-       if( p_desc->h_mr )
-               p_port->p_adapter->p_ifc->dereg_mr( p_desc->h_mr );
-
-       if( p_desc->p_alloc_buf )
-               ExFreePoolWithTag( p_desc->p_alloc_buf, 'DOMC' );
-}
-
-
-static NDIS_PACKET*
-__endpt_cm_get_ndis_pkt(
-       IN              ipoib_port_t* const                     p_port,
-       IN              ipoib_cm_desc_t* const  p_desc )
-{
-       NDIS_STATUS                             status;
-       NDIS_PACKET                             *p_packet;
-       NDIS_BUFFER                             *p_buffer;
-
-       IPOIB_ENTER(  IPOIB_DBG_RECV );
-
-       NdisDprAllocatePacketNonInterlocked( &status, &p_packet,
-                       p_port->cm_buf_mgr.h_packet_pool );
-       if( status != NDIS_STATUS_SUCCESS )
-       {
-               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("Failed to allocate NDIS_PACKET: %08x\n", status) );
-               return NULL;
-       }
-
-       IPOIB_PORT_FROM_PACKET( p_packet ) = p_port;
-       IPOIB_RECV_FROM_PACKET( p_packet ) = p_desc;
-
-       NdisAllocateBuffer(
-                       &status,
-                       &p_buffer,
-                       p_port->cm_buf_mgr.h_buffer_pool,
-                       (void *)(p_desc->p_buf - DATA_OFFSET),
-                       p_desc->len + DATA_OFFSET );
-
-       if( status != NDIS_STATUS_SUCCESS )
-       {
-               IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("Failed to allocate NDIS_BUFFER: %08x\n", status) );
-               NdisDprFreePacketNonInterlocked( p_packet );
-               return NULL;
-       }
-
-       NdisChainBufferAtFront( p_packet, p_buffer );
-       NDIS_SET_PACKET_HEADER_SIZE( p_packet, sizeof(eth_hdr_t) );
-
-       IPOIB_EXIT(  IPOIB_DBG_RECV );
-       return p_packet;
-}
-
-static inline ipoib_cm_desc_t*
-__endpt_cm_buf_mgr_get_recv(
-       IN              endpt_buf_mgr_t * const         p_buf_mgr )
-{
-       ipoib_cm_desc_t *p_desc;
-
-       p_desc = (ipoib_cm_desc_t*)cl_qpool_get( &p_buf_mgr->recv_pool );
-       if( p_desc )
-               cl_qlist_insert_tail( &p_buf_mgr->posted_list, &p_desc->list_item );
-
-       return p_desc;
-}

 void
-endpt_cm_buf_mgr_put_recv(
-       IN              endpt_buf_mgr_t * const         p_buf_mgr,
-       IN              ipoib_cm_desc_t* const  p_desc )
+ipoib_endpt_cm_mgr_thread( IN void* p_context )
 {
-
-       IPOIB_ENTER(IPOIB_DBG_RECV );
-
-       /* Return the descriptor to it's pool. */
-       cl_qlist_remove_item( &p_buf_mgr->posted_list, &p_desc->list_item );
-       cl_qpool_put( &p_buf_mgr->recv_pool, &p_desc->item );
-
-       IPOIB_EXIT(  IPOIB_DBG_RECV );
-}
-
-void
-endpt_cm_buf_mgr_put_recv_list(
-       IN              endpt_buf_mgr_t * const         p_buf_mgr,
-       IN              cl_qlist_t* const                       p_list )
-{
-       cl_qpool_put_list( &p_buf_mgr->recv_pool, p_list );
-}
-
-uint32_t
-endpt_cm_recv_mgr_build_pkt_array(
-       IN                      ipoib_port_t* const                     p_port,
-       IN                      ipoib_endpt_t* const            p_endpt,
-       IN                      cl_qlist_t* const                       p_done_list,
-       IN OUT          uint32_t*                                       p_bytes_recv )
-{
-       cl_list_item_t                  *p_item;
-       ipoib_cm_desc_t         *p_desc;
-       uint32_t                                i = 0;
-       NDIS_PACKET                             *p_packet;
-       NDIS_TCP_IP_CHECKSUM_PACKET_INFO        chksum;
-
-       IPOIB_ENTER( IPOIB_DBG_RECV );
-       UNUSED_PARAM( p_endpt );
-
-       p_item = cl_qlist_remove_head( p_done_list );
+       ib_api_status_t ib_status;
+       LIST_ENTRY              *p_item;
+       ipoib_endpt_t   *p_endpt;
+       ipoib_port_t    *p_port =( ipoib_port_t *)p_context;

-       *p_bytes_recv = 0;
-
-       for( p_item; p_item != cl_qlist_end( p_done_list );
-               p_item = cl_qlist_remove_head( p_done_list ) )
-       {
-               p_desc = (ipoib_cm_desc_t*)p_item;
-
-               p_packet = __endpt_cm_get_ndis_pkt( p_port, p_desc );
-               if( !p_packet )
-               {
-                       IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                               ("Failed to get Packet from descriptor\n" ) );
-                       endpt_cm_buf_mgr_put_recv( &p_port->cm_buf_mgr, p_desc );
-                       p_port->cm_recv_mgr.depth--;
-                       continue;
-               }
-               chksum.Value = 0;
-               switch( p_port->p_adapter->params.recv_chksum_offload )
-               {
-               default:
-                       CL_ASSERT( FALSE );
-               case CSUM_DISABLED:
-               case CSUM_ENABLED:
-               NDIS_PER_PACKET_INFO_FROM_PACKET( p_packet, TcpIpChecksumPacketInfo ) =
-                               (void*)(uintn_t)chksum.Value;
-                       break;
-               case CSUM_BYPASS:
-                       /* Flag the checksums as having been calculated. */
-                       chksum.Receive.NdisPacketTcpChecksumSucceeded = TRUE;
-                       chksum.Receive.NdisPacketUdpChecksumSucceeded = TRUE;
-                       chksum.Receive.NdisPacketIpChecksumSucceeded = TRUE;
-                       NDIS_PER_PACKET_INFO_FROM_PACKET( p_packet, TcpIpChecksumPacketInfo ) =
-                               (void*)(uintn_t)chksum.Value;
-                       break;
-               }
-
-               NDIS_SET_PACKET_STATUS( p_packet, NDIS_STATUS_SUCCESS );
-               p_port->cm_recv_mgr.recv_NBL_array[i] = p_packet;
-               i++;
-               *p_bytes_recv += p_desc->len;
-       }
-
-       IPOIB_EXIT( IPOIB_DBG_RECV );
-       return i;
-}
-void
-endpt_cm_flush_recv(
-       IN                              ipoib_port_t* const             p_port,
-       IN                              ipoib_endpt_t* const    p_endpt )
-{
-       ib_api_status_t         ib_status = IB_SUCCESS;
-       ib_qp_mod_t                     mod_attr;
-       ib_wc_t                         wc[MAX_RECV_WC];
-       ib_wc_t                         *p_free_wc;
-       ib_wc_t                         *p_done_wc;
-       ib_wc_t                         *p_wc;
-       ipoib_cm_desc_t         *p_desc;
-
-       IPOIB_ENTER( IPOIB_DBG_RECV );
-
-       CL_ASSERT( p_endpt );
+       IPOIB_ENTER( IPOIB_DBG_CM );

-       if( p_endpt->conn.h_recv_qp )
-       {
-               memset( &mod_attr, 0, sizeof( mod_attr ) );
-               mod_attr.req_state = IB_QPS_ERROR;
-               p_port->p_adapter->p_ifc->modify_qp( p_endpt->conn.h_send_qp, &mod_attr );
-               p_port->p_adapter->p_ifc->modify_qp( p_endpt->conn.h_recv_qp, &mod_attr );
-
-               for( p_free_wc=wc; p_free_wc < &wc[MAX_RECV_WC - 1]; p_free_wc++ )
-                       p_free_wc->p_next = p_free_wc + 1;
-               p_free_wc->p_next = NULL;
+       IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_INIT,
+               ("Port[%d] Starting Endpt CM thread\n", p_port->port_num ) );

-               do
-               {
-                       p_free_wc = wc;
-                       ib_status =
-                               p_port->p_adapter->p_ifc->poll_cq( p_endpt->conn.h_recv_cq,
-                               &p_free_wc, &p_done_wc );
-                       if( ib_status != IB_SUCCESS &&
-                               ib_status != IB_NOT_FOUND )
-                       {
-                               /* connection CQ failed */
-                               IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                                       ("Poll Recv CQ failed status %#x\n", ib_status ) );
-                               break;
-                       }
-                       cl_spinlock_acquire( &p_port->recv_lock );
-                       for( p_wc = p_done_wc; p_wc; p_wc = p_wc->p_next )
-                       {
-                               p_desc = (ipoib_cm_desc_t *)(uintn_t)p_wc->wr_id;
-                               endpt_cm_buf_mgr_put_recv( &p_port->cm_buf_mgr, p_desc );
-                               p_port->cm_recv_mgr.depth--;
-                       }
-                       cl_spinlock_release( &p_port->recv_lock );
-               } while( !p_free_wc );
+       ipoib_port_ref(p_port, ref_endpt_track ); /* keep the port around */

-               ib_status = p_port->p_adapter->p_ifc->destroy_qp( p_endpt->conn.h_recv_qp, NULL );
-               if( ib_status != IB_SUCCESS )
-               {
-                       IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                               ("Destroy Recv QP failed status %#x\n", ib_status ) );
-               }
-               p_endpt->conn.h_recv_qp = NULL;
-       }
-
-       if( p_endpt->conn.h_send_qp )
+       while( !p_port->endpt_mgr.thread_is_done )
        {
-               ib_status = p_port->p_adapter->p_ifc->destroy_qp( p_endpt->conn.h_send_qp, NULL );
-               if( ib_status != IB_SUCCESS )
+               cl_event_wait_on( &p_port->endpt_mgr.event, EVENT_NO_TIMEOUT, FALSE );
+
+               while( ( p_item = NdisInterlockedRemoveHeadList(
+                                                               &p_port->endpt_mgr.pending_conns,
+                                                               &p_port->endpt_mgr.conn_lock) ) != NULL )
                {
-                       IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                               ("Destroy Send QP failed status %#x\n", ib_status ) );
-               }
-               p_endpt->conn.h_send_qp = NULL;
-       }
-
-       IPOIB_EXIT( IPOIB_DBG_RECV );
-}
-
-int32_t
-endpt_cm_recv_mgr_filter(
-       IN              ipoib_endpt_t* const            p_endpt,
-       IN              ib_wc_t* const                          p_done_wc_list,
-       OUT             cl_qlist_t* const                       p_done_list,
-       OUT             cl_qlist_t* const                       p_bad_list )
-{
-       ib_api_status_t                 ib_status;
-       ipoib_cm_desc_t                 *p_desc;
-       ib_wc_t                                 *p_wc;
-       ipoib_pkt_t                             *p_ipoib;
-       eth_pkt_t                               *p_eth;
-       ipoib_port_t*                   p_port;
-       int32_t                                 recv_cnt;
-
-       IPOIB_ENTER( IPOIB_DBG_RECV );
-
-       p_port = ipoib_endpt_parent( p_endpt );
+                       p_endpt = PARENT_STRUCT( p_item, ipoib_endpt_t, list_item );

-       for( p_wc = p_done_wc_list, recv_cnt = 0; p_wc; p_wc = p_wc->p_next )
-       {
-               p_desc = (ipoib_cm_desc_t *)(uintn_t)p_wc->wr_id;
-               recv_cnt++;
-               if(  p_wc->status != IB_WCS_SUCCESS )
-               {
-                       if( p_wc->status != IB_WCS_WR_FLUSHED_ERR )
-                       {
-
-                               IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                                       ("Failed completion %s  (vendor specific %#x)\n",
-                                       p_port->p_adapter->p_ifc->get_wc_status_str( p_wc->status ),
-                                       (int)p_wc->vendor_specific) );
-                       }
-                       else
+                       /* EndPoint being destroyed after queued for connection?
+                        * or Port down in progress or System shutdown?
+                        * Just walk away...
+                        */
+                       if( p_port->endpt_mgr.thread_is_done || p_endpt->cm_ep_destroy )
                        {
-                               IPOIB_PRINT(TRACE_LEVEL_INFORMATION, IPOIB_DBG_RECV,
-                                       ("Flushed completion %s\n",
-                                       p_port->p_adapter->p_ifc->get_wc_status_str( p_wc->status )) );
+                               endpt_cm_set_state( p_endpt, IPOIB_CM_DISCONNECTED );
+                               continue;
                        }
-
-                       ipoib_inc_recv_stat( p_port->p_adapter, IP_STAT_ERROR, 0, 0 );
+                       endpt_cm_set_state( p_endpt, IPOIB_CM_CONNECTING );

-                       cl_qlist_remove_item( &p_port->cm_buf_mgr.posted_list, &p_desc->list_item );
-                       cl_qlist_insert_tail( p_bad_list, &p_desc->item.list_item );
-                       continue;
-               }
+                       ib_status = endpt_cm_connect( p_endpt );

-               /* Successful completion
-                Setup the ethernet/ip/arp header and queue descriptor for report. */
-               ib_status = IB_SUCCESS;
-               p_ipoib = (ipoib_pkt_t *)((uint8_t*)p_desc->p_buf );
-               p_eth = (eth_pkt_t *)((uint8_t*)p_desc->p_buf - DATA_OFFSET );
-
-               switch( p_ipoib->hdr.type )
-               {
-               case ETH_PROT_TYPE_ARP:
-                       if( p_wc->length < (sizeof(ipoib_hdr_t) + sizeof(ipoib_arp_pkt_t)) )
+                       if( (ib_status != IB_SUCCESS && ib_status != IB_PENDING)
+                                || p_endpt->cm_ep_destroy )
                        {
                                IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                               ("Received ARP packet too short (wc_len %d)\n", p_wc->length) );
-                               ib_status = IB_ERROR;
-                               break;
+                                       ("Connect to Endpt %s failed %s\n",
+                                               p_endpt->tag, p_endpt->p_ifc->get_err_str(ib_status)) );
+                               endpt_cm_set_state( p_endpt, IPOIB_CM_DISCONNECTED );
+                               cm_release_resources( p_port, p_endpt, 1 );
+
+                               /* if rx_flushing then obj destroy handled in async_err callback */
+                               if( p_endpt->cm_ep_destroy && !p_endpt->cm_rx_flushing)
+                               {
+                                       IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
+                                               ("Destroy EP %s Object\n", p_endpt->tag) );
+                                       cl_obj_destroy( &p_endpt->obj );
+                               }
                        }
-                       ib_status = __endpt_cm_recv_arp( p_port, p_ipoib, p_eth, p_endpt );
-                       break;
+               }//while( p_item != NULL )

-               case ETH_PROT_TYPE_IP:
-                       if( p_wc->length < (sizeof(ipoib_hdr_t) + sizeof(ip_hdr_t)) )
-                       {
-                               IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                                       ("Received IP packet too short (wc_len %d)\n", p_wc->length) );
-                               ib_status = IB_ERROR;
-                               break;
-                       }
-                       if( p_ipoib->type.ip.hdr.prot == IP_PROT_UDP )
-                       {
-                               ib_status = __endpt_cm_recv_udp( p_port,
-                                                                                                p_wc,
-                                                                                                p_ipoib,
-                                                                                                p_eth,
-                                                                                                p_endpt );
-                       }
-
-                       break;
-               }
-
-               if( ib_status != IB_SUCCESS )
+               while( ( p_item = NdisInterlockedRemoveHeadList(
+                                                               &p_port->endpt_mgr.remove_conns,
+                                                               &p_port->endpt_mgr.remove_lock ) ) != NULL )
                {
-                       ipoib_inc_recv_stat( p_port->p_adapter, IP_STAT_ERROR, 0, 0 );
-                       cl_qlist_insert_tail( p_bad_list, &p_desc->item.list_item );
-                       continue;
-               }
+                       cm_state_t      old_state, cstate;

-               p_eth->hdr.type = p_ipoib->hdr.type;
-               p_eth->hdr.src = p_endpt->mac;
-               p_eth->hdr.dst = p_port->p_adapter->mac;
+                       p_endpt = PARENT_STRUCT( p_item, ipoib_endpt_t, list_item );

-               /* save payload length */
-               p_desc->len = p_wc->length;
-
-               cl_qlist_insert_tail( p_done_list, &p_desc->item.list_item );
-       }
-
-       IPOIB_EXIT( IPOIB_DBG_RECV );
-       return recv_cnt;
-}
+                       cstate = endpt_cm_get_state( p_endpt );

-ib_api_status_t
-endpt_cm_post_recv(
-       IN              ipoib_port_t* const                     p_port )
-{
-       ib_api_status_t         ib_status = IB_SUCCESS;
-       ipoib_cm_desc_t         *p_head_desc = NULL;
-       ipoib_cm_desc_t         *p_tail_desc = NULL;
-       ipoib_cm_desc_t         *p_next_desc;
-       ib_recv_wr_t            *p_failed_wc = NULL;
-
-       IPOIB_ENTER( IPOIB_DBG_RECV );
-
-       while( cl_qpool_count( &p_port->cm_buf_mgr.recv_pool )  > 1  )
-       {
-                       /* Pull receives out of the pool and chain them up. */
-               p_next_desc = __endpt_cm_buf_mgr_get_recv(
-                                                                       &p_port->cm_buf_mgr );
-               if( !p_next_desc )
-               {
-                       IPOIB_PRINT(TRACE_LEVEL_INFORMATION, IPOIB_DBG_RECV,
-                               ("Out of receive descriptors! Endpt recv queue depth 0x%x\n",
-                               p_port->cm_recv_mgr.depth ) );
-                       break;
-               }
-
-               if( !p_tail_desc )
-               {
-                       p_tail_desc = p_next_desc;
-                       p_next_desc->wr.p_next = NULL;
-               }
-               else
-               {
-                       p_next_desc->wr.p_next = &p_head_desc->wr;
-               }
-
-               p_head_desc = p_next_desc;
-
-               p_port->cm_recv_mgr.depth++;
-       }
-
-       if( p_head_desc )
-       {
-               ib_status = p_port->p_adapter->p_ifc->post_srq_recv(
-                       p_port->ib_mgr.h_srq, &p_head_desc->wr, &p_failed_wc );
-
-               if( ib_status != IB_SUCCESS )
-               {
-                       IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                               ("ip_post_recv returned %s\n",
-                               p_port->p_adapter->p_ifc->get_err_str( ib_status )) );
-
-                       /* put descriptors back to the pool */
-                       while( p_failed_wc )
+                       if( cstate == IPOIB_CM_DISCONNECT_CLEANUP )
                        {
-                               p_head_desc = PARENT_STRUCT( p_failed_wc, ipoib_cm_desc_t, wr );
-                               p_failed_wc = p_failed_wc->p_next;
-                               endpt_cm_buf_mgr_put_recv( &p_port->cm_buf_mgr, p_head_desc );
-                               p_port->cm_recv_mgr.depth--;
+                               /* Conn was Rejected, cleanup CM TX resources, EP still UD valid */
+                               IPOIB_PRINT( TRACE_LEVEL_WARNING, IPOIB_DBG_CM,
+                                       ("CM Tx Cleanup Endpoint %s MAC %s\n\n",
+                                               p_endpt->tag, mk_mac_str(&p_endpt->mac)) );
+                               cl_obj_lock( &p_port->obj );
+                               endpt_unmap_conn_dgid( p_port, p_endpt );
+                               cl_obj_unlock( &p_port->obj );
+                               cm_release_resources( p_port, p_endpt, 1 );
+                               endpt_cm_set_state( p_endpt, IPOIB_CM_DISCONNECTED );
+                               continue;
                        }
-               }
-       }

+                       old_state = endpt_cm_set_state( p_endpt, IPOIB_CM_DESTROY );

-       IPOIB_EXIT( IPOIB_DBG_RECV );
-       return( ib_status );
-}
+                       IPOIB_PRINT( TRACE_LEVEL_WARNING, IPOIB_DBG_CM,
+                               ("\nDESTROYING Endpoint[%p] %s MAC %s\n\n",
+                                       p_endpt, p_endpt->tag, mk_mac_str(&p_endpt->mac)) );

-static ib_api_status_t
-__endpt_cm_recv_arp(
-       IN              ipoib_port_t* const                             p_port,
-       IN              const   ipoib_pkt_t* const              p_ipoib,
-       OUT             eth_pkt_t* const                                p_eth,
-       IN              ipoib_endpt_t* const                    p_src_endpt )
-{
-       const ipoib_arp_pkt_t   *p_ib_arp;
-       arp_pkt_t                               *p_arp;
-
-       p_ib_arp = &p_ipoib->type.arp;
-       p_arp = &p_eth->type.arp;
-
-       if( p_ib_arp->hw_type != ARP_HW_TYPE_IB ||
-               p_ib_arp->hw_size != sizeof(ipoib_hw_addr_t) ||
-               p_ib_arp->prot_type != ETH_PROT_TYPE_IP )
-       {
-               return IB_ERROR;
+                       if( old_state == IPOIB_CM_CONNECTED )
+                               endpt_cm_disconnect( p_endpt );
+                       cm_release_resources( p_port, p_endpt, 0 );
+                       endpt_cm_set_state( p_endpt, IPOIB_CM_DISCONNECTED );
+                       cl_obj_destroy( &p_endpt->obj );
+               }
        }
-
-       p_arp->hw_type = ARP_HW_TYPE_ETH;
-       p_arp->hw_size = sizeof(mac_addr_t);
-       p_arp->src_hw = p_src_endpt->mac;
-       p_arp->src_ip = p_ib_arp->src_ip;
-       p_arp->dst_hw = p_port->p_local_endpt->mac;
-       p_arp->dst_ip = p_ib_arp->dst_ip;
+       p_port->endpt_mgr.thread_is_done++;

-       return IB_SUCCESS;
-}
+       NdisFreeSpinLock( &p_port->endpt_mgr.remove_lock );
+       NdisFreeSpinLock( &p_port->endpt_mgr.conn_lock );
+
+       IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_INIT,
+               (" Port [%d] Endpt_mgr thread exit\n", p_port->port_num) );

-static ib_api_status_t
-__endpt_cm_recv_udp(
-       IN      ipoib_port_t* const     p_port,
-       IN                      ib_wc_t* const                          p_wc,
-       IN              const   ipoib_pkt_t* const              p_ipoib,
-       OUT                     eth_pkt_t* const                        p_eth,
-       IN                      ipoib_endpt_t* const            p_src_endpt )
-{
-       ib_api_status_t                 ib_status = IB_SUCCESS;
+       ipoib_port_deref(p_port, ref_endpt_track );     /* allow port to go away */

-       if( p_wc->length <
-               (sizeof(ipoib_hdr_t) + sizeof(ip_hdr_t) + sizeof(udp_hdr_t)) )
-       {
-               IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
-                       ("Received UDP packet too short\n") );
-               return IB_ERROR;
-       }
-       if( __cm_recv_is_dhcp( p_ipoib ) )
-       {
-               ib_status = ipoib_recv_dhcp( p_port,
-                                                                        p_ipoib,
-                                                                        p_eth,
-                                                                        p_src_endpt,
-                                                                        p_port->p_local_endpt );
-       }
-
-       return ib_status;
+       IPOIB_EXIT( IPOIB_DBG_CM );
 }

-static boolean_t
-__cm_recv_is_dhcp(
-       IN      const ipoib_pkt_t* const        p_ipoib )
-{
-       return( (p_ipoib->type.ip.prot.udp.hdr.dst_port == DHCP_PORT_SERVER &&
-                               p_ipoib->type.ip.prot.udp.hdr.src_port == DHCP_PORT_CLIENT) ||
-                               (p_ipoib->type.ip.prot.udp.hdr.dst_port == DHCP_PORT_CLIENT &&
-                               p_ipoib->type.ip.prot.udp.hdr.src_port == DHCP_PORT_SERVER) );
-}
-#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipoib_endpoint.cpp.patch
Type: application/octet-stream
Size: 31899 bytes
Desc: ipoib_endpoint.cpp.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20110111/4e73d827/attachment.obj>


More information about the ofw mailing list