4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * Kernel TLI-like function to allocate memory for the various TLI
46 * Returns 0 on success or a positive error value. On success, ptr is
47 * set the structure required.
50 #include <sys/param.h>
51 #include <sys/types.h>
53 #include <sys/stream.h>
54 #include <sys/ioctl.h>
56 #include <sys/stropts.h>
57 #include <sys/tihdr.h>
58 #include <sys/timod.h>
59 #include <sys/tiuser.h>
60 #include <sys/errno.h>
61 #include <sys/signal.h>
62 #include <sys/t_kuser.h>
64 #include <sys/sysmacros.h>
66 static void _alloc_buf(struct netbuf
*, t_scalar_t
);
69 t_kalloc(TIUSER
*tiptr
, int struct_type
, int fields
, char **ptr
)
76 struct t_optmgmt
*opt
;
77 struct t_kunitdata
*udata
;
78 struct t_uderr
*uderr
;
87 * allocate appropriate structure and the specified
88 * fields within each structure. Initialize the
89 * 'buf' and 'maxlen' fields of each.
91 switch (struct_type
) {
93 p
.bind
= kmem_zalloc(sizeof (struct t_bind
), KM_SLEEP
);
95 _alloc_buf(&p
.bind
->addr
, tiptr
->tp_info
.addr
);
96 *ptr
= ((char *)p
.bind
);
100 p
.call
= kmem_zalloc(sizeof (struct t_call
), KM_SLEEP
);
102 _alloc_buf(&p
.call
->addr
, tiptr
->tp_info
.addr
);
104 _alloc_buf(&p
.call
->opt
, tiptr
->tp_info
.options
);
105 if (fields
& T_UDATA
) {
106 dsize
= MAX(tiptr
->tp_info
.connect
,
107 tiptr
->tp_info
.discon
);
108 _alloc_buf(&p
.call
->opt
, dsize
);
110 *ptr
= ((char *)p
.call
);
114 p
.opt
= kmem_zalloc(sizeof (struct t_optmgmt
), KM_SLEEP
);
116 _alloc_buf(&p
.opt
->opt
, tiptr
->tp_info
.options
);
117 *ptr
= ((char *)p
.opt
);
121 p
.dis
= kmem_zalloc(sizeof (struct t_discon
), KM_SLEEP
);
122 if (fields
& T_UDATA
)
123 _alloc_buf(&p
.dis
->udata
, tiptr
->tp_info
.discon
);
124 *ptr
= ((char *)p
.dis
);
128 p
.udata
= kmem_zalloc(sizeof (struct t_kunitdata
), KM_SLEEP
);
130 _alloc_buf(&p
.udata
->addr
, tiptr
->tp_info
.addr
);
132 p
.udata
->addr
.maxlen
= p
.udata
->addr
.len
= 0;
135 _alloc_buf(&p
.udata
->opt
, tiptr
->tp_info
.options
);
137 p
.udata
->opt
.maxlen
= p
.udata
->opt
.len
= 0;
139 if (fields
& T_UDATA
) {
140 p
.udata
->udata
.udata_mp
= NULL
;
141 p
.udata
->udata
.buf
= NULL
;
142 p
.udata
->udata
.maxlen
= tiptr
->tp_info
.tsdu
;
143 p
.udata
->udata
.len
= 0;
145 p
.udata
->udata
.maxlen
= p
.udata
->udata
.len
= 0;
147 *ptr
= (char *)p
.udata
;
151 p
.uderr
= kmem_zalloc(sizeof (struct t_uderr
), KM_SLEEP
);
153 _alloc_buf(&p
.uderr
->addr
, tiptr
->tp_info
.addr
);
155 _alloc_buf(&p
.uderr
->opt
, tiptr
->tp_info
.options
);
156 *ptr
= (char *)p
.uderr
;
160 p
.info
= kmem_zalloc(sizeof (struct t_info
), KM_SLEEP
);
161 *ptr
= (char *)p
.info
;
171 _alloc_buf(struct netbuf
*buf
, t_scalar_t n
)
175 buf
->buf
= kmem_zalloc(1024, KM_SLEEP
);
188 buf
->buf
= kmem_zalloc(n
, KM_SLEEP
);