Merge branch 'davem-next' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6] / net / bridge / br_device.c
1 /*
2  *      Device handling code
3  *      Linux ethernet bridge
4  *
5  *      Authors:
6  *      Lennert Buytenhek               <buytenh@gnu.org>
7  *
8  *      This program is free software; you can redistribute it and/or
9  *      modify it under the terms of the GNU General Public License
10  *      as published by the Free Software Foundation; either version
11  *      2 of the License, or (at your option) any later version.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/ethtool.h>
18
19 #include <asm/uaccess.h>
20 #include "br_private.h"
21
22 /* net device transmit always called with no BH (preempt_disabled) */
23 int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
24 {
25         struct net_bridge *br = netdev_priv(dev);
26         const unsigned char *dest = skb->data;
27         struct net_bridge_fdb_entry *dst;
28
29         dev->stats.tx_packets++;
30         dev->stats.tx_bytes += skb->len;
31
32         skb_reset_mac_header(skb);
33         skb_pull(skb, ETH_HLEN);
34
35         if (dest[0] & 1)
36                 br_flood_deliver(br, skb);
37         else if ((dst = __br_fdb_get(br, dest)) != NULL)
38                 br_deliver(dst->dst, skb);
39         else
40                 br_flood_deliver(br, skb);
41
42         return 0;
43 }
44
45 static int br_dev_open(struct net_device *dev)
46 {
47         struct net_bridge *br = netdev_priv(dev);
48
49         br_features_recompute(br);
50         netif_start_queue(dev);
51         br_stp_enable_bridge(br);
52
53         return 0;
54 }
55
56 static void br_dev_set_multicast_list(struct net_device *dev)
57 {
58 }
59
60 static int br_dev_stop(struct net_device *dev)
61 {
62         br_stp_disable_bridge(netdev_priv(dev));
63
64         netif_stop_queue(dev);
65
66         return 0;
67 }
68
69 static int br_change_mtu(struct net_device *dev, int new_mtu)
70 {
71         if (new_mtu < 68 || new_mtu > br_min_mtu(netdev_priv(dev)))
72                 return -EINVAL;
73
74         dev->mtu = new_mtu;
75         return 0;
76 }
77
78 /* Allow setting mac address to any valid ethernet address. */
79 static int br_set_mac_address(struct net_device *dev, void *p)
80 {
81         struct net_bridge *br = netdev_priv(dev);
82         struct sockaddr *addr = p;
83
84         if (!is_valid_ether_addr(addr->sa_data))
85                 return -EINVAL;
86
87         spin_lock_bh(&br->lock);
88         memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
89         br_stp_change_bridge_id(br, addr->sa_data);
90         spin_unlock_bh(&br->lock);
91
92         return 0;
93 }
94
95 static void br_getinfo(struct net_device *dev, struct ethtool_drvinfo *info)
96 {
97         strcpy(info->driver, "bridge");
98         strcpy(info->version, BR_VERSION);
99         strcpy(info->fw_version, "N/A");
100         strcpy(info->bus_info, "N/A");
101 }
102
103 static int br_set_sg(struct net_device *dev, u32 data)
104 {
105         struct net_bridge *br = netdev_priv(dev);
106
107         if (data)
108                 br->feature_mask |= NETIF_F_SG;
109         else
110                 br->feature_mask &= ~NETIF_F_SG;
111
112         br_features_recompute(br);
113         return 0;
114 }
115
116 static int br_set_tso(struct net_device *dev, u32 data)
117 {
118         struct net_bridge *br = netdev_priv(dev);
119
120         if (data)
121                 br->feature_mask |= NETIF_F_TSO;
122         else
123                 br->feature_mask &= ~NETIF_F_TSO;
124
125         br_features_recompute(br);
126         return 0;
127 }
128
129 static int br_set_tx_csum(struct net_device *dev, u32 data)
130 {
131         struct net_bridge *br = netdev_priv(dev);
132
133         if (data)
134                 br->feature_mask |= NETIF_F_NO_CSUM;
135         else
136                 br->feature_mask &= ~NETIF_F_ALL_CSUM;
137
138         br_features_recompute(br);
139         return 0;
140 }
141
142 static struct ethtool_ops br_ethtool_ops = {
143         .get_drvinfo = br_getinfo,
144         .get_link = ethtool_op_get_link,
145         .set_sg = br_set_sg,
146         .set_tx_csum = br_set_tx_csum,
147         .set_tso = br_set_tso,
148 };
149
150 void br_dev_setup(struct net_device *dev)
151 {
152         random_ether_addr(dev->dev_addr);
153         ether_setup(dev);
154
155         dev->do_ioctl = br_dev_ioctl;
156         dev->hard_start_xmit = br_dev_xmit;
157         dev->open = br_dev_open;
158         dev->set_multicast_list = br_dev_set_multicast_list;
159         dev->change_mtu = br_change_mtu;
160         dev->destructor = free_netdev;
161         SET_ETHTOOL_OPS(dev, &br_ethtool_ops);
162         dev->stop = br_dev_stop;
163         dev->tx_queue_len = 0;
164         dev->set_mac_address = br_set_mac_address;
165         dev->priv_flags = IFF_EBRIDGE;
166
167         dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
168                         NETIF_F_GSO_MASK | NETIF_F_NO_CSUM | NETIF_F_LLTX;
169 }