2 * $Id: netiucv.c,v 1.51 2004/04/23 08:11:21 mschwide Exp $
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
9 * Driverfs integration and all bugs therein by Cornelia Huck(cohuck@de.ibm.com)
12 * the source of the original IUCV driver by:
13 * Stefan Hegewald <hegewald@de.ibm.com>
14 * Hartmut Penner <hpenner@de.ibm.com>
15 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
16 * Martin Schwidefsky (schwidefsky@de.ibm.com)
17 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2, or (at your option)
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 * RELEASE-TAG: IUCV network driver $Revision: 1.51 $
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/kernel.h>
42 #include <linux/slab.h>
43 #include <linux/errno.h>
44 #include <linux/types.h>
45 #include <linux/interrupt.h>
46 #include <linux/timer.h>
47 #include <linux/sched.h>
49 #include <linux/signal.h>
50 #include <linux/string.h>
51 #include <linux/device.h>
54 #include <linux/if_arp.h>
55 #include <linux/tcp.h>
56 #include <linux/skbuff.h>
57 #include <linux/ctype.h>
61 #include <asm/bitops.h>
62 #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");
73 * Per connection profiling data
75 struct connection_profile {
76 unsigned long maxmulti;
77 unsigned long maxcqueue;
78 unsigned long doios_single;
79 unsigned long doios_multi;
81 unsigned long tx_time;
82 struct timespec send_stamp;
83 unsigned long tx_pending;
84 unsigned long tx_max_pending;
88 * Representation of one iucv connection
90 struct iucv_connection {
91 struct iucv_connection *next;
94 struct sk_buff *rx_buff;
95 struct sk_buff *tx_buff;
96 struct sk_buff_head collect_queue;
97 struct sk_buff_head commit_queue;
98 spinlock_t collect_lock;
104 struct net_device *netdev;
105 struct connection_profile prof;
109 #define CONN_FLAGS_BUFSIZE_CHANGED 1
112 * Linked list of all connection structs.
114 static struct iucv_connection *connections;
116 /* Keep track of interfaces. */
120 * Representation of event-data for the
121 * connection state machine.
124 struct iucv_connection *conn;
129 * Private part of the network device structure
131 struct netiucv_priv {
132 struct net_device_stats stats;
135 struct iucv_connection *conn;
141 * Link level header for a packet.
143 typedef struct ll_header_t {
147 #define NETIUCV_HDRLEN (sizeof(ll_header))
148 #define NETIUCV_BUFSIZE_MAX 32768
149 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
150 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
151 #define NETIUCV_MTU_DEFAULT 9216
152 #define NETIUCV_QUEUELEN_DEFAULT 50
153 #define NETIUCV_TIMEOUT_5SEC 5000
156 * Compatibility macros for busy handling
157 * of network devices.
159 static __inline__ void netiucv_clear_busy(struct net_device *dev)
161 clear_bit(0, &(((struct netiucv_priv *)dev->priv)->tbusy));
162 netif_wake_queue(dev);
165 static __inline__ int netiucv_test_and_set_busy(struct net_device *dev)
167 netif_stop_queue(dev);
168 return test_and_set_bit(0, &((struct netiucv_priv *)dev->priv)->tbusy);
171 static __u8 iucv_host[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
172 //static __u8 iucvMagic[16] = {
173 // 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
174 // 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
178 * This mask means the 16-byte IUCV "magic" and the origin userid must
179 * match exactly as specified in order to give connection_pending()
182 static __u8 mask[] = {
183 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
184 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
185 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
189 * Convert an iucv userId to its printable
190 * form (strip whitespace at end).
192 * @param An iucv userId
194 * @returns The printable string (static data!!)
196 static __inline__ char *
197 netiucv_printname(char *name)
201 memcpy(tmp, name, 8);
203 while (*p && (!isspace(*p)))
210 * States of the interface statemachine.
218 * MUST be always the last element!!
223 static const char *dev_state_names[] = {
231 * Events of the interface statemachine.
240 * MUST be always the last element!!
245 static const char *dev_event_names[] = {
254 * Events of the connection statemachine
258 * Events, representing callbacks from
259 * lowlevel iucv layer)
270 * Events, representing errors return codes from
271 * calls to lowlevel iucv layer
275 * Event, representing timer expiry.
280 * Events, representing commands from upper levels.
286 * MUST be always the last element!!
291 static const char *conn_event_names[] = {
292 "Remote connection request",
293 "Remote connection acknowledge",
294 "Remote connection reject",
295 "Connection suspended",
296 "Connection resumed",
307 * States of the connection statemachine.
311 * Connection not assigned to any device,
312 * initial state, invalid
317 * Userid assigned but not operating
322 * Connection registered,
323 * no connection request sent yet,
324 * no connection request received
326 CONN_STATE_STARTWAIT,
329 * Connection registered and connection request sent,
330 * no acknowledge and no connection request received yet.
332 CONN_STATE_SETUPWAIT,
335 * Connection up and running idle
340 * Data sent, awaiting CONN_EVENT_TXDONE
345 * Error during registration.
350 * Error during registration.
355 * MUST be always the last element!!
360 static const char *conn_state_names[] = {
368 "Registration error",
374 * Callback-wrappers, called from lowlevel iucv layer.
375 *****************************************************************************/
378 netiucv_callback_rx(iucv_MessagePending *eib, void *pgm_data)
380 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
381 struct iucv_event ev;
384 ev.data = (void *)eib;
386 fsm_event(conn->fsm, CONN_EVENT_RX, &ev);
390 netiucv_callback_txdone(iucv_MessageComplete *eib, void *pgm_data)
392 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
393 struct iucv_event ev;
396 ev.data = (void *)eib;
397 fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev);
401 netiucv_callback_connack(iucv_ConnectionComplete *eib, void *pgm_data)
403 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
404 struct iucv_event ev;
407 ev.data = (void *)eib;
408 fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, &ev);
412 netiucv_callback_connreq(iucv_ConnectionPending *eib, void *pgm_data)
414 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
415 struct iucv_event ev;
418 ev.data = (void *)eib;
419 fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev);
423 netiucv_callback_connrej(iucv_ConnectionSevered *eib, void *pgm_data)
425 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
426 struct iucv_event ev;
429 ev.data = (void *)eib;
430 fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, &ev);
434 netiucv_callback_connsusp(iucv_ConnectionQuiesced *eib, void *pgm_data)
436 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
437 struct iucv_event ev;
440 ev.data = (void *)eib;
441 fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, &ev);
445 netiucv_callback_connres(iucv_ConnectionResumed *eib, void *pgm_data)
447 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
448 struct iucv_event ev;
451 ev.data = (void *)eib;
452 fsm_event(conn->fsm, CONN_EVENT_CONN_RES, &ev);
455 static iucv_interrupt_ops_t netiucv_ops = {
456 .ConnectionPending = netiucv_callback_connreq,
457 .ConnectionComplete = netiucv_callback_connack,
458 .ConnectionSevered = netiucv_callback_connrej,
459 .ConnectionQuiesced = netiucv_callback_connsusp,
460 .ConnectionResumed = netiucv_callback_connres,
461 .MessagePending = netiucv_callback_rx,
462 .MessageComplete = netiucv_callback_txdone
466 * Dummy NOP action for all statemachines
469 fsm_action_nop(fsm_instance *fi, int event, void *arg)
474 * Actions of the connection statemachine
475 *****************************************************************************/
478 * Helper function for conn_action_rx()
479 * Unpack a just received skb and hand it over to
482 * @param conn The connection where this skb has been received.
483 * @param pskb The received skb.
485 //static __inline__ void
487 netiucv_unpack_skb(struct iucv_connection *conn, struct sk_buff *pskb)
489 struct net_device *dev = conn->netdev;
490 struct netiucv_priv *privptr = dev->priv;
493 skb_put(pskb, NETIUCV_HDRLEN);
495 pskb->ip_summed = CHECKSUM_NONE;
496 pskb->protocol = ntohs(ETH_P_IP);
500 ll_header *header = (ll_header *)pskb->data;
502 if (header->next == 0)
505 skb_pull(pskb, NETIUCV_HDRLEN);
506 header->next -= offset;
507 offset += header->next;
508 header->next -= NETIUCV_HDRLEN;
509 if (skb_tailroom(pskb) < header->next) {
511 "%s: Illegal next field in iucv header: "
513 dev->name, header->next, skb_tailroom(pskb));
516 skb_put(pskb, header->next);
517 pskb->mac.raw = pskb->data;
518 skb = dev_alloc_skb(pskb->len);
521 "%s Out of memory in netiucv_unpack_skb\n",
523 privptr->stats.rx_dropped++;
526 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
527 skb->mac.raw = skb->data;
528 skb->dev = pskb->dev;
529 skb->protocol = pskb->protocol;
530 pskb->ip_summed = CHECKSUM_UNNECESSARY;
532 * Since receiving is always initiated from a tasklet (in iucv.c),
533 * we must use netif_rx_ni() instead of netif_rx()
536 dev->last_rx = jiffies;
537 privptr->stats.rx_packets++;
538 privptr->stats.rx_bytes += skb->len;
539 skb_pull(pskb, header->next);
540 skb_put(pskb, NETIUCV_HDRLEN);
545 conn_action_rx(fsm_instance *fi, int event, void *arg)
547 struct iucv_event *ev = (struct iucv_event *)arg;
548 struct iucv_connection *conn = ev->conn;
549 iucv_MessagePending *eib = (iucv_MessagePending *)ev->data;
550 struct netiucv_priv *privptr = (struct netiucv_priv *)conn->netdev->priv;
552 __u16 msglen = eib->ln1msg2.ipbfln1f;
555 pr_debug("%s() called\n", __FUNCTION__);
558 /* FRITZ: How to tell iucv LL to drop the msg? */
560 "Received data for unlinked connection\n");
563 if (msglen > conn->max_buffsize) {
564 /* FRITZ: How to tell iucv LL to drop the msg? */
565 privptr->stats.rx_dropped++;
568 conn->rx_buff->data = conn->rx_buff->tail = conn->rx_buff->head;
569 conn->rx_buff->len = 0;
570 rc = iucv_receive(conn->pathid, eib->ipmsgid, eib->iptrgcls,
571 conn->rx_buff->data, msglen, NULL, NULL, NULL);
572 if (rc != 0 || msglen < 5) {
573 privptr->stats.rx_errors++;
576 netiucv_unpack_skb(conn, conn->rx_buff);
580 conn_action_txdone(fsm_instance *fi, int event, void *arg)
582 struct iucv_event *ev = (struct iucv_event *)arg;
583 struct iucv_connection *conn = ev->conn;
584 iucv_MessageComplete *eib = (iucv_MessageComplete *)ev->data;
585 struct netiucv_priv *privptr = NULL;
586 /* Shut up, gcc! skb is always below 2G. */
587 __u32 single_flag = eib->ipmsgtag;
590 __u32 stat_maxcq = 0;
592 unsigned long saveflags;
595 pr_debug("%s() called\n", __FUNCTION__);
597 if (conn && conn->netdev && conn->netdev->priv)
598 privptr = (struct netiucv_priv *)conn->netdev->priv;
599 conn->prof.tx_pending--;
601 if ((skb = skb_dequeue(&conn->commit_queue))) {
602 atomic_dec(&skb->users);
603 dev_kfree_skb_any(skb);
605 privptr->stats.tx_packets++;
606 privptr->stats.tx_bytes +=
607 (skb->len - NETIUCV_HDRLEN
612 conn->tx_buff->data = conn->tx_buff->tail = conn->tx_buff->head;
613 conn->tx_buff->len = 0;
614 spin_lock_irqsave(&conn->collect_lock, saveflags);
615 while ((skb = skb_dequeue(&conn->collect_queue))) {
616 header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN;
617 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
619 memcpy(skb_put(conn->tx_buff, skb->len), skb->data, skb->len);
623 atomic_dec(&skb->users);
624 dev_kfree_skb_any(skb);
626 if (conn->collect_len > conn->prof.maxmulti)
627 conn->prof.maxmulti = conn->collect_len;
628 conn->collect_len = 0;
629 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
630 if (conn->tx_buff->len) {
634 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
637 conn->prof.send_stamp = xtime;
638 rc = iucv_send(conn->pathid, NULL, 0, 0, 0, 0,
639 conn->tx_buff->data, conn->tx_buff->len);
640 conn->prof.doios_multi++;
641 conn->prof.txlen += conn->tx_buff->len;
642 conn->prof.tx_pending++;
643 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
644 conn->prof.tx_max_pending = conn->prof.tx_pending;
646 conn->prof.tx_pending--;
647 fsm_newstate(fi, CONN_STATE_IDLE);
649 privptr->stats.tx_errors += txpackets;
650 printk(KERN_DEBUG "iucv_send returned %08x\n",
654 privptr->stats.tx_packets += txpackets;
655 privptr->stats.tx_bytes += txbytes;
657 if (stat_maxcq > conn->prof.maxcqueue)
658 conn->prof.maxcqueue = stat_maxcq;
661 fsm_newstate(fi, CONN_STATE_IDLE);
665 conn_action_connaccept(fsm_instance *fi, int event, void *arg)
667 struct iucv_event *ev = (struct iucv_event *)arg;
668 struct iucv_connection *conn = ev->conn;
669 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
670 struct net_device *netdev = conn->netdev;
671 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
676 pr_debug("%s() called\n", __FUNCTION__);
678 rc = iucv_accept(eib->ippathid, NETIUCV_QUEUELEN_DEFAULT, udata, 0,
679 conn->handle, conn, NULL, &msglimit);
682 "%s: IUCV accept failed with error %d\n",
686 fsm_newstate(fi, CONN_STATE_IDLE);
687 conn->pathid = eib->ippathid;
688 netdev->tx_queue_len = msglimit;
689 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
693 conn_action_connreject(fsm_instance *fi, int event, void *arg)
695 struct iucv_event *ev = (struct iucv_event *)arg;
696 struct iucv_connection *conn = ev->conn;
697 struct net_device *netdev = conn->netdev;
698 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
701 pr_debug("%s() called\n", __FUNCTION__);
703 iucv_sever(eib->ippathid, udata);
704 if (eib->ippathid != conn->pathid) {
706 "%s: IR pathid %d does not match original pathid %d\n",
707 netdev->name, eib->ippathid, conn->pathid);
708 iucv_sever(conn->pathid, udata);
713 conn_action_connack(fsm_instance *fi, int event, void *arg)
715 struct iucv_event *ev = (struct iucv_event *)arg;
716 struct iucv_connection *conn = ev->conn;
717 iucv_ConnectionComplete *eib = (iucv_ConnectionComplete *)ev->data;
718 struct net_device *netdev = conn->netdev;
719 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
721 pr_debug("%s() called\n", __FUNCTION__);
723 fsm_deltimer(&conn->timer);
724 fsm_newstate(fi, CONN_STATE_IDLE);
725 if (eib->ippathid != conn->pathid) {
727 "%s: IR pathid %d does not match original pathid %d\n",
728 netdev->name, eib->ippathid, conn->pathid);
729 conn->pathid = eib->ippathid;
731 netdev->tx_queue_len = eib->ipmsglim;
732 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
736 conn_action_conntimsev(fsm_instance *fi, int event, void *arg)
738 struct iucv_connection *conn = (struct iucv_connection *)arg;
741 pr_debug("%s() called\n", __FUNCTION__);
743 fsm_deltimer(&conn->timer);
744 iucv_sever(conn->pathid, udata);
745 fsm_newstate(fi, CONN_STATE_STARTWAIT);
749 conn_action_connsever(fsm_instance *fi, int event, void *arg)
751 struct iucv_event *ev = (struct iucv_event *)arg;
752 struct iucv_connection *conn = ev->conn;
753 struct net_device *netdev = conn->netdev;
754 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
757 pr_debug("%s() called\n", __FUNCTION__);
759 fsm_deltimer(&conn->timer);
760 iucv_sever(conn->pathid, udata);
761 printk(KERN_INFO "%s: Remote dropped connection\n",
763 fsm_newstate(fi, CONN_STATE_STARTWAIT);
764 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
768 conn_action_start(fsm_instance *fi, int event, void *arg)
770 struct iucv_event *ev = (struct iucv_event *)arg;
771 struct iucv_connection *conn = ev->conn;
774 __u8 iucvMagic[16] = {
775 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
776 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
779 pr_debug("%s() called\n", __FUNCTION__);
781 memcpy(iucvMagic, conn->netdev->name, IFNAMSIZ);
782 if (conn->handle == 0) {
784 iucv_register_program(iucvMagic, conn->userid, mask,
786 fsm_newstate(fi, CONN_STATE_STARTWAIT);
787 if (conn->handle <= 0) {
788 fsm_newstate(fi, CONN_STATE_REGERR);
793 pr_debug("%s('%s'): registered successfully\n",
794 conn->netdev->name, conn->userid);
797 pr_debug("%s('%s'): connecting ...\n",
798 conn->netdev->name, conn->userid);
800 /* We must set the state before calling iucv_connect because the callback
801 * handler could be called at any point after the connection request is
804 fsm_newstate(fi, CONN_STATE_SETUPWAIT);
805 rc = iucv_connect(&(conn->pathid), NETIUCV_QUEUELEN_DEFAULT, iucvMagic,
806 conn->userid, iucv_host, 0, NULL, &msglimit, conn->handle,
810 conn->netdev->tx_queue_len = msglimit;
811 fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC,
812 CONN_EVENT_TIMER, conn);
816 "%s: User %s is currently not available.\n",
818 netiucv_printname(conn->userid));
819 fsm_newstate(fi, CONN_STATE_STARTWAIT);
823 "%s: User %s is currently not ready.\n",
825 netiucv_printname(conn->userid));
826 fsm_newstate(fi, CONN_STATE_STARTWAIT);
830 "%s: Too many IUCV connections.\n",
832 fsm_newstate(fi, CONN_STATE_CONNERR);
836 "%s: User %s has too many IUCV connections.\n",
838 netiucv_printname(conn->userid));
839 fsm_newstate(fi, CONN_STATE_CONNERR);
843 "%s: No IUCV authorization in CP directory.\n",
845 fsm_newstate(fi, CONN_STATE_CONNERR);
849 "%s: iucv_connect returned error %d\n",
850 conn->netdev->name, rc);
851 fsm_newstate(fi, CONN_STATE_CONNERR);
854 iucv_unregister_program(conn->handle);
859 netiucv_purge_skb_queue(struct sk_buff_head *q)
863 while ((skb = skb_dequeue(q))) {
864 atomic_dec(&skb->users);
865 dev_kfree_skb_any(skb);
870 conn_action_stop(fsm_instance *fi, int event, void *arg)
872 struct iucv_event *ev = (struct iucv_event *)arg;
873 struct iucv_connection *conn = ev->conn;
874 struct net_device *netdev = conn->netdev;
875 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
877 pr_debug("%s() called\n", __FUNCTION__);
879 fsm_deltimer(&conn->timer);
880 fsm_newstate(fi, CONN_STATE_STOPPED);
881 netiucv_purge_skb_queue(&conn->collect_queue);
883 iucv_unregister_program(conn->handle);
885 netiucv_purge_skb_queue(&conn->commit_queue);
886 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
890 conn_action_inval(fsm_instance *fi, int event, void *arg)
892 struct iucv_event *ev = (struct iucv_event *)arg;
893 struct iucv_connection *conn = ev->conn;
894 struct net_device *netdev = conn->netdev;
897 "%s: Cannot connect without username\n",
901 static const fsm_node conn_fsm[] = {
902 { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval },
903 { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start },
905 { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop },
906 { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop },
907 { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop },
908 { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop },
909 { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop },
910 { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop },
911 { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop },
913 { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject },
914 { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
915 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
916 { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject },
917 { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject },
919 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack },
920 { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev },
922 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever },
923 { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever },
924 { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever },
926 { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx },
927 { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx },
929 { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone },
930 { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone },
933 static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node);
937 * Actions for interface - statemachine.
938 *****************************************************************************/
941 * Startup connection by sending CONN_EVENT_START to it.
943 * @param fi An instance of an interface statemachine.
944 * @param event The event, just happened.
945 * @param arg Generic pointer, casted from struct net_device * upon call.
948 dev_action_start(fsm_instance *fi, int event, void *arg)
950 struct net_device *dev = (struct net_device *)arg;
951 struct netiucv_priv *privptr = dev->priv;
952 struct iucv_event ev;
954 pr_debug("%s() called\n", __FUNCTION__);
956 ev.conn = privptr->conn;
957 fsm_newstate(fi, DEV_STATE_STARTWAIT);
958 fsm_event(privptr->conn->fsm, CONN_EVENT_START, &ev);
962 * Shutdown connection by sending CONN_EVENT_STOP to it.
964 * @param fi An instance of an interface statemachine.
965 * @param event The event, just happened.
966 * @param arg Generic pointer, casted from struct net_device * upon call.
969 dev_action_stop(fsm_instance *fi, int event, void *arg)
971 struct net_device *dev = (struct net_device *)arg;
972 struct netiucv_priv *privptr = dev->priv;
973 struct iucv_event ev;
975 pr_debug("%s() called\n", __FUNCTION__);
977 ev.conn = privptr->conn;
979 fsm_newstate(fi, DEV_STATE_STOPWAIT);
980 fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev);
984 * Called from connection statemachine
985 * when a connection is up and running.
987 * @param fi An instance of an interface statemachine.
988 * @param event The event, just happened.
989 * @param arg Generic pointer, casted from struct net_device * upon call.
992 dev_action_connup(fsm_instance *fi, int event, void *arg)
994 struct net_device *dev = (struct net_device *)arg;
996 pr_debug("%s() called\n", __FUNCTION__);
998 switch (fsm_getstate(fi)) {
999 case DEV_STATE_STARTWAIT:
1000 fsm_newstate(fi, DEV_STATE_RUNNING);
1002 "%s: connected with remote side\n",
1005 case DEV_STATE_STOPWAIT:
1007 "%s: got connection UP event during shutdown!!\n",
1014 * Called from connection statemachine
1015 * when a connection has been shutdown.
1017 * @param fi An instance of an interface statemachine.
1018 * @param event The event, just happened.
1019 * @param arg Generic pointer, casted from struct net_device * upon call.
1022 dev_action_conndown(fsm_instance *fi, int event, void *arg)
1024 pr_debug("%s() called\n", __FUNCTION__);
1026 switch (fsm_getstate(fi)) {
1027 case DEV_STATE_RUNNING:
1028 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1030 case DEV_STATE_STOPWAIT:
1031 fsm_newstate(fi, DEV_STATE_STOPPED);
1036 static const fsm_node dev_fsm[] = {
1037 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
1039 { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start },
1040 { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown },
1042 { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop },
1043 { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup },
1045 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
1046 { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown },
1047 { DEV_STATE_RUNNING, DEV_EVENT_CONUP, fsm_action_nop },
1050 static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node);
1053 * Transmit a packet.
1054 * This is a helper function for netiucv_tx().
1056 * @param conn Connection to be used for sending.
1057 * @param skb Pointer to struct sk_buff of packet to send.
1058 * The linklevel header has already been set up
1061 * @return 0 on success, -ERRNO on failure. (Never fails.)
1064 netiucv_transmit_skb(struct iucv_connection *conn, struct sk_buff *skb) {
1065 unsigned long saveflags;
1069 if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) {
1070 int l = skb->len + NETIUCV_HDRLEN;
1072 spin_lock_irqsave(&conn->collect_lock, saveflags);
1073 if (conn->collect_len + l >
1074 (conn->max_buffsize - NETIUCV_HDRLEN))
1077 atomic_inc(&skb->users);
1078 skb_queue_tail(&conn->collect_queue, skb);
1079 conn->collect_len += l;
1081 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
1083 struct sk_buff *nskb = skb;
1085 * Copy the skb to a new allocated skb in lowmem only if the
1086 * data is located above 2G in memory or tailroom is < 2.
1089 ((unsigned long)(skb->tail + NETIUCV_HDRLEN)) >> 31;
1091 if (hi || (skb_tailroom(skb) < 2)) {
1092 nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
1093 NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
1096 "%s: Could not allocate tx_skb\n",
1097 conn->netdev->name);
1101 skb_reserve(nskb, NETIUCV_HDRLEN);
1102 memcpy(skb_put(nskb, skb->len),
1103 skb->data, skb->len);
1108 * skb now is below 2G and has enough room. Add headers.
1110 header.next = nskb->len + NETIUCV_HDRLEN;
1111 memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1113 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1115 fsm_newstate(conn->fsm, CONN_STATE_TX);
1116 conn->prof.send_stamp = xtime;
1118 rc = iucv_send(conn->pathid, NULL, 0, 0, 1 /* single_flag */,
1119 0, nskb->data, nskb->len);
1120 /* Shut up, gcc! nskb is always below 2G. */
1121 conn->prof.doios_single++;
1122 conn->prof.txlen += skb->len;
1123 conn->prof.tx_pending++;
1124 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
1125 conn->prof.tx_max_pending = conn->prof.tx_pending;
1127 struct netiucv_priv *privptr;
1128 fsm_newstate(conn->fsm, CONN_STATE_IDLE);
1129 conn->prof.tx_pending--;
1130 privptr = (struct netiucv_priv *)conn->netdev->priv;
1132 privptr->stats.tx_errors++;
1134 dev_kfree_skb(nskb);
1137 * Remove our headers. They get added
1138 * again on retransmit.
1140 skb_pull(skb, NETIUCV_HDRLEN);
1141 skb_trim(skb, skb->len - NETIUCV_HDRLEN);
1143 printk(KERN_DEBUG "iucv_send returned %08x\n",
1148 atomic_inc(&nskb->users);
1149 skb_queue_tail(&conn->commit_queue, nskb);
1157 * Interface API for upper network layers
1158 *****************************************************************************/
1161 * Open an interface.
1162 * Called from generic network layer when ifconfig up is run.
1164 * @param dev Pointer to interface struct.
1166 * @return 0 on success, -ERRNO on failure. (Never fails.)
1169 netiucv_open(struct net_device *dev) {
1170 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_START, dev);
1175 * Close an interface.
1176 * Called from generic network layer when ifconfig down is run.
1178 * @param dev Pointer to interface struct.
1180 * @return 0 on success, -ERRNO on failure. (Never fails.)
1183 netiucv_close(struct net_device *dev) {
1184 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_STOP, dev);
1189 * Start transmission of a packet.
1190 * Called from generic network device layer.
1192 * @param skb Pointer to buffer containing the packet.
1193 * @param dev Pointer to interface struct.
1195 * @return 0 if packet consumed, !0 if packet rejected.
1196 * Note: If we return !0, then the packet is free'd by
1197 * the generic network layer.
1199 static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1202 struct netiucv_priv *privptr = dev->priv;
1205 * Some sanity checks ...
1208 printk(KERN_WARNING "%s: NULL sk_buff passed\n", dev->name);
1209 privptr->stats.tx_dropped++;
1212 if (skb_headroom(skb) < (NETIUCV_HDRLEN)) {
1214 "%s: Got sk_buff with head room < %ld bytes\n",
1215 dev->name, NETIUCV_HDRLEN);
1217 privptr->stats.tx_dropped++;
1222 * If connection is not running, try to restart it
1223 * and throw away packet.
1225 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1226 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1228 privptr->stats.tx_dropped++;
1229 privptr->stats.tx_errors++;
1230 privptr->stats.tx_carrier_errors++;
1234 if (netiucv_test_and_set_busy(dev))
1237 dev->trans_start = jiffies;
1238 if (netiucv_transmit_skb(privptr->conn, skb) != 0)
1240 netiucv_clear_busy(dev);
1245 * Returns interface statistics of a device.
1247 * @param dev Pointer to interface struct.
1249 * @return Pointer to stats struct of this interface.
1251 static struct net_device_stats *
1252 netiucv_stats (struct net_device * dev)
1254 return &((struct netiucv_priv *)dev->priv)->stats;
1258 * Sets MTU of an interface.
1260 * @param dev Pointer to interface struct.
1261 * @param new_mtu The new MTU to use for this interface.
1263 * @return 0 on success, -EINVAL if MTU is out of valid range.
1264 * (valid range is 576 .. NETIUCV_MTU_MAX).
1267 netiucv_change_mtu (struct net_device * dev, int new_mtu)
1269 if ((new_mtu < 576) || (new_mtu > NETIUCV_MTU_MAX))
1276 * attributes in sysfs
1277 *****************************************************************************/
1280 user_show (struct device *dev, char *buf)
1282 struct netiucv_priv *priv = dev->driver_data;
1284 return sprintf(buf, "%s\n", netiucv_printname(priv->conn->userid));
1288 user_write (struct device *dev, const char *buf, size_t count)
1290 struct netiucv_priv *priv = dev->driver_data;
1291 struct net_device *ndev = priv->conn->netdev;
1299 "netiucv: username too long (%d)!\n", (int)count);
1303 tmp = strsep((char **) &buf, "\n");
1304 for (i=0, p=tmp; i<8 && *p; i++, p++) {
1305 if (isalnum(*p) || (*p == '$'))
1307 else if (*p == '\n') {
1308 /* trailing lf, grr */
1312 "netiucv: Invalid character in username!\n");
1317 username[i++] = ' ';
1320 if (memcmp(username, priv->conn->userid, 8) != 0) {
1321 /* username changed */
1322 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1324 "netiucv: device %s active, connected to %s\n",
1325 dev->bus_id, priv->conn->userid);
1327 "netiucv: user cannot be updated\n");
1331 memcpy(priv->conn->userid, username, 9);
1337 static DEVICE_ATTR(user, 0644, user_show, user_write);
1340 buffer_show (struct device *dev, char *buf)
1342 struct netiucv_priv *priv = dev->driver_data;
1344 return sprintf(buf, "%d\n", priv->conn->max_buffsize);
1348 buffer_write (struct device *dev, const char *buf, size_t count)
1350 struct netiucv_priv *priv = dev->driver_data;
1351 struct net_device *ndev = priv->conn->netdev;
1358 bs1 = simple_strtoul(buf, &e, 0);
1360 if (e && (!isspace(*e))) {
1362 "netiucv: Invalid character in buffer!\n");
1365 if (bs1 > NETIUCV_BUFSIZE_MAX) {
1367 "netiucv: Given buffer size %d too large.\n",
1372 if ((ndev->flags & IFF_RUNNING) &&
1373 (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2)))
1375 if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN))
1378 priv->conn->max_buffsize = bs1;
1379 if (!(ndev->flags & IFF_RUNNING))
1380 ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN;
1381 priv->conn->flags |= CONN_FLAGS_BUFSIZE_CHANGED;
1387 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
1390 dev_fsm_show (struct device *dev, char *buf)
1392 struct netiucv_priv *priv = dev->driver_data;
1394 return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm));
1397 static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL);
1400 conn_fsm_show (struct device *dev, char *buf)
1402 struct netiucv_priv *priv = dev->driver_data;
1404 return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm));
1407 static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL);
1410 maxmulti_show (struct device *dev, char *buf)
1412 struct netiucv_priv *priv = dev->driver_data;
1414 return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti);
1418 maxmulti_write (struct device *dev, const char *buf, size_t count)
1420 struct netiucv_priv *priv = dev->driver_data;
1422 priv->conn->prof.maxmulti = 0;
1426 static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write);
1429 maxcq_show (struct device *dev, char *buf)
1431 struct netiucv_priv *priv = dev->driver_data;
1433 return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue);
1437 maxcq_write (struct device *dev, const char *buf, size_t count)
1439 struct netiucv_priv *priv = dev->driver_data;
1441 priv->conn->prof.maxcqueue = 0;
1445 static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write);
1448 sdoio_show (struct device *dev, char *buf)
1450 struct netiucv_priv *priv = dev->driver_data;
1452 return sprintf(buf, "%ld\n", priv->conn->prof.doios_single);
1456 sdoio_write (struct device *dev, const char *buf, size_t count)
1458 struct netiucv_priv *priv = dev->driver_data;
1460 priv->conn->prof.doios_single = 0;
1464 static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write);
1467 mdoio_show (struct device *dev, char *buf)
1469 struct netiucv_priv *priv = dev->driver_data;
1471 return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi);
1475 mdoio_write (struct device *dev, const char *buf, size_t count)
1477 struct netiucv_priv *priv = dev->driver_data;
1479 priv->conn->prof.doios_multi = 0;
1483 static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write);
1486 txlen_show (struct device *dev, char *buf)
1488 struct netiucv_priv *priv = dev->driver_data;
1490 return sprintf(buf, "%ld\n", priv->conn->prof.txlen);
1494 txlen_write (struct device *dev, const char *buf, size_t count)
1496 struct netiucv_priv *priv = dev->driver_data;
1498 priv->conn->prof.txlen = 0;
1502 static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write);
1505 txtime_show (struct device *dev, char *buf)
1507 struct netiucv_priv *priv = dev->driver_data;
1509 return sprintf(buf, "%ld\n", priv->conn->prof.tx_time);
1513 txtime_write (struct device *dev, const char *buf, size_t count)
1515 struct netiucv_priv *priv = dev->driver_data;
1517 priv->conn->prof.tx_time = 0;
1521 static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write);
1524 txpend_show (struct device *dev, char *buf)
1526 struct netiucv_priv *priv = dev->driver_data;
1528 return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending);
1532 txpend_write (struct device *dev, const char *buf, size_t count)
1534 struct netiucv_priv *priv = dev->driver_data;
1536 priv->conn->prof.tx_pending = 0;
1540 static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write);
1543 txmpnd_show (struct device *dev, char *buf)
1545 struct netiucv_priv *priv = dev->driver_data;
1547 return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending);
1551 txmpnd_write (struct device *dev, const char *buf, size_t count)
1553 struct netiucv_priv *priv = dev->driver_data;
1555 priv->conn->prof.tx_max_pending = 0;
1559 static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write);
1561 static struct attribute *netiucv_attrs[] = {
1562 &dev_attr_buffer.attr,
1563 &dev_attr_user.attr,
1567 static struct attribute_group netiucv_attr_group = {
1568 .attrs = netiucv_attrs,
1571 static struct attribute *netiucv_stat_attrs[] = {
1572 &dev_attr_device_fsm_state.attr,
1573 &dev_attr_connection_fsm_state.attr,
1574 &dev_attr_max_tx_buffer_used.attr,
1575 &dev_attr_max_chained_skbs.attr,
1576 &dev_attr_tx_single_write_ops.attr,
1577 &dev_attr_tx_multi_write_ops.attr,
1578 &dev_attr_netto_bytes.attr,
1579 &dev_attr_max_tx_io_time.attr,
1580 &dev_attr_tx_pending.attr,
1581 &dev_attr_tx_max_pending.attr,
1585 static struct attribute_group netiucv_stat_attr_group = {
1587 .attrs = netiucv_stat_attrs,
1591 netiucv_add_files(struct device *dev)
1595 pr_debug("%s() called\n", __FUNCTION__);
1597 ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group);
1600 ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group);
1602 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1607 netiucv_remove_files(struct device *dev)
1609 pr_debug("%s() called\n", __FUNCTION__);
1610 sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group);
1611 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1615 netiucv_register_device(struct net_device *ndev, int ifno)
1617 struct netiucv_priv *priv = ndev->priv;
1618 struct device *dev = kmalloc(sizeof(struct device), GFP_KERNEL);
1622 pr_debug("%s() called\n", __FUNCTION__);
1625 memset(dev, 0, sizeof(struct device));
1626 snprintf(dev->bus_id, BUS_ID_SIZE, "netiucv%x", ifno);
1627 dev->bus = &iucv_bus;
1628 dev->parent = iucv_root;
1630 * The release function could be called after the
1631 * module has been unloaded. It's _only_ task is to
1632 * free the struct. Therefore, we specify kfree()
1633 * directly here. (Probably a little bit obfuscating
1634 * but legitime ...).
1636 dev->release = (void (*)(struct device *))kfree;
1640 ret = device_register(dev);
1644 ret = netiucv_add_files(dev);
1647 dev->driver_data = priv;
1652 device_unregister(dev);
1657 netiucv_unregister_device(struct device *dev)
1659 pr_debug("%s() called\n", __FUNCTION__);
1660 netiucv_remove_files(dev);
1661 device_unregister(dev);
1665 * Allocate and initialize a new connection structure.
1666 * Add it to the list of connections;
1668 static struct iucv_connection *
1669 netiucv_new_connection(struct net_device *dev, char *username)
1671 struct iucv_connection **clist = &connections;
1672 struct iucv_connection *conn =
1673 (struct iucv_connection *)
1674 kmalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1677 memset(conn, 0, sizeof(struct iucv_connection));
1678 skb_queue_head_init(&conn->collect_queue);
1679 skb_queue_head_init(&conn->commit_queue);
1680 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1683 conn->rx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1684 GFP_KERNEL | GFP_DMA);
1685 if (!conn->rx_buff) {
1689 conn->tx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1690 GFP_KERNEL | GFP_DMA);
1691 if (!conn->tx_buff) {
1692 kfree_skb(conn->rx_buff);
1696 conn->fsm = init_fsm("netiucvconn", conn_state_names,
1697 conn_event_names, NR_CONN_STATES,
1698 NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN,
1701 kfree_skb(conn->tx_buff);
1702 kfree_skb(conn->rx_buff);
1706 fsm_settimer(conn->fsm, &conn->timer);
1707 fsm_newstate(conn->fsm, CONN_STATE_INVALID);
1710 memcpy(conn->userid, username, 9);
1711 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1714 conn->next = *clist;
1721 * Release a connection structure and remove it from the
1722 * list of connections.
1725 netiucv_remove_connection(struct iucv_connection *conn)
1727 struct iucv_connection **clist = &connections;
1729 pr_debug("%s() called\n", __FUNCTION__);
1734 if (*clist == conn) {
1735 *clist = conn->next;
1736 if (conn->handle != 0) {
1737 iucv_unregister_program(conn->handle);
1740 fsm_deltimer(&conn->timer);
1741 kfree_fsm(conn->fsm);
1742 kfree_skb(conn->rx_buff);
1743 kfree_skb(conn->tx_buff);
1746 clist = &((*clist)->next);
1751 * Release everything of a net device.
1754 netiucv_free_netdevice(struct net_device *dev)
1756 struct netiucv_priv *privptr;
1758 pr_debug("%s() called\n", __FUNCTION__);
1763 privptr = (struct netiucv_priv *)dev->priv;
1766 fsm_deltimer(&privptr->timer);
1768 netiucv_remove_connection(privptr->conn);
1770 kfree_fsm(privptr->fsm);
1771 privptr->conn = 0; privptr->fsm = 0;
1772 /* privptr gets freed by free_netdev() */
1778 * Initialize a net device. (Called from kernel in alloc_netdev())
1781 netiucv_setup_netdevice(struct net_device *dev)
1783 memset(dev->priv, 0, sizeof(struct netiucv_priv));
1785 dev->mtu = NETIUCV_MTU_DEFAULT;
1786 dev->hard_start_xmit = netiucv_tx;
1787 dev->open = netiucv_open;
1788 dev->stop = netiucv_close;
1789 dev->get_stats = netiucv_stats;
1790 dev->change_mtu = netiucv_change_mtu;
1791 dev->destructor = netiucv_free_netdevice;
1792 dev->hard_header_len = NETIUCV_HDRLEN;
1794 dev->type = ARPHRD_SLIP;
1795 dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT;
1796 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1797 SET_MODULE_OWNER(dev);
1801 * Allocate and initialize everything of a net device.
1803 static struct net_device *
1804 netiucv_init_netdevice(int ifno, char *username)
1806 struct netiucv_priv *privptr;
1807 struct net_device *dev;
1809 dev = alloc_netdev(sizeof(struct netiucv_priv), "",
1810 netiucv_setup_netdevice);
1813 sprintf(dev->name, "iucv%d", ifno);
1815 privptr = (struct netiucv_priv *)dev->priv;
1816 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
1817 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
1818 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
1819 if (privptr->fsm == NULL) {
1823 privptr->conn = netiucv_new_connection(dev, username);
1824 if (!privptr->conn) {
1825 kfree_fsm(privptr->fsm);
1829 fsm_settimer(privptr->fsm, &privptr->timer);
1830 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
1836 conn_write(struct device_driver *drv, const char *buf, size_t count)
1841 struct net_device *dev;
1845 "netiucv: username too long (%d)!\n", (int)count);
1849 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) {
1850 if (isalnum(*p) || (*p == '$'))
1852 else if (*p == '\n') {
1853 /* trailing lf, grr */
1857 "netiucv: Invalid character in username!\n");
1862 username[i++] = ' ';
1864 dev = netiucv_init_netdevice(ifno, username);
1867 "netiucv: Could not allocate network device structure "
1868 "for user '%s'\n", netiucv_printname(username));
1872 if ((ret = netiucv_register_device(dev, ifno)))
1875 SET_NETDEV_DEV(dev, (struct device*)((struct netiucv_priv*)dev->priv)->dev);
1876 if ((ret = register_netdev(dev))) {
1877 netiucv_unregister_device((struct device*)((struct netiucv_priv*)dev->priv)->dev);
1880 printk(KERN_INFO "%s: '%s'\n", dev->name, netiucv_printname(username));
1887 "netiucv: Could not register '%s'\n", dev->name);
1888 netiucv_free_netdevice(dev);
1892 DRIVER_ATTR(connection, 0200, NULL, conn_write);
1894 static struct device_driver netiucv_driver = {
1900 netiucv_banner(void)
1902 char vbuf[] = "$Revision: 1.51 $";
1903 char *version = vbuf;
1905 if ((version = strchr(version, ':'))) {
1906 char *p = strchr(version + 1, '$');
1911 printk(KERN_INFO "NETIUCV driver Version%s initialized\n", version);
1917 while (connections) {
1918 struct net_device *ndev = connections->netdev;
1919 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv;
1920 struct device *dev = priv->dev;
1922 unregister_netdev(ndev);
1923 netiucv_unregister_device(dev);
1926 driver_remove_file(&netiucv_driver, &driver_attr_connection);
1927 driver_unregister(&netiucv_driver);
1929 printk(KERN_INFO "NETIUCV driver unloaded\n");
1938 ret = driver_register(&netiucv_driver);
1940 printk(KERN_ERR "NETIUCV: failed to register driver.\n");
1944 /* Add entry for specifying connections. */
1945 ret = driver_create_file(&netiucv_driver, &driver_attr_connection);
1950 printk(KERN_ERR "NETIUCV: failed to add driver attribute.\n");
1951 driver_unregister(&netiucv_driver);
1956 module_init(netiucv_init);
1957 module_exit(netiucv_exit);
1958 MODULE_LICENSE("GPL");