xref: /dragonfly/sys/net/netisr.h (revision ffe53622)
1 /*
2  * Copyright (c) 2004 Jeffrey M. Hsu.  All rights reserved.
3  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
4  *
5  * This code is derived from software contributed to The DragonFly Project
6  * by Jeffrey M. Hsu.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of The DragonFly Project nor the names of its
17  *    contributors may be used to endorse or promote products derived
18  *    from this software without specific, prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1980, 1986, 1989, 1993
36  *	The Regents of the University of California.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  *
62  *	@(#)netisr.h	8.1 (Berkeley) 6/10/93
63  * $FreeBSD: src/sys/net/netisr.h,v 1.21.2.5 2002/02/09 23:02:39 luigi Exp $
64  */
65 
66 #ifndef _NET_NETISR_H_
67 #define _NET_NETISR_H_
68 
69 /*
70  * The networking code runs off software interrupts.
71  *
72  * You can switch into the network by doing splnet() and return by splx().
73  * The software interrupt level for the network is higher than the software
74  * level for the clock (so you can enter the network in routines called
75  * at timeout time).
76  */
77 
78 /*
79  * Each ``pup-level-1'' input queue has a bit in a ``netisr'' status
80  * word which is used to de-multiplex a single software
81  * interrupt used for scheduling the network code to calls
82  * on the lowest level routine of each protocol.
83  */
84 #define NETISR_RESERVED0 0		/* cannot be used */
85 #define	NETISR_IP	2		/* same as AF_INET */
86 #define	NETISR_ARP	18		/* same as AF_LINK */
87 #define	NETISR_MPLS	21		/* MPLS */
88 #define	NETISR_USB	25		/* USB soft interrupt */
89 #define	NETISR_PPP	27		/* PPP soft interrupt */
90 #define	NETISR_IPV6	28		/* same as AF_INET6 */
91 #define	NETISR_NETGRAPH	30		/* same as AF_NETGRAPH */
92 #define	NETISR_BLUETOOTH 31
93 
94 #define	NETISR_MAX	32
95 
96 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
97 
98 #ifndef _SYS_TYPES_H_
99 #include <sys/types.h>
100 #endif
101 #ifndef _SYS_QUEUE_H_
102 #include <sys/queue.h>
103 #endif
104 #ifndef _SYS_PROTOSW_H_
105 #include <sys/protosw.h>
106 #endif
107 #ifndef _SYS_MSGPORT_H_
108 #include <sys/msgport.h>
109 #endif
110 #ifndef _NET_NETMSG_H_
111 #include <net/netmsg.h>
112 #endif
113 
114 #endif
115 
116 #ifdef _KERNEL
117 
118 void netmsg_so_notify(netmsg_t);
119 void netmsg_so_notify_abort(netmsg_t);
120 void netmsg_so_notify_doabort(lwkt_msg_t);
121 
122 #endif
123 
124 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
125 
126 /*
127  * Temporary pktinfo structure passed directly from the driver to
128  * ether_input(), allows us to bypass numerous checks.
129  */
130 struct pktinfo {
131 	int		pi_netisr;	/* netisr index, e.g. NETISR_IP */
132 	uint32_t	pi_flags;	/* PKTINFO_FLAG_ */
133 	int		pi_l3proto;	/* layer3 protocol number */
134 };
135 
136 #define PKTINFO_FLAG_FRAG      0x1
137 
138 /*
139  * NETISR_xxx registrations
140  */
141 struct netisr {
142 	netisr_fn_t	ni_handler;	/* packet handler function */
143 	netisr_hashck_t	ni_hashck;	/* hash check function */
144 	netisr_hashfn_t	ni_hashfn;	/* characterize pkt return hash */
145 	struct netmsg_base ni_netmsg;	/* for sched_netisr() (no-data) */
146 };
147 
148 #endif
149 
150 #ifdef _KERNEL
151 
152 /* NOTE: MUST be power-of-2 */
153 #define NETISR_CPUMAX			128	/* supported by most NICs */
154 #define NETISR_CPUMASK			(NETISR_CPUMAX - 1)
155 
156 #define NETISR_ROLLUP_PRIO_TCP		200
157 #define NETISR_ROLLUP_PRIO_IFSTART	50
158 
159 extern int	 netisr_ncpus;
160 extern lwkt_port netisr_adone_rport;
161 extern lwkt_port netisr_afree_rport;
162 extern lwkt_port netisr_afree_free_so_rport;
163 extern lwkt_port netisr_apanic_rport;
164 extern lwkt_port netisr_sync_port;
165 
166 struct netisr_rollup;
167 
168 void		netisr_register(int, netisr_fn_t, netisr_hashfn_t);
169 void		netisr_register_hashcheck(int, netisr_hashck_t);
170 struct netisr_rollup
171 		*netisr_register_rollup(netisr_ru_t ru_func, int ru_prio);
172 void		netisr_unregister_rollup(struct netisr_rollup *key);
173 
174 void		netisr_characterize(int num, struct mbuf **mp, int hoff);
175 void		netisr_hashcheck(int num, struct mbuf *m,
176 		    const struct pktinfo *pi);
177 int		netisr_queue(int, struct mbuf *);
178 int		netisr_handle(int, struct mbuf *);
179 
180 struct netisr_barrier *netisr_barrier_create(void);
181 void		netisr_barrier_set(struct netisr_barrier *);
182 void		netisr_barrier_rem(struct netisr_barrier *);
183 
184 void		netmsg_service_sync(void);
185 void		netmsg_sync_handler(netmsg_t);
186 void		schednetisr(int);
187 
188 #endif	/* _KERNEL */
189 
190 #endif	/* _NET_NETISR_H_ */
191