xref: /dflybsd-src/sys/net/netisr.c (revision ac2e3f5effc58aa364c7e5c199f35ebbae7cda81)
1 /*-
2  * Copyright (c) 2003 Matthew Dillon
3  *
4  * $DragonFly: src/sys/net/netisr.c,v 1.1 2003/06/29 03:28:45 dillon Exp $
5  */
6 
7 #include <sys/param.h>
8 #include <sys/systm.h>
9 #include <sys/proc.h>
10 #include <sys/interrupt.h>
11 #include <net/netisr.h>
12 #include <machine/cpufunc.h>
13 #include <machine/ipl.h>
14 
15 static int isrmask;
16 static int isrsoftint_installed;
17 static netisr_t *netisrs[NETISR_MAX];
18 
19 static void
20 swi_net(void *arg)
21 {
22     int mask;
23     int bit;
24     netisr_t *func;
25 
26     while ((mask = isrmask) != 0) {
27 	bit = bsfl(mask);
28 	if (btrl(&isrmask, bit)) {
29 	    if ((func = netisrs[bit]) != NULL)
30 		func();
31 	}
32     }
33 }
34 
35 int
36 register_netisr(int num, netisr_t *handler)
37 {
38     if (num < 0 || num >= (sizeof(netisrs)/sizeof(*netisrs)) ) {
39 	printf("register_netisr: bad isr number: %d\n", num);
40 	return (EINVAL);
41     }
42     if (isrsoftint_installed == 0) {
43 	isrsoftint_installed = 1;
44 	register_swi(SWI_NET, swi_net, NULL, "swi_net");
45     }
46     netisrs[num] = handler;
47     return (0);
48 }
49 
50 int
51 unregister_netisr(int num)
52 {
53     if (num < 0 || num >= (sizeof(netisrs)/sizeof(*netisrs)) ) {
54 	printf("unregister_netisr: bad isr number: %d\n", num);
55 	return (EINVAL);
56     }
57     netisrs[num] = NULL;
58     return (0);
59 }
60 
61 void
62 schednetisr(int isrnum)
63 {
64     atomic_set_int(&isrmask, 1 << isrnum);
65     setsoftnet();
66 }
67 
68