Sync with NetBSD.
[dragonfly/port-amd64.git] / sys / net / intrq.c
blob77c27b6b3052a7aa08afc7b1d71f3856435035fc
1 /*-
2 * Copyright (c) 2000 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD: src/sys/net/intrq.c,v 1.3 2000/01/29 16:13:08 peter Exp $
27 * $DragonFly: src/sys/net/intrq.c,v 1.6 2006/01/14 11:05:17 swildner Exp $
30 #include <sys/param.h>
31 #include <sys/mbuf.h>
32 #include <sys/socket.h>
33 #include <sys/systm.h>
34 #include <sys/thread2.h>
35 #include <sys/time.h>
37 #include <net/if.h>
38 #include <net/if_var.h>
39 #include <net/netisr.h>
40 #include <net/intrq.h>
42 #ifdef __i386__
43 #include <netproto/atm/kern_include.h> /* XXX overkill, fixme! */
44 #endif
47 * If the appropriate intrq_present variable is zero, don't use
48 * the queue (as it'll never get processed).
49 * When defined, each of the network stacks declares their own
50 * *intrq_present variable to be non-zero.
52 const int atintrq1_present;
53 const int atintrq2_present;
54 #ifdef NETISR_ATM
55 const int atmintrq_present;
56 #endif
57 const int ipintrq_present;
58 const int ip6intrq_present;
59 const int ipxintrq_present;
60 const int natmintrq_present;
61 const int nsintrq_present;
63 struct ifqueue atintrq1;
64 struct ifqueue atintrq2;
65 #ifdef NETISR_ATM
66 struct ifqueue atm_intrq;
67 #endif
68 struct ifqueue ipintrq;
69 struct ifqueue ip6intrq;
70 struct ifqueue ipxintrq;
71 struct ifqueue natmintrq;
72 struct ifqueue nsintrq;
75 static const struct {
76 sa_family_t family;
77 struct ifqueue *q;
78 int const *present;
79 int isr;
80 } queue[] = {
81 #ifdef NETISR_ATM
82 { AF_ATM, &atm_intrq, &atmintrq_present, NETISR_ATM },
83 #endif
84 { AF_INET, &ipintrq, &ipintrq_present, NETISR_IP },
85 { AF_INET6, &ip6intrq, &ip6intrq_present, NETISR_IPV6 },
86 { AF_IPX, &ipxintrq, &ipxintrq_present, NETISR_IPX },
87 { AF_NATM, &natmintrq, &natmintrq_present, NETISR_NATM },
88 { AF_APPLETALK, &atintrq2, &atintrq2_present, NETISR_ATALK2 },
89 { AF_NS, &nsintrq, &nsintrq_present, NETISR_NS }
92 int
93 family_enqueue(sa_family_t family, struct mbuf *m)
95 int entry, s;
97 for (entry = 0; entry < sizeof queue / sizeof queue[0]; entry++)
98 if (queue[entry].family == family) {
99 if (queue[entry].present) {
100 crit_enter();
101 if (IF_QFULL(queue[entry].q)) {
102 IF_DROP(queue[entry].q);
103 crit_exit();
104 m_freem(m);
105 return ENOBUFS;
107 IF_ENQUEUE(queue[entry].q, m);
108 crit_exit();
109 schednetisr(queue[entry].isr);
110 return 0;
111 } else
112 break;
115 m_freem(m);
116 return EAFNOSUPPORT;