2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
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>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
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 /*****************************************************************************
36 * @(#) n8_enqueue_common.h 1.32@(#)
37 *****************************************************************************/
39 /*****************************************************************************/
40 /** @file n8_enqueue_common.h
41 * @brief Common queueing definitions.
43 * Common infrastructure for queueing requests.
45 *****************************************************************************/
47 /*****************************************************************************
49 * 05/19/03 brr Eliminate freeList_p from API request.
50 * 05/15/03 brr Eliminated obsolete N8_freeList_t & include n8_rn_common.h.
51 * 04/01/03 brr Eliminated APIReqIndex.
52 * 03/19/03 brr Added APIReqIndex to API_Request_t to support waiting on a
54 * 03/10/03 brr Added support for API callbacks.
55 * 06/10/02 hml Added the userRequest boolean to API_Request_t.
56 * 06/06/02 brr Moved waitQueue to the queue structure.
57 * 05/30/02 brr Added common struct for queue statistics.
58 * 05/14/02 brr Removed all fields associated with chained requests.
59 * 05/07/02 msz Added field to QMgr Request to mark as synchronous.
60 * 04/30/02 brr Removed obsolete fields in API requests.
61 * 04/10/02 mmd Removed obsolete NSP_PSEUDO_DEVICE_NAME.
62 * 03/27/02 hml Removed obsolete include file.
63 * 03/26/02 brr Added dataoffset to API_Request_t.
64 * 03/06/02 msz Added physical address to QMgrRequest
65 * (Chained subsequent messages in kernel support)
66 * 02/28/02 brr Move internal QMgr structure to QMQueue.h
67 * 02/20/02 brr Removed obsolete "size" variables since FPGA's are not
69 * 02/18/02 brr Support user space API, removed obsolete Context memory
71 * 02/19/02 msz No more randomParmSem.
72 * 01/31/02 brr Added postProcessBuffer to API_Request_t.
73 * 01/25/02 bac Added ccmFreeIndex_p to QueueControl_t.
74 * 01/28/02 msz No more nextRequestToBeReturnedToAPI_index
75 * 01/21/02 msz Added event wait type information.
76 * 01/23/02 brr Modified API_Request_t to support reduced memory allocations.
77 * 01/17/02 msz Changes to support mirror registers - BUG 413
78 * 01/16/01 brr Moved several definition here from QMgrInit.h.
79 * 12/15/01 msz Adding shadow copy of command queue. Fix for BUG 382, 411.
80 * 12/04/01 msz Changes to allow chaining of requests.
81 * Changed N8_QueueStatusCodes_t, added N8_QueueErrorCodes_t
82 * 11/15/01 msz Added nextAPIRequest_t to API_Request_t so they can be
84 * 11/11/01 mmd Added nspData field to QueueControl_t.
85 * 11/10/01 brr Modified to support static allocations of persistant data
87 * 10/30/01 hml Added EA_ContextSize and SKS_MemorySize to QueueControl_t.
88 * 10/29/01 msz Added bncConstantsSem.
89 * 10/02/01 bac API_Request_t copyBackCommandBlock changed name and is now a
91 * 10/02/01 msz Changed sharedPerUnit as it now accessed differently.
92 * 09/26/01 msz Merged with hml 9/21/01 and 09/13/01 changes below, note
93 * however that there is no longer any seed_source to add.
94 * 09/21/01 hml Reordered and augmented the Queue control structure.
95 * 09/13/01 hml Added seed_source.
96 * 09/26/01 msz No longer need seed_source, started shared per execution
98 * 09/24/01 msz Added some comments.
99 * 09/13/01 msz Added seed_source.
100 * 09/06/01 bac Renumbered enums to start with non-zero (BUG #190).
101 * 08/29/01 msz Moved elapsedTimeInQueueAndSimon so it is per request rather
102 * than per command. Eliminated numCmdBlksProcessed from
103 * API_Request_t, eliminated nextCmdToBeReturnedToAPI_index,
104 * index_of_next_command_to_evaluate.
105 * 08/27/01 msz Renamed fcnToCallbackWhenRequestIsFilled to callback
106 * and FcnCalledOnRequestCompletionOrError to callback
107 * 08/16/01 mmd Now including n8_driver_api.h instead of simon.h and
108 * simon_driver_api.h.
109 * 08/20/01 msz Use n8_time and n8_timeval_t
110 * 08/08/01 msz Removed include of n8_semaphore.h
111 * Merged other Revision history into this one.
112 * 08/08/01 hml Added contextListSem and randomParmSem to queue control struct.
113 * 08/06/01 msz Combined sizeOfRNG_Q with sizeOfQueue, some moving around
114 * of offsets of values in QueueControl_t.
115 * 08/01/01 bac Removed N8_QueueStatusCodes_t and N8_QueueReturnCodes_t
116 * as they are now defined elsewhere.
117 * 07/31/01 bac Documented simon_error_report_t to clarify the index.
118 * 07/30/01 bac Added BNC_multiplier and PK_BytesPerBignumDigit to
120 * 07/23/01 bac Forced to add ENQUEUE enums back in for integration. They
121 * will be removed later.
122 * 07/17/01 bac Consolidated all success enums to be N8_QUEUE_SUCCESS. Added
123 * values to enum definitions for easier lookup.
124 * 07/20/01 hml Added chip to the queue control.
125 * 07/20/01 bac Added hardware type and BNC bits per digit to the queue
127 * 07/19/01 bac Moved LLReqCtrl_t, API_Request_t, and RN_Request_t to here
128 * from other header files.
129 * 07/10/01 bac Changed DEFAULT_QUEUE_LEN_LOG_2 to be 10 (1024).
130 * 06/15/01 hml added unit and chip to the API_Request_t structure.
131 * 05/01/01 bac Added to API_Reqeust_t the freeList_p and postProcessingData_p
132 * 04/24/01 bac fixed merge error.
133 * 04/16/01 jke moved enqueue retvals from n8_pk_common.h, genericized names
134 * 04/16/01 jke moved status and return types from PK*.h and genericized for
136 * 04/12/01 jke added header per spec
137 * 04/11/01 bac Standardization. Removed non-ANSI-compliant code.
138 * 03/28/01 jke copied from EnQueue.h
139 ****************************************************************************/
140 /** @defgroup subsystem_name Subsystem Title (not used for a header file)
142 /*****************************************************************************
143 * n8_enqueue_common.h
145 * #defs and typedefs used in implementing the request queues.
147 *****************************************************************************/
151 #ifndef N8_ENQUEUE_COMMON_H
152 #define N8_ENQUEUE_COMMON_H
154 #include "n8_time.h" /* for the n8_timeval_t */
155 #include "n8_common.h"
156 #include "n8_OS_intf.h"
157 #include "n8_pub_common.h"
158 #include "n8_pk_common.h" /* for typedef of PK_CMD_BLOCK */
159 #include "n8_ea_common.h" /* for typedef of EA_CMD_BLOCK */
160 #include "n8_malloc_common.h"
163 typedef struct simon_error_report_t
165 int errorReturnedFromSimon
; /* error returned from the hardware.
166 * look at the hardware specification
167 * error flags for deciphering this
169 int indexOfCommandThatCausedError
; /* index of command that caused the
170 * error. (1...number of commands) */
171 } simon_error_report_t
;
174 /*****************************************************************************
175 * N8_QueueErrorCodes_t
176 *****************************************************************************/
178 * @brief This enum contains the error status of a request from SAPI to QMGR.
180 * N8_QUEUE_REQUEST_OK The request has no error
181 * N8_QUEUE_REQUEST_ERROR There was an error in or with the
184 *****************************************************************************/
186 /* Error status of request/event that is in the queue */
189 N8_QUEUE_REQUEST_OK
= 1,
190 N8_QUEUE_REQUEST_ERROR
= 2,
191 } N8_QueueErrorCodes_t
;
194 /*****************************************************************************
196 *****************************************************************************/
198 * @struct QMgrRequest_t
199 * @brief This structure contains the common part of a RN_request_ and
200 * API_Request_t (and any other request types that might be added).
202 * requestStatus tells if the request is in API or QMgr, or if its FINISHED
203 * requestError tells if the request is in error state
204 * unit tells the component the request goes to (eg. PK, EA, RNG)
205 * chip tells what chipset the request is for
206 * callback is a pointer to a callback routine, or a NULL if
207 * there is no callback routine.
208 * physicalAddress The Physical Address of this request (used in user address
209 * to kernel address conversions)
210 * synchronous This request has been generated by a synchronous API call.
212 *****************************************************************************/
214 typedef struct QMgrRequest_t
216 N8_QueueStatusCodes_t requestStatus
;
217 N8_QueueErrorCodes_t requestError
;
220 void (* callback
) (struct QMgrRequest_t
*);
221 unsigned long physicalAddress
;
222 N8_Boolean_t synchronous
;
227 /*****************************************************************************
229 *****************************************************************************/
231 * @struct RN_Request_t
232 * @brief This structure contains the a request to the RNG queue.
234 * userBuffer_p Where to copy the random numbers to.
235 * userRequest Flag to indicate request came from user space.
236 * numBytesRequested Has the number of random bytes the user requested
237 * numBytesProvided Used to store how many bytes have been copied out.
239 *****************************************************************************/
241 typedef struct RN_Request_t
244 int userRequest
; /* Flag to indicate request */
245 /* received from user space. */
246 int numBytesRequested
;
247 int numBytesProvided
;
251 /*****************************************************************************
253 *****************************************************************************/
255 * @struct API_request_t
256 * @brief This structure contains the a request to the EA or PK queue. The
257 * first section of this structure must be a QMgrRequest_t type.
258 * qr Has common QMgrRequest data.
260 *****************************************************************************/
264 QMgrRequest_t qr
; /* NOTE: the QMgrRequest_t contains the common
265 * elements between an API_Request_t and an
266 * RN_Request_t. IT MUST BE THE FIRST ENTRY IN
269 /* QMgr Only members */
270 int index_of_first_command
;
271 int index_of_last_command
;
274 EA_CMD_BLOCK_t
*EA_CommandBlock_ptr
;
275 PK_CMD_BLOCK_t
*PK_CommandBlock_ptr
;
277 N8_Boolean_t copyBackCommandBlock
;
278 simon_error_report_t err_rpt_bfr
;
280 N8_Callback_t usrCallback
; /* User's callback function */
281 void *usrData
; /* Pointer to user's data */
283 /* SAPI Only members */
285 N8_Boolean_t userRequest
; /* N8_TRUE: This request was alloced by
286 N8_AllocateRequest */
287 N8_Boolean_t userSpace
; /* N8_TRUE: This request was generated
290 /* set this pointer to any data that needs to be associated with
291 * this request for processing after the completion of the request
293 void *postProcessingData_p
;
295 N8_Buffer_t
*copyBackFrom_p
;
296 N8_Buffer_t
*copyBackTo_p
;
297 struct uio
*copyBackTo_uio
;
298 uint32_t postProcessBuffer
[12];
302 /*****************************************************************************
304 *****************************************************************************/
306 * @struct QueueStats_t
307 * @brief This structure contains the statistics for each queue.
309 *****************************************************************************/
314 uint32_t hardwareErrorCount
; /**< Counter of hardware errors
315 detected. A non zero value does
316 not mean there is a hardware
318 uint32_t requestsQueued
; /**< Counter of number of requests
319 that have been queued (not the
320 number of current requests). */
321 uint32_t requestsCompleted
; /**< Counter of number of queued requests
322 that have been completed, regardless
323 of success or failure. */
324 uint32_t requestCheckCalled
; /**< Counter of number of times we
325 have called check request on
327 uint32_t requestsPreempted
; /**< Counter of number of times a
328 request has been preempted by
329 a signal or timeout. */
337 QueueStats_t PKstats
;
338 QueueStats_t EAstats
;
339 QueueStats_t RNstats
;
341 } N8_QueueStatistics_t
;
344 #endif /* ifdef N8_ENQUEUE_COMMON_H */