diff options
Diffstat (limited to 'net/phonet')
-rw-r--r-- | net/phonet/pep-gprs.c | 170 |
1 files changed, 86 insertions, 84 deletions
diff --git a/net/phonet/pep-gprs.c b/net/phonet/pep-gprs.c index 22848dd7d67a..0b640b0fce0c 100644 --- a/net/phonet/pep-gprs.c +++ b/net/phonet/pep-gprs.c | |||
@@ -40,7 +40,7 @@ struct gprs_dev { | |||
40 | void (*old_data_ready)(struct sock *, int); | 40 | void (*old_data_ready)(struct sock *, int); |
41 | void (*old_write_space)(struct sock *); | 41 | void (*old_write_space)(struct sock *); |
42 | 42 | ||
43 | struct net_device *net; | 43 | struct net_device *dev; |
44 | 44 | ||
45 | struct sk_buff_head tx_queue; | 45 | struct sk_buff_head tx_queue; |
46 | struct work_struct tx_work; | 46 | struct work_struct tx_work; |
@@ -72,17 +72,19 @@ static __be16 gprs_type_trans(struct sk_buff *skb) | |||
72 | 72 | ||
73 | static void gprs_state_change(struct sock *sk) | 73 | static void gprs_state_change(struct sock *sk) |
74 | { | 74 | { |
75 | struct gprs_dev *dev = sk->sk_user_data; | 75 | struct gprs_dev *gp = sk->sk_user_data; |
76 | 76 | ||
77 | if (sk->sk_state == TCP_CLOSE_WAIT) { | 77 | if (sk->sk_state == TCP_CLOSE_WAIT) { |
78 | netif_stop_queue(dev->net); | 78 | struct net_device *dev = gp->dev; |
79 | netif_carrier_off(dev->net); | 79 | |
80 | netif_stop_queue(dev); | ||
81 | netif_carrier_off(dev); | ||
80 | } | 82 | } |
81 | } | 83 | } |
82 | 84 | ||
83 | static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb) | 85 | static int gprs_recv(struct gprs_dev *gp, struct sk_buff *skb) |
84 | { | 86 | { |
85 | struct net_device *net = dev->net; | 87 | struct net_device *dev = gp->dev; |
86 | int err = 0; | 88 | int err = 0; |
87 | __be16 protocol = gprs_type_trans(skb); | 89 | __be16 protocol = gprs_type_trans(skb); |
88 | 90 | ||
@@ -99,7 +101,7 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb) | |||
99 | * so wrap the IP packet as a single fragment of an head-less | 101 | * so wrap the IP packet as a single fragment of an head-less |
100 | * socket buffer. The network stack will pull what it needs, | 102 | * socket buffer. The network stack will pull what it needs, |
101 | * but at least, the whole IP payload is not memcpy'd. */ | 103 | * but at least, the whole IP payload is not memcpy'd. */ |
102 | rskb = netdev_alloc_skb(net, 0); | 104 | rskb = netdev_alloc_skb(dev, 0); |
103 | if (!rskb) { | 105 | if (!rskb) { |
104 | err = -ENOBUFS; | 106 | err = -ENOBUFS; |
105 | goto drop; | 107 | goto drop; |
@@ -123,11 +125,11 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb) | |||
123 | 125 | ||
124 | skb->protocol = protocol; | 126 | skb->protocol = protocol; |
125 | skb_reset_mac_header(skb); | 127 | skb_reset_mac_header(skb); |
126 | skb->dev = net; | 128 | skb->dev = dev; |
127 | 129 | ||
128 | if (likely(net->flags & IFF_UP)) { | 130 | if (likely(dev->flags & IFF_UP)) { |
129 | net->stats.rx_packets++; | 131 | dev->stats.rx_packets++; |
130 | net->stats.rx_bytes += skb->len; | 132 | dev->stats.rx_bytes += skb->len; |
131 | netif_rx(skb); | 133 | netif_rx(skb); |
132 | skb = NULL; | 134 | skb = NULL; |
133 | } else | 135 | } else |
@@ -136,33 +138,33 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb) | |||
136 | drop: | 138 | drop: |
137 | if (skb) { | 139 | if (skb) { |
138 | dev_kfree_skb(skb); | 140 | dev_kfree_skb(skb); |
139 | net->stats.rx_dropped++; | 141 | dev->stats.rx_dropped++; |
140 | } | 142 | } |
141 | return err; | 143 | return err; |
142 | } | 144 | } |
143 | 145 | ||
144 | static void gprs_data_ready(struct sock *sk, int len) | 146 | static void gprs_data_ready(struct sock *sk, int len) |
145 | { | 147 | { |
146 | struct gprs_dev *dev = sk->sk_user_data; | 148 | struct gprs_dev *gp = sk->sk_user_data; |
147 | struct sk_buff *skb; | 149 | struct sk_buff *skb; |
148 | 150 | ||
149 | while ((skb = pep_read(sk)) != NULL) { | 151 | while ((skb = pep_read(sk)) != NULL) { |
150 | skb_orphan(skb); | 152 | skb_orphan(skb); |
151 | gprs_recv(dev, skb); | 153 | gprs_recv(gp, skb); |
152 | } | 154 | } |
153 | } | 155 | } |
154 | 156 | ||
155 | static void gprs_write_space(struct sock *sk) | 157 | static void gprs_write_space(struct sock *sk) |
156 | { | 158 | { |
157 | struct gprs_dev *dev = sk->sk_user_data; | 159 | struct gprs_dev *gp = sk->sk_user_data; |
158 | struct net_device *net = dev->net; | 160 | struct net_device *dev = gp->dev; |
159 | unsigned credits = pep_writeable(sk); | 161 | unsigned credits = pep_writeable(sk); |
160 | 162 | ||
161 | spin_lock_bh(&dev->tx_lock); | 163 | spin_lock_bh(&gp->tx_lock); |
162 | dev->tx_max = credits; | 164 | gp->tx_max = credits; |
163 | if (credits > skb_queue_len(&dev->tx_queue) && netif_running(net)) | 165 | if (credits > skb_queue_len(&gp->tx_queue) && netif_running(dev)) |
164 | netif_wake_queue(net); | 166 | netif_wake_queue(dev); |
165 | spin_unlock_bh(&dev->tx_lock); | 167 | spin_unlock_bh(&gp->tx_lock); |
166 | } | 168 | } |
167 | 169 | ||
168 | /* | 170 | /* |
@@ -186,9 +188,9 @@ static int gprs_close(struct net_device *dev) | |||
186 | return 0; | 188 | return 0; |
187 | } | 189 | } |
188 | 190 | ||
189 | static int gprs_xmit(struct sk_buff *skb, struct net_device *net) | 191 | static int gprs_xmit(struct sk_buff *skb, struct net_device *dev) |
190 | { | 192 | { |
191 | struct gprs_dev *dev = netdev_priv(net); | 193 | struct gprs_dev *gp = netdev_priv(dev); |
192 | 194 | ||
193 | switch (skb->protocol) { | 195 | switch (skb->protocol) { |
194 | case htons(ETH_P_IP): | 196 | case htons(ETH_P_IP): |
@@ -199,16 +201,16 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *net) | |||
199 | return 0; | 201 | return 0; |
200 | } | 202 | } |
201 | 203 | ||
202 | spin_lock(&dev->tx_lock); | 204 | spin_lock(&gp->tx_lock); |
203 | if (likely(skb_queue_len(&dev->tx_queue) < dev->tx_max)) { | 205 | if (likely(skb_queue_len(&gp->tx_queue) < gp->tx_max)) { |
204 | skb_queue_tail(&dev->tx_queue, skb); | 206 | skb_queue_tail(&gp->tx_queue, skb); |
205 | skb = NULL; | 207 | skb = NULL; |
206 | } | 208 | } |
207 | if (skb_queue_len(&dev->tx_queue) >= dev->tx_max) | 209 | if (skb_queue_len(&gp->tx_queue) >= gp->tx_max) |
208 | netif_stop_queue(net); | 210 | netif_stop_queue(dev); |
209 | spin_unlock(&dev->tx_lock); | 211 | spin_unlock(&gp->tx_lock); |
210 | 212 | ||
211 | schedule_work(&dev->tx_work); | 213 | schedule_work(&gp->tx_work); |
212 | if (unlikely(skb)) | 214 | if (unlikely(skb)) |
213 | dev_kfree_skb(skb); | 215 | dev_kfree_skb(skb); |
214 | return 0; | 216 | return 0; |
@@ -216,16 +218,16 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *net) | |||
216 | 218 | ||
217 | static void gprs_tx(struct work_struct *work) | 219 | static void gprs_tx(struct work_struct *work) |
218 | { | 220 | { |
219 | struct gprs_dev *dev = container_of(work, struct gprs_dev, tx_work); | 221 | struct gprs_dev *gp = container_of(work, struct gprs_dev, tx_work); |
220 | struct net_device *net = dev->net; | 222 | struct net_device *dev = gp->dev; |
221 | struct sock *sk = dev->sk; | 223 | struct sock *sk = gp->sk; |
222 | struct sk_buff *skb; | 224 | struct sk_buff *skb; |
223 | 225 | ||
224 | while ((skb = skb_dequeue(&dev->tx_queue)) != NULL) { | 226 | while ((skb = skb_dequeue(&gp->tx_queue)) != NULL) { |
225 | int err; | 227 | int err; |
226 | 228 | ||
227 | net->stats.tx_bytes += skb->len; | 229 | dev->stats.tx_bytes += skb->len; |
228 | net->stats.tx_packets++; | 230 | dev->stats.tx_packets++; |
229 | 231 | ||
230 | skb_orphan(skb); | 232 | skb_orphan(skb); |
231 | skb_set_owner_w(skb, sk); | 233 | skb_set_owner_w(skb, sk); |
@@ -234,9 +236,9 @@ static void gprs_tx(struct work_struct *work) | |||
234 | err = pep_write(sk, skb); | 236 | err = pep_write(sk, skb); |
235 | if (err) { | 237 | if (err) { |
236 | LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n", | 238 | LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n", |
237 | net->name, err); | 239 | dev->name, err); |
238 | net->stats.tx_aborted_errors++; | 240 | dev->stats.tx_aborted_errors++; |
239 | net->stats.tx_errors++; | 241 | dev->stats.tx_errors++; |
240 | } | 242 | } |
241 | release_sock(sk); | 243 | release_sock(sk); |
242 | } | 244 | } |
@@ -246,30 +248,30 @@ static void gprs_tx(struct work_struct *work) | |||
246 | release_sock(sk); | 248 | release_sock(sk); |
247 | } | 249 | } |
248 | 250 | ||
249 | static int gprs_set_mtu(struct net_device *net, int new_mtu) | 251 | static int gprs_set_mtu(struct net_device *dev, int new_mtu) |
250 | { | 252 | { |
251 | if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11))) | 253 | if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11))) |
252 | return -EINVAL; | 254 | return -EINVAL; |
253 | 255 | ||
254 | net->mtu = new_mtu; | 256 | dev->mtu = new_mtu; |
255 | return 0; | 257 | return 0; |
256 | } | 258 | } |
257 | 259 | ||
258 | static void gprs_setup(struct net_device *net) | 260 | static void gprs_setup(struct net_device *dev) |
259 | { | 261 | { |
260 | net->features = NETIF_F_FRAGLIST; | 262 | dev->features = NETIF_F_FRAGLIST; |
261 | net->type = ARPHRD_NONE; | 263 | dev->type = ARPHRD_NONE; |
262 | net->flags = IFF_POINTOPOINT | IFF_NOARP; | 264 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; |
263 | net->mtu = GPRS_DEFAULT_MTU; | 265 | dev->mtu = GPRS_DEFAULT_MTU; |
264 | net->hard_header_len = 0; | 266 | dev->hard_header_len = 0; |
265 | net->addr_len = 0; | 267 | dev->addr_len = 0; |
266 | net->tx_queue_len = 10; | 268 | dev->tx_queue_len = 10; |
267 | 269 | ||
268 | net->destructor = free_netdev; | 270 | dev->destructor = free_netdev; |
269 | net->open = gprs_open; | 271 | dev->open = gprs_open; |
270 | net->stop = gprs_close; | 272 | dev->stop = gprs_close; |
271 | net->hard_start_xmit = gprs_xmit; /* mandatory */ | 273 | dev->hard_start_xmit = gprs_xmit; /* mandatory */ |
272 | net->change_mtu = gprs_set_mtu; | 274 | dev->change_mtu = gprs_set_mtu; |
273 | } | 275 | } |
274 | 276 | ||
275 | /* | 277 | /* |
@@ -283,28 +285,28 @@ static void gprs_setup(struct net_device *net) | |||
283 | int gprs_attach(struct sock *sk) | 285 | int gprs_attach(struct sock *sk) |
284 | { | 286 | { |
285 | static const char ifname[] = "gprs%d"; | 287 | static const char ifname[] = "gprs%d"; |
286 | struct gprs_dev *dev; | 288 | struct gprs_dev *gp; |
287 | struct net_device *net; | 289 | struct net_device *dev; |
288 | int err; | 290 | int err; |
289 | 291 | ||
290 | if (unlikely(sk->sk_type == SOCK_STREAM)) | 292 | if (unlikely(sk->sk_type == SOCK_STREAM)) |
291 | return -EINVAL; /* need packet boundaries */ | 293 | return -EINVAL; /* need packet boundaries */ |
292 | 294 | ||
293 | /* Create net device */ | 295 | /* Create net device */ |
294 | net = alloc_netdev(sizeof(*dev), ifname, gprs_setup); | 296 | dev = alloc_netdev(sizeof(*gp), ifname, gprs_setup); |
295 | if (!net) | 297 | if (!dev) |
296 | return -ENOMEM; | 298 | return -ENOMEM; |
297 | dev = netdev_priv(net); | 299 | gp = netdev_priv(dev); |
298 | dev->net = net; | 300 | gp->dev = dev; |
299 | dev->tx_max = 0; | 301 | gp->tx_max = 0; |
300 | spin_lock_init(&dev->tx_lock); | 302 | spin_lock_init(&gp->tx_lock); |
301 | skb_queue_head_init(&dev->tx_queue); | 303 | skb_queue_head_init(&gp->tx_queue); |
302 | INIT_WORK(&dev->tx_work, gprs_tx); | 304 | INIT_WORK(&gp->tx_work, gprs_tx); |
303 | 305 | ||
304 | netif_stop_queue(net); | 306 | netif_stop_queue(dev); |
305 | err = register_netdev(net); | 307 | err = register_netdev(dev); |
306 | if (err) { | 308 | if (err) { |
307 | free_netdev(net); | 309 | free_netdev(dev); |
308 | return err; | 310 | return err; |
309 | } | 311 | } |
310 | 312 | ||
@@ -318,40 +320,40 @@ int gprs_attach(struct sock *sk) | |||
318 | err = -EINVAL; | 320 | err = -EINVAL; |
319 | goto out_rel; | 321 | goto out_rel; |
320 | } | 322 | } |
321 | sk->sk_user_data = dev; | 323 | sk->sk_user_data = gp; |
322 | dev->old_state_change = sk->sk_state_change; | 324 | gp->old_state_change = sk->sk_state_change; |
323 | dev->old_data_ready = sk->sk_data_ready; | 325 | gp->old_data_ready = sk->sk_data_ready; |
324 | dev->old_write_space = sk->sk_write_space; | 326 | gp->old_write_space = sk->sk_write_space; |
325 | sk->sk_state_change = gprs_state_change; | 327 | sk->sk_state_change = gprs_state_change; |
326 | sk->sk_data_ready = gprs_data_ready; | 328 | sk->sk_data_ready = gprs_data_ready; |
327 | sk->sk_write_space = gprs_write_space; | 329 | sk->sk_write_space = gprs_write_space; |
328 | release_sock(sk); | 330 | release_sock(sk); |
329 | 331 | ||
330 | sock_hold(sk); | 332 | sock_hold(sk); |
331 | dev->sk = sk; | 333 | gp->sk = sk; |
332 | 334 | ||
333 | printk(KERN_DEBUG"%s: attached\n", net->name); | 335 | printk(KERN_DEBUG"%s: attached\n", dev->name); |
334 | return net->ifindex; | 336 | return dev->ifindex; |
335 | 337 | ||
336 | out_rel: | 338 | out_rel: |
337 | release_sock(sk); | 339 | release_sock(sk); |
338 | unregister_netdev(net); | 340 | unregister_netdev(dev); |
339 | return err; | 341 | return err; |
340 | } | 342 | } |
341 | 343 | ||
342 | void gprs_detach(struct sock *sk) | 344 | void gprs_detach(struct sock *sk) |
343 | { | 345 | { |
344 | struct gprs_dev *dev = sk->sk_user_data; | 346 | struct gprs_dev *gp = sk->sk_user_data; |
345 | struct net_device *net = dev->net; | 347 | struct net_device *dev = gp->dev; |
346 | 348 | ||
347 | lock_sock(sk); | 349 | lock_sock(sk); |
348 | sk->sk_user_data = NULL; | 350 | sk->sk_user_data = NULL; |
349 | sk->sk_state_change = dev->old_state_change; | 351 | sk->sk_state_change = gp->old_state_change; |
350 | sk->sk_data_ready = dev->old_data_ready; | 352 | sk->sk_data_ready = gp->old_data_ready; |
351 | sk->sk_write_space = dev->old_write_space; | 353 | sk->sk_write_space = gp->old_write_space; |
352 | release_sock(sk); | 354 | release_sock(sk); |
353 | 355 | ||
354 | printk(KERN_DEBUG"%s: detached\n", net->name); | 356 | printk(KERN_DEBUG"%s: detached\n", dev->name); |
355 | unregister_netdev(net); | 357 | unregister_netdev(dev); |
356 | sock_put(sk); | 358 | sock_put(sk); |
357 | } | 359 | } |