xref: /titanic_53/usr/src/uts/common/os/space.c (revision 4b46d1ef625bf17cc3dd4b14b9ad807be97dc558)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*4b46d1efSkrgopi  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * The intent of this file is to contain any data that must remain
317c478bd9Sstevel@tonic-gate  * resident in the kernel.
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * space_store(), space_fetch(), and space_free() have been added to
347c478bd9Sstevel@tonic-gate  * easily store and retrieve kernel resident data.
357c478bd9Sstevel@tonic-gate  * These functions are recommended rather than adding new variables to
367c478bd9Sstevel@tonic-gate  * this file.
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * Note that it's possible for name collisions to occur.  In order to
397c478bd9Sstevel@tonic-gate  * prevent collisions, it's recommended that the convention in
407c478bd9Sstevel@tonic-gate  * PSARC/1997/389 be used.  If a collision occurs, then space_store will
417c478bd9Sstevel@tonic-gate  * fail.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #include <sys/types.h>
457c478bd9Sstevel@tonic-gate #include <sys/param.h>
467c478bd9Sstevel@tonic-gate #include <sys/var.h>
477c478bd9Sstevel@tonic-gate #include <sys/proc.h>
487c478bd9Sstevel@tonic-gate #include <sys/signal.h>
497c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
507c478bd9Sstevel@tonic-gate #include <sys/buf.h>
517c478bd9Sstevel@tonic-gate #include <sys/cred.h>
527c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
537c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
547c478bd9Sstevel@tonic-gate #include <sys/sysinfo.h>
557c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
567c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
577c478bd9Sstevel@tonic-gate #include <sys/modhash.h>
587c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #include <sys/strredir.h>
617c478bd9Sstevel@tonic-gate #include <sys/kbio.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate struct	buf	bfreelist;	/* Head of the free list of buffers */
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate sysinfo_t	sysinfo;
667c478bd9Sstevel@tonic-gate vminfo_t	vminfo;		/* VM stats protected by sysinfolock mutex */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #ifdef	lint
697c478bd9Sstevel@tonic-gate int	__lintzero;		/* Alway zero for shutting up lint */
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * The following describe the physical memory configuration.
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  *	physmem	 -  The amount of physical memory configured
767c478bd9Sstevel@tonic-gate  *		    in pages.  ptob(physmem) is the amount
777c478bd9Sstevel@tonic-gate  *		    of physical memory in bytes.  Defined in
787c478bd9Sstevel@tonic-gate  *		    .../os/startup.c.
797c478bd9Sstevel@tonic-gate  *
807c478bd9Sstevel@tonic-gate  *	physmax  -  The highest numbered physical page in memory.
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  *	maxmem	 -  Maximum available memory, in pages.  Defined
837c478bd9Sstevel@tonic-gate  *		    in main.c.
847c478bd9Sstevel@tonic-gate  *
857c478bd9Sstevel@tonic-gate  *	physinstalled
867c478bd9Sstevel@tonic-gate  *		 -  Pages of physical memory installed;
877c478bd9Sstevel@tonic-gate  *		    includes use by PROM/boot not counted in
887c478bd9Sstevel@tonic-gate  *		    physmem.
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate pfn_t	physmax;
927c478bd9Sstevel@tonic-gate pgcnt_t	physinstalled;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate struct var v;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #include <sys/systm.h>
977c478bd9Sstevel@tonic-gate #include <sys/conf.h>
987c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
997c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
1007c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Data from swapgeneric.c that must be resident.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate struct vnode *rootvp;		/* vnode of the root device */
1067c478bd9Sstevel@tonic-gate dev_t rootdev;			/* dev_t of the root device */
1077c478bd9Sstevel@tonic-gate int root_is_svm;		/* root is a mirrored device flag */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate int netboot;
1107c478bd9Sstevel@tonic-gate int obpdebug;
1117c478bd9Sstevel@tonic-gate char *dhcack;	/* Used to cache ascii form of DHCPACK handed up by boot */
1127c478bd9Sstevel@tonic-gate char *netdev_path;	/* Used to cache the netdev_path handed up by boot */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * Data from arp.c that must be resident.
1167c478bd9Sstevel@tonic-gate  */
1177c478bd9Sstevel@tonic-gate #include <sys/socket.h>
1187c478bd9Sstevel@tonic-gate #include <sys/errno.h>
1197c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
1207c478bd9Sstevel@tonic-gate #include <sys/stream.h>
1217c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
1227c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
1237c478bd9Sstevel@tonic-gate #include <net/if.h>
1247c478bd9Sstevel@tonic-gate #include <net/if_arp.h>
1257c478bd9Sstevel@tonic-gate #include <netinet/in.h>
1267c478bd9Sstevel@tonic-gate #include <netinet/in_var.h>
1277c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate ether_addr_t etherbroadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * Data from timod that must be resident
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  * state transition table for TI interface
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	nr	127		/* not reachable */
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate char ti_statetbl[TE_NOEVENTS][TS_NOSTATES] = {
1437c478bd9Sstevel@tonic-gate 				/* STATES */
1447c478bd9Sstevel@tonic-gate 	/* 0  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16 */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	{ 1, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1477c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  2, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1487c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  4, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1497c478bd9Sstevel@tonic-gate 	{nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1507c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1517c478bd9Sstevel@tonic-gate 	{nr,  0,  3, nr,  3,  3, nr, nr,  7, nr, nr, nr,  6,  7,  9, 10, 11},
1527c478bd9Sstevel@tonic-gate 	{nr, nr,  0, nr, nr,  6, nr, nr, nr, nr, nr, nr,  3, nr,  3,  3,  3},
1537c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, nr, nr, nr,  3, nr, nr, nr},
1547c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  3, nr, nr, nr, nr,  3, nr, nr, nr},
1557c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  7, nr, nr, nr, nr,  7, nr, nr, nr},
1567c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  5, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1577c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  8, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1587c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, 12, 13, nr, 14, 15, 16, nr, nr, nr, nr, nr},
1597c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, 11, nr, nr, nr, nr, nr},
1607c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, 11, nr, nr, nr, nr, nr},
1617c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr, 10, nr,  3, nr, nr, nr, nr, nr},
1627c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  7, nr, nr, nr,  7, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1637c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr,  9, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1647c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, 10, nr, nr, nr, nr, nr, nr},
1657c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, 10, nr, nr, nr, nr, nr, nr},
1667c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr, 11,  3, nr, nr, nr, nr, nr, nr},
1677c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr,  3, nr, nr,  3,  3,  3, nr, nr, nr, nr, nr},
1687c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1697c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  7, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1707c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  9, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1717c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1727c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1737c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1747c478bd9Sstevel@tonic-gate };
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #include <sys/sad.h>
1787c478bd9Sstevel@tonic-gate #include <sys/tty.h>
1797c478bd9Sstevel@tonic-gate #include <sys/ptyvar.h>
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate static void store_fetch_initspace();
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * Allocate tunable structures at runtime.
1857c478bd9Sstevel@tonic-gate  */
1867c478bd9Sstevel@tonic-gate void
1877c478bd9Sstevel@tonic-gate space_init(void)
1887c478bd9Sstevel@tonic-gate {
1897c478bd9Sstevel@tonic-gate 	sad_initspace();
1907c478bd9Sstevel@tonic-gate 	pty_initspace();
1917c478bd9Sstevel@tonic-gate 	store_fetch_initspace();
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate int ts_dispatch_extended = -1; /* set in ts_getdptbl or set_platform_default */
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * Previously defined in consmsconf.c ...
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate dev_t kbddev = NODEV;
2007c478bd9Sstevel@tonic-gate dev_t mousedev = NODEV;
2017c478bd9Sstevel@tonic-gate dev_t stdindev = NODEV;
2027c478bd9Sstevel@tonic-gate struct vnode *wsconsvp;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate dev_t fbdev = NODEV;
2057c478bd9Sstevel@tonic-gate struct vnode *fbvp;
2067c478bd9Sstevel@tonic-gate dev_info_t *fbdip;
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * moved from cons.c because they must be resident in the kernel.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate vnode_t	*rconsvp;
2127c478bd9Sstevel@tonic-gate dev_t	rconsdev;
2137c478bd9Sstevel@tonic-gate dev_t	uconsdev = NODEV;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate  * This flag, when set marks rconsvp in a transition state.
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate int	cn_conf;
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate /*
2227c478bd9Sstevel@tonic-gate  * Moved from sad_conf.c because of the usual in loadable modules
2237c478bd9Sstevel@tonic-gate  */
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #ifndef NSTRPHASH
2267c478bd9Sstevel@tonic-gate #define	NSTRPHASH	128
2277c478bd9Sstevel@tonic-gate #endif
2287c478bd9Sstevel@tonic-gate struct autopush **strpcache;
2297c478bd9Sstevel@tonic-gate int strpmask = NSTRPHASH - 1;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * Moved here from wscons.c
2337c478bd9Sstevel@tonic-gate  * Package the redirection-related routines into an ops vector of the form
2347c478bd9Sstevel@tonic-gate  * that the redirecting driver expects.
2357c478bd9Sstevel@tonic-gate  */
2367c478bd9Sstevel@tonic-gate extern int wcvnget();
2377c478bd9Sstevel@tonic-gate extern void wcvnrele();
2387c478bd9Sstevel@tonic-gate srvnops_t	wscons_srvnops = {
2397c478bd9Sstevel@tonic-gate 	wcvnget,
2407c478bd9Sstevel@tonic-gate 	wcvnrele
2417c478bd9Sstevel@tonic-gate };
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * consconfig() in autoconf.c sets this; it's the vnode of the distinguished
2457c478bd9Sstevel@tonic-gate  * keyboard/frame buffer combination, aka the workstation console.
2467c478bd9Sstevel@tonic-gate  */
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate vnode_t *rwsconsvp;
2497c478bd9Sstevel@tonic-gate dev_t	rwsconsdev;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * Platform console abort policy.
2537c478bd9Sstevel@tonic-gate  * Platforms may override the default software policy, if such hardware
2547c478bd9Sstevel@tonic-gate  * (e.g. keyswitches with a secure position) exists.
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate int abort_enable = KIOCABORTENABLE;
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate /* from iwscons.c */
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate kthread_id_t	iwscn_thread;	/* thread that is allowed to push redirm */
2617c478bd9Sstevel@tonic-gate wcm_data_t	*iwscn_wcm_data; /* allocated data for redirm */
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate /* from cpc.c */
2647c478bd9Sstevel@tonic-gate uint_t kcpc_key;	/* TSD key for CPU performance counter context */
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * storing and retrieving data by string key
2687c478bd9Sstevel@tonic-gate  *
2697c478bd9Sstevel@tonic-gate  * this mechanism allows a consumer to store and retrieve by name a pointer
2707c478bd9Sstevel@tonic-gate  * to some space maintained by the consumer.
2717c478bd9Sstevel@tonic-gate  * For example, a driver or module may want to have persistent data
2727c478bd9Sstevel@tonic-gate  * over unloading/loading cycles. The pointer is typically to some
2737c478bd9Sstevel@tonic-gate  * kmem_alloced space and it should not be pointing to data that will
2747c478bd9Sstevel@tonic-gate  * be destroyed when the module is unloaded.
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate static mod_hash_t *space_hash;
2777c478bd9Sstevel@tonic-gate static char *space_hash_name = "space_hash";
2787c478bd9Sstevel@tonic-gate static size_t	space_hash_nchains = 8;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate static void
2817c478bd9Sstevel@tonic-gate store_fetch_initspace()
2827c478bd9Sstevel@tonic-gate {
2837c478bd9Sstevel@tonic-gate 	space_hash = mod_hash_create_strhash(space_hash_name,
2847c478bd9Sstevel@tonic-gate 		space_hash_nchains, mod_hash_null_valdtor);
2857c478bd9Sstevel@tonic-gate 	ASSERT(space_hash);
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate int
2897c478bd9Sstevel@tonic-gate space_store(char *key, uintptr_t ptr)
2907c478bd9Sstevel@tonic-gate {
2917c478bd9Sstevel@tonic-gate 	char *s;
2927c478bd9Sstevel@tonic-gate 	int rval;
2937c478bd9Sstevel@tonic-gate 	size_t l;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	/* some sanity checks first */
2967c478bd9Sstevel@tonic-gate 	if (key == NULL) {
2977c478bd9Sstevel@tonic-gate 		return (-1);
2987c478bd9Sstevel@tonic-gate 	}
2997c478bd9Sstevel@tonic-gate 	l = (size_t)strlen(key);
3007c478bd9Sstevel@tonic-gate 	if (l == 0) {
3017c478bd9Sstevel@tonic-gate 		return (-1);
3027c478bd9Sstevel@tonic-gate 	}
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	/* increment for null terminator */
3057c478bd9Sstevel@tonic-gate 	l++;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	/* alloc space for the string, mod_hash_insert will deallocate */
3087c478bd9Sstevel@tonic-gate 	s = kmem_alloc(l, KM_SLEEP);
3097c478bd9Sstevel@tonic-gate 	bcopy(key, s, l);
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	rval = mod_hash_insert(space_hash,
3127c478bd9Sstevel@tonic-gate 		(mod_hash_key_t)s, (mod_hash_val_t)ptr);
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	switch (rval) {
3157c478bd9Sstevel@tonic-gate 	case 0:
3167c478bd9Sstevel@tonic-gate 		break;
3177c478bd9Sstevel@tonic-gate #ifdef DEBUG
3187c478bd9Sstevel@tonic-gate 	case MH_ERR_DUPLICATE:
3197c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: duplicate key %s", key);
3207c478bd9Sstevel@tonic-gate 		rval = -1;
3217c478bd9Sstevel@tonic-gate 		break;
3227c478bd9Sstevel@tonic-gate 	case MH_ERR_NOMEM:
3237c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: no mem for key %s", key);
3247c478bd9Sstevel@tonic-gate 		rval = -1;
3257c478bd9Sstevel@tonic-gate 		break;
3267c478bd9Sstevel@tonic-gate 	default:
3277c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: unspecified error for key %s",
3287c478bd9Sstevel@tonic-gate 		    key);
3297c478bd9Sstevel@tonic-gate 		rval = -1;
3307c478bd9Sstevel@tonic-gate 		break;
3317c478bd9Sstevel@tonic-gate #else
3327c478bd9Sstevel@tonic-gate 	default:
3337c478bd9Sstevel@tonic-gate 		rval = -1;
3347c478bd9Sstevel@tonic-gate 		break;
3357c478bd9Sstevel@tonic-gate #endif
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	return (rval);
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate uintptr_t
3427c478bd9Sstevel@tonic-gate space_fetch(char *key)
3437c478bd9Sstevel@tonic-gate {
3447c478bd9Sstevel@tonic-gate 	uintptr_t ptr = 0;
3457c478bd9Sstevel@tonic-gate 	mod_hash_val_t val;
3467c478bd9Sstevel@tonic-gate 	int rval;
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	if (key) {
3497c478bd9Sstevel@tonic-gate 		rval = mod_hash_find(space_hash, (mod_hash_key_t)key, &val);
3507c478bd9Sstevel@tonic-gate 		if (rval == 0) {
3517c478bd9Sstevel@tonic-gate 			ptr = (uintptr_t)val;
3527c478bd9Sstevel@tonic-gate 		}
3537c478bd9Sstevel@tonic-gate 	}
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	return (ptr);
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate void
3597c478bd9Sstevel@tonic-gate space_free(char *key)
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate 	if (key) {
3627c478bd9Sstevel@tonic-gate 		(void) mod_hash_destroy(space_hash, (mod_hash_key_t)key);
3637c478bd9Sstevel@tonic-gate 	}
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate /*
3677c478bd9Sstevel@tonic-gate  * Support for CRC32.  At present all calculations are done in simple
3687c478bd9Sstevel@tonic-gate  * macros, so all we need is somewhere to declare the global lookup table.
3697c478bd9Sstevel@tonic-gate  */
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate #include <sys/crc32.h>
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate const uint32_t crc32_table[256] = { CRC32_TABLE };
374*4b46d1efSkrgopi 
375*4b46d1efSkrgopi 
376*4b46d1efSkrgopi /*
377*4b46d1efSkrgopi  * We need to fanout load from NIC which can overwhelm a single
378*4b46d1efSkrgopi  * CPU. A 10Gb NIC interrupting a single CPU is a good example.
379*4b46d1efSkrgopi  * Instead of fanning out to random CPUs, it a big performance
380*4b46d1efSkrgopi  * win if you can fanout to the threads on the same core (niagara)
381*4b46d1efSkrgopi  * that is taking interrupts.
382*4b46d1efSkrgopi  *
383*4b46d1efSkrgopi  * We need a better mechanism to figure out the other threads on
384*4b46d1efSkrgopi  * the same core or cores on the same chip which share caches etc.
385*4b46d1efSkrgopi  * but for time being, this will suffice.
386*4b46d1efSkrgopi  */
387*4b46d1efSkrgopi #define	NUMBER_OF_THREADS_PER_CPU	4
388*4b46d1efSkrgopi uint_t		ip_threads_per_cpu = NUMBER_OF_THREADS_PER_CPU;
389*4b46d1efSkrgopi 
390*4b46d1efSkrgopi /* Global flag to enable/disable soft ring facility */
391*4b46d1efSkrgopi boolean_t	ip_squeue_soft_ring = B_FALSE;
392