xref: /titanic_51/usr/src/uts/common/inet/mi.h (revision 9aa73b6813b3fd35e78fcc44fd17535e765e504c)
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 2009 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 /*
51  * Double linked list of type MI_O with a mi_head_t as the head.
52  * Used for mi_open_comm etc.
53  */
54 typedef struct mi_o_s {
55 	struct mi_o_s	*mi_o_next;
56 	struct mi_o_s	*mi_o_prev;
57 	boolean_t	mi_o_isdev;	/* Is this a device instance */
58 	dev_t		mi_o_dev;
59 } MI_O, *MI_OP;
60 
61 /*
62  * List head for MI_O doubly linked list.
63  * The list contains unsorted driver, module and detached instances.
64  *
65  * Minor numbers are allocated from mh_arena which initially contains
66  * [MI_MIN_DEV, mh_maxminor] numbers. When this arena is fully allocated, it is
67  * extended to MAXMIN32.
68  *
69  * The module_dev is used to give almost unique numbers to module instances.
70  * This is only needed for mi_strlog which uses the mi_o_dev field when
71  * logging messages.
72  */
73 
74 typedef struct mi_head_s {
75 	struct mi_o_s	mh_o;	/* Contains head of doubly linked list */
76 	vmem_t *mh_arena;	/* Minor number arena */
77 	int	mh_module_dev;  /* Wraparound number for use when MODOPEN */
78 	minor_t mh_maxminor;	/* max minor number in the arena */
79 } mi_head_t;
80 
81 extern void	*mi_alloc(size_t size, uint_t pri);
82 extern void	*mi_alloc_sleep(size_t size, uint_t pri);
83 extern void	mi_free(void *ptr);
84 
85 extern int	mi_close_comm(void **mi_head, queue_t *q);
86 extern void	mi_close_free(IDP ptr);
87 extern void	mi_close_unlink(void **mi_head, IDP ptr);
88 
89 extern void	mi_copyin(queue_t *q, MBLKP mp, char *uaddr, size_t len);
90 extern void	mi_copyin_n(queue_t *q, MBLKP mp, size_t offset, size_t len);
91 extern void	mi_copyout(queue_t *q, MBLKP mp);
92 extern MBLKP	mi_copyout_alloc(queue_t *q, MBLKP mp, char *uaddr, size_t len,
93 		    boolean_t free_on_error);
94 extern void	mi_copy_done(queue_t *q, MBLKP mp, int err);
95 extern int	mi_copy_state(queue_t *q, MBLKP mp, MBLKP *mpp);
96 
97 /*PRINTFLIKE2*/
98 extern int	mi_mpprintf(MBLKP mp, char *fmt, ...)
99 	__KPRINTFLIKE(2);
100 /*PRINTFLIKE2*/
101 extern int	mi_mpprintf_nr(MBLKP mp, char *fmt, ...)
102 	__KPRINTFLIKE(2);
103 extern int	mi_mpprintf_putc(char *cookie, int ch);
104 
105 extern IDP	mi_first_ptr(void **mi_head);
106 extern IDP	mi_first_dev_ptr(void **mi_head);
107 extern IDP	mi_next_ptr(void **mi_head, IDP ptr);
108 extern IDP	mi_next_dev_ptr(void **mi_head, IDP ptr);
109 
110 extern IDP	mi_open_alloc(size_t size);
111 extern IDP	mi_open_alloc_sleep(size_t size);
112 extern int	mi_open_comm(void **mi_head, size_t size, queue_t *q,
113 		    dev_t *devp, int flag, int sflag, cred_t *credp);
114 extern int	mi_open_link(void **mi_head, IDP ptr, dev_t *devp, int flag,
115 		    int sflag, cred_t *credp);
116 
117 extern uint8_t *mi_offset_param(mblk_t *mp, size_t offset, size_t len);
118 extern uint8_t *mi_offset_paramc(mblk_t *mp, size_t offset, size_t len);
119 
120 /*PRINTFLIKE2*/
121 extern int	mi_sprintf(char *buf, char *fmt, ...)
122 	__KPRINTFLIKE(2);
123 extern int	mi_sprintf_putc(char *cookie, int ch);
124 
125 extern int	mi_strcmp(const char *cp1, const char *cp2);
126 extern size_t	mi_strlen(const char *str);
127 
128 /*PRINTFLIKE4*/
129 extern int	mi_strlog(queue_t *q, char level, ushort_t flags,
130 		    char *fmt, ...) __KPRINTFLIKE(4);
131 #pragma rarely_called(mi_strlog)
132 
133 extern long	mi_strtol(const char *str, char **ptr, int base);
134 
135 extern void	mi_timer(queue_t *q, MBLKP mp, clock_t tim);
136 extern MBLKP	mi_timer_alloc(size_t size);
137 extern void	mi_timer_free(MBLKP mp);
138 extern void	mi_timer_move(queue_t *, mblk_t *);
139 extern void	mi_timer_stop(mblk_t *);
140 extern boolean_t	mi_timer_valid(MBLKP mp);
141 
142 extern MBLKP	mi_tpi_conn_con(MBLKP trailer_mp, char *src,
143 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length);
144 extern MBLKP	mi_tpi_conn_ind(MBLKP trailer_mp, char *src,
145 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length,
146 		    t_scalar_t seqnum);
147 extern MBLKP	mi_tpi_extconn_ind(MBLKP trailer_mp, char *src,
148 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length,
149 		    char *dst, t_scalar_t dst_length, t_scalar_t seqnum);
150 extern MBLKP	mi_tpi_discon_ind(MBLKP trailer_mp, t_scalar_t reason,
151 		    t_scalar_t seqnum);
152 extern MBLKP	mi_tpi_err_ack_alloc(MBLKP mp, t_scalar_t tlierr, int unixerr);
153 extern MBLKP	mi_tpi_ok_ack_alloc(MBLKP mp);
154 extern MBLKP	mi_tpi_ok_ack_alloc_extra(MBLKP mp, int extra);
155 extern MBLKP	mi_tpi_ordrel_ind(void);
156 extern MBLKP	mi_tpi_uderror_ind(char *dest, t_scalar_t dest_length,
157 		    char *opt, t_scalar_t opt_length, t_scalar_t error);
158 
159 extern IDP	mi_zalloc(size_t size);
160 extern IDP	mi_zalloc_sleep(size_t size);
161 
162 #endif	/* _KERNEL */
163 
164 #ifdef	__cplusplus
165 }
166 #endif
167 
168 #endif	/* _INET_MI_H */
169