Import 2.3.15pre2
[davej-history.git] / drivers / ap1000 / bif.c
blob331ee0f26b9636579464c03cf520f4e19b815412
1 /*
2 * Copyright 1996 The Australian National University.
3 * Copyright 1996 Fujitsu Laboratories Limited
4 *
5 * This software may be distributed under the terms of the Gnu
6 * Public License version 2 or later
7 */
8 /*
9 * $Id: bif.c,v 1.13 1996/12/18 01:45:52 tridge Exp $
11 * Network interface definitions for bif device.
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/interrupt.h>
17 #include <linux/fs.h>
18 #include <linux/types.h>
19 #include <linux/string.h>
20 #include <linux/socket.h>
21 #include <linux/errno.h>
22 #include <linux/fcntl.h>
23 #include <linux/in.h>
24 #include <linux/if_ether.h> /* For the statistics structure. */
25 #include <linux/netdevice.h>
26 #include <linux/if_arp.h> /* For ARPHRD_BIF */
28 #include <asm/system.h>
29 #include <asm/segment.h>
30 #include <asm/io.h>
32 #include <linux/inet.h>
33 #include <linux/etherdevice.h>
34 #include <linux/skbuff.h>
35 #include <net/sock.h>
37 #include <asm/ap1000/apservice.h>
38 #include <asm/ap1000/apreg.h>
40 #define BIF_DEBUG 0
41 #if BIF_DEBUG
42 static int seq = 0;
43 #endif
45 #define BIF_MTU 10240
47 static struct net_device *bif_device = 0;
48 static struct net_device_stats *bif_stats = 0;
50 int bif_init(struct net_device *dev);
51 int bif_open(struct net_device *dev);
52 static int bif_xmit(struct sk_buff *skb, struct net_device *dev);
53 int bif_rx(struct sk_buff *skb);
54 int bif_stop(struct net_device *dev);
55 static struct net_device_stats *bif_get_stats(struct net_device *dev);
57 static int bif_hard_header(struct sk_buff *skb, struct net_device *dev,
58 unsigned short type, void *daddr,
59 void *saddr, unsigned len)
61 #if BIF_DEBUG
62 printk("bif_hard_header()\n");
63 #endif
65 skb_push(skb,dev->hard_header_len);
67 if (daddr) skb->arp = 1;
69 /* tell IP how much space we took */
70 return (dev->hard_header_len);
73 static int bif_rebuild_header(void *buff, struct net_device *dev,
74 unsigned long raddr, struct sk_buff *skb)
76 /* this would normally be used to fill in hardware addresses after
77 an ARP */
78 #if BIF_DEBUG
79 printk("bif_rebuild_header()\n");
80 #endif
81 if (skb) skb->arp = 1;
82 return(0);
85 static int bif_set_mac_address(struct net_device *dev, void *addr)
87 printk("BIF: set_mac_address called\n");
88 return (0);
91 static void bif_set_multicast_list(struct net_device *dev)
93 return;
96 static int bif_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
98 printk("BIF: Called do_ioctl\n");
99 return (0);
102 static int bif_set_config(struct net_device *dev, struct ifmap *map)
104 printk("BIF: Called bif_set_config\n");
105 return (0);
109 * Initialise bif network interface.
111 int bif_init(struct net_device *dev)
113 int i;
115 printk("bif_init(): Initialising bif interface\n");
116 bif_device = dev;
118 dev->mtu = BIF_MTU;
119 dev->tbusy = 0;
120 dev->hard_start_xmit = bif_xmit;
121 dev->hard_header = bif_hard_header;
122 dev->hard_header_len = sizeof(struct cap_request);
123 dev->addr_len = 0;
124 dev->tx_queue_len = 50000; /* no limit (almost!) */
125 dev->type = ARPHRD_BIF;
126 dev->rebuild_header = bif_rebuild_header;
127 dev->open = bif_open;
128 dev->flags = IFF_NOARP; /* Don't use ARP on this device */
129 dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
130 if (dev->priv == NULL)
131 return -ENOMEM;
132 memset(dev->priv, 0, sizeof(struct net_device_stats));
133 bif_stats = (struct net_device_stats *)bif_device->priv;
136 dev->stop = bif_stop;
137 dev->get_stats = bif_get_stats;
139 dev->set_mac_address = bif_set_mac_address;
140 dev->header_cache_update = NULL;
141 dev->do_ioctl = bif_do_ioctl;
142 dev->set_config = bif_set_config;
143 dev->set_multicast_list = bif_set_multicast_list;
145 memset(dev->broadcast, 0xFF, ETH_ALEN);
147 dev_init_buffers(dev);
149 return(0);
152 int bif_open(struct net_device *dev)
154 printk("In bif_open\n");
155 dev->tbusy = 0;
156 dev->start = 1;
157 return 0;
160 #if BIF_DEBUG
161 static void dump_packet(char *action, char *buf, int len, int seq)
163 int flags;
164 char *sep;
166 printk("%s packet %d of %d bytes at %d:\n", action, seq,
167 len, (int)jiffies);
168 printk(" from %x to %x pktid=%d ttl=%d pcol=%d len=%d\n",
169 *(long *)(buf+12), *(long *)(buf+16), *(u_short *)(buf+4),
170 *(unsigned char *)(buf+8), buf[9], *(u_short *)(buf+2));
171 if( buf[9] == 6 || buf[9] == 17 ){
172 /* TCP or UDP */
173 printk(" sport=%d dport=%d",
174 *(u_short *)(buf+20), *(u_short *)(buf+22));
175 if( buf[9] == 6 ){
176 printk(" seq=%d ack=%d win=%d flags=<",
177 *(long *)(buf+24), *(long *)(buf+28),
178 *(unsigned short *)(buf+34));
179 flags = buf[33];
180 sep = "";
181 printk(">");
183 printk("\n");
185 else {
186 printk(" protocol = %d\n", buf[9]);
189 #endif
192 static int bif_xmit(struct sk_buff *skb, struct net_device *dev)
194 extern int bif_send_ip(int cid,struct sk_buff *skb);
195 extern int tnet_send_ip(int cid,struct sk_buff *skb);
196 extern int msc_blocked, tnet_ip_enabled;
197 u_long destip;
198 int cid;
200 if (skb == NULL || dev == NULL)
201 return(0);
203 destip = *(u_long *)(skb->data+sizeof(struct cap_request)+16);
204 cid = ap_ip_to_cid(destip);
206 skb->dev = dev;
207 skb->mac.raw = skb->data;
209 if (cid != -1 && tnet_ip_enabled && !msc_blocked) {
210 tnet_send_ip(cid,skb);
211 } else {
212 bif_send_ip(cid, skb);
215 dev->tbusy = 0;
217 bif_stats->tx_packets++;
219 mark_bh(NET_BH);
221 return 0;
226 * Receive a packet from the BIF - called from interrupt handler.
228 int bif_rx(struct sk_buff *skb)
230 #if BIF_DEBUG
231 dump_packet("bif_rx:", skb->data, skb->len, seq++);
232 #endif
234 if (bif_device == NULL) {
235 printk("bif: bif_device is NULL in bif_rx\n");
236 dev_kfree_skb(skb);
237 return 0;
239 skb->dev = bif_device;
240 skb->protocol = ETH_P_IP;
242 #if 1
243 /* try disabling checksums on receive */
244 if (ap_ip_to_cid(*(u_long *)(((char *)skb->data)+12)) != -1)
245 skb->ip_summed = CHECKSUM_UNNECESSARY;
246 #endif
249 * Inform the network layer of the new packet.
251 skb->mac.raw = skb->data;
252 netif_rx(skb);
254 if (bif_stats == NULL) {
255 printk("bif: bif_stats is NULL is bif_rx\n");
256 return 0;
258 bif_stats->rx_packets++;
260 return 0;
263 int bif_stop(struct net_device *dev)
265 printk("in bif_close\n");
267 dev->tbusy = 1;
268 dev->start = 0;
270 return 0;
274 * Return statistics of bif driver.
276 static struct net_device_stats *bif_get_stats(struct net_device *dev)
278 return((struct net_device_stats *)dev->priv);