[PATCH] uml: use GFP_ATOMIC for allocations under spinlocks.
[linux-2.6] / arch / um / drivers / slirp_kern.c
1 #include "linux/kernel.h"
2 #include "linux/stddef.h"
3 #include "linux/init.h"
4 #include "linux/netdevice.h"
5 #include "linux/if_arp.h"
6 #include "net_kern.h"
7 #include "net_user.h"
8 #include "kern.h"
9 #include "slirp.h"
10
11 struct slirp_init {
12         struct arg_list_dummy_wrapper argw;  /* XXX should be simpler... */
13 };
14
15 void slirp_init(struct net_device *dev, void *data)
16 {
17         struct uml_net_private *private;
18         struct slirp_data *spri;
19         struct slirp_init *init = data;
20         int i;
21
22         private = dev->priv;
23         spri = (struct slirp_data *) private->user;
24         *spri = ((struct slirp_data)
25                 { .argw         = init->argw,
26                   .pid          = -1,
27                   .slave        = -1,
28                   .slip         = SLIP_PROTO_INIT,
29                   .dev          = dev });
30
31         dev->init = NULL;
32         dev->hard_header_len = 0;
33         dev->header_cache_update = NULL;
34         dev->hard_header_cache = NULL;
35         dev->hard_header = NULL;
36         dev->addr_len = 0;
37         dev->type = ARPHRD_SLIP;
38         dev->tx_queue_len = 256;
39         dev->flags = IFF_NOARP;
40         printk("SLIRP backend - command line:");
41         for(i=0;spri->argw.argv[i]!=NULL;i++) {
42                 printk(" '%s'",spri->argw.argv[i]);
43         }
44         printk("\n");
45 }
46
47 static unsigned short slirp_protocol(struct sk_buff *skbuff)
48 {
49         return(htons(ETH_P_IP));
50 }
51
52 static int slirp_read(int fd, struct sk_buff **skb, 
53                        struct uml_net_private *lp)
54 {
55         return(slirp_user_read(fd, (*skb)->mac.raw, (*skb)->dev->mtu, 
56                               (struct slirp_data *) &lp->user));
57 }
58
59 static int slirp_write(int fd, struct sk_buff **skb,
60                       struct uml_net_private *lp)
61 {
62         return(slirp_user_write(fd, (*skb)->data, (*skb)->len, 
63                                (struct slirp_data *) &lp->user));
64 }
65
66 struct net_kern_info slirp_kern_info = {
67         .init                   = slirp_init,
68         .protocol               = slirp_protocol,
69         .read                   = slirp_read,
70         .write                  = slirp_write,
71 };
72
73 static int slirp_setup(char *str, char **mac_out, void *data)
74 {
75         struct slirp_init *init = data;
76         int i=0;
77
78         *init = ((struct slirp_init)
79                 { argw :                { { "slirp", NULL  } } });
80
81         str = split_if_spec(str, mac_out, NULL);
82
83         if(str == NULL) { /* no command line given after MAC addr */
84                 return(1);
85         }
86
87         do {
88                 if(i>=SLIRP_MAX_ARGS-1) {
89                         printk("slirp_setup: truncating slirp arguments\n");
90                         break;
91                 }
92                 init->argw.argv[i++] = str;
93                 while(*str && *str!=',') {
94                         if(*str=='_') *str=' ';
95                         str++;
96                 }
97                 if(*str!=',')
98                         break;
99                 *str++='\0';
100         } while(1);
101         init->argw.argv[i]=NULL;
102         return(1);
103 }
104
105 static struct transport slirp_transport = {
106         .list           = LIST_HEAD_INIT(slirp_transport.list),
107         .name           = "slirp",
108         .setup          = slirp_setup,
109         .user           = &slirp_user_info,
110         .kern           = &slirp_kern_info,
111         .private_size   = sizeof(struct slirp_data),
112         .setup_size     = sizeof(struct slirp_init),
113 };
114
115 static int register_slirp(void)
116 {
117         register_transport(&slirp_transport);
118         return(1);
119 }
120
121 __initcall(register_slirp);
122
123 /*
124  * Overrides for Emacs so that we follow Linus's tabbing style.
125  * Emacs will notice this stuff at the end of the file and automatically
126  * adjust the settings for this buffer only.  This must remain at the end
127  * of the file.
128  * ---------------------------------------------------------------------------
129  * Local variables:
130  * c-file-style: "linux"
131  * End:
132  */