diff options
author | Stephen Hemminger <shemminger@linux-foundation.org> | 2007-10-09 04:40:57 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:52:52 -0400 |
commit | 3b04ddde02cf1b6f14f2697da5c20eca5715017f (patch) | |
tree | 9da1341a5a399a507b5ea6bf5a3047506b8d8f8f /drivers/net/plip.c | |
parent | b95cce3576813ac3f86bafa6b5daaaaf7574b0fe (diff) |
[NET]: Move hardware header operations out of netdevice.
Since hardware header operations are part of the protocol class
not the device instance, make them into a separate object and
save memory.
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/plip.c')
-rw-r--r-- | drivers/net/plip.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/drivers/net/plip.c b/drivers/net/plip.c index c17d9ac9ff30..b5e9981d1060 100644 --- a/drivers/net/plip.c +++ b/drivers/net/plip.c | |||
@@ -148,9 +148,9 @@ static void plip_interrupt(int irq, void *dev_id); | |||
148 | /* Functions for DEV methods */ | 148 | /* Functions for DEV methods */ |
149 | static int plip_tx_packet(struct sk_buff *skb, struct net_device *dev); | 149 | static int plip_tx_packet(struct sk_buff *skb, struct net_device *dev); |
150 | static int plip_hard_header(struct sk_buff *skb, struct net_device *dev, | 150 | static int plip_hard_header(struct sk_buff *skb, struct net_device *dev, |
151 | unsigned short type, void *daddr, | 151 | unsigned short type, const void *daddr, |
152 | void *saddr, unsigned len); | 152 | const void *saddr, unsigned len); |
153 | static int plip_hard_header_cache(struct neighbour *neigh, | 153 | static int plip_hard_header_cache(const struct neighbour *neigh, |
154 | struct hh_cache *hh); | 154 | struct hh_cache *hh); |
155 | static int plip_open(struct net_device *dev); | 155 | static int plip_open(struct net_device *dev); |
156 | static int plip_close(struct net_device *dev); | 156 | static int plip_close(struct net_device *dev); |
@@ -219,11 +219,6 @@ struct net_local { | |||
219 | int is_deferred; | 219 | int is_deferred; |
220 | int port_owner; | 220 | int port_owner; |
221 | int should_relinquish; | 221 | int should_relinquish; |
222 | int (*orig_hard_header)(struct sk_buff *skb, struct net_device *dev, | ||
223 | unsigned short type, void *daddr, | ||
224 | void *saddr, unsigned len); | ||
225 | int (*orig_hard_header_cache)(struct neighbour *neigh, | ||
226 | struct hh_cache *hh); | ||
227 | spinlock_t lock; | 222 | spinlock_t lock; |
228 | atomic_t kill_timer; | 223 | atomic_t kill_timer; |
229 | struct semaphore killed_timer_sem; | 224 | struct semaphore killed_timer_sem; |
@@ -265,6 +260,11 @@ static inline unsigned char read_status (struct net_device *dev) | |||
265 | return port->ops->read_status (port); | 260 | return port->ops->read_status (port); |
266 | } | 261 | } |
267 | 262 | ||
263 | static const struct header_ops plip_header_ops = { | ||
264 | .create = plip_hard_header, | ||
265 | .cache = plip_hard_header_cache, | ||
266 | }; | ||
267 | |||
268 | /* Entry point of PLIP driver. | 268 | /* Entry point of PLIP driver. |
269 | Probe the hardware, and register/initialize the driver. | 269 | Probe the hardware, and register/initialize the driver. |
270 | 270 | ||
@@ -284,17 +284,12 @@ plip_init_netdev(struct net_device *dev) | |||
284 | dev->open = plip_open; | 284 | dev->open = plip_open; |
285 | dev->stop = plip_close; | 285 | dev->stop = plip_close; |
286 | dev->do_ioctl = plip_ioctl; | 286 | dev->do_ioctl = plip_ioctl; |
287 | dev->header_cache_update = NULL; | 287 | |
288 | dev->tx_queue_len = 10; | 288 | dev->tx_queue_len = 10; |
289 | dev->flags = IFF_POINTOPOINT|IFF_NOARP; | 289 | dev->flags = IFF_POINTOPOINT|IFF_NOARP; |
290 | memset(dev->dev_addr, 0xfc, ETH_ALEN); | 290 | memset(dev->dev_addr, 0xfc, ETH_ALEN); |
291 | 291 | ||
292 | /* Set the private structure */ | 292 | dev->header_ops = &plip_header_ops; |
293 | nl->orig_hard_header = dev->hard_header; | ||
294 | dev->hard_header = plip_hard_header; | ||
295 | |||
296 | nl->orig_hard_header_cache = dev->hard_header_cache; | ||
297 | dev->hard_header_cache = plip_hard_header_cache; | ||
298 | 293 | ||
299 | 294 | ||
300 | nl->port_owner = 0; | 295 | nl->port_owner = 0; |
@@ -993,14 +988,14 @@ plip_tx_packet(struct sk_buff *skb, struct net_device *dev) | |||
993 | } | 988 | } |
994 | 989 | ||
995 | static void | 990 | static void |
996 | plip_rewrite_address(struct net_device *dev, struct ethhdr *eth) | 991 | plip_rewrite_address(const struct net_device *dev, struct ethhdr *eth) |
997 | { | 992 | { |
998 | struct in_device *in_dev; | 993 | const struct in_device *in_dev = dev->ip_ptr; |
999 | 994 | ||
1000 | if ((in_dev=dev->ip_ptr) != NULL) { | 995 | if (in_dev) { |
1001 | /* Any address will do - we take the first */ | 996 | /* Any address will do - we take the first */ |
1002 | struct in_ifaddr *ifa=in_dev->ifa_list; | 997 | const struct in_ifaddr *ifa = in_dev->ifa_list; |
1003 | if (ifa != NULL) { | 998 | if (ifa) { |
1004 | memcpy(eth->h_source, dev->dev_addr, 6); | 999 | memcpy(eth->h_source, dev->dev_addr, 6); |
1005 | memset(eth->h_dest, 0xfc, 2); | 1000 | memset(eth->h_dest, 0xfc, 2); |
1006 | memcpy(eth->h_dest+2, &ifa->ifa_address, 4); | 1001 | memcpy(eth->h_dest+2, &ifa->ifa_address, 4); |
@@ -1010,26 +1005,25 @@ plip_rewrite_address(struct net_device *dev, struct ethhdr *eth) | |||
1010 | 1005 | ||
1011 | static int | 1006 | static int |
1012 | plip_hard_header(struct sk_buff *skb, struct net_device *dev, | 1007 | plip_hard_header(struct sk_buff *skb, struct net_device *dev, |
1013 | unsigned short type, void *daddr, | 1008 | unsigned short type, const void *daddr, |
1014 | void *saddr, unsigned len) | 1009 | const void *saddr, unsigned len) |
1015 | { | 1010 | { |
1016 | struct net_local *nl = netdev_priv(dev); | ||
1017 | int ret; | 1011 | int ret; |
1018 | 1012 | ||
1019 | if ((ret = nl->orig_hard_header(skb, dev, type, daddr, saddr, len)) >= 0) | 1013 | ret = eth_header(skb, dev, type, daddr, saddr, len); |
1014 | if (ret >= 0) | ||
1020 | plip_rewrite_address (dev, (struct ethhdr *)skb->data); | 1015 | plip_rewrite_address (dev, (struct ethhdr *)skb->data); |
1021 | 1016 | ||
1022 | return ret; | 1017 | return ret; |
1023 | } | 1018 | } |
1024 | 1019 | ||
1025 | int plip_hard_header_cache(struct neighbour *neigh, | 1020 | int plip_hard_header_cache(const struct neighbour *neigh, |
1026 | struct hh_cache *hh) | 1021 | struct hh_cache *hh) |
1027 | { | 1022 | { |
1028 | struct net_local *nl = neigh->dev->priv; | ||
1029 | int ret; | 1023 | int ret; |
1030 | 1024 | ||
1031 | if ((ret = nl->orig_hard_header_cache(neigh, hh)) == 0) | 1025 | ret = eth_header_cache(neigh, hh); |
1032 | { | 1026 | if (ret == 0) { |
1033 | struct ethhdr *eth; | 1027 | struct ethhdr *eth; |
1034 | 1028 | ||
1035 | eth = (struct ethhdr*)(((u8*)hh->hh_data) + | 1029 | eth = (struct ethhdr*)(((u8*)hh->hh_data) + |