No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / pci / n8 / common / api / n8_request.c
blob957ec6daa15d5323531c8b1cbf1de1665d85e172
1 /*-
2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
3 * All rights reserved.
5 * NBMK Encryption Technologies provides no support of any kind for
6 * this software. Questions or concerns about it may be addressed to
7 * the members of the relevant open-source community at
8 * <tech-crypto@netbsd.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
12 * met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 static char const n8_id[] = "$Id: n8_request.c,v 1.1 2008/10/30 12:02:15 darran Exp $";
36 /*****************************************************************************/
37 /** @file n8_request.c
38 * @briefs file contains the N8_RequestAllocate and N8_RequestFree API calls.
41 *****************************************************************************/
43 /*****************************************************************************
44 * Revision history:
45 * 04/24/03 jpw Change N8_KMALLOC_PK in N8_RequestAllocate to N8_KMALLOC
46 * so we always use the EA segment for N8_RequestAlllocate
47 * 07/14/02 bac Fixed a bug where pointer arithmetic was incorrect when
48 * calculating *bufferVirt_pp.
49 * 06/14/02 hml Removed N8_PacketRequestSet.
50 * 06/10/02 hml First completed version.
51 * 06/04/02 hml Original version.
52 ****************************************************************************/
53 /** @defgroup Request
55 #include "n8_util.h"
56 #include "n8_enqueue_common.h"
57 #include "n8_pub_errors.h"
58 #include "n8_pub_common.h"
59 #include "n8_pub_request.h"
60 #include "n8_API_Initialize.h"
62 /*****************************************************************************
63 * N8_RequestAllocate
64 *****************************************************************************/
65 /** @ingroup Request
66 * @brief Allocates a request buffer of contiguous kernel memory of the requested
67 * data size from the request pool.
69 * @param dataBytes RO: Number of bytes in the data area.
70 * @param request_p WO: Pointer to return handle.
71 * @param bufferVirt_pp WO: Pointer in which to return the virtual address of
72 * the data area of the request.
74 * @par Externals:
75 * requestPoolCtl_gp The bank control for the default pool.
77 * @return
78 * returns N8_STATUS_OK if successful or Error value.
80 * @par Errors
81 * N8_INVALID_OBJECT One of the parameters is invalid.
82 * N8_NO_MORE_RESOURCE The resource is exhausted.
83 * @par Assumptions
84 * None<br>
85 *****************************************************************************/
86 N8_Status_t N8_RequestAllocate(const unsigned int nDataBytes,
87 N8_RequestHandle_t *request_p,
88 N8_Buffer_t **bufferVirt_pp)
90 N8_Status_t ret = N8_STATUS_OK;
91 N8_MemoryHandle_t *kmem_p = NULL;
92 int allocBytes;
96 ret = N8_preamble();
97 CHECK_RETURN(ret);
99 /* Parameter checking */
100 CHECK_OBJECT(request_p, ret);
101 CHECK_OBJECT(bufferVirt_pp, ret);
103 if (nDataBytes == 0)
105 /* This is ok, but there is nothing much to do */
106 *bufferVirt_pp = NULL;
107 break;
110 if (nDataBytes > N8_MAX_REQUEST_DATA_BYTES)
112 ret = N8_INVALID_VALUE;
113 break;
115 /* We are allocating memory for the complete request. The memory struct
116 be added on by the KMALLOC, but we need to add the memory for the API
117 request and the command blocks and the context. */
118 allocBytes = nDataBytes +
119 sizeof(API_Request_t) + N8_COMMAND_BLOCK_BYTES + N8_CTX_BYTES;
121 /* Allocate the buffer */
122 kmem_p = N8_KMALLOC(allocBytes);
123 CHECK_OBJECT(kmem_p, ret);
125 /* Return the data to the user */
126 *request_p = (N8_RequestHandle_t) kmem_p;
127 *bufferVirt_pp = (N8_Buffer_t *)((int)kmem_p->VirtualAddress +
128 sizeof(API_Request_t) +
129 N8_COMMAND_BLOCK_BYTES +
130 N8_CTX_BYTES);
131 } while (FALSE);
133 return ret;
134 } /* N8_RequestAllocate */
136 /*****************************************************************************
137 * N8_RequestFree
138 *****************************************************************************/
139 /** @ingroup Request
140 * @brief Frees a previously allocated request of contiguous kernel memory.
142 * @param requestHandle RO: Handle of request to free.
144 * @return
145 * returns N8_STATUS_OK if successful or Error value.
146 * @par Errors
147 * N8_INVALID_OBJECT One of the parameters is invalid.
148 * @par Assumptions
149 * None<br>
150 *****************************************************************************/
151 N8_Status_t N8_RequestFree(N8_RequestHandle_t requestHandle)
153 N8_Status_t ret = N8_STATUS_OK;
157 ret = N8_preamble();
158 CHECK_RETURN(ret);
160 /* Parameter checking */
161 CHECK_OBJECT(requestHandle, ret);
163 /* Free the buffer */
164 N8_KFREE((N8_MemoryHandle_t *) requestHandle);
165 } while (FALSE);
167 return ret;
168 } /* N8_RequestFree */