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