kernel - network protocol thread routing
[dragonfly.git] / sys / net / netisr.h
CommitLineData
66d6c637
JH
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
984263bc
MD
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. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)netisr.h 8.1 (Berkeley) 6/10/93
67 * $FreeBSD: src/sys/net/netisr.h,v 1.21.2.5 2002/02/09 23:02:39 luigi Exp $
e3873585 68 * $DragonFly: src/sys/net/netisr.h,v 1.38 2008/10/27 02:56:30 sephe Exp $
984263bc
MD
69 */
70
71#ifndef _NET_NETISR_H_
72#define _NET_NETISR_H_
73
74/*
75 * The networking code runs off software interrupts.
76 *
77 * You can switch into the network by doing splnet() and return by splx().
78 * The software interrupt level for the network is higher than the software
79 * level for the clock (so you can enter the network in routines called
80 * at timeout time).
81 */
82
83/*
84 * Each ``pup-level-1'' input queue has a bit in a ``netisr'' status
85 * word which is used to de-multiplex a single software
86 * interrupt used for scheduling the network code to calls
87 * on the lowest level routine of each protocol.
88 */
35746821 89#define NETISR_RESERVED0 0 /* cannot be used */
984263bc
MD
90#define NETISR_IP 2 /* same as AF_INET */
91#define NETISR_NS 6 /* same as AF_NS */
8bde602d
JH
92#define NETISR_AARP 15 /* Appletalk ARP */
93#define NETISR_ATALK2 16 /* Appletalk phase 2 */
94#define NETISR_ATALK1 17 /* Appletalk phase 1 */
984263bc 95#define NETISR_ARP 18 /* same as AF_LINK */
9b42cabe 96#define NETISR_MPLS 21 /* MPLS */
984263bc 97#define NETISR_IPX 23 /* same as AF_IPX */
8bde602d 98#define NETISR_USB 25 /* USB soft interrupt */
984263bc
MD
99#define NETISR_PPP 27 /* PPP soft interrupt */
100#define NETISR_IPV6 28 /* same as AF_INET6 */
101#define NETISR_NATM 29 /* same as AF_NATM */
102#define NETISR_NETGRAPH 30 /* same as AF_NETGRAPH */
0a9108eb 103#define NETISR_BLUETOOTH 31
984263bc 104
8bde602d 105#define NETISR_MAX 32
ef0fdad1 106
03d6a592 107#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
984263bc 108
03d6a592
MD
109#ifndef _SYS_TYPES_H_
110#include <sys/types.h>
111#endif
112#ifndef _SYS_QUEUE_H_
113#include <sys/queue.h>
114#endif
115#ifndef _SYS_PROTOSW_H_
9eeaa8a9 116#include <sys/protosw.h>
03d6a592
MD
117#endif
118#ifndef _SYS_MSGPORT_H_
119#include <sys/msgport.h>
120#endif
4599cf19
MD
121#ifndef _NET_NETMSG_H_
122#include <net/netmsg.h>
123#endif
03d6a592
MD
124
125TAILQ_HEAD(notifymsglist, netmsg_so_notify);
9eeaa8a9 126
03d6a592 127typedef __boolean_t (*msg_predicate_fn_t)(struct netmsg *);
9eeaa8a9
JH
128
129/*
130 * Base class. All net messages must start with the same fields.
131 */
9eeaa8a9
JH
132
133struct netmsg_packet {
4599cf19 134 struct netmsg nm_netmsg;
9eeaa8a9 135 struct mbuf *nm_packet;
6a704092 136 int nm_nxt;
9eeaa8a9
JH
137};
138
9eeaa8a9 139struct netmsg_pr_timeout {
4599cf19 140 struct netmsg nm_netmsg;
b44419cb 141 int (*nm_prfn) (void);
9eeaa8a9
JH
142};
143
c1d0003c 144struct netmsg_so_notify {
4599cf19 145 struct netmsg nm_netmsg;
c1d0003c
JH
146 msg_predicate_fn_t nm_predicate;
147 struct socket *nm_so;
9ba76b73 148 int nm_fflags; /* flags e.g. FNONBLOCK */
c1d0003c
JH
149 int nm_etype; /* receive or send event */
150 TAILQ_ENTRY(netmsg_so_notify) nm_list;
151};
152
4599cf19
MD
153struct netmsg_so_notify_abort {
154 struct netmsg nm_netmsg;
155 struct netmsg_so_notify *nm_notifymsg;
156};
157
c1d0003c
JH
158#define NM_REVENT 0x1 /* event on receive buffer */
159#define NM_SEVENT 0x2 /* event on send buffer */
160
03d6a592
MD
161#endif
162
163#ifdef _KERNEL
164
9eeaa8a9
JH
165/*
166 * for dispatching pr_ functions,
167 * until they can be converted to message-passing
168 */
4599cf19
MD
169void netmsg_pru_abort(netmsg_t);
170void netmsg_pru_accept(netmsg_t);
171void netmsg_pru_attach(netmsg_t);
172void netmsg_pru_bind(netmsg_t);
173void netmsg_pru_connect(netmsg_t);
174void netmsg_pru_connect2(netmsg_t);
175void netmsg_pru_control(netmsg_t);
176void netmsg_pru_detach(netmsg_t);
177void netmsg_pru_disconnect(netmsg_t);
178void netmsg_pru_listen(netmsg_t);
179void netmsg_pru_peeraddr(netmsg_t);
180void netmsg_pru_rcvd(netmsg_t);
181void netmsg_pru_rcvoob(netmsg_t);
182void netmsg_pru_send(netmsg_t);
183void netmsg_pru_sense(netmsg_t);
184void netmsg_pru_shutdown(netmsg_t);
185void netmsg_pru_sockaddr(netmsg_t);
186
e71a125f 187void netmsg_pru_ctloutput(netmsg_t);
e3873585 188void netmsg_pru_ctlinput(netmsg_t);
4599cf19 189
4599cf19
MD
190void netmsg_pr_timeout(netmsg_t);
191
192void netmsg_so_notify(netmsg_t);
193void netmsg_so_notify_abort(netmsg_t);
194void netmsg_so_notify_doabort(lwkt_msg_t);
0ddb6032 195
03d6a592
MD
196#endif
197
198#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
199
f92bfd8c
SZ
200struct pktinfo {
201 int pi_netisr; /* netisr index, e.g. NETISR_IP */
202 uint32_t pi_flags; /* PKTINFO_FLAG_ */
203 int pi_l3proto; /* layer3 protocol number */
f92bfd8c
SZ
204};
205
206#define PKTINFO_FLAG_FRAG 0x1
207
f3eb6c49 208typedef lwkt_port_t (*pkt_portfn_t)(struct mbuf **);
2eb0d069 209typedef lwkt_port_t (*pktinfo_portfn_t)(const struct pktinfo *, struct mbuf *);
8bde602d 210
8bde602d 211struct netisr {
a29576fc 212 lwkt_port ni_port; /* must be first */
f3eb6c49 213 pkt_portfn_t ni_mport;
f92bfd8c 214 pktinfo_portfn_t ni_mport_pktinfo;
8bde602d 215 netisr_fn_t ni_handler;
a29576fc 216 struct netmsg ni_netmsg; /* for sched_netisr() (no-data) */
92db3805 217 uint32_t ni_flags; /* NETISR_FLAG_ */
8bde602d
JH
218};
219
95af0087
SZ
220#define NETISR_FLAG_NOTMPSAFE 0x0 /* ni_handler is not MPSAFE */
221#define NETISR_FLAG_MPSAFE 0x1 /* ni_handler is MPSAFE */
92db3805 222
03d6a592
MD
223#endif
224
225#ifdef _KERNEL
226
92db3805
SZ
227#define NETMSG_SERVICE_ADAPTIVE 1
228#define NETMSG_SERVICE_MPSAFE 2
229
1630efc5 230extern lwkt_port netisr_adone_rport;
3f48f9c5 231extern lwkt_port netisr_afree_rport;
ecd27a4c 232extern lwkt_port netisr_apanic_rport;
3f48f9c5 233
b01ae44a 234lwkt_port_t cpu0_portfn(struct mbuf **mptr);
ecdefdda 235lwkt_port_t cpu_portfn(int cpu);
2eb0d069
SZ
236lwkt_port_t pktinfo_portfn_cpu0(const struct pktinfo *, struct mbuf *);
237lwkt_port_t pktinfo_portfn_notsupp(const struct pktinfo *, struct mbuf *);
c244d613 238lwkt_port_t cur_netport(void);
f92bfd8c 239
29bc1092 240lwkt_port_t netisr_find_port(int, struct mbuf **);
2eb0d069 241lwkt_port_t netisr_find_pktinfo_port(const struct pktinfo *, struct mbuf *);
bf82f9b7 242void netisr_dispatch(int, struct mbuf *);
29bc1092 243void netisr_run(int, struct mbuf *);
bf82f9b7 244int netisr_queue(int, struct mbuf *);
f92bfd8c
SZ
245void netisr_register(int, pkt_portfn_t, pktinfo_portfn_t,
246 netisr_fn_t, uint32_t);
bf82f9b7 247int netisr_unregister(int);
f92bfd8c 248
5c703385 249void netmsg_service_port_init(lwkt_port_t);
bf82f9b7 250void netmsg_service_loop(void *arg);
92db3805 251int netmsg_service(struct netmsg *, int, int);
5c703385 252void netmsg_service_sync(void);
bf82f9b7 253void schednetisr(int);
984263bc 254
c244d613
SZ
255#define curnetport cur_netport()
256
03d6a592 257#endif /* _KERNEL */
984263bc 258
bf82f9b7 259#endif /* _NET_NETISR_H_ */