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 * @(#) RN_Queue.h 1.42@(#)
37 *****************************************************************************/
39 /*****************************************************************************
41 * @brief Random Number Queue
43 * Structures and defines for the Random Number queue
45 *****************************************************************************/
47 /*****************************************************************************
49 * 03/26/03 brr Remove unused defines & updated RN_POINTER_MASK macro.
50 * 10/25/02 brr Clean up function prototypes & include files.
51 * 05/15/02 brr Removed obsolete prototypes.
52 * 04/01/02 msz Most macros gone.
53 * 03/18/02 msz Don't loop forever on a hardware error.
54 * 03/01/02 brr Moved RNG_ALL_UNITS to n8_rn_common since its used by SAPI.
55 * 02/22/02 spm Converted n8_delay to n8_usleep.
56 * 02/19/02 msz Eliminated some unused macros, and unused #defines
57 * 12/15/01 msz Added RNG_CMD_Q_GET_READ_WRITE_PTR.
58 * 12/04/01 mel Fixed bug #395 : Added BM_includes.h to avoid crash for build
59 * when SUPPORTING_BM is not defined
60 * 10/05/01 msz Added RNG_ALL_UNITS, RNG_FIRST_UNIT in support for
61 * mulitple RNG execution units.
62 * 10/04/01 msz Added RN_InitParameters
63 * 09/25/01 msz Set size of queue based on RNG_QUEUE_LEN_LOG2
64 * 09/17/01 msz Wait a bit to let some random numbers be generated. This
65 * prevents a hardware hang in waiting for lack of busy bit.
66 * 09/12/01 msz Added External Clock Scaler Register Access.
67 * Changes for host seed support. Access to read
68 * seed sample msw and lsw.
69 * 08/31/01 msz Fixed a bug in RNH_WAIT_WHILE_BUSY, added
70 * RN_READ_RNG_CFG_STATUS
71 * 08/24/01 msz Simplified macros a bit.
72 * 08/16/01 mmd Now including n8_driver_api.h instead of simon.h.
73 * 08/16/01 msz Code review changes
74 * 08/15/01 brr Fixed complier error when SUPPORTING_BM is not defined.
75 * 08/06/01 msz All macros now take queue_p rather than simon_p, and are
76 * capitalized, and combined sizeOfRNG_Q with sizeOfQueue.
77 * Deleted some unused macros.
78 * 07/19/01 bac Necessary to include n8_enqueue_common.h for RN_Request_t.
79 * 07/18/01 mel Added n8_OS_intf.h for system specific definitions.
80 * 06/27/01 msz Added rnh_wait_while_busy
81 * 06/27/01 hml Added some debugging to selected macro calls.
82 * added rn_read_rnh_cfg_status macro.
83 * changed rn_write_tod_init to use rng_tod_seconds instead
85 * 06/21/01 hml Removed chip parameter from init_rng_q routine.
86 * 06/21/01 msz Added some more documentation on macros.
87 * 06/19/01 hml Correct set of prototypes.
88 * 06/13/01 msz Added _simon_p pointer to macros, redid macros using new
89 * bmodel or fpga/simon scheme.
90 * 06/08/01 hml Added macro set for fpga.
91 * 05/10/01 dws Removed #include of inttypes.h. This is done implicitly
92 * through sim_rn.h and n8_common.h.
93 * 05/03/01 jke fixed macro bugs for incrementing read-queue-pointer
94 * 04/27/01 dkm Corrected #define RNG_q_Write_Ptr
95 * 04/11/01 bac Removed non-ANSI-compliant comments.
96 * 03/1901 jke Original version.
97 ****************************************************************************/
103 #include "n8_rn_common.h"
104 #include "n8_common.h"
106 /*****************************************************************************
108 *****************************************************************************/
111 /* This defines what a long time looping wait is. */
112 /* It is an arbitrarily somewhat large number. */
113 #define RNH_BUSY_WAIT_HARDWARE_START_COUNT 100
116 /**********************************************************************
117 * RNG_CMD_Q_GET_READ_WRITE_PTR
118 **********************************************************************/
119 /** @brief Read the value of the read and write q pointers.
121 * This next macro combines the getting of the read pointer
122 * and the getting of the write pointer. This avoids having to
123 * hit the hardware and bus twice in a row to get the same information.
125 * @param _queue_p RO: Pointer to the Queue Control Structure
126 * @param _read_p WO: The read pointer value.
127 * @param _write_p WO: The write pointer value.
133 * _read_p and _write_p values.
139 * This routine requires the hardwareAccessSem.
143 *********************************************************************/
144 #define RNG_CMD_Q_GET_READ_WRITE_PTR(_queue_p,_read_p, _write_p) \
146 uint32_t readWrite; \
147 readWrite = (_queue_p)->rngReg_p->rnh_q_ptr; \
148 *(_read_p) = (readWrite) & RN_POINTER_MASK(_queue_p); \
149 *(_write_p) = (readWrite>>16) & RN_POINTER_MASK(_queue_p); \
154 #define RN_POINTER_MASK(_queue_p) \
155 ((_queue_p)->sizeMask)
158 #endif /* RN_QUEUE_H */