]> git.ozlabs.org Git - ppp.git/blob - modules/ppp_mod.h
priority queueing stuff (define bcanputnext)
[ppp.git] / modules / ppp_mod.h
1 /*
2  * Miscellaneous definitions for PPP STREAMS modules.
3  */
4
5 /*
6  * Macros for allocating and freeing kernel memory.
7  */
8 #ifdef SVR4                     /* SVR4, including Solaris 2 */
9 #include <sys/kmem.h>
10 #define ALLOC_SLEEP(n)          kmem_alloc((n), KM_SLEEP)
11 #define ALLOC_NOSLEEP(n)        kmem_alloc((n), KM_NOSLEEP)
12 #define FREE(p, n)              kmem_free((p), (n))
13 #endif
14
15 #ifdef SUNOS4
16 #include <sys/kmem_alloc.h>     /* SunOS 4.x */
17 #define ALLOC_SLEEP(n)          kmem_alloc((n), KMEM_SLEEP)
18 #define ALLOC_NOSLEEP(n)        kmem_alloc((n), KMEM_NOSLEEP)
19 #define FREE(p, n)              kmem_free((p), (n))
20 #define NOTSUSER()              (suser()? 0: EPERM)
21 #define bcanputnext(q, band)    canputnext((q))
22 #endif /* SunOS 4 */
23
24 #ifdef __osf__
25 #include <sys/malloc.h>
26
27 /* caution: this mirrors macros in sys/malloc.h, and uses interfaces
28  * which are subject to change.
29  * The problems are that:
30  *     - the official MALLOC macro wants the lhs of the assignment as an argument,
31  *       and it takes care of the assignment itself (yuck.)
32  *     - PPP insists on using "FREE" which conflicts with a macro of the same name.
33  *
34  */
35 #ifdef BUCKETINDX /* V2.0 */
36 #define ALLOC_SLEEP(n)          (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_WAITOK)
37 #define ALLOC_NOSLEEP(n)        (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_NOWAIT)
38 #else
39 #define ALLOC_SLEEP(n)          (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_WAITOK)
40 #define ALLOC_NOSLEEP(n)        (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_NOWAIT)
41 #endif
42
43 #ifdef FREE
44 #undef FREE
45 #endif
46 #define FREE(p, n)              free((void *)(p), M_DEVBUF)
47
48 #define NO_DLPI 1
49
50 #ifndef IFT_PPP
51 #define IFT_PPP 0x17
52 #endif
53
54 #include <sys/proc.h>
55 #define NOTSUSER()              (suser(u.u_procp->p_rcred, &u.u_acflag) ? EPERM : 0)
56
57 #include "ppp_osf.h"
58
59 #endif /* __osf__ */
60
61 #ifdef AIX4
62 #define ALLOC_SLEEP(n)          xmalloc((n), 0, pinned_heap)    /* AIX V4.x */
63 #define ALLOC_NOSLEEP(n)        xmalloc((n), 0, pinned_heap)    /* AIX V4.x */
64 #define FREE(p, n)              xmfree((p), pinned_heap)
65 #define NOTSUSER()              (suser()? 0: EPERM)
66 #endif /* AIX */
67
68 /*
69  * Macros for printing debugging stuff.
70  */
71 #ifdef DEBUG
72 #if defined(SVR4) || defined(__osf__)
73 #define DPRINT(f)               cmn_err(CE_CONT, f)
74 #define DPRINT1(f, a1)          cmn_err(CE_CONT, f, a1)
75 #define DPRINT2(f, a1, a2)      cmn_err(CE_CONT, f, a1, a2)
76 #define DPRINT3(f, a1, a2, a3)  cmn_err(CE_CONT, f, a1, a2, a3)
77 #else
78 #define DPRINT(f)               printf(f)
79 #define DPRINT1(f, a1)          printf(f, a1)
80 #define DPRINT2(f, a1, a2)      printf(f, a1, a2)
81 #define DPRINT3(f, a1, a2, a3)  printf(f, a1, a2, a3)
82 #endif /* SVR4 */
83
84 #else
85 #define DPRINT(f)               0
86 #define DPRINT1(f, a1)          0
87 #define DPRINT2(f, a1, a2)      0
88 #define DPRINT3(f, a1, a2, a3)  0
89 #endif /* DEBUG */
90
91 #ifndef SVR4
92 typedef unsigned char uchar_t;
93 typedef unsigned short ushort_t;
94 #ifndef __osf__
95 typedef int minor_t;
96 #endif
97 #endif
98
99 /*
100  * If we don't have multithreading support, define substitutes.
101  */
102 #ifndef D_MP
103 # define qprocson(q)
104 # define qprocsoff(q)
105 # define put(q, mp)     ((*(q)->q_qinfo->qi_putp)((q), (mp)))
106 # define canputnext(q)  canput((q)->q_next)
107 # define qwriter(q, mp, func, scope)    (func)((q), (mp))
108 #endif
109
110 #ifdef D_MP
111 /* Use msgpullup if we have other multithreading support. */
112 #define PULLUP(mp, len)                         \
113     do {                                        \
114         mblk_t *np = msgpullup((mp), (len));    \
115         freemsg((mp));                          \
116         mp = np;                                \
117     } while (0)
118
119 #else
120 /* Use pullupmsg if we don't have any multithreading support. */
121 #define PULLUP(mp, len)                 \
122     do {                                \
123         if (!pullupmsg((mp), (len))) {  \
124             freemsg((mp));              \
125             mp = 0;                     \
126         }                               \
127     } while (0)
128 #endif
129
130 /*
131  * How to declare the open and close procedures for a module.
132  */
133 #ifdef SVR4
134 #define MOD_OPEN_DECL(name)     \
135 static int name __P((queue_t *, dev_t *, int, int, cred_t *))
136
137 #define MOD_CLOSE_DECL(name)    \
138 static int name __P((queue_t *, int, cred_t *))
139
140 #define MOD_OPEN(name)                          \
141 static int name(q, devp, flag, sflag, credp)    \
142     queue_t *q;                                 \
143     dev_t *devp;                                \
144     int flag, sflag;                            \
145     cred_t *credp;
146
147 #define MOD_CLOSE(name)         \
148 static int name(q, flag, credp) \
149     queue_t *q;                 \
150     int flag;                   \
151     cred_t *credp;
152
153 #define OPEN_ERROR(x)           return (x)
154 #define DRV_OPEN_OK(dev)        return 0
155
156 #define NOTSUSER()              (drv_priv(credp))
157
158 #else   /* not SVR4 */
159 #define MOD_OPEN_DECL(name)     \
160 static int name __P((queue_t *, int, int, int))
161
162 #define MOD_CLOSE_DECL(name)    \
163 static int name __P((queue_t *, int))
164
165 #define MOD_OPEN(name)          \
166 static int name(q, dev, flag, sflag)    \
167     queue_t *q;                         \
168     int dev;                            \
169     int flag, sflag;
170
171 #define MOD_CLOSE(name)         \
172 static int name(q, flag)        \
173     queue_t *q;                 \
174     int flag;
175
176 #define OPEN_ERROR(x)           { u.u_error = (x); return OPENFAIL; }
177 #define DRV_OPEN_OK(dev)        return (dev)
178
179 #endif  /* SVR4 */