Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / pci / n8 / QMgr / QMUtil.c
blobfb157a2418a50bf815deef079cefcab92c03d0b2
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: QMUtil.c,v 1.1 2008/10/30 12:02:14 darran Exp $";
36 /*****************************************************************************/
37 /** @file QMUtil.c
38 * @brief Queue manager utility file.
40 * This file contains some utility functions for the queue manager
41 * functionality. These functions are all generic to the core type
42 * (RNG, PKP, EA)
44 *****************************************************************************/
46 /*****************************************************************************
47 * Revision history:
48 * 04/01/03 brr Eliminated obslete variable form displayQMgr.
49 * 03/20/03 brr Added displayQMgr function.
50 * 10/25/02 brr Clean up function prototypes & include files.
51 * 06/05/02 brr Moved N8_QMgrQueryStatistics here from QMgrInit & removed
52 * obsolete functions.
53 * 05/14/02 brr Removed functions used to process chained requests.
54 * 05/01/02 brr Streamline chained request processing.
55 * 04/03/02 brr Fix compile error when N8DEBUG is defined.
56 * 03/27/02 hml Replaced all of the N8_QueueReturnCodes_t with N8_Status_t.
57 * 03/07/02 brr Perform CheckQueue operation in the IOCTL.
58 * 03/06/02 msz Use subsequent physical address to get virtual address
59 * (Chained subsequent messages in kernel support)
60 * 03/01/02 brr Deleted obsolete function QMgr_get_pseudo_device_handle.
61 * 02/26/02 brr Do not copy finished requests to user space, since they are
62 * now shared buffers.
63 * 02/22/02 spm Fixed compiler warning (Nested comment: Line 336).
64 * 02/22/02 spm Converted printk's to DBG's.
65 * 01/19/02 brr Moved callback processing to N8_EventCheck.
66 * 02/19/02 brr Copy API request back to user space upon completion of a
67 * request submitted from user space.
68 * 01/31/02 brr Removed QMCopy.
69 * 01/23/02 msz Fix for BUG 485, re-arrangement in QMgrFinishRequests.
70 * 02/13/02 brr Moved several function to the driver file n8_queueInit.c
71 * 01/16/02 brr Removed references to obsolete include files.
72 * 12/05/01 msz Moved some common RNQueue, QMQueue routines into here.
73 * 11/10/01 brr Modified to support static allocations of persistant data
74 * by the driver.
75 * 11/05/01 hml Added the N8_USE_ONE_CHIP #define and some debugging.
76 * 10/30/01 dkm Added N8_INVALID_UNIT error.
77 * 10/05/01 msz Added QMgr_QueueGetChipAndUnit
78 * 09/24/01 hml Converted QMgr_get_valid_unit_num to use N8_Unit_t.
79 * 09/20/01 hml Added QMgr_get_valid_unit_num.
80 * 09/06/01 hml Added QMgr_get_psuedo_device_handle.
81 * 08/21/01 hml Added QMgr_get_num_control_structs.
82 * 09/26/01 msz Added QMgr_QueueInitialized
83 * 08/16/01 mmd Now including n8_driver_api.h instead of simon_driver_api.h.
85 * 08/13/01 msz Added QMgr_get_chip_for_request function.
86 * 08/06/01 mel Deleted include for strings.h.
87 * 07/30/01 bac Added QMCopy function.
88 * 06/22/01 hml Updated documentation and error checking.
89 * 06/15/01 hml Original version.
91 ****************************************************************************/
93 #include "n8_pub_types.h"
94 #include "n8_common.h"
95 #include "n8_malloc_common.h"
96 #include "n8_pub_errors.h"
97 #include "n8_enqueue_common.h"
98 #include "QMUtil.h"
99 #include "QMQueue.h"
100 #include "RN_Queue.h"
101 #include "helper.h"
102 #include "n8_driver_api.h"
105 /*****************************************************************************
106 * QMgr_get_chip_for_request
107 *****************************************************************************/
108 /** @ingroup QMgr
109 * @brief Given a component type, this function fetches the next available
110 * pointer for the appropriate control structure.
112 * @param queue_pp WO: Ptr in which to store the address of the target
113 * control structure.
114 * @param unit RO: The execution unit.
116 * @par Externals:
117 * queueTable_g: The global table of queue information.
119 * @return
120 * The queue_pp will contian the pointer to the queue control structure
121 * that is being assigned.
122 * N8_STATUS_OK: The function succeeded. <BR>
123 * N8_INVALID_PARAMETER: The unit is invalid.
125 * @par Errors:
126 * Errors are returned form the function. See the return section.
128 * @par Assumptions:
129 * The global queue table has been initialized before this function is
130 * called.
131 *****************************************************************************/
133 N8_Status_t
134 QMgr_get_chip_for_request (QueueControl_t **queue_pp,
135 N8_Component_t unit )
137 if (unit >= N8_NUM_COMPONENTS)
139 /* Requested an invalid chip/unit or passed a null pointer */
140 return (N8_INVALID_PARAMETER);
143 /* Get the current control set */
144 *queue_pp = &(queueTable_g.controlSets_p[queueTable_g.currentSet][unit]);
146 #if defined N8_USE_ONE_CHIP
147 /* If the library has been built with N8_USE_ONE_CHIP defined, then
148 set the currentSet to 0. This is for testing/analyses use only and
149 should NEVER be turned on in normal usage. */
150 queueTable_g.currentSet = 0;
151 #else
153 /* Bump to the next control set */
154 queueTable_g.currentSet = ( queueTable_g.currentSet + 1 )
155 % queueTable_g.nControlSets;
156 #endif
158 DBG(("QMgr_get_chip_for_request: providing chip %d.\n",
159 (*queue_pp)->chip));
160 return N8_STATUS_OK;
162 } /* QMgr_get_chip_for_request */
165 /*****************************************************************************
166 * QMgr_get_control_struct
167 *****************************************************************************/
168 /** @ingroup QMgr
169 * @brief Given a component type and a chip index, this function fetches the
170 * pointer for the appropriate control structure.
172 * @param queue_pp WO: Ptr in which to store the address of the target
173 * control structure.
174 * @param unit RO: The execution unit.
175 * @param chip RO: The chip identifier.
177 * @par Externals:
178 * queueTable_g: The global table of queue information.
180 * @return
181 * N8_STATUS_OK: The function succeeded. <BR>
182 * N8_INVALID_PARAMETER: The unit or chip is invalid or the input pointer
183 * is invalid.
185 * @par Errors:
186 * Errors are returned form the function. See the return section.
188 * @par Assumptions:
189 * The global queue table has been initialized before this function is
190 * called.
191 *****************************************************************************/
193 N8_Status_t
194 QMgr_get_control_struct(QueueControl_t **queue_pp,
195 N8_Component_t unit,
196 int chip)
198 if ((chip >= queueTable_g.nControlSets) ||
199 (unit >= N8_NUM_COMPONENTS) ||
200 (!queue_pp))
202 /* Requested an invalid chip/unit or passed a null pointer */
203 return (N8_INVALID_PARAMETER);
206 *queue_pp = &(queueTable_g.controlSets_p[chip][unit]);
207 return N8_STATUS_OK;
208 } /* QMgr_get_control_struct */
211 /*****************************************************************************
212 * QMgr_get_valid_unit_number
213 *****************************************************************************/
214 /** @ingroup QMgr
215 * @brief This function takes a unit type specifier and a unit number and
216 * validates the unit number.
218 * This function will detect invalid unit numbers and fulfill requests for
219 * the API to generate a unit number.
221 * @param type RO: The unit type for the request.
222 * @param unitRequest RO: The unit id requested.
223 * @param unitReturn WO: The validated unit to return. The unit returned
224 * will be the unit requested unless the user asked
225 * us to pick one for him.
227 * @par Externals:
228 * None.
230 * @return
231 * N8_STATUS_OK: The function succeeded. <BR>
232 * N8_INVALID_PARAMETER: The unitReturn parameter is NULL <BR>
233 * N8_INVALID_UNIT: The unit requested is invalid.
235 * @par Errors:
236 * Errors are returned form the function. See the return section.
238 * @par Assumptions:
239 * None.
240 *****************************************************************************/
241 N8_Status_t
242 QMgr_get_valid_unit_num(N8_Component_t type,
243 N8_Unit_t unitRequest,
244 N8_Unit_t *unitReturn)
246 int nChips;
247 N8_Status_t ret = N8_STATUS_OK;
248 QueueControl_t *queue_p;
250 if (unitReturn == NULL)
252 return N8_INVALID_PARAMETER;
257 /* Use num chips as num units. */
258 nChips = queueTable_g.nControlSets;
260 if (unitRequest >= 0 && unitRequest < nChips)
262 /* This case is fine */
263 *unitReturn = unitRequest;
264 DBG(("QMgr_get_valid_unit_num: using requested chip %d.\n",
265 *unitReturn));
266 break;
269 else if (unitRequest == N8_ANY_UNIT)
271 /* The user has asked us to select a chip for the request */
272 ret = QMgr_get_chip_for_request(&queue_p, type);
273 if (ret != N8_STATUS_OK)
275 break;
277 *unitReturn = queue_p->chip;
278 DBG(("QMgr_get_valid_unit_num: using N8_ANY_UNIT set to %d.\n",
279 *unitReturn));
280 break;
283 else
285 /* The unit requested is neither valid or N8_ANY_UNIT */
286 ret = N8_INVALID_UNIT;
288 } while (FALSE);
290 return (ret);
293 /*****************************************************************************
294 * N8_QMgrQueryStatistics
295 *****************************************************************************/
296 /** @ingroup QMgr
297 * @brief Returns values of all stat counters in the Queue Manager.
299 * Returns values of all stat counters in the Queue Manager.
301 * @param index RO: Index of a global hardware instance.
303 * @par Externals:
304 * queueTable_g: RW: The global queue control table.
306 * @return
307 * N8_STATUS_OK: The function succeeded.
308 * N8_INVALID_PARAMETER: Invalid hardware instance specified.
310 * @par Errors:
311 * The only possible failure, is if an invalid hardware instance is
312 * requested.
314 * @par Locks:
315 * n/a
317 * @par Assumptions:
318 * That HWindex is a valid NSP2000 hardware instance.
320 *****************************************************************************/
322 N8_Status_t N8_QMgrQueryStatistics(N8_QueueStatistics_t *stats)
325 /* GET LOCAL POINTERS TO THIS HARDWARE INSTANCE'S QUEUE CONTROL STRUCTS */
326 QueueControl_t *queuePK_p, *queueRN_p, *queueEA_p;
327 if (QMgr_get_control_struct(&queuePK_p, N8_PKP, stats->chip) == N8_INVALID_PARAMETER)
329 return N8_INVALID_PARAMETER;
331 if (QMgr_get_control_struct(&queueRN_p, N8_RNG, stats->chip) == N8_INVALID_PARAMETER)
333 return N8_INVALID_PARAMETER;
335 if (QMgr_get_control_struct(&queueEA_p, N8_EA, stats->chip) == N8_INVALID_PARAMETER)
337 return N8_INVALID_PARAMETER;
340 /* LOAD QueueStatistics_t RETURN STRUCT WITH ALL PK COUNTER VALUES */
341 stats->PKstats = queuePK_p->stats;
343 /* LOAD QueueStatistics_t RETURN STRUCT WITH ALL EA COUNTER VALUES */
344 stats->EAstats = queueEA_p->stats;
346 /* LOAD QueueStatistics_t RETURN STRUCT WITH ALL RN COUNTER VALUES */
347 stats->RNstats = queueRN_p->stats;
349 return N8_STATUS_OK;
351 } /* N8_QMgrQueryStatistics */
353 /*****************************************************************************
354 * displayQMgr
355 *****************************************************************************/
356 /** @ingroup QMgr
357 * @brief Prints Queue Manager debug information to the kernel log.
359 * @param none
361 * @par Externals:
363 * @return
365 * @par Errors:
367 *****************************************************************************/
369 void displayQMgr(void)
371 N8_PRINT(KERN_CRIT "displayQMgr: EA queueCount = %d, PK queueCount = %d\n",
372 QMgrCount(N8_EA), QMgrCount(N8_PKP));