1 /*-
2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
3 * All rights reserved.
4 *
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:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
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.
21 *
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.
33 */
34
35 static char const n8_id[] = "$Id: config.c,v 1.4 2015/04/13 16:33:25 riastradh Exp $";
36 /*****************************************************************************/
37 /** @file config.c
38 * @brief NSP2000 Device Driver Configuration Manager.
39 *
40 * This file implements the configuration management routines for the NSP2000
41 * device driver.
42 *
43 *****************************************************************************/
44
45 /*****************************************************************************
46 * Revision history:
47 * 02/15/04 jpw Dynamically allocate queue size based on the number of
48 * chips installed as counted by NSPcount_g. Note that FreeBSD
49 * currently requires this value to be forced since it doesn't
50 * know how to properly count devices.
51 * 05/15/03 brr Enable RNG interrupt, enable interrupts only in
52 * n8_enableInterrupts().
53 * 05/09/03 brr Add user pool count to driver infomation.
54 * 05/07/03 brr Do not fail HW resource allocation if SKS is not present.
55 * 04/30/03 brr Reconcile differences between 2.4 & 3.0 baselines.
56 * 04/21/03 brr Added support for multiple memory banks.
57 * 03/19/03 brr Modified N8_ConfigInterrupts to always enble the AMBA timer
58 * and the PK command complete interrupt.
59 * 03/03/03 jpw Added N8_EnableAmbaTimer_g param to N8_ConfigInterrupts
60 * 03/11/03 brr Added N8_CloseDevice so N8_InitializeAPI can be common.
61 * 03/10/03 brr Added N8_OpenDevice so N8_InitializeAPI can be common.
62 * 02/20/03 brr Removed references to shared memory.
63 * 11/25/02 brr Reworked initialization to us common functions to allocate
64 * all resources for NSP2000 driver and each chip.
65 * 10/23/02 brr Modified N8_ConfigInterrupts to accept parameter for
66 * the AMBA timer preset.
67 * 10/25/02 brr Clean up function prototypes & include files.
68 * 10/22/02 brr Retrieve driverMode in N8_GetConfig.
69 * 09/25/02 brr Eliminate references to EVENT_WAIT_TYPE.
70 * 09/10/02 brr Conditionally enable either the amba timer interrupt or
71 * the command completion interrupts.
72 * 07/08/02 brr Added N8_GetFD to return NULL fd for kernel API.
73 * 06/26/02 brr Remove bank parameter from calls to N8_PhysToVirt.
74 * 06/25/02 brr Rework user pool allocation to only mmap portion used by
75 * the individual process.
76 * 06/12/02 hml Calls to N8_PhysToVirt now take the bank parameter.
77 * 06/10/02 hml Calls to pmalloc now use the bank parameter
78 * 06/07/02 brr Call SKS_Remove to deallocate SKS resources.
79 * 05/30/02 brr Enable interrupts for error conditions.
80 * 05/22/02 hml Passed memCtlBank parameter to call to n8_pmalloc
81 * and n8_pfree.
82 * 05/09/02 brr Allocate and setup BNC constants.
83 * 05/02/02 brr Call SKS_Init to perform all SKS initialization. Do not
84 * allocate SKS map from memory pool.
85 * 04/03/02 brr Use N8_VERSION as defined in n8_version.h.
86 * 04/03/02 spm Removed #include of daemon headers.
87 * 03/29/02 brr Modified N8_ConfigInterrupts to use N8_AMBA_TIMER_CHIP.
88 * 03/20/02 msz Don't do consecutive 32 bit writes.
89 * 03/20/02 brr Modified N8_ConfigInterrupts to configure & enable
90 * interrupts on all detected devices.
91 * 03/19/02 msz Shadow memory is now called shared memory, and is not
92 * allocated here.
93 * 03/18/02 brr Pass null session ID into pmalloc function.
94 * 03/18/02 msz We no longer need the shadow queue nor its memory
95 * 03/12/02 brr Moved daemon initialization to base.c
96 * 03/08/02 brr Memset SKS & shadow memory allocations to zero since
97 * n8_pmalloc is no longer clearing allocations.
98 * 03/01/02 brr Added N8_DisableInterrupts.
99 * 02/22/02 spm Converted printk's to DBG's. Added include of n8_OS_intf.h
100 * 02/25/02 brr Removed references to qmgrData & modified N8_GetConfig to
101 * return all driver information in a single call.
102 * 02/15/02 brr Moved context memory functions to contextMem.c.
103 * 02/14/02 brr Reconcile memory management differences with 2.0.
104 * 02/04/02 msz Enable interrupts for errors, pass hwidx so timer is enabled
105 * only on first nsp.
106 * 01/25/02 bac Added include of bigalloc_support.h as required.
107 * 01/30/02 brr Modified to support changes in bigalloc.
108 * 01/21/02 msz Set up event wait type based on header options
109 * 01/21/02 brr Modified to remove the mmap on each buffer on allocation.
110 * 02/13/02 brr Conditionally initialize the daemon.
111 * 02/15/02 brr Moved context memory functions to contextMem.c.
112 * 01/21/02 spm Moved SKS_Prom2Cache to n8_sksInit.c.
113 * 01/19/02 spm Changed n8_daemon_kernel.h to n8_daemon_internals.h
114 * 01/17/02 spm Added call to n8_daemon_init to N8_AllocateHardwareResources.
115 * This does initialization of the N8 daemon.
116 * 01/17/02 brr Updated for new memory management scheme.
117 * 01/16/02 brr Removed FPGA support.
118 * 01/14/02 brr Correctly pass shadow register pointers to QMGR.
119 * 01/10/02 mmd Removed fixed context memory size. Modified
120 * N8_GetContextMemSize to simply return a size, and no longer
121 * return any kind of error. If Context Memory accesses fail,
122 * it now indicates 0 bytes available. Corrected the Context
123 * memory read/write routines to correctly read/write (no longer
124 * clearing pending ops, and no longer sleeping, but instead
125 * expecting any pending ops to complete within a reasonable
126 * time).
127 * 01/10/02 msz Disable bridge timer when we are done.
128 * 01/03/02 brr Setup and enable bridge timer.
129 * 12/21/01 brr Fix context memory size to 64MB.
130 * 12/20/01 brr Perform all static allocation with sessionID 0.
131 * 12/18/01 brr Perform all static allocation from n8_pmalloc.
132 * 12/14/01 brr Support dynamic queue sizing & memory management performance
133 * improvements.
134 * 12/06/01 brr Added seperate define for RNG queue sizing, moved SKS init
135 * to the driver, and correct context memory detection.
136 * 12/05/01 brr Move queue initialization to the driver.
137 * 11/26/01 mmd Updated parms for N8_ConfigInit to accomodate new PCIinfo
138 * field of NspInstance_t. Generally updated N8_ConfigInit and
139 * N8_GetConfig to ensure full support of both ASIC and FPGA.
140 * 11/14/01 mmd Using global parm defines from n8_driver_parms.h.
141 * 11/13/01 mmd Implemented N8_AllocateHardwareResources and
142 * N8_ReleaseHardwareResources;
143 * 11/10/01 brr Modified to support static allocations of persistant data
144 * by the driver.
145 * 11/06/01 mmd Now calls admxrc_eeprom_read to determine values for
146 * FPGA_Type and FPGA_CrystalType.
147 * 10/29/01 mmd N8_OpenRulesChecker now uses N8_UTIL_MALLOC instead of
148 * N8_VIRT_MALLOC. N8_CloseRulesChecker now uses N8_UTIL_FREE.
149 * 10/22/01 mmd Implemented N8_ClaimHardwareInstance and
150 * N8_ReleaseHardwareInstance.
151 * 10/12/01 mmd Renamed Atomic*() routines to N8_Atomic*().
152 * 10/12/01 mmd Implemented N8_OpenRulesChecker, N8_CloseRulesChecker, and
153 * N8_PurgeNextRelatedSession, as well as the global process
154 * table. Also now initializing the programmed field of
155 * NspInstance_t.
156 * 09/25/01 mmd Creation.
157 ****************************************************************************/
158 /** @defgroup NSP2000Driver NSP2000 Device Driver Configuration Manager.
159 */
160
161 #include <sys/param.h>
162 #include <sys/systm.h>
163 #include <sys/proc.h>
164 #include <sys/endian.h>
165 #ifdef __NetBSD__
166 #define letoh16 htole16
167 #define letoh32 htole32
168 #endif
169 #include <sys/errno.h>
170 #include <sys/malloc.h>
171 #include <sys/kernel.h>
172 #include <sys/mbuf.h>
173 #include <sys/device.h>
174 #include <sys/queue.h>
175 #include <sys/module.h>
176 #include <sys/bus.h>
177
178 #include <opencrypto/cryptodev.h>
179 #include <opencrypto/xform.h>
180 #include <sys/md5.h>
181 #include <sys/sha1.h>
182
183 #include <dev/pci/pcireg.h>
184 #include <dev/pci/pcivar.h>
185 #include <dev/pci/pcidevs.h>
186
187 #include "n8_pub_errors.h"
188 #include "n8_driver_main.h"
189 #include "irq.h"
190 #include "n8_manage_memory.h"
191 #include "n8_pk_common.h"
192 #include "n8_rn_common.h"
193 #include "n8_ea_common.h"
194 #include "n8_sksInit.h"
195 #include "QMgrInit.h"
196 #include "config.h"
197 #include "nsp2000_regs.h"
198 #include "n8_version.h"
199 #include "n8_memory.h"
200 #include "userPool.h"
201 #include "n8_driver_api.h"
202 #if 0
203 #include "n8_OS_intf.h"
204 #include "helper.h"
205 #include "n8_driver_main.h"
206 #include "n8_driver_parms.h"
207 #include "irq.h"
208 #include "displayRegs.h"
209 #include "n8_memory.h"
210 #include "nsp_ioctl.h"
211 #include "n8_daemon_common.h"
212 #include "n8_sksInit.h"
213 #include "contextMem.h"
214 #include "n8_version.h"
215 #include "n8_pk_common.h"
216 #include "n8_rn_common.h"
217 #include "config.h"
218 #include "n8_driver_api.h"
219 #include "userPool.h"
220 #include "QMgrInit.h"
221 #include "n8_semaphore.h"
222 #endif
223
224 extern int NSPcount_g;
225 extern NspInstance_t NSPDeviceTable_g [];
226
227 int driverMode = 0;
228 unsigned long bncAddr = 0;
229 n8_WaitQueue_t requestBlock;
230 n8_WaitQueue_t nsp2000_wait;
231 /*****************************************************************************
232 * n8_chipInit
233 *****************************************************************************/
234 /** @ingroup NSP2000Driver
235 * @brief Allocates and initializes resources used by each nsp2000 core.
236 *
237 * This function allocates and initializes resources used by each nsp2000 core.
238 * It should be called once per chip detected as the driver is initialized.
239 *
240 *
241 * @param NSPinstance_p RO: Pointer to the information structure for an
242 * NSP2000 hardware instance, containing a
243 * pointer to its control register set.
244 * @param HWidx RO: Specifies the chip index.
245 * @param queueSize RO: The size of the command queue to allocate
246 * for the EA & PK cores.
247 * @param Debug RO: The value of the N8_Debug_g flag.
248 *
249 * @return
250 * N/A
251 *
252 * @par Errors:
253 * See return section for error information.
254 *****************************************************************************/
255
n8_chipInit(NspInstance_t * NSPinstance_p,int HWidx,int queueSize,unsigned char Debug)256 int n8_chipInit( NspInstance_t *NSPinstance_p,
257 int HWidx,
258 int queueSize,
259 unsigned char Debug)
260 {
261 volatile NSP2000REGS_t *nsp = (NSP2000REGS_t *)NSPinstance_p->NSPregs_p;
262 int queueLength; /* Number of entries */
263
264 /* First store model identifiers */
265 DBG(("store model id\n"));
266 NSPinstance_p->hardwareType = N8_NSP2000_HW;
267 NSPinstance_p->HardwareVersion = NSPinstance_p->PCIinfo.device_id;
268 NSPinstance_p->RevisionID = NSPinstance_p->PCIinfo.revision_id;
269
270 /* Initialize bus error statistics */
271 DBG(("bus error stats\n"));
272 NSPinstance_p->RNHbuserrors = 0;
273 NSPinstance_p->PKHbuserrors = 0;
274 NSPinstance_p->CCHbuserrors = 0;
275
276 /* Set the amba PCI endian mode register */
277 nsp->amba_pci_endian_mode = 0;
278
279 queueLength = 1 << queueSize;
280
281 /* Initialize sizes for allocated resources */
282 NSPinstance_p->RNqueue_size = 0;
283 NSPinstance_p->PKqueue_size = 0;
284 NSPinstance_p->EAqueue_size = 0;
285
286 /* Initialize physical base address of each queue and struct */
287 NSPinstance_p->RNqueue_base = 0;
288 NSPinstance_p->PKqueue_base = 0;
289 NSPinstance_p->EAqueue_base = 0;
290
291 NSPinstance_p->chip = HWidx;
292
293 /* Allocate static resources */
294 if (bncAddr == 0)
295 {
296 bncAddr = n8_pmalloc(N8_MEMBANK_QUEUE, PKDIGITS_TO_BYTES(2), 0);
297 DBG(("n8_pmalloc(N8_MEMBANK_QUEUE) -> 0x%x\n",
298 (uint32_t)bncAddr));
299 if (bncAddr)
300 {
301 char *bnc_one_p;
302 bnc_one_p = N8_PhysToVirt(bncAddr);
303 DBG(("bncAddr 0x%x -> virt 0x%x\n",
304 (uint32_t)bncAddr,
305 (uint32_t)bnc_one_p));
306 memset(bnc_one_p, 0x0, PKDIGITS_TO_BYTES(2));
307 bnc_one_p[PK_Bytes_Per_BigNum_Digit - 1] = 1;
308 }
309 else
310 {
311 DBG(( "NSP2000: Failed BNC constant allocation.\n"));
312 return 0;
313 }
314 }
315 NSPinstance_p->RNqueue_base = n8_pmalloc(N8_MEMBANK_QUEUE,
316 N8_DEF_RNG_QUE_SIZE*sizeof(RNG_Sample_t),
317 0);
318 if (!NSPinstance_p->RNqueue_base)
319 {
320 N8_PRINT(KERN_CRIT "NSP2000: Failed RN queue allocation.\n");
321 return 0;
322 }
323 NSPinstance_p->PKqueue_base = n8_pmalloc(N8_MEMBANK_QUEUE,
324 queueLength*sizeof(PK_CMD_BLOCK_t),
325 0);
326 if (!NSPinstance_p->PKqueue_base)
327 {
328 N8_PRINT(KERN_CRIT "NSP2000: Failed PK queue allocation.\n");
329 return 0;
330 }
331 NSPinstance_p->EAqueue_base = n8_pmalloc(N8_MEMBANK_QUEUE,
332 queueLength*sizeof(EA_CMD_BLOCK_t),
333 0);
334 if (!NSPinstance_p->EAqueue_base)
335 {
336 N8_PRINT(KERN_CRIT "NSP2000: Failed EA queue allocation.\n");
337 return 0;
338 }
339
340 /* Update sizes of allocated resources */
341 NSPinstance_p->RNqueue_size = N8_DEF_RNG_QUE_SIZE;
342 NSPinstance_p->PKqueue_size = queueLength;
343 NSPinstance_p->EAqueue_size = queueLength;
344
345
346 /* Convert physical base address of each struct to a kernel virtual address*/
347 NSPinstance_p->RNqueue_p = N8_PhysToVirt(NSPinstance_p->RNqueue_base);
348 NSPinstance_p->PKqueue_p = N8_PhysToVirt(NSPinstance_p->PKqueue_base);
349 NSPinstance_p->EAqueue_p = N8_PhysToVirt(NSPinstance_p->EAqueue_base);
350
351 /* EAshared_p and PKshared_p are owned by QMgr and are thus set by QMgr */
352
353 /* Set the queue pointers */
354 nsp->pkh_q_bar1 = 0;
355 nsp->cch_q_bar1 = 0;
356 nsp->rnh_q_bar1 = 0;
357
358 nsp->pkh_q_bar0 = NSPinstance_p->PKqueue_base;
359 nsp->cch_q_bar0 = NSPinstance_p->EAqueue_base;
360 nsp->rnh_q_bar0 = NSPinstance_p->RNqueue_base;
361
362 nsp->pkh_q_length = queueSize;
363 nsp->cch_q_length = queueSize;
364 nsp->rnh_q_length = N8_DEF_RNG_QUE_EXP;
365
366 /* Initialize the SKS data structures. */
367 if (!SKS_Init(NSPinstance_p))
368 {
369 N8_PRINT(KERN_CRIT "NSP2000: Failed to Initialize SKS.\n");
370 }
371
372 /* Enable the EA & PK Queues since they need no parameters to start. */
373 nsp->pkh_control_status |= NSP_CORE_ENABLE;
374 nsp->cch_control_status |= NSP_CORE_ENABLE;
375
376 if (Debug)
377 {
378 /* Announce allocations */
379 N8_PRINT(KERN_CRIT "NSP2000: Allocated RN queue - %ld entries @ %08lx.\n",
380 NSPinstance_p->RNqueue_size, NSPinstance_p->RNqueue_base);
381 N8_PRINT(KERN_CRIT "NSP2000: Allocated PK queue - %ld entries @ %08lx.\n",
382 NSPinstance_p->PKqueue_size, NSPinstance_p->PKqueue_base);
383 N8_PRINT(KERN_CRIT "NSP2000: Allocated EA queue - %ld entries @ %08lx.\n",
384 NSPinstance_p->EAqueue_size, NSPinstance_p->EAqueue_base);
385 }
386
387 /* Allocate resources to manage the context memory */
388 N8_ContextMemInit(HWidx);
389
390 /* Initialize QMgr. */
391 QMgrInit(HWidx);
392
393 /* Initialize wait queue for each core */
394 N8_InitWaitQueue(&NSPinstance_p->RNHblock);
395 N8_InitWaitQueue(&NSPinstance_p->CCHblock);
396 N8_InitWaitQueue(&NSPinstance_p->PKHblock);
397 N8_InitWaitQueue(&NSPinstance_p->AMBAblock);
398
399 return 1;
400 }
401
402
403
404 /*****************************************************************************
405 * n8_chipRemove
406 *****************************************************************************/
407 /** @ingroup NSP2000Driver
408 * @brief Deallocates resources for each chip.
409 *
410 * This funciton deallocates the resources used by each chip. Upon driver exit
411 * this function should be called once for each chip initialized.
412 *
413 * @param NSPinstance_p RO: Pointer to the information structure for an
414 * NSP2000 hardware instance, containing a
415 * pointer to its control register set.
416 * @param HWidx RO: Specifies the chip index.
417 *
418 * @return
419 * N/A
420 *
421 * @par Errors:
422 * See return section for error information.
423 *****************************************************************************/
424
n8_chipRemove(NspInstance_t * NSPinstance_p,int HWidx)425 N8_Status_t n8_chipRemove(NspInstance_t *NSPinstance_p, int HWidx)
426 {
427
428 volatile NSP2000REGS_t *nsp = (NSP2000REGS_t *)NSPinstance_p->NSPregs_p;
429
430 /* Disable each of the Cores */
431 nsp->pkh_control_status = 0;
432 nsp->cch_control_status = 0;
433 nsp->rnh_control_status = 0;
434
435 /* Reset the queue pointers */
436 nsp->pkh_q_bar0 = 0;
437 nsp->cch_q_bar0 = 0;
438 nsp->rnh_q_bar0 = 0;
439
440 /* Deallocate the resources used by the context memory management */
441 N8_ContextMemRemove(HWidx);
442
443 /* Remove the SKS data structures. */
444 SKS_Remove(NSPinstance_p);
445
446 /* Free static resources */
447 if (bncAddr)
448 {
449 n8_pfree(N8_MEMBANK_QUEUE, (void *)bncAddr);
450 bncAddr = 0;
451 }
452 n8_pfree(N8_MEMBANK_QUEUE, (void *)NSPinstance_p->RNqueue_base);
453 n8_pfree(N8_MEMBANK_QUEUE, (void *)NSPinstance_p->PKqueue_base);
454 n8_pfree(N8_MEMBANK_QUEUE, (void *)NSPinstance_p->EAqueue_base);
455
456 /* Reset sizes for allocated resources */
457 NSPinstance_p->RNqueue_size = 0;
458 NSPinstance_p->PKqueue_size = 0;
459 NSPinstance_p->EAqueue_size = 0;
460
461 /* Reset physical base address of each queue and struct */
462 NSPinstance_p->RNqueue_base = 0;
463 NSPinstance_p->PKqueue_base = 0;
464 NSPinstance_p->EAqueue_base = 0;
465
466 /* Disable the timer and its interrupt */
467 nsp->amba_pci_timer_preset = 0;
468 nsp->amba_pci_control = 0;
469
470 QMgrRemove(HWidx);
471
472 /* Deallocate wait queue for each core */
473 N8_DelWaitQueue(NSPinstance_p->RNHblock);
474 N8_DelWaitQueue(NSPinstance_p->CCHblock);
475 N8_DelWaitQueue(NSPinstance_p->PKHblock);
476 N8_DelWaitQueue(NSPinstance_p->AMBAblock);
477
478 return(N8_STATUS_OK);
479 }
480
481 /*****************************************************************************
482 * N8_GetConfig
483 *****************************************************************************/
484 /** @ingroup NSP2000Driver
485 * @brief Configuration manager.
486 *
487 * This routine retrieves information about the device(s) installed and running
488 * under this driver and writes it to the location requested by the caller.
489 *
490 * @param *driverInfo_p RO: Address where the caller has requested the data
491 * to be written.
492 *
493 * @par Externals:
494 *
495 * @return
496 *
497 * @par Errors:
498 * See return section for error information.
499 *****************************************************************************/
500
N8_GetConfig(NSPdriverInfo_t * driverInfo_p)501 void N8_GetConfig(NSPdriverInfo_t *driverInfo_p)
502 {
503
504 int ctr;
505
506 /* Make sure the pointer is not NULL */
507 if (driverInfo_p)
508 {
509
510 /* Collect information about this driver installation. */
511 driverInfo_p->numChips = NSPcount_g;
512 driverInfo_p->driverVersion = N8_VERSION;
513
514 /* Collect information about each memory region. */
515 driverInfo_p->eaMemoryBase = memBankCtl_gp[N8_MEMBANK_EA]->memBaseAddress;
516 driverInfo_p->eaMemorySize = memBankCtl_gp[N8_MEMBANK_EA]->allocSize;
517 driverInfo_p->pkMemoryBase = memBankCtl_gp[N8_MEMBANK_PK]->memBaseAddress;
518 driverInfo_p->pkMemorySize = memBankCtl_gp[N8_MEMBANK_PK]->allocSize;
519
520 driverInfo_p->bncAddress = bncAddr;
521 driverInfo_p->sessionID = N8_GET_SESSION_ID;
522 driverInfo_p->userPools = userPoolCount();
523
524 /* Collect information about each chip. */
525 for (ctr = 0; ctr < NSPcount_g; ctr++)
526 {
527 driverInfo_p->chipInfo[ctr].contextMemsize = NSPDeviceTable_g[ctr].contextMemSize;
528 driverInfo_p->chipInfo[ctr].SKS_size = NSPDeviceTable_g[ctr].SKS_size;
529 driverInfo_p->chipInfo[ctr].HardwareVersion = NSPDeviceTable_g[ctr].HardwareVersion;
530 driverInfo_p->chipInfo[ctr].hardwareType = NSPDeviceTable_g[ctr].hardwareType;
531 driverInfo_p->chipInfo[ctr].RevisionID = NSPDeviceTable_g[ctr].RevisionID;
532 driverInfo_p->chipInfo[ctr].RNqueueSize = NSPDeviceTable_g[ctr].RNqueue_size;
533 driverInfo_p->chipInfo[ctr].PKqueueSize = NSPDeviceTable_g[ctr].PKqueue_size;
534 driverInfo_p->chipInfo[ctr].EAqueueSize = NSPDeviceTable_g[ctr].EAqueue_size;
535 }
536
537 driverInfo_p->mode = driverMode;
538 }
539
540 return;
541 }
542
543 /*****************************************************************************
544 * N8_OpenDevice
545 *****************************************************************************/
546 /** @ingroup NSP2000Driver
547 * @brief Configuration manager.
548 *
549 * This routine mirrors the user level function that is required to open the
550 * NSP2000 device and mmap its resources.
551 *
552 * @param *driverInfo_p RO: Address where the caller has requested the data
553 * to be written.
554 *
555 * @par Externals:
556 *
557 * @return
558 *
559 * @par Errors:
560 * See return section for error information.
561 *****************************************************************************/
562
N8_OpenDevice(NSPdriverInfo_t * driverInfo_p,N8_Boolean_t allocUserPool,N8_Open_t openMode)563 N8_Status_t N8_OpenDevice(NSPdriverInfo_t *driverInfo_p,
564 N8_Boolean_t allocUserPool,
565 N8_Open_t openMode)
566 {
567 N8_GetConfig(driverInfo_p);
568 return (N8_STATUS_OK);
569 }
570
571
572 /*****************************************************************************
573 * N8_CloseDevice
574 *****************************************************************************/
575 /** @ingroup NSP2000Driver
576 * @brief Configuration manager.
577 *
578 * This routine mirrors the user level function that is required to close the
579 * NSP2000 device and deallocates its resources.
580 *
581 * @return
582 *
583 * @par Errors:
584 * See return section for error information.
585 *****************************************************************************/
586
N8_CloseDevice(void)587 void N8_CloseDevice(void)
588 {
589 return;
590 }
591
592
593 /*****************************************************************************
594 * n8_enableInterrupts
595 *****************************************************************************/
596 /** @ingroup NSP2000Driver
597 * @brief Configuration of interrupts
598 *
599 * Configures and enables interrupts all detected NSP2000's. Must be called
600 * after * the driver has registered its interrupt handler with the OS.
601 *
602 * @param
603 *
604 * @return
605 *
606 * @par Errors:
607 * See return section for error information.
608 *****************************************************************************/
609
n8_enableInterrupts(int timer_preset)610 void n8_enableInterrupts(int timer_preset)
611 {
612
613 int counter;
614 NspInstance_t *NSPinstance_p;
615 unsigned long amba_pci_control;
616 volatile NSP2000REGS_t *nsp;
617
618 for (counter = 0; counter < NSPcount_g; counter++)
619 {
620 NSPinstance_p = &NSPDeviceTable_g[counter];
621 nsp = (NSP2000REGS_t *)NSPinstance_p->NSPregs_p;
622
623 /* Set up for error interrupts */
624 amba_pci_control = AMBAIRQ_PKP | AMBAIRQ_CCH | AMBAIRQ_RNG;
625
626 /* Configure the timer interrupt on the first NSP2000. */
627 if (counter == N8_AMBA_TIMER_CHIP)
628 {
629 /* Set up the timer preset */
630 nsp->amba_pci_timer_preset = timer_preset;
631 }
632
633 /* Enable interrupt on error and PK command complete */
634 nsp->pkh_intr_enable = PK_Status_Halting_Error_Mask |
635 PK_Enable_Cmd_Complete_Enable;
636 nsp->cch_intr_enable = EA_Status_Halting_Error_Mask;
637
638 nsp->amba_pci_control = amba_pci_control;
639
640 }
641 }
642
643 /*****************************************************************************
644 * n8_disableInterrupts
645 *****************************************************************************/
646 /** @ingroup NSP2000Driver
647 * @brief Configuration of interrupts
648 *
649 * Disables interrupts on the hardware. Must be called before deallocating
650 * the resources referenced by the IRQ.
651 *
652 * @return
653 *
654 * @par Errors:
655 * See return section for error information.
656 *****************************************************************************/
657
n8_disableInterrupts(void)658 void n8_disableInterrupts(void)
659 {
660
661 unsigned long amba_pci_control;
662 volatile NSP2000REGS_t *nsp;
663 int ctr;
664
665 /* Set up for error interrupts */
666 amba_pci_control = 0;
667
668 for (ctr = 0; ctr < NSPcount_g; ctr++)
669 {
670
671 /* Disable all interrupts for each device */
672 nsp = (NSP2000REGS_t *)NSPDeviceTable_g[ctr].NSPregs_p;
673 nsp->amba_pci_control = amba_pci_control;
674 }
675
676 }
677
678 #if 0
679 /*****************************************************************************
680 * N8_GetFD
681 *****************************************************************************/
682 /** @ingroup NSP2000Driver
683 * @brief Return NULL file descriptor.
684 *
685 * Returns a NULL file descriptor for the kernel API.
686 *
687 * @return
688 *
689 * @par Errors:
690 * See return section for error information.
691 *****************************************************************************/
692
693 int N8_GetFD(void)
694 {
695 return(0);
696 }
697 #endif
698
699
700 /*****************************************************************************
701 * n8_driverInit
702 *****************************************************************************/
703 /** @ingroup NSP2000Driver
704 * @brief Allocation and initialization of drivers resources.
705 *
706 * This function should be called once at driver installation. It is
707 * responsible for the allocation and initialization of global structures
708 * used by the NSP2000 device driver.
709 *
710 * @param eaPoolSize R0: Size (in KB) of the EA memory pool.
711 * pkPoolSize R0: Size (in KB) of the PK memory pool.
712 *
713 * @par Externals:
714 *
715 * @return
716 * 0 - Success
717 *
718 * @par Errors:
719 * See return section for error information.
720 *
721 * NOTE: All resources allocated here should be removed in n8_driverRemove.
722 *****************************************************************************/
723
n8_driverInit(int eaPoolSize,int pkPoolSize)724 int n8_driverInit(int eaPoolSize, int pkPoolSize)
725 {
726
727 /* Allocate physically contiguous blocks of memory that are locked down */
728 /* This pool of memory will be accessed by the NSP2000's DMA engine. */
729
730 /* The first allocation is for the command queues */
731 if (!n8_memoryInit(N8_MEMBANK_QUEUE,
732 N8_QUEUE_POOL_SIZE * N8_ONE_KILOBYTE * NSPcount_g,
733 N8_QUEUE_GRANULARITY))
734 {
735 return -ENOMEM;
736 }
737 /* The second allocation is for the EA requests */
738 if (!n8_memoryInit(N8_MEMBANK_EA,
739 eaPoolSize * N8_ONE_KILOBYTE,
740 N8_EA_GRANULARITY))
741 {
742 n8_memoryRelease(N8_MEMBANK_QUEUE);
743 return -ENOMEM;
744 }
745
746 /* The third allocation is for the PK requests */
747 if (!n8_memoryInit(N8_MEMBANK_PK,
748 pkPoolSize * N8_ONE_KILOBYTE,
749 N8_PK_GRANULARITY))
750 {
751 n8_memoryRelease(N8_MEMBANK_EA);
752 n8_memoryRelease(N8_MEMBANK_QUEUE);
753 return -ENOMEM;
754 }
755
756 /* Create the user pool */
757 userPoolInit( DEF_USER_POOL_BANKS,
758 DEF_USER_POOL_SIZE,
759 DEF_USER_GRANULARITY);
760
761 #if 0
762 /* Initialize the process init semaphore */
763 n8_create_process_init_sem();
764 #endif
765
766 /* Initialize driver wait queues */
767 N8_InitWaitQueue(&nsp2000_wait);
768 N8_InitWaitQueue(&requestBlock);
769
770 return 0;
771 }
772
773
774 /*****************************************************************************
775 * n8_driverRemove
776 *****************************************************************************/
777 /** @ingroup NSP2000Driver
778 * @brief Deallocation and removal of drivers resources.
779 *
780 * This function should be called once at driver removal. It is
781 * responsible for the deallocation and removal of global structures
782 * used by the NSP2000 device driver.
783 *
784 * @param
785 *
786 * @par Externals:
787 *
788 * @return
789 * 0 - Success
790 *
791 * @par Errors:
792 * See return section for error information.
793 *****************************************************************************/
794
n8_driverRemove(void)795 int n8_driverRemove(void)
796 {
797
798 #if 0
799 /* Delete the process init semaphore */
800 n8_delete_process_init_sem();
801 #endif
802
803 /* Remove the user pool */
804 userPoolRelease();
805
806 /* Remove the driver memory pools */
807 DBG(("n8_driverRemove: n8_memoryRelease(PK=%d)\n", N8_MEMBANK_PK));
808 n8_memoryRelease(N8_MEMBANK_PK);
809 DBG(("n8_driverRemove: n8_memoryRelease(EA=%d)\n", N8_MEMBANK_EA));
810 n8_memoryRelease(N8_MEMBANK_EA);
811 DBG(("n8_driverRemove: n8_memoryRelease(QUEUE=%d)\n", N8_MEMBANK_QUEUE));
812 n8_memoryRelease(N8_MEMBANK_QUEUE);
813
814 /* Deallocate driver wait queues */
815 N8_DelWaitQueue(nsp2000_wait);
816 N8_DelWaitQueue(requestBlock);
817 return 0;
818 }
819
820
821
822