2 * $Id: netiucv.c,v 1.21.8.6 2004/06/29 07:37:33 braunu Exp $
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
10 * the source of the original IUCV driver by:
11 * Stefan Hegewald <hegewald@de.ibm.com>
12 * Hartmut Penner <hpenner@de.ibm.com>
13 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
14 * Martin Schwidefsky (schwidefsky@de.ibm.com)
15 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 * RELEASE-TAG: IUCV network driver $Revision: 1.21.8.6 $
35 #include <linux/version.h>
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/errno.h>
41 #include <linux/types.h>
42 #include <linux/interrupt.h>
43 #include <linux/timer.h>
44 #include <linux/sched.h>
46 #include <linux/signal.h>
47 #include <linux/string.h>
48 #include <linux/proc_fs.h>
51 #include <linux/if_arp.h>
52 #include <linux/tcp.h>
53 #include <linux/skbuff.h>
54 #include <linux/ctype.h>
58 #include <asm/bitops.h>
59 #include <asm/uaccess.h>
68 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
69 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
70 MODULE_PARM (iucv, "1s");
71 MODULE_PARM_DESC (iucv,
72 "Specify the initial remote userids for iucv0 .. iucvn:\n"
73 "iucv=userid0:userid1:...:useridN");
76 static char *iucv = "";
81 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0))
82 typedef struct net_device net_device;
84 typedef struct device net_device;
89 * Per connection profiling data
91 typedef struct connection_profile_t {
92 unsigned long maxmulti;
93 unsigned long maxcqueue;
94 unsigned long doios_single;
95 unsigned long doios_multi;
97 unsigned long tx_time;
98 struct timeval send_stamp;
99 unsigned long tx_pending;
100 unsigned long tx_max_pending;
101 } connection_profile;
104 * Representation of one iucv connection
106 typedef struct iucv_connection_t {
107 struct iucv_connection_t *next;
108 iucv_handle_t handle;
110 struct sk_buff *rx_buff;
111 struct sk_buff *tx_buff;
112 struct sk_buff_head collect_queue;
113 struct sk_buff_head commit_queue;
114 spinlock_t collect_lock;
120 connection_profile prof;
125 * Linked list of all connection structs.
127 iucv_connection *connections;
130 * Representation of event-data for the
131 * connection state machine.
133 typedef struct iucv_event_t {
134 iucv_connection *conn;
139 * Private part of the network device structure
141 typedef struct netiucv_priv_t {
142 struct net_device_stats stats;
143 #if LINUX_VERSION_CODE >= 0x02032D
147 iucv_connection *conn;
148 struct proc_dir_entry *proc_dentry;
149 struct proc_dir_entry *proc_stat_entry;
150 struct proc_dir_entry *proc_buffer_entry;
151 struct proc_dir_entry *proc_user_entry;
156 * Link level header for a packet.
158 typedef struct ll_header_t {
162 #define NETIUCV_HDRLEN (sizeof(ll_header))
163 #define NETIUCV_BUFSIZE_MAX 32768
164 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
165 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
166 #define NETIUCV_MTU_DEFAULT 9216
167 #define NETIUCV_QUEUELEN_DEFAULT 50
168 #define NETIUCV_TIMEOUT_5SEC 5000
171 * Compatibility macros for busy handling
172 * of network devices.
174 #if LINUX_VERSION_CODE < 0x02032D
175 static __inline__ void netiucv_clear_busy(net_device *dev)
177 clear_bit(0 ,(void *)&dev->tbusy);
181 static __inline__ int netiucv_test_and_set_busy(net_device *dev)
183 return(test_and_set_bit(0, (void *)&dev->tbusy));
186 #define SET_DEVICE_START(device, value) dev->start = value
188 static __inline__ void netiucv_clear_busy(net_device *dev)
190 clear_bit(0, &(((netiucv_priv *)dev->priv)->tbusy));
191 netif_wake_queue(dev);
194 static __inline__ int netiucv_test_and_set_busy(net_device *dev)
196 netif_stop_queue(dev);
197 return test_and_set_bit(0, &((netiucv_priv *)dev->priv)->tbusy);
200 #define SET_DEVICE_START(device, value)
203 #if LINUX_VERSION_CODE < 0x020400
204 # define dev_kfree_skb_irq(a) dev_kfree_skb(a)
207 __u8 iucv_host[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
208 __u8 iucvMagic[16] = {
209 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
210 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
214 * This mask means the 16-byte IUCV "magic" and the origin userid must
215 * match exactly as specified in order to give connection_pending()
219 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
220 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
221 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
225 * Convert an iucv userId to its printable
226 * form (strip whitespace at end).
228 * @param An iucv userId
230 * @returns The printable string (static data!!)
232 static __inline__ char *
233 netiucv_printname(char *name)
237 memcpy(tmp, name, 8);
239 while (*p && (!isspace(*p)))
246 * States of the interface statemachine.
254 * MUST be always the last element!!
259 static const char *dev_state_names[] = {
267 * Events of the interface statemachine.
275 * MUST be always the last element!!
280 static const char *dev_event_names[] = {
288 * Events of the connection statemachine
292 * Events, representing callbacks from
293 * lowlevel iucv layer)
304 * Events, representing errors return codes from
305 * calls to lowlevel iucv layer
309 * Event, representing timer expiry.
314 * Events, representing commands from upper levels.
320 * MUST be always the last element!!
325 static const char *conn_event_names[] = {
326 "Remote connection request",
327 "Remote connection acknowledge",
328 "Remote connection reject",
329 "Connection suspended",
330 "Connection resumed",
341 * States of the connection statemachine.
345 * Connection not assigned to any device,
346 * initial state, invalid
351 * Userid assigned but not operating
356 * Connection registered,
357 * no connection request sent yet,
358 * no connection request received
360 CONN_STATE_STARTWAIT,
363 * Connection registered and connection request sent,
364 * no acknowledge and no connection request received yet.
366 CONN_STATE_SETUPWAIT,
369 * Connection up and running idle
374 * Data sent, awaiting CONN_EVENT_TXDONE
384 * Error during registration.
389 * Error during registration.
394 * MUST be always the last element!!
399 static const char *conn_state_names[] = {
407 "Registration error",
413 * Callback-wrappers, called from lowlevel iucv layer.
414 *****************************************************************************/
417 netiucv_callback_rx(iucv_MessagePending *eib, void *pgm_data)
419 iucv_connection *conn = (iucv_connection *)pgm_data;
423 ev.data = (void *)eib;
425 fsm_event(conn->fsm, CONN_EVENT_RX, &ev);
429 netiucv_callback_txdone(iucv_MessageComplete *eib, void *pgm_data)
431 iucv_connection *conn = (iucv_connection *)pgm_data;
435 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
439 ev.data = (void *)eib;
440 fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev);
444 netiucv_callback_connack(iucv_ConnectionComplete *eib, void *pgm_data)
446 iucv_connection *conn = (iucv_connection *)pgm_data;
450 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
454 ev.data = (void *)eib;
455 fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, &ev);
459 netiucv_callback_connreq(iucv_ConnectionPending *eib, void *pgm_data)
461 iucv_connection *conn = (iucv_connection *)pgm_data;
465 ev.data = (void *)eib;
466 fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev);
470 netiucv_callback_connrej(iucv_ConnectionSevered *eib, void *pgm_data)
472 iucv_connection *conn = (iucv_connection *)pgm_data;
476 ev.data = (void *)eib;
477 fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, &ev);
481 netiucv_callback_connsusp(iucv_ConnectionQuiesced *eib, void *pgm_data)
483 iucv_connection *conn = (iucv_connection *)pgm_data;
487 ev.data = (void *)eib;
488 fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, &ev);
492 netiucv_callback_connres(iucv_ConnectionResumed *eib, void *pgm_data)
494 iucv_connection *conn = (iucv_connection *)pgm_data;
498 ev.data = (void *)eib;
499 fsm_event(conn->fsm, CONN_EVENT_CONN_RES, &ev);
502 static iucv_interrupt_ops_t netiucv_ops = {
503 ConnectionPending: netiucv_callback_connreq,
504 ConnectionComplete: netiucv_callback_connack,
505 ConnectionSevered: netiucv_callback_connrej,
506 ConnectionQuiesced: netiucv_callback_connsusp,
507 ConnectionResumed: netiucv_callback_connres,
508 MessagePending: netiucv_callback_rx,
509 MessageComplete: netiucv_callback_txdone
513 * Dummy NOP action for all statemachines
516 fsm_action_nop(fsm_instance *fi, int event, void *arg)
521 * Actions of the connection statemachine
522 *****************************************************************************/
525 * Helper function for conn_action_rx()
526 * Unpack a just received skb and hand it over to
529 * @param conn The connection where this skb has been received.
530 * @param pskb The received skb.
532 //static __inline__ void
534 netiucv_unpack_skb(iucv_connection *conn, struct sk_buff *pskb)
536 net_device *dev = conn->netdev;
537 netiucv_priv *privptr = (netiucv_priv *)dev->priv;
540 skb_put(pskb, NETIUCV_HDRLEN);
542 pskb->ip_summed = CHECKSUM_NONE;
543 pskb->protocol = ntohs(ETH_P_IP);
547 ll_header *header = (ll_header *)pskb->data;
549 if (header->next == 0)
552 skb_pull(pskb, NETIUCV_HDRLEN);
553 header->next -= offset;
554 offset += header->next;
555 header->next -= NETIUCV_HDRLEN;
556 if (skb_tailroom(pskb) < header->next) {
558 "%s: Illegal next field in iucv header: %d > %d\n",
559 dev->name, header->next, skb_tailroom(pskb));
562 skb_put(pskb, header->next);
563 pskb->mac.raw = pskb->data;
564 skb = dev_alloc_skb(pskb->len);
567 "%s Out of memory in netiucv_unpack_skb\n",
569 privptr->stats.rx_dropped++;
572 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
573 skb->mac.raw = skb->data;
574 skb->dev = pskb->dev;
575 skb->protocol = pskb->protocol;
576 pskb->ip_summed = CHECKSUM_UNNECESSARY;
578 privptr->stats.rx_packets++;
579 privptr->stats.rx_bytes += skb->len;
580 skb_pull(pskb, header->next);
581 skb_put(pskb, NETIUCV_HDRLEN);
586 conn_action_rx(fsm_instance *fi, int event, void *arg)
588 iucv_event *ev = (iucv_event *)arg;
589 iucv_connection *conn = ev->conn;
590 iucv_MessagePending *eib = (iucv_MessagePending *)ev->data;
591 netiucv_priv *privptr = (netiucv_priv *)conn->netdev->priv;
593 __u32 msglen = eib->ln1msg2.ipbfln1f;
597 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
600 /* FRITZ: How to tell iucv LL to drop the msg? */
602 "Received data for unlinked connection\n");
605 if (msglen > conn->max_buffsize) {
606 /* FRITZ: How to tell iucv LL to drop the msg? */
607 privptr->stats.rx_dropped++;
610 conn->rx_buff->data = conn->rx_buff->tail = conn->rx_buff->head;
611 conn->rx_buff->len = 0;
612 rc = iucv_receive(conn->pathid, eib->ipmsgid, eib->iptrgcls,
613 conn->rx_buff->data, msglen, NULL, NULL, NULL);
614 if (rc != 0 || msglen < 5) {
615 privptr->stats.rx_errors++;
616 printk(KERN_INFO "iucv_receive returned %08x\n", rc);
619 netiucv_unpack_skb(conn, conn->rx_buff);
623 conn_action_txdone(fsm_instance *fi, int event, void *arg)
625 iucv_event *ev = (iucv_event *)arg;
626 iucv_connection *conn = ev->conn;
627 iucv_MessageComplete *eib = (iucv_MessageComplete *)ev->data;
628 netiucv_priv *privptr = NULL;
629 /* Shut up, gcc! skb is always below 2G. */
630 __u32 single_flag = eib->ipmsgtag;
633 __u32 stat_maxcq = 0;
635 unsigned long saveflags;
639 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
641 if (conn && conn->netdev && conn->netdev->priv)
642 privptr = (netiucv_priv *)conn->netdev->priv;
643 conn->prof.tx_pending--;
645 if ((skb = skb_dequeue(&conn->commit_queue))) {
646 atomic_dec(&skb->users);
647 dev_kfree_skb_any(skb);
649 privptr->stats.tx_packets++;
650 privptr->stats.tx_bytes +=
651 (skb->len - NETIUCV_HDRLEN
656 conn->tx_buff->data = conn->tx_buff->tail = conn->tx_buff->head;
657 conn->tx_buff->len = 0;
658 spin_lock_irqsave(&conn->collect_lock, saveflags);
659 while ((skb = skb_dequeue(&conn->collect_queue))) {
660 header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN;
661 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
663 memcpy(skb_put(conn->tx_buff, skb->len), skb->data, skb->len);
667 atomic_dec(&skb->users);
668 dev_kfree_skb_any(skb);
670 if (conn->collect_len > conn->prof.maxmulti)
671 conn->prof.maxmulti = conn->collect_len;
672 conn->collect_len = 0;
673 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
674 if (conn->tx_buff->len) {
678 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
681 conn->prof.send_stamp = xtime;
682 rc = iucv_send(conn->pathid, NULL, 0, 0, 0, 0,
683 conn->tx_buff->data, conn->tx_buff->len);
684 conn->prof.doios_multi++;
685 conn->prof.txlen += conn->tx_buff->len;
686 conn->prof.tx_pending++;
687 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
688 conn->prof.tx_max_pending = conn->prof.tx_pending;
690 conn->prof.tx_pending--;
691 fsm_newstate(fi, CONN_STATE_IDLE);
693 privptr->stats.tx_errors += txpackets;
694 printk(KERN_INFO "iucv_send returned %08x\n",
698 privptr->stats.tx_packets += txpackets;
699 privptr->stats.tx_bytes += txbytes;
701 if (stat_maxcq > conn->prof.maxcqueue)
702 conn->prof.maxcqueue = stat_maxcq;
705 fsm_newstate(fi, CONN_STATE_IDLE);
709 conn_action_connaccept(fsm_instance *fi, int event, void *arg)
711 iucv_event *ev = (iucv_event *)arg;
712 iucv_connection *conn = ev->conn;
713 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
714 net_device *netdev = conn->netdev;
715 netiucv_priv *privptr = (netiucv_priv *)netdev->priv;
721 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
723 rc = iucv_accept(eib->ippathid, NETIUCV_QUEUELEN_DEFAULT, udata, 0,
724 conn->handle, conn, NULL, &msglimit);
727 "%s: IUCV accept failed with error %d\n",
731 fsm_newstate(fi, CONN_STATE_IDLE);
732 conn->pathid = eib->ippathid;
733 netdev->tx_queue_len = msglimit;
734 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
738 conn_action_connreject(fsm_instance *fi, int event, void *arg)
740 iucv_event *ev = (iucv_event *)arg;
741 // iucv_connection *conn = ev->conn;
742 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
746 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
748 iucv_sever(eib->ippathid, udata);
752 conn_action_connack(fsm_instance *fi, int event, void *arg)
754 iucv_event *ev = (iucv_event *)arg;
755 iucv_connection *conn = ev->conn;
756 iucv_ConnectionComplete *eib = (iucv_ConnectionComplete *)ev->data;
757 net_device *netdev = conn->netdev;
758 netiucv_priv *privptr = (netiucv_priv *)netdev->priv;
761 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
763 fsm_deltimer(&conn->timer);
764 fsm_newstate(fi, CONN_STATE_IDLE);
765 conn->pathid = eib->ippathid;
766 netdev->tx_queue_len = eib->ipmsglim;
767 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
771 conn_action_conntimsev(fsm_instance *fi, int event, void *arg)
773 iucv_connection *conn = (iucv_connection *)arg;
776 pr_debug("%s() called\n", __FUNCTION__);
778 fsm_deltimer(&conn->timer);
779 iucv_sever(conn->pathid, udata);
780 fsm_newstate(fi, CONN_STATE_STARTWAIT);
784 conn_action_connsever(fsm_instance *fi, int event, void *arg)
786 iucv_event *ev = (iucv_event *)arg;
787 iucv_connection *conn = ev->conn;
788 // iucv_ConnectionSevered *eib = (iucv_ConnectionSevered *)ev->data;
789 net_device *netdev = conn->netdev;
790 netiucv_priv *privptr = (netiucv_priv *)netdev->priv;
794 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
796 fsm_deltimer(&conn->timer);
797 iucv_sever(conn->pathid, udata);
798 printk(KERN_INFO "%s: Remote dropped connection\n",
800 fsm_newstate(fi, CONN_STATE_STARTWAIT);
801 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
805 conn_action_start(fsm_instance *fi, int event, void *arg)
807 iucv_event *ev = (iucv_event *)arg;
808 iucv_connection *conn = ev->conn;
813 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
815 if (conn->handle == 0) {
817 iucv_register_program(iucvMagic, conn->userid, mask,
819 fsm_newstate(fi, CONN_STATE_STARTWAIT);
820 if (conn->handle <= 0) {
821 fsm_newstate(fi, CONN_STATE_REGERR);
826 printk(KERN_DEBUG "%s('%s'): registered successfully\n",
827 conn->netdev->name, conn->userid);
831 printk(KERN_DEBUG "%s('%s'): connecting ...\n",
832 conn->netdev->name, conn->userid);
835 /* We must set the state before calling iucv_connect because the callback
836 * handler could be called at any point after the connection request is
839 fsm_newstate(fi, CONN_STATE_SETUPWAIT);
840 rc = iucv_connect(&(conn->pathid), NETIUCV_QUEUELEN_DEFAULT, iucvMagic,
841 conn->userid, iucv_host, 0, NULL, &msglimit, conn->handle,
845 conn->netdev->tx_queue_len = msglimit;
846 fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC,
847 CONN_EVENT_TIMER, conn);
851 "%s: User %s is currently not available.\n",
853 netiucv_printname(conn->userid));
854 fsm_newstate(fi, CONN_STATE_STARTWAIT);
858 "%s: User %s is currently not ready.\n",
860 netiucv_printname(conn->userid));
861 fsm_newstate(fi, CONN_STATE_STARTWAIT);
865 "%s: Too many IUCV connections.\n",
867 fsm_newstate(fi, CONN_STATE_CONNERR);
871 "%s: User %s has too many IUCV connections.\n",
873 netiucv_printname(conn->userid));
874 fsm_newstate(fi, CONN_STATE_CONNERR);
878 "%s: No IUCV authorization in CP directory.\n",
880 fsm_newstate(fi, CONN_STATE_CONNERR);
884 "%s: iucv_connect returned error %d\n",
885 conn->netdev->name, rc);
886 fsm_newstate(fi, CONN_STATE_CONNERR);
889 iucv_unregister_program(conn->handle);
894 netiucv_purge_skb_queue(struct sk_buff_head *q)
898 while ((skb = skb_dequeue(q))) {
899 atomic_dec(&skb->users);
900 dev_kfree_skb_any(skb);
905 conn_action_stop(fsm_instance *fi, int event, void *arg)
907 iucv_event *ev = (iucv_event *)arg;
908 iucv_connection *conn = ev->conn;
909 net_device *netdev = conn->netdev;
910 netiucv_priv *privptr = (netiucv_priv *)netdev->priv;
913 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
915 fsm_deltimer(&conn->timer);
916 fsm_newstate(fi, CONN_STATE_STOPPED);
917 netiucv_purge_skb_queue(&conn->collect_queue);
919 iucv_unregister_program(conn->handle);
921 netiucv_purge_skb_queue(&conn->commit_queue);
922 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
926 conn_action_inval(fsm_instance *fi, int event, void *arg)
928 iucv_event *ev = (iucv_event *)arg;
929 iucv_connection *conn = ev->conn;
930 net_device *netdev = conn->netdev;
933 "%s: Cannot connect without username\n",
937 static const fsm_node conn_fsm[] = {
938 { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval },
939 { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start },
941 { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop },
942 { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop },
943 { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop },
944 { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop },
945 { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop },
946 { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop },
947 { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop },
949 { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject },
950 { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
951 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
952 { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject },
953 { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject },
955 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack },
956 { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev },
958 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever },
959 { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever },
960 { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever },
962 { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx },
963 { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx },
965 { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone },
966 { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone },
969 static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node);
973 * Actions for interface - statemachine.
974 *****************************************************************************/
977 * Startup connection by sending CONN_EVENT_START to it.
979 * @param fi An instance of an interface statemachine.
980 * @param event The event, just happened.
981 * @param arg Generic pointer, casted from net_device * upon call.
984 dev_action_start(fsm_instance *fi, int event, void *arg)
986 net_device *dev = (net_device *)arg;
987 netiucv_priv *privptr = dev->priv;
991 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
993 ev.conn = privptr->conn;
994 fsm_newstate(fi, DEV_STATE_STARTWAIT);
995 fsm_event(privptr->conn->fsm, CONN_EVENT_START, &ev);
999 * Shutdown connection by sending CONN_EVENT_STOP to it.
1001 * @param fi An instance of an interface statemachine.
1002 * @param event The event, just happened.
1003 * @param arg Generic pointer, casted from net_device * upon call.
1006 dev_action_stop(fsm_instance *fi, int event, void *arg)
1008 net_device *dev = (net_device *)arg;
1009 netiucv_priv *privptr = dev->priv;
1013 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
1015 ev.conn = privptr->conn;
1017 fsm_newstate(fi, DEV_STATE_STOPWAIT);
1018 fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev);
1022 * Called from connection statemachine
1023 * when a connection is up and running.
1025 * @param fi An instance of an interface statemachine.
1026 * @param event The event, just happened.
1027 * @param arg Generic pointer, casted from net_device * upon call.
1030 dev_action_connup(fsm_instance *fi, int event, void *arg)
1032 net_device *dev = (net_device *)arg;
1033 netiucv_priv *privptr = (netiucv_priv *)dev->priv;
1036 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
1038 switch (fsm_getstate(fi)) {
1039 case DEV_STATE_STARTWAIT:
1040 fsm_newstate(fi, DEV_STATE_RUNNING);
1042 "%s: connected with remote side %s\n",
1043 dev->name, privptr->conn->userid);
1045 case DEV_STATE_STOPWAIT:
1047 "%s: got connection UP event during shutdown!!\n",
1054 * Called from connection statemachine
1055 * when a connection has been shutdown.
1057 * @param fi An instance of an interface statemachine.
1058 * @param event The event, just happened.
1059 * @param arg Generic pointer, casted from net_device * upon call.
1062 dev_action_conndown(fsm_instance *fi, int event, void *arg)
1066 printk(KERN_DEBUG "%s() called\n", __FUNCTION__);
1068 switch (fsm_getstate(fi)) {
1069 case DEV_STATE_RUNNING:
1070 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1072 case DEV_STATE_STOPWAIT:
1073 fsm_newstate(fi, DEV_STATE_STOPPED);
1078 static const fsm_node dev_fsm[] = {
1079 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
1081 { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start },
1082 { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown },
1084 { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop },
1085 { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup },
1087 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
1088 { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown },
1089 { DEV_STATE_RUNNING, DEV_EVENT_CONUP, fsm_action_nop },
1092 static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node);
1095 * Transmit a packet.
1096 * This is a helper function for netiucv_tx().
1098 * @param conn Connection to be used for sending.
1099 * @param skb Pointer to struct sk_buff of packet to send.
1100 * The linklevel header has already been set up
1103 * @return 0 on success, -ERRNO on failure. (Never fails.)
1106 netiucv_transmit_skb(iucv_connection *conn, struct sk_buff *skb) {
1107 unsigned long saveflags;
1111 if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) {
1112 int l = skb->len + NETIUCV_HDRLEN;
1114 spin_lock_irqsave(&conn->collect_lock, saveflags);
1115 if (conn->collect_len + l >
1116 (conn->max_buffsize - NETIUCV_HDRLEN))
1119 atomic_inc(&skb->users);
1120 skb_queue_tail(&conn->collect_queue, skb);
1121 conn->collect_len += l;
1123 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
1125 struct sk_buff *nskb = skb;
1127 * Copy the skb to a new allocated skb in lowmem only if the
1128 * data is located above 2G in memory or tailroom is < 2.
1131 ((unsigned long)(skb->tail + NETIUCV_HDRLEN)) >> 31;
1133 if (hi || (skb_tailroom(skb) < 2)) {
1134 nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
1135 NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
1138 "%s: Could not allocate tx_skb\n",
1139 conn->netdev->name);
1143 skb_reserve(nskb, NETIUCV_HDRLEN);
1144 memcpy(skb_put(nskb, skb->len),
1145 skb->data, skb->len);
1150 * skb now is below 2G and has enough room. Add headers.
1152 header.next = nskb->len + NETIUCV_HDRLEN;
1153 memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1155 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1157 fsm_newstate(conn->fsm, CONN_STATE_TX);
1158 conn->prof.send_stamp = xtime;
1160 rc = iucv_send(conn->pathid, NULL, 0, 0, 1 /* single_flag */,
1161 0, nskb->data, nskb->len);
1162 conn->prof.doios_single++;
1163 conn->prof.txlen += skb->len;
1164 conn->prof.tx_pending++;
1165 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
1166 conn->prof.tx_max_pending = conn->prof.tx_pending;
1168 netiucv_priv *privptr;
1169 fsm_newstate(conn->fsm, CONN_STATE_IDLE);
1170 conn->prof.tx_pending--;
1171 privptr = (netiucv_priv *)conn->netdev->priv;
1173 privptr->stats.tx_errors++;
1175 dev_kfree_skb(nskb);
1178 * Remove our headers. They get added
1179 * again on retransmit.
1181 skb_pull(skb, NETIUCV_HDRLEN);
1182 skb_trim(skb, skb->len - NETIUCV_HDRLEN);
1184 printk(KERN_DEBUG "iucv_send returned %08x\n",
1189 atomic_inc(&nskb->users);
1190 skb_queue_tail(&conn->commit_queue, nskb);
1198 * Interface API for upper network layers
1199 *****************************************************************************/
1202 * Open an interface.
1203 * Called from generic network layer when ifconfig up is run.
1205 * @param dev Pointer to interface struct.
1207 * @return 0 on success, -ERRNO on failure. (Never fails.)
1210 netiucv_open(net_device *dev) {
1212 SET_DEVICE_START(dev, 1);
1213 fsm_event(((netiucv_priv *)dev->priv)->fsm, DEV_EVENT_START, dev);
1218 * Close an interface.
1219 * Called from generic network layer when ifconfig down is run.
1221 * @param dev Pointer to interface struct.
1223 * @return 0 on success, -ERRNO on failure. (Never fails.)
1226 netiucv_close(net_device *dev) {
1227 SET_DEVICE_START(dev, 0);
1228 fsm_event(((netiucv_priv *)dev->priv)->fsm, DEV_EVENT_STOP, dev);
1234 * Start transmission of a packet.
1235 * Called from generic network device layer.
1237 * @param skb Pointer to buffer containing the packet.
1238 * @param dev Pointer to interface struct.
1240 * @return 0 if packet consumed, !0 if packet rejected.
1241 * Note: If we return !0, then the packet is free'd by
1242 * the generic network layer.
1244 static int netiucv_tx(struct sk_buff *skb, net_device *dev)
1247 netiucv_priv *privptr = (netiucv_priv *)dev->priv;
1250 * Some sanity checks ...
1253 printk(KERN_WARNING "%s: NULL sk_buff passed\n", dev->name);
1254 privptr->stats.tx_dropped++;
1257 if (skb_headroom(skb) < (NETIUCV_HDRLEN)) {
1259 "%s: Got sk_buff with head room < %ld bytes\n",
1260 dev->name, NETIUCV_HDRLEN);
1262 privptr->stats.tx_dropped++;
1267 * If connection is not running, try to restart it
1268 * notify anybody about a link failure and throw
1271 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1272 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1274 privptr->stats.tx_dropped++;
1275 privptr->stats.tx_errors++;
1276 privptr->stats.tx_carrier_errors++;
1280 if (netiucv_test_and_set_busy(dev))
1283 dev->trans_start = jiffies;
1284 if (netiucv_transmit_skb(privptr->conn, skb) != 0)
1286 netiucv_clear_busy(dev);
1291 * Returns interface statistics of a device.
1293 * @param dev Pointer to interface struct.
1295 * @return Pointer to stats struct of this interface.
1297 static struct net_device_stats *
1298 netiucv_stats (net_device * dev)
1300 return &((netiucv_priv *)dev->priv)->stats;
1304 * Sets MTU of an interface.
1306 * @param dev Pointer to interface struct.
1307 * @param new_mtu The new MTU to use for this interface.
1309 * @return 0 on success, -EINVAL if MTU is out of valid range.
1310 * (valid range is 576 .. NETIUCV_MTU_MAX).
1313 netiucv_change_mtu (net_device * dev, int new_mtu)
1315 if ((new_mtu < 576) || (new_mtu > NETIUCV_MTU_MAX))
1323 * procfs related structures and routines
1324 *****************************************************************************/
1327 find_netdev_by_ino(unsigned long ino)
1329 iucv_connection *conn = connections;
1330 net_device *dev = NULL;
1331 netiucv_priv *privptr;
1334 if (conn->netdev != dev) {
1336 privptr = (netiucv_priv *)dev->priv;
1338 if ((privptr->proc_buffer_entry->low_ino == ino) ||
1339 (privptr->proc_user_entry->low_ino == ino) ||
1340 (privptr->proc_stat_entry->low_ino == ino) )
1348 #if LINUX_VERSION_CODE < 0x020363
1350 * Lock the module, if someone changes into
1351 * our proc directory.
1354 netiucv_fill_inode(struct inode *inode, int fill)
1363 #define CTRL_BUFSIZE 40
1366 netiucv_buffer_open(struct inode *inode, struct file *file)
1368 file->private_data = kmalloc(CTRL_BUFSIZE, GFP_KERNEL);
1369 if (file->private_data == NULL)
1371 *(char *)file->private_data = '\0';
1377 netiucv_buffer_close(struct inode *inode, struct file *file)
1379 kfree(file->private_data);
1385 netiucv_buffer_write(struct file *file, const char *buf, size_t count,
1388 unsigned int ino = ((struct inode *)file->f_dentry->d_inode)->i_ino;
1390 netiucv_priv *privptr;
1393 char tmp[CTRL_BUFSIZE];
1395 if (!(dev = find_netdev_by_ino(ino)))
1397 if (ppos != &file->f_pos)
1400 privptr = (netiucv_priv *)dev->priv;
1402 if (count >= CTRL_BUFSIZE-1)
1405 if (copy_from_user(tmp, buf, count))
1407 tmp[count+1] = '\0';
1408 bs1 = simple_strtoul(tmp, &e, 0);
1410 if ((bs1 > NETIUCV_BUFSIZE_MAX) ||
1411 (e && (!isspace(*e))))
1413 if ((dev->flags & IFF_RUNNING) &&
1414 (bs1 < (dev->mtu + NETIUCV_HDRLEN + 2)))
1416 if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN))
1420 privptr->conn->max_buffsize = bs1;
1421 if (!(dev->flags & IFF_RUNNING))
1422 dev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN;
1428 netiucv_buffer_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1430 unsigned int ino = ((struct inode *)file->f_dentry->d_inode)->i_ino;
1431 char *sbuf = (char *)file->private_data;
1433 netiucv_priv *privptr;
1439 if (!(dev = find_netdev_by_ino(ino)))
1441 if (ppos != &file->f_pos)
1444 privptr = (netiucv_priv *)dev->priv;
1446 if (!*sbuf || pos == 0)
1447 sprintf(sbuf, "%d\n", privptr->conn->max_buffsize);
1451 if (pos == (unsigned)pos && pos < l) {
1454 ret = (count > l) ? l : count;
1455 if (copy_to_user(buf, p, ret))
1464 netiucv_user_open(struct inode *inode, struct file *file)
1466 file->private_data = kmalloc(CTRL_BUFSIZE, GFP_KERNEL);
1467 if (file->private_data == NULL)
1469 *(char *)file->private_data = '\0';
1475 netiucv_user_close(struct inode *inode, struct file *file)
1477 kfree(file->private_data);
1483 netiucv_user_write(struct file *file, const char *buf, size_t count,
1486 unsigned int ino = ((struct inode *)file->f_dentry->d_inode)->i_ino;
1488 netiucv_priv *privptr;
1491 char tmp[CTRL_BUFSIZE];
1494 if (!(dev = find_netdev_by_ino(ino)))
1496 if (ppos != &file->f_pos)
1499 privptr = (netiucv_priv *)dev->priv;
1501 if (count >= CTRL_BUFSIZE-1)
1504 if (copy_from_user(tmp, buf, count))
1506 tmp[count+1] = '\0';
1508 memset(user, ' ', sizeof(user));
1510 for (p = tmp, i = 0; *p && (!isspace(*p)); p++) {
1516 if (memcmp(user, privptr->conn->userid, 8) != 0) {
1517 /* username changed */
1518 if (dev->flags & IFF_RUNNING)
1521 memcpy(privptr->conn->userid, user, 9);
1526 netiucv_user_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1528 unsigned int ino = ((struct inode *)file->f_dentry->d_inode)->i_ino;
1529 char *sbuf = (char *)file->private_data;
1531 netiucv_priv *privptr;
1537 if (!(dev = find_netdev_by_ino(ino)))
1539 if (ppos != &file->f_pos)
1542 privptr = (netiucv_priv *)dev->priv;
1545 if (!*sbuf || pos == 0)
1546 sprintf(sbuf, "%s\n",
1547 netiucv_printname(privptr->conn->userid));
1551 if (pos == (unsigned)pos && pos < l) {
1554 ret = (count > l) ? l : count;
1555 if (copy_to_user(buf, p, ret))
1562 #define STATS_BUFSIZE 2048
1565 netiucv_stat_open(struct inode *inode, struct file *file)
1567 file->private_data = kmalloc(STATS_BUFSIZE, GFP_KERNEL);
1568 if (file->private_data == NULL)
1570 *(char *)file->private_data = '\0';
1576 netiucv_stat_close(struct inode *inode, struct file *file)
1578 kfree(file->private_data);
1584 netiucv_stat_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1586 unsigned int ino = ((struct inode *)file->f_dentry->d_inode)->i_ino;
1588 netiucv_priv *privptr;
1590 if (!(dev = find_netdev_by_ino(ino)))
1592 privptr = (netiucv_priv *)dev->priv;
1593 memset(&(privptr->conn->prof), 0, sizeof(privptr->conn->prof));
1598 netiucv_stat_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1600 unsigned int ino = ((struct inode *)file->f_dentry->d_inode)->i_ino;
1602 char *sbuf = (char *)file->private_data;
1604 netiucv_priv *privptr;
1609 if (!(dev = find_netdev_by_ino(ino)))
1611 if (ppos != &file->f_pos)
1614 privptr = (netiucv_priv *)dev->priv;
1616 if (!*sbuf || pos == 0) {
1617 p += sprintf(p, "Device FSM state: %s\n",
1618 fsm_getstate_str(privptr->fsm));
1619 p += sprintf(p, "Connection FSM state: %s\n",
1620 fsm_getstate_str(privptr->conn->fsm));
1621 p += sprintf(p, "Max. TX buffer used: %ld\n",
1622 privptr->conn->prof.maxmulti);
1623 p += sprintf(p, "Max. chained SKBs: %ld\n",
1624 privptr->conn->prof.maxcqueue);
1625 p += sprintf(p, "TX single write ops: %ld\n",
1626 privptr->conn->prof.doios_single);
1627 p += sprintf(p, "TX multi write ops: %ld\n",
1628 privptr->conn->prof.doios_multi);
1629 p += sprintf(p, "Netto bytes written: %ld\n",
1630 privptr->conn->prof.txlen);
1631 p += sprintf(p, "Max. TX IO-time: %ld\n",
1632 privptr->conn->prof.tx_time);
1633 p += sprintf(p, "Pending transmits: %ld\n",
1634 privptr->conn->prof.tx_pending);
1635 p += sprintf(p, "Max. pending transmits: %ld\n",
1636 privptr->conn->prof.tx_max_pending);
1640 if (pos == (unsigned)pos && pos < l) {
1643 ret = (count > l) ? l : count;
1644 if (copy_to_user(buf, p, ret))
1651 static struct file_operations netiucv_stat_fops = {
1652 read: netiucv_stat_read,
1653 write: netiucv_stat_write,
1654 open: netiucv_stat_open,
1655 release: netiucv_stat_close,
1658 static struct file_operations netiucv_buffer_fops = {
1659 read: netiucv_buffer_read,
1660 write: netiucv_buffer_write,
1661 open: netiucv_buffer_open,
1662 release: netiucv_buffer_close,
1665 static struct file_operations netiucv_user_fops = {
1666 read: netiucv_user_read,
1667 write: netiucv_user_write,
1668 open: netiucv_user_open,
1669 release: netiucv_user_close,
1672 static struct inode_operations netiucv_stat_iops = {
1673 #if LINUX_VERSION_CODE < 0x020363
1674 default_file_ops: &netiucv_stat_fops
1677 static struct inode_operations netiucv_buffer_iops = {
1678 #if LINUX_VERSION_CODE < 0x020363
1679 default_file_ops: &netiucv_buffer_fops
1683 static struct inode_operations netiucv_user_iops = {
1684 #if LINUX_VERSION_CODE < 0x020363
1685 default_file_ops: &netiucv_user_fops
1689 static struct proc_dir_entry stat_entry = {
1692 "statistics", /* name */
1693 S_IFREG | S_IRUGO | S_IWUSR, /* mode */
1698 &netiucv_stat_iops /* ops */
1701 static struct proc_dir_entry buffer_entry = {
1704 "buffersize", /* name */
1705 S_IFREG | S_IRUSR | S_IWUSR, /* mode */
1710 &netiucv_buffer_iops /* ops */
1713 static struct proc_dir_entry user_entry = {
1716 "username", /* name */
1717 S_IFREG | S_IRUSR | S_IWUSR, /* mode */
1722 &netiucv_user_iops /* ops */
1725 #if LINUX_VERSION_CODE < 0x020363
1726 static struct proc_dir_entry netiucv_dir = {
1730 S_IFDIR | S_IRUGO | S_IXUGO, /* mode */
1737 netiucv_fill_inode /* fill_ino (for locking) */
1740 static struct proc_dir_entry netiucv_template =
1745 S_IFDIR | S_IRUGO | S_IXUGO, /* mode */
1752 netiucv_fill_inode /* fill_ino (for locking) */
1755 static struct proc_dir_entry *netiucv_dir = NULL;
1756 static struct proc_dir_entry *netiucv_template = NULL;
1760 * Create the driver's main directory /proc/net/iucv
1763 netiucv_proc_create_main(void)
1766 * If not registered, register main proc dir-entry now
1768 #if LINUX_VERSION_CODE > 0x020362
1769 #ifdef CONFIG_PROC_FS
1771 netiucv_dir = proc_mkdir("iucv", proc_net);
1774 if (netiucv_dir.low_ino == 0)
1775 proc_net_register(&netiucv_dir);
1781 * Destroy /proc/net/iucv
1784 netiucv_proc_destroy_main(void)
1786 #if LINUX_VERSION_CODE > 0x020362
1787 #ifdef CONFIG_PROC_FS
1788 remove_proc_entry("iucv", proc_net);
1791 proc_net_unregister(netiucv_dir.low_ino);
1797 * Create a device specific subdirectory in /proc/net/iucv/ with the
1798 * same name like the device. In that directory, create 3 entries
1799 * "statistics", "buffersize" and "username".
1801 * @param dev The device for which the subdirectory should be created.
1805 netiucv_proc_create_sub(net_device *dev) {
1806 netiucv_priv *privptr = dev->priv;
1808 #if LINUX_VERSION_CODE > 0x020362
1809 privptr->proc_dentry = proc_mkdir(dev->name, netiucv_dir);
1810 privptr->proc_stat_entry =
1811 create_proc_entry("statistics",
1812 S_IFREG | S_IRUSR | S_IWUSR,
1813 privptr->proc_dentry);
1814 privptr->proc_stat_entry->proc_fops = &netiucv_stat_fops;
1815 privptr->proc_stat_entry->proc_iops = &netiucv_stat_iops;
1816 privptr->proc_buffer_entry =
1817 create_proc_entry("buffersize",
1818 S_IFREG | S_IRUSR | S_IWUSR,
1819 privptr->proc_dentry);
1820 privptr->proc_buffer_entry->proc_fops = &netiucv_buffer_fops;
1821 privptr->proc_buffer_entry->proc_iops = &netiucv_buffer_iops;
1822 privptr->proc_user_entry =
1823 create_proc_entry("username",
1824 S_IFREG | S_IRUSR | S_IWUSR,
1825 privptr->proc_dentry);
1826 privptr->proc_user_entry->proc_fops = &netiucv_user_fops;
1827 privptr->proc_user_entry->proc_iops = &netiucv_user_iops;
1829 privptr->proc_dentry->name = dev->name;
1830 privptr->proc_dentry->namelen = strlen(dev->name);
1831 proc_register(&netiucv_dir, privptr->proc_dentry);
1832 proc_register(privptr->proc_dentry, privptr->proc_stat_entry);
1833 proc_register(privptr->proc_dentry, privptr->proc_buffer_entry);
1834 proc_register(privptr->proc_dentry, privptr->proc_user_entry);
1836 privptr->proc_registered = 1;
1841 * Destroy a device specific subdirectory.
1843 * @param privptr Pointer to device private data.
1846 netiucv_proc_destroy_sub(netiucv_priv *privptr) {
1847 if (!privptr->proc_registered)
1849 #if LINUX_VERSION_CODE > 0x020362
1850 remove_proc_entry("statistics", privptr->proc_dentry);
1851 remove_proc_entry("buffersize", privptr->proc_dentry);
1852 remove_proc_entry("username", privptr->proc_dentry);
1853 remove_proc_entry(privptr->proc_dentry->name, netiucv_dir);
1855 proc_unregister(privptr->proc_dentry,
1856 privptr->proc_stat_entry->low_ino);
1857 proc_unregister(privptr->proc_dentry,
1858 privptr->proc_buffer_entry->low_ino);
1859 proc_unregister(privptr->proc_dentry,
1860 privptr->proc_user_entry->low_ino);
1861 proc_unregister(&netiucv_dir,
1862 privptr->proc_dentry->low_ino);
1864 privptr->proc_registered = 0;
1869 * Allocate and initialize a new connection structure.
1870 * Add it to the list of connections;
1872 static iucv_connection *
1873 netiucv_new_connection(net_device *dev, char *username)
1875 iucv_connection **clist = &connections;
1876 iucv_connection *conn =
1877 (iucv_connection *)kmalloc(sizeof(iucv_connection), GFP_KERNEL);
1879 memset(conn, 0, sizeof(iucv_connection));
1880 skb_queue_head_init(&conn->collect_queue);
1881 skb_queue_head_init(&conn->commit_queue);
1882 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1885 conn->rx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT, GFP_DMA);
1886 if (!conn->rx_buff) {
1890 conn->tx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT, GFP_DMA);
1891 if (!conn->tx_buff) {
1892 kfree_skb(conn->rx_buff);
1896 conn->fsm = init_fsm("netiucvconn", conn_state_names,
1897 conn_event_names, NR_CONN_STATES,
1898 NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN,
1901 kfree_skb(conn->tx_buff);
1902 kfree_skb(conn->rx_buff);
1906 fsm_settimer(conn->fsm, &conn->timer);
1907 fsm_newstate(conn->fsm, CONN_STATE_INVALID);
1910 memcpy(conn->userid, username, 9);
1911 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1914 conn->next = *clist;
1921 * Release a connection structure and remove it from the
1922 * list of connections.
1925 netiucv_remove_connection(iucv_connection *conn)
1927 iucv_connection **clist = &connections;
1932 if (*clist == conn) {
1933 *clist = conn->next;
1934 if (conn->handle != 0) {
1935 iucv_unregister_program(conn->handle);
1938 fsm_deltimer(&conn->timer);
1939 kfree_fsm(conn->fsm);
1940 kfree_skb(conn->rx_buff);
1941 kfree_skb(conn->tx_buff);
1944 clist = &((*clist)->next);
1949 * Allocate and initialize everything of a net device.
1952 netiucv_init_netdevice(int ifno, char *username)
1954 netiucv_priv *privptr;
1957 net_device *dev = kmalloc(sizeof(net_device)
1958 #if LINUX_VERSION_CODE < 0x020300
1959 + 11 /* name + zero */
1964 memset(dev, 0, sizeof(net_device));
1965 #if LINUX_VERSION_CODE < 0x020300
1966 dev->name = (char *)dev + sizeof(net_device);
1968 sprintf(dev->name, "iucv%d", ifno);
1970 priv_size = sizeof(netiucv_priv) + sizeof(netiucv_template) +
1971 sizeof(stat_entry) + sizeof(buffer_entry) + sizeof(user_entry);
1972 dev->priv = kmalloc(priv_size, GFP_KERNEL);
1973 if (dev->priv == NULL) {
1977 memset(dev->priv, 0, priv_size);
1978 privptr = (netiucv_priv *)dev->priv;
1979 privptr->proc_dentry = (struct proc_dir_entry *)
1980 (((char *)privptr) + sizeof(netiucv_priv));
1981 privptr->proc_stat_entry = (struct proc_dir_entry *)
1982 (((char *)privptr) + sizeof(netiucv_priv) +
1983 sizeof(netiucv_template));
1984 privptr->proc_buffer_entry = (struct proc_dir_entry *)
1985 (((char *)privptr) + sizeof(netiucv_priv) +
1986 sizeof(netiucv_template) + sizeof(stat_entry));
1987 privptr->proc_user_entry = (struct proc_dir_entry *)
1988 (((char *)privptr) + sizeof(netiucv_priv) +
1989 sizeof(netiucv_template) + sizeof(stat_entry) +
1990 sizeof(buffer_entry));
1991 memcpy(privptr->proc_dentry, &netiucv_template,
1992 sizeof(netiucv_template));
1993 memcpy(privptr->proc_stat_entry, &stat_entry, sizeof(stat_entry));
1994 memcpy(privptr->proc_buffer_entry, &buffer_entry, sizeof(buffer_entry));
1995 memcpy(privptr->proc_user_entry, &user_entry, sizeof(user_entry));
1996 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
1997 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
1998 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
1999 if (privptr->fsm == NULL) {
2004 privptr->conn = netiucv_new_connection(dev, username);
2005 if (!privptr->conn) {
2006 kfree_fsm(privptr->fsm);
2012 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
2013 dev->mtu = NETIUCV_MTU_DEFAULT;
2014 dev->hard_start_xmit = netiucv_tx;
2015 dev->open = netiucv_open;
2016 dev->stop = netiucv_close;
2017 dev->get_stats = netiucv_stats;
2018 dev->change_mtu = netiucv_change_mtu;
2019 dev->hard_header_len = NETIUCV_HDRLEN;
2021 dev->type = ARPHRD_SLIP;
2022 dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT;
2023 dev_init_buffers(dev);
2024 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2029 * Allocate and initialize everything of a net device.
2032 netiucv_free_netdevice(net_device *dev)
2034 netiucv_priv *privptr;
2039 privptr = (netiucv_priv *)dev->priv;
2042 netiucv_remove_connection(privptr->conn);
2044 kfree_fsm(privptr->fsm);
2045 netiucv_proc_destroy_sub(privptr);
2052 netiucv_banner(void)
2054 char vbuf[] = "$Revision: 1.21.8.6 $";
2055 char *version = vbuf;
2057 if ((version = strchr(version, ':'))) {
2058 char *p = strchr(version + 1, '$');
2063 printk(KERN_INFO "NETIUCV driver Version%s initialized\n", version);
2067 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0))
2068 # define init_return(a) return a
2070 iucv_setup(char *param)
2072 # define init_return(a) return
2073 __initfunc (void iucv_setup(char *param, int *ints))
2077 * We do not parse parameters here because at the time of
2078 * calling iucv_setup(), the kernel does not yet have
2079 * memory management running. We delay this until probing
2086 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0))
2087 __setup ("iucv=", iucv_setup);
2093 while (connections) {
2094 net_device *dev = connections->netdev;
2095 unregister_netdev(dev);
2096 netiucv_free_netdevice(dev);
2098 netiucv_proc_destroy_main();
2100 printk(KERN_INFO "NETIUCV driver unloaded\n");
2113 netiucv_proc_create_main();
2115 if (isalnum(*p) || (*p == '$')) {
2116 username[i++] = *p++;
2120 "netiucv: Invalid user name '%s'\n",
2122 while (*p && (*p != ':') && (*p != ','))
2126 if (*p && (*p != ':') && (*p != ',')) {
2128 "netiucv: Invalid delimiter '%c'\n",
2130 while (*p && (*p != ':') && (*p != ','))
2137 username[i++] = ' ';
2139 dev = netiucv_init_netdevice(ifno,
2143 "netiucv: Could not allocate network device structure for user '%s'\n", netiucv_printname(username));
2145 if (register_netdev(dev)) {
2147 "netiucv: Could not register '%s'\n", dev->name);
2148 netiucv_free_netdevice(dev);
2150 printk(KERN_INFO "%s: '%s'\n", dev->name, netiucv_printname(username));
2151 netiucv_proc_create_sub(dev);
2168 module_init(netiucv_init);
2169 module_exit(netiucv_exit);
2170 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12))
2171 MODULE_LICENSE("GPL");