2 * $Id: netiucv.c,v 1.20 2003/05/27 11:34:24 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.20 $
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>
69 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
70 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
74 * Per connection profiling data
76 struct connection_profile
{
77 unsigned long maxmulti
;
78 unsigned long maxcqueue
;
79 unsigned long doios_single
;
80 unsigned long doios_multi
;
82 unsigned long tx_time
;
83 struct timespec send_stamp
;
87 * Representation of one iucv connection
89 struct iucv_connection
{
90 struct iucv_connection
*next
;
93 struct sk_buff
*rx_buff
;
94 struct sk_buff
*tx_buff
;
95 struct sk_buff_head collect_queue
;
96 spinlock_t collect_lock
;
103 struct net_device
*netdev
;
104 struct connection_profile prof
;
108 #define CONN_FLAGS_BUFSIZE_CHANGED 1
111 * Linked list of all connection structs.
113 static struct iucv_connection
*connections
;
115 /* Keep track of interfaces. */
119 iucv_bus_match (struct device
*dev
, struct device_driver
*drv
)
124 /* Hm - move to iucv.c and export? - CH */
125 static struct bus_type iucv_bus
= {
127 .match
= iucv_bus_match
,
130 static struct device iucv_root
= {
136 * Representation of event-data for the
137 * connection state machine.
140 struct iucv_connection
*conn
;
145 * Private part of the network device structure
147 struct netiucv_priv
{
148 struct net_device_stats stats
;
151 struct iucv_connection
*conn
;
156 * Link level header for a packet.
158 typedef struct ll_header_t
{
162 #define NETIUCV_HDRLEN (sizeof(ll_header))
163 #define NETIUCV_BUFSIZE_MAX 32768
164 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
165 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
166 #define NETIUCV_MTU_DEFAULT 9216
167 #define NETIUCV_QUEUELEN_DEFAULT 50
168 #define NETIUCV_TIMEOUT_5SEC 5000
171 * Compatibility macros for busy handling
172 * of network devices.
174 static __inline__
void netiucv_clear_busy(struct net_device
*dev
)
176 clear_bit(0, &(((struct netiucv_priv
*)dev
->priv
)->tbusy
));
177 netif_wake_queue(dev
);
180 static __inline__
int netiucv_test_and_set_busy(struct net_device
*dev
)
182 netif_stop_queue(dev
);
183 return test_and_set_bit(0, &((struct netiucv_priv
*)dev
->priv
)->tbusy
);
186 #define SET_DEVICE_START(device, value)
188 static __u8 iucv_host
[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
189 static __u8 iucvMagic
[16] = {
190 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
191 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
195 * This mask means the 16-byte IUCV "magic" and the origin userid must
196 * match exactly as specified in order to give connection_pending()
199 static __u8 mask
[] = {
200 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
201 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
202 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
206 * Convert an iucv userId to its printable
207 * form (strip whitespace at end).
209 * @param An iucv userId
211 * @returns The printable string (static data!!)
213 static __inline__
char *
214 netiucv_printname(char *name
)
218 memcpy(tmp
, name
, 8);
220 while (*p
&& (!isspace(*p
)))
227 * States of the interface statemachine.
235 * MUST be always the last element!!
240 static const char *dev_state_names
[] = {
248 * Events of the interface statemachine.
256 * MUST be always the last element!!
261 static const char *dev_event_names
[] = {
269 * Events of the connection statemachine
273 * Events, representing callbacks from
274 * lowlevel iucv layer)
285 * Events, representing errors return codes from
286 * calls to lowlevel iucv layer
290 * Event, representing timer expiry.
295 * Events, representing commands from upper levels.
301 * MUST be always the last element!!
306 static const char *conn_event_names
[] = {
307 "Remote connection request",
308 "Remote connection acknowledge",
309 "Remote connection reject",
310 "Connection suspended",
311 "Connection resumed",
322 * States of the connection statemachine.
326 * Connection not assigned to any device,
327 * initial state, invalid
332 * Userid assigned but not operating
337 * Connection registered,
338 * no connection request sent yet,
339 * no connection request received
341 CONN_STATE_STARTWAIT
,
344 * Connection registered and connection request sent,
345 * no acknowledge and no connection request received yet.
347 CONN_STATE_SETUPWAIT
,
350 * Connection up and running idle
355 * Data sent, awaiting CONN_EVENT_TXDONE
365 * Error during registration.
370 * Error during registration.
375 * MUST be always the last element!!
380 static const char *conn_state_names
[] = {
388 "Registration error",
394 * Callback-wrappers, called from lowlevel iucv layer.
395 *****************************************************************************/
398 netiucv_callback_rx(iucv_MessagePending
*eib
, void *pgm_data
)
400 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
401 struct iucv_event ev
;
404 ev
.data
= (void *)eib
;
406 fsm_event(conn
->fsm
, CONN_EVENT_RX
, &ev
);
410 netiucv_callback_txdone(iucv_MessageComplete
*eib
, void *pgm_data
)
412 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
413 struct iucv_event ev
;
416 ev
.data
= (void *)eib
;
417 fsm_event(conn
->fsm
, CONN_EVENT_TXDONE
, &ev
);
421 netiucv_callback_connack(iucv_ConnectionComplete
*eib
, void *pgm_data
)
423 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
424 struct iucv_event ev
;
427 ev
.data
= (void *)eib
;
428 fsm_event(conn
->fsm
, CONN_EVENT_CONN_ACK
, &ev
);
432 netiucv_callback_connreq(iucv_ConnectionPending
*eib
, void *pgm_data
)
434 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
435 struct iucv_event ev
;
438 ev
.data
= (void *)eib
;
439 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REQ
, &ev
);
443 netiucv_callback_connrej(iucv_ConnectionSevered
*eib
, void *pgm_data
)
445 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
446 struct iucv_event ev
;
449 ev
.data
= (void *)eib
;
450 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REJ
, &ev
);
454 netiucv_callback_connsusp(iucv_ConnectionQuiesced
*eib
, void *pgm_data
)
456 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
457 struct iucv_event ev
;
460 ev
.data
= (void *)eib
;
461 fsm_event(conn
->fsm
, CONN_EVENT_CONN_SUS
, &ev
);
465 netiucv_callback_connres(iucv_ConnectionResumed
*eib
, void *pgm_data
)
467 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
468 struct iucv_event ev
;
471 ev
.data
= (void *)eib
;
472 fsm_event(conn
->fsm
, CONN_EVENT_CONN_RES
, &ev
);
475 static iucv_interrupt_ops_t netiucv_ops
= {
476 .ConnectionPending
= netiucv_callback_connreq
,
477 .ConnectionComplete
= netiucv_callback_connack
,
478 .ConnectionSevered
= netiucv_callback_connrej
,
479 .ConnectionQuiesced
= netiucv_callback_connsusp
,
480 .ConnectionResumed
= netiucv_callback_connres
,
481 .MessagePending
= netiucv_callback_rx
,
482 .MessageComplete
= netiucv_callback_txdone
486 * Dummy NOP action for all statemachines
489 fsm_action_nop(fsm_instance
*fi
, int event
, void *arg
)
494 * Actions of the connection statemachine
495 *****************************************************************************/
498 * Helper function for conn_action_rx()
499 * Unpack a just received skb and hand it over to
502 * @param conn The connection where this skb has been received.
503 * @param pskb The received skb.
505 //static __inline__ void
507 netiucv_unpack_skb(struct iucv_connection
*conn
, struct sk_buff
*pskb
)
509 struct net_device
*dev
= conn
->netdev
;
510 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)dev
->priv
;
513 skb_put(pskb
, NETIUCV_HDRLEN
);
515 pskb
->ip_summed
= CHECKSUM_NONE
;
516 pskb
->protocol
= ntohs(ETH_P_IP
);
520 ll_header
*header
= (ll_header
*)pskb
->data
;
522 if (header
->next
== 0)
525 skb_pull(pskb
, NETIUCV_HDRLEN
);
526 header
->next
-= offset
;
527 offset
+= header
->next
;
528 header
->next
-= NETIUCV_HDRLEN
;
529 if (skb_tailroom(pskb
) < header
->next
) {
531 "%s: Illegal next field in iucv header: "
533 dev
->name
, header
->next
, skb_tailroom(pskb
));
536 skb_put(pskb
, header
->next
);
537 pskb
->mac
.raw
= pskb
->data
;
538 skb
= dev_alloc_skb(pskb
->len
);
541 "%s Out of memory in netiucv_unpack_skb\n",
543 privptr
->stats
.rx_dropped
++;
546 memcpy(skb_put(skb
, pskb
->len
), pskb
->data
, pskb
->len
);
547 skb
->mac
.raw
= skb
->data
;
548 skb
->dev
= pskb
->dev
;
549 skb
->protocol
= pskb
->protocol
;
550 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
552 dev
->last_rx
= jiffies
;
553 privptr
->stats
.rx_packets
++;
554 privptr
->stats
.rx_bytes
+= skb
->len
;
555 skb_pull(pskb
, header
->next
);
556 skb_put(pskb
, NETIUCV_HDRLEN
);
561 conn_action_rx(fsm_instance
*fi
, int event
, void *arg
)
563 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
564 struct iucv_connection
*conn
= ev
->conn
;
565 iucv_MessagePending
*eib
= (iucv_MessagePending
*)ev
->data
;
566 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)conn
->netdev
->priv
;
568 __u16 msglen
= eib
->ln1msg2
.ipbfln1f
;
571 pr_debug("%s() called\n", __FUNCTION__
);
574 /* FRITZ: How to tell iucv LL to drop the msg? */
576 "Received data for unlinked connection\n");
579 if (msglen
> conn
->max_buffsize
) {
580 /* FRITZ: How to tell iucv LL to drop the msg? */
581 privptr
->stats
.rx_dropped
++;
584 conn
->rx_buff
->data
= conn
->rx_buff
->tail
= conn
->rx_buff
->head
;
585 conn
->rx_buff
->len
= 0;
586 rc
= iucv_receive(conn
->pathid
, eib
->ipmsgid
, eib
->iptrgcls
,
587 conn
->rx_buff
->data
, msglen
, NULL
, NULL
, NULL
);
588 if (rc
!= 0 || msglen
< 5) {
589 privptr
->stats
.rx_errors
++;
592 netiucv_unpack_skb(conn
, conn
->rx_buff
);
596 conn_action_txdone(fsm_instance
*fi
, int event
, void *arg
)
598 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
599 struct iucv_connection
*conn
= ev
->conn
;
600 iucv_MessageComplete
*eib
= (iucv_MessageComplete
*)ev
->data
;
601 struct netiucv_priv
*privptr
= NULL
;
602 /* Shut up, gcc! skb is always below 2G. */
603 struct sk_buff
*skb
= (struct sk_buff
*)(unsigned long)eib
->ipmsgtag
;
606 __u32 stat_maxcq
= 0;
607 unsigned long saveflags
;
610 pr_debug("%s() called\n", __FUNCTION__
);
612 fsm_deltimer(&conn
->timer
);
613 if (conn
&& conn
->netdev
&& conn
->netdev
->priv
)
614 privptr
= (struct netiucv_priv
*)conn
->netdev
->priv
;
617 privptr
->stats
.tx_packets
++;
618 privptr
->stats
.tx_bytes
+=
619 (skb
->len
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
);
621 dev_kfree_skb_any(skb
);
623 conn
->tx_buff
->data
= conn
->tx_buff
->tail
= conn
->tx_buff
->head
;
624 conn
->tx_buff
->len
= 0;
625 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
626 while ((skb
= skb_dequeue(&conn
->collect_queue
))) {
627 header
.next
= conn
->tx_buff
->len
+ skb
->len
+ NETIUCV_HDRLEN
;
628 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
630 memcpy(skb_put(conn
->tx_buff
, skb
->len
), skb
->data
, skb
->len
);
634 atomic_dec(&skb
->users
);
635 dev_kfree_skb_any(skb
);
637 if (conn
->collect_len
> conn
->prof
.maxmulti
)
638 conn
->prof
.maxmulti
= conn
->collect_len
;
639 conn
->collect_len
= 0;
640 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
641 if (conn
->tx_buff
->len
) {
645 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
648 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
649 CONN_EVENT_TIMER
, conn
);
650 conn
->prof
.send_stamp
= xtime
;
651 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0, 0, 0,
652 conn
->tx_buff
->data
, conn
->tx_buff
->len
);
653 conn
->prof
.doios_multi
++;
654 conn
->prof
.txlen
+= conn
->tx_buff
->len
;
656 fsm_deltimer(&conn
->timer
);
657 fsm_newstate(fi
, CONN_STATE_IDLE
);
659 privptr
->stats
.tx_errors
+= txpackets
;
662 privptr
->stats
.tx_packets
+= txpackets
;
663 privptr
->stats
.tx_bytes
+= txbytes
;
665 if (stat_maxcq
> conn
->prof
.maxcqueue
)
666 conn
->prof
.maxcqueue
= stat_maxcq
;
669 fsm_newstate(fi
, CONN_STATE_IDLE
);
673 conn_action_connaccept(fsm_instance
*fi
, int event
, void *arg
)
675 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
676 struct iucv_connection
*conn
= ev
->conn
;
677 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
678 struct net_device
*netdev
= conn
->netdev
;
679 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
684 pr_debug("%s() called\n", __FUNCTION__
);
686 rc
= iucv_accept(eib
->ippathid
, NETIUCV_QUEUELEN_DEFAULT
, udata
, 0,
687 conn
->handle
, conn
, NULL
, &msglimit
);
690 "%s: IUCV accept failed with error %d\n",
694 fsm_newstate(fi
, CONN_STATE_IDLE
);
695 conn
->pathid
= eib
->ippathid
;
696 netdev
->tx_queue_len
= msglimit
;
697 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
701 conn_action_connreject(fsm_instance
*fi
, int event
, void *arg
)
703 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
704 // struct iucv_connection *conn = ev->conn;
705 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
708 pr_debug("%s() called\n", __FUNCTION__
);
710 iucv_sever(eib
->ippathid
, udata
);
714 conn_action_connack(fsm_instance
*fi
, int event
, void *arg
)
716 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
717 struct iucv_connection
*conn
= ev
->conn
;
718 iucv_ConnectionComplete
*eib
= (iucv_ConnectionComplete
*)ev
->data
;
719 struct net_device
*netdev
= conn
->netdev
;
720 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
722 pr_debug("%s() called\n", __FUNCTION__
);
724 fsm_newstate(fi
, CONN_STATE_IDLE
);
725 conn
->pathid
= eib
->ippathid
;
726 netdev
->tx_queue_len
= eib
->ipmsglim
;
727 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
731 conn_action_connsever(fsm_instance
*fi
, int event
, void *arg
)
733 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
734 struct iucv_connection
*conn
= ev
->conn
;
735 // iucv_ConnectionSevered *eib = (iucv_ConnectionSevered *)ev->data;
736 struct net_device
*netdev
= conn
->netdev
;
737 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
738 int state
= fsm_getstate(fi
);
740 pr_debug("%s() called\n", __FUNCTION__
);
743 case CONN_STATE_IDLE
:
745 printk(KERN_INFO
"%s: Remote dropped connection\n",
748 iucv_unregister_program(conn
->handle
);
750 fsm_newstate(fi
, CONN_STATE_STOPPED
);
751 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
757 conn_action_start(fsm_instance
*fi
, int event
, void *arg
)
759 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
760 struct iucv_connection
*conn
= ev
->conn
;
764 pr_debug("%s() called\n", __FUNCTION__
);
766 if (conn
->handle
== 0) {
768 iucv_register_program(iucvMagic
, conn
->userid
, mask
,
770 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
771 if (conn
->handle
<= 0) {
772 fsm_newstate(fi
, CONN_STATE_REGERR
);
777 pr_debug("%s('%s'): registered successfully\n",
778 conn
->netdev
->name
, conn
->userid
);
781 pr_debug("%s('%s'): connecting ...\n",
782 conn
->netdev
->name
, conn
->userid
);
784 rc
= iucv_connect(&(conn
->pathid
), NETIUCV_QUEUELEN_DEFAULT
, iucvMagic
,
785 conn
->userid
, iucv_host
, 0, NULL
, NULL
, conn
->handle
,
787 fsm_newstate(fi
, CONN_STATE_SETUPWAIT
);
793 "%s: User %s is currently not available.\n",
795 netiucv_printname(conn
->userid
));
796 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
800 "%s: User %s is currently not ready.\n",
802 netiucv_printname(conn
->userid
));
803 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
807 "%s: Too many IUCV connections.\n",
809 fsm_newstate(fi
, CONN_STATE_CONNERR
);
813 "%s: User %s has too many IUCV connections.\n",
815 netiucv_printname(conn
->userid
));
816 fsm_newstate(fi
, CONN_STATE_CONNERR
);
820 "%s: No IUCV authorization in CP directory.\n",
822 fsm_newstate(fi
, CONN_STATE_CONNERR
);
826 "%s: iucv_connect returned error %d\n",
827 conn
->netdev
->name
, rc
);
828 fsm_newstate(fi
, CONN_STATE_CONNERR
);
831 iucv_unregister_program(conn
->handle
);
836 netiucv_purge_skb_queue(struct sk_buff_head
*q
)
840 while ((skb
= skb_dequeue(q
))) {
841 atomic_dec(&skb
->users
);
842 dev_kfree_skb_any(skb
);
847 conn_action_stop(fsm_instance
*fi
, int event
, void *arg
)
849 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
850 struct iucv_connection
*conn
= ev
->conn
;
851 struct net_device
*netdev
= conn
->netdev
;
852 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
854 pr_debug("%s() called\n", __FUNCTION__
);
856 fsm_newstate(fi
, CONN_STATE_STOPPED
);
857 netiucv_purge_skb_queue(&conn
->collect_queue
);
859 iucv_unregister_program(conn
->handle
);
861 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
865 conn_action_inval(fsm_instance
*fi
, int event
, void *arg
)
867 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
868 struct iucv_connection
*conn
= ev
->conn
;
869 struct net_device
*netdev
= conn
->netdev
;
872 "%s: Cannot connect without username\n",
876 static const fsm_node conn_fsm
[] = {
877 { CONN_STATE_INVALID
, CONN_EVENT_START
, conn_action_inval
},
878 { CONN_STATE_STOPPED
, CONN_EVENT_START
, conn_action_start
},
879 { CONN_STATE_STARTWAIT
, CONN_EVENT_START
, conn_action_start
},
881 { CONN_STATE_STARTWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
882 { CONN_STATE_SETUPWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
883 { CONN_STATE_IDLE
, CONN_EVENT_STOP
, conn_action_stop
},
884 { CONN_STATE_TX
, CONN_EVENT_STOP
, conn_action_stop
},
885 { CONN_STATE_REGERR
, CONN_EVENT_STOP
, conn_action_stop
},
886 { CONN_STATE_CONNERR
, CONN_EVENT_STOP
, conn_action_stop
},
888 { CONN_STATE_STOPPED
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
889 { CONN_STATE_STARTWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
890 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
891 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
892 { CONN_STATE_TX
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
894 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_ACK
, conn_action_connack
},
896 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
897 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
898 { CONN_STATE_TX
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
900 { CONN_STATE_IDLE
, CONN_EVENT_RX
, conn_action_rx
},
901 { CONN_STATE_TX
, CONN_EVENT_RX
, conn_action_rx
},
903 { CONN_STATE_TX
, CONN_EVENT_TXDONE
, conn_action_txdone
},
906 static const int CONN_FSM_LEN
= sizeof(conn_fsm
) / sizeof(fsm_node
);
910 * Actions for interface - statemachine.
911 *****************************************************************************/
914 * Startup connection by sending CONN_EVENT_START to it.
916 * @param fi An instance of an interface statemachine.
917 * @param event The event, just happened.
918 * @param arg Generic pointer, casted from struct net_device * upon call.
921 dev_action_start(fsm_instance
*fi
, int event
, void *arg
)
923 struct net_device
*dev
= (struct net_device
*)arg
;
924 struct netiucv_priv
*privptr
= dev
->priv
;
925 struct iucv_event ev
;
927 pr_debug("%s() called\n", __FUNCTION__
);
929 ev
.conn
= privptr
->conn
;
930 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
931 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, &ev
);
935 * Shutdown connection by sending CONN_EVENT_STOP to it.
937 * @param fi An instance of an interface statemachine.
938 * @param event The event, just happened.
939 * @param arg Generic pointer, casted from struct net_device * upon call.
942 dev_action_stop(fsm_instance
*fi
, int event
, void *arg
)
944 struct net_device
*dev
= (struct net_device
*)arg
;
945 struct netiucv_priv
*privptr
= dev
->priv
;
946 struct iucv_event ev
;
948 pr_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 struct net_device * upon call.
965 dev_action_connup(fsm_instance
*fi
, int event
, void *arg
)
967 struct net_device
*dev
= (struct net_device
*)arg
;
969 pr_debug("%s() called\n", __FUNCTION__
);
971 switch (fsm_getstate(fi
)) {
972 case DEV_STATE_STARTWAIT
:
973 fsm_newstate(fi
, DEV_STATE_RUNNING
);
975 "%s: connected with remote side\n",
978 case DEV_STATE_STOPWAIT
:
980 "%s: got connection UP event during shutdown!!\n",
987 * Called from connection statemachine
988 * when a connection has been shutdown.
990 * @param fi An instance of an interface statemachine.
991 * @param event The event, just happened.
992 * @param arg Generic pointer, casted from struct net_device * upon call.
995 dev_action_conndown(fsm_instance
*fi
, int event
, void *arg
)
997 struct net_device
*dev
= (struct net_device
*)arg
;
998 struct netiucv_priv
*privptr
= dev
->priv
;
999 struct iucv_event ev
;
1001 pr_debug("%s() called\n", __FUNCTION__
);
1003 switch (fsm_getstate(fi
)) {
1004 case DEV_STATE_RUNNING
:
1005 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1006 ev
.conn
= privptr
->conn
;
1007 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, &ev
);
1009 case DEV_STATE_STARTWAIT
:
1011 case DEV_STATE_STOPWAIT
:
1012 fsm_newstate(fi
, DEV_STATE_STOPPED
);
1017 static const fsm_node dev_fsm
[] = {
1018 { DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
1020 { DEV_STATE_STOPWAIT
, DEV_EVENT_START
, dev_action_start
},
1021 { DEV_STATE_STOPWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1023 { DEV_STATE_STARTWAIT
, DEV_EVENT_STOP
, dev_action_stop
},
1024 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONUP
, dev_action_connup
},
1025 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1027 { DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
1028 { DEV_STATE_RUNNING
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1029 { DEV_STATE_RUNNING
, DEV_EVENT_CONUP
, fsm_action_nop
},
1032 static const int DEV_FSM_LEN
= sizeof(dev_fsm
) / sizeof(fsm_node
);
1035 * Transmit a packet.
1036 * This is a helper function for netiucv_tx().
1038 * @param conn Connection to be used for sending.
1039 * @param skb Pointer to struct sk_buff of packet to send.
1040 * The linklevel header has already been set up
1043 * @return 0 on success, -ERRNO on failure. (Never fails.)
1046 netiucv_transmit_skb(struct iucv_connection
*conn
, struct sk_buff
*skb
) {
1047 unsigned long saveflags
;
1051 if (fsm_getstate(conn
->fsm
) != CONN_STATE_IDLE
) {
1052 int l
= skb
->len
+ NETIUCV_HDRLEN
;
1054 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
1055 if (conn
->collect_len
+ l
>
1056 (conn
->max_buffsize
- NETIUCV_HDRLEN
))
1059 atomic_inc(&skb
->users
);
1060 skb_queue_tail(&conn
->collect_queue
, skb
);
1061 conn
->collect_len
+= l
;
1063 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
1065 struct sk_buff
*nskb
= skb
;
1067 * Copy the skb to a new allocated skb in lowmem only if the
1068 * data is located above 2G in memory or tailroom is < 2.
1071 ((unsigned long)(skb
->tail
+ NETIUCV_HDRLEN
)) >> 31;
1073 if (hi
|| (skb_tailroom(skb
) < 2)) {
1074 nskb
= alloc_skb(skb
->len
+ NETIUCV_HDRLEN
+
1075 NETIUCV_HDRLEN
, GFP_ATOMIC
| GFP_DMA
);
1078 "%s: Could not allocate tx_skb\n",
1079 conn
->netdev
->name
);
1082 skb_reserve(nskb
, NETIUCV_HDRLEN
);
1083 memcpy(skb_put(nskb
, skb
->len
),
1084 skb
->data
, skb
->len
);
1089 * skb now is below 2G and has enough room. Add headers.
1091 header
.next
= nskb
->len
+ NETIUCV_HDRLEN
;
1092 memcpy(skb_push(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1094 memcpy(skb_put(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1097 fsm_newstate(conn
->fsm
, CONN_STATE_TX
);
1098 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
1099 CONN_EVENT_TIMER
, conn
);
1100 conn
->prof
.send_stamp
= xtime
;
1102 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0,
1103 /* Shut up, gcc! nskb is always below 2G. */
1104 (__u32
)(((unsigned long)nskb
)&0xffffffff), 0,
1105 nskb
->data
, nskb
->len
);
1106 conn
->prof
.doios_single
++;
1107 conn
->prof
.txlen
+= skb
->len
;
1109 fsm_deltimer(&conn
->timer
);
1111 dev_kfree_skb(nskb
);
1114 * Remove our headers. They get added
1115 * again on retransmit.
1117 skb_pull(skb
, NETIUCV_HDRLEN
);
1118 skb_trim(skb
, skb
->len
- NETIUCV_HDRLEN
);
1130 * Interface API for upper network layers
1131 *****************************************************************************/
1134 * Open an interface.
1135 * Called from generic network layer when ifconfig up is run.
1137 * @param dev Pointer to interface struct.
1139 * @return 0 on success, -ERRNO on failure. (Never fails.)
1142 netiucv_open(struct net_device
*dev
) {
1143 SET_DEVICE_START(dev
, 1);
1144 fsm_event(((struct netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_START
, dev
);
1149 * Close an interface.
1150 * Called from generic network layer when ifconfig down is run.
1152 * @param dev Pointer to interface struct.
1154 * @return 0 on success, -ERRNO on failure. (Never fails.)
1157 netiucv_close(struct net_device
*dev
) {
1158 SET_DEVICE_START(dev
, 0);
1159 fsm_event(((struct netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_STOP
, dev
);
1164 * Start transmission of a packet.
1165 * Called from generic network device layer.
1167 * @param skb Pointer to buffer containing the packet.
1168 * @param dev Pointer to interface struct.
1170 * @return 0 if packet consumed, !0 if packet rejected.
1171 * Note: If we return !0, then the packet is free'd by
1172 * the generic network layer.
1174 static int netiucv_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1177 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)dev
->priv
;
1180 * Some sanity checks ...
1183 printk(KERN_WARNING
"%s: NULL sk_buff passed\n", dev
->name
);
1184 privptr
->stats
.tx_dropped
++;
1187 if (skb_headroom(skb
) < (NETIUCV_HDRLEN
)) {
1189 "%s: Got sk_buff with head room < %ld bytes\n",
1190 dev
->name
, NETIUCV_HDRLEN
);
1192 privptr
->stats
.tx_dropped
++;
1197 * If connection is not running, try to restart it
1198 * notify anybody about a link failure and throw
1201 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
1202 fsm_event(privptr
->fsm
, DEV_EVENT_START
, dev
);
1203 dst_link_failure(skb
);
1205 privptr
->stats
.tx_dropped
++;
1206 privptr
->stats
.tx_errors
++;
1207 privptr
->stats
.tx_carrier_errors
++;
1211 if (netiucv_test_and_set_busy(dev
))
1214 dev
->trans_start
= jiffies
;
1215 if (netiucv_transmit_skb(privptr
->conn
, skb
) != 0)
1217 netiucv_clear_busy(dev
);
1222 * Returns interface statistics of a device.
1224 * @param dev Pointer to interface struct.
1226 * @return Pointer to stats struct of this interface.
1228 static struct net_device_stats
*
1229 netiucv_stats (struct net_device
* dev
)
1231 return &((struct netiucv_priv
*)dev
->priv
)->stats
;
1235 * Sets MTU of an interface.
1237 * @param dev Pointer to interface struct.
1238 * @param new_mtu The new MTU to use for this interface.
1240 * @return 0 on success, -EINVAL if MTU is out of valid range.
1241 * (valid range is 576 .. NETIUCV_MTU_MAX).
1244 netiucv_change_mtu (struct net_device
* dev
, int new_mtu
)
1246 if ((new_mtu
< 576) || (new_mtu
> NETIUCV_MTU_MAX
))
1253 * attributes in sysfs
1254 *****************************************************************************/
1255 #define CTRL_BUFSIZE 40
1258 buffer_show (struct device
*dev
, char *buf
)
1260 struct netiucv_priv
*priv
= dev
->driver_data
;
1262 return sprintf(buf
, "%d\n", priv
->conn
->max_buffsize
);
1266 buffer_write (struct device
*dev
, const char *buf
, size_t count
)
1268 struct netiucv_priv
*priv
= dev
->driver_data
;
1269 struct net_device
*ndev
=
1270 container_of((void *)priv
, struct net_device
, priv
);
1273 char tmp
[CTRL_BUFSIZE
];
1278 if (copy_from_user(tmp
, buf
, count
))
1280 tmp
[count
+1] = '\0';
1281 bs1
= simple_strtoul(tmp
, &e
, 0);
1283 if ((bs1
> NETIUCV_BUFSIZE_MAX
) ||
1284 (e
&& (!isspace(*e
))))
1286 if ((ndev
->flags
& IFF_RUNNING
) &&
1287 (bs1
< (ndev
->mtu
+ NETIUCV_HDRLEN
+ 2)))
1289 if (bs1
< (576 + NETIUCV_HDRLEN
+ NETIUCV_HDRLEN
))
1293 priv
->conn
->max_buffsize
= bs1
;
1294 if (!(ndev
->flags
& IFF_RUNNING
))
1295 ndev
->mtu
= bs1
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
;
1296 priv
->conn
->flags
|= CONN_FLAGS_BUFSIZE_CHANGED
;
1302 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
1305 dev_fsm_show (struct device
*dev
, char *buf
)
1307 struct netiucv_priv
*priv
= dev
->driver_data
;
1309 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->fsm
));
1312 static DEVICE_ATTR(device_fsm_state
, 0444, dev_fsm_show
, NULL
);
1315 conn_fsm_show (struct device
*dev
, char *buf
)
1317 struct netiucv_priv
*priv
= dev
->driver_data
;
1319 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->conn
->fsm
));
1322 static DEVICE_ATTR(connection_fsm_state
, 0444, conn_fsm_show
, NULL
);
1325 maxmulti_show (struct device
*dev
, char *buf
)
1327 struct netiucv_priv
*priv
= dev
->driver_data
;
1329 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxmulti
);
1333 maxmulti_write (struct device
*dev
, const char *buf
, size_t count
)
1335 struct netiucv_priv
*priv
= dev
->driver_data
;
1337 priv
->conn
->prof
.maxmulti
= 0;
1341 static DEVICE_ATTR(max_tx_buffer_used
, 0644, maxmulti_show
, maxmulti_write
);
1344 maxcq_show (struct device
*dev
, char *buf
)
1346 struct netiucv_priv
*priv
= dev
->driver_data
;
1348 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxcqueue
);
1352 maxcq_write (struct device
*dev
, const char *buf
, size_t count
)
1354 struct netiucv_priv
*priv
= dev
->driver_data
;
1356 priv
->conn
->prof
.maxcqueue
= 0;
1360 static DEVICE_ATTR(max_chained_skbs
, 0644, maxcq_show
, maxcq_write
);
1363 sdoio_show (struct device
*dev
, char *buf
)
1365 struct netiucv_priv
*priv
= dev
->driver_data
;
1367 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_single
);
1371 sdoio_write (struct device
*dev
, const char *buf
, size_t count
)
1373 struct netiucv_priv
*priv
= dev
->driver_data
;
1375 priv
->conn
->prof
.doios_single
= 0;
1379 static DEVICE_ATTR(tx_single_write_ops
, 0644, sdoio_show
, sdoio_write
);
1382 mdoio_show (struct device
*dev
, char *buf
)
1384 struct netiucv_priv
*priv
= dev
->driver_data
;
1386 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_multi
);
1390 mdoio_write (struct device
*dev
, const char *buf
, size_t count
)
1392 struct netiucv_priv
*priv
= dev
->driver_data
;
1394 priv
->conn
->prof
.doios_multi
= 0;
1398 static DEVICE_ATTR(tx_multi_write_ops
, 0644, mdoio_show
, mdoio_write
);
1401 txlen_show (struct device
*dev
, char *buf
)
1403 struct netiucv_priv
*priv
= dev
->driver_data
;
1405 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.txlen
);
1409 txlen_write (struct device
*dev
, const char *buf
, size_t count
)
1411 struct netiucv_priv
*priv
= dev
->driver_data
;
1413 priv
->conn
->prof
.txlen
= 0;
1417 static DEVICE_ATTR(netto_bytes
, 0644, txlen_show
, txlen_write
);
1420 txtime_show (struct device
*dev
, char *buf
)
1422 struct netiucv_priv
*priv
= dev
->driver_data
;
1424 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_time
);
1428 txtime_write (struct device
*dev
, const char *buf
, size_t count
)
1430 struct netiucv_priv
*priv
= dev
->driver_data
;
1432 priv
->conn
->prof
.tx_time
= 0;
1436 static DEVICE_ATTR(max_tx_io_time
, 0644, txtime_show
, txtime_write
);
1439 netiucv_add_files(struct device
*dev
)
1443 if ((ret
= device_create_file(dev
, &dev_attr_buffer
)) ||
1444 (ret
= device_create_file(dev
, &dev_attr_device_fsm_state
)) ||
1445 (ret
= device_create_file(dev
, &dev_attr_connection_fsm_state
)) ||
1446 (ret
= device_create_file(dev
, &dev_attr_max_tx_buffer_used
)) ||
1447 (ret
= device_create_file(dev
, &dev_attr_max_chained_skbs
)) ||
1448 (ret
= device_create_file(dev
, &dev_attr_tx_single_write_ops
)) ||
1449 (ret
= device_create_file(dev
, &dev_attr_tx_multi_write_ops
)) ||
1450 (ret
= device_create_file(dev
, &dev_attr_netto_bytes
)) ||
1451 (ret
= device_create_file(dev
, &dev_attr_max_tx_io_time
))) {
1452 device_remove_file(dev
, &dev_attr_netto_bytes
);
1453 device_remove_file(dev
, &dev_attr_tx_multi_write_ops
);
1454 device_remove_file(dev
, &dev_attr_tx_single_write_ops
);
1455 device_remove_file(dev
, &dev_attr_max_chained_skbs
);
1456 device_remove_file(dev
, &dev_attr_max_tx_buffer_used
);
1457 device_remove_file(dev
, &dev_attr_connection_fsm_state
);
1458 device_remove_file(dev
, &dev_attr_device_fsm_state
);
1459 device_remove_file(dev
, &dev_attr_buffer
);
1465 netiucv_register_device(struct net_device
*ndev
, int ifno
)
1467 struct netiucv_priv
*priv
= ndev
->priv
;
1468 struct device
*dev
= &priv
->dev
;
1470 char *str
= "netiucv";
1472 snprintf(dev
->name
, DEVICE_NAME_SIZE
, "%s", priv
->conn
->userid
);
1473 snprintf(dev
->bus_id
, BUS_ID_SIZE
, "%s%x", str
, ifno
);
1474 dev
->bus
= &iucv_bus
;
1475 dev
->parent
= &iucv_root
;
1477 ret
= device_register(dev
);
1482 ret
= netiucv_add_files(dev
);
1485 device_unregister(dev
);
1487 dev
->driver_data
= priv
;
1492 netiucv_unregister_device(struct net_device
*ndev
)
1494 struct netiucv_priv
*priv
= (struct netiucv_priv
*)ndev
->priv
;
1495 struct device
*dev
= &priv
->dev
;
1497 device_unregister(dev
);
1501 * Allocate and initialize a new connection structure.
1502 * Add it to the list of connections;
1504 static struct iucv_connection
*
1505 netiucv_new_connection(struct net_device
*dev
, char *username
)
1507 struct iucv_connection
**clist
= &connections
;
1508 struct iucv_connection
*conn
=
1509 (struct iucv_connection
*)
1510 kmalloc(sizeof(struct iucv_connection
), GFP_KERNEL
);
1513 memset(conn
, 0, sizeof(struct iucv_connection
));
1514 skb_queue_head_init(&conn
->collect_queue
);
1515 conn
->max_buffsize
= NETIUCV_BUFSIZE_DEFAULT
;
1518 conn
->rx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
,
1519 GFP_KERNEL
| GFP_DMA
);
1520 if (!conn
->rx_buff
) {
1524 conn
->tx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
,
1525 GFP_KERNEL
| GFP_DMA
);
1526 if (!conn
->tx_buff
) {
1527 kfree_skb(conn
->rx_buff
);
1531 conn
->fsm
= init_fsm("netiucvconn", conn_state_names
,
1532 conn_event_names
, NR_CONN_STATES
,
1533 NR_CONN_EVENTS
, conn_fsm
, CONN_FSM_LEN
,
1536 kfree_skb(conn
->tx_buff
);
1537 kfree_skb(conn
->rx_buff
);
1541 fsm_settimer(conn
->fsm
, &conn
->timer
);
1542 fsm_newstate(conn
->fsm
, CONN_STATE_INVALID
);
1545 memcpy(conn
->userid
, username
, 9);
1546 fsm_newstate(conn
->fsm
, CONN_STATE_STOPPED
);
1549 conn
->next
= *clist
;
1556 * Release a connection structure and remove it from the
1557 * list of connections.
1560 netiucv_remove_connection(struct iucv_connection
*conn
)
1562 struct iucv_connection
**clist
= &connections
;
1567 if (*clist
== conn
) {
1568 *clist
= conn
->next
;
1569 if (conn
->handle
!= 0) {
1570 iucv_unregister_program(conn
->handle
);
1573 fsm_deltimer(&conn
->timer
);
1574 kfree_fsm(conn
->fsm
);
1575 kfree_skb(conn
->rx_buff
);
1576 kfree_skb(conn
->tx_buff
);
1579 clist
= &((*clist
)->next
);
1584 * Allocate and initialize everything of a net device.
1586 static struct net_device
*
1587 netiucv_init_netdevice(int ifno
, char *username
)
1589 struct netiucv_priv
*privptr
;
1592 struct net_device
*dev
= kmalloc(sizeof(struct net_device
), GFP_KERNEL
);
1595 memset(dev
, 0, sizeof(struct net_device
));
1596 sprintf(dev
->name
, "iucv%d", ifno
);
1598 priv_size
= sizeof(struct netiucv_priv
);
1599 dev
->priv
= kmalloc(priv_size
, GFP_KERNEL
);
1600 if (dev
->priv
== NULL
) {
1604 memset(dev
->priv
, 0, priv_size
);
1605 privptr
= (struct netiucv_priv
*)dev
->priv
;
1606 privptr
->fsm
= init_fsm("netiucvdev", dev_state_names
,
1607 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
1608 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
1609 if (privptr
->fsm
== NULL
) {
1614 privptr
->conn
= netiucv_new_connection(dev
, username
);
1615 if (!privptr
->conn
) {
1616 kfree_fsm(privptr
->fsm
);
1622 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
1623 dev
->mtu
= NETIUCV_MTU_DEFAULT
;
1624 dev
->hard_start_xmit
= netiucv_tx
;
1625 dev
->open
= netiucv_open
;
1626 dev
->stop
= netiucv_close
;
1627 dev
->get_stats
= netiucv_stats
;
1628 dev
->change_mtu
= netiucv_change_mtu
;
1629 dev
->hard_header_len
= NETIUCV_HDRLEN
;
1631 dev
->type
= ARPHRD_SLIP
;
1632 dev
->tx_queue_len
= NETIUCV_QUEUELEN_DEFAULT
;
1633 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
1634 SET_MODULE_OWNER(dev
);
1639 * Allocate and initialize everything of a net device.
1642 netiucv_free_netdevice(struct net_device
*dev
)
1644 struct netiucv_priv
*privptr
;
1649 privptr
= (struct netiucv_priv
*)dev
->priv
;
1652 netiucv_remove_connection(privptr
->conn
);
1654 kfree_fsm(privptr
->fsm
);
1661 conn_write(struct device_driver
*drv
, const char *buf
, size_t count
)
1666 struct net_device
*dev
;
1670 "netiucv: username too long (%d)!\n", (int)count
);
1674 for (i
=0, p
=(char *)buf
; i
<8 && *p
; i
++, p
++) {
1677 else if (*p
== '\n') {
1678 /* trailing lf, grr */
1682 "netiucv: Invalid character in username!\n");
1687 username
[i
++] = ' ';
1689 dev
= netiucv_init_netdevice(ifno
, username
);
1692 "netiucv: Could not allocate network device structure "
1693 "for user '%s'\n", netiucv_printname(username
));
1697 if (register_netdev(dev
)) {
1699 "netiucv: Could not register '%s'\n", dev
->name
);
1700 netiucv_free_netdevice(dev
);
1703 printk(KERN_INFO
"%s: '%s'\n", dev
->name
, netiucv_printname(username
));
1704 netiucv_register_device(dev
, ifno
);
1710 DRIVER_ATTR(connection
, 0200, NULL
, conn_write
);
1712 static struct device_driver netiucv_driver
= {
1718 netiucv_banner(void)
1720 char vbuf
[] = "$Revision: 1.20 $";
1721 char *version
= vbuf
;
1723 if ((version
= strchr(version
, ':'))) {
1724 char *p
= strchr(version
+ 1, '$');
1729 printk(KERN_INFO
"NETIUCV driver Version%s initialized\n", version
);
1735 while (connections
) {
1736 struct net_device
*dev
= connections
->netdev
;
1737 unregister_netdev(dev
);
1738 netiucv_unregister_device(dev
);
1739 netiucv_free_netdevice(dev
);
1742 driver_remove_file(&netiucv_driver
, &driver_attr_connection
);
1743 driver_unregister(&netiucv_driver
);
1744 bus_unregister(&iucv_bus
);
1746 printk(KERN_INFO
"NETIUCV driver unloaded\n");
1755 /* Move the bus stuff to iucv.c? - CH */
1756 ret
= bus_register(&iucv_bus
);
1758 printk(KERN_ERR
"NETIUCV: failed to register bus.\n");
1762 ret
= driver_register(&netiucv_driver
);
1764 printk(KERN_ERR
"NETIUCV: failed to register driver.\n");
1765 bus_unregister(&iucv_bus
);
1769 ret
= device_register(&iucv_root
);
1771 printk(KERN_ERR
"NETIUCV: failed to register iucv root.\n");
1772 driver_unregister(&netiucv_driver
);
1773 bus_unregister(&iucv_bus
);
1777 /* Add entry for specifying connections. */
1778 ret
= driver_create_file(&netiucv_driver
, &driver_attr_connection
);
1783 printk(KERN_ERR
"NETIUCV: failed to add driver attribute.\n");
1784 device_unregister(&iucv_root
);
1785 driver_unregister(&netiucv_driver
);
1786 bus_unregister(&iucv_bus
);
1791 module_init(netiucv_init
);
1792 module_exit(netiucv_exit
);
1793 MODULE_LICENSE("GPL");