2 * $Id: netiucv.c,v 1.12 2002/11/26 16:00:54 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.12 $
37 #include <linux/version.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/errno.h>
43 #include <linux/types.h>
44 #include <linux/interrupt.h>
45 #include <linux/timer.h>
46 #include <linux/sched.h>
48 #include <linux/signal.h>
49 #include <linux/string.h>
50 #include <linux/device.h>
53 #include <linux/if_arp.h>
54 #include <linux/tcp.h>
55 #include <linux/skbuff.h>
56 #include <linux/ctype.h>
60 #include <asm/bitops.h>
61 #include <asm/uaccess.h>
70 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
71 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
72 MODULE_PARM (iucv
, "1s");
73 MODULE_PARM_DESC (iucv
,
74 "Specify the initial remote userids for iucv0 .. iucvn:\n"
75 "iucv=userid0:userid1:...:useridN");
78 static char *iucv
= "";
80 typedef struct net_device net_device
;
84 * Per connection profiling data
86 typedef struct connection_profile_t
{
87 unsigned long maxmulti
;
88 unsigned long maxcqueue
;
89 unsigned long doios_single
;
90 unsigned long doios_multi
;
92 unsigned long tx_time
;
93 struct timespec send_stamp
;
97 * Representation of one iucv connection
99 typedef struct iucv_connection_t
{
100 struct iucv_connection_t
*next
;
101 iucv_handle_t handle
;
103 struct sk_buff
*rx_buff
;
104 struct sk_buff
*tx_buff
;
105 struct sk_buff_head collect_queue
;
106 spinlock_t collect_lock
;
114 connection_profile prof
;
118 #define CONN_FLAGS_BUFSIZE_CHANGED 1
121 * Linked list of all connection structs.
123 static iucv_connection
*connections
;
126 * Representation of event-data for the
127 * connection state machine.
129 typedef struct iucv_event_t
{
130 iucv_connection
*conn
;
135 * Private part of the network device structure
137 typedef struct netiucv_priv_t
{
138 struct net_device_stats stats
;
141 iucv_connection
*conn
;
142 struct platform_device pldev
;
146 * Link level header for a packet.
148 typedef struct ll_header_t
{
152 #define NETIUCV_HDRLEN (sizeof(ll_header))
153 #define NETIUCV_BUFSIZE_MAX 32768
154 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
155 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
156 #define NETIUCV_MTU_DEFAULT 9216
157 #define NETIUCV_QUEUELEN_DEFAULT 50
158 #define NETIUCV_TIMEOUT_5SEC 5000
161 * Compatibility macros for busy handling
162 * of network devices.
164 static __inline__
void netiucv_clear_busy(net_device
*dev
)
166 clear_bit(0, &(((netiucv_priv
*)dev
->priv
)->tbusy
));
167 netif_wake_queue(dev
);
170 static __inline__
int netiucv_test_and_set_busy(net_device
*dev
)
172 netif_stop_queue(dev
);
173 return test_and_set_bit(0, &((netiucv_priv
*)dev
->priv
)->tbusy
);
176 #define SET_DEVICE_START(device, value)
178 static __u8 iucv_host
[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
179 static __u8 iucvMagic
[16] = {
180 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
181 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
185 * This mask means the 16-byte IUCV "magic" and the origin userid must
186 * match exactly as specified in order to give connection_pending()
189 static __u8 mask
[] = {
190 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
191 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
192 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
196 * Convert an iucv userId to its printable
197 * form (strip whitespace at end).
199 * @param An iucv userId
201 * @returns The printable string (static data!!)
203 static __inline__
char *
204 netiucv_printname(char *name
)
208 memcpy(tmp
, name
, 8);
210 while (*p
&& (!isspace(*p
)))
217 * States of the interface statemachine.
225 * MUST be always the last element!!
230 static const char *dev_state_names
[] = {
238 * Events of the interface statemachine.
246 * MUST be always the last element!!
251 static const char *dev_event_names
[] = {
259 * Events of the connection statemachine
263 * Events, representing callbacks from
264 * lowlevel iucv layer)
275 * Events, representing errors return codes from
276 * calls to lowlevel iucv layer
280 * Event, representing timer expiry.
285 * Events, representing commands from upper levels.
291 * MUST be always the last element!!
296 static const char *conn_event_names
[] = {
297 "Remote connection request",
298 "Remote connection acknowledge",
299 "Remote connection reject",
300 "Connection suspended",
301 "Connection resumed",
312 * States of the connection statemachine.
316 * Connection not assigned to any device,
317 * initial state, invalid
322 * Userid assigned but not operating
327 * Connection registered,
328 * no connection request sent yet,
329 * no connection request received
331 CONN_STATE_STARTWAIT
,
334 * Connection registered and connection request sent,
335 * no acknowledge and no connection request received yet.
337 CONN_STATE_SETUPWAIT
,
340 * Connection up and running idle
345 * Data sent, awaiting CONN_EVENT_TXDONE
355 * Error during registration.
360 * Error during registration.
365 * MUST be always the last element!!
370 static const char *conn_state_names
[] = {
378 "Registration error",
384 * Callback-wrappers, called from lowlevel iucv layer.
385 *****************************************************************************/
388 netiucv_callback_rx(iucv_MessagePending
*eib
, void *pgm_data
)
390 iucv_connection
*conn
= (iucv_connection
*)pgm_data
;
394 ev
.data
= (void *)eib
;
396 fsm_event(conn
->fsm
, CONN_EVENT_RX
, &ev
);
400 netiucv_callback_txdone(iucv_MessageComplete
*eib
, void *pgm_data
)
402 iucv_connection
*conn
= (iucv_connection
*)pgm_data
;
406 ev
.data
= (void *)eib
;
407 fsm_event(conn
->fsm
, CONN_EVENT_TXDONE
, &ev
);
411 netiucv_callback_connack(iucv_ConnectionComplete
*eib
, void *pgm_data
)
413 iucv_connection
*conn
= (iucv_connection
*)pgm_data
;
417 ev
.data
= (void *)eib
;
418 fsm_event(conn
->fsm
, CONN_EVENT_CONN_ACK
, &ev
);
422 netiucv_callback_connreq(iucv_ConnectionPending
*eib
, void *pgm_data
)
424 iucv_connection
*conn
= (iucv_connection
*)pgm_data
;
428 ev
.data
= (void *)eib
;
429 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REQ
, &ev
);
433 netiucv_callback_connrej(iucv_ConnectionSevered
*eib
, void *pgm_data
)
435 iucv_connection
*conn
= (iucv_connection
*)pgm_data
;
439 ev
.data
= (void *)eib
;
440 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REJ
, &ev
);
444 netiucv_callback_connsusp(iucv_ConnectionQuiesced
*eib
, void *pgm_data
)
446 iucv_connection
*conn
= (iucv_connection
*)pgm_data
;
450 ev
.data
= (void *)eib
;
451 fsm_event(conn
->fsm
, CONN_EVENT_CONN_SUS
, &ev
);
455 netiucv_callback_connres(iucv_ConnectionResumed
*eib
, void *pgm_data
)
457 iucv_connection
*conn
= (iucv_connection
*)pgm_data
;
461 ev
.data
= (void *)eib
;
462 fsm_event(conn
->fsm
, CONN_EVENT_CONN_RES
, &ev
);
465 static iucv_interrupt_ops_t netiucv_ops
= {
466 .ConnectionPending
= netiucv_callback_connreq
,
467 .ConnectionComplete
= netiucv_callback_connack
,
468 .ConnectionSevered
= netiucv_callback_connrej
,
469 .ConnectionQuiesced
= netiucv_callback_connsusp
,
470 .ConnectionResumed
= netiucv_callback_connres
,
471 .MessagePending
= netiucv_callback_rx
,
472 .MessageComplete
= netiucv_callback_txdone
476 * Dummy NOP action for all statemachines
479 fsm_action_nop(fsm_instance
*fi
, int event
, void *arg
)
484 * Actions of the connection statemachine
485 *****************************************************************************/
488 * Helper function for conn_action_rx()
489 * Unpack a just received skb and hand it over to
492 * @param conn The connection where this skb has been received.
493 * @param pskb The received skb.
495 //static __inline__ void
497 netiucv_unpack_skb(iucv_connection
*conn
, struct sk_buff
*pskb
)
499 net_device
*dev
= conn
->netdev
;
500 netiucv_priv
*privptr
= (netiucv_priv
*)dev
->priv
;
503 skb_put(pskb
, NETIUCV_HDRLEN
);
505 pskb
->ip_summed
= CHECKSUM_NONE
;
506 pskb
->protocol
= ntohs(ETH_P_IP
);
510 ll_header
*header
= (ll_header
*)pskb
->data
;
512 if (header
->next
== 0)
515 skb_pull(pskb
, NETIUCV_HDRLEN
);
516 header
->next
-= offset
;
517 offset
+= header
->next
;
518 header
->next
-= NETIUCV_HDRLEN
;
519 if (skb_tailroom(pskb
) < header
->next
) {
521 "%s: Illegal next field in iucv header: %d > %d\n",
522 dev
->name
, header
->next
, skb_tailroom(pskb
));
525 skb_put(pskb
, header
->next
);
526 pskb
->mac
.raw
= pskb
->data
;
527 skb
= dev_alloc_skb(pskb
->len
);
530 "%s Out of memory in netiucv_unpack_skb\n",
532 privptr
->stats
.rx_dropped
++;
535 memcpy(skb_put(skb
, pskb
->len
), pskb
->data
, pskb
->len
);
536 skb
->mac
.raw
= skb
->data
;
537 skb
->dev
= pskb
->dev
;
538 skb
->protocol
= pskb
->protocol
;
539 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
541 dev
->last_rx
= jiffies
;
542 privptr
->stats
.rx_packets
++;
543 privptr
->stats
.rx_bytes
+= skb
->len
;
544 skb_pull(pskb
, header
->next
);
545 skb_put(pskb
, NETIUCV_HDRLEN
);
550 conn_action_rx(fsm_instance
*fi
, int event
, void *arg
)
552 iucv_event
*ev
= (iucv_event
*)arg
;
553 iucv_connection
*conn
= ev
->conn
;
554 iucv_MessagePending
*eib
= (iucv_MessagePending
*)ev
->data
;
555 netiucv_priv
*privptr
= (netiucv_priv
*)conn
->netdev
->priv
;
557 __u16 msglen
= eib
->ln1msg2
.ipbfln1f
;
561 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
564 /* FRITZ: How to tell iucv LL to drop the msg? */
566 "Received data for unlinked connection\n");
569 if (msglen
> conn
->max_buffsize
) {
570 /* FRITZ: How to tell iucv LL to drop the msg? */
571 privptr
->stats
.rx_dropped
++;
574 conn
->rx_buff
->data
= conn
->rx_buff
->tail
= conn
->rx_buff
->head
;
575 conn
->rx_buff
->len
= 0;
576 rc
= iucv_receive(conn
->pathid
, eib
->ipmsgid
, eib
->iptrgcls
,
577 conn
->rx_buff
->data
, msglen
, NULL
, NULL
, NULL
);
578 if (rc
!= 0 || msglen
< 5) {
579 privptr
->stats
.rx_errors
++;
582 netiucv_unpack_skb(conn
, conn
->rx_buff
);
586 conn_action_txdone(fsm_instance
*fi
, int event
, void *arg
)
588 iucv_event
*ev
= (iucv_event
*)arg
;
589 iucv_connection
*conn
= ev
->conn
;
590 iucv_MessageComplete
*eib
= (iucv_MessageComplete
*)ev
->data
;
591 netiucv_priv
*privptr
= NULL
;
592 /* Shut up, gcc! skb is always below 2G. */
593 struct sk_buff
*skb
= (struct sk_buff
*)(unsigned long)eib
->ipmsgtag
;
596 __u32 stat_maxcq
= 0;
597 unsigned long saveflags
;
601 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
603 fsm_deltimer(&conn
->timer
);
604 if (conn
&& conn
->netdev
&& conn
->netdev
->priv
)
605 privptr
= (netiucv_priv
*)conn
->netdev
->priv
;
608 privptr
->stats
.tx_packets
++;
609 privptr
->stats
.tx_bytes
+=
610 (skb
->len
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
);
612 dev_kfree_skb_any(skb
);
614 conn
->tx_buff
->data
= conn
->tx_buff
->tail
= conn
->tx_buff
->head
;
615 conn
->tx_buff
->len
= 0;
616 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
617 while ((skb
= skb_dequeue(&conn
->collect_queue
))) {
618 header
.next
= conn
->tx_buff
->len
+ skb
->len
+ NETIUCV_HDRLEN
;
619 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
621 memcpy(skb_put(conn
->tx_buff
, skb
->len
), skb
->data
, skb
->len
);
625 atomic_dec(&skb
->users
);
626 dev_kfree_skb_any(skb
);
628 if (conn
->collect_len
> conn
->prof
.maxmulti
)
629 conn
->prof
.maxmulti
= conn
->collect_len
;
630 conn
->collect_len
= 0;
631 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
632 if (conn
->tx_buff
->len
) {
636 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
639 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
640 CONN_EVENT_TIMER
, conn
);
641 conn
->prof
.send_stamp
= xtime
;
642 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0, 0, 0,
643 conn
->tx_buff
->data
, conn
->tx_buff
->len
);
644 conn
->prof
.doios_multi
++;
645 conn
->prof
.txlen
+= conn
->tx_buff
->len
;
647 fsm_deltimer(&conn
->timer
);
648 fsm_newstate(fi
, CONN_STATE_IDLE
);
650 privptr
->stats
.tx_errors
+= txpackets
;
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 iucv_event
*ev
= (iucv_event
*)arg
;
667 iucv_connection
*conn
= ev
->conn
;
668 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
669 net_device
*netdev
= conn
->netdev
;
670 netiucv_priv
*privptr
= (netiucv_priv
*)netdev
->priv
;
676 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
678 rc
= iucv_accept(eib
->ippathid
, NETIUCV_QUEUELEN_DEFAULT
, udata
, 0,
679 conn
->handle
, conn
, NULL
, &msglimit
);
682 "%s: IUCV accept failed with error %d\n",
686 fsm_newstate(fi
, CONN_STATE_IDLE
);
687 conn
->pathid
= eib
->ippathid
;
688 netdev
->tx_queue_len
= msglimit
;
689 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
693 conn_action_connreject(fsm_instance
*fi
, int event
, void *arg
)
695 iucv_event
*ev
= (iucv_event
*)arg
;
696 // iucv_connection *conn = ev->conn;
697 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
701 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
703 iucv_sever(eib
->ippathid
, udata
);
707 conn_action_connack(fsm_instance
*fi
, int event
, void *arg
)
709 iucv_event
*ev
= (iucv_event
*)arg
;
710 iucv_connection
*conn
= ev
->conn
;
711 iucv_ConnectionComplete
*eib
= (iucv_ConnectionComplete
*)ev
->data
;
712 net_device
*netdev
= conn
->netdev
;
713 netiucv_priv
*privptr
= (netiucv_priv
*)netdev
->priv
;
716 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
718 fsm_newstate(fi
, CONN_STATE_IDLE
);
719 conn
->pathid
= eib
->ippathid
;
720 netdev
->tx_queue_len
= eib
->ipmsglim
;
721 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
725 conn_action_connsever(fsm_instance
*fi
, int event
, void *arg
)
727 iucv_event
*ev
= (iucv_event
*)arg
;
728 iucv_connection
*conn
= ev
->conn
;
729 // iucv_ConnectionSevered *eib = (iucv_ConnectionSevered *)ev->data;
730 net_device
*netdev
= conn
->netdev
;
731 netiucv_priv
*privptr
= (netiucv_priv
*)netdev
->priv
;
732 int state
= fsm_getstate(fi
);
735 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
738 case CONN_STATE_IDLE
:
740 printk(KERN_INFO
"%s: Remote dropped connection\n",
743 iucv_unregister_program(conn
->handle
);
745 fsm_newstate(fi
, CONN_STATE_STOPPED
);
746 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
752 conn_action_start(fsm_instance
*fi
, int event
, void *arg
)
754 iucv_event
*ev
= (iucv_event
*)arg
;
755 iucv_connection
*conn
= ev
->conn
;
760 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
762 if (conn
->handle
== 0) {
764 iucv_register_program(iucvMagic
, conn
->userid
, mask
,
766 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
767 if (conn
->handle
<= 0) {
768 fsm_newstate(fi
, CONN_STATE_REGERR
);
773 printk(KERN_DEBUG
"%s('%s'): registered successfully\n",
774 conn
->netdev
->name
, conn
->userid
);
778 printk(KERN_DEBUG
"%s('%s'): connecting ...\n",
779 conn
->netdev
->name
, conn
->userid
);
781 rc
= iucv_connect(&(conn
->pathid
), NETIUCV_QUEUELEN_DEFAULT
, iucvMagic
,
782 conn
->userid
, iucv_host
, 0, NULL
, NULL
, conn
->handle
,
784 fsm_newstate(fi
, CONN_STATE_SETUPWAIT
);
790 "%s: User %s is currently not available.\n",
792 netiucv_printname(conn
->userid
));
793 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
797 "%s: User %s is currently not ready.\n",
799 netiucv_printname(conn
->userid
));
800 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
804 "%s: Too many IUCV connections.\n",
806 fsm_newstate(fi
, CONN_STATE_CONNERR
);
810 "%s: User %s has too many IUCV connections.\n",
812 netiucv_printname(conn
->userid
));
813 fsm_newstate(fi
, CONN_STATE_CONNERR
);
817 "%s: No IUCV authorization in CP directory.\n",
819 fsm_newstate(fi
, CONN_STATE_CONNERR
);
823 "%s: iucv_connect returned error %d\n",
824 conn
->netdev
->name
, rc
);
825 fsm_newstate(fi
, CONN_STATE_CONNERR
);
828 iucv_unregister_program(conn
->handle
);
833 netiucv_purge_skb_queue(struct sk_buff_head
*q
)
837 while ((skb
= skb_dequeue(q
))) {
838 atomic_dec(&skb
->users
);
839 dev_kfree_skb_any(skb
);
844 conn_action_stop(fsm_instance
*fi
, int event
, void *arg
)
846 iucv_event
*ev
= (iucv_event
*)arg
;
847 iucv_connection
*conn
= ev
->conn
;
848 net_device
*netdev
= conn
->netdev
;
849 netiucv_priv
*privptr
= (netiucv_priv
*)netdev
->priv
;
852 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
854 fsm_newstate(fi
, CONN_STATE_STOPPED
);
855 netiucv_purge_skb_queue(&conn
->collect_queue
);
857 iucv_unregister_program(conn
->handle
);
859 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
863 conn_action_inval(fsm_instance
*fi
, int event
, void *arg
)
865 iucv_event
*ev
= (iucv_event
*)arg
;
866 iucv_connection
*conn
= ev
->conn
;
867 net_device
*netdev
= conn
->netdev
;
870 "%s: Cannot connect without username\n",
874 static const fsm_node conn_fsm
[] = {
875 { CONN_STATE_INVALID
, CONN_EVENT_START
, conn_action_inval
},
876 { CONN_STATE_STOPPED
, CONN_EVENT_START
, conn_action_start
},
877 { CONN_STATE_STARTWAIT
, CONN_EVENT_START
, conn_action_start
},
879 { CONN_STATE_STARTWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
880 { CONN_STATE_SETUPWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
881 { CONN_STATE_IDLE
, CONN_EVENT_STOP
, conn_action_stop
},
882 { CONN_STATE_TX
, CONN_EVENT_STOP
, conn_action_stop
},
883 { CONN_STATE_REGERR
, CONN_EVENT_STOP
, conn_action_stop
},
884 { CONN_STATE_CONNERR
, CONN_EVENT_STOP
, conn_action_stop
},
886 { CONN_STATE_STOPPED
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
887 { CONN_STATE_STARTWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
888 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
889 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
890 { CONN_STATE_TX
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
892 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_ACK
, conn_action_connack
},
894 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
895 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
896 { CONN_STATE_TX
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
898 { CONN_STATE_IDLE
, CONN_EVENT_RX
, conn_action_rx
},
899 { CONN_STATE_TX
, CONN_EVENT_RX
, conn_action_rx
},
901 { CONN_STATE_TX
, CONN_EVENT_TXDONE
, conn_action_txdone
},
904 static const int CONN_FSM_LEN
= sizeof(conn_fsm
) / sizeof(fsm_node
);
908 * Actions for interface - statemachine.
909 *****************************************************************************/
912 * Startup connection by sending CONN_EVENT_START to it.
914 * @param fi An instance of an interface statemachine.
915 * @param event The event, just happened.
916 * @param arg Generic pointer, casted from net_device * upon call.
919 dev_action_start(fsm_instance
*fi
, int event
, void *arg
)
921 net_device
*dev
= (net_device
*)arg
;
922 netiucv_priv
*privptr
= dev
->priv
;
926 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
928 ev
.conn
= privptr
->conn
;
929 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
930 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, &ev
);
934 * Shutdown connection by sending CONN_EVENT_STOP 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 net_device * upon call.
941 dev_action_stop(fsm_instance
*fi
, int event
, void *arg
)
943 net_device
*dev
= (net_device
*)arg
;
944 netiucv_priv
*privptr
= dev
->priv
;
948 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
950 ev
.conn
= privptr
->conn
;
952 fsm_newstate(fi
, DEV_STATE_STOPWAIT
);
953 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_STOP
, &ev
);
957 * Called from connection statemachine
958 * when a connection is up and running.
960 * @param fi An instance of an interface statemachine.
961 * @param event The event, just happened.
962 * @param arg Generic pointer, casted from net_device * upon call.
965 dev_action_connup(fsm_instance
*fi
, int event
, void *arg
)
967 net_device
*dev
= (net_device
*)arg
;
970 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
972 switch (fsm_getstate(fi
)) {
973 case DEV_STATE_STARTWAIT
:
974 fsm_newstate(fi
, DEV_STATE_RUNNING
);
976 "%s: connected with remote side\n",
979 case DEV_STATE_STOPWAIT
:
981 "%s: got connection UP event during shutdown!!\n",
988 * Called from connection statemachine
989 * when a connection has been shutdown.
991 * @param fi An instance of an interface statemachine.
992 * @param event The event, just happened.
993 * @param arg Generic pointer, casted from net_device * upon call.
996 dev_action_conndown(fsm_instance
*fi
, int event
, void *arg
)
998 net_device
*dev
= (net_device
*)arg
;
999 netiucv_priv
*privptr
= dev
->priv
;
1003 printk(KERN_DEBUG
"%s() called\n", __FUNCTION__
);
1005 switch (fsm_getstate(fi
)) {
1006 case DEV_STATE_RUNNING
:
1007 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1008 ev
.conn
= privptr
->conn
;
1009 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, &ev
);
1011 case DEV_STATE_STARTWAIT
:
1013 case DEV_STATE_STOPWAIT
:
1014 fsm_newstate(fi
, DEV_STATE_STOPPED
);
1019 static const fsm_node dev_fsm
[] = {
1020 { DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
1022 { DEV_STATE_STOPWAIT
, DEV_EVENT_START
, dev_action_start
},
1023 { DEV_STATE_STOPWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1025 { DEV_STATE_STARTWAIT
, DEV_EVENT_STOP
, dev_action_stop
},
1026 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONUP
, dev_action_connup
},
1027 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1029 { DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
1030 { DEV_STATE_RUNNING
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1031 { DEV_STATE_RUNNING
, DEV_EVENT_CONUP
, fsm_action_nop
},
1034 static const int DEV_FSM_LEN
= sizeof(dev_fsm
) / sizeof(fsm_node
);
1037 * Transmit a packet.
1038 * This is a helper function for netiucv_tx().
1040 * @param conn Connection to be used for sending.
1041 * @param skb Pointer to struct sk_buff of packet to send.
1042 * The linklevel header has already been set up
1045 * @return 0 on success, -ERRNO on failure. (Never fails.)
1048 netiucv_transmit_skb(iucv_connection
*conn
, struct sk_buff
*skb
) {
1049 unsigned long saveflags
;
1053 if (fsm_getstate(conn
->fsm
) != CONN_STATE_IDLE
) {
1054 int l
= skb
->len
+ NETIUCV_HDRLEN
;
1056 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
1057 if (conn
->collect_len
+ l
>
1058 (conn
->max_buffsize
- NETIUCV_HDRLEN
))
1061 atomic_inc(&skb
->users
);
1062 skb_queue_tail(&conn
->collect_queue
, skb
);
1063 conn
->collect_len
+= l
;
1065 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
1067 struct sk_buff
*nskb
= skb
;
1069 * Copy the skb to a new allocated skb in lowmem only if the
1070 * data is located above 2G in memory or tailroom is < 2.
1073 ((unsigned long)(skb
->tail
+ NETIUCV_HDRLEN
)) >> 31;
1075 if (hi
|| (skb_tailroom(skb
) < 2)) {
1076 nskb
= alloc_skb(skb
->len
+ NETIUCV_HDRLEN
+
1077 NETIUCV_HDRLEN
, GFP_ATOMIC
| GFP_DMA
);
1080 "%s: Could not allocate tx_skb\n",
1081 conn
->netdev
->name
);
1084 skb_reserve(nskb
, NETIUCV_HDRLEN
);
1085 memcpy(skb_put(nskb
, skb
->len
),
1086 skb
->data
, skb
->len
);
1091 * skb now is below 2G and has enough room. Add headers.
1093 header
.next
= nskb
->len
+ NETIUCV_HDRLEN
;
1094 memcpy(skb_push(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1096 memcpy(skb_put(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1099 fsm_newstate(conn
->fsm
, CONN_STATE_TX
);
1100 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
1101 CONN_EVENT_TIMER
, conn
);
1102 conn
->prof
.send_stamp
= xtime
;
1104 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0,
1105 /* Shut up, gcc! nskb is always below 2G. */
1106 (__u32
)(((unsigned long)nskb
)&0xffffffff), 0,
1107 nskb
->data
, nskb
->len
);
1108 conn
->prof
.doios_single
++;
1109 conn
->prof
.txlen
+= skb
->len
;
1111 fsm_deltimer(&conn
->timer
);
1113 dev_kfree_skb(nskb
);
1116 * Remove our headers. They get added
1117 * again on retransmit.
1119 skb_pull(skb
, NETIUCV_HDRLEN
);
1120 skb_trim(skb
, skb
->len
- NETIUCV_HDRLEN
);
1132 * Interface API for upper network layers
1133 *****************************************************************************/
1136 * Open an interface.
1137 * Called from generic network layer when ifconfig up is run.
1139 * @param dev Pointer to interface struct.
1141 * @return 0 on success, -ERRNO on failure. (Never fails.)
1144 netiucv_open(net_device
*dev
) {
1146 SET_DEVICE_START(dev
, 1);
1147 fsm_event(((netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_START
, dev
);
1152 * Close an interface.
1153 * Called from generic network layer when ifconfig down is run.
1155 * @param dev Pointer to interface struct.
1157 * @return 0 on success, -ERRNO on failure. (Never fails.)
1160 netiucv_close(net_device
*dev
) {
1161 SET_DEVICE_START(dev
, 0);
1162 fsm_event(((netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_STOP
, dev
);
1168 * Start transmission of a packet.
1169 * Called from generic network device layer.
1171 * @param skb Pointer to buffer containing the packet.
1172 * @param dev Pointer to interface struct.
1174 * @return 0 if packet consumed, !0 if packet rejected.
1175 * Note: If we return !0, then the packet is free'd by
1176 * the generic network layer.
1178 static int netiucv_tx(struct sk_buff
*skb
, net_device
*dev
)
1181 netiucv_priv
*privptr
= (netiucv_priv
*)dev
->priv
;
1184 * Some sanity checks ...
1187 printk(KERN_WARNING
"%s: NULL sk_buff passed\n", dev
->name
);
1188 privptr
->stats
.tx_dropped
++;
1191 if (skb_headroom(skb
) < (NETIUCV_HDRLEN
)) {
1193 "%s: Got sk_buff with head room < %ld bytes\n",
1194 dev
->name
, NETIUCV_HDRLEN
);
1196 privptr
->stats
.tx_dropped
++;
1201 * If connection is not running, try to restart it
1202 * notify anybody about a link failure and throw
1205 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
1206 fsm_event(privptr
->fsm
, DEV_EVENT_START
, dev
);
1207 dst_link_failure(skb
);
1209 privptr
->stats
.tx_dropped
++;
1210 privptr
->stats
.tx_errors
++;
1211 privptr
->stats
.tx_carrier_errors
++;
1215 if (netiucv_test_and_set_busy(dev
))
1218 dev
->trans_start
= jiffies
;
1219 if (netiucv_transmit_skb(privptr
->conn
, skb
) != 0)
1221 netiucv_clear_busy(dev
);
1226 * Returns interface statistics of a device.
1228 * @param dev Pointer to interface struct.
1230 * @return Pointer to stats struct of this interface.
1232 static struct net_device_stats
*
1233 netiucv_stats (net_device
* dev
)
1235 return &((netiucv_priv
*)dev
->priv
)->stats
;
1239 * Sets MTU of an interface.
1241 * @param dev Pointer to interface struct.
1242 * @param new_mtu The new MTU to use for this interface.
1244 * @return 0 on success, -EINVAL if MTU is out of valid range.
1245 * (valid range is 576 .. NETIUCV_MTU_MAX).
1248 netiucv_change_mtu (net_device
* dev
, int new_mtu
)
1250 if ((new_mtu
< 576) || (new_mtu
> NETIUCV_MTU_MAX
))
1257 * attributes in sysfs
1258 *****************************************************************************/
1259 #define CTRL_BUFSIZE 40
1262 user_show (struct device
*dev
, char *buf
)
1264 netiucv_priv
*priv
= dev
->driver_data
;
1266 return snprintf(buf
, PAGE_SIZE
, "%s\n",
1267 netiucv_printname(priv
->conn
->userid
));
1271 user_write (struct device
*dev
, const char *buf
, size_t count
)
1273 netiucv_priv
*priv
= dev
->driver_data
;
1274 struct net_device
*ndev
= container_of((void *)priv
, struct net_device
, priv
);
1277 char tmp
[CTRL_BUFSIZE
];
1283 if (copy_from_user(tmp
, buf
, count
))
1285 tmp
[count
+1] = '\0';
1287 memset(user
, ' ', sizeof(user
));
1289 for (p
= tmp
, i
= 0; *p
&& (!isspace(*p
)); p
++) {
1295 if (memcmp(user
, priv
->conn
->userid
, 8) != 0) {
1296 /* username changed */
1297 if (ndev
->flags
& IFF_RUNNING
)
1300 memcpy(priv
->conn
->userid
, user
, 9);
1305 static DEVICE_ATTR(user
, 0644, user_show
, user_write
);
1308 buffer_show (struct device
*dev
, char *buf
)
1310 netiucv_priv
*priv
= dev
->driver_data
;
1312 return sprintf(buf
, "%d\n",
1313 priv
->conn
->max_buffsize
);
1317 buffer_write (struct device
*dev
, const char *buf
, size_t count
)
1319 netiucv_priv
*priv
= dev
->driver_data
;
1320 struct net_device
*ndev
= container_of((void *)priv
, struct net_device
, priv
);
1323 char tmp
[CTRL_BUFSIZE
];
1328 if (copy_from_user(tmp
, buf
, count
))
1330 tmp
[count
+1] = '\0';
1331 bs1
= simple_strtoul(tmp
, &e
, 0);
1333 if ((bs1
> NETIUCV_BUFSIZE_MAX
) ||
1334 (e
&& (!isspace(*e
))))
1336 if ((ndev
->flags
& IFF_RUNNING
) &&
1337 (bs1
< (ndev
->mtu
+ NETIUCV_HDRLEN
+ 2)))
1339 if (bs1
< (576 + NETIUCV_HDRLEN
+ NETIUCV_HDRLEN
))
1343 priv
->conn
->max_buffsize
= bs1
;
1344 if (!(ndev
->flags
& IFF_RUNNING
))
1345 ndev
->mtu
= bs1
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
;
1346 priv
->conn
->flags
|= CONN_FLAGS_BUFSIZE_CHANGED
;
1352 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
1355 dev_fsm_show (struct device
*dev
, char *buf
)
1357 netiucv_priv
*priv
= dev
->driver_data
;
1359 return snprintf(buf
, PAGE_SIZE
, "%s\n",
1360 fsm_getstate_str(priv
->fsm
));
1363 static DEVICE_ATTR(device_fsm_state
, 0444, dev_fsm_show
, NULL
);
1366 conn_fsm_show (struct device
*dev
, char *buf
)
1368 netiucv_priv
*priv
= dev
->driver_data
;
1370 return snprintf(buf
, PAGE_SIZE
, "%s\n",
1371 fsm_getstate_str(priv
->conn
->fsm
));
1374 static DEVICE_ATTR(connection_fsm_state
, 0444, conn_fsm_show
, NULL
);
1377 maxmulti_show (struct device
*dev
, char *buf
)
1379 netiucv_priv
*priv
= dev
->driver_data
;
1381 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxmulti
);
1385 maxmulti_write (struct device
*dev
, const char *buf
, size_t count
)
1387 netiucv_priv
*priv
= dev
->driver_data
;
1389 priv
->conn
->prof
.maxmulti
= 0;
1393 static DEVICE_ATTR(max_tx_buffer_used
, 0644, maxmulti_show
, maxmulti_write
);
1396 maxcq_show (struct device
*dev
, char *buf
)
1398 netiucv_priv
*priv
= dev
->driver_data
;
1400 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxcqueue
);
1404 maxcq_write (struct device
*dev
, const char *buf
, size_t count
)
1406 netiucv_priv
*priv
= dev
->driver_data
;
1408 priv
->conn
->prof
.maxcqueue
= 0;
1412 static DEVICE_ATTR(max_chained_skbs
, 0644, maxcq_show
, maxcq_write
);
1415 sdoio_show (struct device
*dev
, char *buf
)
1417 netiucv_priv
*priv
= dev
->driver_data
;
1419 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_single
);
1423 sdoio_write (struct device
*dev
, const char *buf
, size_t count
)
1425 netiucv_priv
*priv
= dev
->driver_data
;
1427 priv
->conn
->prof
.doios_single
= 0;
1431 static DEVICE_ATTR(tx_single_write_ops
, 0644, sdoio_show
, sdoio_write
);
1434 mdoio_show (struct device
*dev
, char *buf
)
1436 netiucv_priv
*priv
= dev
->driver_data
;
1438 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_multi
);
1442 mdoio_write (struct device
*dev
, const char *buf
, size_t count
)
1444 netiucv_priv
*priv
= dev
->driver_data
;
1446 priv
->conn
->prof
.doios_multi
= 0;
1450 static DEVICE_ATTR(tx_multi_write_ops
, 0644, mdoio_show
, mdoio_write
);
1453 txlen_show (struct device
*dev
, char *buf
)
1455 netiucv_priv
*priv
= dev
->driver_data
;
1457 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.txlen
);
1461 txlen_write (struct device
*dev
, const char *buf
, size_t count
)
1463 netiucv_priv
*priv
= dev
->driver_data
;
1465 priv
->conn
->prof
.txlen
= 0;
1469 static DEVICE_ATTR(netto_bytes
, 0644, txlen_show
, txlen_write
);
1472 txtime_show (struct device
*dev
, char *buf
)
1474 netiucv_priv
*priv
= dev
->driver_data
;
1476 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_time
);
1480 txtime_write (struct device
*dev
, const char *buf
, size_t count
)
1482 netiucv_priv
*priv
= dev
->driver_data
;
1484 priv
->conn
->prof
.tx_time
= 0;
1488 static DEVICE_ATTR(max_tx_io_time
, 0644, txtime_show
, txtime_write
);
1491 netiucv_add_files(struct device
*dev
)
1495 if ((ret
= device_create_file(dev
, &dev_attr_user
)) ||
1496 (ret
= device_create_file(dev
, &dev_attr_buffer
)) ||
1497 (ret
= device_create_file(dev
, &dev_attr_device_fsm_state
)) ||
1498 (ret
= device_create_file(dev
, &dev_attr_connection_fsm_state
)) ||
1499 (ret
= device_create_file(dev
, &dev_attr_max_tx_buffer_used
)) ||
1500 (ret
= device_create_file(dev
, &dev_attr_max_chained_skbs
)) ||
1501 (ret
= device_create_file(dev
, &dev_attr_tx_single_write_ops
)) ||
1502 (ret
= device_create_file(dev
, &dev_attr_tx_multi_write_ops
)) ||
1503 (ret
= device_create_file(dev
, &dev_attr_netto_bytes
)) ||
1504 (ret
= device_create_file(dev
, &dev_attr_max_tx_io_time
))) {
1505 device_remove_file(dev
, &dev_attr_netto_bytes
);
1506 device_remove_file(dev
, &dev_attr_tx_multi_write_ops
);
1507 device_remove_file(dev
, &dev_attr_tx_single_write_ops
);
1508 device_remove_file(dev
, &dev_attr_max_chained_skbs
);
1509 device_remove_file(dev
, &dev_attr_max_tx_buffer_used
);
1510 device_remove_file(dev
, &dev_attr_connection_fsm_state
);
1511 device_remove_file(dev
, &dev_attr_device_fsm_state
);
1512 device_remove_file(dev
, &dev_attr_buffer
);
1513 device_remove_file(dev
, &dev_attr_user
);
1519 netiucv_register_device(struct net_device
*ndev
, int ifno
)
1521 netiucv_priv
*priv
= ndev
->priv
;
1522 struct platform_device
*pldev
= &priv
->pldev
;
1524 char *str
= "netiucv";
1526 snprintf(pldev
->dev
.name
, DEVICE_NAME_SIZE
,
1531 ret
= platform_device_register(pldev
);
1536 ret
= netiucv_add_files(&pldev
->dev
);
1539 platform_device_unregister(pldev
);
1541 pldev
->dev
.driver_data
= priv
;
1547 netiucv_unregister_device(struct net_device
*ndev
)
1549 netiucv_priv
*priv
= (netiucv_priv
*)ndev
->priv
;
1550 struct platform_device
*pldev
= &priv
->pldev
;
1552 platform_device_unregister(pldev
);
1557 * Allocate and initialize a new connection structure.
1558 * Add it to the list of connections;
1560 static iucv_connection
*
1561 netiucv_new_connection(net_device
*dev
, char *username
)
1563 iucv_connection
**clist
= &connections
;
1564 iucv_connection
*conn
=
1565 (iucv_connection
*)kmalloc(sizeof(iucv_connection
), GFP_KERNEL
);
1567 memset(conn
, 0, sizeof(iucv_connection
));
1568 skb_queue_head_init(&conn
->collect_queue
);
1569 conn
->max_buffsize
= NETIUCV_BUFSIZE_DEFAULT
;
1572 conn
->rx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
, GFP_DMA
);
1573 if (!conn
->rx_buff
) {
1577 conn
->tx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
, GFP_DMA
);
1578 if (!conn
->tx_buff
) {
1579 kfree_skb(conn
->rx_buff
);
1583 conn
->fsm
= init_fsm("netiucvconn", conn_state_names
,
1584 conn_event_names
, NR_CONN_STATES
,
1585 NR_CONN_EVENTS
, conn_fsm
, CONN_FSM_LEN
,
1588 kfree_skb(conn
->tx_buff
);
1589 kfree_skb(conn
->rx_buff
);
1593 fsm_settimer(conn
->fsm
, &conn
->timer
);
1594 fsm_newstate(conn
->fsm
, CONN_STATE_INVALID
);
1597 memcpy(conn
->userid
, username
, 9);
1598 fsm_newstate(conn
->fsm
, CONN_STATE_STOPPED
);
1601 conn
->next
= *clist
;
1608 * Release a connection structure and remove it from the
1609 * list of connections.
1612 netiucv_remove_connection(iucv_connection
*conn
)
1614 iucv_connection
**clist
= &connections
;
1619 if (*clist
== conn
) {
1620 *clist
= conn
->next
;
1621 if (conn
->handle
!= 0) {
1622 iucv_unregister_program(conn
->handle
);
1625 fsm_deltimer(&conn
->timer
);
1626 kfree_fsm(conn
->fsm
);
1627 kfree_skb(conn
->rx_buff
);
1628 kfree_skb(conn
->tx_buff
);
1631 clist
= &((*clist
)->next
);
1636 * Allocate and initialize everything of a net device.
1639 netiucv_init_netdevice(int ifno
, char *username
)
1641 netiucv_priv
*privptr
;
1644 net_device
*dev
= kmalloc(sizeof(net_device
), GFP_KERNEL
);
1647 memset(dev
, 0, sizeof(net_device
));
1648 sprintf(dev
->name
, "iucv%d", ifno
);
1650 priv_size
= sizeof(netiucv_priv
);
1651 dev
->priv
= kmalloc(priv_size
, GFP_KERNEL
);
1652 if (dev
->priv
== NULL
) {
1656 memset(dev
->priv
, 0, priv_size
);
1657 privptr
= (netiucv_priv
*)dev
->priv
;
1658 privptr
->fsm
= init_fsm("netiucvdev", dev_state_names
,
1659 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
1660 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
1661 if (privptr
->fsm
== NULL
) {
1666 privptr
->conn
= netiucv_new_connection(dev
, username
);
1667 if (!privptr
->conn
) {
1668 kfree_fsm(privptr
->fsm
);
1674 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
1675 dev
->mtu
= NETIUCV_MTU_DEFAULT
;
1676 dev
->hard_start_xmit
= netiucv_tx
;
1677 dev
->open
= netiucv_open
;
1678 dev
->stop
= netiucv_close
;
1679 dev
->get_stats
= netiucv_stats
;
1680 dev
->change_mtu
= netiucv_change_mtu
;
1681 dev
->hard_header_len
= NETIUCV_HDRLEN
;
1683 dev
->type
= ARPHRD_SLIP
;
1684 dev
->tx_queue_len
= NETIUCV_QUEUELEN_DEFAULT
;
1685 dev_init_buffers(dev
);
1686 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
1691 * Allocate and initialize everything of a net device.
1694 netiucv_free_netdevice(net_device
*dev
)
1696 netiucv_priv
*privptr
;
1701 privptr
= (netiucv_priv
*)dev
->priv
;
1704 netiucv_remove_connection(privptr
->conn
);
1706 kfree_fsm(privptr
->fsm
);
1713 netiucv_banner(void)
1715 char vbuf
[] = "$Revision: 1.12 $";
1716 char *version
= vbuf
;
1718 if ((version
= strchr(version
, ':'))) {
1719 char *p
= strchr(version
+ 1, '$');
1724 printk(KERN_INFO
"NETIUCV driver Version%s initialized\n", version
);
1729 iucv_setup(char *param
)
1732 * We do not parse parameters here because at the time of
1733 * calling iucv_setup(), the kernel does not yet have
1734 * memory management running. We delay this until probing
1741 __setup ("iucv=", iucv_setup
);
1748 while (connections
) {
1749 net_device
*dev
= connections
->netdev
;
1750 unregister_netdev(dev
);
1751 netiucv_unregister_device(dev
);
1752 netiucv_free_netdevice(dev
);
1755 printk(KERN_INFO
"NETIUCV driver unloaded\n");
1759 module_exit(netiucv_exit
);
1772 username
[i
++] = *p
++;
1776 "netiucv: Invalid user name '%s'\n",
1778 while (*p
&& (*p
!= ':') && (*p
!= ','))
1782 if (*p
&& (*p
!= ':') && (*p
!= ',')) {
1784 "netiucv: Invalid delimiter '%c'\n",
1786 while (*p
&& (*p
!= ':') && (*p
!= ','))
1793 username
[i
++] = ' ';
1795 dev
= netiucv_init_netdevice(ifno
,
1799 "netiucv: Could not allocate network device structure for user '%s'\n", netiucv_printname(username
));
1801 if (register_netdev(dev
)) {
1803 "netiucv: Could not register '%s'\n", dev
->name
);
1804 netiucv_free_netdevice(dev
);
1806 printk(KERN_INFO
"%s: '%s'\n", dev
->name
, netiucv_printname(username
));
1807 netiucv_register_device(dev
, ifno
);
1823 module_init(netiucv_init
);
1824 MODULE_LICENSE("GPL");