]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/irda/irlan/irlan_eth.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[net-next-2.6.git] / net / irda / irlan / irlan_eth.c
CommitLineData
1da177e4 1/*********************************************************************
6819bc2e 2 *
1da177e4 3 * Filename: irlan_eth.c
6819bc2e
YH
4 * Version:
5 * Description:
1da177e4
LT
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Thu Oct 15 08:37:58 1998
9 * Modified at: Tue Mar 21 09:06:41 2000
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 * Sources: skeleton.c by Donald Becker <becker@CESDIS.gsfc.nasa.gov>
12 * slip.c by Laurence Culhane, <loz@holmes.demon.co.uk>
13 * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
6819bc2e 14 *
1da177e4 15 * Copyright (c) 1998-2000 Dag Brattli, All Rights Reserved.
6819bc2e
YH
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
1da177e4 20 * the License, or (at your option) any later version.
6819bc2e 21 *
96de0e25 22 * Neither Dag Brattli nor University of Tromsø admit liability nor
6819bc2e 23 * provide warranty for any of this software. This material is
1da177e4 24 * provided "AS-IS" and at no charge.
6819bc2e 25 *
1da177e4
LT
26 ********************************************************************/
27
1da177e4
LT
28#include <linux/netdevice.h>
29#include <linux/etherdevice.h>
30#include <linux/inetdevice.h>
31#include <linux/if_arp.h>
32#include <linux/module.h>
d43c36dc 33#include <linux/sched.h>
1da177e4
LT
34#include <net/arp.h>
35
36#include <net/irda/irda.h>
37#include <net/irda/irmod.h>
38#include <net/irda/irlan_common.h>
39#include <net/irda/irlan_client.h>
40#include <net/irda/irlan_event.h>
41#include <net/irda/irlan_eth.h>
42
43static int irlan_eth_open(struct net_device *dev);
44static int irlan_eth_close(struct net_device *dev);
6518bbb8
SH
45static netdev_tx_t irlan_eth_xmit(struct sk_buff *skb,
46 struct net_device *dev);
1da177e4
LT
47static void irlan_eth_set_multicast_list( struct net_device *dev);
48static struct net_device_stats *irlan_eth_get_stats(struct net_device *dev);
49
9cc8ba78
SH
50static const struct net_device_ops irlan_eth_netdev_ops = {
51 .ndo_open = irlan_eth_open,
52 .ndo_stop = irlan_eth_close,
53 .ndo_start_xmit = irlan_eth_xmit,
54 .ndo_get_stats = irlan_eth_get_stats,
55 .ndo_set_multicast_list = irlan_eth_set_multicast_list,
56 .ndo_change_mtu = eth_change_mtu,
57 .ndo_validate_addr = eth_validate_addr,
58};
59
1da177e4
LT
60/*
61 * Function irlan_eth_setup (dev)
62 *
63 * The network device initialization function.
64 *
65 */
66static void irlan_eth_setup(struct net_device *dev)
67{
9cc8ba78
SH
68 ether_setup(dev);
69
70 dev->netdev_ops = &irlan_eth_netdev_ops;
1da177e4
LT
71 dev->destructor = free_netdev;
72
6819bc2e
YH
73
74 /*
1da177e4
LT
75 * Lets do all queueing in IrTTP instead of this device driver.
76 * Queueing here as well can introduce some strange latency
77 * problems, which we will avoid by setting the queue size to 0.
78 */
79 /*
80 * The bugs in IrTTP and IrLAN that created this latency issue
81 * have now been fixed, and we can propagate flow control properly
82 * to the network layer. However, this requires a minimal queue of
83 * packets for the device.
84 * Without flow control, the Tx Queue is 14 (ttp) + 0 (dev) = 14
85 * With flow control, the Tx Queue is 7 (ttp) + 4 (dev) = 11
86 * See irlan_eth_flow_indication()...
87 * Note : this number was randomly selected and would need to
88 * be adjusted.
89 * Jean II */
90 dev->tx_queue_len = 4;
91}
92
93/*
94 * Function alloc_irlandev
95 *
96 * Allocate network device and control block
97 *
98 */
99struct net_device *alloc_irlandev(const char *name)
100{
101 return alloc_netdev(sizeof(struct irlan_cb), name,
102 irlan_eth_setup);
103}
104
105/*
106 * Function irlan_eth_open (dev)
107 *
108 * Network device has been opened by user
109 *
110 */
111static int irlan_eth_open(struct net_device *dev)
112{
113 struct irlan_cb *self = netdev_priv(dev);
6819bc2e 114
0dc47877 115 IRDA_DEBUG(2, "%s()\n", __func__ );
1da177e4
LT
116
117 /* Ready to play! */
6819bc2e 118 netif_stop_queue(dev); /* Wait until data link is ready */
1da177e4
LT
119
120 /* We are now open, so time to do some work */
121 self->disconnect_reason = 0;
122 irlan_client_wakeup(self, self->saddr, self->daddr);
123
6819bc2e 124 /* Make sure we have a hardware address before we return,
1da177e4
LT
125 so DHCP clients gets happy */
126 return wait_event_interruptible(self->open_wait,
127 !self->tsap_data->connected);
128}
129
130/*
131 * Function irlan_eth_close (dev)
132 *
133 * Stop the ether network device, his function will usually be called by
6819bc2e 134 * ifconfig down. We should now disconnect the link, We start the
1da177e4
LT
135 * close timer, so that the instance will be removed if we are unable
136 * to discover the remote device after the disconnect.
137 */
138static int irlan_eth_close(struct net_device *dev)
139{
140 struct irlan_cb *self = netdev_priv(dev);
6819bc2e 141
0dc47877 142 IRDA_DEBUG(2, "%s()\n", __func__ );
6819bc2e 143
1da177e4
LT
144 /* Stop device */
145 netif_stop_queue(dev);
6819bc2e 146
1da177e4
LT
147 irlan_close_data_channel(self);
148 irlan_close_tsaps(self);
149
150 irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL);
6819bc2e
YH
151 irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL);
152
1da177e4
LT
153 /* Remove frames queued on the control channel */
154 skb_queue_purge(&self->client.txq);
155
156 self->client.tx_busy = 0;
6819bc2e 157
1da177e4
LT
158 return 0;
159}
160
161/*
162 * Function irlan_eth_tx (skb)
163 *
164 * Transmits ethernet frames over IrDA link.
165 *
166 */
6518bbb8
SH
167static netdev_tx_t irlan_eth_xmit(struct sk_buff *skb,
168 struct net_device *dev)
1da177e4
LT
169{
170 struct irlan_cb *self = netdev_priv(dev);
171 int ret;
79c5f51c 172 unsigned int len;
1da177e4
LT
173
174 /* skb headroom large enough to contain all IrDA-headers? */
175 if ((skb_headroom(skb) < self->max_header_size) || (skb_shared(skb))) {
6819bc2e 176 struct sk_buff *new_skb =
1da177e4
LT
177 skb_realloc_headroom(skb, self->max_header_size);
178
179 /* We have to free the original skb anyway */
180 dev_kfree_skb(skb);
181
182 /* Did the realloc succeed? */
183 if (new_skb == NULL)
6ed10654 184 return NETDEV_TX_OK;
1da177e4
LT
185
186 /* Use the new skb instead */
187 skb = new_skb;
6819bc2e 188 }
1da177e4
LT
189
190 dev->trans_start = jiffies;
191
79c5f51c 192 len = skb->len;
1da177e4
LT
193 /* Now queue the packet in the transport layer */
194 if (self->use_udata)
195 ret = irttp_udata_request(self->tsap_data, skb);
196 else
197 ret = irttp_data_request(self->tsap_data, skb);
198
199 if (ret < 0) {
6819bc2e 200 /*
1da177e4
LT
201 * IrTTPs tx queue is full, so we just have to
202 * drop the frame! You might think that we should
203 * just return -1 and don't deallocate the frame,
204 * but that is dangerous since it's possible that
205 * we have replaced the original skb with a new
206 * one with larger headroom, and that would really
207 * confuse do_dev_queue_xmit() in dev.c! I have
6819bc2e 208 * tried :-) DB
1da177e4
LT
209 */
210 /* irttp_data_request already free the packet */
211 self->stats.tx_dropped++;
212 } else {
213 self->stats.tx_packets++;
79c5f51c 214 self->stats.tx_bytes += len;
1da177e4 215 }
6819bc2e 216
6ed10654 217 return NETDEV_TX_OK;
1da177e4
LT
218}
219
220/*
221 * Function irlan_eth_receive (handle, skb)
222 *
223 * This function gets the data that is received on the data channel
224 *
225 */
226int irlan_eth_receive(void *instance, void *sap, struct sk_buff *skb)
227{
228 struct irlan_cb *self = instance;
229
230 if (skb == NULL) {
6819bc2e 231 ++self->stats.rx_dropped;
1da177e4
LT
232 return 0;
233 }
234 if (skb->len < ETH_HLEN) {
235 IRDA_DEBUG(0, "%s() : IrLAN frame too short (%d)\n",
0dc47877 236 __func__, skb->len);
6819bc2e 237 ++self->stats.rx_dropped;
1da177e4
LT
238 dev_kfree_skb(skb);
239 return 0;
240 }
6819bc2e
YH
241
242 /*
243 * Adopt this frame! Important to set all these fields since they
1da177e4 244 * might have been previously set by the low level IrDA network
6819bc2e 245 * device driver
1da177e4 246 */
4c13eb66 247 skb->protocol = eth_type_trans(skb, self->dev); /* Remove eth header */
6819bc2e 248
1da177e4 249 self->stats.rx_packets++;
6819bc2e 250 self->stats.rx_bytes += skb->len;
1da177e4
LT
251
252 netif_rx(skb); /* Eat it! */
6819bc2e 253
1da177e4
LT
254 return 0;
255}
256
257/*
258 * Function irlan_eth_flow (status)
259 *
6819bc2e 260 * Do flow control between IP/Ethernet and IrLAN/IrTTP. This is done by
1da177e4
LT
261 * controlling the queue stop/start.
262 *
263 * The IrDA link layer has the advantage to have flow control, and
264 * IrTTP now properly handles that. Flow controlling the higher layers
265 * prevent us to drop Tx packets in here (up to 15% for a TCP socket,
266 * more for UDP socket).
267 * Also, this allow us to reduce the overall transmit queue, which means
268 * less latency in case of mixed traffic.
269 * Jean II
270 */
271void irlan_eth_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
272{
273 struct irlan_cb *self;
274 struct net_device *dev;
275
276 self = (struct irlan_cb *) instance;
277
278 IRDA_ASSERT(self != NULL, return;);
279 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
6819bc2e 280
1da177e4
LT
281 dev = self->dev;
282
283 IRDA_ASSERT(dev != NULL, return;);
6819bc2e 284
0dc47877 285 IRDA_DEBUG(0, "%s() : flow %s ; running %d\n", __func__,
1da177e4
LT
286 flow == FLOW_STOP ? "FLOW_STOP" : "FLOW_START",
287 netif_running(dev));
288
289 switch (flow) {
290 case FLOW_STOP:
291 /* IrTTP is full, stop higher layers */
292 netif_stop_queue(dev);
293 break;
294 case FLOW_START:
295 default:
296 /* Tell upper layers that its time to transmit frames again */
297 /* Schedule network layer */
298 netif_wake_queue(dev);
299 break;
300 }
301}
302
1da177e4
LT
303/*
304 * Function set_multicast_list (dev)
305 *
306 * Configure the filtering of the device
307 *
308 */
309#define HW_MAX_ADDRS 4 /* Must query to get it! */
6819bc2e 310static void irlan_eth_set_multicast_list(struct net_device *dev)
1da177e4 311{
6819bc2e 312 struct irlan_cb *self = netdev_priv(dev);
1da177e4 313
0dc47877 314 IRDA_DEBUG(2, "%s()\n", __func__ );
1da177e4
LT
315
316 /* Check if data channel has been connected yet */
317 if (self->client.state != IRLAN_DATA) {
0dc47877 318 IRDA_DEBUG(1, "%s(), delaying!\n", __func__ );
1da177e4
LT
319 return;
320 }
321
322 if (dev->flags & IFF_PROMISC) {
323 /* Enable promiscuous mode */
cc53ded2 324 IRDA_WARNING("Promiscuous mode not implemented by IrLAN!\n");
6819bc2e 325 }
4cd24eaf
JP
326 else if ((dev->flags & IFF_ALLMULTI) ||
327 netdev_mc_count(dev) > HW_MAX_ADDRS) {
1da177e4 328 /* Disable promiscuous mode, use normal mode. */
0dc47877 329 IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__ );
1da177e4
LT
330 /* hardware_set_filter(NULL); */
331
332 irlan_set_multicast_filter(self, TRUE);
333 }
4cd24eaf 334 else if (!netdev_mc_empty(dev)) {
0dc47877 335 IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__ );
1da177e4
LT
336 /* Walk the address list, and load the filter */
337 /* hardware_set_filter(dev->mc_list); */
338
339 irlan_set_multicast_filter(self, TRUE);
340 }
341 else {
0dc47877 342 IRDA_DEBUG(4, "%s(), Clearing multicast filter\n", __func__ );
1da177e4
LT
343 irlan_set_multicast_filter(self, FALSE);
344 }
345
346 if (dev->flags & IFF_BROADCAST)
347 irlan_set_broadcast_filter(self, TRUE);
348 else
349 irlan_set_broadcast_filter(self, FALSE);
350}
351
352/*
353 * Function irlan_get_stats (dev)
354 *
355 * Get the current statistics for this device
356 *
357 */
6819bc2e 358static struct net_device_stats *irlan_eth_get_stats(struct net_device *dev)
1da177e4
LT
359{
360 struct irlan_cb *self = netdev_priv(dev);
361
362 return &self->stats;
363}