2 * An implementation of the Acorn Econet and AUN protocols.
3 * Philip Blundell <philb@gnu.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
12 #include <linux/config.h>
13 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/string.h>
20 #include <linux/socket.h>
21 #include <linux/sockios.h>
23 #include <linux/errno.h>
24 #include <linux/interrupt.h>
25 #include <linux/if_ether.h>
26 #include <linux/netdevice.h>
27 #include <linux/inetdevice.h>
28 #include <linux/route.h>
29 #include <linux/inet.h>
30 #include <linux/etherdevice.h>
31 #include <linux/if_arp.h>
32 #include <linux/wireless.h>
33 #include <linux/skbuff.h>
35 #include <net/inet_common.h>
36 #include <linux/stat.h>
37 #include <linux/init.h>
38 #include <linux/if_ec.h>
41 #include <linux/spinlock.h>
43 #include <asm/uaccess.h>
44 #include <asm/system.h>
45 #include <asm/bitops.h>
47 static struct proto_ops econet_ops;
48 static struct hlist_head econet_sklist;
49 static rwlock_t econet_lock = RW_LOCK_UNLOCKED;
51 /* Since there are only 256 possible network numbers (or fewer, depends
52 how you count) it makes sense to use a simple lookup table. */
53 static struct net_device *net2dev_map[256];
55 #define EC_PORT_IP 0xd2
57 #ifdef CONFIG_ECONET_AUNUDP
58 static spinlock_t aun_queue_lock;
59 static struct socket *udpsock;
60 #define AUN_PORT 0x8000
65 unsigned char code; /* AUN magic protocol byte */
72 static unsigned long aun_seq;
74 /* Queue of packets waiting to be transmitted. */
75 static struct sk_buff_head aun_queue;
76 static struct timer_list ab_cleanup_timer;
78 #endif /* CONFIG_ECONET_AUNUDP */
80 /* Per-packet information */
83 struct sockaddr_ec sec;
84 unsigned long cookie; /* Supplied by user. */
85 #ifdef CONFIG_ECONET_AUNUDP
87 unsigned long seq; /* Sequencing */
88 unsigned long timeout; /* Timeout */
89 unsigned long start; /* jiffies */
91 #ifdef CONFIG_ECONET_NATIVE
92 void (*sent)(struct sk_buff *, int result);
96 static void econet_remove_socket(struct hlist_head *list, struct sock *sk)
98 write_lock_bh(&econet_lock);
100 write_unlock_bh(&econet_lock);
103 static void econet_insert_socket(struct hlist_head *list, struct sock *sk)
105 write_lock_bh(&econet_lock);
106 sk_add_node(sk, list);
107 write_unlock_bh(&econet_lock);
111 * Pull a packet from our receive queue and hand it to the user.
112 * If necessary we block.
115 static int econet_recvmsg(struct kiocb *iocb, struct socket *sock,
116 struct msghdr *msg, size_t len, int flags)
118 struct sock *sk = sock->sk;
123 msg->msg_namelen = sizeof(struct sockaddr_ec);
126 * Call the generic datagram receiver. This handles all sorts
127 * of horrible races and re-entrancy so we can forget about it
128 * in the protocol layers.
130 * Now it will return ENETDOWN, if device have just gone down,
131 * but then it will block.
134 skb=skb_recv_datagram(sk,flags,flags&MSG_DONTWAIT,&err);
137 * An error occurred so return it. Because skb_recv_datagram()
138 * handles the blocking we don't see and worry about blocking
146 * You lose any data beyond the buffer you gave. If it worries a
147 * user program they can ask the device for its MTU anyway.
154 msg->msg_flags|=MSG_TRUNC;
157 /* We can't use skb_copy_datagram here */
158 err = memcpy_toiovec(msg->msg_iov, skb->data, copied);
161 sk->sk_stamp = skb->stamp;
164 memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
167 * Free or return the buffer as appropriate. Again this
168 * hides all the races and re-entrancy issues from us.
173 skb_free_datagram(sk, skb);
179 * Bind an Econet socket.
182 static int econet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
184 struct sockaddr_ec *sec = (struct sockaddr_ec *)uaddr;
185 struct sock *sk=sock->sk;
186 struct econet_opt *eo = ec_sk(sk);
192 if (addr_len < sizeof(struct sockaddr_ec) ||
193 sec->sec_family != AF_ECONET)
197 eo->port = sec->port;
198 eo->station = sec->addr.station;
199 eo->net = sec->addr.net;
204 #if defined(CONFIG_ECONET_AUNUDP) || defined(CONFIG_ECONET_NATIVE)
206 * Queue a transmit result for the user to be told about.
209 static void tx_result(struct sock *sk, unsigned long cookie, int result)
211 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
213 struct sockaddr_ec *sec;
217 printk(KERN_DEBUG "ec: memory squeeze, transmit result dropped.\n");
221 eb = (struct ec_cb *)&skb->cb;
222 sec = (struct sockaddr_ec *)&eb->sec;
223 memset(sec, 0, sizeof(struct sockaddr_ec));
224 sec->cookie = cookie;
225 sec->type = ECTYPE_TRANSMIT_STATUS | result;
226 sec->sec_family = AF_ECONET;
228 if (sock_queue_rcv_skb(sk, skb) < 0)
233 #ifdef CONFIG_ECONET_NATIVE
235 * Called by the Econet hardware driver when a packet transmit
236 * has completed. Tell the user.
239 static void ec_tx_done(struct sk_buff *skb, int result)
241 struct ec_cb *eb = (struct ec_cb *)&skb->cb;
242 tx_result(skb->sk, eb->cookie, result);
247 * Send a packet. We have to work out which device it's going out on
248 * and hence whether to use real Econet or the UDP emulation.
251 static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
252 struct msghdr *msg, size_t len)
254 struct sock *sk = sock->sk;
255 struct sockaddr_ec *saddr=(struct sockaddr_ec *)msg->msg_name;
256 struct net_device *dev;
259 unsigned char port, cb;
260 #if defined(CONFIG_ECONET_AUNUDP) || defined(CONFIG_ECONET_NATIVE)
264 #ifdef CONFIG_ECONET_AUNUDP
265 struct msghdr udpmsg;
266 struct iovec iov[msg->msg_iovlen+1];
268 struct sockaddr_in udpdest;
269 __kernel_size_t size;
278 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
282 * Get and verify the address.
286 struct econet_opt *eo = ec_sk(sk);
288 addr.station = eo->station;
293 if (msg->msg_namelen < sizeof(struct sockaddr_ec))
295 addr.station = saddr->addr.station;
296 addr.net = saddr->addr.net;
301 /* Look for a device with the right network number. */
302 dev = net2dev_map[addr.net];
304 /* If not directly reachable, use some default */
307 dev = net2dev_map[0];
308 /* No interfaces at all? */
313 if (len + 15 > dev->mtu)
316 if (dev->type == ARPHRD_ECONET)
318 /* Real hardware Econet. We're not worthy etc. */
319 #ifdef CONFIG_ECONET_NATIVE
320 unsigned short proto = 0;
324 skb = sock_alloc_send_skb(sk, len+LL_RESERVED_SPACE(dev),
325 msg->msg_flags & MSG_DONTWAIT, &err);
329 skb_reserve(skb, LL_RESERVED_SPACE(dev));
330 skb->nh.raw = skb->data;
332 eb = (struct ec_cb *)&skb->cb;
334 /* BUG: saddr may be NULL */
335 eb->cookie = saddr->cookie;
337 eb->sent = ec_tx_done;
339 if (dev->hard_header) {
341 struct ec_framehdr *fh;
343 res = dev->hard_header(skb, dev, ntohs(proto),
345 /* Poke in our control byte and
346 port number. Hack, hack. */
347 fh = (struct ec_framehdr *)(skb->data);
350 if (sock->type != SOCK_DGRAM) {
351 skb->tail = skb->data;
357 /* Copy the data. Returns -EFAULT on error */
358 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
359 skb->protocol = proto;
361 skb->priority = sk->sk_priority;
366 if (!(dev->flags & IFF_UP))
388 #ifdef CONFIG_ECONET_AUNUDP
389 /* AUN virtual Econet. */
392 return -ENETDOWN; /* No socket - can't send */
394 /* Make up a UDP datagram and hand it off to some higher intellect. */
396 memset(&udpdest, 0, sizeof(udpdest));
397 udpdest.sin_family = AF_INET;
398 udpdest.sin_port = htons(AUN_PORT);
400 /* At the moment we use the stupid Acorn scheme of Econet address
401 y.x maps to IP a.b.c.x. This should be replaced with something
402 more flexible and more aware of subnet masks. */
404 struct in_device *idev = in_dev_get(dev);
405 unsigned long network = 0;
407 read_lock(&idev->lock);
409 network = ntohl(idev->ifa_list->ifa_address) &
410 0xffffff00; /* !!! */
411 read_unlock(&idev->lock);
414 udpdest.sin_addr.s_addr = htonl(network | addr.station);
419 ah.code = 2; /* magic */
422 /* tack our header on the front of the iovec */
423 size = sizeof(struct aunhdr);
425 * XXX: that is b0rken. We can't mix userland and kernel pointers
426 * in iovec, since on a lot of platforms copy_from_user() will
427 * *not* work with the kernel and userland ones at the same time,
428 * regardless of what we do with set_fs(). And we are talking about
429 * econet-over-ethernet here, so "it's only ARM anyway" doesn't
430 * apply. Any suggestions on fixing that code? -- AV
432 iov[0].iov_base = (void *)&ah;
433 iov[0].iov_len = size;
434 for (i = 0; i < msg->msg_iovlen; i++) {
435 void __user *base = msg->msg_iov[i].iov_base;
436 size_t len = msg->msg_iov[i].iov_len;
437 /* Check it now since we switch to KERNEL_DS later. */
438 if ((err = verify_area(VERIFY_READ, base, len)) < 0)
440 iov[i+1].iov_base = base;
441 iov[i+1].iov_len = len;
445 /* Get a skbuff (no data, just holds our cb information) */
446 if ((skb = sock_alloc_send_skb(sk, 0,
447 msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
450 eb = (struct ec_cb *)&skb->cb;
452 eb->cookie = saddr->cookie;
453 eb->timeout = (5*HZ);
456 eb->seq = (aun_seq++);
459 skb_queue_tail(&aun_queue, skb);
461 udpmsg.msg_name = (void *)&udpdest;
462 udpmsg.msg_namelen = sizeof(udpdest);
463 udpmsg.msg_iov = &iov[0];
464 udpmsg.msg_iovlen = msg->msg_iovlen + 1;
465 udpmsg.msg_control = NULL;
466 udpmsg.msg_controllen = 0;
469 oldfs = get_fs(); set_fs(KERNEL_DS); /* More privs :-) */
470 err = sock_sendmsg(udpsock, &udpmsg, size);
479 * Look up the address of a socket.
482 static int econet_getname(struct socket *sock, struct sockaddr *uaddr,
483 int *uaddr_len, int peer)
485 struct sock *sk = sock->sk;
486 struct econet_opt *eo = ec_sk(sk);
487 struct sockaddr_ec *sec = (struct sockaddr_ec *)uaddr;
492 sec->sec_family = AF_ECONET;
493 sec->port = eo->port;
494 sec->addr.station = eo->station;
495 sec->addr.net = eo->net;
497 *uaddr_len = sizeof(*sec);
501 static void econet_destroy_timer(unsigned long data)
503 struct sock *sk=(struct sock *)data;
505 if (!atomic_read(&sk->sk_wmem_alloc) &&
506 !atomic_read(&sk->sk_rmem_alloc)) {
511 sk->sk_timer.expires = jiffies + 10 * HZ;
512 add_timer(&sk->sk_timer);
513 printk(KERN_DEBUG "econet socket destroy delayed\n");
517 * Close an econet socket.
520 static int econet_release(struct socket *sock)
522 struct sock *sk = sock->sk;
527 econet_remove_socket(&econet_sklist, sk);
530 * Now the socket is dead. No more input will appear.
533 sk->sk_state_change(sk); /* It is useless. Just for sanity. */
536 sk->sk_socket = NULL;
537 sock_set_flag(sk, SOCK_DEAD);
541 skb_queue_purge(&sk->sk_receive_queue);
543 if (atomic_read(&sk->sk_rmem_alloc) ||
544 atomic_read(&sk->sk_wmem_alloc)) {
545 sk->sk_timer.data = (unsigned long)sk;
546 sk->sk_timer.expires = jiffies + HZ;
547 sk->sk_timer.function = econet_destroy_timer;
548 add_timer(&sk->sk_timer);
557 * Create an Econet socket
560 static int econet_create(struct socket *sock, int protocol)
563 struct econet_opt *eo;
566 /* Econet only provides datagram services. */
567 if (sock->type != SOCK_DGRAM)
568 return -ESOCKTNOSUPPORT;
570 sock->state = SS_UNCONNECTED;
573 sk = sk_alloc(PF_ECONET, GFP_KERNEL, 1, NULL);
578 sock->ops = &econet_ops;
579 sock_init_data(sock,sk);
580 sk_set_owner(sk, THIS_MODULE);
582 eo = sk->sk_protinfo = kmalloc(sizeof(*eo), GFP_KERNEL);
585 memset(eo, 0, sizeof(*eo));
587 sk->sk_family = PF_ECONET;
590 econet_insert_socket(&econet_sklist, sk);
600 * Handle Econet specific ioctls
603 static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg)
606 struct ec_device *edev;
607 struct net_device *dev;
608 struct sockaddr_ec *sec;
611 * Fetch the caller's info block into kernel space
614 if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
617 if ((dev = dev_get_by_name(ifr.ifr_name)) == NULL)
620 sec = (struct sockaddr_ec *)&ifr.ifr_addr;
628 /* Magic up a new one. */
629 edev = kmalloc(sizeof(struct ec_device), GFP_KERNEL);
631 printk("af_ec: memory squeeze.\n");
635 memset(edev, 0, sizeof(struct ec_device));
639 net2dev_map[edev->net] = NULL;
640 edev->station = sec->addr.station;
641 edev->net = sec->addr.net;
642 net2dev_map[sec->addr.net] = dev;
644 net2dev_map[0] = dev;
655 memset(sec, 0, sizeof(struct sockaddr_ec));
656 sec->addr.station = edev->station;
657 sec->addr.net = edev->net;
658 sec->sec_family = AF_ECONET;
660 if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
670 * Handle generic ioctls
673 static int econet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
675 struct sock *sk = sock->sk;
676 void __user *argp = (void __user *)arg;
680 return sock_get_timestamp(sk, argp);
684 return ec_dev_ioctl(sock, cmd, argp);
688 return dev_ioctl(cmd, argp);
694 static struct net_proto_family econet_family_ops = {
696 .create = econet_create,
697 .owner = THIS_MODULE,
700 static struct proto_ops SOCKOPS_WRAPPED(econet_ops) = {
702 .owner = THIS_MODULE,
703 .release = econet_release,
705 .connect = sock_no_connect,
706 .socketpair = sock_no_socketpair,
707 .accept = sock_no_accept,
708 .getname = econet_getname,
709 .poll = datagram_poll,
710 .ioctl = econet_ioctl,
711 .listen = sock_no_listen,
712 .shutdown = sock_no_shutdown,
713 .setsockopt = sock_no_setsockopt,
714 .getsockopt = sock_no_getsockopt,
715 .sendmsg = econet_sendmsg,
716 .recvmsg = econet_recvmsg,
717 .mmap = sock_no_mmap,
718 .sendpage = sock_no_sendpage,
721 #include <linux/smp_lock.h>
722 SOCKOPS_WRAP(econet, PF_ECONET);
724 #if defined(CONFIG_ECONET_AUNUDP) || defined(CONFIG_ECONET_NATIVE)
726 * Find the listening socket, if any, for the given data.
729 static struct sock *ec_listening_socket(unsigned char port, unsigned char
730 station, unsigned char net)
733 struct hlist_node *node;
735 sk_for_each(sk, node, &econet_sklist) {
736 struct econet_opt *opt = ec_sk(sk);
737 if ((opt->port == port || opt->port == 0) &&
738 (opt->station == station || opt->station == 0) &&
739 (opt->net == net || opt->net == 0))
748 * Queue a received packet for a socket.
751 static int ec_queue_packet(struct sock *sk, struct sk_buff *skb,
752 unsigned char stn, unsigned char net,
753 unsigned char cb, unsigned char port)
755 struct ec_cb *eb = (struct ec_cb *)&skb->cb;
756 struct sockaddr_ec *sec = (struct sockaddr_ec *)&eb->sec;
758 memset(sec, 0, sizeof(struct sockaddr_ec));
759 sec->sec_family = AF_ECONET;
760 sec->type = ECTYPE_PACKET_RECEIVED;
764 sec->addr.station = stn;
766 return sock_queue_rcv_skb(sk, skb);
770 #ifdef CONFIG_ECONET_AUNUDP
772 * Send an AUN protocol response.
775 static void aun_send_response(__u32 addr, unsigned long seq, int code, int cb)
777 struct sockaddr_in sin = {
778 .sin_family = AF_INET,
779 .sin_port = htons(AUN_PORT),
780 .sin_addr = {.s_addr = addr}
782 struct aunhdr ah = {.code = code, .cb = cb, .handle = seq};
783 struct kvec iov = {.iov_base = (void *)&ah, .iov_len = sizeof(ah)};
784 struct msghdr udpmsg;
786 udpmsg.msg_name = (void *)&sin;
787 udpmsg.msg_namelen = sizeof(sin);
788 udpmsg.msg_control = NULL;
789 udpmsg.msg_controllen = 0;
792 kernel_sendmsg(udpsock, &udpmsg, &iov, 1, sizeof(ah));
797 * Handle incoming AUN packets. Work out if anybody wants them,
798 * and send positive or negative acknowledgements as appropriate.
801 static void aun_incoming(struct sk_buff *skb, struct aunhdr *ah, size_t len)
803 struct iphdr *ip = skb->nh.iph;
804 unsigned char stn = ntohl(ip->saddr) & 0xff;
806 struct sk_buff *newskb;
807 struct ec_device *edev = skb->dev->ec_ptr;
812 if ((sk = ec_listening_socket(ah->port, stn, edev->net)) == NULL)
813 goto bad; /* Nobody wants it */
815 newskb = alloc_skb((len - sizeof(struct aunhdr) + 15) & ~15,
819 printk(KERN_DEBUG "AUN: memory squeeze, dropping packet.\n");
820 /* Send nack and hope sender tries again */
824 memcpy(skb_put(newskb, len - sizeof(struct aunhdr)), (void *)(ah+1),
825 len - sizeof(struct aunhdr));
827 if (ec_queue_packet(sk, newskb, stn, edev->net, ah->cb, ah->port))
829 /* Socket is bankrupt. */
834 aun_send_response(ip->saddr, ah->handle, 3, 0);
838 aun_send_response(ip->saddr, ah->handle, 4, 0);
842 * Handle incoming AUN transmit acknowledgements. If the sequence
843 * number matches something in our backlog then kill it and tell
844 * the user. If the remote took too long to reply then we may have
845 * dropped the packet already.
848 static void aun_tx_ack(unsigned long seq, int result)
854 spin_lock_irqsave(&aun_queue_lock, flags);
855 skb = skb_peek(&aun_queue);
856 while (skb && skb != (struct sk_buff *)&aun_queue)
858 struct sk_buff *newskb = skb->next;
859 eb = (struct ec_cb *)&skb->cb;
865 spin_unlock_irqrestore(&aun_queue_lock, flags);
866 printk(KERN_DEBUG "AUN: unknown sequence %ld\n", seq);
870 tx_result(skb->sk, eb->cookie, result);
872 spin_unlock_irqrestore(&aun_queue_lock, flags);
877 * Deal with received AUN frames - sort out what type of thing it is
878 * and hand it to the right function.
881 static void aun_data_available(struct sock *sk, int slen)
890 while ((skb = skb_recv_datagram(sk, 0, 1, &err)) == NULL) {
891 if (err == -EAGAIN) {
892 printk(KERN_ERR "AUN: no data available?!");
895 printk(KERN_DEBUG "AUN: recvfrom() error %d\n", -err);
898 data = skb->h.raw + sizeof(struct udphdr);
899 ah = (struct aunhdr *)data;
900 len = skb->len - sizeof(struct udphdr);
906 aun_incoming(skb, ah, len);
909 aun_tx_ack(ah->handle, ECTYPE_TRANSMIT_OK);
912 aun_tx_ack(ah->handle, ECTYPE_TRANSMIT_NOT_LISTENING);
915 /* This isn't quite right yet. */
917 aun_send_response(ip->saddr, ah->handle, 6, ah->cb);
921 printk(KERN_DEBUG "unknown AUN packet (type %d)\n", data[0]);
924 skb_free_datagram(sk, skb);
928 * Called by the timer to manage the AUN transmit queue. If a packet
929 * was sent to a dead or nonexistent host then we will never get an
930 * acknowledgement back. After a few seconds we need to spot this and
934 static void ab_cleanup(unsigned long h)
939 spin_lock_irqsave(&aun_queue_lock, flags);
940 skb = skb_peek(&aun_queue);
941 while (skb && skb != (struct sk_buff *)&aun_queue)
943 struct sk_buff *newskb = skb->next;
944 struct ec_cb *eb = (struct ec_cb *)&skb->cb;
945 if ((jiffies - eb->start) > eb->timeout)
947 tx_result(skb->sk, eb->cookie,
948 ECTYPE_TRANSMIT_NOT_PRESENT);
954 spin_unlock_irqrestore(&aun_queue_lock, flags);
956 mod_timer(&ab_cleanup_timer, jiffies + (HZ*2));
959 static int __init aun_udp_initialise(void)
962 struct sockaddr_in sin;
964 skb_queue_head_init(&aun_queue);
965 spin_lock_init(&aun_queue_lock);
966 init_timer(&ab_cleanup_timer);
967 ab_cleanup_timer.expires = jiffies + (HZ*2);
968 ab_cleanup_timer.function = ab_cleanup;
969 add_timer(&ab_cleanup_timer);
971 memset(&sin, 0, sizeof(sin));
972 sin.sin_port = htons(AUN_PORT);
974 /* We can count ourselves lucky Acorn machines are too dim to
976 if ((error = sock_create_kern(PF_INET, SOCK_DGRAM, 0, &udpsock)) < 0)
978 printk("AUN: socket error %d\n", -error);
982 udpsock->sk->sk_reuse = 1;
983 udpsock->sk->sk_allocation = GFP_ATOMIC; /* we're going to call it
986 error = udpsock->ops->bind(udpsock, (struct sockaddr *)&sin,
990 printk("AUN: bind error %d\n", -error);
994 udpsock->sk->sk_data_ready = aun_data_available;
999 sock_release(udpsock);
1005 #ifdef CONFIG_ECONET_NATIVE
1008 * Receive an Econet frame from a device.
1011 static int econet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
1013 struct ec_framehdr *hdr;
1015 struct ec_device *edev = dev->ec_ptr;
1017 if (skb->pkt_type == PACKET_OTHERHOST)
1023 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
1026 if (!pskb_may_pull(skb, sizeof(struct ec_framehdr)))
1029 hdr = (struct ec_framehdr *) skb->data;
1031 /* First check for encapsulated IP */
1032 if (hdr->port == EC_PORT_IP) {
1033 skb->protocol = htons(ETH_P_IP);
1034 skb_pull(skb, sizeof(struct ec_framehdr));
1039 sk = ec_listening_socket(hdr->port, hdr->src_stn, hdr->src_net);
1043 if (ec_queue_packet(sk, skb, edev->net, hdr->src_stn, hdr->cb,
1054 static struct packet_type econet_packet_type = {
1055 .type = __constant_htons(ETH_P_ECONET),
1059 static void econet_hw_initialise(void)
1061 dev_add_pack(&econet_packet_type);
1066 static int econet_notifier(struct notifier_block *this, unsigned long msg, void *data)
1068 struct net_device *dev = (struct net_device *)data;
1069 struct ec_device *edev;
1072 case NETDEV_UNREGISTER:
1073 /* A device has gone down - kill any data we hold for it. */
1077 if (net2dev_map[0] == dev)
1078 net2dev_map[0] = NULL;
1079 net2dev_map[edev->net] = NULL;
1089 static struct notifier_block econet_netdev_notifier = {
1090 .notifier_call =econet_notifier,
1093 static void __exit econet_proto_exit(void)
1095 #ifdef CONFIG_ECONET_AUNUDP
1096 del_timer(&ab_cleanup_timer);
1098 sock_release(udpsock);
1100 unregister_netdevice_notifier(&econet_netdev_notifier);
1101 sock_unregister(econet_family_ops.family);
1104 static int __init econet_proto_init(void)
1106 sock_register(&econet_family_ops);
1107 #ifdef CONFIG_ECONET_AUNUDP
1108 spin_lock_init(&aun_queue_lock);
1109 aun_udp_initialise();
1111 #ifdef CONFIG_ECONET_NATIVE
1112 econet_hw_initialise();
1114 register_netdevice_notifier(&econet_netdev_notifier);
1118 module_init(econet_proto_init);
1119 module_exit(econet_proto_exit);
1121 MODULE_LICENSE("GPL");
1122 MODULE_ALIAS_NETPROTO(PF_ECONET);