Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

vipderegistermem.c

Go to the documentation of this file.
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 "vipl_priv.h"
00014 
00015 
00041 VIP_ENTRY_POINT VIP_RETURN
00042 VipDeregisterMem (VIP_NIC_HANDLE NicHandle,
00043                   VIP_PVOID VirtualAddress, VIP_MEM_HANDLE MemoryHandle)
00044 {
00045   VIP_NIC *vip_nic_ptr;
00046   VIP_GM *vip_gm_ptr;
00047   VIP_MEM *vip_mem_ptr;
00048   VIP_PTAG *vip_ptag_ptr;
00049   VIP_DEBUG_LABEL (("VipDeregisterMem"));
00050 
00051 
00052   if (VirtualAddress == NULL)
00053     {
00054       VIP_DEBUG (("VirtualAddress is null"));
00055       return VIP_INVALID_PARAMETER;
00056     }
00057 
00058   if ((MemoryHandle == 0) || (MemoryHandle > VI_GM_MAX_REGISTER_REGIONS))
00059     {
00060       VIP_DEBUG (("MemoryHandle is invalid"));
00061       return VIP_INVALID_PARAMETER;
00062     }
00063 
00064   /* check nic handle */
00065   vip_nic_ptr = (VIP_NIC *) NicHandle;
00066   if (VIP_INVALID_NIC_HANDLE (vip_nic_ptr))
00067     {
00068       VIP_DEBUG (("Invalid NIC handle"));
00069       return VIP_INVALID_PARAMETER;
00070     }
00071   vip_gm_ptr = vip_nic_ptr->vip_gm_ptr;
00072   VIP_MUTEX_LOCK (&(vip_gm_ptr->lock));
00073   VIP_PROGRESSION (vip_gm_ptr);
00074   VIP_MUTEX_LOCK (&(vip_nic_ptr->lock));
00075 
00076   /* check regmem handle */
00077   vip_mem_ptr = (VIP_MEM *) (vip_nic_ptr->vip_mem_handle_ptrs[MemoryHandle]);
00078   if (VIP_INVALID_MEM_HANDLE (vip_mem_ptr))
00079     {
00080       VIP_DEBUG (("Invalid MEM handle"));
00081       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00082       VIP_MUTEX_UNLOCK (&(vip_gm_ptr->lock));
00083       return VIP_INVALID_PARAMETER;
00084     }
00085 
00086   /* check virtual address consistency */
00087   if (vip_mem_ptr->address != VirtualAddress)
00088     {
00089       VIP_DEBUG (("Inconsistent virtual address"));
00090       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00091       VIP_MUTEX_UNLOCK (&(vip_gm_ptr->lock));
00092       return VIP_INVALID_PARAMETER;
00093     }
00094 
00095   /* check ptag */
00096   vip_ptag_ptr = vip_mem_ptr->vip_ptag_ptr;
00097   if (VIP_INVALID_PTAG_HANDLE (vip_ptag_ptr))
00098     {
00099       VIP_DEBUG (("Invalid PTAG in MEM handle"));
00100       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00101       VIP_MUTEX_UNLOCK (&(vip_gm_ptr->lock));
00102       return VIP_INVALID_PTAG;
00103     }
00104 
00105   /* deregister memory */
00106   if (vip_avl_deregister_memory (vip_gm_ptr, 
00107                                  (((VIP_UINTPTR) VirtualAddress)
00108                                   & ~((VIP_UINTPTR) GM_PAGE_LEN - 1)),
00109                                  ((((VIP_UINTPTR) VirtualAddress)
00110                                    + vip_mem_ptr->length + GM_PAGE_LEN - 1)
00111                                   & ~((VIP_UINTPTR) GM_PAGE_LEN - 1)))
00112       != VIP_SUCCESS)
00113     {
00114       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00115       VIP_MUTEX_UNLOCK (&(vip_gm_ptr->lock));
00116       return VIP_ERROR_RESOURCE;
00117     }
00118 
00119   /* update ptag reference count and amount of memory registered */
00120   VIP_ASSERT (vip_ptag_ptr->handle.ref_count > 0);
00121   vip_ptag_ptr->handle.ref_count--;
00122   vip_gm_ptr->memory_registered -= vip_mem_ptr->length;
00123 
00124   /* free the entry in the Mem handle tab and free the handle itself */
00125   vip_nic_ptr->vip_mem_handle_ptrs[MemoryHandle] =
00126     (VIP_MEM *) ((VIP_UINTPTR) (vip_nic_ptr->vip_mem_handle_free));
00127   vip_nic_ptr->vip_mem_handle_free = MemoryHandle;
00128   vip_free_handle (&(vip_nic_ptr->vip_mem_set), (VIP_HANDLE *) vip_mem_ptr);
00129 
00130   VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00131   VIP_MUTEX_UNLOCK (&(vip_gm_ptr->lock));
00132   VIP_DEBUG (("Success"));
00133   return VIP_SUCCESS;
00134 }
VI-GM-1.3 by Myricom © 1997-2006. Documentation generated on 20 May 2006 by doxygen 1.4.4.