2 * $Id: netiucv.c,v 1.53 2004/05/07 14:29:37 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.53 $
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>
63 #include <asm/ebcdic.h>
69 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
70 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
74 * Per connection profiling data
76 struct connection_profile {
77 unsigned long maxmulti;
78 unsigned long maxcqueue;
79 unsigned long doios_single;
80 unsigned long doios_multi;
82 unsigned long tx_time;
83 struct timespec send_stamp;
84 unsigned long tx_pending;
85 unsigned long tx_max_pending;
89 * Representation of one iucv connection
91 struct iucv_connection {
92 struct iucv_connection *next;
95 struct sk_buff *rx_buff;
96 struct sk_buff *tx_buff;
97 struct sk_buff_head collect_queue;
98 struct sk_buff_head commit_queue;
99 spinlock_t collect_lock;
105 struct net_device *netdev;
106 struct connection_profile prof;
110 #define CONN_FLAGS_BUFSIZE_CHANGED 1
113 * Linked list of all connection structs.
115 static struct iucv_connection *connections;
118 * Representation of event-data for the
119 * connection state machine.
122 struct iucv_connection *conn;
127 * Private part of the network device structure
129 struct netiucv_priv {
130 struct net_device_stats stats;
133 struct iucv_connection *conn;
139 * Link level header for a packet.
141 typedef struct ll_header_t {
145 #define NETIUCV_HDRLEN (sizeof(ll_header))
146 #define NETIUCV_BUFSIZE_MAX 32768
147 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
148 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
149 #define NETIUCV_MTU_DEFAULT 9216
150 #define NETIUCV_QUEUELEN_DEFAULT 50
151 #define NETIUCV_TIMEOUT_5SEC 5000
154 * Compatibility macros for busy handling
155 * of network devices.
157 static __inline__ void netiucv_clear_busy(struct net_device *dev)
159 clear_bit(0, &(((struct netiucv_priv *)dev->priv)->tbusy));
160 netif_wake_queue(dev);
163 static __inline__ int netiucv_test_and_set_busy(struct net_device *dev)
165 netif_stop_queue(dev);
166 return test_and_set_bit(0, &((struct netiucv_priv *)dev->priv)->tbusy);
169 static __u8 iucv_host[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
170 //static __u8 iucvMagic[16] = {
171 // 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
172 // 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
176 * This mask means the 16-byte IUCV "magic" and the origin userid must
177 * match exactly as specified in order to give connection_pending()
180 static __u8 mask[] = {
181 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
182 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
183 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
187 * Convert an iucv userId to its printable
188 * form (strip whitespace at end).
190 * @param An iucv userId
192 * @returns The printable string (static data!!)
194 static __inline__ char *
195 netiucv_printname(char *name)
199 memcpy(tmp, name, 8);
201 while (*p && (!isspace(*p)))
208 * States of the interface statemachine.
216 * MUST be always the last element!!
221 static const char *dev_state_names[] = {
229 * Events of the interface statemachine.
238 * MUST be always the last element!!
243 static const char *dev_event_names[] = {
252 * Events of the connection statemachine
256 * Events, representing callbacks from
257 * lowlevel iucv layer)
268 * Events, representing errors return codes from
269 * calls to lowlevel iucv layer
273 * Event, representing timer expiry.
278 * Events, representing commands from upper levels.
284 * MUST be always the last element!!
289 static const char *conn_event_names[] = {
290 "Remote connection request",
291 "Remote connection acknowledge",
292 "Remote connection reject",
293 "Connection suspended",
294 "Connection resumed",
305 * States of the connection statemachine.
309 * Connection not assigned to any device,
310 * initial state, invalid
315 * Userid assigned but not operating
320 * Connection registered,
321 * no connection request sent yet,
322 * no connection request received
324 CONN_STATE_STARTWAIT,
327 * Connection registered and connection request sent,
328 * no acknowledge and no connection request received yet.
330 CONN_STATE_SETUPWAIT,
333 * Connection up and running idle
338 * Data sent, awaiting CONN_EVENT_TXDONE
343 * Error during registration.
348 * Error during registration.
353 * MUST be always the last element!!
358 static const char *conn_state_names[] = {
366 "Registration error",
372 * Callback-wrappers, called from lowlevel iucv layer.
373 *****************************************************************************/
376 netiucv_callback_rx(iucv_MessagePending *eib, void *pgm_data)
378 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
379 struct iucv_event ev;
382 ev.data = (void *)eib;
384 fsm_event(conn->fsm, CONN_EVENT_RX, &ev);
388 netiucv_callback_txdone(iucv_MessageComplete *eib, void *pgm_data)
390 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
391 struct iucv_event ev;
394 ev.data = (void *)eib;
395 fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev);
399 netiucv_callback_connack(iucv_ConnectionComplete *eib, void *pgm_data)
401 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
402 struct iucv_event ev;
405 ev.data = (void *)eib;
406 fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, &ev);
410 netiucv_callback_connreq(iucv_ConnectionPending *eib, void *pgm_data)
412 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
413 struct iucv_event ev;
416 ev.data = (void *)eib;
417 fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev);
421 netiucv_callback_connrej(iucv_ConnectionSevered *eib, void *pgm_data)
423 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
424 struct iucv_event ev;
427 ev.data = (void *)eib;
428 fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, &ev);
432 netiucv_callback_connsusp(iucv_ConnectionQuiesced *eib, void *pgm_data)
434 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
435 struct iucv_event ev;
438 ev.data = (void *)eib;
439 fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, &ev);
443 netiucv_callback_connres(iucv_ConnectionResumed *eib, void *pgm_data)
445 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
446 struct iucv_event ev;
449 ev.data = (void *)eib;
450 fsm_event(conn->fsm, CONN_EVENT_CONN_RES, &ev);
453 static iucv_interrupt_ops_t netiucv_ops = {
454 .ConnectionPending = netiucv_callback_connreq,
455 .ConnectionComplete = netiucv_callback_connack,
456 .ConnectionSevered = netiucv_callback_connrej,
457 .ConnectionQuiesced = netiucv_callback_connsusp,
458 .ConnectionResumed = netiucv_callback_connres,
459 .MessagePending = netiucv_callback_rx,
460 .MessageComplete = netiucv_callback_txdone
464 * Dummy NOP action for all statemachines
467 fsm_action_nop(fsm_instance *fi, int event, void *arg)
472 * Actions of the connection statemachine
473 *****************************************************************************/
476 * Helper function for conn_action_rx()
477 * Unpack a just received skb and hand it over to
480 * @param conn The connection where this skb has been received.
481 * @param pskb The received skb.
483 //static __inline__ void
485 netiucv_unpack_skb(struct iucv_connection *conn, struct sk_buff *pskb)
487 struct net_device *dev = conn->netdev;
488 struct netiucv_priv *privptr = dev->priv;
491 skb_put(pskb, NETIUCV_HDRLEN);
493 pskb->ip_summed = CHECKSUM_NONE;
494 pskb->protocol = ntohs(ETH_P_IP);
498 ll_header *header = (ll_header *)pskb->data;
500 if (header->next == 0)
503 skb_pull(pskb, NETIUCV_HDRLEN);
504 header->next -= offset;
505 offset += header->next;
506 header->next -= NETIUCV_HDRLEN;
507 if (skb_tailroom(pskb) < header->next) {
509 "%s: Illegal next field in iucv header: "
511 dev->name, header->next, skb_tailroom(pskb));
514 skb_put(pskb, header->next);
515 pskb->mac.raw = pskb->data;
516 skb = dev_alloc_skb(pskb->len);
519 "%s Out of memory in netiucv_unpack_skb\n",
521 privptr->stats.rx_dropped++;
524 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
525 skb->mac.raw = skb->data;
526 skb->dev = pskb->dev;
527 skb->protocol = pskb->protocol;
528 pskb->ip_summed = CHECKSUM_UNNECESSARY;
530 * Since receiving is always initiated from a tasklet (in iucv.c),
531 * we must use netif_rx_ni() instead of netif_rx()
534 dev->last_rx = jiffies;
535 privptr->stats.rx_packets++;
536 privptr->stats.rx_bytes += skb->len;
537 skb_pull(pskb, header->next);
538 skb_put(pskb, NETIUCV_HDRLEN);
543 conn_action_rx(fsm_instance *fi, int event, void *arg)
545 struct iucv_event *ev = (struct iucv_event *)arg;
546 struct iucv_connection *conn = ev->conn;
547 iucv_MessagePending *eib = (iucv_MessagePending *)ev->data;
548 struct netiucv_priv *privptr = (struct netiucv_priv *)conn->netdev->priv;
550 __u32 msglen = eib->ln1msg2.ipbfln1f;
553 pr_debug("%s() called\n", __FUNCTION__);
556 /* FRITZ: How to tell iucv LL to drop the msg? */
558 "Received data for unlinked connection\n");
561 if (msglen > conn->max_buffsize) {
562 /* FRITZ: How to tell iucv LL to drop the msg? */
563 privptr->stats.rx_dropped++;
566 conn->rx_buff->data = conn->rx_buff->tail = conn->rx_buff->head;
567 conn->rx_buff->len = 0;
568 rc = iucv_receive(conn->pathid, eib->ipmsgid, eib->iptrgcls,
569 conn->rx_buff->data, msglen, NULL, NULL, NULL);
570 if (rc != 0 || msglen < 5) {
571 privptr->stats.rx_errors++;
572 printk(KERN_INFO "iucv_receive returned %08x\n", rc);
575 netiucv_unpack_skb(conn, conn->rx_buff);
579 conn_action_txdone(fsm_instance *fi, int event, void *arg)
581 struct iucv_event *ev = (struct iucv_event *)arg;
582 struct iucv_connection *conn = ev->conn;
583 iucv_MessageComplete *eib = (iucv_MessageComplete *)ev->data;
584 struct netiucv_priv *privptr = NULL;
585 /* Shut up, gcc! skb is always below 2G. */
586 __u32 single_flag = eib->ipmsgtag;
589 __u32 stat_maxcq = 0;
591 unsigned long saveflags;
594 pr_debug("%s() called\n", __FUNCTION__);
596 if (conn && conn->netdev && conn->netdev->priv)
597 privptr = (struct netiucv_priv *)conn->netdev->priv;
598 conn->prof.tx_pending--;
600 if ((skb = skb_dequeue(&conn->commit_queue))) {
601 atomic_dec(&skb->users);
602 dev_kfree_skb_any(skb);
604 privptr->stats.tx_packets++;
605 privptr->stats.tx_bytes +=
606 (skb->len - NETIUCV_HDRLEN
611 conn->tx_buff->data = conn->tx_buff->tail = conn->tx_buff->head;
612 conn->tx_buff->len = 0;
613 spin_lock_irqsave(&conn->collect_lock, saveflags);
614 while ((skb = skb_dequeue(&conn->collect_queue))) {
615 header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN;
616 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
618 memcpy(skb_put(conn->tx_buff, skb->len), skb->data, skb->len);
622 atomic_dec(&skb->users);
623 dev_kfree_skb_any(skb);
625 if (conn->collect_len > conn->prof.maxmulti)
626 conn->prof.maxmulti = conn->collect_len;
627 conn->collect_len = 0;
628 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
629 if (conn->tx_buff->len) {
633 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
636 conn->prof.send_stamp = xtime;
637 rc = iucv_send(conn->pathid, NULL, 0, 0, 0, 0,
638 conn->tx_buff->data, conn->tx_buff->len);
639 conn->prof.doios_multi++;
640 conn->prof.txlen += conn->tx_buff->len;
641 conn->prof.tx_pending++;
642 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
643 conn->prof.tx_max_pending = conn->prof.tx_pending;
645 conn->prof.tx_pending--;
646 fsm_newstate(fi, CONN_STATE_IDLE);
648 privptr->stats.tx_errors += txpackets;
649 printk(KERN_INFO "iucv_send returned %08x\n",
653 privptr->stats.tx_packets += txpackets;
654 privptr->stats.tx_bytes += txbytes;
656 if (stat_maxcq > conn->prof.maxcqueue)
657 conn->prof.maxcqueue = stat_maxcq;
660 fsm_newstate(fi, CONN_STATE_IDLE);
664 conn_action_connaccept(fsm_instance *fi, int event, void *arg)
666 struct iucv_event *ev = (struct iucv_event *)arg;
667 struct iucv_connection *conn = ev->conn;
668 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
669 struct net_device *netdev = conn->netdev;
670 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
675 pr_debug("%s() called\n", __FUNCTION__);
677 rc = iucv_accept(eib->ippathid, NETIUCV_QUEUELEN_DEFAULT, udata, 0,
678 conn->handle, conn, NULL, &msglimit);
681 "%s: IUCV accept failed with error %d\n",
685 fsm_newstate(fi, CONN_STATE_IDLE);
686 conn->pathid = eib->ippathid;
687 netdev->tx_queue_len = msglimit;
688 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
692 conn_action_connreject(fsm_instance *fi, int event, void *arg)
694 struct iucv_event *ev = (struct iucv_event *)arg;
695 struct iucv_connection *conn = ev->conn;
696 struct net_device *netdev = conn->netdev;
697 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
700 pr_debug("%s() called\n", __FUNCTION__);
702 iucv_sever(eib->ippathid, udata);
703 if (eib->ippathid != conn->pathid) {
705 "%s: IR pathid %d does not match original pathid %d\n",
706 netdev->name, eib->ippathid, conn->pathid);
707 iucv_sever(conn->pathid, udata);
712 conn_action_connack(fsm_instance *fi, int event, void *arg)
714 struct iucv_event *ev = (struct iucv_event *)arg;
715 struct iucv_connection *conn = ev->conn;
716 iucv_ConnectionComplete *eib = (iucv_ConnectionComplete *)ev->data;
717 struct net_device *netdev = conn->netdev;
718 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
720 pr_debug("%s() called\n", __FUNCTION__);
722 fsm_deltimer(&conn->timer);
723 fsm_newstate(fi, CONN_STATE_IDLE);
724 if (eib->ippathid != conn->pathid) {
726 "%s: IR pathid %d does not match original pathid %d\n",
727 netdev->name, eib->ippathid, conn->pathid);
728 conn->pathid = eib->ippathid;
730 netdev->tx_queue_len = eib->ipmsglim;
731 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
735 conn_action_conntimsev(fsm_instance *fi, int event, void *arg)
737 struct iucv_connection *conn = (struct iucv_connection *)arg;
740 pr_debug("%s() called\n", __FUNCTION__);
742 fsm_deltimer(&conn->timer);
743 iucv_sever(conn->pathid, udata);
744 fsm_newstate(fi, CONN_STATE_STARTWAIT);
748 conn_action_connsever(fsm_instance *fi, int event, void *arg)
750 struct iucv_event *ev = (struct iucv_event *)arg;
751 struct iucv_connection *conn = ev->conn;
752 struct net_device *netdev = conn->netdev;
753 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
756 pr_debug("%s() called\n", __FUNCTION__);
758 fsm_deltimer(&conn->timer);
759 iucv_sever(conn->pathid, udata);
760 printk(KERN_INFO "%s: Remote dropped connection\n",
762 fsm_newstate(fi, CONN_STATE_STARTWAIT);
763 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
767 conn_action_start(fsm_instance *fi, int event, void *arg)
769 struct iucv_event *ev = (struct iucv_event *)arg;
770 struct iucv_connection *conn = ev->conn;
773 __u8 iucvMagic[16] = {
774 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
775 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
778 pr_debug("%s() called\n", __FUNCTION__);
780 len = (IFNAMSIZ < sizeof(conn->netdev->name)) ?
781 IFNAMSIZ : sizeof(conn->netdev->name);
782 memcpy(iucvMagic, conn->netdev->name, len);
783 ASCEBC (iucvMagic, len);
784 if (conn->handle == 0) {
786 iucv_register_program(iucvMagic, conn->userid, mask,
788 fsm_newstate(fi, CONN_STATE_STARTWAIT);
789 if (conn->handle <= 0) {
790 fsm_newstate(fi, CONN_STATE_REGERR);
795 pr_debug("%s('%s'): registered successfully\n",
796 conn->netdev->name, conn->userid);
799 pr_debug("%s('%s'): connecting ...\n",
800 conn->netdev->name, conn->userid);
802 /* We must set the state before calling iucv_connect because the callback
803 * handler could be called at any point after the connection request is
806 fsm_newstate(fi, CONN_STATE_SETUPWAIT);
807 rc = iucv_connect(&(conn->pathid), NETIUCV_QUEUELEN_DEFAULT, iucvMagic,
808 conn->userid, iucv_host, 0, NULL, &msglimit, conn->handle,
812 conn->netdev->tx_queue_len = msglimit;
813 fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC,
814 CONN_EVENT_TIMER, conn);
818 "%s: User %s is currently not available.\n",
820 netiucv_printname(conn->userid));
821 fsm_newstate(fi, CONN_STATE_STARTWAIT);
825 "%s: User %s is currently not ready.\n",
827 netiucv_printname(conn->userid));
828 fsm_newstate(fi, CONN_STATE_STARTWAIT);
832 "%s: Too many IUCV connections.\n",
834 fsm_newstate(fi, CONN_STATE_CONNERR);
838 "%s: User %s has too many IUCV connections.\n",
840 netiucv_printname(conn->userid));
841 fsm_newstate(fi, CONN_STATE_CONNERR);
845 "%s: No IUCV authorization in CP directory.\n",
847 fsm_newstate(fi, CONN_STATE_CONNERR);
851 "%s: iucv_connect returned error %d\n",
852 conn->netdev->name, rc);
853 fsm_newstate(fi, CONN_STATE_CONNERR);
856 iucv_unregister_program(conn->handle);
861 netiucv_purge_skb_queue(struct sk_buff_head *q)
865 while ((skb = skb_dequeue(q))) {
866 atomic_dec(&skb->users);
867 dev_kfree_skb_any(skb);
872 conn_action_stop(fsm_instance *fi, int event, void *arg)
874 struct iucv_event *ev = (struct iucv_event *)arg;
875 struct iucv_connection *conn = ev->conn;
876 struct net_device *netdev = conn->netdev;
877 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
879 pr_debug("%s() called\n", __FUNCTION__);
881 fsm_deltimer(&conn->timer);
882 fsm_newstate(fi, CONN_STATE_STOPPED);
883 netiucv_purge_skb_queue(&conn->collect_queue);
885 iucv_unregister_program(conn->handle);
887 netiucv_purge_skb_queue(&conn->commit_queue);
888 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
892 conn_action_inval(fsm_instance *fi, int event, void *arg)
894 struct iucv_event *ev = (struct iucv_event *)arg;
895 struct iucv_connection *conn = ev->conn;
896 struct net_device *netdev = conn->netdev;
899 "%s: Cannot connect without username\n",
903 static const fsm_node conn_fsm[] = {
904 { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval },
905 { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start },
907 { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop },
908 { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop },
909 { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop },
910 { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop },
911 { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop },
912 { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop },
913 { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop },
915 { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject },
916 { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
917 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
918 { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject },
919 { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject },
921 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack },
922 { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev },
924 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever },
925 { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever },
926 { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever },
928 { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx },
929 { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx },
931 { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone },
932 { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone },
935 static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node);
939 * Actions for interface - statemachine.
940 *****************************************************************************/
943 * Startup connection by sending CONN_EVENT_START to it.
945 * @param fi An instance of an interface statemachine.
946 * @param event The event, just happened.
947 * @param arg Generic pointer, casted from struct net_device * upon call.
950 dev_action_start(fsm_instance *fi, int event, void *arg)
952 struct net_device *dev = (struct net_device *)arg;
953 struct netiucv_priv *privptr = dev->priv;
954 struct iucv_event ev;
956 pr_debug("%s() called\n", __FUNCTION__);
958 ev.conn = privptr->conn;
959 fsm_newstate(fi, DEV_STATE_STARTWAIT);
960 fsm_event(privptr->conn->fsm, CONN_EVENT_START, &ev);
964 * Shutdown connection by sending CONN_EVENT_STOP to it.
966 * @param fi An instance of an interface statemachine.
967 * @param event The event, just happened.
968 * @param arg Generic pointer, casted from struct net_device * upon call.
971 dev_action_stop(fsm_instance *fi, int event, void *arg)
973 struct net_device *dev = (struct net_device *)arg;
974 struct netiucv_priv *privptr = dev->priv;
975 struct iucv_event ev;
977 pr_debug("%s() called\n", __FUNCTION__);
979 ev.conn = privptr->conn;
981 fsm_newstate(fi, DEV_STATE_STOPWAIT);
982 fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev);
986 * Called from connection statemachine
987 * when a connection is up and running.
989 * @param fi An instance of an interface statemachine.
990 * @param event The event, just happened.
991 * @param arg Generic pointer, casted from struct net_device * upon call.
994 dev_action_connup(fsm_instance *fi, int event, void *arg)
996 struct net_device *dev = (struct net_device *)arg;
997 struct netiucv_priv *privptr = dev->priv;
999 pr_debug("%s() called\n", __FUNCTION__);
1001 switch (fsm_getstate(fi)) {
1002 case DEV_STATE_STARTWAIT:
1003 fsm_newstate(fi, DEV_STATE_RUNNING);
1005 "%s: connected with remote side %s\n",
1006 dev->name, privptr->conn->userid);
1008 case DEV_STATE_STOPWAIT:
1010 "%s: got connection UP event during shutdown!!\n",
1017 * Called from connection statemachine
1018 * when a connection has been shutdown.
1020 * @param fi An instance of an interface statemachine.
1021 * @param event The event, just happened.
1022 * @param arg Generic pointer, casted from struct net_device * upon call.
1025 dev_action_conndown(fsm_instance *fi, int event, void *arg)
1027 pr_debug("%s() called\n", __FUNCTION__);
1029 switch (fsm_getstate(fi)) {
1030 case DEV_STATE_RUNNING:
1031 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1033 case DEV_STATE_STOPWAIT:
1034 fsm_newstate(fi, DEV_STATE_STOPPED);
1039 static const fsm_node dev_fsm[] = {
1040 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
1042 { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start },
1043 { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown },
1045 { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop },
1046 { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup },
1048 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
1049 { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown },
1050 { DEV_STATE_RUNNING, DEV_EVENT_CONUP, fsm_action_nop },
1053 static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node);
1056 * Transmit a packet.
1057 * This is a helper function for netiucv_tx().
1059 * @param conn Connection to be used for sending.
1060 * @param skb Pointer to struct sk_buff of packet to send.
1061 * The linklevel header has already been set up
1064 * @return 0 on success, -ERRNO on failure. (Never fails.)
1067 netiucv_transmit_skb(struct iucv_connection *conn, struct sk_buff *skb) {
1068 unsigned long saveflags;
1072 if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) {
1073 int l = skb->len + NETIUCV_HDRLEN;
1075 spin_lock_irqsave(&conn->collect_lock, saveflags);
1076 if (conn->collect_len + l >
1077 (conn->max_buffsize - NETIUCV_HDRLEN))
1080 atomic_inc(&skb->users);
1081 skb_queue_tail(&conn->collect_queue, skb);
1082 conn->collect_len += l;
1084 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
1086 struct sk_buff *nskb = skb;
1088 * Copy the skb to a new allocated skb in lowmem only if the
1089 * data is located above 2G in memory or tailroom is < 2.
1092 ((unsigned long)(skb->tail + NETIUCV_HDRLEN)) >> 31;
1094 if (hi || (skb_tailroom(skb) < 2)) {
1095 nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
1096 NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
1099 "%s: Could not allocate tx_skb\n",
1100 conn->netdev->name);
1104 skb_reserve(nskb, NETIUCV_HDRLEN);
1105 memcpy(skb_put(nskb, skb->len),
1106 skb->data, skb->len);
1111 * skb now is below 2G and has enough room. Add headers.
1113 header.next = nskb->len + NETIUCV_HDRLEN;
1114 memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1116 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1118 fsm_newstate(conn->fsm, CONN_STATE_TX);
1119 conn->prof.send_stamp = xtime;
1121 rc = iucv_send(conn->pathid, NULL, 0, 0, 1 /* single_flag */,
1122 0, nskb->data, nskb->len);
1123 /* Shut up, gcc! nskb is always below 2G. */
1124 conn->prof.doios_single++;
1125 conn->prof.txlen += skb->len;
1126 conn->prof.tx_pending++;
1127 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
1128 conn->prof.tx_max_pending = conn->prof.tx_pending;
1130 struct netiucv_priv *privptr;
1131 fsm_newstate(conn->fsm, CONN_STATE_IDLE);
1132 conn->prof.tx_pending--;
1133 privptr = (struct netiucv_priv *)conn->netdev->priv;
1135 privptr->stats.tx_errors++;
1137 dev_kfree_skb(nskb);
1140 * Remove our headers. They get added
1141 * again on retransmit.
1143 skb_pull(skb, NETIUCV_HDRLEN);
1144 skb_trim(skb, skb->len - NETIUCV_HDRLEN);
1146 printk(KERN_INFO "iucv_send returned %08x\n",
1151 atomic_inc(&nskb->users);
1152 skb_queue_tail(&conn->commit_queue, nskb);
1160 * Interface API for upper network layers
1161 *****************************************************************************/
1164 * Open an interface.
1165 * Called from generic network layer when ifconfig up is run.
1167 * @param dev Pointer to interface struct.
1169 * @return 0 on success, -ERRNO on failure. (Never fails.)
1172 netiucv_open(struct net_device *dev) {
1173 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_START, dev);
1178 * Close an interface.
1179 * Called from generic network layer when ifconfig down is run.
1181 * @param dev Pointer to interface struct.
1183 * @return 0 on success, -ERRNO on failure. (Never fails.)
1186 netiucv_close(struct net_device *dev) {
1187 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_STOP, dev);
1192 * Start transmission of a packet.
1193 * Called from generic network device layer.
1195 * @param skb Pointer to buffer containing the packet.
1196 * @param dev Pointer to interface struct.
1198 * @return 0 if packet consumed, !0 if packet rejected.
1199 * Note: If we return !0, then the packet is free'd by
1200 * the generic network layer.
1202 static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1205 struct netiucv_priv *privptr = dev->priv;
1208 * Some sanity checks ...
1211 printk(KERN_WARNING "%s: NULL sk_buff passed\n", dev->name);
1212 privptr->stats.tx_dropped++;
1215 if (skb_headroom(skb) < (NETIUCV_HDRLEN)) {
1217 "%s: Got sk_buff with head room < %ld bytes\n",
1218 dev->name, NETIUCV_HDRLEN);
1220 privptr->stats.tx_dropped++;
1225 * If connection is not running, try to restart it
1226 * and throw away packet.
1228 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1229 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1231 privptr->stats.tx_dropped++;
1232 privptr->stats.tx_errors++;
1233 privptr->stats.tx_carrier_errors++;
1237 if (netiucv_test_and_set_busy(dev))
1240 dev->trans_start = jiffies;
1241 if (netiucv_transmit_skb(privptr->conn, skb) != 0)
1243 netiucv_clear_busy(dev);
1248 * Returns interface statistics of a device.
1250 * @param dev Pointer to interface struct.
1252 * @return Pointer to stats struct of this interface.
1254 static struct net_device_stats *
1255 netiucv_stats (struct net_device * dev)
1257 return &((struct netiucv_priv *)dev->priv)->stats;
1261 * Sets MTU of an interface.
1263 * @param dev Pointer to interface struct.
1264 * @param new_mtu The new MTU to use for this interface.
1266 * @return 0 on success, -EINVAL if MTU is out of valid range.
1267 * (valid range is 576 .. NETIUCV_MTU_MAX).
1270 netiucv_change_mtu (struct net_device * dev, int new_mtu)
1272 if ((new_mtu < 576) || (new_mtu > NETIUCV_MTU_MAX))
1279 * attributes in sysfs
1280 *****************************************************************************/
1283 user_show (struct device *dev, char *buf)
1285 struct netiucv_priv *priv = dev->driver_data;
1287 return sprintf(buf, "%s\n", netiucv_printname(priv->conn->userid));
1291 user_write (struct device *dev, const char *buf, size_t count)
1293 struct netiucv_priv *priv = dev->driver_data;
1294 struct net_device *ndev = priv->conn->netdev;
1302 "netiucv: username too long (%d)!\n", (int)count);
1306 tmp = strsep((char **) &buf, "\n");
1307 for (i=0, p=tmp; i<8 && *p; i++, p++) {
1308 if (isalnum(*p) || (*p == '$'))
1310 else if (*p == '\n') {
1311 /* trailing lf, grr */
1315 "netiucv: Invalid character in username!\n");
1320 username[i++] = ' ';
1323 if (memcmp(username, priv->conn->userid, 8) != 0) {
1324 /* username changed */
1325 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1327 "netiucv: device %s active, connected to %s\n",
1328 dev->bus_id, priv->conn->userid);
1330 "netiucv: user cannot be updated\n");
1334 memcpy(priv->conn->userid, username, 9);
1340 static DEVICE_ATTR(user, 0644, user_show, user_write);
1343 buffer_show (struct device *dev, char *buf)
1345 struct netiucv_priv *priv = dev->driver_data;
1347 return sprintf(buf, "%d\n", priv->conn->max_buffsize);
1351 buffer_write (struct device *dev, const char *buf, size_t count)
1353 struct netiucv_priv *priv = dev->driver_data;
1354 struct net_device *ndev = priv->conn->netdev;
1361 bs1 = simple_strtoul(buf, &e, 0);
1363 if (e && (!isspace(*e))) {
1365 "netiucv: Invalid character in buffer!\n");
1368 if (bs1 > NETIUCV_BUFSIZE_MAX) {
1370 "netiucv: Given buffer size %d too large.\n",
1375 if ((ndev->flags & IFF_RUNNING) &&
1376 (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2)))
1378 if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN))
1381 priv->conn->max_buffsize = bs1;
1382 if (!(ndev->flags & IFF_RUNNING))
1383 ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN;
1384 priv->conn->flags |= CONN_FLAGS_BUFSIZE_CHANGED;
1390 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
1393 dev_fsm_show (struct device *dev, char *buf)
1395 struct netiucv_priv *priv = dev->driver_data;
1397 return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm));
1400 static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL);
1403 conn_fsm_show (struct device *dev, char *buf)
1405 struct netiucv_priv *priv = dev->driver_data;
1407 return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm));
1410 static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL);
1413 maxmulti_show (struct device *dev, char *buf)
1415 struct netiucv_priv *priv = dev->driver_data;
1417 return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti);
1421 maxmulti_write (struct device *dev, const char *buf, size_t count)
1423 struct netiucv_priv *priv = dev->driver_data;
1425 priv->conn->prof.maxmulti = 0;
1429 static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write);
1432 maxcq_show (struct device *dev, char *buf)
1434 struct netiucv_priv *priv = dev->driver_data;
1436 return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue);
1440 maxcq_write (struct device *dev, const char *buf, size_t count)
1442 struct netiucv_priv *priv = dev->driver_data;
1444 priv->conn->prof.maxcqueue = 0;
1448 static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write);
1451 sdoio_show (struct device *dev, char *buf)
1453 struct netiucv_priv *priv = dev->driver_data;
1455 return sprintf(buf, "%ld\n", priv->conn->prof.doios_single);
1459 sdoio_write (struct device *dev, const char *buf, size_t count)
1461 struct netiucv_priv *priv = dev->driver_data;
1463 priv->conn->prof.doios_single = 0;
1467 static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write);
1470 mdoio_show (struct device *dev, char *buf)
1472 struct netiucv_priv *priv = dev->driver_data;
1474 return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi);
1478 mdoio_write (struct device *dev, const char *buf, size_t count)
1480 struct netiucv_priv *priv = dev->driver_data;
1482 priv->conn->prof.doios_multi = 0;
1486 static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write);
1489 txlen_show (struct device *dev, char *buf)
1491 struct netiucv_priv *priv = dev->driver_data;
1493 return sprintf(buf, "%ld\n", priv->conn->prof.txlen);
1497 txlen_write (struct device *dev, const char *buf, size_t count)
1499 struct netiucv_priv *priv = dev->driver_data;
1501 priv->conn->prof.txlen = 0;
1505 static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write);
1508 txtime_show (struct device *dev, char *buf)
1510 struct netiucv_priv *priv = dev->driver_data;
1512 return sprintf(buf, "%ld\n", priv->conn->prof.tx_time);
1516 txtime_write (struct device *dev, const char *buf, size_t count)
1518 struct netiucv_priv *priv = dev->driver_data;
1520 priv->conn->prof.tx_time = 0;
1524 static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write);
1527 txpend_show (struct device *dev, char *buf)
1529 struct netiucv_priv *priv = dev->driver_data;
1531 return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending);
1535 txpend_write (struct device *dev, const char *buf, size_t count)
1537 struct netiucv_priv *priv = dev->driver_data;
1539 priv->conn->prof.tx_pending = 0;
1543 static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write);
1546 txmpnd_show (struct device *dev, char *buf)
1548 struct netiucv_priv *priv = dev->driver_data;
1550 return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending);
1554 txmpnd_write (struct device *dev, const char *buf, size_t count)
1556 struct netiucv_priv *priv = dev->driver_data;
1558 priv->conn->prof.tx_max_pending = 0;
1562 static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write);
1564 static struct attribute *netiucv_attrs[] = {
1565 &dev_attr_buffer.attr,
1566 &dev_attr_user.attr,
1570 static struct attribute_group netiucv_attr_group = {
1571 .attrs = netiucv_attrs,
1574 static struct attribute *netiucv_stat_attrs[] = {
1575 &dev_attr_device_fsm_state.attr,
1576 &dev_attr_connection_fsm_state.attr,
1577 &dev_attr_max_tx_buffer_used.attr,
1578 &dev_attr_max_chained_skbs.attr,
1579 &dev_attr_tx_single_write_ops.attr,
1580 &dev_attr_tx_multi_write_ops.attr,
1581 &dev_attr_netto_bytes.attr,
1582 &dev_attr_max_tx_io_time.attr,
1583 &dev_attr_tx_pending.attr,
1584 &dev_attr_tx_max_pending.attr,
1588 static struct attribute_group netiucv_stat_attr_group = {
1590 .attrs = netiucv_stat_attrs,
1594 netiucv_add_files(struct device *dev)
1598 pr_debug("%s() called\n", __FUNCTION__);
1600 ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group);
1603 ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group);
1605 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1610 netiucv_remove_files(struct device *dev)
1612 pr_debug("%s() called\n", __FUNCTION__);
1613 sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group);
1614 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1618 netiucv_register_device(struct net_device *ndev)
1620 struct netiucv_priv *priv = ndev->priv;
1621 struct device *dev = kmalloc(sizeof(struct device), GFP_KERNEL);
1625 pr_debug("%s() called\n", __FUNCTION__);
1628 memset(dev, 0, sizeof(struct device));
1629 snprintf(dev->bus_id, BUS_ID_SIZE, "net%s", ndev->name);
1630 dev->bus = &iucv_bus;
1631 dev->parent = iucv_root;
1633 * The release function could be called after the
1634 * module has been unloaded. It's _only_ task is to
1635 * free the struct. Therefore, we specify kfree()
1636 * directly here. (Probably a little bit obfuscating
1637 * but legitime ...).
1639 dev->release = (void (*)(struct device *))kfree;
1643 ret = device_register(dev);
1647 ret = netiucv_add_files(dev);
1650 dev->driver_data = priv;
1655 device_unregister(dev);
1660 netiucv_unregister_device(struct device *dev)
1662 pr_debug("%s() called\n", __FUNCTION__);
1663 netiucv_remove_files(dev);
1664 device_unregister(dev);
1668 * Allocate and initialize a new connection structure.
1669 * Add it to the list of connections;
1671 static struct iucv_connection *
1672 netiucv_new_connection(struct net_device *dev, char *username)
1674 struct iucv_connection **clist = &connections;
1675 struct iucv_connection *conn =
1676 (struct iucv_connection *)
1677 kmalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1680 memset(conn, 0, sizeof(struct iucv_connection));
1681 skb_queue_head_init(&conn->collect_queue);
1682 skb_queue_head_init(&conn->commit_queue);
1683 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1686 conn->rx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1687 GFP_KERNEL | GFP_DMA);
1688 if (!conn->rx_buff) {
1692 conn->tx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1693 GFP_KERNEL | GFP_DMA);
1694 if (!conn->tx_buff) {
1695 kfree_skb(conn->rx_buff);
1699 conn->fsm = init_fsm("netiucvconn", conn_state_names,
1700 conn_event_names, NR_CONN_STATES,
1701 NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN,
1704 kfree_skb(conn->tx_buff);
1705 kfree_skb(conn->rx_buff);
1709 fsm_settimer(conn->fsm, &conn->timer);
1710 fsm_newstate(conn->fsm, CONN_STATE_INVALID);
1713 memcpy(conn->userid, username, 9);
1714 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1717 conn->next = *clist;
1724 * Release a connection structure and remove it from the
1725 * list of connections.
1728 netiucv_remove_connection(struct iucv_connection *conn)
1730 struct iucv_connection **clist = &connections;
1732 pr_debug("%s() called\n", __FUNCTION__);
1737 if (*clist == conn) {
1738 *clist = conn->next;
1739 if (conn->handle != 0) {
1740 iucv_unregister_program(conn->handle);
1743 fsm_deltimer(&conn->timer);
1744 kfree_fsm(conn->fsm);
1745 kfree_skb(conn->rx_buff);
1746 kfree_skb(conn->tx_buff);
1749 clist = &((*clist)->next);
1754 * Release everything of a net device.
1757 netiucv_free_netdevice(struct net_device *dev)
1759 struct netiucv_priv *privptr;
1761 pr_debug("%s() called\n", __FUNCTION__);
1766 privptr = (struct netiucv_priv *)dev->priv;
1769 fsm_deltimer(&privptr->timer);
1771 netiucv_remove_connection(privptr->conn);
1773 kfree_fsm(privptr->fsm);
1774 privptr->conn = 0; privptr->fsm = 0;
1775 /* privptr gets freed by free_netdev() */
1781 * Initialize a net device. (Called from kernel in alloc_netdev())
1784 netiucv_setup_netdevice(struct net_device *dev)
1786 memset(dev->priv, 0, sizeof(struct netiucv_priv));
1788 dev->mtu = NETIUCV_MTU_DEFAULT;
1789 dev->hard_start_xmit = netiucv_tx;
1790 dev->open = netiucv_open;
1791 dev->stop = netiucv_close;
1792 dev->get_stats = netiucv_stats;
1793 dev->change_mtu = netiucv_change_mtu;
1794 dev->destructor = netiucv_free_netdevice;
1795 dev->hard_header_len = NETIUCV_HDRLEN;
1797 dev->type = ARPHRD_SLIP;
1798 dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT;
1799 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1800 SET_MODULE_OWNER(dev);
1804 * Allocate and initialize everything of a net device.
1806 static struct net_device *
1807 netiucv_init_netdevice(char *username)
1809 struct netiucv_priv *privptr;
1810 struct net_device *dev;
1812 dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d",
1813 netiucv_setup_netdevice);
1817 privptr = (struct netiucv_priv *)dev->priv;
1818 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
1819 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
1820 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
1821 if (privptr->fsm == NULL) {
1825 privptr->conn = netiucv_new_connection(dev, username);
1826 if (!privptr->conn) {
1827 kfree_fsm(privptr->fsm);
1831 fsm_settimer(privptr->fsm, &privptr->timer);
1832 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
1838 conn_write(struct device_driver *drv, const char *buf, size_t count)
1843 struct net_device *dev;
1847 "netiucv: username too long (%d)!\n", (int)count);
1851 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) {
1852 if (isalnum(*p) || (*p == '$'))
1854 else if (*p == '\n') {
1855 /* trailing lf, grr */
1859 "netiucv: Invalid character in username!\n");
1864 username[i++] = ' ';
1866 dev = netiucv_init_netdevice(username);
1869 "netiucv: Could not allocate network device structure "
1870 "for user '%s'\n", netiucv_printname(username));
1874 if ((ret = register_netdev(dev))) {
1878 if ((ret = netiucv_register_device(dev))) {
1879 unregister_netdev(dev);
1884 SET_NETDEV_DEV(dev, (struct device*)((struct netiucv_priv*)dev->priv)->dev);
1885 printk(KERN_INFO "%s: '%s'\n", dev->name, netiucv_printname(username));
1891 "netiucv: Could not register '%s'\n", dev->name);
1892 netiucv_free_netdevice(dev);
1896 DRIVER_ATTR(connection, 0200, NULL, conn_write);
1899 remove_write (struct device_driver *drv, const char *buf, size_t count)
1901 struct iucv_connection **clist = &connections;
1902 struct net_device *ndev;
1903 struct netiucv_priv *priv;
1905 char name[IFNAMSIZ];
1909 pr_debug("%s() called\n", __FUNCTION__);
1911 if (count >= IFNAMSIZ)
1914 for (i=0, p=(char *)buf; i<count && *p; i++, p++) {
1915 if ((*p == '\n') | (*p == ' ')) {
1916 /* trailing lf, grr */
1925 ndev = (*clist)->netdev;
1926 priv = (struct netiucv_priv*)ndev->priv;
1929 if (strncmp(name, ndev->name, count)) {
1930 clist = &((*clist)->next);
1933 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1935 "netiucv: net device %s active with peer %s\n",
1936 ndev->name, priv->conn->userid);
1938 "netiucv: %s cannot be removed\n",
1942 unregister_netdev(ndev);
1943 netiucv_unregister_device(dev);
1947 "netiucv: net device %s unknown\n", name);
1951 DRIVER_ATTR(remove, 0200, NULL, remove_write);
1953 static struct device_driver netiucv_driver = {
1959 netiucv_banner(void)
1961 char vbuf[] = "$Revision: 1.53 $";
1962 char *version = vbuf;
1964 if ((version = strchr(version, ':'))) {
1965 char *p = strchr(version + 1, '$');
1970 printk(KERN_INFO "NETIUCV driver Version%s initialized\n", version);
1976 while (connections) {
1977 struct net_device *ndev = connections->netdev;
1978 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv;
1979 struct device *dev = priv->dev;
1981 unregister_netdev(ndev);
1982 netiucv_unregister_device(dev);
1985 driver_remove_file(&netiucv_driver, &driver_attr_connection);
1986 driver_remove_file(&netiucv_driver, &driver_attr_remove);
1987 driver_unregister(&netiucv_driver);
1989 printk(KERN_INFO "NETIUCV driver unloaded\n");
1998 ret = driver_register(&netiucv_driver);
2000 printk(KERN_ERR "NETIUCV: failed to register driver.\n");
2004 /* Add entry for specifying connections. */
2005 ret = driver_create_file(&netiucv_driver, &driver_attr_connection);
2007 ret = driver_create_file(&netiucv_driver, &driver_attr_remove);
2010 printk(KERN_ERR "NETIUCV: failed to add driver attribute.\n");
2011 driver_unregister(&netiucv_driver);
2016 module_init(netiucv_init);
2017 module_exit(netiucv_exit);
2018 MODULE_LICENSE("GPL");