xref: /titanic_44/usr/src/uts/common/inet/mi.h (revision d5b6ed4b2ef09ba3e41de5d786a1836943a63613)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50f1702c5SYu Xiangning  * Common Development and Distribution License (the "License").
60f1702c5SYu Xiangning  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d5b6ed4bSVasumathi Sundaram - Sun Microsystems  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate /* Copyright (c) 1990 Mentat Inc. */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_INET_MI_H
287c478bd9Sstevel@tonic-gate #define	_INET_MI_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef _KERNEL
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
387c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
390f1702c5SYu Xiangning #include <netinet/in.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	MI_MIN_DEV		INET_MIN_DEV /* minimum minor device number */
427c478bd9Sstevel@tonic-gate #define	MI_COPY_IN		1
437c478bd9Sstevel@tonic-gate #define	MI_COPY_OUT		2
447c478bd9Sstevel@tonic-gate #define	MI_COPY_DIRECTION(mp)	(*(int *)&(mp)->b_cont->b_next)
457c478bd9Sstevel@tonic-gate #define	MI_COPY_COUNT(mp)	(*(int *)&(mp)->b_cont->b_prev)
467c478bd9Sstevel@tonic-gate #define	MI_COPY_CASE(dir, cnt)	(((cnt)<<2)|dir)
477c478bd9Sstevel@tonic-gate #define	MI_COPY_STATE(mp)	MI_COPY_CASE(MI_COPY_DIRECTION(mp), \
487c478bd9Sstevel@tonic-gate 					MI_COPY_COUNT(mp))
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Double linked list of type MI_O with a mi_head_t as the head.
527c478bd9Sstevel@tonic-gate  * Used for mi_open_comm etc.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate typedef struct mi_o_s {
557c478bd9Sstevel@tonic-gate 	struct mi_o_s	*mi_o_next;
567c478bd9Sstevel@tonic-gate 	struct mi_o_s	*mi_o_prev;
577c478bd9Sstevel@tonic-gate 	boolean_t	mi_o_isdev;	/* Is this a device instance */
587c478bd9Sstevel@tonic-gate 	dev_t		mi_o_dev;
597c478bd9Sstevel@tonic-gate } MI_O, *MI_OP;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * List head for MI_O doubly linked list.
637c478bd9Sstevel@tonic-gate  * The list contains unsorted driver, module and detached instances.
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * Minor numbers are allocated from mh_arena which initially contains
667c478bd9Sstevel@tonic-gate  * [MI_MIN_DEV, mh_maxminor] numbers. When this arena is fully allocated, it is
677c478bd9Sstevel@tonic-gate  * extended to MAXMIN32.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * The module_dev is used to give almost unique numbers to module instances.
707c478bd9Sstevel@tonic-gate  * This is only needed for mi_strlog which uses the mi_o_dev field when
717c478bd9Sstevel@tonic-gate  * logging messages.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate typedef struct mi_head_s {
757c478bd9Sstevel@tonic-gate 	struct mi_o_s	mh_o;	/* Contains head of doubly linked list */
767c478bd9Sstevel@tonic-gate 	vmem_t *mh_arena;	/* Minor number arena */
777c478bd9Sstevel@tonic-gate 	int	mh_module_dev;  /* Wraparound number for use when MODOPEN */
787c478bd9Sstevel@tonic-gate 	minor_t mh_maxminor;	/* max minor number in the arena */
797c478bd9Sstevel@tonic-gate } mi_head_t;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate extern void	*mi_alloc(size_t size, uint_t pri);
827c478bd9Sstevel@tonic-gate extern void	*mi_alloc_sleep(size_t size, uint_t pri);
837c478bd9Sstevel@tonic-gate extern void	mi_free(void *ptr);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern int	mi_close_comm(void **mi_head, queue_t *q);
867c478bd9Sstevel@tonic-gate extern void	mi_close_free(IDP ptr);
877c478bd9Sstevel@tonic-gate extern void	mi_close_unlink(void **mi_head, IDP ptr);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate extern void	mi_copyin(queue_t *q, MBLKP mp, char *uaddr, size_t len);
907c478bd9Sstevel@tonic-gate extern void	mi_copyin_n(queue_t *q, MBLKP mp, size_t offset, size_t len);
917c478bd9Sstevel@tonic-gate extern void	mi_copyout(queue_t *q, MBLKP mp);
927c478bd9Sstevel@tonic-gate extern MBLKP	mi_copyout_alloc(queue_t *q, MBLKP mp, char *uaddr, size_t len,
937c478bd9Sstevel@tonic-gate 		    boolean_t free_on_error);
947c478bd9Sstevel@tonic-gate extern void	mi_copy_done(queue_t *q, MBLKP mp, int err);
957c478bd9Sstevel@tonic-gate extern int	mi_copy_state(queue_t *q, MBLKP mp, MBLKP *mpp);
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/
987c478bd9Sstevel@tonic-gate extern int	mi_mpprintf(MBLKP mp, char *fmt, ...)
997c478bd9Sstevel@tonic-gate 	__KPRINTFLIKE(2);
1007c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/
1017c478bd9Sstevel@tonic-gate extern int	mi_mpprintf_nr(MBLKP mp, char *fmt, ...)
1027c478bd9Sstevel@tonic-gate 	__KPRINTFLIKE(2);
1037c478bd9Sstevel@tonic-gate extern int	mi_mpprintf_putc(char *cookie, int ch);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate extern IDP	mi_first_ptr(void **mi_head);
1067c478bd9Sstevel@tonic-gate extern IDP	mi_first_dev_ptr(void **mi_head);
1077c478bd9Sstevel@tonic-gate extern IDP	mi_next_ptr(void **mi_head, IDP ptr);
1087c478bd9Sstevel@tonic-gate extern IDP	mi_next_dev_ptr(void **mi_head, IDP ptr);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate extern IDP	mi_open_alloc(size_t size);
1117c478bd9Sstevel@tonic-gate extern IDP	mi_open_alloc_sleep(size_t size);
1127c478bd9Sstevel@tonic-gate extern int	mi_open_comm(void **mi_head, size_t size, queue_t *q,
1137c478bd9Sstevel@tonic-gate 		    dev_t *devp, int flag, int sflag, cred_t *credp);
1147c478bd9Sstevel@tonic-gate extern int	mi_open_link(void **mi_head, IDP ptr, dev_t *devp, int flag,
1157c478bd9Sstevel@tonic-gate 		    int sflag, cred_t *credp);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate extern uint8_t *mi_offset_param(mblk_t *mp, size_t offset, size_t len);
1187c478bd9Sstevel@tonic-gate extern uint8_t *mi_offset_paramc(mblk_t *mp, size_t offset, size_t len);
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/
1217c478bd9Sstevel@tonic-gate extern int	mi_sprintf(char *buf, char *fmt, ...)
1227c478bd9Sstevel@tonic-gate 	__KPRINTFLIKE(2);
1237c478bd9Sstevel@tonic-gate extern int	mi_sprintf_putc(char *cookie, int ch);
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate extern int	mi_strcmp(const char *cp1, const char *cp2);
1267c478bd9Sstevel@tonic-gate extern size_t	mi_strlen(const char *str);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*PRINTFLIKE4*/
1297c478bd9Sstevel@tonic-gate extern int	mi_strlog(queue_t *q, char level, ushort_t flags,
1307c478bd9Sstevel@tonic-gate 		    char *fmt, ...) __KPRINTFLIKE(4);
1317c478bd9Sstevel@tonic-gate #pragma rarely_called(mi_strlog)
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate extern long	mi_strtol(const char *str, char **ptr, int base);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate extern void	mi_timer(queue_t *q, MBLKP mp, clock_t tim);
1367c478bd9Sstevel@tonic-gate extern MBLKP	mi_timer_alloc(size_t size);
1377c478bd9Sstevel@tonic-gate extern void	mi_timer_free(MBLKP mp);
1387c478bd9Sstevel@tonic-gate extern void	mi_timer_move(queue_t *, mblk_t *);
1397c478bd9Sstevel@tonic-gate extern void	mi_timer_stop(mblk_t *);
1407c478bd9Sstevel@tonic-gate extern boolean_t	mi_timer_valid(MBLKP mp);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_conn_con(MBLKP trailer_mp, char *src,
1437c478bd9Sstevel@tonic-gate 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length);
1447c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_conn_ind(MBLKP trailer_mp, char *src,
1457c478bd9Sstevel@tonic-gate 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length,
1467c478bd9Sstevel@tonic-gate 		    t_scalar_t seqnum);
1477c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_extconn_ind(MBLKP trailer_mp, char *src,
1487c478bd9Sstevel@tonic-gate 		    t_scalar_t src_length, char *opt, t_scalar_t opt_length,
1497c478bd9Sstevel@tonic-gate 		    char *dst, t_scalar_t dst_length, t_scalar_t seqnum);
1507c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_discon_ind(MBLKP trailer_mp, t_scalar_t reason,
1517c478bd9Sstevel@tonic-gate 		    t_scalar_t seqnum);
1527c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_err_ack_alloc(MBLKP mp, t_scalar_t tlierr, int unixerr);
1537c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_ok_ack_alloc(MBLKP mp);
1547c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_ok_ack_alloc_extra(MBLKP mp, int extra);
1557c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_ordrel_ind(void);
1567c478bd9Sstevel@tonic-gate extern MBLKP	mi_tpi_uderror_ind(char *dest, t_scalar_t dest_length,
1577c478bd9Sstevel@tonic-gate 		    char *opt, t_scalar_t opt_length, t_scalar_t error);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate extern IDP	mi_zalloc(size_t size);
1607c478bd9Sstevel@tonic-gate extern IDP	mi_zalloc_sleep(size_t size);
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate #endif
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #endif	/* _INET_MI_H */
169