2 * Netbufs don't come with nifty queuing functions
3 * like mbufs. We therefore make our own quques by
4 * squirreling away an extra pointer before the data
5 * in a netbuf. As we can't guarantee that this will
6 * be aligned to anything in particular I use bcopy to
7 * read and write it. bcopy can use 32 bit if it really
15 #import <kernserv/machine/spl.h>
17 #include <kernserv/kern_server_types.h>
18 #include <kernserv/kalloc.h>
22 * There is no driver kit for the Moto release.
26 #define IOLogDbg if (sc->sc_flags & SC_DEBUG) printf
28 #define IOLogDbg if (sc->sc_flags & SC_DEBUG) IOLog
31 extern kern_server_t instance;
34 * Careful about using this function. Some places
35 * in the code drop packets based on this count
36 * but they never free them.
40 nbq_full(struct nb_queue* nbq)
43 rv = (nbq->len >= nbq->max);
48 nbq_empty(struct nb_queue* nbq)
56 nbq_low(struct nb_queue* nbq)
59 rv = (nbq->len <= nbq->low);
64 nbq_high(struct nb_queue* nbq)
67 rv = (nbq->len >= nbq->high);
71 static inline NETBUF_T
72 nbq_peek(struct nb_queue* nbq)
83 static inline NETBUF_T
84 nbq_dequeue(struct nb_queue* nbq)
94 NB_GET_NEXT(nb,&nbq->head);
104 * One simple note about nbq_enqueue: it will enqueue packets even if
105 * it is full, so the caller is responsible for checking this first...
107 * We return 1 if we added, else we return 0
108 * if there was a problem. We leave it up to the caller
109 * to detect an error return value (0) and print
110 * an appropriate message/update stats. However, in the spirit of
111 * keeping the code as close to the netbsd version as is possible,
112 * WE WILL FREE a packet that can't be enqueued. This should be the
113 * responsibility of the caller but that is currently not the case.
115 * Actually, now I'm using the hidden pointer arrangement then theres
116 * no circumstances under which this can return 0, oh well...
121 nbq_enqueue(struct nb_queue* nbq, NETBUF_T nb)
125 NB_SET_NEXT(nb,NULL);
128 NB_SET_NEXT(nbq->tail,nb);
138 nbq_flush(struct nb_queue *nbq)
151 nbq->head = nbq->tail = NULL;
158 * Must not be called at interrupt priority
162 nbq_init(struct nb_queue *nbq, struct qparms *qp)
164 nbq->name = qp->q_name;
165 nbq->head = nbq->tail = NULL;
166 nbq->low = qp->q_low;
167 nbq->high = qp->q_high;
168 nbq->max = qp->q_max;
174 nbq_free(struct nb_queue *nbq)
180 nbq_drop(struct nb_queue *nbq)
186 * Not very pretty, but it makes for less "diffs"...
188 #define mtod(m,type) ((type) NB_MAP(m))
190 typedef void (*pfv)(void *);
192 /* used by both ppp_tty.c and if_ppp.c */
193 static inline kern_return_t
194 pppsched(pfv func, struct ppp_softc *sc)
196 extern kern_server_t instance;
197 kern_return_t result;
199 if ((result = kern_serv_callout(&instance, func, (void *)sc)) != KERN_SUCCESS)
200 IOLog("kern_serv_callout failed: ret = %x\n", result);
207 static inline thread_t
210 extern thread_t active_threads[];
212 return active_threads[0];
215 extern struct proc *proc_from_thread(thread_t);
216 extern struct uthread *uthread_from_thread(thread_t);
218 #define curproc (proc_from_thread(current_thread()))
223 extern struct bpf_fns fnarg;
226 bpfattach(caddr_t *driverp, netif_t ifp, u_int dlt, u_int hdrlen)
228 struct bpf_attachargs atarg = {driverp, (caddr_t) ifp, dlt, hdrlen};
230 if (cdevsw[BPF_MAJOR_CHAR].d_ioctl != 0)
232 (*cdevsw[BPF_MAJOR_CHAR].d_ioctl)(0, BIOCATTACH, &atarg, 0);
233 (*cdevsw[BPF_MAJOR_CHAR].d_ioctl)(0, BIOCGFNS, &fnarg, 0);
240 bpf_tap(caddr_t arg, u_char *pkt, u_int pktlen)
242 bpf_tap(caddr_t arg, NETBUF_T pkt, u_int pktlen)
245 (*fnarg.tapfn)(arg, pkt, pktlen);