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>
34 #include <linux/udp.h>
36 #include <net/inet_common.h>
37 #include <linux/stat.h>
38 #include <linux/init.h>
39 #include <linux/if_ec.h>
42 #include <linux/spinlock.h>
43 #include <linux/rcupdate.h>
44 #include <linux/bitops.h>
46 #include <asm/uaccess.h>
47 #include <asm/system.h>
49 static const struct proto_ops econet_ops;
50 static struct hlist_head econet_sklist;
51 static DEFINE_RWLOCK(econet_lock);
53 /* Since there are only 256 possible network numbers (or fewer, depends
54 how you count) it makes sense to use a simple lookup table. */
55 static struct net_device *net2dev_map[256];
57 #define EC_PORT_IP 0xd2
59 #ifdef CONFIG_ECONET_AUNUDP
60 static DEFINE_SPINLOCK(aun_queue_lock);
61 static struct socket *udpsock;
62 #define AUN_PORT 0x8000
67 unsigned char code; /* AUN magic protocol byte */
74 static unsigned long aun_seq;
76 /* Queue of packets waiting to be transmitted. */
77 static struct sk_buff_head aun_queue;
78 static struct timer_list ab_cleanup_timer;
80 #endif /* CONFIG_ECONET_AUNUDP */
82 /* Per-packet information */
85 struct sockaddr_ec sec;
86 unsigned long cookie; /* Supplied by user. */
87 #ifdef CONFIG_ECONET_AUNUDP
89 unsigned long seq; /* Sequencing */
90 unsigned long timeout; /* Timeout */
91 unsigned long start; /* jiffies */
93 #ifdef CONFIG_ECONET_NATIVE
94 void (*sent)(struct sk_buff *, int result);
98 static void econet_remove_socket(struct hlist_head *list, struct sock *sk)
100 write_lock_bh(&econet_lock);
101 sk_del_node_init(sk);
102 write_unlock_bh(&econet_lock);
105 static void econet_insert_socket(struct hlist_head *list, struct sock *sk)
107 write_lock_bh(&econet_lock);
108 sk_add_node(sk, list);
109 write_unlock_bh(&econet_lock);
113 * Pull a packet from our receive queue and hand it to the user.
114 * If necessary we block.
117 static int econet_recvmsg(struct kiocb *iocb, struct socket *sock,
118 struct msghdr *msg, size_t len, int flags)
120 struct sock *sk = sock->sk;
125 msg->msg_namelen = sizeof(struct sockaddr_ec);
128 * Call the generic datagram receiver. This handles all sorts
129 * of horrible races and re-entrancy so we can forget about it
130 * in the protocol layers.
132 * Now it will return ENETDOWN, if device have just gone down,
133 * but then it will block.
136 skb=skb_recv_datagram(sk,flags,flags&MSG_DONTWAIT,&err);
139 * An error occurred so return it. Because skb_recv_datagram()
140 * handles the blocking we don't see and worry about blocking
148 * You lose any data beyond the buffer you gave. If it worries a
149 * user program they can ask the device for its MTU anyway.
156 msg->msg_flags|=MSG_TRUNC;
159 /* We can't use skb_copy_datagram here */
160 err = memcpy_toiovec(msg->msg_iov, skb->data, copied);
163 skb_get_timestamp(skb, &sk->sk_stamp);
166 memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
169 * Free or return the buffer as appropriate. Again this
170 * hides all the races and re-entrancy issues from us.
175 skb_free_datagram(sk, skb);
181 * Bind an Econet socket.
184 static int econet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
186 struct sockaddr_ec *sec = (struct sockaddr_ec *)uaddr;
187 struct sock *sk=sock->sk;
188 struct econet_sock *eo = ec_sk(sk);
194 if (addr_len < sizeof(struct sockaddr_ec) ||
195 sec->sec_family != AF_ECONET)
199 eo->port = sec->port;
200 eo->station = sec->addr.station;
201 eo->net = sec->addr.net;
206 #if defined(CONFIG_ECONET_AUNUDP) || defined(CONFIG_ECONET_NATIVE)
208 * Queue a transmit result for the user to be told about.
211 static void tx_result(struct sock *sk, unsigned long cookie, int result)
213 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
215 struct sockaddr_ec *sec;
219 printk(KERN_DEBUG "ec: memory squeeze, transmit result dropped.\n");
223 eb = (struct ec_cb *)&skb->cb;
224 sec = (struct sockaddr_ec *)&eb->sec;
225 memset(sec, 0, sizeof(struct sockaddr_ec));
226 sec->cookie = cookie;
227 sec->type = ECTYPE_TRANSMIT_STATUS | result;
228 sec->sec_family = AF_ECONET;
230 if (sock_queue_rcv_skb(sk, skb) < 0)
235 #ifdef CONFIG_ECONET_NATIVE
237 * Called by the Econet hardware driver when a packet transmit
238 * has completed. Tell the user.
241 static void ec_tx_done(struct sk_buff *skb, int result)
243 struct ec_cb *eb = (struct ec_cb *)&skb->cb;
244 tx_result(skb->sk, eb->cookie, result);
249 * Send a packet. We have to work out which device it's going out on
250 * and hence whether to use real Econet or the UDP emulation.
253 static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
254 struct msghdr *msg, size_t len)
256 struct sock *sk = sock->sk;
257 struct sockaddr_ec *saddr=(struct sockaddr_ec *)msg->msg_name;
258 struct net_device *dev;
261 unsigned char port, cb;
262 #if defined(CONFIG_ECONET_AUNUDP) || defined(CONFIG_ECONET_NATIVE)
266 #ifdef CONFIG_ECONET_AUNUDP
267 struct msghdr udpmsg;
268 struct iovec iov[msg->msg_iovlen+1];
270 struct sockaddr_in udpdest;
271 __kernel_size_t size;
280 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
284 * Get and verify the address.
288 struct econet_sock *eo = ec_sk(sk);
290 addr.station = eo->station;
295 if (msg->msg_namelen < sizeof(struct sockaddr_ec))
297 addr.station = saddr->addr.station;
298 addr.net = saddr->addr.net;
303 /* Look for a device with the right network number. */
304 dev = net2dev_map[addr.net];
306 /* If not directly reachable, use some default */
309 dev = net2dev_map[0];
310 /* No interfaces at all? */
315 if (len + 15 > dev->mtu)
318 if (dev->type == ARPHRD_ECONET)
320 /* Real hardware Econet. We're not worthy etc. */
321 #ifdef CONFIG_ECONET_NATIVE
322 unsigned short proto = 0;
326 skb = sock_alloc_send_skb(sk, len+LL_RESERVED_SPACE(dev),
327 msg->msg_flags & MSG_DONTWAIT, &err);
331 skb_reserve(skb, LL_RESERVED_SPACE(dev));
332 skb->nh.raw = skb->data;
334 eb = (struct ec_cb *)&skb->cb;
336 /* BUG: saddr may be NULL */
337 eb->cookie = saddr->cookie;
339 eb->sent = ec_tx_done;
341 if (dev->hard_header) {
343 struct ec_framehdr *fh;
345 res = dev->hard_header(skb, dev, ntohs(proto),
347 /* Poke in our control byte and
348 port number. Hack, hack. */
349 fh = (struct ec_framehdr *)(skb->data);
352 if (sock->type != SOCK_DGRAM) {
353 skb->tail = skb->data;
359 /* Copy the data. Returns -EFAULT on error */
360 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
361 skb->protocol = proto;
363 skb->priority = sk->sk_priority;
368 if (!(dev->flags & IFF_UP))
390 #ifdef CONFIG_ECONET_AUNUDP
391 /* AUN virtual Econet. */
394 return -ENETDOWN; /* No socket - can't send */
396 /* Make up a UDP datagram and hand it off to some higher intellect. */
398 memset(&udpdest, 0, sizeof(udpdest));
399 udpdest.sin_family = AF_INET;
400 udpdest.sin_port = htons(AUN_PORT);
402 /* At the moment we use the stupid Acorn scheme of Econet address
403 y.x maps to IP a.b.c.x. This should be replaced with something
404 more flexible and more aware of subnet masks. */
406 struct in_device *idev;
407 unsigned long network = 0;
410 idev = __in_dev_get_rcu(dev);
413 network = ntohl(idev->ifa_list->ifa_address) &
414 0xffffff00; /* !!! */
417 udpdest.sin_addr.s_addr = htonl(network | addr.station);
422 ah.code = 2; /* magic */
425 /* tack our header on the front of the iovec */
426 size = sizeof(struct aunhdr);
428 * XXX: that is b0rken. We can't mix userland and kernel pointers
429 * in iovec, since on a lot of platforms copy_from_user() will
430 * *not* work with the kernel and userland ones at the same time,
431 * regardless of what we do with set_fs(). And we are talking about
432 * econet-over-ethernet here, so "it's only ARM anyway" doesn't
433 * apply. Any suggestions on fixing that code? -- AV
435 iov[0].iov_base = (void *)&ah;
436 iov[0].iov_len = size;
437 for (i = 0; i < msg->msg_iovlen; i++) {
438 void __user *base = msg->msg_iov[i].iov_base;
439 size_t len = msg->msg_iov[i].iov_len;
440 /* Check it now since we switch to KERNEL_DS later. */
441 if (!access_ok(VERIFY_READ, base, len))
443 iov[i+1].iov_base = base;
444 iov[i+1].iov_len = len;
448 /* Get a skbuff (no data, just holds our cb information) */
449 if ((skb = sock_alloc_send_skb(sk, 0,
450 msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
453 eb = (struct ec_cb *)&skb->cb;
455 eb->cookie = saddr->cookie;
456 eb->timeout = (5*HZ);
459 eb->seq = (aun_seq++);
462 skb_queue_tail(&aun_queue, skb);
464 udpmsg.msg_name = (void *)&udpdest;
465 udpmsg.msg_namelen = sizeof(udpdest);
466 udpmsg.msg_iov = &iov[0];
467 udpmsg.msg_iovlen = msg->msg_iovlen + 1;
468 udpmsg.msg_control = NULL;
469 udpmsg.msg_controllen = 0;
472 oldfs = get_fs(); set_fs(KERNEL_DS); /* More privs :-) */
473 err = sock_sendmsg(udpsock, &udpmsg, size);
482 * Look up the address of a socket.
485 static int econet_getname(struct socket *sock, struct sockaddr *uaddr,
486 int *uaddr_len, int peer)
488 struct sock *sk = sock->sk;
489 struct econet_sock *eo = ec_sk(sk);
490 struct sockaddr_ec *sec = (struct sockaddr_ec *)uaddr;
495 sec->sec_family = AF_ECONET;
496 sec->port = eo->port;
497 sec->addr.station = eo->station;
498 sec->addr.net = eo->net;
500 *uaddr_len = sizeof(*sec);
504 static void econet_destroy_timer(unsigned long data)
506 struct sock *sk=(struct sock *)data;
508 if (!atomic_read(&sk->sk_wmem_alloc) &&
509 !atomic_read(&sk->sk_rmem_alloc)) {
514 sk->sk_timer.expires = jiffies + 10 * HZ;
515 add_timer(&sk->sk_timer);
516 printk(KERN_DEBUG "econet socket destroy delayed\n");
520 * Close an econet socket.
523 static int econet_release(struct socket *sock)
525 struct sock *sk = sock->sk;
530 econet_remove_socket(&econet_sklist, sk);
533 * Now the socket is dead. No more input will appear.
536 sk->sk_state_change(sk); /* It is useless. Just for sanity. */
539 sk->sk_socket = NULL;
540 sock_set_flag(sk, SOCK_DEAD);
544 skb_queue_purge(&sk->sk_receive_queue);
546 if (atomic_read(&sk->sk_rmem_alloc) ||
547 atomic_read(&sk->sk_wmem_alloc)) {
548 sk->sk_timer.data = (unsigned long)sk;
549 sk->sk_timer.expires = jiffies + HZ;
550 sk->sk_timer.function = econet_destroy_timer;
551 add_timer(&sk->sk_timer);
559 static struct proto econet_proto = {
561 .owner = THIS_MODULE,
562 .obj_size = sizeof(struct econet_sock),
566 * Create an Econet socket
569 static int econet_create(struct socket *sock, int protocol)
572 struct econet_sock *eo;
575 /* Econet only provides datagram services. */
576 if (sock->type != SOCK_DGRAM)
577 return -ESOCKTNOSUPPORT;
579 sock->state = SS_UNCONNECTED;
582 sk = sk_alloc(PF_ECONET, GFP_KERNEL, &econet_proto, 1);
587 sock->ops = &econet_ops;
588 sock_init_data(sock, sk);
591 sock_reset_flag(sk, SOCK_ZAPPED);
592 sk->sk_family = PF_ECONET;
595 econet_insert_socket(&econet_sklist, sk);
602 * Handle Econet specific ioctls
605 static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg)
608 struct ec_device *edev;
609 struct net_device *dev;
610 struct sockaddr_ec *sec;
613 * Fetch the caller's info block into kernel space
616 if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
619 if ((dev = dev_get_by_name(ifr.ifr_name)) == NULL)
622 sec = (struct sockaddr_ec *)&ifr.ifr_addr;
630 /* Magic up a new one. */
631 edev = kmalloc(sizeof(struct ec_device), GFP_KERNEL);
633 printk("af_ec: memory squeeze.\n");
637 memset(edev, 0, sizeof(struct ec_device));
641 net2dev_map[edev->net] = NULL;
642 edev->station = sec->addr.station;
643 edev->net = sec->addr.net;
644 net2dev_map[sec->addr.net] = dev;
646 net2dev_map[0] = dev;
657 memset(sec, 0, sizeof(struct sockaddr_ec));
658 sec->addr.station = edev->station;
659 sec->addr.net = edev->net;
660 sec->sec_family = AF_ECONET;
662 if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
672 * Handle generic ioctls
675 static int econet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
677 struct sock *sk = sock->sk;
678 void __user *argp = (void __user *)arg;
682 return sock_get_timestamp(sk, argp);
686 return ec_dev_ioctl(sock, cmd, argp);
696 static struct net_proto_family econet_family_ops = {
698 .create = econet_create,
699 .owner = THIS_MODULE,
702 static const struct proto_ops SOCKOPS_WRAPPED(econet_ops) = {
704 .owner = THIS_MODULE,
705 .release = econet_release,
707 .connect = sock_no_connect,
708 .socketpair = sock_no_socketpair,
709 .accept = sock_no_accept,
710 .getname = econet_getname,
711 .poll = datagram_poll,
712 .ioctl = econet_ioctl,
713 .listen = sock_no_listen,
714 .shutdown = sock_no_shutdown,
715 .setsockopt = sock_no_setsockopt,
716 .getsockopt = sock_no_getsockopt,
717 .sendmsg = econet_sendmsg,
718 .recvmsg = econet_recvmsg,
719 .mmap = sock_no_mmap,
720 .sendpage = sock_no_sendpage,
723 #include <linux/smp_lock.h>
724 SOCKOPS_WRAP(econet, PF_ECONET);
726 #if defined(CONFIG_ECONET_AUNUDP) || defined(CONFIG_ECONET_NATIVE)
728 * Find the listening socket, if any, for the given data.
731 static struct sock *ec_listening_socket(unsigned char port, unsigned char
732 station, unsigned char net)
735 struct hlist_node *node;
737 sk_for_each(sk, node, &econet_sklist) {
738 struct econet_sock *opt = ec_sk(sk);
739 if ((opt->port == port || opt->port == 0) &&
740 (opt->station == station || opt->station == 0) &&
741 (opt->net == net || opt->net == 0))
750 * Queue a received packet for a socket.
753 static int ec_queue_packet(struct sock *sk, struct sk_buff *skb,
754 unsigned char stn, unsigned char net,
755 unsigned char cb, unsigned char port)
757 struct ec_cb *eb = (struct ec_cb *)&skb->cb;
758 struct sockaddr_ec *sec = (struct sockaddr_ec *)&eb->sec;
760 memset(sec, 0, sizeof(struct sockaddr_ec));
761 sec->sec_family = AF_ECONET;
762 sec->type = ECTYPE_PACKET_RECEIVED;
766 sec->addr.station = stn;
768 return sock_queue_rcv_skb(sk, skb);
772 #ifdef CONFIG_ECONET_AUNUDP
774 * Send an AUN protocol response.
777 static void aun_send_response(__u32 addr, unsigned long seq, int code, int cb)
779 struct sockaddr_in sin = {
780 .sin_family = AF_INET,
781 .sin_port = htons(AUN_PORT),
782 .sin_addr = {.s_addr = addr}
784 struct aunhdr ah = {.code = code, .cb = cb, .handle = seq};
785 struct kvec iov = {.iov_base = (void *)&ah, .iov_len = sizeof(ah)};
786 struct msghdr udpmsg;
788 udpmsg.msg_name = (void *)&sin;
789 udpmsg.msg_namelen = sizeof(sin);
790 udpmsg.msg_control = NULL;
791 udpmsg.msg_controllen = 0;
794 kernel_sendmsg(udpsock, &udpmsg, &iov, 1, sizeof(ah));
799 * Handle incoming AUN packets. Work out if anybody wants them,
800 * and send positive or negative acknowledgements as appropriate.
803 static void aun_incoming(struct sk_buff *skb, struct aunhdr *ah, size_t len)
805 struct iphdr *ip = skb->nh.iph;
806 unsigned char stn = ntohl(ip->saddr) & 0xff;
808 struct sk_buff *newskb;
809 struct ec_device *edev = skb->dev->ec_ptr;
814 if ((sk = ec_listening_socket(ah->port, stn, edev->net)) == NULL)
815 goto bad; /* Nobody wants it */
817 newskb = alloc_skb((len - sizeof(struct aunhdr) + 15) & ~15,
821 printk(KERN_DEBUG "AUN: memory squeeze, dropping packet.\n");
822 /* Send nack and hope sender tries again */
826 memcpy(skb_put(newskb, len - sizeof(struct aunhdr)), (void *)(ah+1),
827 len - sizeof(struct aunhdr));
829 if (ec_queue_packet(sk, newskb, stn, edev->net, ah->cb, ah->port))
831 /* Socket is bankrupt. */
836 aun_send_response(ip->saddr, ah->handle, 3, 0);
840 aun_send_response(ip->saddr, ah->handle, 4, 0);
844 * Handle incoming AUN transmit acknowledgements. If the sequence
845 * number matches something in our backlog then kill it and tell
846 * the user. If the remote took too long to reply then we may have
847 * dropped the packet already.
850 static void aun_tx_ack(unsigned long seq, int result)
856 spin_lock_irqsave(&aun_queue_lock, flags);
857 skb = skb_peek(&aun_queue);
858 while (skb && skb != (struct sk_buff *)&aun_queue)
860 struct sk_buff *newskb = skb->next;
861 eb = (struct ec_cb *)&skb->cb;
867 spin_unlock_irqrestore(&aun_queue_lock, flags);
868 printk(KERN_DEBUG "AUN: unknown sequence %ld\n", seq);
872 tx_result(skb->sk, eb->cookie, result);
873 skb_unlink(skb, &aun_queue);
874 spin_unlock_irqrestore(&aun_queue_lock, flags);
879 * Deal with received AUN frames - sort out what type of thing it is
880 * and hand it to the right function.
883 static void aun_data_available(struct sock *sk, int slen)
892 while ((skb = skb_recv_datagram(sk, 0, 1, &err)) == NULL) {
893 if (err == -EAGAIN) {
894 printk(KERN_ERR "AUN: no data available?!");
897 printk(KERN_DEBUG "AUN: recvfrom() error %d\n", -err);
900 data = skb->h.raw + sizeof(struct udphdr);
901 ah = (struct aunhdr *)data;
902 len = skb->len - sizeof(struct udphdr);
908 aun_incoming(skb, ah, len);
911 aun_tx_ack(ah->handle, ECTYPE_TRANSMIT_OK);
914 aun_tx_ack(ah->handle, ECTYPE_TRANSMIT_NOT_LISTENING);
917 /* This isn't quite right yet. */
919 aun_send_response(ip->saddr, ah->handle, 6, ah->cb);
923 printk(KERN_DEBUG "unknown AUN packet (type %d)\n", data[0]);
926 skb_free_datagram(sk, skb);
930 * Called by the timer to manage the AUN transmit queue. If a packet
931 * was sent to a dead or nonexistent host then we will never get an
932 * acknowledgement back. After a few seconds we need to spot this and
936 static void ab_cleanup(unsigned long h)
941 spin_lock_irqsave(&aun_queue_lock, flags);
942 skb = skb_peek(&aun_queue);
943 while (skb && skb != (struct sk_buff *)&aun_queue)
945 struct sk_buff *newskb = skb->next;
946 struct ec_cb *eb = (struct ec_cb *)&skb->cb;
947 if ((jiffies - eb->start) > eb->timeout)
949 tx_result(skb->sk, eb->cookie,
950 ECTYPE_TRANSMIT_NOT_PRESENT);
951 skb_unlink(skb, &aun_queue);
956 spin_unlock_irqrestore(&aun_queue_lock, flags);
958 mod_timer(&ab_cleanup_timer, jiffies + (HZ*2));
961 static int __init aun_udp_initialise(void)
964 struct sockaddr_in sin;
966 skb_queue_head_init(&aun_queue);
967 spin_lock_init(&aun_queue_lock);
968 init_timer(&ab_cleanup_timer);
969 ab_cleanup_timer.expires = jiffies + (HZ*2);
970 ab_cleanup_timer.function = ab_cleanup;
971 add_timer(&ab_cleanup_timer);
973 memset(&sin, 0, sizeof(sin));
974 sin.sin_port = htons(AUN_PORT);
976 /* We can count ourselves lucky Acorn machines are too dim to
978 if ((error = sock_create_kern(PF_INET, SOCK_DGRAM, 0, &udpsock)) < 0)
980 printk("AUN: socket error %d\n", -error);
984 udpsock->sk->sk_reuse = 1;
985 udpsock->sk->sk_allocation = GFP_ATOMIC; /* we're going to call it
988 error = udpsock->ops->bind(udpsock, (struct sockaddr *)&sin,
992 printk("AUN: bind error %d\n", -error);
996 udpsock->sk->sk_data_ready = aun_data_available;
1001 sock_release(udpsock);
1007 #ifdef CONFIG_ECONET_NATIVE
1010 * Receive an Econet frame from a device.
1013 static int econet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
1015 struct ec_framehdr *hdr;
1017 struct ec_device *edev = dev->ec_ptr;
1019 if (skb->pkt_type == PACKET_OTHERHOST)
1025 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
1028 if (!pskb_may_pull(skb, sizeof(struct ec_framehdr)))
1031 hdr = (struct ec_framehdr *) skb->data;
1033 /* First check for encapsulated IP */
1034 if (hdr->port == EC_PORT_IP) {
1035 skb->protocol = htons(ETH_P_IP);
1036 skb_pull(skb, sizeof(struct ec_framehdr));
1041 sk = ec_listening_socket(hdr->port, hdr->src_stn, hdr->src_net);
1045 if (ec_queue_packet(sk, skb, edev->net, hdr->src_stn, hdr->cb,
1056 static struct packet_type econet_packet_type = {
1057 .type = __constant_htons(ETH_P_ECONET),
1061 static void econet_hw_initialise(void)
1063 dev_add_pack(&econet_packet_type);
1068 static int econet_notifier(struct notifier_block *this, unsigned long msg, void *data)
1070 struct net_device *dev = (struct net_device *)data;
1071 struct ec_device *edev;
1074 case NETDEV_UNREGISTER:
1075 /* A device has gone down - kill any data we hold for it. */
1079 if (net2dev_map[0] == dev)
1080 net2dev_map[0] = NULL;
1081 net2dev_map[edev->net] = NULL;
1091 static struct notifier_block econet_netdev_notifier = {
1092 .notifier_call =econet_notifier,
1095 static void __exit econet_proto_exit(void)
1097 #ifdef CONFIG_ECONET_AUNUDP
1098 del_timer(&ab_cleanup_timer);
1100 sock_release(udpsock);
1102 unregister_netdevice_notifier(&econet_netdev_notifier);
1103 sock_unregister(econet_family_ops.family);
1104 proto_unregister(&econet_proto);
1107 static int __init econet_proto_init(void)
1109 int err = proto_register(&econet_proto, 0);
1113 sock_register(&econet_family_ops);
1114 #ifdef CONFIG_ECONET_AUNUDP
1115 spin_lock_init(&aun_queue_lock);
1116 aun_udp_initialise();
1118 #ifdef CONFIG_ECONET_NATIVE
1119 econet_hw_initialise();
1121 register_netdevice_notifier(&econet_netdev_notifier);
1126 module_init(econet_proto_init);
1127 module_exit(econet_proto_exit);
1129 MODULE_LICENSE("GPL");
1130 MODULE_ALIAS_NETPROTO(PF_ECONET);