xref: /titanic_50/usr/src/uts/common/inet/mi.h (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /* Copyright (c) 1990 Mentat Inc. */
27 
28 #ifndef	_INET_MI_H
29 #define	_INET_MI_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #ifdef _KERNEL
38 
39 #include <sys/types.h>
40 #include <sys/vmem.h>
41 #include <sys/varargs.h>
42 
43 #define	MI_MIN_DEV		INET_MIN_DEV /* minimum minor device number */
44 #define	MI_COPY_IN		1
45 #define	MI_COPY_OUT		2
46 #define	MI_COPY_DIRECTION(mp)	(*(int *)&(mp)->b_cont->b_next)
47 #define	MI_COPY_COUNT(mp)	(*(int *)&(mp)->b_cont->b_prev)
48 #define	MI_COPY_CASE(dir, cnt)	(((cnt)<<2)|dir)
49 #define	MI_COPY_STATE(mp)	MI_COPY_CASE(MI_COPY_DIRECTION(mp), \
50 					MI_COPY_COUNT(mp))
51 
52 #ifdef __lint
53 /* Lint complains about %p with field width specifiers. */
54 #define	MI_COL_PTRFMT_STR	"%p "
55 #define	MI_COL_HDRPAD_STR	""
56 #else
57 #ifdef _ILP32
58 #if defined(__GNUC__)
59 #define	MI_COL_PTRFMT_STR	"%8p "
60 #else
61 #define	MI_COL_PTRFMT_STR	"%08p "
62 #endif	/* __GNUC__ */
63 #define	MI_COL_HDRPAD_STR	""
64 #else
65 #define	MI_COL_PTRFMT_STR	"%16p "
66 #define	MI_COL_HDRPAD_STR	"        "
67 #endif
68 #endif
69 
70 /*
71  * Double linked list of type MI_O with a mi_head_t as the head.
72  * Used for mi_open_comm etc.
73  */
74 typedef struct mi_o_s {
75 	struct mi_o_s	*mi_o_next;
76 	struct mi_o_s	*mi_o_prev;
77 	boolean_t	mi_o_isdev;	/* Is this a device instance */
78 	dev_t		mi_o_dev;
79 } MI_O, *MI_OP;
80 
81 /*
82  * List head for MI_O doubly linked list.
83  * The list contains unsorted driver, module and detached instances.
84  *
85  * Minor numbers are allocated from mh_arena which initially contains
86  * [MI_MIN_DEV, mh_maxminor] numbers. When this arena is fully allocated, it is
87  * extended to MAXMIN32.
88  *
89  * The module_dev is used to give almost unique numbers to module instances.
90  * This is only needed for mi_strlog which uses the mi_o_dev field when
91  * logging messages.
92  */
93 
94 typedef struct mi_head_s {
95 	struct mi_o_s	mh_o;	/* Contains head of doubly linked list */
96 	vmem_t *mh_arena;	/* Minor number arena */
97 	int	mh_module_dev;  /* Wraparound number for use when MODOPEN */
98 	minor_t mh_maxminor;	/* max minor number in the arena */
99 } mi_head_t;
100 
101 extern void	*mi_alloc(size_t size, uint_t pri);
102 extern void	*mi_alloc_sleep(size_t size, uint_t pri);
103 extern void	mi_free(void *ptr);
104 
105 extern int	mi_close_comm(void **mi_head, queue_t *q);
106 extern void	mi_close_free(IDP ptr);
107 extern void	mi_close_unlink(void **mi_head, IDP ptr);
108 
109 extern void	mi_copyin(queue_t *q, MBLKP mp, char *uaddr, size_t len);
110 extern void	mi_copyin_n(queue_t *q, MBLKP mp, size_t offset, size_t len);
111 extern void	mi_copyout(queue_t *q, MBLKP mp);
112 extern MBLKP	mi_copyout_alloc(queue_t *q, MBLKP mp, char *uaddr, size_t len,
113 		    boolean_t free_on_error);
114 extern void	mi_copy_done(queue_t *q, MBLKP mp, int err);
115 extern int	mi_copy_state(queue_t *q, MBLKP mp, MBLKP *mpp);
116 
117 /*PRINTFLIKE2*/
118 extern int	mi_mpprintf(MBLKP mp, char *fmt, ...)
119 	__KPRINTFLIKE(2);
120 /*PRINTFLIKE2*/
121 extern int	mi_mpprintf_nr(MBLKP mp, char *fmt, ...)
122 	__KPRINTFLIKE(2);
123 extern int	mi_mpprintf_putc(char *cookie, int ch);
124 
125 extern IDP	mi_first_ptr(void **mi_head);
126 extern IDP	mi_first_dev_ptr(void **mi_head);
127 extern IDP	mi_next_ptr(void **mi_head, IDP ptr);
128 extern IDP	mi_next_dev_ptr(void **mi_head, IDP ptr);
129 
130 extern IDP	mi_open_alloc(size_t size);
131 extern IDP	mi_open_alloc_sleep(size_t size);
132 extern int	mi_open_comm(void **mi_head, size_t size, queue_t *q,
133 		    dev_t *devp, int flag, int sflag, cred_t *credp);
134 extern int	mi_open_link(void **mi_head, IDP ptr, dev_t *devp, int flag,
135 		    int sflag, cred_t *credp);
136 
137 extern uint8_t *mi_offset_param(mblk_t *mp, size_t offset, size_t len);
138 extern uint8_t *mi_offset_paramc(mblk_t *mp, size_t offset, size_t len);
139 
140 
141 extern boolean_t	mi_set_sth_hiwat(queue_t *q, size_t size);
142 extern boolean_t	mi_set_sth_lowat(queue_t *q, size_t size);
143 extern boolean_t	mi_set_sth_maxblk(queue_t *q, ssize_t size);
144 extern boolean_t	mi_set_sth_copyopt(queue_t *q, int copyopt);
145 extern boolean_t	mi_set_sth_wroff(queue_t *q, size_t size);
146 
147 /*PRINTFLIKE2*/
148 extern int	mi_sprintf(char *buf, char *fmt, ...)
149 	__KPRINTFLIKE(2);
150 extern int	mi_sprintf_putc(char *cookie, int ch);
151 
152 extern int	mi_strcmp(const char *cp1, const char *cp2);
153 extern size_t	mi_strlen(const char *str);
154 
155 /*PRINTFLIKE4*/
156 extern int	mi_strlog(queue_t *q, char level, ushort_t flags,
157 		    char *fmt, ...) __KPRINTFLIKE(4);
158 #pragma rarely_called(mi_strlog)
159 
160 extern long	mi_strtol(const char *str, char **ptr, int base);
161 
162 extern void	mi_timer(queue_t *q, MBLKP mp, clock_t tim);
163 extern MBLKP	mi_timer_alloc(size_t size);
164 extern void	mi_timer_free(MBLKP mp);
165 extern void	mi_timer_move(queue_t *, mblk_t *);
166 extern void	mi_timer_stop(mblk_t *);
167 extern boolean_t	mi_timer_valid(MBLKP mp);
168 
169 extern MBLKP	mi_tpi_conn_con(MBLKP trailer_mp, char *src,
170 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length);
171 extern MBLKP	mi_tpi_conn_ind(MBLKP trailer_mp, char *src,
172 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length,
173 		    t_scalar_t seqnum);
174 extern MBLKP	mi_tpi_extconn_ind(MBLKP trailer_mp, char *src,
175 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length,
176 		    char *dst, t_scalar_t dst_length, t_scalar_t seqnum);
177 extern MBLKP	mi_tpi_discon_ind(MBLKP trailer_mp, t_scalar_t reason,
178 		    t_scalar_t seqnum);
179 extern MBLKP	mi_tpi_err_ack_alloc(MBLKP mp, t_scalar_t tlierr, int unixerr);
180 extern MBLKP	mi_tpi_ok_ack_alloc(MBLKP mp);
181 extern MBLKP	mi_tpi_ok_ack_alloc_extra(MBLKP mp, int extra);
182 extern MBLKP	mi_tpi_ordrel_ind(void);
183 extern MBLKP	mi_tpi_uderror_ind(char *dest, t_scalar_t dest_length,
184 		    char *opt, t_scalar_t opt_length, t_scalar_t error);
185 
186 extern IDP	mi_zalloc(size_t size);
187 extern IDP	mi_zalloc_sleep(size_t size);
188 
189 #endif	/* _KERNEL */
190 
191 #ifdef	__cplusplus
192 }
193 #endif
194 
195 #endif	/* _INET_MI_H */
196