2 * $Id: netiucv.c,v 1.54 2004/05/28 08:04:14 braunu 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.54 $
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;
117 * Representation of event-data for the
118 * connection state machine.
121 struct iucv_connection *conn;
126 * Private part of the network device structure
128 struct netiucv_priv {
129 struct net_device_stats stats;
132 struct iucv_connection *conn;
138 * Link level header for a packet.
140 typedef struct ll_header_t {
144 #define NETIUCV_HDRLEN (sizeof(ll_header))
145 #define NETIUCV_BUFSIZE_MAX 32768
146 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
147 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
148 #define NETIUCV_MTU_DEFAULT 9216
149 #define NETIUCV_QUEUELEN_DEFAULT 50
150 #define NETIUCV_TIMEOUT_5SEC 5000
153 * Compatibility macros for busy handling
154 * of network devices.
156 static __inline__ void netiucv_clear_busy(struct net_device *dev)
158 clear_bit(0, &(((struct netiucv_priv *)dev->priv)->tbusy));
159 netif_wake_queue(dev);
162 static __inline__ int netiucv_test_and_set_busy(struct net_device *dev)
164 netif_stop_queue(dev);
165 return test_and_set_bit(0, &((struct netiucv_priv *)dev->priv)->tbusy);
168 static __u8 iucv_host[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
169 static __u8 iucvMagic[16] = {
170 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
171 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
175 * This mask means the 16-byte IUCV "magic" and the origin userid must
176 * match exactly as specified in order to give connection_pending()
179 static __u8 mask[] = {
180 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
181 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
182 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
186 * Convert an iucv userId to its printable
187 * form (strip whitespace at end).
189 * @param An iucv userId
191 * @returns The printable string (static data!!)
193 static __inline__ char *
194 netiucv_printname(char *name)
198 memcpy(tmp, name, 8);
200 while (*p && (!isspace(*p)))
207 * States of the interface statemachine.
215 * MUST be always the last element!!
220 static const char *dev_state_names[] = {
228 * Events of the interface statemachine.
237 * MUST be always the last element!!
242 static const char *dev_event_names[] = {
251 * Events of the connection statemachine
255 * Events, representing callbacks from
256 * lowlevel iucv layer)
267 * Events, representing errors return codes from
268 * calls to lowlevel iucv layer
272 * Event, representing timer expiry.
277 * Events, representing commands from upper levels.
283 * MUST be always the last element!!
288 static const char *conn_event_names[] = {
289 "Remote connection request",
290 "Remote connection acknowledge",
291 "Remote connection reject",
292 "Connection suspended",
293 "Connection resumed",
304 * States of the connection statemachine.
308 * Connection not assigned to any device,
309 * initial state, invalid
314 * Userid assigned but not operating
319 * Connection registered,
320 * no connection request sent yet,
321 * no connection request received
323 CONN_STATE_STARTWAIT,
326 * Connection registered and connection request sent,
327 * no acknowledge and no connection request received yet.
329 CONN_STATE_SETUPWAIT,
332 * Connection up and running idle
337 * Data sent, awaiting CONN_EVENT_TXDONE
342 * Error during registration.
347 * Error during registration.
352 * MUST be always the last element!!
357 static const char *conn_state_names[] = {
365 "Registration error",
371 * Callback-wrappers, called from lowlevel iucv layer.
372 *****************************************************************************/
375 netiucv_callback_rx(iucv_MessagePending *eib, void *pgm_data)
377 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
378 struct iucv_event ev;
381 ev.data = (void *)eib;
383 fsm_event(conn->fsm, CONN_EVENT_RX, &ev);
387 netiucv_callback_txdone(iucv_MessageComplete *eib, void *pgm_data)
389 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
390 struct iucv_event ev;
393 ev.data = (void *)eib;
394 fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev);
398 netiucv_callback_connack(iucv_ConnectionComplete *eib, void *pgm_data)
400 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
401 struct iucv_event ev;
404 ev.data = (void *)eib;
405 fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, &ev);
409 netiucv_callback_connreq(iucv_ConnectionPending *eib, void *pgm_data)
411 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
412 struct iucv_event ev;
415 ev.data = (void *)eib;
416 fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev);
420 netiucv_callback_connrej(iucv_ConnectionSevered *eib, void *pgm_data)
422 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
423 struct iucv_event ev;
426 ev.data = (void *)eib;
427 fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, &ev);
431 netiucv_callback_connsusp(iucv_ConnectionQuiesced *eib, void *pgm_data)
433 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
434 struct iucv_event ev;
437 ev.data = (void *)eib;
438 fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, &ev);
442 netiucv_callback_connres(iucv_ConnectionResumed *eib, void *pgm_data)
444 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
445 struct iucv_event ev;
448 ev.data = (void *)eib;
449 fsm_event(conn->fsm, CONN_EVENT_CONN_RES, &ev);
452 static iucv_interrupt_ops_t netiucv_ops = {
453 .ConnectionPending = netiucv_callback_connreq,
454 .ConnectionComplete = netiucv_callback_connack,
455 .ConnectionSevered = netiucv_callback_connrej,
456 .ConnectionQuiesced = netiucv_callback_connsusp,
457 .ConnectionResumed = netiucv_callback_connres,
458 .MessagePending = netiucv_callback_rx,
459 .MessageComplete = netiucv_callback_txdone
463 * Dummy NOP action for all statemachines
466 fsm_action_nop(fsm_instance *fi, int event, void *arg)
471 * Actions of the connection statemachine
472 *****************************************************************************/
475 * Helper function for conn_action_rx()
476 * Unpack a just received skb and hand it over to
479 * @param conn The connection where this skb has been received.
480 * @param pskb The received skb.
482 //static __inline__ void
484 netiucv_unpack_skb(struct iucv_connection *conn, struct sk_buff *pskb)
486 struct net_device *dev = conn->netdev;
487 struct netiucv_priv *privptr = dev->priv;
490 skb_put(pskb, NETIUCV_HDRLEN);
492 pskb->ip_summed = CHECKSUM_NONE;
493 pskb->protocol = ntohs(ETH_P_IP);
497 ll_header *header = (ll_header *)pskb->data;
499 if (header->next == 0)
502 skb_pull(pskb, NETIUCV_HDRLEN);
503 header->next -= offset;
504 offset += header->next;
505 header->next -= NETIUCV_HDRLEN;
506 if (skb_tailroom(pskb) < header->next) {
508 "%s: Illegal next field in iucv header: "
510 dev->name, header->next, skb_tailroom(pskb));
513 skb_put(pskb, header->next);
514 pskb->mac.raw = pskb->data;
515 skb = dev_alloc_skb(pskb->len);
518 "%s Out of memory in netiucv_unpack_skb\n",
520 privptr->stats.rx_dropped++;
523 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
524 skb->mac.raw = skb->data;
525 skb->dev = pskb->dev;
526 skb->protocol = pskb->protocol;
527 pskb->ip_summed = CHECKSUM_UNNECESSARY;
529 * Since receiving is always initiated from a tasklet (in iucv.c),
530 * we must use netif_rx_ni() instead of netif_rx()
533 dev->last_rx = jiffies;
534 privptr->stats.rx_packets++;
535 privptr->stats.rx_bytes += skb->len;
536 skb_pull(pskb, header->next);
537 skb_put(pskb, NETIUCV_HDRLEN);
542 conn_action_rx(fsm_instance *fi, int event, void *arg)
544 struct iucv_event *ev = (struct iucv_event *)arg;
545 struct iucv_connection *conn = ev->conn;
546 iucv_MessagePending *eib = (iucv_MessagePending *)ev->data;
547 struct netiucv_priv *privptr = (struct netiucv_priv *)conn->netdev->priv;
549 __u32 msglen = eib->ln1msg2.ipbfln1f;
552 pr_debug("%s() called\n", __FUNCTION__);
555 /* FRITZ: How to tell iucv LL to drop the msg? */
557 "Received data for unlinked connection\n");
560 if (msglen > conn->max_buffsize) {
561 /* FRITZ: How to tell iucv LL to drop the msg? */
562 privptr->stats.rx_dropped++;
565 conn->rx_buff->data = conn->rx_buff->tail = conn->rx_buff->head;
566 conn->rx_buff->len = 0;
567 rc = iucv_receive(conn->pathid, eib->ipmsgid, eib->iptrgcls,
568 conn->rx_buff->data, msglen, NULL, NULL, NULL);
569 if (rc != 0 || msglen < 5) {
570 privptr->stats.rx_errors++;
571 printk(KERN_INFO "iucv_receive returned %08x\n", rc);
574 netiucv_unpack_skb(conn, conn->rx_buff);
578 conn_action_txdone(fsm_instance *fi, int event, void *arg)
580 struct iucv_event *ev = (struct iucv_event *)arg;
581 struct iucv_connection *conn = ev->conn;
582 iucv_MessageComplete *eib = (iucv_MessageComplete *)ev->data;
583 struct netiucv_priv *privptr = NULL;
584 /* Shut up, gcc! skb is always below 2G. */
585 __u32 single_flag = eib->ipmsgtag;
588 __u32 stat_maxcq = 0;
590 unsigned long saveflags;
593 pr_debug("%s() called\n", __FUNCTION__);
595 if (conn && conn->netdev && conn->netdev->priv)
596 privptr = (struct netiucv_priv *)conn->netdev->priv;
597 conn->prof.tx_pending--;
599 if ((skb = skb_dequeue(&conn->commit_queue))) {
600 atomic_dec(&skb->users);
601 dev_kfree_skb_any(skb);
603 privptr->stats.tx_packets++;
604 privptr->stats.tx_bytes +=
605 (skb->len - NETIUCV_HDRLEN
610 conn->tx_buff->data = conn->tx_buff->tail = conn->tx_buff->head;
611 conn->tx_buff->len = 0;
612 spin_lock_irqsave(&conn->collect_lock, saveflags);
613 while ((skb = skb_dequeue(&conn->collect_queue))) {
614 header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN;
615 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
617 memcpy(skb_put(conn->tx_buff, skb->len), skb->data, skb->len);
621 atomic_dec(&skb->users);
622 dev_kfree_skb_any(skb);
624 if (conn->collect_len > conn->prof.maxmulti)
625 conn->prof.maxmulti = conn->collect_len;
626 conn->collect_len = 0;
627 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
628 if (conn->tx_buff->len) {
632 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
635 conn->prof.send_stamp = xtime;
636 rc = iucv_send(conn->pathid, NULL, 0, 0, 0, 0,
637 conn->tx_buff->data, conn->tx_buff->len);
638 conn->prof.doios_multi++;
639 conn->prof.txlen += conn->tx_buff->len;
640 conn->prof.tx_pending++;
641 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
642 conn->prof.tx_max_pending = conn->prof.tx_pending;
644 conn->prof.tx_pending--;
645 fsm_newstate(fi, CONN_STATE_IDLE);
647 privptr->stats.tx_errors += txpackets;
648 printk(KERN_INFO "iucv_send returned %08x\n",
652 privptr->stats.tx_packets += txpackets;
653 privptr->stats.tx_bytes += txbytes;
655 if (stat_maxcq > conn->prof.maxcqueue)
656 conn->prof.maxcqueue = stat_maxcq;
659 fsm_newstate(fi, CONN_STATE_IDLE);
663 conn_action_connaccept(fsm_instance *fi, int event, void *arg)
665 struct iucv_event *ev = (struct iucv_event *)arg;
666 struct iucv_connection *conn = ev->conn;
667 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
668 struct net_device *netdev = conn->netdev;
669 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
674 pr_debug("%s() called\n", __FUNCTION__);
676 rc = iucv_accept(eib->ippathid, NETIUCV_QUEUELEN_DEFAULT, udata, 0,
677 conn->handle, conn, NULL, &msglimit);
680 "%s: IUCV accept failed with error %d\n",
684 fsm_newstate(fi, CONN_STATE_IDLE);
685 conn->pathid = eib->ippathid;
686 netdev->tx_queue_len = msglimit;
687 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
691 conn_action_connreject(fsm_instance *fi, int event, void *arg)
693 struct iucv_event *ev = (struct iucv_event *)arg;
694 struct iucv_connection *conn = ev->conn;
695 struct net_device *netdev = conn->netdev;
696 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
699 pr_debug("%s() called\n", __FUNCTION__);
701 iucv_sever(eib->ippathid, udata);
702 if (eib->ippathid != conn->pathid) {
704 "%s: IR pathid %d does not match original pathid %d\n",
705 netdev->name, eib->ippathid, conn->pathid);
706 iucv_sever(conn->pathid, udata);
711 conn_action_connack(fsm_instance *fi, int event, void *arg)
713 struct iucv_event *ev = (struct iucv_event *)arg;
714 struct iucv_connection *conn = ev->conn;
715 iucv_ConnectionComplete *eib = (iucv_ConnectionComplete *)ev->data;
716 struct net_device *netdev = conn->netdev;
717 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
719 pr_debug("%s() called\n", __FUNCTION__);
721 fsm_deltimer(&conn->timer);
722 fsm_newstate(fi, CONN_STATE_IDLE);
723 if (eib->ippathid != conn->pathid) {
725 "%s: IR pathid %d does not match original pathid %d\n",
726 netdev->name, eib->ippathid, conn->pathid);
727 conn->pathid = eib->ippathid;
729 netdev->tx_queue_len = eib->ipmsglim;
730 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
734 conn_action_conntimsev(fsm_instance *fi, int event, void *arg)
736 struct iucv_connection *conn = (struct iucv_connection *)arg;
739 pr_debug("%s() called\n", __FUNCTION__);
741 fsm_deltimer(&conn->timer);
742 iucv_sever(conn->pathid, udata);
743 fsm_newstate(fi, CONN_STATE_STARTWAIT);
747 conn_action_connsever(fsm_instance *fi, int event, void *arg)
749 struct iucv_event *ev = (struct iucv_event *)arg;
750 struct iucv_connection *conn = ev->conn;
751 struct net_device *netdev = conn->netdev;
752 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
755 pr_debug("%s() called\n", __FUNCTION__);
757 fsm_deltimer(&conn->timer);
758 iucv_sever(conn->pathid, udata);
759 printk(KERN_INFO "%s: Remote dropped connection\n",
761 fsm_newstate(fi, CONN_STATE_STARTWAIT);
762 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
766 conn_action_start(fsm_instance *fi, int event, void *arg)
768 struct iucv_event *ev = (struct iucv_event *)arg;
769 struct iucv_connection *conn = ev->conn;
773 pr_debug("%s() called\n", __FUNCTION__);
775 if (conn->handle == 0) {
777 iucv_register_program(iucvMagic, conn->userid, mask,
779 fsm_newstate(fi, CONN_STATE_STARTWAIT);
780 if (conn->handle <= 0) {
781 fsm_newstate(fi, CONN_STATE_REGERR);
786 pr_debug("%s('%s'): registered successfully\n",
787 conn->netdev->name, conn->userid);
790 pr_debug("%s('%s'): connecting ...\n",
791 conn->netdev->name, conn->userid);
793 /* We must set the state before calling iucv_connect because the callback
794 * handler could be called at any point after the connection request is
797 fsm_newstate(fi, CONN_STATE_SETUPWAIT);
798 rc = iucv_connect(&(conn->pathid), NETIUCV_QUEUELEN_DEFAULT, iucvMagic,
799 conn->userid, iucv_host, 0, NULL, &msglimit, conn->handle,
803 conn->netdev->tx_queue_len = msglimit;
804 fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC,
805 CONN_EVENT_TIMER, conn);
809 "%s: User %s is currently not available.\n",
811 netiucv_printname(conn->userid));
812 fsm_newstate(fi, CONN_STATE_STARTWAIT);
816 "%s: User %s is currently not ready.\n",
818 netiucv_printname(conn->userid));
819 fsm_newstate(fi, CONN_STATE_STARTWAIT);
823 "%s: Too many IUCV connections.\n",
825 fsm_newstate(fi, CONN_STATE_CONNERR);
829 "%s: User %s has too many IUCV connections.\n",
831 netiucv_printname(conn->userid));
832 fsm_newstate(fi, CONN_STATE_CONNERR);
836 "%s: No IUCV authorization in CP directory.\n",
838 fsm_newstate(fi, CONN_STATE_CONNERR);
842 "%s: iucv_connect returned error %d\n",
843 conn->netdev->name, rc);
844 fsm_newstate(fi, CONN_STATE_CONNERR);
847 iucv_unregister_program(conn->handle);
852 netiucv_purge_skb_queue(struct sk_buff_head *q)
856 while ((skb = skb_dequeue(q))) {
857 atomic_dec(&skb->users);
858 dev_kfree_skb_any(skb);
863 conn_action_stop(fsm_instance *fi, int event, void *arg)
865 struct iucv_event *ev = (struct iucv_event *)arg;
866 struct iucv_connection *conn = ev->conn;
867 struct net_device *netdev = conn->netdev;
868 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
870 pr_debug("%s() called\n", __FUNCTION__);
872 fsm_deltimer(&conn->timer);
873 fsm_newstate(fi, CONN_STATE_STOPPED);
874 netiucv_purge_skb_queue(&conn->collect_queue);
876 iucv_unregister_program(conn->handle);
878 netiucv_purge_skb_queue(&conn->commit_queue);
879 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
883 conn_action_inval(fsm_instance *fi, int event, void *arg)
885 struct iucv_event *ev = (struct iucv_event *)arg;
886 struct iucv_connection *conn = ev->conn;
887 struct net_device *netdev = conn->netdev;
890 "%s: Cannot connect without username\n",
894 static const fsm_node conn_fsm[] = {
895 { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval },
896 { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start },
898 { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop },
899 { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop },
900 { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop },
901 { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop },
902 { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop },
903 { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop },
904 { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop },
906 { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject },
907 { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
908 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
909 { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject },
910 { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject },
912 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack },
913 { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev },
915 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever },
916 { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever },
917 { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever },
919 { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx },
920 { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx },
922 { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone },
923 { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone },
926 static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node);
930 * Actions for interface - statemachine.
931 *****************************************************************************/
934 * Startup connection by sending CONN_EVENT_START to it.
936 * @param fi An instance of an interface statemachine.
937 * @param event The event, just happened.
938 * @param arg Generic pointer, casted from struct net_device * upon call.
941 dev_action_start(fsm_instance *fi, int event, void *arg)
943 struct net_device *dev = (struct net_device *)arg;
944 struct netiucv_priv *privptr = dev->priv;
945 struct iucv_event ev;
947 pr_debug("%s() called\n", __FUNCTION__);
949 ev.conn = privptr->conn;
950 fsm_newstate(fi, DEV_STATE_STARTWAIT);
951 fsm_event(privptr->conn->fsm, CONN_EVENT_START, &ev);
955 * Shutdown connection by sending CONN_EVENT_STOP to it.
957 * @param fi An instance of an interface statemachine.
958 * @param event The event, just happened.
959 * @param arg Generic pointer, casted from struct net_device * upon call.
962 dev_action_stop(fsm_instance *fi, int event, void *arg)
964 struct net_device *dev = (struct net_device *)arg;
965 struct netiucv_priv *privptr = dev->priv;
966 struct iucv_event ev;
968 pr_debug("%s() called\n", __FUNCTION__);
970 ev.conn = privptr->conn;
972 fsm_newstate(fi, DEV_STATE_STOPWAIT);
973 fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev);
977 * Called from connection statemachine
978 * when a connection is up and running.
980 * @param fi An instance of an interface statemachine.
981 * @param event The event, just happened.
982 * @param arg Generic pointer, casted from struct net_device * upon call.
985 dev_action_connup(fsm_instance *fi, int event, void *arg)
987 struct net_device *dev = (struct net_device *)arg;
988 struct netiucv_priv *privptr = dev->priv;
990 pr_debug("%s() called\n", __FUNCTION__);
992 switch (fsm_getstate(fi)) {
993 case DEV_STATE_STARTWAIT:
994 fsm_newstate(fi, DEV_STATE_RUNNING);
996 "%s: connected with remote side %s\n",
997 dev->name, privptr->conn->userid);
999 case DEV_STATE_STOPWAIT:
1001 "%s: got connection UP event during shutdown!!\n",
1008 * Called from connection statemachine
1009 * when a connection has been shutdown.
1011 * @param fi An instance of an interface statemachine.
1012 * @param event The event, just happened.
1013 * @param arg Generic pointer, casted from struct net_device * upon call.
1016 dev_action_conndown(fsm_instance *fi, int event, void *arg)
1018 pr_debug("%s() called\n", __FUNCTION__);
1020 switch (fsm_getstate(fi)) {
1021 case DEV_STATE_RUNNING:
1022 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1024 case DEV_STATE_STOPWAIT:
1025 fsm_newstate(fi, DEV_STATE_STOPPED);
1030 static const fsm_node dev_fsm[] = {
1031 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
1033 { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start },
1034 { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown },
1036 { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop },
1037 { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup },
1039 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
1040 { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown },
1041 { DEV_STATE_RUNNING, DEV_EVENT_CONUP, fsm_action_nop },
1044 static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node);
1047 * Transmit a packet.
1048 * This is a helper function for netiucv_tx().
1050 * @param conn Connection to be used for sending.
1051 * @param skb Pointer to struct sk_buff of packet to send.
1052 * The linklevel header has already been set up
1055 * @return 0 on success, -ERRNO on failure. (Never fails.)
1058 netiucv_transmit_skb(struct iucv_connection *conn, struct sk_buff *skb) {
1059 unsigned long saveflags;
1063 if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) {
1064 int l = skb->len + NETIUCV_HDRLEN;
1066 spin_lock_irqsave(&conn->collect_lock, saveflags);
1067 if (conn->collect_len + l >
1068 (conn->max_buffsize - NETIUCV_HDRLEN))
1071 atomic_inc(&skb->users);
1072 skb_queue_tail(&conn->collect_queue, skb);
1073 conn->collect_len += l;
1075 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
1077 struct sk_buff *nskb = skb;
1079 * Copy the skb to a new allocated skb in lowmem only if the
1080 * data is located above 2G in memory or tailroom is < 2.
1083 ((unsigned long)(skb->tail + NETIUCV_HDRLEN)) >> 31;
1085 if (hi || (skb_tailroom(skb) < 2)) {
1086 nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
1087 NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
1090 "%s: Could not allocate tx_skb\n",
1091 conn->netdev->name);
1095 skb_reserve(nskb, NETIUCV_HDRLEN);
1096 memcpy(skb_put(nskb, skb->len),
1097 skb->data, skb->len);
1102 * skb now is below 2G and has enough room. Add headers.
1104 header.next = nskb->len + NETIUCV_HDRLEN;
1105 memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1107 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1109 fsm_newstate(conn->fsm, CONN_STATE_TX);
1110 conn->prof.send_stamp = xtime;
1112 rc = iucv_send(conn->pathid, NULL, 0, 0, 1 /* single_flag */,
1113 0, nskb->data, nskb->len);
1114 /* Shut up, gcc! nskb is always below 2G. */
1115 conn->prof.doios_single++;
1116 conn->prof.txlen += skb->len;
1117 conn->prof.tx_pending++;
1118 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
1119 conn->prof.tx_max_pending = conn->prof.tx_pending;
1121 struct netiucv_priv *privptr;
1122 fsm_newstate(conn->fsm, CONN_STATE_IDLE);
1123 conn->prof.tx_pending--;
1124 privptr = (struct netiucv_priv *)conn->netdev->priv;
1126 privptr->stats.tx_errors++;
1128 dev_kfree_skb(nskb);
1131 * Remove our headers. They get added
1132 * again on retransmit.
1134 skb_pull(skb, NETIUCV_HDRLEN);
1135 skb_trim(skb, skb->len - NETIUCV_HDRLEN);
1137 printk(KERN_INFO "iucv_send returned %08x\n",
1142 atomic_inc(&nskb->users);
1143 skb_queue_tail(&conn->commit_queue, nskb);
1151 * Interface API for upper network layers
1152 *****************************************************************************/
1155 * Open an interface.
1156 * Called from generic network layer when ifconfig up is run.
1158 * @param dev Pointer to interface struct.
1160 * @return 0 on success, -ERRNO on failure. (Never fails.)
1163 netiucv_open(struct net_device *dev) {
1164 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_START, dev);
1169 * Close an interface.
1170 * Called from generic network layer when ifconfig down is run.
1172 * @param dev Pointer to interface struct.
1174 * @return 0 on success, -ERRNO on failure. (Never fails.)
1177 netiucv_close(struct net_device *dev) {
1178 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_STOP, dev);
1183 * Start transmission of a packet.
1184 * Called from generic network device layer.
1186 * @param skb Pointer to buffer containing the packet.
1187 * @param dev Pointer to interface struct.
1189 * @return 0 if packet consumed, !0 if packet rejected.
1190 * Note: If we return !0, then the packet is free'd by
1191 * the generic network layer.
1193 static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1196 struct netiucv_priv *privptr = dev->priv;
1199 * Some sanity checks ...
1202 printk(KERN_WARNING "%s: NULL sk_buff passed\n", dev->name);
1203 privptr->stats.tx_dropped++;
1206 if (skb_headroom(skb) < (NETIUCV_HDRLEN)) {
1208 "%s: Got sk_buff with head room < %ld bytes\n",
1209 dev->name, NETIUCV_HDRLEN);
1211 privptr->stats.tx_dropped++;
1216 * If connection is not running, try to restart it
1217 * and throw away packet.
1219 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1220 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1222 privptr->stats.tx_dropped++;
1223 privptr->stats.tx_errors++;
1224 privptr->stats.tx_carrier_errors++;
1228 if (netiucv_test_and_set_busy(dev))
1231 dev->trans_start = jiffies;
1232 if (netiucv_transmit_skb(privptr->conn, skb) != 0)
1234 netiucv_clear_busy(dev);
1239 * Returns interface statistics of a device.
1241 * @param dev Pointer to interface struct.
1243 * @return Pointer to stats struct of this interface.
1245 static struct net_device_stats *
1246 netiucv_stats (struct net_device * dev)
1248 return &((struct netiucv_priv *)dev->priv)->stats;
1252 * Sets MTU of an interface.
1254 * @param dev Pointer to interface struct.
1255 * @param new_mtu The new MTU to use for this interface.
1257 * @return 0 on success, -EINVAL if MTU is out of valid range.
1258 * (valid range is 576 .. NETIUCV_MTU_MAX).
1261 netiucv_change_mtu (struct net_device * dev, int new_mtu)
1263 if ((new_mtu < 576) || (new_mtu > NETIUCV_MTU_MAX))
1270 * attributes in sysfs
1271 *****************************************************************************/
1274 user_show (struct device *dev, char *buf)
1276 struct netiucv_priv *priv = dev->driver_data;
1278 return sprintf(buf, "%s\n", netiucv_printname(priv->conn->userid));
1282 user_write (struct device *dev, const char *buf, size_t count)
1284 struct netiucv_priv *priv = dev->driver_data;
1285 struct net_device *ndev = priv->conn->netdev;
1293 "netiucv: username too long (%d)!\n", (int)count);
1297 tmp = strsep((char **) &buf, "\n");
1298 for (i=0, p=tmp; i<8 && *p; i++, p++) {
1299 if (isalnum(*p) || (*p == '$'))
1301 else if (*p == '\n') {
1302 /* trailing lf, grr */
1306 "netiucv: Invalid character in username!\n");
1311 username[i++] = ' ';
1314 if (memcmp(username, priv->conn->userid, 8) != 0) {
1315 /* username changed */
1316 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1318 "netiucv: device %s active, connected to %s\n",
1319 dev->bus_id, priv->conn->userid);
1321 "netiucv: user cannot be updated\n");
1325 memcpy(priv->conn->userid, username, 9);
1331 static DEVICE_ATTR(user, 0644, user_show, user_write);
1334 buffer_show (struct device *dev, char *buf)
1336 struct netiucv_priv *priv = dev->driver_data;
1338 return sprintf(buf, "%d\n", priv->conn->max_buffsize);
1342 buffer_write (struct device *dev, const char *buf, size_t count)
1344 struct netiucv_priv *priv = dev->driver_data;
1345 struct net_device *ndev = priv->conn->netdev;
1352 bs1 = simple_strtoul(buf, &e, 0);
1354 if (e && (!isspace(*e))) {
1356 "netiucv: Invalid character in buffer!\n");
1359 if (bs1 > NETIUCV_BUFSIZE_MAX) {
1361 "netiucv: Given buffer size %d too large.\n",
1366 if ((ndev->flags & IFF_RUNNING) &&
1367 (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2)))
1369 if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN))
1372 priv->conn->max_buffsize = bs1;
1373 if (!(ndev->flags & IFF_RUNNING))
1374 ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN;
1375 priv->conn->flags |= CONN_FLAGS_BUFSIZE_CHANGED;
1381 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
1384 dev_fsm_show (struct device *dev, char *buf)
1386 struct netiucv_priv *priv = dev->driver_data;
1388 return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm));
1391 static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL);
1394 conn_fsm_show (struct device *dev, char *buf)
1396 struct netiucv_priv *priv = dev->driver_data;
1398 return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm));
1401 static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL);
1404 maxmulti_show (struct device *dev, char *buf)
1406 struct netiucv_priv *priv = dev->driver_data;
1408 return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti);
1412 maxmulti_write (struct device *dev, const char *buf, size_t count)
1414 struct netiucv_priv *priv = dev->driver_data;
1416 priv->conn->prof.maxmulti = 0;
1420 static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write);
1423 maxcq_show (struct device *dev, char *buf)
1425 struct netiucv_priv *priv = dev->driver_data;
1427 return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue);
1431 maxcq_write (struct device *dev, const char *buf, size_t count)
1433 struct netiucv_priv *priv = dev->driver_data;
1435 priv->conn->prof.maxcqueue = 0;
1439 static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write);
1442 sdoio_show (struct device *dev, char *buf)
1444 struct netiucv_priv *priv = dev->driver_data;
1446 return sprintf(buf, "%ld\n", priv->conn->prof.doios_single);
1450 sdoio_write (struct device *dev, const char *buf, size_t count)
1452 struct netiucv_priv *priv = dev->driver_data;
1454 priv->conn->prof.doios_single = 0;
1458 static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write);
1461 mdoio_show (struct device *dev, char *buf)
1463 struct netiucv_priv *priv = dev->driver_data;
1465 return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi);
1469 mdoio_write (struct device *dev, const char *buf, size_t count)
1471 struct netiucv_priv *priv = dev->driver_data;
1473 priv->conn->prof.doios_multi = 0;
1477 static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write);
1480 txlen_show (struct device *dev, char *buf)
1482 struct netiucv_priv *priv = dev->driver_data;
1484 return sprintf(buf, "%ld\n", priv->conn->prof.txlen);
1488 txlen_write (struct device *dev, const char *buf, size_t count)
1490 struct netiucv_priv *priv = dev->driver_data;
1492 priv->conn->prof.txlen = 0;
1496 static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write);
1499 txtime_show (struct device *dev, char *buf)
1501 struct netiucv_priv *priv = dev->driver_data;
1503 return sprintf(buf, "%ld\n", priv->conn->prof.tx_time);
1507 txtime_write (struct device *dev, const char *buf, size_t count)
1509 struct netiucv_priv *priv = dev->driver_data;
1511 priv->conn->prof.tx_time = 0;
1515 static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write);
1518 txpend_show (struct device *dev, char *buf)
1520 struct netiucv_priv *priv = dev->driver_data;
1522 return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending);
1526 txpend_write (struct device *dev, const char *buf, size_t count)
1528 struct netiucv_priv *priv = dev->driver_data;
1530 priv->conn->prof.tx_pending = 0;
1534 static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write);
1537 txmpnd_show (struct device *dev, char *buf)
1539 struct netiucv_priv *priv = dev->driver_data;
1541 return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending);
1545 txmpnd_write (struct device *dev, const char *buf, size_t count)
1547 struct netiucv_priv *priv = dev->driver_data;
1549 priv->conn->prof.tx_max_pending = 0;
1553 static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write);
1555 static struct attribute *netiucv_attrs[] = {
1556 &dev_attr_buffer.attr,
1557 &dev_attr_user.attr,
1561 static struct attribute_group netiucv_attr_group = {
1562 .attrs = netiucv_attrs,
1565 static struct attribute *netiucv_stat_attrs[] = {
1566 &dev_attr_device_fsm_state.attr,
1567 &dev_attr_connection_fsm_state.attr,
1568 &dev_attr_max_tx_buffer_used.attr,
1569 &dev_attr_max_chained_skbs.attr,
1570 &dev_attr_tx_single_write_ops.attr,
1571 &dev_attr_tx_multi_write_ops.attr,
1572 &dev_attr_netto_bytes.attr,
1573 &dev_attr_max_tx_io_time.attr,
1574 &dev_attr_tx_pending.attr,
1575 &dev_attr_tx_max_pending.attr,
1579 static struct attribute_group netiucv_stat_attr_group = {
1581 .attrs = netiucv_stat_attrs,
1585 netiucv_add_files(struct device *dev)
1589 pr_debug("%s() called\n", __FUNCTION__);
1591 ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group);
1594 ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group);
1596 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1601 netiucv_remove_files(struct device *dev)
1603 pr_debug("%s() called\n", __FUNCTION__);
1604 sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group);
1605 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1609 netiucv_register_device(struct net_device *ndev)
1611 struct netiucv_priv *priv = ndev->priv;
1612 struct device *dev = kmalloc(sizeof(struct device), GFP_KERNEL);
1616 pr_debug("%s() called\n", __FUNCTION__);
1619 memset(dev, 0, sizeof(struct device));
1620 snprintf(dev->bus_id, BUS_ID_SIZE, "net%s", ndev->name);
1621 dev->bus = &iucv_bus;
1622 dev->parent = iucv_root;
1624 * The release function could be called after the
1625 * module has been unloaded. It's _only_ task is to
1626 * free the struct. Therefore, we specify kfree()
1627 * directly here. (Probably a little bit obfuscating
1628 * but legitime ...).
1630 dev->release = (void (*)(struct device *))kfree;
1634 ret = device_register(dev);
1638 ret = netiucv_add_files(dev);
1641 dev->driver_data = priv;
1646 device_unregister(dev);
1651 netiucv_unregister_device(struct device *dev)
1653 pr_debug("%s() called\n", __FUNCTION__);
1654 netiucv_remove_files(dev);
1655 device_unregister(dev);
1659 * Allocate and initialize a new connection structure.
1660 * Add it to the list of connections;
1662 static struct iucv_connection *
1663 netiucv_new_connection(struct net_device *dev, char *username)
1665 struct iucv_connection **clist = &connections;
1666 struct iucv_connection *conn =
1667 (struct iucv_connection *)
1668 kmalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1671 memset(conn, 0, sizeof(struct iucv_connection));
1672 skb_queue_head_init(&conn->collect_queue);
1673 skb_queue_head_init(&conn->commit_queue);
1674 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1677 conn->rx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1678 GFP_KERNEL | GFP_DMA);
1679 if (!conn->rx_buff) {
1683 conn->tx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1684 GFP_KERNEL | GFP_DMA);
1685 if (!conn->tx_buff) {
1686 kfree_skb(conn->rx_buff);
1690 conn->fsm = init_fsm("netiucvconn", conn_state_names,
1691 conn_event_names, NR_CONN_STATES,
1692 NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN,
1695 kfree_skb(conn->tx_buff);
1696 kfree_skb(conn->rx_buff);
1700 fsm_settimer(conn->fsm, &conn->timer);
1701 fsm_newstate(conn->fsm, CONN_STATE_INVALID);
1704 memcpy(conn->userid, username, 9);
1705 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1708 conn->next = *clist;
1715 * Release a connection structure and remove it from the
1716 * list of connections.
1719 netiucv_remove_connection(struct iucv_connection *conn)
1721 struct iucv_connection **clist = &connections;
1723 pr_debug("%s() called\n", __FUNCTION__);
1728 if (*clist == conn) {
1729 *clist = conn->next;
1730 if (conn->handle != 0) {
1731 iucv_unregister_program(conn->handle);
1734 fsm_deltimer(&conn->timer);
1735 kfree_fsm(conn->fsm);
1736 kfree_skb(conn->rx_buff);
1737 kfree_skb(conn->tx_buff);
1740 clist = &((*clist)->next);
1745 * Release everything of a net device.
1748 netiucv_free_netdevice(struct net_device *dev)
1750 struct netiucv_priv *privptr;
1752 pr_debug("%s() called\n", __FUNCTION__);
1757 privptr = (struct netiucv_priv *)dev->priv;
1760 fsm_deltimer(&privptr->timer);
1762 netiucv_remove_connection(privptr->conn);
1764 kfree_fsm(privptr->fsm);
1765 privptr->conn = 0; privptr->fsm = 0;
1766 /* privptr gets freed by free_netdev() */
1772 * Initialize a net device. (Called from kernel in alloc_netdev())
1775 netiucv_setup_netdevice(struct net_device *dev)
1777 memset(dev->priv, 0, sizeof(struct netiucv_priv));
1779 dev->mtu = NETIUCV_MTU_DEFAULT;
1780 dev->hard_start_xmit = netiucv_tx;
1781 dev->open = netiucv_open;
1782 dev->stop = netiucv_close;
1783 dev->get_stats = netiucv_stats;
1784 dev->change_mtu = netiucv_change_mtu;
1785 dev->destructor = netiucv_free_netdevice;
1786 dev->hard_header_len = NETIUCV_HDRLEN;
1788 dev->type = ARPHRD_SLIP;
1789 dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT;
1790 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1791 SET_MODULE_OWNER(dev);
1795 * Allocate and initialize everything of a net device.
1797 static struct net_device *
1798 netiucv_init_netdevice(char *username)
1800 struct netiucv_priv *privptr;
1801 struct net_device *dev;
1803 dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d",
1804 netiucv_setup_netdevice);
1808 privptr = (struct netiucv_priv *)dev->priv;
1809 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
1810 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
1811 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
1812 if (privptr->fsm == NULL) {
1816 privptr->conn = netiucv_new_connection(dev, username);
1817 if (!privptr->conn) {
1818 kfree_fsm(privptr->fsm);
1822 fsm_settimer(privptr->fsm, &privptr->timer);
1823 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
1829 conn_write(struct device_driver *drv, const char *buf, size_t count)
1834 struct net_device *dev;
1838 "netiucv: username too long (%d)!\n", (int)count);
1842 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) {
1843 if (isalnum(*p) || (*p == '$'))
1845 else if (*p == '\n') {
1846 /* trailing lf, grr */
1850 "netiucv: Invalid character in username!\n");
1855 username[i++] = ' ';
1857 dev = netiucv_init_netdevice(username);
1860 "netiucv: Could not allocate network device structure "
1861 "for user '%s'\n", netiucv_printname(username));
1865 if ((ret = register_netdev(dev))) {
1869 if ((ret = netiucv_register_device(dev))) {
1870 unregister_netdev(dev);
1875 SET_NETDEV_DEV(dev, (struct device*)((struct netiucv_priv*)dev->priv)->dev);
1876 printk(KERN_INFO "%s: '%s'\n", dev->name, netiucv_printname(username));
1882 "netiucv: Could not register '%s'\n", dev->name);
1883 netiucv_free_netdevice(dev);
1887 DRIVER_ATTR(connection, 0200, NULL, conn_write);
1890 remove_write (struct device_driver *drv, const char *buf, size_t count)
1892 struct iucv_connection **clist = &connections;
1893 struct net_device *ndev;
1894 struct netiucv_priv *priv;
1896 char name[IFNAMSIZ];
1900 pr_debug("%s() called\n", __FUNCTION__);
1902 if (count >= IFNAMSIZ)
1905 for (i=0, p=(char *)buf; i<count && *p; i++, p++) {
1906 if ((*p == '\n') | (*p == ' ')) {
1907 /* trailing lf, grr */
1916 ndev = (*clist)->netdev;
1917 priv = (struct netiucv_priv*)ndev->priv;
1920 if (strncmp(name, ndev->name, count)) {
1921 clist = &((*clist)->next);
1924 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1926 "netiucv: net device %s active with peer %s\n",
1927 ndev->name, priv->conn->userid);
1929 "netiucv: %s cannot be removed\n",
1933 unregister_netdev(ndev);
1934 netiucv_unregister_device(dev);
1938 "netiucv: net device %s unknown\n", name);
1942 DRIVER_ATTR(remove, 0200, NULL, remove_write);
1944 static struct device_driver netiucv_driver = {
1950 netiucv_banner(void)
1952 char vbuf[] = "$Revision: 1.54 $";
1953 char *version = vbuf;
1955 if ((version = strchr(version, ':'))) {
1956 char *p = strchr(version + 1, '$');
1961 printk(KERN_INFO "NETIUCV driver Version%s initialized\n", version);
1967 while (connections) {
1968 struct net_device *ndev = connections->netdev;
1969 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv;
1970 struct device *dev = priv->dev;
1972 unregister_netdev(ndev);
1973 netiucv_unregister_device(dev);
1976 driver_remove_file(&netiucv_driver, &driver_attr_connection);
1977 driver_remove_file(&netiucv_driver, &driver_attr_remove);
1978 driver_unregister(&netiucv_driver);
1980 printk(KERN_INFO "NETIUCV driver unloaded\n");
1989 ret = driver_register(&netiucv_driver);
1991 printk(KERN_ERR "NETIUCV: failed to register driver.\n");
1995 /* Add entry for specifying connections. */
1996 ret = driver_create_file(&netiucv_driver, &driver_attr_connection);
1998 ret = driver_create_file(&netiucv_driver, &driver_attr_remove);
2001 printk(KERN_ERR "NETIUCV: failed to add driver attribute.\n");
2002 driver_unregister(&netiucv_driver);
2007 module_init(netiucv_init);
2008 module_exit(netiucv_exit);
2009 MODULE_LICENSE("GPL");