1 /*********************************************************************
3 * Filename: irlan_eth.c
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>
15 * Copyright (c) 1998-2000 Dag Brattli, All Rights Reserved.
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
20 * the License, or (at your option) any later version.
22 * Neither Dag Brattli nor University of Tromsø admit liability nor
23 * provide warranty for any of this software. This material is
24 * provided "AS-IS" and at no charge.
26 ********************************************************************/
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>
33 #include <linux/sched.h>
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>
43 static int irlan_eth_open(struct net_device
*dev
);
44 static int irlan_eth_close(struct net_device
*dev
);
45 static netdev_tx_t
irlan_eth_xmit(struct sk_buff
*skb
,
46 struct net_device
*dev
);
47 static void irlan_eth_set_multicast_list(struct net_device
*dev
);
49 static const struct net_device_ops irlan_eth_netdev_ops
= {
50 .ndo_open
= irlan_eth_open
,
51 .ndo_stop
= irlan_eth_close
,
52 .ndo_start_xmit
= irlan_eth_xmit
,
53 .ndo_set_rx_mode
= irlan_eth_set_multicast_list
,
54 .ndo_change_mtu
= eth_change_mtu
,
55 .ndo_validate_addr
= eth_validate_addr
,
59 * Function irlan_eth_setup (dev)
61 * The network device initialization function.
64 static void irlan_eth_setup(struct net_device
*dev
)
68 dev
->netdev_ops
= &irlan_eth_netdev_ops
;
69 dev
->destructor
= free_netdev
;
73 * Lets do all queueing in IrTTP instead of this device driver.
74 * Queueing here as well can introduce some strange latency
75 * problems, which we will avoid by setting the queue size to 0.
78 * The bugs in IrTTP and IrLAN that created this latency issue
79 * have now been fixed, and we can propagate flow control properly
80 * to the network layer. However, this requires a minimal queue of
81 * packets for the device.
82 * Without flow control, the Tx Queue is 14 (ttp) + 0 (dev) = 14
83 * With flow control, the Tx Queue is 7 (ttp) + 4 (dev) = 11
84 * See irlan_eth_flow_indication()...
85 * Note : this number was randomly selected and would need to
88 dev
->tx_queue_len
= 4;
92 * Function alloc_irlandev
94 * Allocate network device and control block
97 struct net_device
*alloc_irlandev(const char *name
)
99 return alloc_netdev(sizeof(struct irlan_cb
), name
, NET_NAME_UNKNOWN
,
104 * Function irlan_eth_open (dev)
106 * Network device has been opened by user
109 static int irlan_eth_open(struct net_device
*dev
)
111 struct irlan_cb
*self
= netdev_priv(dev
);
114 netif_stop_queue(dev
); /* Wait until data link is ready */
116 /* We are now open, so time to do some work */
117 self
->disconnect_reason
= 0;
118 irlan_client_wakeup(self
, self
->saddr
, self
->daddr
);
120 /* Make sure we have a hardware address before we return,
121 so DHCP clients gets happy */
122 return wait_event_interruptible(self
->open_wait
,
123 !self
->tsap_data
->connected
);
127 * Function irlan_eth_close (dev)
129 * Stop the ether network device, his function will usually be called by
130 * ifconfig down. We should now disconnect the link, We start the
131 * close timer, so that the instance will be removed if we are unable
132 * to discover the remote device after the disconnect.
134 static int irlan_eth_close(struct net_device
*dev
)
136 struct irlan_cb
*self
= netdev_priv(dev
);
139 netif_stop_queue(dev
);
141 irlan_close_data_channel(self
);
142 irlan_close_tsaps(self
);
144 irlan_do_client_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
145 irlan_do_provider_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
147 /* Remove frames queued on the control channel */
148 skb_queue_purge(&self
->client
.txq
);
150 self
->client
.tx_busy
= 0;
156 * Function irlan_eth_tx (skb)
158 * Transmits ethernet frames over IrDA link.
161 static netdev_tx_t
irlan_eth_xmit(struct sk_buff
*skb
,
162 struct net_device
*dev
)
164 struct irlan_cb
*self
= netdev_priv(dev
);
168 /* skb headroom large enough to contain all IrDA-headers? */
169 if ((skb_headroom(skb
) < self
->max_header_size
) || (skb_shared(skb
))) {
170 struct sk_buff
*new_skb
=
171 skb_realloc_headroom(skb
, self
->max_header_size
);
173 /* We have to free the original skb anyway */
176 /* Did the realloc succeed? */
180 /* Use the new skb instead */
184 dev
->trans_start
= jiffies
;
187 /* Now queue the packet in the transport layer */
189 ret
= irttp_udata_request(self
->tsap_data
, skb
);
191 ret
= irttp_data_request(self
->tsap_data
, skb
);
195 * IrTTPs tx queue is full, so we just have to
196 * drop the frame! You might think that we should
197 * just return -1 and don't deallocate the frame,
198 * but that is dangerous since it's possible that
199 * we have replaced the original skb with a new
200 * one with larger headroom, and that would really
201 * confuse do_dev_queue_xmit() in dev.c! I have
204 /* irttp_data_request already free the packet */
205 dev
->stats
.tx_dropped
++;
207 dev
->stats
.tx_packets
++;
208 dev
->stats
.tx_bytes
+= len
;
215 * Function irlan_eth_receive (handle, skb)
217 * This function gets the data that is received on the data channel
220 int irlan_eth_receive(void *instance
, void *sap
, struct sk_buff
*skb
)
222 struct irlan_cb
*self
= instance
;
223 struct net_device
*dev
= self
->dev
;
226 dev
->stats
.rx_dropped
++;
229 if (skb
->len
< ETH_HLEN
) {
230 pr_debug("%s() : IrLAN frame too short (%d)\n",
232 dev
->stats
.rx_dropped
++;
238 * Adopt this frame! Important to set all these fields since they
239 * might have been previously set by the low level IrDA network
242 skb
->protocol
= eth_type_trans(skb
, dev
); /* Remove eth header */
244 dev
->stats
.rx_packets
++;
245 dev
->stats
.rx_bytes
+= skb
->len
;
247 netif_rx(skb
); /* Eat it! */
253 * Function irlan_eth_flow (status)
255 * Do flow control between IP/Ethernet and IrLAN/IrTTP. This is done by
256 * controlling the queue stop/start.
258 * The IrDA link layer has the advantage to have flow control, and
259 * IrTTP now properly handles that. Flow controlling the higher layers
260 * prevent us to drop Tx packets in here (up to 15% for a TCP socket,
261 * more for UDP socket).
262 * Also, this allow us to reduce the overall transmit queue, which means
263 * less latency in case of mixed traffic.
266 void irlan_eth_flow_indication(void *instance
, void *sap
, LOCAL_FLOW flow
)
268 struct irlan_cb
*self
;
269 struct net_device
*dev
;
273 IRDA_ASSERT(self
!= NULL
, return;);
274 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
278 IRDA_ASSERT(dev
!= NULL
, return;);
280 pr_debug("%s() : flow %s ; running %d\n", __func__
,
281 flow
== FLOW_STOP
? "FLOW_STOP" : "FLOW_START",
286 /* IrTTP is full, stop higher layers */
287 netif_stop_queue(dev
);
291 /* Tell upper layers that its time to transmit frames again */
292 /* Schedule network layer */
293 netif_wake_queue(dev
);
299 * Function set_multicast_list (dev)
301 * Configure the filtering of the device
304 #define HW_MAX_ADDRS 4 /* Must query to get it! */
305 static void irlan_eth_set_multicast_list(struct net_device
*dev
)
307 struct irlan_cb
*self
= netdev_priv(dev
);
309 /* Check if data channel has been connected yet */
310 if (self
->client
.state
!= IRLAN_DATA
) {
311 pr_debug("%s(), delaying!\n", __func__
);
315 if (dev
->flags
& IFF_PROMISC
) {
316 /* Enable promiscuous mode */
317 net_warn_ratelimited("Promiscuous mode not implemented by IrLAN!\n");
318 } else if ((dev
->flags
& IFF_ALLMULTI
) ||
319 netdev_mc_count(dev
) > HW_MAX_ADDRS
) {
320 /* Disable promiscuous mode, use normal mode. */
321 pr_debug("%s(), Setting multicast filter\n", __func__
);
322 /* hardware_set_filter(NULL); */
324 irlan_set_multicast_filter(self
, TRUE
);
325 } else if (!netdev_mc_empty(dev
)) {
326 pr_debug("%s(), Setting multicast filter\n", __func__
);
327 /* Walk the address list, and load the filter */
328 /* hardware_set_filter(dev->mc_list); */
330 irlan_set_multicast_filter(self
, TRUE
);
332 pr_debug("%s(), Clearing multicast filter\n", __func__
);
333 irlan_set_multicast_filter(self
, FALSE
);
336 if (dev
->flags
& IFF_BROADCAST
)
337 irlan_set_broadcast_filter(self
, TRUE
);
339 irlan_set_broadcast_filter(self
, FALSE
);