2 * $Id: netiucv.c,v 1.57 2004/06/30 09:26:40 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.57 $
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;
103 struct net_device *netdev;
104 struct connection_profile prof;
109 * Linked list of all connection structs.
111 static struct iucv_connection *connections;
114 * Representation of event-data for the
115 * connection state machine.
118 struct iucv_connection *conn;
123 * Private part of the network device structure
125 struct netiucv_priv {
126 struct net_device_stats stats;
129 struct iucv_connection *conn;
134 * Link level header for a packet.
136 typedef struct ll_header_t {
140 #define NETIUCV_HDRLEN (sizeof(ll_header))
141 #define NETIUCV_BUFSIZE_MAX 32768
142 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
143 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
144 #define NETIUCV_MTU_DEFAULT 9216
145 #define NETIUCV_QUEUELEN_DEFAULT 50
146 #define NETIUCV_TIMEOUT_5SEC 5000
149 * Compatibility macros for busy handling
150 * of network devices.
152 static __inline__ void netiucv_clear_busy(struct net_device *dev)
154 clear_bit(0, &(((struct netiucv_priv *)dev->priv)->tbusy));
155 netif_wake_queue(dev);
158 static __inline__ int netiucv_test_and_set_busy(struct net_device *dev)
160 netif_stop_queue(dev);
161 return test_and_set_bit(0, &((struct netiucv_priv *)dev->priv)->tbusy);
164 static __u8 iucv_host[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
165 static __u8 iucvMagic[16] = {
166 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
167 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
171 * This mask means the 16-byte IUCV "magic" and the origin userid must
172 * match exactly as specified in order to give connection_pending()
175 static __u8 mask[] = {
176 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
177 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
178 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
182 * Convert an iucv userId to its printable
183 * form (strip whitespace at end).
185 * @param An iucv userId
187 * @returns The printable string (static data!!)
189 static __inline__ char *
190 netiucv_printname(char *name)
194 memcpy(tmp, name, 8);
196 while (*p && (!isspace(*p)))
203 * States of the interface statemachine.
211 * MUST be always the last element!!
216 static const char *dev_state_names[] = {
224 * Events of the interface statemachine.
232 * MUST be always the last element!!
237 static const char *dev_event_names[] = {
245 * Events of the connection statemachine
249 * Events, representing callbacks from
250 * lowlevel iucv layer)
261 * Events, representing errors return codes from
262 * calls to lowlevel iucv layer
266 * Event, representing timer expiry.
271 * Events, representing commands from upper levels.
277 * MUST be always the last element!!
282 static const char *conn_event_names[] = {
283 "Remote connection request",
284 "Remote connection acknowledge",
285 "Remote connection reject",
286 "Connection suspended",
287 "Connection resumed",
298 * States of the connection statemachine.
302 * Connection not assigned to any device,
303 * initial state, invalid
308 * Userid assigned but not operating
313 * Connection registered,
314 * no connection request sent yet,
315 * no connection request received
317 CONN_STATE_STARTWAIT,
320 * Connection registered and connection request sent,
321 * no acknowledge and no connection request received yet.
323 CONN_STATE_SETUPWAIT,
326 * Connection up and running idle
331 * Data sent, awaiting CONN_EVENT_TXDONE
336 * Error during registration.
341 * Error during registration.
346 * MUST be always the last element!!
351 static const char *conn_state_names[] = {
359 "Registration error",
365 * Callback-wrappers, called from lowlevel iucv layer.
366 *****************************************************************************/
369 netiucv_callback_rx(iucv_MessagePending *eib, void *pgm_data)
371 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
372 struct iucv_event ev;
375 ev.data = (void *)eib;
377 fsm_event(conn->fsm, CONN_EVENT_RX, &ev);
381 netiucv_callback_txdone(iucv_MessageComplete *eib, void *pgm_data)
383 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
384 struct iucv_event ev;
387 ev.data = (void *)eib;
388 fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev);
392 netiucv_callback_connack(iucv_ConnectionComplete *eib, void *pgm_data)
394 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
395 struct iucv_event ev;
398 ev.data = (void *)eib;
399 fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, &ev);
403 netiucv_callback_connreq(iucv_ConnectionPending *eib, void *pgm_data)
405 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
406 struct iucv_event ev;
409 ev.data = (void *)eib;
410 fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev);
414 netiucv_callback_connrej(iucv_ConnectionSevered *eib, void *pgm_data)
416 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
417 struct iucv_event ev;
420 ev.data = (void *)eib;
421 fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, &ev);
425 netiucv_callback_connsusp(iucv_ConnectionQuiesced *eib, void *pgm_data)
427 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
428 struct iucv_event ev;
431 ev.data = (void *)eib;
432 fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, &ev);
436 netiucv_callback_connres(iucv_ConnectionResumed *eib, void *pgm_data)
438 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
439 struct iucv_event ev;
442 ev.data = (void *)eib;
443 fsm_event(conn->fsm, CONN_EVENT_CONN_RES, &ev);
446 static iucv_interrupt_ops_t netiucv_ops = {
447 .ConnectionPending = netiucv_callback_connreq,
448 .ConnectionComplete = netiucv_callback_connack,
449 .ConnectionSevered = netiucv_callback_connrej,
450 .ConnectionQuiesced = netiucv_callback_connsusp,
451 .ConnectionResumed = netiucv_callback_connres,
452 .MessagePending = netiucv_callback_rx,
453 .MessageComplete = netiucv_callback_txdone
457 * Dummy NOP action for all statemachines
460 fsm_action_nop(fsm_instance *fi, int event, void *arg)
465 * Actions of the connection statemachine
466 *****************************************************************************/
469 * Helper function for conn_action_rx()
470 * Unpack a just received skb and hand it over to
473 * @param conn The connection where this skb has been received.
474 * @param pskb The received skb.
476 //static __inline__ void
478 netiucv_unpack_skb(struct iucv_connection *conn, struct sk_buff *pskb)
480 struct net_device *dev = conn->netdev;
481 struct netiucv_priv *privptr = dev->priv;
484 skb_put(pskb, NETIUCV_HDRLEN);
486 pskb->ip_summed = CHECKSUM_NONE;
487 pskb->protocol = ntohs(ETH_P_IP);
491 ll_header *header = (ll_header *)pskb->data;
493 if (header->next == 0)
496 skb_pull(pskb, NETIUCV_HDRLEN);
497 header->next -= offset;
498 offset += header->next;
499 header->next -= NETIUCV_HDRLEN;
500 if (skb_tailroom(pskb) < header->next) {
502 "%s: Illegal next field in iucv header: "
504 dev->name, header->next, skb_tailroom(pskb));
507 skb_put(pskb, header->next);
508 pskb->mac.raw = pskb->data;
509 skb = dev_alloc_skb(pskb->len);
512 "%s Out of memory in netiucv_unpack_skb\n",
514 privptr->stats.rx_dropped++;
517 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
518 skb->mac.raw = skb->data;
519 skb->dev = pskb->dev;
520 skb->protocol = pskb->protocol;
521 pskb->ip_summed = CHECKSUM_UNNECESSARY;
523 * Since receiving is always initiated from a tasklet (in iucv.c),
524 * we must use netif_rx_ni() instead of netif_rx()
527 dev->last_rx = jiffies;
528 privptr->stats.rx_packets++;
529 privptr->stats.rx_bytes += skb->len;
530 skb_pull(pskb, header->next);
531 skb_put(pskb, NETIUCV_HDRLEN);
536 conn_action_rx(fsm_instance *fi, int event, void *arg)
538 struct iucv_event *ev = (struct iucv_event *)arg;
539 struct iucv_connection *conn = ev->conn;
540 iucv_MessagePending *eib = (iucv_MessagePending *)ev->data;
541 struct netiucv_priv *privptr = (struct netiucv_priv *)conn->netdev->priv;
543 __u32 msglen = eib->ln1msg2.ipbfln1f;
546 pr_debug("%s() called\n", __FUNCTION__);
549 /* FRITZ: How to tell iucv LL to drop the msg? */
551 "Received data for unlinked connection\n");
554 if (msglen > conn->max_buffsize) {
555 /* FRITZ: How to tell iucv LL to drop the msg? */
556 privptr->stats.rx_dropped++;
559 conn->rx_buff->data = conn->rx_buff->tail = conn->rx_buff->head;
560 conn->rx_buff->len = 0;
561 rc = iucv_receive(conn->pathid, eib->ipmsgid, eib->iptrgcls,
562 conn->rx_buff->data, msglen, NULL, NULL, NULL);
563 if (rc != 0 || msglen < 5) {
564 privptr->stats.rx_errors++;
565 printk(KERN_INFO "iucv_receive returned %08x\n", rc);
568 netiucv_unpack_skb(conn, conn->rx_buff);
572 conn_action_txdone(fsm_instance *fi, int event, void *arg)
574 struct iucv_event *ev = (struct iucv_event *)arg;
575 struct iucv_connection *conn = ev->conn;
576 iucv_MessageComplete *eib = (iucv_MessageComplete *)ev->data;
577 struct netiucv_priv *privptr = NULL;
578 /* Shut up, gcc! skb is always below 2G. */
579 __u32 single_flag = eib->ipmsgtag;
582 __u32 stat_maxcq = 0;
584 unsigned long saveflags;
587 pr_debug("%s() called\n", __FUNCTION__);
589 if (conn && conn->netdev && conn->netdev->priv)
590 privptr = (struct netiucv_priv *)conn->netdev->priv;
591 conn->prof.tx_pending--;
593 if ((skb = skb_dequeue(&conn->commit_queue))) {
594 atomic_dec(&skb->users);
595 dev_kfree_skb_any(skb);
597 privptr->stats.tx_packets++;
598 privptr->stats.tx_bytes +=
599 (skb->len - NETIUCV_HDRLEN
604 conn->tx_buff->data = conn->tx_buff->tail = conn->tx_buff->head;
605 conn->tx_buff->len = 0;
606 spin_lock_irqsave(&conn->collect_lock, saveflags);
607 while ((skb = skb_dequeue(&conn->collect_queue))) {
608 header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN;
609 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
611 memcpy(skb_put(conn->tx_buff, skb->len), skb->data, skb->len);
615 atomic_dec(&skb->users);
616 dev_kfree_skb_any(skb);
618 if (conn->collect_len > conn->prof.maxmulti)
619 conn->prof.maxmulti = conn->collect_len;
620 conn->collect_len = 0;
621 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
622 if (conn->tx_buff->len) {
626 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
629 conn->prof.send_stamp = xtime;
630 rc = iucv_send(conn->pathid, NULL, 0, 0, 0, 0,
631 conn->tx_buff->data, conn->tx_buff->len);
632 conn->prof.doios_multi++;
633 conn->prof.txlen += conn->tx_buff->len;
634 conn->prof.tx_pending++;
635 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
636 conn->prof.tx_max_pending = conn->prof.tx_pending;
638 conn->prof.tx_pending--;
639 fsm_newstate(fi, CONN_STATE_IDLE);
641 privptr->stats.tx_errors += txpackets;
642 printk(KERN_INFO "iucv_send returned %08x\n",
646 privptr->stats.tx_packets += txpackets;
647 privptr->stats.tx_bytes += txbytes;
649 if (stat_maxcq > conn->prof.maxcqueue)
650 conn->prof.maxcqueue = stat_maxcq;
653 fsm_newstate(fi, CONN_STATE_IDLE);
657 conn_action_connaccept(fsm_instance *fi, int event, void *arg)
659 struct iucv_event *ev = (struct iucv_event *)arg;
660 struct iucv_connection *conn = ev->conn;
661 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
662 struct net_device *netdev = conn->netdev;
663 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
668 pr_debug("%s() called\n", __FUNCTION__);
670 rc = iucv_accept(eib->ippathid, NETIUCV_QUEUELEN_DEFAULT, udata, 0,
671 conn->handle, conn, NULL, &msglimit);
674 "%s: IUCV accept failed with error %d\n",
678 fsm_newstate(fi, CONN_STATE_IDLE);
679 conn->pathid = eib->ippathid;
680 netdev->tx_queue_len = msglimit;
681 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
685 conn_action_connreject(fsm_instance *fi, int event, void *arg)
687 struct iucv_event *ev = (struct iucv_event *)arg;
688 struct iucv_connection *conn = ev->conn;
689 struct net_device *netdev = conn->netdev;
690 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
693 pr_debug("%s() called\n", __FUNCTION__);
695 iucv_sever(eib->ippathid, udata);
696 if (eib->ippathid != conn->pathid) {
698 "%s: IR Connection Pending; pathid %d does not match original pathid %d\n",
699 netdev->name, eib->ippathid, conn->pathid);
700 iucv_sever(conn->pathid, udata);
705 conn_action_connack(fsm_instance *fi, int event, void *arg)
707 struct iucv_event *ev = (struct iucv_event *)arg;
708 struct iucv_connection *conn = ev->conn;
709 iucv_ConnectionComplete *eib = (iucv_ConnectionComplete *)ev->data;
710 struct net_device *netdev = conn->netdev;
711 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
713 pr_debug("%s() called\n", __FUNCTION__);
715 fsm_deltimer(&conn->timer);
716 fsm_newstate(fi, CONN_STATE_IDLE);
717 if (eib->ippathid != conn->pathid) {
719 "%s: IR Connection Complete; pathid %d does not match original pathid %d\n",
720 netdev->name, eib->ippathid, conn->pathid);
721 conn->pathid = eib->ippathid;
723 netdev->tx_queue_len = eib->ipmsglim;
724 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
728 conn_action_conntimsev(fsm_instance *fi, int event, void *arg)
730 struct iucv_connection *conn = (struct iucv_connection *)arg;
733 pr_debug("%s() called\n", __FUNCTION__);
735 fsm_deltimer(&conn->timer);
736 iucv_sever(conn->pathid, udata);
737 fsm_newstate(fi, CONN_STATE_STARTWAIT);
741 conn_action_connsever(fsm_instance *fi, int event, void *arg)
743 struct iucv_event *ev = (struct iucv_event *)arg;
744 struct iucv_connection *conn = ev->conn;
745 struct net_device *netdev = conn->netdev;
746 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
749 pr_debug("%s() called\n", __FUNCTION__);
751 fsm_deltimer(&conn->timer);
752 iucv_sever(conn->pathid, udata);
753 printk(KERN_INFO "%s: Remote dropped connection\n",
755 fsm_newstate(fi, CONN_STATE_STARTWAIT);
756 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
760 conn_action_start(fsm_instance *fi, int event, void *arg)
762 struct iucv_event *ev = (struct iucv_event *)arg;
763 struct iucv_connection *conn = ev->conn;
767 pr_debug("%s() called\n", __FUNCTION__);
769 if (conn->handle == 0) {
771 iucv_register_program(iucvMagic, conn->userid, mask,
773 fsm_newstate(fi, CONN_STATE_STARTWAIT);
774 if (conn->handle <= 0) {
775 fsm_newstate(fi, CONN_STATE_REGERR);
780 pr_debug("%s('%s'): registered successfully\n",
781 conn->netdev->name, conn->userid);
784 pr_debug("%s('%s'): connecting ...\n",
785 conn->netdev->name, conn->userid);
787 /* We must set the state before calling iucv_connect because the callback
788 * handler could be called at any point after the connection request is
791 fsm_newstate(fi, CONN_STATE_SETUPWAIT);
792 rc = iucv_connect(&(conn->pathid), NETIUCV_QUEUELEN_DEFAULT, iucvMagic,
793 conn->userid, iucv_host, 0, NULL, &msglimit, conn->handle,
797 conn->netdev->tx_queue_len = msglimit;
798 fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC,
799 CONN_EVENT_TIMER, conn);
803 "%s: User %s is currently not available.\n",
805 netiucv_printname(conn->userid));
806 fsm_newstate(fi, CONN_STATE_STARTWAIT);
810 "%s: User %s is currently not ready.\n",
812 netiucv_printname(conn->userid));
813 fsm_newstate(fi, CONN_STATE_STARTWAIT);
817 "%s: Too many IUCV connections.\n",
819 fsm_newstate(fi, CONN_STATE_CONNERR);
823 "%s: User %s has too many IUCV connections.\n",
825 netiucv_printname(conn->userid));
826 fsm_newstate(fi, CONN_STATE_CONNERR);
830 "%s: No IUCV authorization in CP directory.\n",
832 fsm_newstate(fi, CONN_STATE_CONNERR);
836 "%s: iucv_connect returned error %d\n",
837 conn->netdev->name, rc);
838 fsm_newstate(fi, CONN_STATE_CONNERR);
841 iucv_unregister_program(conn->handle);
846 netiucv_purge_skb_queue(struct sk_buff_head *q)
850 while ((skb = skb_dequeue(q))) {
851 atomic_dec(&skb->users);
852 dev_kfree_skb_any(skb);
857 conn_action_stop(fsm_instance *fi, int event, void *arg)
859 struct iucv_event *ev = (struct iucv_event *)arg;
860 struct iucv_connection *conn = ev->conn;
861 struct net_device *netdev = conn->netdev;
862 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
864 pr_debug("%s() called\n", __FUNCTION__);
866 fsm_deltimer(&conn->timer);
867 fsm_newstate(fi, CONN_STATE_STOPPED);
868 netiucv_purge_skb_queue(&conn->collect_queue);
870 iucv_unregister_program(conn->handle);
872 netiucv_purge_skb_queue(&conn->commit_queue);
873 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
877 conn_action_inval(fsm_instance *fi, int event, void *arg)
879 struct iucv_event *ev = (struct iucv_event *)arg;
880 struct iucv_connection *conn = ev->conn;
881 struct net_device *netdev = conn->netdev;
884 "%s: Cannot connect without username\n",
888 static const fsm_node conn_fsm[] = {
889 { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval },
890 { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start },
892 { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop },
893 { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop },
894 { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop },
895 { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop },
896 { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop },
897 { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop },
898 { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop },
900 { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject },
901 { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
902 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
903 { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject },
904 { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject },
906 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack },
907 { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev },
909 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever },
910 { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever },
911 { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever },
913 { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx },
914 { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx },
916 { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone },
917 { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone },
920 static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node);
924 * Actions for interface - statemachine.
925 *****************************************************************************/
928 * Startup connection by sending CONN_EVENT_START to it.
930 * @param fi An instance of an interface statemachine.
931 * @param event The event, just happened.
932 * @param arg Generic pointer, casted from struct net_device * upon call.
935 dev_action_start(fsm_instance *fi, int event, void *arg)
937 struct net_device *dev = (struct net_device *)arg;
938 struct netiucv_priv *privptr = dev->priv;
939 struct iucv_event ev;
941 pr_debug("%s() called\n", __FUNCTION__);
943 ev.conn = privptr->conn;
944 fsm_newstate(fi, DEV_STATE_STARTWAIT);
945 fsm_event(privptr->conn->fsm, CONN_EVENT_START, &ev);
949 * Shutdown connection by sending CONN_EVENT_STOP to it.
951 * @param fi An instance of an interface statemachine.
952 * @param event The event, just happened.
953 * @param arg Generic pointer, casted from struct net_device * upon call.
956 dev_action_stop(fsm_instance *fi, int event, void *arg)
958 struct net_device *dev = (struct net_device *)arg;
959 struct netiucv_priv *privptr = dev->priv;
960 struct iucv_event ev;
962 pr_debug("%s() called\n", __FUNCTION__);
964 ev.conn = privptr->conn;
966 fsm_newstate(fi, DEV_STATE_STOPWAIT);
967 fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev);
971 * Called from connection statemachine
972 * when a connection is up and running.
974 * @param fi An instance of an interface statemachine.
975 * @param event The event, just happened.
976 * @param arg Generic pointer, casted from struct net_device * upon call.
979 dev_action_connup(fsm_instance *fi, int event, void *arg)
981 struct net_device *dev = (struct net_device *)arg;
982 struct netiucv_priv *privptr = dev->priv;
984 pr_debug("%s() called\n", __FUNCTION__);
986 switch (fsm_getstate(fi)) {
987 case DEV_STATE_STARTWAIT:
988 fsm_newstate(fi, DEV_STATE_RUNNING);
990 "%s: connected with remote side %s\n",
991 dev->name, privptr->conn->userid);
993 case DEV_STATE_STOPWAIT:
995 "%s: got connection UP event during shutdown!!\n",
1002 * Called from connection statemachine
1003 * when a connection has been shutdown.
1005 * @param fi An instance of an interface statemachine.
1006 * @param event The event, just happened.
1007 * @param arg Generic pointer, casted from struct net_device * upon call.
1010 dev_action_conndown(fsm_instance *fi, int event, void *arg)
1012 pr_debug("%s() called\n", __FUNCTION__);
1014 switch (fsm_getstate(fi)) {
1015 case DEV_STATE_RUNNING:
1016 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1018 case DEV_STATE_STOPWAIT:
1019 fsm_newstate(fi, DEV_STATE_STOPPED);
1024 static const fsm_node dev_fsm[] = {
1025 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
1027 { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start },
1028 { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown },
1030 { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop },
1031 { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup },
1033 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
1034 { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown },
1035 { DEV_STATE_RUNNING, DEV_EVENT_CONUP, fsm_action_nop },
1038 static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node);
1041 * Transmit a packet.
1042 * This is a helper function for netiucv_tx().
1044 * @param conn Connection to be used for sending.
1045 * @param skb Pointer to struct sk_buff of packet to send.
1046 * The linklevel header has already been set up
1049 * @return 0 on success, -ERRNO on failure. (Never fails.)
1052 netiucv_transmit_skb(struct iucv_connection *conn, struct sk_buff *skb) {
1053 unsigned long saveflags;
1057 if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) {
1058 int l = skb->len + NETIUCV_HDRLEN;
1060 spin_lock_irqsave(&conn->collect_lock, saveflags);
1061 if (conn->collect_len + l >
1062 (conn->max_buffsize - NETIUCV_HDRLEN))
1065 atomic_inc(&skb->users);
1066 skb_queue_tail(&conn->collect_queue, skb);
1067 conn->collect_len += l;
1069 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
1071 struct sk_buff *nskb = skb;
1073 * Copy the skb to a new allocated skb in lowmem only if the
1074 * data is located above 2G in memory or tailroom is < 2.
1077 ((unsigned long)(skb->tail + NETIUCV_HDRLEN)) >> 31;
1079 if (hi || (skb_tailroom(skb) < 2)) {
1080 nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
1081 NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
1084 "%s: Could not allocate tx_skb\n",
1085 conn->netdev->name);
1089 skb_reserve(nskb, NETIUCV_HDRLEN);
1090 memcpy(skb_put(nskb, skb->len),
1091 skb->data, skb->len);
1096 * skb now is below 2G and has enough room. Add headers.
1098 header.next = nskb->len + NETIUCV_HDRLEN;
1099 memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1101 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1103 fsm_newstate(conn->fsm, CONN_STATE_TX);
1104 conn->prof.send_stamp = xtime;
1106 rc = iucv_send(conn->pathid, NULL, 0, 0, 1 /* single_flag */,
1107 0, nskb->data, nskb->len);
1108 /* Shut up, gcc! nskb is always below 2G. */
1109 conn->prof.doios_single++;
1110 conn->prof.txlen += skb->len;
1111 conn->prof.tx_pending++;
1112 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
1113 conn->prof.tx_max_pending = conn->prof.tx_pending;
1115 struct netiucv_priv *privptr;
1116 fsm_newstate(conn->fsm, CONN_STATE_IDLE);
1117 conn->prof.tx_pending--;
1118 privptr = (struct netiucv_priv *)conn->netdev->priv;
1120 privptr->stats.tx_errors++;
1122 dev_kfree_skb(nskb);
1125 * Remove our headers. They get added
1126 * again on retransmit.
1128 skb_pull(skb, NETIUCV_HDRLEN);
1129 skb_trim(skb, skb->len - NETIUCV_HDRLEN);
1131 printk(KERN_INFO "iucv_send returned %08x\n",
1136 atomic_inc(&nskb->users);
1137 skb_queue_tail(&conn->commit_queue, nskb);
1145 * Interface API for upper network layers
1146 *****************************************************************************/
1149 * Open an interface.
1150 * Called from generic network layer when ifconfig up is run.
1152 * @param dev Pointer to interface struct.
1154 * @return 0 on success, -ERRNO on failure. (Never fails.)
1157 netiucv_open(struct net_device *dev) {
1158 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_START, dev);
1163 * Close an interface.
1164 * Called from generic network layer when ifconfig down is run.
1166 * @param dev Pointer to interface struct.
1168 * @return 0 on success, -ERRNO on failure. (Never fails.)
1171 netiucv_close(struct net_device *dev) {
1172 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_STOP, dev);
1177 * Start transmission of a packet.
1178 * Called from generic network device layer.
1180 * @param skb Pointer to buffer containing the packet.
1181 * @param dev Pointer to interface struct.
1183 * @return 0 if packet consumed, !0 if packet rejected.
1184 * Note: If we return !0, then the packet is free'd by
1185 * the generic network layer.
1187 static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1190 struct netiucv_priv *privptr = dev->priv;
1193 * Some sanity checks ...
1196 printk(KERN_WARNING "%s: NULL sk_buff passed\n", dev->name);
1197 privptr->stats.tx_dropped++;
1200 if (skb_headroom(skb) < (NETIUCV_HDRLEN)) {
1202 "%s: Got sk_buff with head room < %ld bytes\n",
1203 dev->name, NETIUCV_HDRLEN);
1205 privptr->stats.tx_dropped++;
1210 * If connection is not running, try to restart it
1211 * and throw away packet.
1213 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1214 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1216 privptr->stats.tx_dropped++;
1217 privptr->stats.tx_errors++;
1218 privptr->stats.tx_carrier_errors++;
1222 if (netiucv_test_and_set_busy(dev))
1225 dev->trans_start = jiffies;
1226 if (netiucv_transmit_skb(privptr->conn, skb) != 0)
1228 netiucv_clear_busy(dev);
1233 * Returns interface statistics of a device.
1235 * @param dev Pointer to interface struct.
1237 * @return Pointer to stats struct of this interface.
1239 static struct net_device_stats *
1240 netiucv_stats (struct net_device * dev)
1242 return &((struct netiucv_priv *)dev->priv)->stats;
1246 * Sets MTU of an interface.
1248 * @param dev Pointer to interface struct.
1249 * @param new_mtu The new MTU to use for this interface.
1251 * @return 0 on success, -EINVAL if MTU is out of valid range.
1252 * (valid range is 576 .. NETIUCV_MTU_MAX).
1255 netiucv_change_mtu (struct net_device * dev, int new_mtu)
1257 if ((new_mtu < 576) || (new_mtu > NETIUCV_MTU_MAX))
1264 * attributes in sysfs
1265 *****************************************************************************/
1268 user_show (struct device *dev, char *buf)
1270 struct netiucv_priv *priv = dev->driver_data;
1272 return sprintf(buf, "%s\n", netiucv_printname(priv->conn->userid));
1276 user_write (struct device *dev, const char *buf, size_t count)
1278 struct netiucv_priv *priv = dev->driver_data;
1279 struct net_device *ndev = priv->conn->netdev;
1287 "netiucv: username too long (%d)!\n", (int)count);
1291 tmp = strsep((char **) &buf, "\n");
1292 for (i=0, p=tmp; i<8 && *p; i++, p++) {
1293 if (isalnum(*p) || (*p == '$'))
1295 else if (*p == '\n') {
1296 /* trailing lf, grr */
1300 "netiucv: Invalid character in username!\n");
1305 username[i++] = ' ';
1308 if (memcmp(username, priv->conn->userid, 8) != 0) {
1309 /* username changed */
1310 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1312 "netiucv: device %s active, connected to %s\n",
1313 dev->bus_id, priv->conn->userid);
1315 "netiucv: user cannot be updated\n");
1319 memcpy(priv->conn->userid, username, 9);
1325 static DEVICE_ATTR(user, 0644, user_show, user_write);
1328 buffer_show (struct device *dev, char *buf)
1330 struct netiucv_priv *priv = dev->driver_data;
1332 return sprintf(buf, "%d\n", priv->conn->max_buffsize);
1336 buffer_write (struct device *dev, const char *buf, size_t count)
1338 struct netiucv_priv *priv = dev->driver_data;
1339 struct net_device *ndev = priv->conn->netdev;
1346 bs1 = simple_strtoul(buf, &e, 0);
1348 if (e && (!isspace(*e))) {
1350 "netiucv: Invalid character in buffer!\n");
1353 if (bs1 > NETIUCV_BUFSIZE_MAX) {
1355 "netiucv: Given buffer size %d too large.\n",
1360 if ((ndev->flags & IFF_RUNNING) &&
1361 (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2)))
1363 if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN))
1366 priv->conn->max_buffsize = bs1;
1367 if (!(ndev->flags & IFF_RUNNING))
1368 ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN;
1374 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
1377 dev_fsm_show (struct device *dev, char *buf)
1379 struct netiucv_priv *priv = dev->driver_data;
1381 return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm));
1384 static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL);
1387 conn_fsm_show (struct device *dev, char *buf)
1389 struct netiucv_priv *priv = dev->driver_data;
1391 return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm));
1394 static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL);
1397 maxmulti_show (struct device *dev, char *buf)
1399 struct netiucv_priv *priv = dev->driver_data;
1401 return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti);
1405 maxmulti_write (struct device *dev, const char *buf, size_t count)
1407 struct netiucv_priv *priv = dev->driver_data;
1409 priv->conn->prof.maxmulti = 0;
1413 static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write);
1416 maxcq_show (struct device *dev, char *buf)
1418 struct netiucv_priv *priv = dev->driver_data;
1420 return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue);
1424 maxcq_write (struct device *dev, const char *buf, size_t count)
1426 struct netiucv_priv *priv = dev->driver_data;
1428 priv->conn->prof.maxcqueue = 0;
1432 static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write);
1435 sdoio_show (struct device *dev, char *buf)
1437 struct netiucv_priv *priv = dev->driver_data;
1439 return sprintf(buf, "%ld\n", priv->conn->prof.doios_single);
1443 sdoio_write (struct device *dev, const char *buf, size_t count)
1445 struct netiucv_priv *priv = dev->driver_data;
1447 priv->conn->prof.doios_single = 0;
1451 static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write);
1454 mdoio_show (struct device *dev, char *buf)
1456 struct netiucv_priv *priv = dev->driver_data;
1458 return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi);
1462 mdoio_write (struct device *dev, const char *buf, size_t count)
1464 struct netiucv_priv *priv = dev->driver_data;
1466 priv->conn->prof.doios_multi = 0;
1470 static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write);
1473 txlen_show (struct device *dev, char *buf)
1475 struct netiucv_priv *priv = dev->driver_data;
1477 return sprintf(buf, "%ld\n", priv->conn->prof.txlen);
1481 txlen_write (struct device *dev, const char *buf, size_t count)
1483 struct netiucv_priv *priv = dev->driver_data;
1485 priv->conn->prof.txlen = 0;
1489 static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write);
1492 txtime_show (struct device *dev, char *buf)
1494 struct netiucv_priv *priv = dev->driver_data;
1496 return sprintf(buf, "%ld\n", priv->conn->prof.tx_time);
1500 txtime_write (struct device *dev, const char *buf, size_t count)
1502 struct netiucv_priv *priv = dev->driver_data;
1504 priv->conn->prof.tx_time = 0;
1508 static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write);
1511 txpend_show (struct device *dev, char *buf)
1513 struct netiucv_priv *priv = dev->driver_data;
1515 return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending);
1519 txpend_write (struct device *dev, const char *buf, size_t count)
1521 struct netiucv_priv *priv = dev->driver_data;
1523 priv->conn->prof.tx_pending = 0;
1527 static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write);
1530 txmpnd_show (struct device *dev, char *buf)
1532 struct netiucv_priv *priv = dev->driver_data;
1534 return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending);
1538 txmpnd_write (struct device *dev, const char *buf, size_t count)
1540 struct netiucv_priv *priv = dev->driver_data;
1542 priv->conn->prof.tx_max_pending = 0;
1546 static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write);
1548 static struct attribute *netiucv_attrs[] = {
1549 &dev_attr_buffer.attr,
1550 &dev_attr_user.attr,
1554 static struct attribute_group netiucv_attr_group = {
1555 .attrs = netiucv_attrs,
1558 static struct attribute *netiucv_stat_attrs[] = {
1559 &dev_attr_device_fsm_state.attr,
1560 &dev_attr_connection_fsm_state.attr,
1561 &dev_attr_max_tx_buffer_used.attr,
1562 &dev_attr_max_chained_skbs.attr,
1563 &dev_attr_tx_single_write_ops.attr,
1564 &dev_attr_tx_multi_write_ops.attr,
1565 &dev_attr_netto_bytes.attr,
1566 &dev_attr_max_tx_io_time.attr,
1567 &dev_attr_tx_pending.attr,
1568 &dev_attr_tx_max_pending.attr,
1572 static struct attribute_group netiucv_stat_attr_group = {
1574 .attrs = netiucv_stat_attrs,
1578 netiucv_add_files(struct device *dev)
1582 pr_debug("%s() called\n", __FUNCTION__);
1584 ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group);
1587 ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group);
1589 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1594 netiucv_remove_files(struct device *dev)
1596 pr_debug("%s() called\n", __FUNCTION__);
1597 sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group);
1598 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1602 netiucv_register_device(struct net_device *ndev)
1604 struct netiucv_priv *priv = ndev->priv;
1605 struct device *dev = kmalloc(sizeof(struct device), GFP_KERNEL);
1609 pr_debug("%s() called\n", __FUNCTION__);
1612 memset(dev, 0, sizeof(struct device));
1613 snprintf(dev->bus_id, BUS_ID_SIZE, "net%s", ndev->name);
1614 dev->bus = &iucv_bus;
1615 dev->parent = iucv_root;
1617 * The release function could be called after the
1618 * module has been unloaded. It's _only_ task is to
1619 * free the struct. Therefore, we specify kfree()
1620 * directly here. (Probably a little bit obfuscating
1621 * but legitime ...).
1623 dev->release = (void (*)(struct device *))kfree;
1627 ret = device_register(dev);
1631 ret = netiucv_add_files(dev);
1634 dev->driver_data = priv;
1639 device_unregister(dev);
1644 netiucv_unregister_device(struct device *dev)
1646 pr_debug("%s() called\n", __FUNCTION__);
1647 netiucv_remove_files(dev);
1648 device_unregister(dev);
1652 * Allocate and initialize a new connection structure.
1653 * Add it to the list of connections;
1655 static struct iucv_connection *
1656 netiucv_new_connection(struct net_device *dev, char *username)
1658 struct iucv_connection **clist = &connections;
1659 struct iucv_connection *conn =
1660 (struct iucv_connection *)
1661 kmalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1664 memset(conn, 0, sizeof(struct iucv_connection));
1665 skb_queue_head_init(&conn->collect_queue);
1666 skb_queue_head_init(&conn->commit_queue);
1667 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1670 conn->rx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1671 GFP_KERNEL | GFP_DMA);
1672 if (!conn->rx_buff) {
1676 conn->tx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1677 GFP_KERNEL | GFP_DMA);
1678 if (!conn->tx_buff) {
1679 kfree_skb(conn->rx_buff);
1683 conn->fsm = init_fsm("netiucvconn", conn_state_names,
1684 conn_event_names, NR_CONN_STATES,
1685 NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN,
1688 kfree_skb(conn->tx_buff);
1689 kfree_skb(conn->rx_buff);
1693 fsm_settimer(conn->fsm, &conn->timer);
1694 fsm_newstate(conn->fsm, CONN_STATE_INVALID);
1697 memcpy(conn->userid, username, 9);
1698 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1701 conn->next = *clist;
1708 * Release a connection structure and remove it from the
1709 * list of connections.
1712 netiucv_remove_connection(struct iucv_connection *conn)
1714 struct iucv_connection **clist = &connections;
1716 pr_debug("%s() called\n", __FUNCTION__);
1721 if (*clist == conn) {
1722 *clist = conn->next;
1723 if (conn->handle != 0) {
1724 iucv_unregister_program(conn->handle);
1727 fsm_deltimer(&conn->timer);
1728 kfree_fsm(conn->fsm);
1729 kfree_skb(conn->rx_buff);
1730 kfree_skb(conn->tx_buff);
1733 clist = &((*clist)->next);
1738 * Release everything of a net device.
1741 netiucv_free_netdevice(struct net_device *dev)
1743 struct netiucv_priv *privptr;
1745 pr_debug("%s() called\n", __FUNCTION__);
1750 privptr = (struct netiucv_priv *)dev->priv;
1753 netiucv_remove_connection(privptr->conn);
1755 kfree_fsm(privptr->fsm);
1756 privptr->conn = 0; privptr->fsm = 0;
1757 /* privptr gets freed by free_netdev() */
1763 * Initialize a net device. (Called from kernel in alloc_netdev())
1766 netiucv_setup_netdevice(struct net_device *dev)
1768 memset(dev->priv, 0, sizeof(struct netiucv_priv));
1770 dev->mtu = NETIUCV_MTU_DEFAULT;
1771 dev->hard_start_xmit = netiucv_tx;
1772 dev->open = netiucv_open;
1773 dev->stop = netiucv_close;
1774 dev->get_stats = netiucv_stats;
1775 dev->change_mtu = netiucv_change_mtu;
1776 dev->destructor = netiucv_free_netdevice;
1777 dev->hard_header_len = NETIUCV_HDRLEN;
1779 dev->type = ARPHRD_SLIP;
1780 dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT;
1781 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1782 SET_MODULE_OWNER(dev);
1786 * Allocate and initialize everything of a net device.
1788 static struct net_device *
1789 netiucv_init_netdevice(char *username)
1791 struct netiucv_priv *privptr;
1792 struct net_device *dev;
1794 dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d",
1795 netiucv_setup_netdevice);
1799 privptr = (struct netiucv_priv *)dev->priv;
1800 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
1801 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
1802 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
1803 if (privptr->fsm == NULL) {
1807 privptr->conn = netiucv_new_connection(dev, username);
1808 if (!privptr->conn) {
1809 kfree_fsm(privptr->fsm);
1813 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
1819 conn_write(struct device_driver *drv, const char *buf, size_t count)
1824 struct net_device *dev;
1828 "netiucv: username too long (%d)!\n", (int)count);
1832 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) {
1833 if (isalnum(*p) || (*p == '$'))
1835 else if (*p == '\n') {
1836 /* trailing lf, grr */
1840 "netiucv: Invalid character in username!\n");
1845 username[i++] = ' ';
1847 dev = netiucv_init_netdevice(username);
1850 "netiucv: Could not allocate network device structure "
1851 "for user '%s'\n", netiucv_printname(username));
1855 if ((ret = register_netdev(dev))) {
1859 if ((ret = netiucv_register_device(dev))) {
1860 unregister_netdev(dev);
1865 SET_NETDEV_DEV(dev, (struct device*)((struct netiucv_priv*)dev->priv)->dev);
1866 printk(KERN_INFO "%s: '%s'\n", dev->name, netiucv_printname(username));
1872 "netiucv: Could not register '%s'\n", dev->name);
1873 netiucv_free_netdevice(dev);
1877 DRIVER_ATTR(connection, 0200, NULL, conn_write);
1880 remove_write (struct device_driver *drv, const char *buf, size_t count)
1882 struct iucv_connection **clist = &connections;
1883 struct net_device *ndev;
1884 struct netiucv_priv *priv;
1886 char name[IFNAMSIZ];
1890 pr_debug("%s() called\n", __FUNCTION__);
1892 if (count >= IFNAMSIZ)
1895 for (i=0, p=(char *)buf; i<count && *p; i++, p++) {
1896 if ((*p == '\n') | (*p == ' ')) {
1897 /* trailing lf, grr */
1906 ndev = (*clist)->netdev;
1907 priv = (struct netiucv_priv*)ndev->priv;
1910 if (strncmp(name, ndev->name, count)) {
1911 clist = &((*clist)->next);
1914 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1916 "netiucv: net device %s active with peer %s\n",
1917 ndev->name, priv->conn->userid);
1919 "netiucv: %s cannot be removed\n",
1923 unregister_netdev(ndev);
1924 netiucv_unregister_device(dev);
1928 "netiucv: net device %s unknown\n", name);
1932 DRIVER_ATTR(remove, 0200, NULL, remove_write);
1934 static struct device_driver netiucv_driver = {
1940 netiucv_banner(void)
1942 char vbuf[] = "$Revision: 1.57 $";
1943 char *version = vbuf;
1945 if ((version = strchr(version, ':'))) {
1946 char *p = strchr(version + 1, '$');
1951 printk(KERN_INFO "NETIUCV driver Version%s initialized\n", version);
1957 while (connections) {
1958 struct net_device *ndev = connections->netdev;
1959 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv;
1960 struct device *dev = priv->dev;
1962 unregister_netdev(ndev);
1963 netiucv_unregister_device(dev);
1966 driver_remove_file(&netiucv_driver, &driver_attr_connection);
1967 driver_remove_file(&netiucv_driver, &driver_attr_remove);
1968 driver_unregister(&netiucv_driver);
1970 printk(KERN_INFO "NETIUCV driver unloaded\n");
1979 ret = driver_register(&netiucv_driver);
1981 printk(KERN_ERR "NETIUCV: failed to register driver.\n");
1985 /* Add entry for specifying connections. */
1986 ret = driver_create_file(&netiucv_driver, &driver_attr_connection);
1988 ret = driver_create_file(&netiucv_driver, &driver_attr_remove);
1991 printk(KERN_ERR "NETIUCV: failed to add driver attribute.\n");
1992 driver_unregister(&netiucv_driver);
1997 module_init(netiucv_init);
1998 module_exit(netiucv_exit);
1999 MODULE_LICENSE("GPL");