4 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
7 * Sysfs integration and all bugs therein by Cornelia Huck
8 * (cornelia.huck@de.ibm.com)
11 * the source of the original IUCV driver by:
12 * Stefan Hegewald <hegewald@de.ibm.com>
13 * Hartmut Penner <hpenner@de.ibm.com>
14 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
15 * Martin Schwidefsky (schwidefsky@de.ibm.com)
16 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/errno.h>
41 #include <linux/types.h>
42 #include <linux/interrupt.h>
43 #include <linux/timer.h>
44 #include <linux/sched.h>
45 #include <linux/bitops.h>
47 #include <linux/signal.h>
48 #include <linux/string.h>
49 #include <linux/device.h>
52 #include <linux/if_arp.h>
53 #include <linux/tcp.h>
54 #include <linux/skbuff.h>
55 #include <linux/ctype.h>
59 #include <asm/uaccess.h>
65 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
66 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
69 #define PRINTK_HEADER " iucv: " /* for debugging */
71 static struct device_driver netiucv_driver
= {
77 * Per connection profiling data
79 struct connection_profile
{
80 unsigned long maxmulti
;
81 unsigned long maxcqueue
;
82 unsigned long doios_single
;
83 unsigned long doios_multi
;
85 unsigned long tx_time
;
86 struct timespec send_stamp
;
87 unsigned long tx_pending
;
88 unsigned long tx_max_pending
;
92 * Representation of one iucv connection
94 struct iucv_connection
{
95 struct iucv_connection
*next
;
98 struct sk_buff
*rx_buff
;
99 struct sk_buff
*tx_buff
;
100 struct sk_buff_head collect_queue
;
101 struct sk_buff_head commit_queue
;
102 spinlock_t collect_lock
;
107 struct net_device
*netdev
;
108 struct connection_profile prof
;
113 * Linked list of all connection structs.
115 static struct iucv_connection
*iucv_connections
;
118 * Representation of event-data for the
119 * connection state machine.
122 struct iucv_connection
*conn
;
127 * Private part of the network device structure
129 struct netiucv_priv
{
130 struct net_device_stats stats
;
133 struct iucv_connection
*conn
;
138 * Link level header for a packet.
140 typedef struct ll_header_t
{
144 #define NETIUCV_HDRLEN (sizeof(ll_header))
145 #define NETIUCV_BUFSIZE_MAX 32768
146 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
147 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
148 #define NETIUCV_MTU_DEFAULT 9216
149 #define NETIUCV_QUEUELEN_DEFAULT 50
150 #define NETIUCV_TIMEOUT_5SEC 5000
153 * Compatibility macros for busy handling
154 * of network devices.
156 static __inline__
void netiucv_clear_busy(struct net_device
*dev
)
158 clear_bit(0, &(((struct netiucv_priv
*)dev
->priv
)->tbusy
));
159 netif_wake_queue(dev
);
162 static __inline__
int netiucv_test_and_set_busy(struct net_device
*dev
)
164 netif_stop_queue(dev
);
165 return test_and_set_bit(0, &((struct netiucv_priv
*)dev
->priv
)->tbusy
);
168 static __u8 iucv_host
[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
169 static __u8 iucvMagic
[16] = {
170 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
171 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
175 * This mask means the 16-byte IUCV "magic" and the origin userid must
176 * match exactly as specified in order to give connection_pending()
179 static __u8 netiucv_mask
[] = {
180 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
181 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
182 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
186 * Convert an iucv userId to its printable
187 * form (strip whitespace at end).
189 * @param An iucv userId
191 * @returns The printable string (static data!!)
193 static __inline__
char *
194 netiucv_printname(char *name
)
198 memcpy(tmp
, name
, 8);
200 while (*p
&& (!isspace(*p
)))
207 * States of the interface statemachine.
215 * MUST be always the last element!!
220 static const char *dev_state_names
[] = {
228 * Events of the interface statemachine.
236 * MUST be always the last element!!
241 static const char *dev_event_names
[] = {
249 * Events of the connection statemachine
253 * Events, representing callbacks from
254 * lowlevel iucv layer)
265 * Events, representing errors return codes from
266 * calls to lowlevel iucv layer
270 * Event, representing timer expiry.
275 * Events, representing commands from upper levels.
281 * MUST be always the last element!!
286 static const char *conn_event_names
[] = {
287 "Remote connection request",
288 "Remote connection acknowledge",
289 "Remote connection reject",
290 "Connection suspended",
291 "Connection resumed",
302 * States of the connection statemachine.
306 * Connection not assigned to any device,
307 * initial state, invalid
312 * Userid assigned but not operating
317 * Connection registered,
318 * no connection request sent yet,
319 * no connection request received
321 CONN_STATE_STARTWAIT
,
324 * Connection registered and connection request sent,
325 * no acknowledge and no connection request received yet.
327 CONN_STATE_SETUPWAIT
,
330 * Connection up and running idle
335 * Data sent, awaiting CONN_EVENT_TXDONE
340 * Error during registration.
345 * Error during registration.
350 * MUST be always the last element!!
355 static const char *conn_state_names
[] = {
363 "Registration error",
369 * Debug Facility Stuff
371 static debug_info_t
*iucv_dbf_setup
= NULL
;
372 static debug_info_t
*iucv_dbf_data
= NULL
;
373 static debug_info_t
*iucv_dbf_trace
= NULL
;
375 DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf
);
378 iucv_unregister_dbf_views(void)
381 debug_unregister(iucv_dbf_setup
);
383 debug_unregister(iucv_dbf_data
);
385 debug_unregister(iucv_dbf_trace
);
388 iucv_register_dbf_views(void)
390 iucv_dbf_setup
= debug_register(IUCV_DBF_SETUP_NAME
,
391 IUCV_DBF_SETUP_PAGES
,
392 IUCV_DBF_SETUP_NR_AREAS
,
394 iucv_dbf_data
= debug_register(IUCV_DBF_DATA_NAME
,
396 IUCV_DBF_DATA_NR_AREAS
,
398 iucv_dbf_trace
= debug_register(IUCV_DBF_TRACE_NAME
,
399 IUCV_DBF_TRACE_PAGES
,
400 IUCV_DBF_TRACE_NR_AREAS
,
403 if ((iucv_dbf_setup
== NULL
) || (iucv_dbf_data
== NULL
) ||
404 (iucv_dbf_trace
== NULL
)) {
405 iucv_unregister_dbf_views();
408 debug_register_view(iucv_dbf_setup
, &debug_hex_ascii_view
);
409 debug_set_level(iucv_dbf_setup
, IUCV_DBF_SETUP_LEVEL
);
411 debug_register_view(iucv_dbf_data
, &debug_hex_ascii_view
);
412 debug_set_level(iucv_dbf_data
, IUCV_DBF_DATA_LEVEL
);
414 debug_register_view(iucv_dbf_trace
, &debug_hex_ascii_view
);
415 debug_set_level(iucv_dbf_trace
, IUCV_DBF_TRACE_LEVEL
);
421 * Callback-wrappers, called from lowlevel iucv layer.
422 *****************************************************************************/
425 netiucv_callback_rx(iucv_MessagePending
*eib
, void *pgm_data
)
427 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
428 struct iucv_event ev
;
431 ev
.data
= (void *)eib
;
433 fsm_event(conn
->fsm
, CONN_EVENT_RX
, &ev
);
437 netiucv_callback_txdone(iucv_MessageComplete
*eib
, void *pgm_data
)
439 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
440 struct iucv_event ev
;
443 ev
.data
= (void *)eib
;
444 fsm_event(conn
->fsm
, CONN_EVENT_TXDONE
, &ev
);
448 netiucv_callback_connack(iucv_ConnectionComplete
*eib
, void *pgm_data
)
450 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
451 struct iucv_event ev
;
454 ev
.data
= (void *)eib
;
455 fsm_event(conn
->fsm
, CONN_EVENT_CONN_ACK
, &ev
);
459 netiucv_callback_connreq(iucv_ConnectionPending
*eib
, void *pgm_data
)
461 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
462 struct iucv_event ev
;
465 ev
.data
= (void *)eib
;
466 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REQ
, &ev
);
470 netiucv_callback_connrej(iucv_ConnectionSevered
*eib
, void *pgm_data
)
472 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
473 struct iucv_event ev
;
476 ev
.data
= (void *)eib
;
477 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REJ
, &ev
);
481 netiucv_callback_connsusp(iucv_ConnectionQuiesced
*eib
, void *pgm_data
)
483 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
484 struct iucv_event ev
;
487 ev
.data
= (void *)eib
;
488 fsm_event(conn
->fsm
, CONN_EVENT_CONN_SUS
, &ev
);
492 netiucv_callback_connres(iucv_ConnectionResumed
*eib
, void *pgm_data
)
494 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
495 struct iucv_event ev
;
498 ev
.data
= (void *)eib
;
499 fsm_event(conn
->fsm
, CONN_EVENT_CONN_RES
, &ev
);
502 static iucv_interrupt_ops_t netiucv_ops
= {
503 .ConnectionPending
= netiucv_callback_connreq
,
504 .ConnectionComplete
= netiucv_callback_connack
,
505 .ConnectionSevered
= netiucv_callback_connrej
,
506 .ConnectionQuiesced
= netiucv_callback_connsusp
,
507 .ConnectionResumed
= netiucv_callback_connres
,
508 .MessagePending
= netiucv_callback_rx
,
509 .MessageComplete
= netiucv_callback_txdone
513 * Dummy NOP action for all statemachines
516 fsm_action_nop(fsm_instance
*fi
, int event
, void *arg
)
521 * Actions of the connection statemachine
522 *****************************************************************************/
525 * Helper function for conn_action_rx()
526 * Unpack a just received skb and hand it over to
529 * @param conn The connection where this skb has been received.
530 * @param pskb The received skb.
532 //static __inline__ void
534 netiucv_unpack_skb(struct iucv_connection
*conn
, struct sk_buff
*pskb
)
536 struct net_device
*dev
= conn
->netdev
;
537 struct netiucv_priv
*privptr
= dev
->priv
;
540 skb_put(pskb
, NETIUCV_HDRLEN
);
542 pskb
->ip_summed
= CHECKSUM_NONE
;
543 pskb
->protocol
= ntohs(ETH_P_IP
);
547 ll_header
*header
= (ll_header
*)pskb
->data
;
552 skb_pull(pskb
, NETIUCV_HDRLEN
);
553 header
->next
-= offset
;
554 offset
+= header
->next
;
555 header
->next
-= NETIUCV_HDRLEN
;
556 if (skb_tailroom(pskb
) < header
->next
) {
557 PRINT_WARN("%s: Illegal next field in iucv header: "
559 dev
->name
, header
->next
, skb_tailroom(pskb
));
560 IUCV_DBF_TEXT_(data
, 2, "Illegal next field: %d > %d\n",
561 header
->next
, skb_tailroom(pskb
));
564 skb_put(pskb
, header
->next
);
565 pskb
->mac
.raw
= pskb
->data
;
566 skb
= dev_alloc_skb(pskb
->len
);
568 PRINT_WARN("%s Out of memory in netiucv_unpack_skb\n",
570 IUCV_DBF_TEXT(data
, 2,
571 "Out of memory in netiucv_unpack_skb\n");
572 privptr
->stats
.rx_dropped
++;
575 memcpy(skb_put(skb
, pskb
->len
), pskb
->data
, pskb
->len
);
576 skb
->mac
.raw
= skb
->data
;
577 skb
->dev
= pskb
->dev
;
578 skb
->protocol
= pskb
->protocol
;
579 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
581 * Since receiving is always initiated from a tasklet (in iucv.c),
582 * we must use netif_rx_ni() instead of netif_rx()
585 dev
->last_rx
= jiffies
;
586 privptr
->stats
.rx_packets
++;
587 privptr
->stats
.rx_bytes
+= skb
->len
;
588 skb_pull(pskb
, header
->next
);
589 skb_put(pskb
, NETIUCV_HDRLEN
);
594 conn_action_rx(fsm_instance
*fi
, int event
, void *arg
)
596 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
597 struct iucv_connection
*conn
= ev
->conn
;
598 iucv_MessagePending
*eib
= (iucv_MessagePending
*)ev
->data
;
599 struct netiucv_priv
*privptr
=(struct netiucv_priv
*)conn
->netdev
->priv
;
601 __u32 msglen
= eib
->ln1msg2
.ipbfln1f
;
604 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
607 /* FRITZ: How to tell iucv LL to drop the msg? */
608 PRINT_WARN("Received data for unlinked connection\n");
609 IUCV_DBF_TEXT(data
, 2,
610 "Received data for unlinked connection\n");
613 if (msglen
> conn
->max_buffsize
) {
614 /* FRITZ: How to tell iucv LL to drop the msg? */
615 privptr
->stats
.rx_dropped
++;
616 PRINT_WARN("msglen %d > max_buffsize %d\n",
617 msglen
, conn
->max_buffsize
);
618 IUCV_DBF_TEXT_(data
, 2, "msglen %d > max_buffsize %d\n",
619 msglen
, conn
->max_buffsize
);
622 conn
->rx_buff
->data
= conn
->rx_buff
->tail
= conn
->rx_buff
->head
;
623 conn
->rx_buff
->len
= 0;
624 rc
= iucv_receive(conn
->pathid
, eib
->ipmsgid
, eib
->iptrgcls
,
625 conn
->rx_buff
->data
, msglen
, NULL
, NULL
, NULL
);
626 if (rc
|| msglen
< 5) {
627 privptr
->stats
.rx_errors
++;
628 PRINT_WARN("iucv_receive returned %08x\n", rc
);
629 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_receive\n", rc
);
632 netiucv_unpack_skb(conn
, conn
->rx_buff
);
636 conn_action_txdone(fsm_instance
*fi
, int event
, void *arg
)
638 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
639 struct iucv_connection
*conn
= ev
->conn
;
640 iucv_MessageComplete
*eib
= (iucv_MessageComplete
*)ev
->data
;
641 struct netiucv_priv
*privptr
= NULL
;
642 /* Shut up, gcc! skb is always below 2G. */
643 __u32 single_flag
= eib
->ipmsgtag
;
646 __u32 stat_maxcq
= 0;
648 unsigned long saveflags
;
651 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
653 if (conn
&& conn
->netdev
&& conn
->netdev
->priv
)
654 privptr
= (struct netiucv_priv
*)conn
->netdev
->priv
;
655 conn
->prof
.tx_pending
--;
657 if ((skb
= skb_dequeue(&conn
->commit_queue
))) {
658 atomic_dec(&skb
->users
);
659 dev_kfree_skb_any(skb
);
661 privptr
->stats
.tx_packets
++;
662 privptr
->stats
.tx_bytes
+=
663 (skb
->len
- NETIUCV_HDRLEN
668 conn
->tx_buff
->data
= conn
->tx_buff
->tail
= conn
->tx_buff
->head
;
669 conn
->tx_buff
->len
= 0;
670 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
671 while ((skb
= skb_dequeue(&conn
->collect_queue
))) {
672 header
.next
= conn
->tx_buff
->len
+ skb
->len
+ NETIUCV_HDRLEN
;
673 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
675 memcpy(skb_put(conn
->tx_buff
, skb
->len
), skb
->data
, skb
->len
);
679 atomic_dec(&skb
->users
);
680 dev_kfree_skb_any(skb
);
682 if (conn
->collect_len
> conn
->prof
.maxmulti
)
683 conn
->prof
.maxmulti
= conn
->collect_len
;
684 conn
->collect_len
= 0;
685 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
686 if (conn
->tx_buff
->len
) {
690 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
693 conn
->prof
.send_stamp
= xtime
;
694 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0, 0, 0,
695 conn
->tx_buff
->data
, conn
->tx_buff
->len
);
696 conn
->prof
.doios_multi
++;
697 conn
->prof
.txlen
+= conn
->tx_buff
->len
;
698 conn
->prof
.tx_pending
++;
699 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
700 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
702 conn
->prof
.tx_pending
--;
703 fsm_newstate(fi
, CONN_STATE_IDLE
);
705 privptr
->stats
.tx_errors
+= txpackets
;
706 PRINT_WARN("iucv_send returned %08x\n", rc
);
707 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
710 privptr
->stats
.tx_packets
+= txpackets
;
711 privptr
->stats
.tx_bytes
+= txbytes
;
713 if (stat_maxcq
> conn
->prof
.maxcqueue
)
714 conn
->prof
.maxcqueue
= stat_maxcq
;
717 fsm_newstate(fi
, CONN_STATE_IDLE
);
721 conn_action_connaccept(fsm_instance
*fi
, int event
, void *arg
)
723 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
724 struct iucv_connection
*conn
= ev
->conn
;
725 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
726 struct net_device
*netdev
= conn
->netdev
;
727 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
732 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
734 rc
= iucv_accept(eib
->ippathid
, NETIUCV_QUEUELEN_DEFAULT
, udata
, 0,
735 conn
->handle
, conn
, NULL
, &msglimit
);
737 PRINT_WARN("%s: IUCV accept failed with error %d\n",
739 IUCV_DBF_TEXT_(setup
, 2, "rc %d from iucv_accept", rc
);
742 fsm_newstate(fi
, CONN_STATE_IDLE
);
743 conn
->pathid
= eib
->ippathid
;
744 netdev
->tx_queue_len
= msglimit
;
745 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
749 conn_action_connreject(fsm_instance
*fi
, int event
, void *arg
)
751 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
752 struct iucv_connection
*conn
= ev
->conn
;
753 struct net_device
*netdev
= conn
->netdev
;
754 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
757 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
759 iucv_sever(eib
->ippathid
, udata
);
760 if (eib
->ippathid
!= conn
->pathid
) {
761 PRINT_INFO("%s: IR Connection Pending; "
762 "pathid %d does not match original pathid %d\n",
763 netdev
->name
, eib
->ippathid
, conn
->pathid
);
764 IUCV_DBF_TEXT_(data
, 2,
765 "connreject: IR pathid %d, conn. pathid %d\n",
766 eib
->ippathid
, conn
->pathid
);
767 iucv_sever(conn
->pathid
, udata
);
772 conn_action_connack(fsm_instance
*fi
, int event
, void *arg
)
774 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
775 struct iucv_connection
*conn
= ev
->conn
;
776 iucv_ConnectionComplete
*eib
= (iucv_ConnectionComplete
*)ev
->data
;
777 struct net_device
*netdev
= conn
->netdev
;
778 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
780 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
782 fsm_deltimer(&conn
->timer
);
783 fsm_newstate(fi
, CONN_STATE_IDLE
);
784 if (eib
->ippathid
!= conn
->pathid
) {
785 PRINT_INFO("%s: IR Connection Complete; "
786 "pathid %d does not match original pathid %d\n",
787 netdev
->name
, eib
->ippathid
, conn
->pathid
);
788 IUCV_DBF_TEXT_(data
, 2,
789 "connack: IR pathid %d, conn. pathid %d\n",
790 eib
->ippathid
, conn
->pathid
);
791 conn
->pathid
= eib
->ippathid
;
793 netdev
->tx_queue_len
= eib
->ipmsglim
;
794 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
798 conn_action_conntimsev(fsm_instance
*fi
, int event
, void *arg
)
800 struct iucv_connection
*conn
= (struct iucv_connection
*)arg
;
803 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
805 fsm_deltimer(&conn
->timer
);
806 iucv_sever(conn
->pathid
, udata
);
807 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
811 conn_action_connsever(fsm_instance
*fi
, int event
, void *arg
)
813 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
814 struct iucv_connection
*conn
= ev
->conn
;
815 struct net_device
*netdev
= conn
->netdev
;
816 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
819 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
821 fsm_deltimer(&conn
->timer
);
822 iucv_sever(conn
->pathid
, udata
);
823 PRINT_INFO("%s: Remote dropped connection\n", netdev
->name
);
824 IUCV_DBF_TEXT(data
, 2,
825 "conn_action_connsever: Remote dropped connection\n");
826 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
827 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
831 conn_action_start(fsm_instance
*fi
, int event
, void *arg
)
833 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
834 struct iucv_connection
*conn
= ev
->conn
;
838 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
841 IUCV_DBF_TEXT(trace
, 5, "calling iucv_register_program\n");
843 iucv_register_program(iucvMagic
, conn
->userid
,
846 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
848 fsm_newstate(fi
, CONN_STATE_REGERR
);
850 IUCV_DBF_TEXT(setup
, 2,
851 "NULL from iucv_register_program\n");
855 PRINT_DEBUG("%s('%s'): registered successfully\n",
856 conn
->netdev
->name
, conn
->userid
);
859 PRINT_DEBUG("%s('%s'): connecting ...\n",
860 conn
->netdev
->name
, conn
->userid
);
862 /* We must set the state before calling iucv_connect because the callback
863 * handler could be called at any point after the connection request is
866 fsm_newstate(fi
, CONN_STATE_SETUPWAIT
);
867 rc
= iucv_connect(&(conn
->pathid
), NETIUCV_QUEUELEN_DEFAULT
, iucvMagic
,
868 conn
->userid
, iucv_host
, 0, NULL
, &msglimit
,
872 conn
->netdev
->tx_queue_len
= msglimit
;
873 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
874 CONN_EVENT_TIMER
, conn
);
877 PRINT_INFO("%s: User %s is currently not available.\n",
879 netiucv_printname(conn
->userid
));
880 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
883 PRINT_INFO("%s: User %s is currently not ready.\n",
885 netiucv_printname(conn
->userid
));
886 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
889 PRINT_WARN("%s: Too many IUCV connections.\n",
891 fsm_newstate(fi
, CONN_STATE_CONNERR
);
895 "%s: User %s has too many IUCV connections.\n",
897 netiucv_printname(conn
->userid
));
898 fsm_newstate(fi
, CONN_STATE_CONNERR
);
902 "%s: No IUCV authorization in CP directory.\n",
904 fsm_newstate(fi
, CONN_STATE_CONNERR
);
907 PRINT_WARN("%s: iucv_connect returned error %d\n",
908 conn
->netdev
->name
, rc
);
909 fsm_newstate(fi
, CONN_STATE_CONNERR
);
912 IUCV_DBF_TEXT_(setup
, 5, "iucv_connect rc is %d\n", rc
);
913 IUCV_DBF_TEXT(trace
, 5, "calling iucv_unregister_program\n");
914 iucv_unregister_program(conn
->handle
);
919 netiucv_purge_skb_queue(struct sk_buff_head
*q
)
923 while ((skb
= skb_dequeue(q
))) {
924 atomic_dec(&skb
->users
);
925 dev_kfree_skb_any(skb
);
930 conn_action_stop(fsm_instance
*fi
, int event
, void *arg
)
932 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
933 struct iucv_connection
*conn
= ev
->conn
;
934 struct net_device
*netdev
= conn
->netdev
;
935 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
937 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
939 fsm_deltimer(&conn
->timer
);
940 fsm_newstate(fi
, CONN_STATE_STOPPED
);
941 netiucv_purge_skb_queue(&conn
->collect_queue
);
943 IUCV_DBF_TEXT(trace
, 5, "calling iucv_unregister_program\n");
944 iucv_unregister_program(conn
->handle
);
946 netiucv_purge_skb_queue(&conn
->commit_queue
);
947 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
951 conn_action_inval(fsm_instance
*fi
, int event
, void *arg
)
953 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
954 struct iucv_connection
*conn
= ev
->conn
;
955 struct net_device
*netdev
= conn
->netdev
;
957 PRINT_WARN("%s: Cannot connect without username\n",
959 IUCV_DBF_TEXT(data
, 2, "conn_action_inval called\n");
962 static const fsm_node conn_fsm
[] = {
963 { CONN_STATE_INVALID
, CONN_EVENT_START
, conn_action_inval
},
964 { CONN_STATE_STOPPED
, CONN_EVENT_START
, conn_action_start
},
966 { CONN_STATE_STOPPED
, CONN_EVENT_STOP
, conn_action_stop
},
967 { CONN_STATE_STARTWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
968 { CONN_STATE_SETUPWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
969 { CONN_STATE_IDLE
, CONN_EVENT_STOP
, conn_action_stop
},
970 { CONN_STATE_TX
, CONN_EVENT_STOP
, conn_action_stop
},
971 { CONN_STATE_REGERR
, CONN_EVENT_STOP
, conn_action_stop
},
972 { CONN_STATE_CONNERR
, CONN_EVENT_STOP
, conn_action_stop
},
974 { CONN_STATE_STOPPED
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
975 { CONN_STATE_STARTWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
976 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
977 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
978 { CONN_STATE_TX
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
980 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_ACK
, conn_action_connack
},
981 { CONN_STATE_SETUPWAIT
, CONN_EVENT_TIMER
, conn_action_conntimsev
},
983 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
984 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
985 { CONN_STATE_TX
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
987 { CONN_STATE_IDLE
, CONN_EVENT_RX
, conn_action_rx
},
988 { CONN_STATE_TX
, CONN_EVENT_RX
, conn_action_rx
},
990 { CONN_STATE_TX
, CONN_EVENT_TXDONE
, conn_action_txdone
},
991 { CONN_STATE_IDLE
, CONN_EVENT_TXDONE
, conn_action_txdone
},
994 static const int CONN_FSM_LEN
= sizeof(conn_fsm
) / sizeof(fsm_node
);
998 * Actions for interface - statemachine.
999 *****************************************************************************/
1002 * Startup connection by sending CONN_EVENT_START to it.
1004 * @param fi An instance of an interface statemachine.
1005 * @param event The event, just happened.
1006 * @param arg Generic pointer, casted from struct net_device * upon call.
1009 dev_action_start(fsm_instance
*fi
, int event
, void *arg
)
1011 struct net_device
*dev
= (struct net_device
*)arg
;
1012 struct netiucv_priv
*privptr
= dev
->priv
;
1013 struct iucv_event ev
;
1015 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1017 ev
.conn
= privptr
->conn
;
1018 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1019 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, &ev
);
1023 * Shutdown connection by sending CONN_EVENT_STOP to it.
1025 * @param fi An instance of an interface statemachine.
1026 * @param event The event, just happened.
1027 * @param arg Generic pointer, casted from struct net_device * upon call.
1030 dev_action_stop(fsm_instance
*fi
, int event
, void *arg
)
1032 struct net_device
*dev
= (struct net_device
*)arg
;
1033 struct netiucv_priv
*privptr
= dev
->priv
;
1034 struct iucv_event ev
;
1036 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1038 ev
.conn
= privptr
->conn
;
1040 fsm_newstate(fi
, DEV_STATE_STOPWAIT
);
1041 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_STOP
, &ev
);
1045 * Called from connection statemachine
1046 * when a connection is up and running.
1048 * @param fi An instance of an interface statemachine.
1049 * @param event The event, just happened.
1050 * @param arg Generic pointer, casted from struct net_device * upon call.
1053 dev_action_connup(fsm_instance
*fi
, int event
, void *arg
)
1055 struct net_device
*dev
= (struct net_device
*)arg
;
1056 struct netiucv_priv
*privptr
= dev
->priv
;
1058 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1060 switch (fsm_getstate(fi
)) {
1061 case DEV_STATE_STARTWAIT
:
1062 fsm_newstate(fi
, DEV_STATE_RUNNING
);
1063 PRINT_INFO("%s: connected with remote side %s\n",
1064 dev
->name
, privptr
->conn
->userid
);
1065 IUCV_DBF_TEXT(setup
, 3,
1066 "connection is up and running\n");
1068 case DEV_STATE_STOPWAIT
:
1070 "%s: got connection UP event during shutdown!\n",
1072 IUCV_DBF_TEXT(data
, 2,
1073 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1079 * Called from connection statemachine
1080 * when a connection has been shutdown.
1082 * @param fi An instance of an interface statemachine.
1083 * @param event The event, just happened.
1084 * @param arg Generic pointer, casted from struct net_device * upon call.
1087 dev_action_conndown(fsm_instance
*fi
, int event
, void *arg
)
1089 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1091 switch (fsm_getstate(fi
)) {
1092 case DEV_STATE_RUNNING
:
1093 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1095 case DEV_STATE_STOPWAIT
:
1096 fsm_newstate(fi
, DEV_STATE_STOPPED
);
1097 IUCV_DBF_TEXT(setup
, 3, "connection is down\n");
1102 static const fsm_node dev_fsm
[] = {
1103 { DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
1105 { DEV_STATE_STOPWAIT
, DEV_EVENT_START
, dev_action_start
},
1106 { DEV_STATE_STOPWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1108 { DEV_STATE_STARTWAIT
, DEV_EVENT_STOP
, dev_action_stop
},
1109 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONUP
, dev_action_connup
},
1111 { DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
1112 { DEV_STATE_RUNNING
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1113 { DEV_STATE_RUNNING
, DEV_EVENT_CONUP
, fsm_action_nop
},
1116 static const int DEV_FSM_LEN
= sizeof(dev_fsm
) / sizeof(fsm_node
);
1119 * Transmit a packet.
1120 * This is a helper function for netiucv_tx().
1122 * @param conn Connection to be used for sending.
1123 * @param skb Pointer to struct sk_buff of packet to send.
1124 * The linklevel header has already been set up
1127 * @return 0 on success, -ERRNO on failure. (Never fails.)
1130 netiucv_transmit_skb(struct iucv_connection
*conn
, struct sk_buff
*skb
) {
1131 unsigned long saveflags
;
1135 if (fsm_getstate(conn
->fsm
) != CONN_STATE_IDLE
) {
1136 int l
= skb
->len
+ NETIUCV_HDRLEN
;
1138 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
1139 if (conn
->collect_len
+ l
>
1140 (conn
->max_buffsize
- NETIUCV_HDRLEN
)) {
1142 IUCV_DBF_TEXT(data
, 2,
1143 "EBUSY from netiucv_transmit_skb\n");
1145 atomic_inc(&skb
->users
);
1146 skb_queue_tail(&conn
->collect_queue
, skb
);
1147 conn
->collect_len
+= l
;
1149 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
1151 struct sk_buff
*nskb
= skb
;
1153 * Copy the skb to a new allocated skb in lowmem only if the
1154 * data is located above 2G in memory or tailroom is < 2.
1157 ((unsigned long)(skb
->tail
+ NETIUCV_HDRLEN
)) >> 31;
1159 if (hi
|| (skb_tailroom(skb
) < 2)) {
1160 nskb
= alloc_skb(skb
->len
+ NETIUCV_HDRLEN
+
1161 NETIUCV_HDRLEN
, GFP_ATOMIC
| GFP_DMA
);
1163 PRINT_WARN("%s: Could not allocate tx_skb\n",
1164 conn
->netdev
->name
);
1165 IUCV_DBF_TEXT(data
, 2, "alloc_skb failed\n");
1169 skb_reserve(nskb
, NETIUCV_HDRLEN
);
1170 memcpy(skb_put(nskb
, skb
->len
),
1171 skb
->data
, skb
->len
);
1176 * skb now is below 2G and has enough room. Add headers.
1178 header
.next
= nskb
->len
+ NETIUCV_HDRLEN
;
1179 memcpy(skb_push(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1181 memcpy(skb_put(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1183 fsm_newstate(conn
->fsm
, CONN_STATE_TX
);
1184 conn
->prof
.send_stamp
= xtime
;
1186 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0, 1 /* single_flag */,
1187 0, nskb
->data
, nskb
->len
);
1188 /* Shut up, gcc! nskb is always below 2G. */
1189 conn
->prof
.doios_single
++;
1190 conn
->prof
.txlen
+= skb
->len
;
1191 conn
->prof
.tx_pending
++;
1192 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
1193 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
1195 struct netiucv_priv
*privptr
;
1196 fsm_newstate(conn
->fsm
, CONN_STATE_IDLE
);
1197 conn
->prof
.tx_pending
--;
1198 privptr
= (struct netiucv_priv
*)conn
->netdev
->priv
;
1200 privptr
->stats
.tx_errors
++;
1202 dev_kfree_skb(nskb
);
1205 * Remove our headers. They get added
1206 * again on retransmit.
1208 skb_pull(skb
, NETIUCV_HDRLEN
);
1209 skb_trim(skb
, skb
->len
- NETIUCV_HDRLEN
);
1211 PRINT_WARN("iucv_send returned %08x\n", rc
);
1212 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
1216 atomic_inc(&nskb
->users
);
1217 skb_queue_tail(&conn
->commit_queue
, nskb
);
1225 * Interface API for upper network layers
1226 *****************************************************************************/
1229 * Open an interface.
1230 * Called from generic network layer when ifconfig up is run.
1232 * @param dev Pointer to interface struct.
1234 * @return 0 on success, -ERRNO on failure. (Never fails.)
1237 netiucv_open(struct net_device
*dev
) {
1238 fsm_event(((struct netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_START
,dev
);
1243 * Close an interface.
1244 * Called from generic network layer when ifconfig down is run.
1246 * @param dev Pointer to interface struct.
1248 * @return 0 on success, -ERRNO on failure. (Never fails.)
1251 netiucv_close(struct net_device
*dev
) {
1252 fsm_event(((struct netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_STOP
, dev
);
1257 * Start transmission of a packet.
1258 * Called from generic network device layer.
1260 * @param skb Pointer to buffer containing the packet.
1261 * @param dev Pointer to interface struct.
1263 * @return 0 if packet consumed, !0 if packet rejected.
1264 * Note: If we return !0, then the packet is free'd by
1265 * the generic network layer.
1267 static int netiucv_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1270 struct netiucv_priv
*privptr
= dev
->priv
;
1272 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1274 * Some sanity checks ...
1277 PRINT_WARN("%s: NULL sk_buff passed\n", dev
->name
);
1278 IUCV_DBF_TEXT(data
, 2, "netiucv_tx: skb is NULL\n");
1279 privptr
->stats
.tx_dropped
++;
1282 if (skb_headroom(skb
) < NETIUCV_HDRLEN
) {
1283 PRINT_WARN("%s: Got sk_buff with head room < %ld bytes\n",
1284 dev
->name
, NETIUCV_HDRLEN
);
1285 IUCV_DBF_TEXT(data
, 2,
1286 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1288 privptr
->stats
.tx_dropped
++;
1293 * If connection is not running, try to restart it
1294 * and throw away packet.
1296 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
1297 fsm_event(privptr
->fsm
, DEV_EVENT_START
, dev
);
1299 privptr
->stats
.tx_dropped
++;
1300 privptr
->stats
.tx_errors
++;
1301 privptr
->stats
.tx_carrier_errors
++;
1305 if (netiucv_test_and_set_busy(dev
)) {
1306 IUCV_DBF_TEXT(data
, 2, "EBUSY from netiucv_tx\n");
1309 dev
->trans_start
= jiffies
;
1310 if (netiucv_transmit_skb(privptr
->conn
, skb
))
1312 netiucv_clear_busy(dev
);
1317 * Returns interface statistics of a device.
1319 * @param dev Pointer to interface struct.
1321 * @return Pointer to stats struct of this interface.
1323 static struct net_device_stats
*
1324 netiucv_stats (struct net_device
* dev
)
1326 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1327 return &((struct netiucv_priv
*)dev
->priv
)->stats
;
1331 * Sets MTU of an interface.
1333 * @param dev Pointer to interface struct.
1334 * @param new_mtu The new MTU to use for this interface.
1336 * @return 0 on success, -EINVAL if MTU is out of valid range.
1337 * (valid range is 576 .. NETIUCV_MTU_MAX).
1340 netiucv_change_mtu (struct net_device
* dev
, int new_mtu
)
1342 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1343 if ((new_mtu
< 576) || (new_mtu
> NETIUCV_MTU_MAX
)) {
1344 IUCV_DBF_TEXT(setup
, 2, "given MTU out of valid range\n");
1352 * attributes in sysfs
1353 *****************************************************************************/
1356 user_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1358 struct netiucv_priv
*priv
= dev
->driver_data
;
1360 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1361 return sprintf(buf
, "%s\n", netiucv_printname(priv
->conn
->userid
));
1365 user_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1367 struct netiucv_priv
*priv
= dev
->driver_data
;
1368 struct net_device
*ndev
= priv
->conn
->netdev
;
1374 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1376 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count
);
1377 IUCV_DBF_TEXT_(setup
, 2,
1378 "%d is length of username\n", (int)count
);
1382 tmp
= strsep((char **) &buf
, "\n");
1383 for (i
=0, p
=tmp
; i
<8 && *p
; i
++, p
++) {
1384 if (isalnum(*p
) || (*p
== '$'))
1386 else if (*p
== '\n') {
1387 /* trailing lf, grr */
1390 PRINT_WARN("netiucv: Invalid char %c in username!\n",
1392 IUCV_DBF_TEXT_(setup
, 2,
1393 "username: invalid character %c\n",
1399 username
[i
++] = ' ';
1402 if (memcmp(username
, priv
->conn
->userid
, 8)) {
1403 /* username changed */
1404 if (ndev
->flags
& (IFF_UP
| IFF_RUNNING
)) {
1406 "netiucv: device %s active, connected to %s\n",
1407 dev
->bus_id
, priv
->conn
->userid
);
1408 PRINT_WARN("netiucv: user cannot be updated\n");
1409 IUCV_DBF_TEXT(setup
, 2, "user_write: device active\n");
1413 memcpy(priv
->conn
->userid
, username
, 9);
1419 static DEVICE_ATTR(user
, 0644, user_show
, user_write
);
1422 buffer_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1424 struct netiucv_priv
*priv
= dev
->driver_data
;
1426 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1427 return sprintf(buf
, "%d\n", priv
->conn
->max_buffsize
);
1431 buffer_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1433 struct netiucv_priv
*priv
= dev
->driver_data
;
1434 struct net_device
*ndev
= priv
->conn
->netdev
;
1438 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1442 bs1
= simple_strtoul(buf
, &e
, 0);
1444 if (e
&& (!isspace(*e
))) {
1445 PRINT_WARN("netiucv: Invalid character in buffer!\n");
1446 IUCV_DBF_TEXT_(setup
, 2, "buffer_write: invalid char %c\n", *e
);
1449 if (bs1
> NETIUCV_BUFSIZE_MAX
) {
1450 PRINT_WARN("netiucv: Given buffer size %d too large.\n",
1452 IUCV_DBF_TEXT_(setup
, 2,
1453 "buffer_write: buffer size %d too large\n",
1457 if ((ndev
->flags
& IFF_RUNNING
) &&
1458 (bs1
< (ndev
->mtu
+ NETIUCV_HDRLEN
+ 2))) {
1459 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1461 IUCV_DBF_TEXT_(setup
, 2,
1462 "buffer_write: buffer size %d too small\n",
1466 if (bs1
< (576 + NETIUCV_HDRLEN
+ NETIUCV_HDRLEN
)) {
1467 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1469 IUCV_DBF_TEXT_(setup
, 2,
1470 "buffer_write: buffer size %d too small\n",
1475 priv
->conn
->max_buffsize
= bs1
;
1476 if (!(ndev
->flags
& IFF_RUNNING
))
1477 ndev
->mtu
= bs1
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
;
1483 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
1486 dev_fsm_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1488 struct netiucv_priv
*priv
= dev
->driver_data
;
1490 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1491 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->fsm
));
1494 static DEVICE_ATTR(device_fsm_state
, 0444, dev_fsm_show
, NULL
);
1497 conn_fsm_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1499 struct netiucv_priv
*priv
= dev
->driver_data
;
1501 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1502 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->conn
->fsm
));
1505 static DEVICE_ATTR(connection_fsm_state
, 0444, conn_fsm_show
, NULL
);
1508 maxmulti_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1510 struct netiucv_priv
*priv
= dev
->driver_data
;
1512 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1513 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxmulti
);
1517 maxmulti_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1519 struct netiucv_priv
*priv
= dev
->driver_data
;
1521 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1522 priv
->conn
->prof
.maxmulti
= 0;
1526 static DEVICE_ATTR(max_tx_buffer_used
, 0644, maxmulti_show
, maxmulti_write
);
1529 maxcq_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1531 struct netiucv_priv
*priv
= dev
->driver_data
;
1533 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1534 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxcqueue
);
1538 maxcq_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1540 struct netiucv_priv
*priv
= dev
->driver_data
;
1542 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1543 priv
->conn
->prof
.maxcqueue
= 0;
1547 static DEVICE_ATTR(max_chained_skbs
, 0644, maxcq_show
, maxcq_write
);
1550 sdoio_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1552 struct netiucv_priv
*priv
= dev
->driver_data
;
1554 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1555 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_single
);
1559 sdoio_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1561 struct netiucv_priv
*priv
= dev
->driver_data
;
1563 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1564 priv
->conn
->prof
.doios_single
= 0;
1568 static DEVICE_ATTR(tx_single_write_ops
, 0644, sdoio_show
, sdoio_write
);
1571 mdoio_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1573 struct netiucv_priv
*priv
= dev
->driver_data
;
1575 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1576 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_multi
);
1580 mdoio_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1582 struct netiucv_priv
*priv
= dev
->driver_data
;
1584 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1585 priv
->conn
->prof
.doios_multi
= 0;
1589 static DEVICE_ATTR(tx_multi_write_ops
, 0644, mdoio_show
, mdoio_write
);
1592 txlen_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1594 struct netiucv_priv
*priv
= dev
->driver_data
;
1596 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1597 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.txlen
);
1601 txlen_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1603 struct netiucv_priv
*priv
= dev
->driver_data
;
1605 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1606 priv
->conn
->prof
.txlen
= 0;
1610 static DEVICE_ATTR(netto_bytes
, 0644, txlen_show
, txlen_write
);
1613 txtime_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1615 struct netiucv_priv
*priv
= dev
->driver_data
;
1617 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1618 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_time
);
1622 txtime_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1624 struct netiucv_priv
*priv
= dev
->driver_data
;
1626 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1627 priv
->conn
->prof
.tx_time
= 0;
1631 static DEVICE_ATTR(max_tx_io_time
, 0644, txtime_show
, txtime_write
);
1634 txpend_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1636 struct netiucv_priv
*priv
= dev
->driver_data
;
1638 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1639 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_pending
);
1643 txpend_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1645 struct netiucv_priv
*priv
= dev
->driver_data
;
1647 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1648 priv
->conn
->prof
.tx_pending
= 0;
1652 static DEVICE_ATTR(tx_pending
, 0644, txpend_show
, txpend_write
);
1655 txmpnd_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1657 struct netiucv_priv
*priv
= dev
->driver_data
;
1659 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1660 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_max_pending
);
1664 txmpnd_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1666 struct netiucv_priv
*priv
= dev
->driver_data
;
1668 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1669 priv
->conn
->prof
.tx_max_pending
= 0;
1673 static DEVICE_ATTR(tx_max_pending
, 0644, txmpnd_show
, txmpnd_write
);
1675 static struct attribute
*netiucv_attrs
[] = {
1676 &dev_attr_buffer
.attr
,
1677 &dev_attr_user
.attr
,
1681 static struct attribute_group netiucv_attr_group
= {
1682 .attrs
= netiucv_attrs
,
1685 static struct attribute
*netiucv_stat_attrs
[] = {
1686 &dev_attr_device_fsm_state
.attr
,
1687 &dev_attr_connection_fsm_state
.attr
,
1688 &dev_attr_max_tx_buffer_used
.attr
,
1689 &dev_attr_max_chained_skbs
.attr
,
1690 &dev_attr_tx_single_write_ops
.attr
,
1691 &dev_attr_tx_multi_write_ops
.attr
,
1692 &dev_attr_netto_bytes
.attr
,
1693 &dev_attr_max_tx_io_time
.attr
,
1694 &dev_attr_tx_pending
.attr
,
1695 &dev_attr_tx_max_pending
.attr
,
1699 static struct attribute_group netiucv_stat_attr_group
= {
1701 .attrs
= netiucv_stat_attrs
,
1705 netiucv_add_files(struct device
*dev
)
1709 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1710 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_attr_group
);
1713 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1715 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1720 netiucv_remove_files(struct device
*dev
)
1722 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1723 sysfs_remove_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1724 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1728 netiucv_register_device(struct net_device
*ndev
)
1730 struct netiucv_priv
*priv
= ndev
->priv
;
1731 struct device
*dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1735 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1738 snprintf(dev
->bus_id
, BUS_ID_SIZE
, "net%s", ndev
->name
);
1739 dev
->bus
= &iucv_bus
;
1740 dev
->parent
= iucv_root
;
1742 * The release function could be called after the
1743 * module has been unloaded. It's _only_ task is to
1744 * free the struct. Therefore, we specify kfree()
1745 * directly here. (Probably a little bit obfuscating
1746 * but legitime ...).
1748 dev
->release
= (void (*)(struct device
*))kfree
;
1749 dev
->driver
= &netiucv_driver
;
1753 ret
= device_register(dev
);
1757 ret
= netiucv_add_files(dev
);
1761 dev
->driver_data
= priv
;
1765 device_unregister(dev
);
1770 netiucv_unregister_device(struct device
*dev
)
1772 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1773 netiucv_remove_files(dev
);
1774 device_unregister(dev
);
1778 * Allocate and initialize a new connection structure.
1779 * Add it to the list of netiucv connections;
1781 static struct iucv_connection
*
1782 netiucv_new_connection(struct net_device
*dev
, char *username
)
1784 struct iucv_connection
**clist
= &iucv_connections
;
1785 struct iucv_connection
*conn
=
1786 kzalloc(sizeof(struct iucv_connection
), GFP_KERNEL
);
1789 skb_queue_head_init(&conn
->collect_queue
);
1790 skb_queue_head_init(&conn
->commit_queue
);
1791 conn
->max_buffsize
= NETIUCV_BUFSIZE_DEFAULT
;
1794 conn
->rx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
,
1795 GFP_KERNEL
| GFP_DMA
);
1796 if (!conn
->rx_buff
) {
1800 conn
->tx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
,
1801 GFP_KERNEL
| GFP_DMA
);
1802 if (!conn
->tx_buff
) {
1803 kfree_skb(conn
->rx_buff
);
1807 conn
->fsm
= init_fsm("netiucvconn", conn_state_names
,
1808 conn_event_names
, NR_CONN_STATES
,
1809 NR_CONN_EVENTS
, conn_fsm
, CONN_FSM_LEN
,
1812 kfree_skb(conn
->tx_buff
);
1813 kfree_skb(conn
->rx_buff
);
1817 fsm_settimer(conn
->fsm
, &conn
->timer
);
1818 fsm_newstate(conn
->fsm
, CONN_STATE_INVALID
);
1821 memcpy(conn
->userid
, username
, 9);
1822 fsm_newstate(conn
->fsm
, CONN_STATE_STOPPED
);
1825 conn
->next
= *clist
;
1832 * Release a connection structure and remove it from the
1833 * list of netiucv connections.
1836 netiucv_remove_connection(struct iucv_connection
*conn
)
1838 struct iucv_connection
**clist
= &iucv_connections
;
1840 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1844 if (*clist
== conn
) {
1845 *clist
= conn
->next
;
1847 iucv_unregister_program(conn
->handle
);
1848 conn
->handle
= NULL
;
1850 fsm_deltimer(&conn
->timer
);
1851 kfree_fsm(conn
->fsm
);
1852 kfree_skb(conn
->rx_buff
);
1853 kfree_skb(conn
->tx_buff
);
1856 clist
= &((*clist
)->next
);
1861 * Release everything of a net device.
1864 netiucv_free_netdevice(struct net_device
*dev
)
1866 struct netiucv_priv
*privptr
;
1868 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1873 privptr
= (struct netiucv_priv
*)dev
->priv
;
1876 netiucv_remove_connection(privptr
->conn
);
1878 kfree_fsm(privptr
->fsm
);
1879 privptr
->conn
= NULL
; privptr
->fsm
= NULL
;
1880 /* privptr gets freed by free_netdev() */
1886 * Initialize a net device. (Called from kernel in alloc_netdev())
1889 netiucv_setup_netdevice(struct net_device
*dev
)
1891 memset(dev
->priv
, 0, sizeof(struct netiucv_priv
));
1893 dev
->mtu
= NETIUCV_MTU_DEFAULT
;
1894 dev
->hard_start_xmit
= netiucv_tx
;
1895 dev
->open
= netiucv_open
;
1896 dev
->stop
= netiucv_close
;
1897 dev
->get_stats
= netiucv_stats
;
1898 dev
->change_mtu
= netiucv_change_mtu
;
1899 dev
->destructor
= netiucv_free_netdevice
;
1900 dev
->hard_header_len
= NETIUCV_HDRLEN
;
1902 dev
->type
= ARPHRD_SLIP
;
1903 dev
->tx_queue_len
= NETIUCV_QUEUELEN_DEFAULT
;
1904 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
1905 SET_MODULE_OWNER(dev
);
1909 * Allocate and initialize everything of a net device.
1911 static struct net_device
*
1912 netiucv_init_netdevice(char *username
)
1914 struct netiucv_priv
*privptr
;
1915 struct net_device
*dev
;
1917 dev
= alloc_netdev(sizeof(struct netiucv_priv
), "iucv%d",
1918 netiucv_setup_netdevice
);
1921 if (dev_alloc_name(dev
, dev
->name
) < 0) {
1926 privptr
= (struct netiucv_priv
*)dev
->priv
;
1927 privptr
->fsm
= init_fsm("netiucvdev", dev_state_names
,
1928 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
1929 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
1930 if (!privptr
->fsm
) {
1934 privptr
->conn
= netiucv_new_connection(dev
, username
);
1935 if (!privptr
->conn
) {
1936 kfree_fsm(privptr
->fsm
);
1938 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_new_connection\n");
1941 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
1947 conn_write(struct device_driver
*drv
, const char *buf
, size_t count
)
1952 struct net_device
*dev
;
1954 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1956 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count
);
1957 IUCV_DBF_TEXT(setup
, 2, "conn_write: too long\n");
1961 for (i
=0, p
=(char *)buf
; i
<8 && *p
; i
++, p
++) {
1962 if (isalnum(*p
) || (*p
== '$'))
1964 else if (*p
== '\n') {
1965 /* trailing lf, grr */
1968 PRINT_WARN("netiucv: Invalid character in username!\n");
1969 IUCV_DBF_TEXT_(setup
, 2,
1970 "conn_write: invalid character %c\n", *p
);
1975 username
[i
++] = ' ';
1977 dev
= netiucv_init_netdevice(username
);
1980 "netiucv: Could not allocate network device structure "
1981 "for user '%s'\n", netiucv_printname(username
));
1982 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_init_netdevice\n");
1986 if ((ret
= netiucv_register_device(dev
))) {
1987 IUCV_DBF_TEXT_(setup
, 2,
1988 "ret %d from netiucv_register_device\n", ret
);
1994 (struct device
*)((struct netiucv_priv
*)dev
->priv
)->dev
);
1996 if ((ret
= register_netdev(dev
))) {
1997 netiucv_unregister_device((struct device
*)
1998 ((struct netiucv_priv
*)dev
->priv
)->dev
);
2002 PRINT_INFO("%s: '%s'\n", dev
->name
, netiucv_printname(username
));
2007 PRINT_WARN("netiucv: Could not register '%s'\n", dev
->name
);
2008 IUCV_DBF_TEXT(setup
, 2, "conn_write: could not register\n");
2009 netiucv_free_netdevice(dev
);
2013 DRIVER_ATTR(connection
, 0200, NULL
, conn_write
);
2016 remove_write (struct device_driver
*drv
, const char *buf
, size_t count
)
2018 struct iucv_connection
**clist
= &iucv_connections
;
2019 struct net_device
*ndev
;
2020 struct netiucv_priv
*priv
;
2022 char name
[IFNAMSIZ
];
2026 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2028 if (count
>= IFNAMSIZ
)
2031 for (i
=0, p
=(char *)buf
; i
<count
&& *p
; i
++, p
++) {
2032 if ((*p
== '\n') | (*p
== ' ')) {
2033 /* trailing lf, grr */
2042 ndev
= (*clist
)->netdev
;
2043 priv
= (struct netiucv_priv
*)ndev
->priv
;
2046 if (strncmp(name
, ndev
->name
, count
)) {
2047 clist
= &((*clist
)->next
);
2050 if (ndev
->flags
& (IFF_UP
| IFF_RUNNING
)) {
2052 "netiucv: net device %s active with peer %s\n",
2053 ndev
->name
, priv
->conn
->userid
);
2054 PRINT_WARN("netiucv: %s cannot be removed\n",
2056 IUCV_DBF_TEXT(data
, 2, "remove_write: still active\n");
2059 unregister_netdev(ndev
);
2060 netiucv_unregister_device(dev
);
2063 PRINT_WARN("netiucv: net device %s unknown\n", name
);
2064 IUCV_DBF_TEXT(data
, 2, "remove_write: unknown device\n");
2068 DRIVER_ATTR(remove
, 0200, NULL
, remove_write
);
2071 netiucv_banner(void)
2073 PRINT_INFO("NETIUCV driver initialized\n");
2079 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2080 while (iucv_connections
) {
2081 struct net_device
*ndev
= iucv_connections
->netdev
;
2082 struct netiucv_priv
*priv
= (struct netiucv_priv
*)ndev
->priv
;
2083 struct device
*dev
= priv
->dev
;
2085 unregister_netdev(ndev
);
2086 netiucv_unregister_device(dev
);
2089 driver_remove_file(&netiucv_driver
, &driver_attr_connection
);
2090 driver_remove_file(&netiucv_driver
, &driver_attr_remove
);
2091 driver_unregister(&netiucv_driver
);
2092 iucv_unregister_dbf_views();
2094 PRINT_INFO("NETIUCV driver unloaded\n");
2103 ret
= iucv_register_dbf_views();
2105 PRINT_WARN("netiucv_init failed, "
2106 "iucv_register_dbf_views rc = %d\n", ret
);
2109 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2110 ret
= driver_register(&netiucv_driver
);
2112 PRINT_ERR("NETIUCV: failed to register driver.\n");
2113 IUCV_DBF_TEXT_(setup
, 2, "ret %d from driver_register\n", ret
);
2114 iucv_unregister_dbf_views();
2118 /* Add entry for specifying connections. */
2119 ret
= driver_create_file(&netiucv_driver
, &driver_attr_connection
);
2121 ret
= driver_create_file(&netiucv_driver
, &driver_attr_remove
);
2124 PRINT_ERR("NETIUCV: failed to add driver attribute.\n");
2125 IUCV_DBF_TEXT_(setup
, 2, "ret %d from driver_create_file\n", ret
);
2126 driver_unregister(&netiucv_driver
);
2127 iucv_unregister_dbf_views();
2132 module_init(netiucv_init
);
2133 module_exit(netiucv_exit
);
2134 MODULE_LICENSE("GPL");