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