xref: /titanic_44/usr/src/uts/common/os/space.c (revision fea9cb91bd8e12d84069b4dab1268363668b4bff)
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
5*fea9cb91Slq150181  * Common Development and Distribution License (the "License").
6*fea9cb91Slq150181  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*fea9cb91Slq150181 
227c478bd9Sstevel@tonic-gate /*
23*fea9cb91Slq150181  * Copyright 2006 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>
62*fea9cb91Slq150181 #include <sys/consdev.h>
63*fea9cb91Slq150181 #include <sys/wscons.h>
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate struct	buf	bfreelist;	/* Head of the free list of buffers */
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate sysinfo_t	sysinfo;
687c478bd9Sstevel@tonic-gate vminfo_t	vminfo;		/* VM stats protected by sysinfolock mutex */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifdef	lint
717c478bd9Sstevel@tonic-gate int	__lintzero;		/* Alway zero for shutting up lint */
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * The following describe the physical memory configuration.
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  *	physmem	 -  The amount of physical memory configured
787c478bd9Sstevel@tonic-gate  *		    in pages.  ptob(physmem) is the amount
797c478bd9Sstevel@tonic-gate  *		    of physical memory in bytes.  Defined in
807c478bd9Sstevel@tonic-gate  *		    .../os/startup.c.
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  *	physmax  -  The highest numbered physical page in memory.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  *	maxmem	 -  Maximum available memory, in pages.  Defined
857c478bd9Sstevel@tonic-gate  *		    in main.c.
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  *	physinstalled
887c478bd9Sstevel@tonic-gate  *		 -  Pages of physical memory installed;
897c478bd9Sstevel@tonic-gate  *		    includes use by PROM/boot not counted in
907c478bd9Sstevel@tonic-gate  *		    physmem.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate pfn_t	physmax;
947c478bd9Sstevel@tonic-gate pgcnt_t	physinstalled;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate struct var v;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #include <sys/systm.h>
997c478bd9Sstevel@tonic-gate #include <sys/conf.h>
1007c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
1017c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
1027c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * Data from swapgeneric.c that must be resident.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate struct vnode *rootvp;		/* vnode of the root device */
1087c478bd9Sstevel@tonic-gate dev_t rootdev;			/* dev_t of the root device */
1097c478bd9Sstevel@tonic-gate int root_is_svm;		/* root is a mirrored device flag */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate int netboot;
1127c478bd9Sstevel@tonic-gate int obpdebug;
1137c478bd9Sstevel@tonic-gate char *dhcack;	/* Used to cache ascii form of DHCPACK handed up by boot */
1147c478bd9Sstevel@tonic-gate char *netdev_path;	/* Used to cache the netdev_path handed up by boot */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Data from arp.c that must be resident.
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate #include <sys/socket.h>
1207c478bd9Sstevel@tonic-gate #include <sys/errno.h>
1217c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
1227c478bd9Sstevel@tonic-gate #include <sys/stream.h>
1237c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
1247c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
1257c478bd9Sstevel@tonic-gate #include <net/if.h>
1267c478bd9Sstevel@tonic-gate #include <net/if_arp.h>
1277c478bd9Sstevel@tonic-gate #include <netinet/in.h>
1287c478bd9Sstevel@tonic-gate #include <netinet/in_var.h>
1297c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate ether_addr_t etherbroadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Data from timod that must be resident
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * state transition table for TI interface
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	nr	127		/* not reachable */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate char ti_statetbl[TE_NOEVENTS][TS_NOSTATES] = {
1457c478bd9Sstevel@tonic-gate 				/* STATES */
1467c478bd9Sstevel@tonic-gate 	/* 0  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16 */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	{ 1, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1497c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  2, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1507c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  4, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1517c478bd9Sstevel@tonic-gate 	{nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1527c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1537c478bd9Sstevel@tonic-gate 	{nr,  0,  3, nr,  3,  3, nr, nr,  7, nr, nr, nr,  6,  7,  9, 10, 11},
1547c478bd9Sstevel@tonic-gate 	{nr, nr,  0, nr, nr,  6, nr, nr, nr, nr, nr, nr,  3, nr,  3,  3,  3},
1557c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, nr, nr, nr,  3, nr, nr, nr},
1567c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  3, nr, nr, nr, nr,  3, nr, nr, nr},
1577c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  7, nr, nr, nr, nr,  7, nr, nr, nr},
1587c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  5, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1597c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  8, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1607c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, 12, 13, nr, 14, 15, 16, nr, nr, nr, nr, nr},
1617c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, 11, nr, nr, nr, nr, nr},
1627c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, 11, nr, nr, nr, nr, nr},
1637c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr, 10, nr,  3, nr, nr, nr, nr, nr},
1647c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  7, nr, nr, nr,  7, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1657c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr,  9, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1667c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, 10, nr, nr, nr, nr, nr, nr},
1677c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, 10, nr, nr, nr, nr, nr, nr},
1687c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr, 11,  3, nr, nr, nr, nr, nr, nr},
1697c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr,  3, nr, nr,  3,  3,  3, nr, nr, nr, nr, nr},
1707c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1717c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  7, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1727c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  9, 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 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1757c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
1767c478bd9Sstevel@tonic-gate };
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #include <sys/sad.h>
1807c478bd9Sstevel@tonic-gate #include <sys/tty.h>
1817c478bd9Sstevel@tonic-gate #include <sys/ptyvar.h>
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate static void store_fetch_initspace();
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * Allocate tunable structures at runtime.
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate void
1897c478bd9Sstevel@tonic-gate space_init(void)
1907c478bd9Sstevel@tonic-gate {
1917c478bd9Sstevel@tonic-gate 	sad_initspace();
1927c478bd9Sstevel@tonic-gate 	pty_initspace();
1937c478bd9Sstevel@tonic-gate 	store_fetch_initspace();
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate int ts_dispatch_extended = -1; /* set in ts_getdptbl or set_platform_default */
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /*
1997c478bd9Sstevel@tonic-gate  * Previously defined in consmsconf.c ...
2007c478bd9Sstevel@tonic-gate  */
2017c478bd9Sstevel@tonic-gate dev_t kbddev = NODEV;
2027c478bd9Sstevel@tonic-gate dev_t mousedev = NODEV;
2037c478bd9Sstevel@tonic-gate dev_t stdindev = NODEV;
2047c478bd9Sstevel@tonic-gate struct vnode *wsconsvp;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate dev_t fbdev = NODEV;
2077c478bd9Sstevel@tonic-gate struct vnode *fbvp;
2087c478bd9Sstevel@tonic-gate dev_info_t *fbdip;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * moved from cons.c because they must be resident in the kernel.
2127c478bd9Sstevel@tonic-gate  */
2137c478bd9Sstevel@tonic-gate vnode_t	*rconsvp;
2147c478bd9Sstevel@tonic-gate dev_t	rconsdev;
2157c478bd9Sstevel@tonic-gate dev_t	uconsdev = NODEV;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * This flag, when set marks rconsvp in a transition state.
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate int	cn_conf;
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate /*
2247c478bd9Sstevel@tonic-gate  * Moved from sad_conf.c because of the usual in loadable modules
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #ifndef NSTRPHASH
2287c478bd9Sstevel@tonic-gate #define	NSTRPHASH	128
2297c478bd9Sstevel@tonic-gate #endif
2307c478bd9Sstevel@tonic-gate struct autopush **strpcache;
2317c478bd9Sstevel@tonic-gate int strpmask = NSTRPHASH - 1;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate /*
234*fea9cb91Slq150181  * Flag whether console fb output is using PROM/PROM emulation
235*fea9cb91Slq150181  * terminal emulator, or is using the kernel terminal emulator.
236*fea9cb91Slq150181  */
237*fea9cb91Slq150181 int	consmode = CONS_FW;
238*fea9cb91Slq150181 
239*fea9cb91Slq150181 /*
240*fea9cb91Slq150181  * The following allows systems to disable use of the kernel
241*fea9cb91Slq150181  * terminal emulator (retreat to PROM terminal emulator if there
242*fea9cb91Slq150181  * is PROM).
243*fea9cb91Slq150181  */
244*fea9cb91Slq150181 int	cons_tem_disable;
245*fea9cb91Slq150181 
246*fea9cb91Slq150181 /*
2477c478bd9Sstevel@tonic-gate  * Moved here from wscons.c
2487c478bd9Sstevel@tonic-gate  * Package the redirection-related routines into an ops vector of the form
2497c478bd9Sstevel@tonic-gate  * that the redirecting driver expects.
2507c478bd9Sstevel@tonic-gate  */
2517c478bd9Sstevel@tonic-gate srvnops_t wscons_srvnops = {
2527c478bd9Sstevel@tonic-gate 	wcvnget,
2537c478bd9Sstevel@tonic-gate 	wcvnrele
2547c478bd9Sstevel@tonic-gate };
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate /*
2577c478bd9Sstevel@tonic-gate  * consconfig() in autoconf.c sets this; it's the vnode of the distinguished
2587c478bd9Sstevel@tonic-gate  * keyboard/frame buffer combination, aka the workstation console.
2597c478bd9Sstevel@tonic-gate  */
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate vnode_t *rwsconsvp;
2627c478bd9Sstevel@tonic-gate dev_t	rwsconsdev;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * Platform console abort policy.
2667c478bd9Sstevel@tonic-gate  * Platforms may override the default software policy, if such hardware
2677c478bd9Sstevel@tonic-gate  * (e.g. keyswitches with a secure position) exists.
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate int abort_enable = KIOCABORTENABLE;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate /* from iwscons.c */
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate kthread_id_t	iwscn_thread;	/* thread that is allowed to push redirm */
2747c478bd9Sstevel@tonic-gate wcm_data_t	*iwscn_wcm_data; /* allocated data for redirm */
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate /* from cpc.c */
2777c478bd9Sstevel@tonic-gate uint_t kcpc_key;	/* TSD key for CPU performance counter context */
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate  * storing and retrieving data by string key
2817c478bd9Sstevel@tonic-gate  *
2827c478bd9Sstevel@tonic-gate  * this mechanism allows a consumer to store and retrieve by name a pointer
2837c478bd9Sstevel@tonic-gate  * to some space maintained by the consumer.
2847c478bd9Sstevel@tonic-gate  * For example, a driver or module may want to have persistent data
2857c478bd9Sstevel@tonic-gate  * over unloading/loading cycles. The pointer is typically to some
2867c478bd9Sstevel@tonic-gate  * kmem_alloced space and it should not be pointing to data that will
2877c478bd9Sstevel@tonic-gate  * be destroyed when the module is unloaded.
2887c478bd9Sstevel@tonic-gate  */
2897c478bd9Sstevel@tonic-gate static mod_hash_t *space_hash;
2907c478bd9Sstevel@tonic-gate static char *space_hash_name = "space_hash";
2917c478bd9Sstevel@tonic-gate static size_t	space_hash_nchains = 8;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate static void
2947c478bd9Sstevel@tonic-gate store_fetch_initspace()
2957c478bd9Sstevel@tonic-gate {
2967c478bd9Sstevel@tonic-gate 	space_hash = mod_hash_create_strhash(space_hash_name,
2977c478bd9Sstevel@tonic-gate 		space_hash_nchains, mod_hash_null_valdtor);
2987c478bd9Sstevel@tonic-gate 	ASSERT(space_hash);
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate int
3027c478bd9Sstevel@tonic-gate space_store(char *key, uintptr_t ptr)
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate 	char *s;
3057c478bd9Sstevel@tonic-gate 	int rval;
3067c478bd9Sstevel@tonic-gate 	size_t l;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	/* some sanity checks first */
3097c478bd9Sstevel@tonic-gate 	if (key == NULL) {
3107c478bd9Sstevel@tonic-gate 		return (-1);
3117c478bd9Sstevel@tonic-gate 	}
3127c478bd9Sstevel@tonic-gate 	l = (size_t)strlen(key);
3137c478bd9Sstevel@tonic-gate 	if (l == 0) {
3147c478bd9Sstevel@tonic-gate 		return (-1);
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	/* increment for null terminator */
3187c478bd9Sstevel@tonic-gate 	l++;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	/* alloc space for the string, mod_hash_insert will deallocate */
3217c478bd9Sstevel@tonic-gate 	s = kmem_alloc(l, KM_SLEEP);
3227c478bd9Sstevel@tonic-gate 	bcopy(key, s, l);
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	rval = mod_hash_insert(space_hash,
3257c478bd9Sstevel@tonic-gate 		(mod_hash_key_t)s, (mod_hash_val_t)ptr);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	switch (rval) {
3287c478bd9Sstevel@tonic-gate 	case 0:
3297c478bd9Sstevel@tonic-gate 		break;
3307c478bd9Sstevel@tonic-gate #ifdef DEBUG
3317c478bd9Sstevel@tonic-gate 	case MH_ERR_DUPLICATE:
3327c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: duplicate key %s", key);
3337c478bd9Sstevel@tonic-gate 		rval = -1;
3347c478bd9Sstevel@tonic-gate 		break;
3357c478bd9Sstevel@tonic-gate 	case MH_ERR_NOMEM:
3367c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: no mem for key %s", key);
3377c478bd9Sstevel@tonic-gate 		rval = -1;
3387c478bd9Sstevel@tonic-gate 		break;
3397c478bd9Sstevel@tonic-gate 	default:
3407c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: unspecified error for key %s",
3417c478bd9Sstevel@tonic-gate 		    key);
3427c478bd9Sstevel@tonic-gate 		rval = -1;
3437c478bd9Sstevel@tonic-gate 		break;
3447c478bd9Sstevel@tonic-gate #else
3457c478bd9Sstevel@tonic-gate 	default:
3467c478bd9Sstevel@tonic-gate 		rval = -1;
3477c478bd9Sstevel@tonic-gate 		break;
3487c478bd9Sstevel@tonic-gate #endif
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	return (rval);
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate uintptr_t
3557c478bd9Sstevel@tonic-gate space_fetch(char *key)
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate 	uintptr_t ptr = 0;
3587c478bd9Sstevel@tonic-gate 	mod_hash_val_t val;
3597c478bd9Sstevel@tonic-gate 	int rval;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 	if (key) {
3627c478bd9Sstevel@tonic-gate 		rval = mod_hash_find(space_hash, (mod_hash_key_t)key, &val);
3637c478bd9Sstevel@tonic-gate 		if (rval == 0) {
3647c478bd9Sstevel@tonic-gate 			ptr = (uintptr_t)val;
3657c478bd9Sstevel@tonic-gate 		}
3667c478bd9Sstevel@tonic-gate 	}
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	return (ptr);
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate void
3727c478bd9Sstevel@tonic-gate space_free(char *key)
3737c478bd9Sstevel@tonic-gate {
3747c478bd9Sstevel@tonic-gate 	if (key) {
3757c478bd9Sstevel@tonic-gate 		(void) mod_hash_destroy(space_hash, (mod_hash_key_t)key);
3767c478bd9Sstevel@tonic-gate 	}
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate /*
3807c478bd9Sstevel@tonic-gate  * Support for CRC32.  At present all calculations are done in simple
3817c478bd9Sstevel@tonic-gate  * macros, so all we need is somewhere to declare the global lookup table.
3827c478bd9Sstevel@tonic-gate  */
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate #include <sys/crc32.h>
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate const uint32_t crc32_table[256] = { CRC32_TABLE };
3874b46d1efSkrgopi 
3884b46d1efSkrgopi 
3894b46d1efSkrgopi /*
3904b46d1efSkrgopi  * We need to fanout load from NIC which can overwhelm a single
3914b46d1efSkrgopi  * CPU. A 10Gb NIC interrupting a single CPU is a good example.
3924b46d1efSkrgopi  * Instead of fanning out to random CPUs, it a big performance
3934b46d1efSkrgopi  * win if you can fanout to the threads on the same core (niagara)
3944b46d1efSkrgopi  * that is taking interrupts.
3954b46d1efSkrgopi  *
3964b46d1efSkrgopi  * We need a better mechanism to figure out the other threads on
3974b46d1efSkrgopi  * the same core or cores on the same chip which share caches etc.
3984b46d1efSkrgopi  * but for time being, this will suffice.
3994b46d1efSkrgopi  */
4004b46d1efSkrgopi #define	NUMBER_OF_THREADS_PER_CPU	4
4014b46d1efSkrgopi uint_t		ip_threads_per_cpu = NUMBER_OF_THREADS_PER_CPU;
4024b46d1efSkrgopi 
4034b46d1efSkrgopi /* Global flag to enable/disable soft ring facility */
4044b46d1efSkrgopi boolean_t	ip_squeue_soft_ring = B_FALSE;
405