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 static char const n8_id
[] = "$Id: n8_system.c,v 1.1 2008/10/30 12:02:15 darran Exp $";
36 /*****************************************************************************/
38 * @brief Implements the API call N8_GetSystemParameter, which allows users to
39 * query the system for characteristics as defined in the enumeration
41 *****************************************************************************/
43 /*****************************************************************************
46 * 05/16/03 brr Eliminate obsolete include file.
47 * 03/10/03 brr Added N8_INITIALIZE_INFO parameter to N8_GetSystemParameter.
48 * 03/02/03 bac Added support for N8_HARDWAREREVISION.
49 * 07/08/02 brr Added N8_FILEDESCRIPTOR parameter to N8_GetSystemParameter.
50 * 04/05/02 brr Added N8_SWVERSIONTEXT parameter to N8_GetSystemParameter.
51 * 04/03/02 brr Use version identification from n8_version.h. Also added
52 * N8_PrintSoftwareVersion api call to print version info.
53 * 02/25/02 brr Updated for 2.1 release. Use a single call to obtain driver
54 * information & removed all QMgr references.
55 * 10/30/01 hml First working version.
56 * 06/10/01 mel Original version.
57 ****************************************************************************/
58 /** @defgroup SystemInfo System Parameter retrieval
62 #include "n8_API_Initialize.h"
63 #include "n8_device_info.h"
64 #include "n8_version.h"
66 static N8_Status_t
setCount(N8_Buffer_t
*value_p
, N8_Status_t type
);
67 static N8_Status_t
setType(N8_Buffer_t
*value_p
, N8_Status_t type
);
68 static N8_Status_t
setNumberOfChips(N8_Buffer_t
*value_p
);
69 static N8_Status_t
setHWversion(N8_Buffer_t
*value_p
);
70 static N8_Status_t
setHWrevision(N8_Buffer_t
*value_p
);
71 static N8_Status_t
setSWversion(N8_Buffer_t
*value_p
);
72 static N8_Status_t
setContextSize(N8_Buffer_t
*value_p
);
73 static N8_Status_t
setSKSsize(N8_Buffer_t
*value_p
);
74 static N8_Status_t
setSWversionText(N8_Buffer_t
*value_p
);
75 static N8_Status_t
setFD(N8_Buffer_t
*value_p
);
76 static N8_Status_t
setInitInfo(N8_Buffer_t
*value_p
);
78 extern NSPdriverInfo_t nspDriverInfo
;
80 /*****************************************************************************
81 * N8_GetSystemParameter
82 *****************************************************************************/
83 /** @ingroup SystemInfo
84 * @brief Allows the caller to determine the value of various NSP2000 and API
85 * system and configuration values.
87 * The configuration parameter desired is determined by the value specified in
88 * Parameter. Note that the hash units are currently being treated the same
89 * as the EA units since the NSP2000 does not have a separate hash core.
91 * @param parameter RO: A constant naming the configuration value to
93 * @param value_p WO: A pointer to where to return the value(s) of the
94 * requested system parameter. The format (type) of
95 * what is returned depends on the value of
99 * returnResult - returns N8_STATUS_OK if successful or Error value.
101 * N8_INVALID_ENUM - The value of Parameter is not one of the
102 * defined valid configuration enumerations.
103 * N8_INVALID_OBJECT The output parameter is NULL.
106 *****************************************************************************/
107 N8_Status_t
N8_GetSystemParameter(N8_Parameter_t parameter
, void *value_p
)
109 N8_Status_t ret
= N8_STATUS_OK
;
111 DBG(("N8_GetSystemParameter\n"));
117 /* verify value object */
118 CHECK_OBJECT(value_p
, ret
);
123 ret
= setCount(value_p
, N8_EA
);
126 ret
= setType(value_p
, N8_EA
);
129 ret
= setCount(value_p
, N8_PKP
);
132 ret
= setType(value_p
, N8_PKP
);
135 ret
= setCount(value_p
, N8_EA
);
138 ret
= setType(value_p
, N8_EA
);
140 case N8_HARDWAREVERSION
:
141 ret
= setHWversion(value_p
);
143 case N8_HARDWAREREVISION
:
144 ret
= setHWrevision(value_p
);
146 case N8_SOFTWAREVERSION
:
147 ret
= setSWversion(value_p
);
149 case N8_CONTEXTMEMSIZE
:
150 ret
= setContextSize(value_p
);
153 ret
= setSKSsize(value_p
);
155 case N8_NUMBEROFCHIPS
:
156 ret
= setNumberOfChips(value_p
);
158 case N8_SWVERSIONTEXT
:
159 ret
= setSWversionText(value_p
);
161 case N8_INITIALIZE_INFO
:
162 ret
= setInitInfo(value_p
);
164 case N8_FILEDESCRIPTOR
:
165 ret
= setFD(value_p
);
168 /* invalid parameter */
169 DBG(("Invalid parameter\n"));
170 DBG(("N8_GetSystemParameter - return Error\n"));
171 ret
= N8_INVALID_ENUM
;
175 DBG(("N8_GetSystemParameter - OK\n"));
177 } /* N8_GetSystemParameter */
180 /*****************************************************************************
182 *****************************************************************************/
183 /** @ingroup SystemInfo
184 * @brief Get the count of units.
186 * Currently all of the hardware or emulation types have only one unit of any
187 * type. As soon as this ceases to be true, we will need to call the driver
188 * function N8_GetConfigurationItem or depend on knowledge of the
189 * hardware type being stored in the QueueControl structure.
192 * @param value_p WO: Pointer in which to store the number of units.
198 * N8_STATUS_OK: The function worked correctly.
199 * N8_INVALID_OBJECT: The output pointer is NULL.
200 * N8_UNEXPECTED_ERROR: The hardware type in one of the queues
201 * was not recognized.
204 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
212 * This function can not be called until the initialization of the API
214 *****************************************************************************/
216 static N8_Status_t
setCount(N8_Buffer_t
*value_p
, N8_Component_t type
)
218 N8_Status_t ret
= N8_STATUS_OK
;
220 unsigned int nDevices
= 0;
226 CHECK_OBJECT(value_p
, ret
);
228 nStructs
= nspDriverInfo
.numChips
;
230 for (i
= 0; i
< nStructs
; i
++)
233 switch (nspDriverInfo
.chipInfo
[i
].hardwareType
)
235 /* Note that all of these devices have only one unit
236 per device. This may well change with future devices.
244 ret
= N8_UNEXPECTED_ERROR
;
251 DBG(("setCount - OK\n"));
253 if (ret
== N8_STATUS_OK
)
255 memcpy(value_p
, &nDevices
, sizeof(int));
260 /*****************************************************************************
262 *****************************************************************************/
263 /** @ingroup SystemInfo
264 * @brief Get types of units.
266 * Currently all of the hardware or emulation types have only one unit of any
267 * type. When this ceases to be true, we will need to revisit this call.
269 * @param value_p WO: Pointer in which to store unit types.
275 * N8_STATUS_OK: The function worked correctly.
276 * N8_INVALID_OBJECT: The output pointer is NULL.
277 * N8_UNEXPECTED_ERROR: The hardware type in one of the queues
278 * was not recognized.
281 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
289 * This function can not be called until the initialization of the API
290 * is complete. The value_p pointer points to a "reasonable" array.
291 *****************************************************************************/
293 static N8_Status_t
setType(N8_Buffer_t
*value_p
, N8_Component_t type
)
295 N8_Status_t ret
= N8_STATUS_OK
;
298 unsigned int *vPtr_p
;
303 CHECK_OBJECT(value_p
, ret
);
305 nStructs
= nspDriverInfo
.numChips
;
307 vPtr_p
= (unsigned int *)value_p
;
309 for (i
= 0; i
< nStructs
; i
++)
311 switch (nspDriverInfo
.chipInfo
[i
].hardwareType
)
313 /* Note that all of these devices have only one unit
314 per device. This may well change with future devices.
318 *vPtr_p
= N8_NSP2000EMULATED
;
321 *vPtr_p
= N8_NSP2000
;
324 ret
= N8_UNEXPECTED_ERROR
;
332 DBG(("setType - OK\n"));
336 /*****************************************************************************
338 *****************************************************************************/
339 /** @ingroup SystemInfo
340 * @brief Gets the hardware version or returns an emulation type for each
341 * chip or emulation thereof in the current system.
343 * @param value_p WO: Pointer in which to store chip types.
349 * N8_STATUS_OK: The function worked correctly.
350 * N8_INVALID_OBJECT: The output pointer is NULL.
351 * N8_UNEXPECTED_ERROR: The hardware type in one of the queues
352 * was not recognized.
355 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
363 * This function can not be called until the initialization of the API
364 * is complete. The value_p pointer points to a "reasonable" array.
365 *****************************************************************************/
366 static N8_Status_t
setHWversion(N8_Buffer_t
*value_p
)
368 N8_Status_t ret
= N8_STATUS_OK
;
371 unsigned int *vPtr_p
;
373 DBG(("setHWversion\n"));
376 CHECK_OBJECT(value_p
, ret
);
378 nStructs
= nspDriverInfo
.numChips
;
380 vPtr_p
= (unsigned int *) value_p
;
382 for (i
= 0; i
< nStructs
; i
++)
384 switch (nspDriverInfo
.chipInfo
[i
].hardwareType
)
386 /* Note that we only care to know whether or not there is real
387 hardware for this queue.
391 *vPtr_p
= N8_NSP2000EMULATED
;
394 *vPtr_p
= nspDriverInfo
.chipInfo
[i
].HardwareVersion
;
397 ret
= N8_UNEXPECTED_ERROR
;
405 DBG(("setHWversion - OK\n"));
410 /*****************************************************************************
412 *****************************************************************************/
413 /** @ingroup SystemInfo
414 * @brief Gets the hardware revision from the PCI interface. This value is the
415 * same as returned by 'lspci' under Linux.
417 * @param value_p WO: Pointer in which to store chip types.
423 * N8_STATUS_OK: The function worked correctly.
424 * N8_INVALID_OBJECT: The output pointer is NULL.
425 * N8_UNEXPECTED_ERROR: The hardware type in one of the queues
426 * was not recognized.
429 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
436 * This function can not be called until the initialization of the API
437 * is complete. The value_p pointer points to a "reasonable" array.
438 *****************************************************************************/
439 static N8_Status_t
setHWrevision(N8_Buffer_t
*value_p
)
441 N8_Status_t ret
= N8_STATUS_OK
;
444 unsigned int *vPtr_p
;
446 DBG(("setHWrevision\n"));
449 CHECK_OBJECT(value_p
, ret
);
451 nStructs
= nspDriverInfo
.numChips
;
453 vPtr_p
= (unsigned int *) value_p
;
455 for (i
= 0; i
< nStructs
; i
++)
457 *vPtr_p
= (unsigned int) nspDriverInfo
.chipInfo
[i
].RevisionID
;
463 DBG(("setHWrevision - OK\n"));
466 } /* setHWrevision */
468 /*****************************************************************************
470 *****************************************************************************/
471 /** @ingroup SystemInfo
472 * @brief Get the current version of the software.
474 * This function returns the current major and minor revision numbers of the
475 * SDK as specified by the N8_MAJOR_REVISION and N8_MINOR_REVISION #defines
476 * at the top of this file. When the software revision is changed, change
479 * @param value_p WO: Pointer in which to store revision info.
485 * N8_STATUS_OK: The function worked correctly.
486 * N8_INVALID_OBJECT: The output pointer is NULL.
489 * N8_INVALID_OBJECT as described in the return section.
495 * This function can not be called until the initialization of the API
496 * is complete. The value_p pointer points to a "reasonable" location.
497 *****************************************************************************/
498 static N8_Status_t
setSWversion(N8_Buffer_t
*value_p
)
500 N8_Status_t ret
= N8_STATUS_OK
;
501 unsigned int version
= 0;
503 DBG(("setSWversion\n"));
506 CHECK_OBJECT(value_p
, ret
);
507 version
= N8_VERSION
;
508 memcpy(value_p
, &version
, sizeof(unsigned int));
510 DBG(("setSWversion - OK\n"));
514 /*****************************************************************************
516 *****************************************************************************/
517 /** @ingroup SystemInfo
518 * @brief Get the sizes of the context memory for all EA units.
520 * Currently all of the hardware or emulation types have only one unit of any
521 * type. When this ceases to be true, we will need to revisit this call.
523 * @param value_p WO: Pointer in which to store unit types.
529 * N8_STATUS_OK: The function worked correctly.
530 * N8_INVALID_OBJECT: The output pointer is NULL.
533 * N8_INVALID_OBJECT as described in the return section.
540 * This function can not be called until the initialization of the API
541 * is complete. The value_p pointer points to a "reasonable" array.
542 *****************************************************************************/
543 static N8_Status_t
setContextSize(N8_Buffer_t
*value_p
)
545 N8_Status_t ret
= N8_STATUS_OK
;
548 unsigned long *vPtr_p
;
550 DBG(("setContextSize\n"));
553 CHECK_OBJECT(value_p
, ret
);
555 nStructs
= nspDriverInfo
.numChips
;
557 vPtr_p
= (unsigned long *) value_p
;
559 for (i
= 0; i
< nStructs
; i
++)
561 memcpy(vPtr_p
, &nspDriverInfo
.chipInfo
[i
].contextMemsize
, sizeof(int));
567 DBG(("setContextSize - OK\n"));
569 } /* setContextSize */
571 /*****************************************************************************
573 *****************************************************************************/
574 /** @ingroup SystemInfo
575 * @brief Get the sizes of the SKS memory for all PKP units.
577 * Currently all of the hardware or emulation types have only one unit of any
578 * type. When this ceases to be true, we will need to revisit this call.
580 * @param value_p WO: Pointer in which to store unit types.
586 * N8_STATUS_OK: The function worked correctly.
587 * N8_INVALID_OBJECT: The output pointer is NULL.
590 * N8_INVALID_OBJECT as described in the return section.
597 * This function can not be called until the initialization of the API
598 * is complete. The value_p pointer points to a "reasonable" array.
599 *****************************************************************************/
600 static N8_Status_t
setSKSsize(N8_Buffer_t
*value_p
)
602 N8_Status_t ret
= N8_STATUS_OK
;
605 unsigned long *vPtr_p
;
607 DBG(("setSKSSize\n"));
610 CHECK_OBJECT(value_p
, ret
);
612 nStructs
= nspDriverInfo
.numChips
;
614 vPtr_p
= (unsigned long *)value_p
;
616 for (i
= 0; i
< nStructs
; i
++)
618 memcpy(vPtr_p
, &nspDriverInfo
.chipInfo
[i
].SKS_size
, sizeof(unsigned long));
624 DBG(("setSKSSize - OK\n"));
628 /*****************************************************************************
630 *****************************************************************************/
631 /** @ingroup SystemInfo
632 * @brief Get the number of chips on the system.
634 * Because we also want to include the number of "emulated" chips on the system,
635 * we can simply return the number of control structures on the system.
637 * @param value_p WO: Pointer in which to store unit types.
643 * N8_STATUS_OK: The function worked correctly.
644 * N8_INVALID_OBJECT: The output pointer is NULL.
647 * N8_INVALID_OBJECT as described in the return section.
654 * This function can not be called until the initialization of the API
655 * is complete. The value_p pointer points to a "reasonable" memory location.
656 *****************************************************************************/
657 static N8_Status_t
setNumberOfChips(N8_Buffer_t
*value_p
)
659 N8_Status_t ret
= N8_STATUS_OK
;
662 DBG(("setNumberOfChips\n"));
664 nStructs
= nspDriverInfo
.numChips
;
666 DBG(("setNumberOfChips - OK\n"));
667 memcpy(value_p
, &nStructs
, sizeof(int));
670 } /* setNumberOfChips */
672 /*****************************************************************************
674 *****************************************************************************/
675 /** @ingroup SystemInfo
676 * @brief Returns a text string that describes this version of the SDK library.
681 * ret - always returns N8_STATUS_OK.
687 *****************************************************************************/
688 N8_Status_t
setSWversionText(N8_Buffer_t
*value_p
)
690 sprintf(value_p
, N8_VERSION_STRING
);
692 } /* setSWversionText */
694 /*****************************************************************************
696 *****************************************************************************/
697 /** @ingroup SystemInfo
698 * @brief Get the file descriptor for the NSP2000
700 * This function returns the file descriptor for the NSP2000 device.
702 * @param value_p WO: Pointer in which to store revision info.
708 * N8_STATUS_OK: The function worked correctly.
709 * N8_INVALID_OBJECT: The output pointer is NULL.
712 * N8_INVALID_OBJECT as described in the return section.
718 * This function can not be called until the initialization of the API
719 * is complete. The value_p pointer points to a "reasonable" location.
720 *****************************************************************************/
721 static N8_Status_t
setFD(N8_Buffer_t
*value_p
)
723 N8_Status_t ret
= N8_STATUS_OK
;
729 CHECK_OBJECT(value_p
, ret
);
731 memcpy(value_p
, &fd
, sizeof(unsigned int));
733 DBG(("setFD - OK\n"));
736 /*****************************************************************************
738 *****************************************************************************/
739 /** @ingroup SystemInfo
740 * @brief Get the configuration parameters used to initialize the API.
742 * This function returns the configuration parameters that were used to
743 * initialize the API.
745 * @param value_p WO: Pointer in which to store revision info.
751 * N8_STATUS_OK: The function worked correctly.
752 * N8_INVALID_OBJECT: The output pointer is NULL.
755 * N8_INVALID_OBJECT as described in the return section.
761 * This function can not be called until the initialization of the API
762 * is complete. The value_p pointer points to a "reasonable" location.
763 *****************************************************************************/
764 static N8_Status_t
setInitInfo(N8_Buffer_t
*value_p
)
766 N8_Status_t ret
= N8_STATUS_OK
;
768 DBG(("setInitInfo\n"));
771 CHECK_OBJECT(value_p
, ret
);
772 n8_getConfigInfo((N8_ConfigAPI_t
*)value_p
);
774 DBG(("setInitInfo - OK\n"));