
00001 /******************************************************** 00002 * Myricom VI-GM networking software and documentation * 00003 * Copyright (c) 2001 by Myricom, Inc. * 00004 * All rights reserved. * 00005 * See the file `COPYING' for copyright notice. * 00006 ********************************************************/ 00007 00013 #include <stdlib.h> 00014 00015 #include "vipl_priv.h" 00016 00017 00049 VIP_ENTRY_POINT VIP_RETURN 00050 VipCreateCQ (VIP_NIC_HANDLE NicHandle, 00051 VIP_ULONG EntryCount, VIP_CQ_HANDLE * CQHandle) 00052 { 00053 VIP_NIC *vip_nic_ptr; 00054 VIP_CQ *vip_cq_ptr; 00055 VIP_DEBUG_LABEL (("VipCreateCQ")); 00056 00057 00058 if (EntryCount == 0) 00059 { 00060 VIP_DEBUG (("EntryCount is 0")); 00061 return VIP_ERROR_RESOURCE; 00062 } 00063 00064 if (EntryCount > VI_GM_MAX_CQ_ENTRIES) 00065 { 00066 VIP_DEBUG (("EntryCount too large (max=%d)", VI_GM_MAX_CQ_ENTRIES)); 00067 return VIP_ERROR_RESOURCE; 00068 } 00069 00070 if (CQHandle == NULL) 00071 { 00072 VIP_DEBUG (("CQHandle is null")); 00073 return VIP_INVALID_PARAMETER; 00074 } 00075 00076 /* check nic handle */ 00077 vip_nic_ptr = (VIP_NIC *) NicHandle; 00078 if (VIP_INVALID_NIC_HANDLE (vip_nic_ptr)) 00079 { 00080 VIP_DEBUG (("Invalid NIC handle")); 00081 return VIP_INVALID_PARAMETER; 00082 } 00083 VIP_MUTEX_LOCK (&(vip_nic_ptr->lock)); 00084 00085 /* allocate cq */ 00086 vip_cq_ptr = (VIP_CQ *) vip_allocate_handle (&(vip_nic_ptr->vip_cq_set)); 00087 if (vip_cq_ptr == NULL) 00088 { 00089 VIP_DEBUG (("VIP_CQ alloc failed")); 00090 VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock)); 00091 return VIP_ERROR_RESOURCE; 00092 } 00093 00094 /* allocate cq entries */ 00095 vip_cq_ptr->queue = (VIP_CQ_ENTRY *) calloc (EntryCount, 00096 sizeof (VIP_CQ_ENTRY)); 00097 if (vip_cq_ptr->queue == NULL) 00098 { 00099 vip_free_handle (&(vip_nic_ptr->vip_cq_set), (VIP_HANDLE *) vip_cq_ptr); 00100 VIP_DEBUG (("CQ entries alloc failed")); 00101 VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock)); 00102 return VIP_ERROR_RESOURCE; 00103 } 00104 00105 vip_cq_ptr->next_poll = 0; 00106 vip_cq_ptr->next_completion = 0; 00107 vip_cq_ptr->count = EntryCount; 00108 vip_cq_ptr->event_count = 0; 00109 VIP_EVENT_INIT (&(vip_cq_ptr->event)); 00110 VIP_SEMAPHORE_INIT (&(vip_cq_ptr->notify_tokens), 0); 00111 vip_cq_ptr->notify_initialized = VIP_FALSE; 00112 vip_cq_ptr->notify_cancelled = VIP_FALSE; 00113 vip_cq_ptr->first_notify_handler = NULL; 00114 vip_cq_ptr->last_notify_handler = NULL; 00115 00116 *CQHandle = (VIP_CQ_HANDLE) vip_cq_ptr; 00117 00118 VIP_DEBUG (("Success")); 00119 VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock)); 00120 return VIP_SUCCESS; 00121 }
1.4.4.