2 * IPSEC_GLUE_DESC interface code.
3 * Copyright 2003 Intel Corporation All Rights Reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 RCSID $Id: ipsec_glue_desc.c,v 1.0 2003/04/27 05:08:18 rgb Exp $
20 * Put the user defined include files required.
23 #include "IxOsCacheMMU.h"
24 #include "IxOsServices.h"
26 #include <linux/slab.h>
27 #include "ipsec_glue_desc.h"
28 #include "ipsec_glue.h"
31 * Variable declarations global to this file only. Externs are followed by
34 static kmem_cache_t *ipsec_rcv_desc_cachep;
35 static kmem_cache_t *ipsec_xmit_desc_cachep;
40 * ipsec_glue_rcv_desc_init
42 * Initialize ipsec_rcv descriptor management module.
44 * Returns: IPSEC_GLUE_STATUS_SUCCESS - Initialization is successful
45 * IPSEC_GLUE_STATUS_FAIL - Initialization failure
48 ipsec_glue_rcv_desc_init (void)
50 ipsec_rcv_desc_cachep = kmem_cache_create("ipsec_rcv_desc",
51 IPSEC_RCV_DESC_SIZE, 0, 0, NULL, NULL);
52 if (!ipsec_rcv_desc_cachep)
53 return IPSEC_GLUE_STATUS_FAIL;
55 return IPSEC_GLUE_STATUS_SUCCESS;
57 } /* end of ipsec_glue_rcv_desc_init () function */
61 * ipsec_glue_rcv_desc_get
63 * Get descriptor from the ipsec_rcv descriptor pool.
65 * Param : pIpsecRcvDescPtr [out] - Pointer to ipsec_rcv descriptor pointer
67 * Return : IPSEC_GLUE_STATUS_SUCCESS
68 * IPSEC_GLUE_STATUS_FAIL
72 ipsec_glue_rcv_desc_get (IpsecRcvDesc **pIpsecRcvDescPtr)
74 if (!ipsec_rcv_desc_cachep)
75 return IPSEC_GLUE_STATUS_FAIL;
77 *pIpsecRcvDescPtr = kmem_cache_alloc(ipsec_rcv_desc_cachep, GFP_ATOMIC);
78 if (!*pIpsecRcvDescPtr)
79 return IPSEC_GLUE_STATUS_FAIL;
81 (*pIpsecRcvDescPtr)->stats = NULL;
82 return IPSEC_GLUE_STATUS_SUCCESS;
87 * ipsec_glue_rcv_desc_release
89 * Release descriptor previously allocated back to the ipsec_rcv
92 * Return : IPSEC_GLUE_STATUS_SUCCESS
93 * IPSEC_GLUE_STATUS_FAIL
96 ipsec_glue_rcv_desc_release (IpsecRcvDesc *pIpsecRcvDesc)
98 if (!ipsec_rcv_desc_cachep)
99 return IPSEC_GLUE_STATUS_FAIL;
101 kmem_cache_free(ipsec_rcv_desc_cachep, pIpsecRcvDesc);
102 return IPSEC_GLUE_STATUS_SUCCESS;
109 * ipsec_rcv_desc_pool_free
111 * To free the memory allocated to descriptor pool through malloc
119 ipsec_rcv_desc_pool_free (void)
121 if (ipsec_rcv_desc_cachep && kmem_cache_destroy(ipsec_rcv_desc_cachep))
122 ipsec_rcv_desc_cachep = NULL;
128 * ipsec_glue_xmit_desc_init
130 * Initialize ipsec_xmit descriptor management module.
132 * Return: IPSEC_GLUE_STATUS_SUCCESS
133 * IPSEC_GLUE_STATUS_FAIL
136 ipsec_glue_xmit_desc_init (void)
138 ipsec_xmit_desc_cachep = kmem_cache_create("ipsec_xmit_desc",
139 IPSEC_XMIT_DESC_SIZE, 0, 0, NULL, NULL);
140 if (!ipsec_xmit_desc_cachep)
141 return IPSEC_GLUE_STATUS_FAIL;
143 return IPSEC_GLUE_STATUS_SUCCESS;
149 * ipsec_glue_xmit_desc_get
151 * Get descriptor from the ipsec_xmit descriptor pool.
153 * Param : pIpsecXmitDescPtr [out] - Pointer to ipsec_xmit descriptor pointer
155 * Return: IPSEC_GLUE_STATUS_SUCCESS
156 * IPSEC_GLUE_STATUS_FAIL
159 ipsec_glue_xmit_desc_get (IpsecXmitDesc **pIpsecXmitDescPtr)
161 if (!ipsec_xmit_desc_cachep)
162 return IPSEC_GLUE_STATUS_FAIL;
164 *pIpsecXmitDescPtr = kmem_cache_alloc(ipsec_xmit_desc_cachep, GFP_ATOMIC);
165 if (!*pIpsecXmitDescPtr)
166 return IPSEC_GLUE_STATUS_FAIL;
168 (*pIpsecXmitDescPtr)->tot_headroom = 0;
169 (*pIpsecXmitDescPtr)->tot_tailroom = 0;
170 (*pIpsecXmitDescPtr)->saved_header = NULL;
171 (*pIpsecXmitDescPtr)->oskb = NULL;
172 (*pIpsecXmitDescPtr)->pass = 0;
173 memset((char*)&((*pIpsecXmitDescPtr)->tdb), 0, sizeof(struct ipsec_sa));
174 return IPSEC_GLUE_STATUS_SUCCESS;
180 * ipsec_glue_xmit_desc_release
182 * Release descriptor previously allocated back to the ipsec_xmit
185 * pIpsecXmitDesc [in] - Pointer to ipsec_xmit descriptor
187 * Return: IPSEC_GLUE_STATUS_SUCCESS
188 * IPSEC_GLUE_STATUS_FAIL
192 ipsec_glue_xmit_desc_release (IpsecXmitDesc *pIpsecXmitDesc)
194 if (!ipsec_xmit_desc_cachep)
195 return IPSEC_GLUE_STATUS_FAIL;
197 kmem_cache_free(ipsec_xmit_desc_cachep, pIpsecXmitDesc);
198 return IPSEC_GLUE_STATUS_SUCCESS;
204 * ipsec_xmit_desc_pool_free
206 * To free the memory allocated to descriptor pool through malloc
214 ipsec_xmit_desc_pool_free (void)
216 if (ipsec_xmit_desc_cachep && kmem_cache_destroy(ipsec_xmit_desc_cachep))
217 ipsec_xmit_desc_cachep = NULL;