10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*5815Sgt145670 * Common Development and Distribution License (the "License").
6*5815Sgt145670 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*5815Sgt145670 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * Minor number allocation for various protocol modules.
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/kmem.h>
340Sstevel@tonic-gate #include <sys/mutex.h>
350Sstevel@tonic-gate #include <sys/ddi.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/mkdev.h>
380Sstevel@tonic-gate #include <sys/param.h>
390Sstevel@tonic-gate #include <inet/common.h>
400Sstevel@tonic-gate
410Sstevel@tonic-gate typedef struct inet_arena {
420Sstevel@tonic-gate vmem_t *ineta_arena; /* Minor number arena */
430Sstevel@tonic-gate minor_t ineta_maxminor; /* max minor number in the arena */
440Sstevel@tonic-gate } inet_arena_t;
450Sstevel@tonic-gate
460Sstevel@tonic-gate void *
inet_minor_create(char * name,dev_t min_dev,dev_t max_dev,int kmflags)47*5815Sgt145670 inet_minor_create(char *name, dev_t min_dev, dev_t max_dev, int kmflags)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate inet_arena_t *arena = kmem_alloc(sizeof (inet_arena_t), kmflags);
500Sstevel@tonic-gate
510Sstevel@tonic-gate if (arena != NULL) {
52*5815Sgt145670 arena->ineta_maxminor = max_dev;
530Sstevel@tonic-gate arena->ineta_arena = vmem_create(name,
540Sstevel@tonic-gate (void *)min_dev, arena->ineta_maxminor - min_dev + 1,
550Sstevel@tonic-gate 1, NULL, NULL, NULL, 1, kmflags | VMC_IDENTIFIER);
560Sstevel@tonic-gate
570Sstevel@tonic-gate if (arena->ineta_arena == NULL) {
580Sstevel@tonic-gate kmem_free(arena, sizeof (inet_arena_t));
590Sstevel@tonic-gate arena = NULL;
600Sstevel@tonic-gate }
610Sstevel@tonic-gate }
620Sstevel@tonic-gate
630Sstevel@tonic-gate return (arena);
640Sstevel@tonic-gate }
650Sstevel@tonic-gate
660Sstevel@tonic-gate void
inet_minor_destroy(void * a)670Sstevel@tonic-gate inet_minor_destroy(void *a)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate inet_arena_t *arena = (inet_arena_t *)a;
700Sstevel@tonic-gate
710Sstevel@tonic-gate if (arena != NULL) {
720Sstevel@tonic-gate vmem_destroy(arena->ineta_arena);
730Sstevel@tonic-gate kmem_free(arena, sizeof (inet_arena_t));
740Sstevel@tonic-gate }
750Sstevel@tonic-gate }
760Sstevel@tonic-gate
770Sstevel@tonic-gate dev_t
inet_minor_alloc(void * arena)78*5815Sgt145670 inet_minor_alloc(void *arena)
790Sstevel@tonic-gate {
80*5815Sgt145670 return ((dev_t)vmem_alloc(((inet_arena_t *)arena)->ineta_arena,
81*5815Sgt145670 1, VM_NOSLEEP));
820Sstevel@tonic-gate }
830Sstevel@tonic-gate
840Sstevel@tonic-gate void
inet_minor_free(void * arena,dev_t dev)85*5815Sgt145670 inet_minor_free(void *arena, dev_t dev)
860Sstevel@tonic-gate {
87*5815Sgt145670 ASSERT((dev != OPENFAIL) && (dev != 0) && (dev <= MAXMIN));
88*5815Sgt145670 vmem_free(((inet_arena_t *)arena)->ineta_arena, (void *)dev, 1);
890Sstevel@tonic-gate }
90741Smasputra
91741Smasputra /*
92741Smasputra * This function is used to free a message that has gone through
93741Smasputra * mi_copyin processing which modifies the M_IOCTL mblk's b_next
94741Smasputra * and b_prev pointers. We use this function to set b_next/b_prev
95741Smasputra * to NULL and free them.
96741Smasputra */
97741Smasputra void
inet_freemsg(mblk_t * mp)98741Smasputra inet_freemsg(mblk_t *mp)
99741Smasputra {
100741Smasputra mblk_t *bp = mp;
101741Smasputra
102741Smasputra for (; bp != NULL; bp = bp->b_cont) {
103741Smasputra bp->b_prev = NULL;
104741Smasputra bp->b_next = NULL;
105741Smasputra }
106741Smasputra freemsg(mp);
107741Smasputra }
108