Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / n8 / common / api / n8_system.c
blob20158c16dbc2e17ee7a4ba7bd8ad0d66302648a8
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_system.c,v 1.1 2008/10/30 12:02:15 darran Exp $";
36 /*****************************************************************************/
37 /** @file n8_system.c
38 * @brief Implements the API call N8_GetSystemParameter, which allows users to
39 * query the system for characteristics as defined in the enumeration
40 * N8_Parameter_t.
41 *****************************************************************************/
43 /*****************************************************************************
44 * Revision history:
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
61 #include "n8_util.h"
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
92 * return.
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
96 * Parameter.
98 * @return
99 * returnResult - returns N8_STATUS_OK if successful or Error value.
100 * @par Errors
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.
104 * @par Assumptions
105 * None<br>
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"));
114 ret = N8_preamble();
115 CHECK_RETURN(ret);
117 /* verify value object */
118 CHECK_OBJECT(value_p, ret);
120 switch (parameter)
122 case N8_EACOUNT:
123 ret = setCount(value_p, N8_EA);
124 break;
125 case N8_EATYPE:
126 ret = setType(value_p, N8_EA);
127 break;
128 case N8_PKCOUNT:
129 ret = setCount(value_p, N8_PKP);
130 break;
131 case N8_PKTYPE:
132 ret = setType(value_p, N8_PKP);
133 break;
134 case N8_HPCOUNT:
135 ret = setCount(value_p, N8_EA);
136 break;
137 case N8_HPTYPE:
138 ret = setType(value_p, N8_EA);
139 break;
140 case N8_HARDWAREVERSION:
141 ret = setHWversion(value_p);
142 break;
143 case N8_HARDWAREREVISION:
144 ret = setHWrevision(value_p);
145 break;
146 case N8_SOFTWAREVERSION:
147 ret = setSWversion(value_p);
148 break;
149 case N8_CONTEXTMEMSIZE:
150 ret = setContextSize(value_p);
151 break;
152 case N8_SKSMEMSIZE:
153 ret = setSKSsize(value_p);
154 break;
155 case N8_NUMBEROFCHIPS:
156 ret = setNumberOfChips(value_p);
157 break;
158 case N8_SWVERSIONTEXT:
159 ret = setSWversionText(value_p);
160 break;
161 case N8_INITIALIZE_INFO:
162 ret = setInitInfo(value_p);
163 break;
164 case N8_FILEDESCRIPTOR:
165 ret = setFD(value_p);
166 break;
167 default:
168 /* invalid parameter */
169 DBG(("Invalid parameter\n"));
170 DBG(("N8_GetSystemParameter - return Error\n"));
171 ret = N8_INVALID_ENUM;
172 break;
173 } /* switch */
174 }while (FALSE);
175 DBG(("N8_GetSystemParameter - OK\n"));
176 return ret;
177 } /* N8_GetSystemParameter */
180 /*****************************************************************************
181 * setCount
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.
194 * @par Externals:
195 * None.
197 * @return
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.
203 * @par Errors:
204 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
205 * return section.
208 * @par Locks:
209 * None.
211 * @par Assumptions:
212 * This function can not be called until the initialization of the API
213 * is complete.
214 *****************************************************************************/
216 static N8_Status_t setCount(N8_Buffer_t *value_p, N8_Component_t type)
218 N8_Status_t ret = N8_STATUS_OK;
219 int nStructs;
220 unsigned int nDevices = 0;
221 int i;
223 DBG(("setCount\n"));
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.
238 case N8_FPGA:
239 case N8_BM:
240 case N8_NSP2000_HW:
241 nDevices ++;
242 break;
243 default:
244 ret = N8_UNEXPECTED_ERROR;
247 CHECK_RETURN(ret);
249 }while (FALSE);
251 DBG(("setCount - OK\n"));
253 if (ret == N8_STATUS_OK)
255 memcpy(value_p, &nDevices, sizeof(int));
257 return ret;
258 } /* setCount */
260 /*****************************************************************************
261 * setType
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.
271 * @par Externals:
272 * None.
274 * @return
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.
280 * @par Errors:
281 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
282 * return section.
285 * @par Locks:
286 * None.
288 * @par Assumptions:
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;
296 int nStructs;
297 int i;
298 unsigned int *vPtr_p;
300 DBG(("setType\n"));
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.
316 case N8_FPGA:
317 case N8_BM:
318 *vPtr_p = N8_NSP2000EMULATED;
319 break;
320 case N8_NSP2000_HW:
321 *vPtr_p = N8_NSP2000;
322 break;
323 default:
324 ret = N8_UNEXPECTED_ERROR;
326 vPtr_p ++;
328 CHECK_RETURN(ret);
330 }while (FALSE);
332 DBG(("setType - OK\n"));
334 return ret;
335 } /* setType */
336 /*****************************************************************************
337 * setHWversion
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.
345 * @par Externals:
346 * None.
348 * @return
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.
354 * @par Errors:
355 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
356 * return section.
359 * @par Locks:
360 * None.
362 * @par Assumptions:
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;
369 int nStructs;
370 int i;
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.
389 case N8_FPGA:
390 case N8_BM:
391 *vPtr_p = N8_NSP2000EMULATED;
392 break;
393 case N8_NSP2000_HW:
394 *vPtr_p = nspDriverInfo.chipInfo[i].HardwareVersion;
395 break;
396 default:
397 ret = N8_UNEXPECTED_ERROR;
399 vPtr_p ++;
401 CHECK_RETURN(ret);
403 }while (FALSE);
405 DBG(("setHWversion - OK\n"));
407 return ret;
408 } /* setHWversion */
410 /*****************************************************************************
411 * setHWrevision
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.
419 * @par Externals:
420 * None.
422 * @return
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.
428 * @par Errors:
429 * N8_INVALID_OBJECT and N8_UNEXPECTED_ERROR as described in the
430 * return section.
432 * @par Locks:
433 * None.
435 * @par Assumptions:
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;
442 int nStructs;
443 int i;
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;
458 vPtr_p ++;
461 } while (FALSE);
463 DBG(("setHWrevision - OK\n"));
465 return ret;
466 } /* setHWrevision */
468 /*****************************************************************************
469 * setSWVersion
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
477 * these defines.
479 * @param value_p WO: Pointer in which to store revision info.
481 * @par Externals:
482 * None.
484 * @return
485 * N8_STATUS_OK: The function worked correctly.
486 * N8_INVALID_OBJECT: The output pointer is NULL.
488 * @par Errors:
489 * N8_INVALID_OBJECT as described in the return section.
491 * @par Locks:
492 * None.
494 * @par Assumptions:
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));
509 }while (FALSE);
510 DBG(("setSWversion - OK\n"));
511 return ret;
512 } /* setSWversion */
514 /*****************************************************************************
515 * setContextSize
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.
525 * @par Externals:
526 * None.
528 * @return
529 * N8_STATUS_OK: The function worked correctly.
530 * N8_INVALID_OBJECT: The output pointer is NULL.
532 * @par Errors:
533 * N8_INVALID_OBJECT as described in the return section.
536 * @par Locks:
537 * None.
539 * @par Assumptions:
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;
546 int nStructs;
547 int i;
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));
562 vPtr_p ++;
564 CHECK_RETURN(ret);
565 }while (FALSE);
567 DBG(("setContextSize - OK\n"));
568 return ret;
569 } /* setContextSize */
571 /*****************************************************************************
572 * setSKSsize
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.
582 * @par Externals:
583 * None.
585 * @return
586 * N8_STATUS_OK: The function worked correctly.
587 * N8_INVALID_OBJECT: The output pointer is NULL.
589 * @par Errors:
590 * N8_INVALID_OBJECT as described in the return section.
593 * @par Locks:
594 * None.
596 * @par Assumptions:
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;
603 int nStructs;
604 int i;
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));
619 vPtr_p ++;
621 CHECK_RETURN(ret);
622 }while (FALSE);
624 DBG(("setSKSSize - OK\n"));
625 return ret;
626 } /* setSKSsize */
628 /*****************************************************************************
629 * setNumberOfChips
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.
639 * @par Externals:
640 * None.
642 * @return
643 * N8_STATUS_OK: The function worked correctly.
644 * N8_INVALID_OBJECT: The output pointer is NULL.
646 * @par Errors:
647 * N8_INVALID_OBJECT as described in the return section.
650 * @par Locks:
651 * None.
653 * @par Assumptions:
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;
660 int nStructs;
662 DBG(("setNumberOfChips\n"));
664 nStructs = nspDriverInfo.numChips;
666 DBG(("setNumberOfChips - OK\n"));
667 memcpy(value_p, &nStructs, sizeof(int));
669 return ret;
670 } /* setNumberOfChips */
672 /*****************************************************************************
673 * setSWversionText
674 *****************************************************************************/
675 /** @ingroup SystemInfo
676 * @brief Returns a text string that describes this version of the SDK library.
678 * @param NONE
680 * @return
681 * ret - always returns N8_STATUS_OK.
683 * @par Errors
685 * @par Assumptions
686 * None<br>
687 *****************************************************************************/
688 N8_Status_t setSWversionText(N8_Buffer_t *value_p)
690 sprintf(value_p, N8_VERSION_STRING);
691 return N8_STATUS_OK;
692 } /* setSWversionText */
694 /*****************************************************************************
695 * setFD
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.
704 * @par Externals:
705 * None.
707 * @return
708 * N8_STATUS_OK: The function worked correctly.
709 * N8_INVALID_OBJECT: The output pointer is NULL.
711 * @par Errors:
712 * N8_INVALID_OBJECT as described in the return section.
714 * @par Locks:
715 * None.
717 * @par Assumptions:
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;
724 int fd = 0;
726 DBG(("setFD\n"));
729 CHECK_OBJECT(value_p, ret);
730 fd = N8_GetFD();
731 memcpy(value_p, &fd, sizeof(unsigned int));
732 }while (FALSE);
733 DBG(("setFD - OK\n"));
734 return ret;
735 } /* setFD */
736 /*****************************************************************************
737 * setInitInfo
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.
747 * @par Externals:
748 * None.
750 * @return
751 * N8_STATUS_OK: The function worked correctly.
752 * N8_INVALID_OBJECT: The output pointer is NULL.
754 * @par Errors:
755 * N8_INVALID_OBJECT as described in the return section.
757 * @par Locks:
758 * None.
760 * @par Assumptions:
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);
773 }while (FALSE);
774 DBG(("setInitInfo - OK\n"));
775 return ret;