2 * $Id: netiucv.c,v 1.69 2006/01/12 14:33:09 cohuck Exp $
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
9 * Sysfs integration and all bugs therein by Cornelia Huck
10 * (cornelia.huck@de.ibm.com)
13 * the source of the original IUCV driver by:
14 * Stefan Hegewald <hegewald@de.ibm.com>
15 * Hartmut Penner <hpenner@de.ibm.com>
16 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
17 * Martin Schwidefsky (schwidefsky@de.ibm.com)
18 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2, or (at your option)
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 * RELEASE-TAG: IUCV network driver $Revision: 1.69 $
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/kernel.h>
43 #include <linux/slab.h>
44 #include <linux/errno.h>
45 #include <linux/types.h>
46 #include <linux/interrupt.h>
47 #include <linux/timer.h>
48 #include <linux/sched.h>
49 #include <linux/bitops.h>
51 #include <linux/signal.h>
52 #include <linux/string.h>
53 #include <linux/device.h>
56 #include <linux/if_arp.h>
57 #include <linux/tcp.h>
58 #include <linux/skbuff.h>
59 #include <linux/ctype.h>
63 #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");
73 #define PRINTK_HEADER " iucv: " /* for debugging */
75 static struct device_driver netiucv_driver
= {
81 * Per connection profiling data
83 struct connection_profile
{
84 unsigned long maxmulti
;
85 unsigned long maxcqueue
;
86 unsigned long doios_single
;
87 unsigned long doios_multi
;
89 unsigned long tx_time
;
90 struct timespec send_stamp
;
91 unsigned long tx_pending
;
92 unsigned long tx_max_pending
;
96 * Representation of one iucv connection
98 struct iucv_connection
{
99 struct iucv_connection
*next
;
100 iucv_handle_t handle
;
102 struct sk_buff
*rx_buff
;
103 struct sk_buff
*tx_buff
;
104 struct sk_buff_head collect_queue
;
105 struct sk_buff_head commit_queue
;
106 spinlock_t collect_lock
;
111 struct net_device
*netdev
;
112 struct connection_profile prof
;
117 * Linked list of all connection structs.
119 static struct iucv_connection
*iucv_connections
;
122 * Representation of event-data for the
123 * connection state machine.
126 struct iucv_connection
*conn
;
131 * Private part of the network device structure
133 struct netiucv_priv
{
134 struct net_device_stats stats
;
137 struct iucv_connection
*conn
;
142 * Link level header for a packet.
144 typedef struct ll_header_t
{
148 #define NETIUCV_HDRLEN (sizeof(ll_header))
149 #define NETIUCV_BUFSIZE_MAX 32768
150 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
151 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
152 #define NETIUCV_MTU_DEFAULT 9216
153 #define NETIUCV_QUEUELEN_DEFAULT 50
154 #define NETIUCV_TIMEOUT_5SEC 5000
157 * Compatibility macros for busy handling
158 * of network devices.
160 static __inline__
void netiucv_clear_busy(struct net_device
*dev
)
162 clear_bit(0, &(((struct netiucv_priv
*)dev
->priv
)->tbusy
));
163 netif_wake_queue(dev
);
166 static __inline__
int netiucv_test_and_set_busy(struct net_device
*dev
)
168 netif_stop_queue(dev
);
169 return test_and_set_bit(0, &((struct netiucv_priv
*)dev
->priv
)->tbusy
);
172 static __u8 iucv_host
[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
173 static __u8 iucvMagic
[16] = {
174 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
175 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
179 * This mask means the 16-byte IUCV "magic" and the origin userid must
180 * match exactly as specified in order to give connection_pending()
183 static __u8 netiucv_mask
[] = {
184 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
185 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
186 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
190 * Convert an iucv userId to its printable
191 * form (strip whitespace at end).
193 * @param An iucv userId
195 * @returns The printable string (static data!!)
197 static __inline__
char *
198 netiucv_printname(char *name
)
202 memcpy(tmp
, name
, 8);
204 while (*p
&& (!isspace(*p
)))
211 * States of the interface statemachine.
219 * MUST be always the last element!!
224 static const char *dev_state_names
[] = {
232 * Events of the interface statemachine.
240 * MUST be always the last element!!
245 static const char *dev_event_names
[] = {
253 * Events of the connection statemachine
257 * Events, representing callbacks from
258 * lowlevel iucv layer)
269 * Events, representing errors return codes from
270 * calls to lowlevel iucv layer
274 * Event, representing timer expiry.
279 * Events, representing commands from upper levels.
285 * MUST be always the last element!!
290 static const char *conn_event_names
[] = {
291 "Remote connection request",
292 "Remote connection acknowledge",
293 "Remote connection reject",
294 "Connection suspended",
295 "Connection resumed",
306 * States of the connection statemachine.
310 * Connection not assigned to any device,
311 * initial state, invalid
316 * Userid assigned but not operating
321 * Connection registered,
322 * no connection request sent yet,
323 * no connection request received
325 CONN_STATE_STARTWAIT
,
328 * Connection registered and connection request sent,
329 * no acknowledge and no connection request received yet.
331 CONN_STATE_SETUPWAIT
,
334 * Connection up and running idle
339 * Data sent, awaiting CONN_EVENT_TXDONE
344 * Error during registration.
349 * Error during registration.
354 * MUST be always the last element!!
359 static const char *conn_state_names
[] = {
367 "Registration error",
373 * Debug Facility Stuff
375 static debug_info_t
*iucv_dbf_setup
= NULL
;
376 static debug_info_t
*iucv_dbf_data
= NULL
;
377 static debug_info_t
*iucv_dbf_trace
= NULL
;
379 DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf
);
382 iucv_unregister_dbf_views(void)
385 debug_unregister(iucv_dbf_setup
);
387 debug_unregister(iucv_dbf_data
);
389 debug_unregister(iucv_dbf_trace
);
392 iucv_register_dbf_views(void)
394 iucv_dbf_setup
= debug_register(IUCV_DBF_SETUP_NAME
,
395 IUCV_DBF_SETUP_PAGES
,
396 IUCV_DBF_SETUP_NR_AREAS
,
398 iucv_dbf_data
= debug_register(IUCV_DBF_DATA_NAME
,
400 IUCV_DBF_DATA_NR_AREAS
,
402 iucv_dbf_trace
= debug_register(IUCV_DBF_TRACE_NAME
,
403 IUCV_DBF_TRACE_PAGES
,
404 IUCV_DBF_TRACE_NR_AREAS
,
407 if ((iucv_dbf_setup
== NULL
) || (iucv_dbf_data
== NULL
) ||
408 (iucv_dbf_trace
== NULL
)) {
409 iucv_unregister_dbf_views();
412 debug_register_view(iucv_dbf_setup
, &debug_hex_ascii_view
);
413 debug_set_level(iucv_dbf_setup
, IUCV_DBF_SETUP_LEVEL
);
415 debug_register_view(iucv_dbf_data
, &debug_hex_ascii_view
);
416 debug_set_level(iucv_dbf_data
, IUCV_DBF_DATA_LEVEL
);
418 debug_register_view(iucv_dbf_trace
, &debug_hex_ascii_view
);
419 debug_set_level(iucv_dbf_trace
, IUCV_DBF_TRACE_LEVEL
);
425 * Callback-wrappers, called from lowlevel iucv layer.
426 *****************************************************************************/
429 netiucv_callback_rx(iucv_MessagePending
*eib
, void *pgm_data
)
431 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
432 struct iucv_event ev
;
435 ev
.data
= (void *)eib
;
437 fsm_event(conn
->fsm
, CONN_EVENT_RX
, &ev
);
441 netiucv_callback_txdone(iucv_MessageComplete
*eib
, void *pgm_data
)
443 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
444 struct iucv_event ev
;
447 ev
.data
= (void *)eib
;
448 fsm_event(conn
->fsm
, CONN_EVENT_TXDONE
, &ev
);
452 netiucv_callback_connack(iucv_ConnectionComplete
*eib
, void *pgm_data
)
454 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
455 struct iucv_event ev
;
458 ev
.data
= (void *)eib
;
459 fsm_event(conn
->fsm
, CONN_EVENT_CONN_ACK
, &ev
);
463 netiucv_callback_connreq(iucv_ConnectionPending
*eib
, void *pgm_data
)
465 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
466 struct iucv_event ev
;
469 ev
.data
= (void *)eib
;
470 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REQ
, &ev
);
474 netiucv_callback_connrej(iucv_ConnectionSevered
*eib
, void *pgm_data
)
476 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
477 struct iucv_event ev
;
480 ev
.data
= (void *)eib
;
481 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REJ
, &ev
);
485 netiucv_callback_connsusp(iucv_ConnectionQuiesced
*eib
, void *pgm_data
)
487 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
488 struct iucv_event ev
;
491 ev
.data
= (void *)eib
;
492 fsm_event(conn
->fsm
, CONN_EVENT_CONN_SUS
, &ev
);
496 netiucv_callback_connres(iucv_ConnectionResumed
*eib
, void *pgm_data
)
498 struct iucv_connection
*conn
= (struct iucv_connection
*)pgm_data
;
499 struct iucv_event ev
;
502 ev
.data
= (void *)eib
;
503 fsm_event(conn
->fsm
, CONN_EVENT_CONN_RES
, &ev
);
506 static iucv_interrupt_ops_t netiucv_ops
= {
507 .ConnectionPending
= netiucv_callback_connreq
,
508 .ConnectionComplete
= netiucv_callback_connack
,
509 .ConnectionSevered
= netiucv_callback_connrej
,
510 .ConnectionQuiesced
= netiucv_callback_connsusp
,
511 .ConnectionResumed
= netiucv_callback_connres
,
512 .MessagePending
= netiucv_callback_rx
,
513 .MessageComplete
= netiucv_callback_txdone
517 * Dummy NOP action for all statemachines
520 fsm_action_nop(fsm_instance
*fi
, int event
, void *arg
)
525 * Actions of the connection statemachine
526 *****************************************************************************/
529 * Helper function for conn_action_rx()
530 * Unpack a just received skb and hand it over to
533 * @param conn The connection where this skb has been received.
534 * @param pskb The received skb.
536 //static __inline__ void
538 netiucv_unpack_skb(struct iucv_connection
*conn
, struct sk_buff
*pskb
)
540 struct net_device
*dev
= conn
->netdev
;
541 struct netiucv_priv
*privptr
= dev
->priv
;
544 skb_put(pskb
, NETIUCV_HDRLEN
);
546 pskb
->ip_summed
= CHECKSUM_NONE
;
547 pskb
->protocol
= ntohs(ETH_P_IP
);
551 ll_header
*header
= (ll_header
*)pskb
->data
;
556 skb_pull(pskb
, NETIUCV_HDRLEN
);
557 header
->next
-= offset
;
558 offset
+= header
->next
;
559 header
->next
-= NETIUCV_HDRLEN
;
560 if (skb_tailroom(pskb
) < header
->next
) {
561 PRINT_WARN("%s: Illegal next field in iucv header: "
563 dev
->name
, header
->next
, skb_tailroom(pskb
));
564 IUCV_DBF_TEXT_(data
, 2, "Illegal next field: %d > %d\n",
565 header
->next
, skb_tailroom(pskb
));
568 skb_put(pskb
, header
->next
);
569 pskb
->mac
.raw
= pskb
->data
;
570 skb
= dev_alloc_skb(pskb
->len
);
572 PRINT_WARN("%s Out of memory in netiucv_unpack_skb\n",
574 IUCV_DBF_TEXT(data
, 2,
575 "Out of memory in netiucv_unpack_skb\n");
576 privptr
->stats
.rx_dropped
++;
579 memcpy(skb_put(skb
, pskb
->len
), pskb
->data
, pskb
->len
);
580 skb
->mac
.raw
= skb
->data
;
581 skb
->dev
= pskb
->dev
;
582 skb
->protocol
= pskb
->protocol
;
583 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
585 * Since receiving is always initiated from a tasklet (in iucv.c),
586 * we must use netif_rx_ni() instead of netif_rx()
589 dev
->last_rx
= jiffies
;
590 privptr
->stats
.rx_packets
++;
591 privptr
->stats
.rx_bytes
+= skb
->len
;
592 skb_pull(pskb
, header
->next
);
593 skb_put(pskb
, NETIUCV_HDRLEN
);
598 conn_action_rx(fsm_instance
*fi
, int event
, void *arg
)
600 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
601 struct iucv_connection
*conn
= ev
->conn
;
602 iucv_MessagePending
*eib
= (iucv_MessagePending
*)ev
->data
;
603 struct netiucv_priv
*privptr
=(struct netiucv_priv
*)conn
->netdev
->priv
;
605 __u32 msglen
= eib
->ln1msg2
.ipbfln1f
;
608 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
611 /* FRITZ: How to tell iucv LL to drop the msg? */
612 PRINT_WARN("Received data for unlinked connection\n");
613 IUCV_DBF_TEXT(data
, 2,
614 "Received data for unlinked connection\n");
617 if (msglen
> conn
->max_buffsize
) {
618 /* FRITZ: How to tell iucv LL to drop the msg? */
619 privptr
->stats
.rx_dropped
++;
620 PRINT_WARN("msglen %d > max_buffsize %d\n",
621 msglen
, conn
->max_buffsize
);
622 IUCV_DBF_TEXT_(data
, 2, "msglen %d > max_buffsize %d\n",
623 msglen
, conn
->max_buffsize
);
626 conn
->rx_buff
->data
= conn
->rx_buff
->tail
= conn
->rx_buff
->head
;
627 conn
->rx_buff
->len
= 0;
628 rc
= iucv_receive(conn
->pathid
, eib
->ipmsgid
, eib
->iptrgcls
,
629 conn
->rx_buff
->data
, msglen
, NULL
, NULL
, NULL
);
630 if (rc
|| msglen
< 5) {
631 privptr
->stats
.rx_errors
++;
632 PRINT_WARN("iucv_receive returned %08x\n", rc
);
633 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_receive\n", rc
);
636 netiucv_unpack_skb(conn
, conn
->rx_buff
);
640 conn_action_txdone(fsm_instance
*fi
, int event
, void *arg
)
642 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
643 struct iucv_connection
*conn
= ev
->conn
;
644 iucv_MessageComplete
*eib
= (iucv_MessageComplete
*)ev
->data
;
645 struct netiucv_priv
*privptr
= NULL
;
646 /* Shut up, gcc! skb is always below 2G. */
647 __u32 single_flag
= eib
->ipmsgtag
;
650 __u32 stat_maxcq
= 0;
652 unsigned long saveflags
;
655 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
657 if (conn
&& conn
->netdev
&& conn
->netdev
->priv
)
658 privptr
= (struct netiucv_priv
*)conn
->netdev
->priv
;
659 conn
->prof
.tx_pending
--;
661 if ((skb
= skb_dequeue(&conn
->commit_queue
))) {
662 atomic_dec(&skb
->users
);
663 dev_kfree_skb_any(skb
);
665 privptr
->stats
.tx_packets
++;
666 privptr
->stats
.tx_bytes
+=
667 (skb
->len
- NETIUCV_HDRLEN
672 conn
->tx_buff
->data
= conn
->tx_buff
->tail
= conn
->tx_buff
->head
;
673 conn
->tx_buff
->len
= 0;
674 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
675 while ((skb
= skb_dequeue(&conn
->collect_queue
))) {
676 header
.next
= conn
->tx_buff
->len
+ skb
->len
+ NETIUCV_HDRLEN
;
677 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
679 memcpy(skb_put(conn
->tx_buff
, skb
->len
), skb
->data
, skb
->len
);
683 atomic_dec(&skb
->users
);
684 dev_kfree_skb_any(skb
);
686 if (conn
->collect_len
> conn
->prof
.maxmulti
)
687 conn
->prof
.maxmulti
= conn
->collect_len
;
688 conn
->collect_len
= 0;
689 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
690 if (conn
->tx_buff
->len
) {
694 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
697 conn
->prof
.send_stamp
= xtime
;
698 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0, 0, 0,
699 conn
->tx_buff
->data
, conn
->tx_buff
->len
);
700 conn
->prof
.doios_multi
++;
701 conn
->prof
.txlen
+= conn
->tx_buff
->len
;
702 conn
->prof
.tx_pending
++;
703 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
704 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
706 conn
->prof
.tx_pending
--;
707 fsm_newstate(fi
, CONN_STATE_IDLE
);
709 privptr
->stats
.tx_errors
+= txpackets
;
710 PRINT_WARN("iucv_send returned %08x\n", rc
);
711 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
714 privptr
->stats
.tx_packets
+= txpackets
;
715 privptr
->stats
.tx_bytes
+= txbytes
;
717 if (stat_maxcq
> conn
->prof
.maxcqueue
)
718 conn
->prof
.maxcqueue
= stat_maxcq
;
721 fsm_newstate(fi
, CONN_STATE_IDLE
);
725 conn_action_connaccept(fsm_instance
*fi
, int event
, void *arg
)
727 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
728 struct iucv_connection
*conn
= ev
->conn
;
729 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
730 struct net_device
*netdev
= conn
->netdev
;
731 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
736 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
738 rc
= iucv_accept(eib
->ippathid
, NETIUCV_QUEUELEN_DEFAULT
, udata
, 0,
739 conn
->handle
, conn
, NULL
, &msglimit
);
741 PRINT_WARN("%s: IUCV accept failed with error %d\n",
743 IUCV_DBF_TEXT_(setup
, 2, "rc %d from iucv_accept", rc
);
746 fsm_newstate(fi
, CONN_STATE_IDLE
);
747 conn
->pathid
= eib
->ippathid
;
748 netdev
->tx_queue_len
= msglimit
;
749 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
753 conn_action_connreject(fsm_instance
*fi
, int event
, void *arg
)
755 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
756 struct iucv_connection
*conn
= ev
->conn
;
757 struct net_device
*netdev
= conn
->netdev
;
758 iucv_ConnectionPending
*eib
= (iucv_ConnectionPending
*)ev
->data
;
761 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
763 iucv_sever(eib
->ippathid
, udata
);
764 if (eib
->ippathid
!= conn
->pathid
) {
765 PRINT_INFO("%s: IR Connection Pending; "
766 "pathid %d does not match original pathid %d\n",
767 netdev
->name
, eib
->ippathid
, conn
->pathid
);
768 IUCV_DBF_TEXT_(data
, 2,
769 "connreject: IR pathid %d, conn. pathid %d\n",
770 eib
->ippathid
, conn
->pathid
);
771 iucv_sever(conn
->pathid
, udata
);
776 conn_action_connack(fsm_instance
*fi
, int event
, void *arg
)
778 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
779 struct iucv_connection
*conn
= ev
->conn
;
780 iucv_ConnectionComplete
*eib
= (iucv_ConnectionComplete
*)ev
->data
;
781 struct net_device
*netdev
= conn
->netdev
;
782 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
784 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
786 fsm_deltimer(&conn
->timer
);
787 fsm_newstate(fi
, CONN_STATE_IDLE
);
788 if (eib
->ippathid
!= conn
->pathid
) {
789 PRINT_INFO("%s: IR Connection Complete; "
790 "pathid %d does not match original pathid %d\n",
791 netdev
->name
, eib
->ippathid
, conn
->pathid
);
792 IUCV_DBF_TEXT_(data
, 2,
793 "connack: IR pathid %d, conn. pathid %d\n",
794 eib
->ippathid
, conn
->pathid
);
795 conn
->pathid
= eib
->ippathid
;
797 netdev
->tx_queue_len
= eib
->ipmsglim
;
798 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
802 conn_action_conntimsev(fsm_instance
*fi
, int event
, void *arg
)
804 struct iucv_connection
*conn
= (struct iucv_connection
*)arg
;
807 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
809 fsm_deltimer(&conn
->timer
);
810 iucv_sever(conn
->pathid
, udata
);
811 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
815 conn_action_connsever(fsm_instance
*fi
, int event
, void *arg
)
817 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
818 struct iucv_connection
*conn
= ev
->conn
;
819 struct net_device
*netdev
= conn
->netdev
;
820 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
823 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
825 fsm_deltimer(&conn
->timer
);
826 iucv_sever(conn
->pathid
, udata
);
827 PRINT_INFO("%s: Remote dropped connection\n", netdev
->name
);
828 IUCV_DBF_TEXT(data
, 2,
829 "conn_action_connsever: Remote dropped connection\n");
830 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
831 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
835 conn_action_start(fsm_instance
*fi
, int event
, void *arg
)
837 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
838 struct iucv_connection
*conn
= ev
->conn
;
842 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
845 IUCV_DBF_TEXT(trace
, 5, "calling iucv_register_program\n");
847 iucv_register_program(iucvMagic
, conn
->userid
,
850 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
852 fsm_newstate(fi
, CONN_STATE_REGERR
);
854 IUCV_DBF_TEXT(setup
, 2,
855 "NULL from iucv_register_program\n");
859 PRINT_DEBUG("%s('%s'): registered successfully\n",
860 conn
->netdev
->name
, conn
->userid
);
863 PRINT_DEBUG("%s('%s'): connecting ...\n",
864 conn
->netdev
->name
, conn
->userid
);
866 /* We must set the state before calling iucv_connect because the callback
867 * handler could be called at any point after the connection request is
870 fsm_newstate(fi
, CONN_STATE_SETUPWAIT
);
871 rc
= iucv_connect(&(conn
->pathid
), NETIUCV_QUEUELEN_DEFAULT
, iucvMagic
,
872 conn
->userid
, iucv_host
, 0, NULL
, &msglimit
,
876 conn
->netdev
->tx_queue_len
= msglimit
;
877 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
878 CONN_EVENT_TIMER
, conn
);
881 PRINT_INFO("%s: User %s is currently not available.\n",
883 netiucv_printname(conn
->userid
));
884 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
887 PRINT_INFO("%s: User %s is currently not ready.\n",
889 netiucv_printname(conn
->userid
));
890 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
893 PRINT_WARN("%s: Too many IUCV connections.\n",
895 fsm_newstate(fi
, CONN_STATE_CONNERR
);
899 "%s: User %s has too many IUCV connections.\n",
901 netiucv_printname(conn
->userid
));
902 fsm_newstate(fi
, CONN_STATE_CONNERR
);
906 "%s: No IUCV authorization in CP directory.\n",
908 fsm_newstate(fi
, CONN_STATE_CONNERR
);
911 PRINT_WARN("%s: iucv_connect returned error %d\n",
912 conn
->netdev
->name
, rc
);
913 fsm_newstate(fi
, CONN_STATE_CONNERR
);
916 IUCV_DBF_TEXT_(setup
, 5, "iucv_connect rc is %d\n", rc
);
917 IUCV_DBF_TEXT(trace
, 5, "calling iucv_unregister_program\n");
918 iucv_unregister_program(conn
->handle
);
923 netiucv_purge_skb_queue(struct sk_buff_head
*q
)
927 while ((skb
= skb_dequeue(q
))) {
928 atomic_dec(&skb
->users
);
929 dev_kfree_skb_any(skb
);
934 conn_action_stop(fsm_instance
*fi
, int event
, void *arg
)
936 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
937 struct iucv_connection
*conn
= ev
->conn
;
938 struct net_device
*netdev
= conn
->netdev
;
939 struct netiucv_priv
*privptr
= (struct netiucv_priv
*)netdev
->priv
;
941 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
943 fsm_deltimer(&conn
->timer
);
944 fsm_newstate(fi
, CONN_STATE_STOPPED
);
945 netiucv_purge_skb_queue(&conn
->collect_queue
);
947 IUCV_DBF_TEXT(trace
, 5, "calling iucv_unregister_program\n");
948 iucv_unregister_program(conn
->handle
);
950 netiucv_purge_skb_queue(&conn
->commit_queue
);
951 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
955 conn_action_inval(fsm_instance
*fi
, int event
, void *arg
)
957 struct iucv_event
*ev
= (struct iucv_event
*)arg
;
958 struct iucv_connection
*conn
= ev
->conn
;
959 struct net_device
*netdev
= conn
->netdev
;
961 PRINT_WARN("%s: Cannot connect without username\n",
963 IUCV_DBF_TEXT(data
, 2, "conn_action_inval called\n");
966 static const fsm_node conn_fsm
[] = {
967 { CONN_STATE_INVALID
, CONN_EVENT_START
, conn_action_inval
},
968 { CONN_STATE_STOPPED
, CONN_EVENT_START
, conn_action_start
},
970 { CONN_STATE_STOPPED
, CONN_EVENT_STOP
, conn_action_stop
},
971 { CONN_STATE_STARTWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
972 { CONN_STATE_SETUPWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
973 { CONN_STATE_IDLE
, CONN_EVENT_STOP
, conn_action_stop
},
974 { CONN_STATE_TX
, CONN_EVENT_STOP
, conn_action_stop
},
975 { CONN_STATE_REGERR
, CONN_EVENT_STOP
, conn_action_stop
},
976 { CONN_STATE_CONNERR
, CONN_EVENT_STOP
, conn_action_stop
},
978 { CONN_STATE_STOPPED
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
979 { CONN_STATE_STARTWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
980 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
981 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
982 { CONN_STATE_TX
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
984 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_ACK
, conn_action_connack
},
985 { CONN_STATE_SETUPWAIT
, CONN_EVENT_TIMER
, conn_action_conntimsev
},
987 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
988 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
989 { CONN_STATE_TX
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
991 { CONN_STATE_IDLE
, CONN_EVENT_RX
, conn_action_rx
},
992 { CONN_STATE_TX
, CONN_EVENT_RX
, conn_action_rx
},
994 { CONN_STATE_TX
, CONN_EVENT_TXDONE
, conn_action_txdone
},
995 { CONN_STATE_IDLE
, CONN_EVENT_TXDONE
, conn_action_txdone
},
998 static const int CONN_FSM_LEN
= sizeof(conn_fsm
) / sizeof(fsm_node
);
1002 * Actions for interface - statemachine.
1003 *****************************************************************************/
1006 * Startup connection by sending CONN_EVENT_START to it.
1008 * @param fi An instance of an interface statemachine.
1009 * @param event The event, just happened.
1010 * @param arg Generic pointer, casted from struct net_device * upon call.
1013 dev_action_start(fsm_instance
*fi
, int event
, void *arg
)
1015 struct net_device
*dev
= (struct net_device
*)arg
;
1016 struct netiucv_priv
*privptr
= dev
->priv
;
1017 struct iucv_event ev
;
1019 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1021 ev
.conn
= privptr
->conn
;
1022 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1023 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, &ev
);
1027 * Shutdown connection by sending CONN_EVENT_STOP to it.
1029 * @param fi An instance of an interface statemachine.
1030 * @param event The event, just happened.
1031 * @param arg Generic pointer, casted from struct net_device * upon call.
1034 dev_action_stop(fsm_instance
*fi
, int event
, void *arg
)
1036 struct net_device
*dev
= (struct net_device
*)arg
;
1037 struct netiucv_priv
*privptr
= dev
->priv
;
1038 struct iucv_event ev
;
1040 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1042 ev
.conn
= privptr
->conn
;
1044 fsm_newstate(fi
, DEV_STATE_STOPWAIT
);
1045 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_STOP
, &ev
);
1049 * Called from connection statemachine
1050 * when a connection is up and running.
1052 * @param fi An instance of an interface statemachine.
1053 * @param event The event, just happened.
1054 * @param arg Generic pointer, casted from struct net_device * upon call.
1057 dev_action_connup(fsm_instance
*fi
, int event
, void *arg
)
1059 struct net_device
*dev
= (struct net_device
*)arg
;
1060 struct netiucv_priv
*privptr
= dev
->priv
;
1062 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1064 switch (fsm_getstate(fi
)) {
1065 case DEV_STATE_STARTWAIT
:
1066 fsm_newstate(fi
, DEV_STATE_RUNNING
);
1067 PRINT_INFO("%s: connected with remote side %s\n",
1068 dev
->name
, privptr
->conn
->userid
);
1069 IUCV_DBF_TEXT(setup
, 3,
1070 "connection is up and running\n");
1072 case DEV_STATE_STOPWAIT
:
1074 "%s: got connection UP event during shutdown!\n",
1076 IUCV_DBF_TEXT(data
, 2,
1077 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1083 * Called from connection statemachine
1084 * when a connection has been shutdown.
1086 * @param fi An instance of an interface statemachine.
1087 * @param event The event, just happened.
1088 * @param arg Generic pointer, casted from struct net_device * upon call.
1091 dev_action_conndown(fsm_instance
*fi
, int event
, void *arg
)
1093 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1095 switch (fsm_getstate(fi
)) {
1096 case DEV_STATE_RUNNING
:
1097 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1099 case DEV_STATE_STOPWAIT
:
1100 fsm_newstate(fi
, DEV_STATE_STOPPED
);
1101 IUCV_DBF_TEXT(setup
, 3, "connection is down\n");
1106 static const fsm_node dev_fsm
[] = {
1107 { DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
1109 { DEV_STATE_STOPWAIT
, DEV_EVENT_START
, dev_action_start
},
1110 { DEV_STATE_STOPWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1112 { DEV_STATE_STARTWAIT
, DEV_EVENT_STOP
, dev_action_stop
},
1113 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONUP
, dev_action_connup
},
1115 { DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
1116 { DEV_STATE_RUNNING
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1117 { DEV_STATE_RUNNING
, DEV_EVENT_CONUP
, fsm_action_nop
},
1120 static const int DEV_FSM_LEN
= sizeof(dev_fsm
) / sizeof(fsm_node
);
1123 * Transmit a packet.
1124 * This is a helper function for netiucv_tx().
1126 * @param conn Connection to be used for sending.
1127 * @param skb Pointer to struct sk_buff of packet to send.
1128 * The linklevel header has already been set up
1131 * @return 0 on success, -ERRNO on failure. (Never fails.)
1134 netiucv_transmit_skb(struct iucv_connection
*conn
, struct sk_buff
*skb
) {
1135 unsigned long saveflags
;
1139 if (fsm_getstate(conn
->fsm
) != CONN_STATE_IDLE
) {
1140 int l
= skb
->len
+ NETIUCV_HDRLEN
;
1142 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
1143 if (conn
->collect_len
+ l
>
1144 (conn
->max_buffsize
- NETIUCV_HDRLEN
)) {
1146 IUCV_DBF_TEXT(data
, 2,
1147 "EBUSY from netiucv_transmit_skb\n");
1149 atomic_inc(&skb
->users
);
1150 skb_queue_tail(&conn
->collect_queue
, skb
);
1151 conn
->collect_len
+= l
;
1153 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
1155 struct sk_buff
*nskb
= skb
;
1157 * Copy the skb to a new allocated skb in lowmem only if the
1158 * data is located above 2G in memory or tailroom is < 2.
1161 ((unsigned long)(skb
->tail
+ NETIUCV_HDRLEN
)) >> 31;
1163 if (hi
|| (skb_tailroom(skb
) < 2)) {
1164 nskb
= alloc_skb(skb
->len
+ NETIUCV_HDRLEN
+
1165 NETIUCV_HDRLEN
, GFP_ATOMIC
| GFP_DMA
);
1167 PRINT_WARN("%s: Could not allocate tx_skb\n",
1168 conn
->netdev
->name
);
1169 IUCV_DBF_TEXT(data
, 2, "alloc_skb failed\n");
1173 skb_reserve(nskb
, NETIUCV_HDRLEN
);
1174 memcpy(skb_put(nskb
, skb
->len
),
1175 skb
->data
, skb
->len
);
1180 * skb now is below 2G and has enough room. Add headers.
1182 header
.next
= nskb
->len
+ NETIUCV_HDRLEN
;
1183 memcpy(skb_push(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1185 memcpy(skb_put(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1187 fsm_newstate(conn
->fsm
, CONN_STATE_TX
);
1188 conn
->prof
.send_stamp
= xtime
;
1190 rc
= iucv_send(conn
->pathid
, NULL
, 0, 0, 1 /* single_flag */,
1191 0, nskb
->data
, nskb
->len
);
1192 /* Shut up, gcc! nskb is always below 2G. */
1193 conn
->prof
.doios_single
++;
1194 conn
->prof
.txlen
+= skb
->len
;
1195 conn
->prof
.tx_pending
++;
1196 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
1197 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
1199 struct netiucv_priv
*privptr
;
1200 fsm_newstate(conn
->fsm
, CONN_STATE_IDLE
);
1201 conn
->prof
.tx_pending
--;
1202 privptr
= (struct netiucv_priv
*)conn
->netdev
->priv
;
1204 privptr
->stats
.tx_errors
++;
1206 dev_kfree_skb(nskb
);
1209 * Remove our headers. They get added
1210 * again on retransmit.
1212 skb_pull(skb
, NETIUCV_HDRLEN
);
1213 skb_trim(skb
, skb
->len
- NETIUCV_HDRLEN
);
1215 PRINT_WARN("iucv_send returned %08x\n", rc
);
1216 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
1220 atomic_inc(&nskb
->users
);
1221 skb_queue_tail(&conn
->commit_queue
, nskb
);
1229 * Interface API for upper network layers
1230 *****************************************************************************/
1233 * Open an interface.
1234 * Called from generic network layer when ifconfig up is run.
1236 * @param dev Pointer to interface struct.
1238 * @return 0 on success, -ERRNO on failure. (Never fails.)
1241 netiucv_open(struct net_device
*dev
) {
1242 fsm_event(((struct netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_START
,dev
);
1247 * Close an interface.
1248 * Called from generic network layer when ifconfig down is run.
1250 * @param dev Pointer to interface struct.
1252 * @return 0 on success, -ERRNO on failure. (Never fails.)
1255 netiucv_close(struct net_device
*dev
) {
1256 fsm_event(((struct netiucv_priv
*)dev
->priv
)->fsm
, DEV_EVENT_STOP
, dev
);
1261 * Start transmission of a packet.
1262 * Called from generic network device layer.
1264 * @param skb Pointer to buffer containing the packet.
1265 * @param dev Pointer to interface struct.
1267 * @return 0 if packet consumed, !0 if packet rejected.
1268 * Note: If we return !0, then the packet is free'd by
1269 * the generic network layer.
1271 static int netiucv_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1274 struct netiucv_priv
*privptr
= dev
->priv
;
1276 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1278 * Some sanity checks ...
1281 PRINT_WARN("%s: NULL sk_buff passed\n", dev
->name
);
1282 IUCV_DBF_TEXT(data
, 2, "netiucv_tx: skb is NULL\n");
1283 privptr
->stats
.tx_dropped
++;
1286 if (skb_headroom(skb
) < NETIUCV_HDRLEN
) {
1287 PRINT_WARN("%s: Got sk_buff with head room < %ld bytes\n",
1288 dev
->name
, NETIUCV_HDRLEN
);
1289 IUCV_DBF_TEXT(data
, 2,
1290 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1292 privptr
->stats
.tx_dropped
++;
1297 * If connection is not running, try to restart it
1298 * and throw away packet.
1300 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
1301 fsm_event(privptr
->fsm
, DEV_EVENT_START
, dev
);
1303 privptr
->stats
.tx_dropped
++;
1304 privptr
->stats
.tx_errors
++;
1305 privptr
->stats
.tx_carrier_errors
++;
1309 if (netiucv_test_and_set_busy(dev
)) {
1310 IUCV_DBF_TEXT(data
, 2, "EBUSY from netiucv_tx\n");
1313 dev
->trans_start
= jiffies
;
1314 if (netiucv_transmit_skb(privptr
->conn
, skb
))
1316 netiucv_clear_busy(dev
);
1321 * Returns interface statistics of a device.
1323 * @param dev Pointer to interface struct.
1325 * @return Pointer to stats struct of this interface.
1327 static struct net_device_stats
*
1328 netiucv_stats (struct net_device
* dev
)
1330 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1331 return &((struct netiucv_priv
*)dev
->priv
)->stats
;
1335 * Sets MTU of an interface.
1337 * @param dev Pointer to interface struct.
1338 * @param new_mtu The new MTU to use for this interface.
1340 * @return 0 on success, -EINVAL if MTU is out of valid range.
1341 * (valid range is 576 .. NETIUCV_MTU_MAX).
1344 netiucv_change_mtu (struct net_device
* dev
, int new_mtu
)
1346 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1347 if ((new_mtu
< 576) || (new_mtu
> NETIUCV_MTU_MAX
)) {
1348 IUCV_DBF_TEXT(setup
, 2, "given MTU out of valid range\n");
1356 * attributes in sysfs
1357 *****************************************************************************/
1360 user_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1362 struct netiucv_priv
*priv
= dev
->driver_data
;
1364 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1365 return sprintf(buf
, "%s\n", netiucv_printname(priv
->conn
->userid
));
1369 user_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1371 struct netiucv_priv
*priv
= dev
->driver_data
;
1372 struct net_device
*ndev
= priv
->conn
->netdev
;
1378 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1380 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count
);
1381 IUCV_DBF_TEXT_(setup
, 2,
1382 "%d is length of username\n", (int)count
);
1386 tmp
= strsep((char **) &buf
, "\n");
1387 for (i
=0, p
=tmp
; i
<8 && *p
; i
++, p
++) {
1388 if (isalnum(*p
) || (*p
== '$'))
1390 else if (*p
== '\n') {
1391 /* trailing lf, grr */
1394 PRINT_WARN("netiucv: Invalid char %c in username!\n",
1396 IUCV_DBF_TEXT_(setup
, 2,
1397 "username: invalid character %c\n",
1403 username
[i
++] = ' ';
1406 if (memcmp(username
, priv
->conn
->userid
, 8)) {
1407 /* username changed */
1408 if (ndev
->flags
& (IFF_UP
| IFF_RUNNING
)) {
1410 "netiucv: device %s active, connected to %s\n",
1411 dev
->bus_id
, priv
->conn
->userid
);
1412 PRINT_WARN("netiucv: user cannot be updated\n");
1413 IUCV_DBF_TEXT(setup
, 2, "user_write: device active\n");
1417 memcpy(priv
->conn
->userid
, username
, 9);
1423 static DEVICE_ATTR(user
, 0644, user_show
, user_write
);
1426 buffer_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1428 struct netiucv_priv
*priv
= dev
->driver_data
;
1430 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1431 return sprintf(buf
, "%d\n", priv
->conn
->max_buffsize
);
1435 buffer_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1437 struct netiucv_priv
*priv
= dev
->driver_data
;
1438 struct net_device
*ndev
= priv
->conn
->netdev
;
1442 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1446 bs1
= simple_strtoul(buf
, &e
, 0);
1448 if (e
&& (!isspace(*e
))) {
1449 PRINT_WARN("netiucv: Invalid character in buffer!\n");
1450 IUCV_DBF_TEXT_(setup
, 2, "buffer_write: invalid char %c\n", *e
);
1453 if (bs1
> NETIUCV_BUFSIZE_MAX
) {
1454 PRINT_WARN("netiucv: Given buffer size %d too large.\n",
1456 IUCV_DBF_TEXT_(setup
, 2,
1457 "buffer_write: buffer size %d too large\n",
1461 if ((ndev
->flags
& IFF_RUNNING
) &&
1462 (bs1
< (ndev
->mtu
+ NETIUCV_HDRLEN
+ 2))) {
1463 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1465 IUCV_DBF_TEXT_(setup
, 2,
1466 "buffer_write: buffer size %d too small\n",
1470 if (bs1
< (576 + NETIUCV_HDRLEN
+ NETIUCV_HDRLEN
)) {
1471 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1473 IUCV_DBF_TEXT_(setup
, 2,
1474 "buffer_write: buffer size %d too small\n",
1479 priv
->conn
->max_buffsize
= bs1
;
1480 if (!(ndev
->flags
& IFF_RUNNING
))
1481 ndev
->mtu
= bs1
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
;
1487 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
1490 dev_fsm_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1492 struct netiucv_priv
*priv
= dev
->driver_data
;
1494 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1495 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->fsm
));
1498 static DEVICE_ATTR(device_fsm_state
, 0444, dev_fsm_show
, NULL
);
1501 conn_fsm_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1503 struct netiucv_priv
*priv
= dev
->driver_data
;
1505 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1506 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->conn
->fsm
));
1509 static DEVICE_ATTR(connection_fsm_state
, 0444, conn_fsm_show
, NULL
);
1512 maxmulti_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1514 struct netiucv_priv
*priv
= dev
->driver_data
;
1516 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1517 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxmulti
);
1521 maxmulti_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1523 struct netiucv_priv
*priv
= dev
->driver_data
;
1525 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1526 priv
->conn
->prof
.maxmulti
= 0;
1530 static DEVICE_ATTR(max_tx_buffer_used
, 0644, maxmulti_show
, maxmulti_write
);
1533 maxcq_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1535 struct netiucv_priv
*priv
= dev
->driver_data
;
1537 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1538 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxcqueue
);
1542 maxcq_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1544 struct netiucv_priv
*priv
= dev
->driver_data
;
1546 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1547 priv
->conn
->prof
.maxcqueue
= 0;
1551 static DEVICE_ATTR(max_chained_skbs
, 0644, maxcq_show
, maxcq_write
);
1554 sdoio_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1556 struct netiucv_priv
*priv
= dev
->driver_data
;
1558 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1559 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_single
);
1563 sdoio_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1565 struct netiucv_priv
*priv
= dev
->driver_data
;
1567 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1568 priv
->conn
->prof
.doios_single
= 0;
1572 static DEVICE_ATTR(tx_single_write_ops
, 0644, sdoio_show
, sdoio_write
);
1575 mdoio_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1577 struct netiucv_priv
*priv
= dev
->driver_data
;
1579 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1580 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_multi
);
1584 mdoio_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1586 struct netiucv_priv
*priv
= dev
->driver_data
;
1588 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1589 priv
->conn
->prof
.doios_multi
= 0;
1593 static DEVICE_ATTR(tx_multi_write_ops
, 0644, mdoio_show
, mdoio_write
);
1596 txlen_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1598 struct netiucv_priv
*priv
= dev
->driver_data
;
1600 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1601 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.txlen
);
1605 txlen_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1607 struct netiucv_priv
*priv
= dev
->driver_data
;
1609 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1610 priv
->conn
->prof
.txlen
= 0;
1614 static DEVICE_ATTR(netto_bytes
, 0644, txlen_show
, txlen_write
);
1617 txtime_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1619 struct netiucv_priv
*priv
= dev
->driver_data
;
1621 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1622 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_time
);
1626 txtime_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1628 struct netiucv_priv
*priv
= dev
->driver_data
;
1630 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1631 priv
->conn
->prof
.tx_time
= 0;
1635 static DEVICE_ATTR(max_tx_io_time
, 0644, txtime_show
, txtime_write
);
1638 txpend_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1640 struct netiucv_priv
*priv
= dev
->driver_data
;
1642 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1643 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_pending
);
1647 txpend_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1649 struct netiucv_priv
*priv
= dev
->driver_data
;
1651 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1652 priv
->conn
->prof
.tx_pending
= 0;
1656 static DEVICE_ATTR(tx_pending
, 0644, txpend_show
, txpend_write
);
1659 txmpnd_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1661 struct netiucv_priv
*priv
= dev
->driver_data
;
1663 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1664 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_max_pending
);
1668 txmpnd_write (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1670 struct netiucv_priv
*priv
= dev
->driver_data
;
1672 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1673 priv
->conn
->prof
.tx_max_pending
= 0;
1677 static DEVICE_ATTR(tx_max_pending
, 0644, txmpnd_show
, txmpnd_write
);
1679 static struct attribute
*netiucv_attrs
[] = {
1680 &dev_attr_buffer
.attr
,
1681 &dev_attr_user
.attr
,
1685 static struct attribute_group netiucv_attr_group
= {
1686 .attrs
= netiucv_attrs
,
1689 static struct attribute
*netiucv_stat_attrs
[] = {
1690 &dev_attr_device_fsm_state
.attr
,
1691 &dev_attr_connection_fsm_state
.attr
,
1692 &dev_attr_max_tx_buffer_used
.attr
,
1693 &dev_attr_max_chained_skbs
.attr
,
1694 &dev_attr_tx_single_write_ops
.attr
,
1695 &dev_attr_tx_multi_write_ops
.attr
,
1696 &dev_attr_netto_bytes
.attr
,
1697 &dev_attr_max_tx_io_time
.attr
,
1698 &dev_attr_tx_pending
.attr
,
1699 &dev_attr_tx_max_pending
.attr
,
1703 static struct attribute_group netiucv_stat_attr_group
= {
1705 .attrs
= netiucv_stat_attrs
,
1709 netiucv_add_files(struct device
*dev
)
1713 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1714 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_attr_group
);
1717 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1719 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1724 netiucv_remove_files(struct device
*dev
)
1726 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1727 sysfs_remove_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1728 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1732 netiucv_register_device(struct net_device
*ndev
)
1734 struct netiucv_priv
*priv
= ndev
->priv
;
1735 struct device
*dev
= kmalloc(sizeof(struct device
), GFP_KERNEL
);
1739 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1742 memset(dev
, 0, sizeof(struct device
));
1743 snprintf(dev
->bus_id
, BUS_ID_SIZE
, "net%s", ndev
->name
);
1744 dev
->bus
= &iucv_bus
;
1745 dev
->parent
= iucv_root
;
1747 * The release function could be called after the
1748 * module has been unloaded. It's _only_ task is to
1749 * free the struct. Therefore, we specify kfree()
1750 * directly here. (Probably a little bit obfuscating
1751 * but legitime ...).
1753 dev
->release
= (void (*)(struct device
*))kfree
;
1754 dev
->driver
= &netiucv_driver
;
1758 ret
= device_register(dev
);
1762 ret
= netiucv_add_files(dev
);
1766 dev
->driver_data
= priv
;
1770 device_unregister(dev
);
1775 netiucv_unregister_device(struct device
*dev
)
1777 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1778 netiucv_remove_files(dev
);
1779 device_unregister(dev
);
1783 * Allocate and initialize a new connection structure.
1784 * Add it to the list of netiucv connections;
1786 static struct iucv_connection
*
1787 netiucv_new_connection(struct net_device
*dev
, char *username
)
1789 struct iucv_connection
**clist
= &iucv_connections
;
1790 struct iucv_connection
*conn
=
1791 (struct iucv_connection
*)
1792 kmalloc(sizeof(struct iucv_connection
), GFP_KERNEL
);
1795 memset(conn
, 0, sizeof(struct iucv_connection
));
1796 skb_queue_head_init(&conn
->collect_queue
);
1797 skb_queue_head_init(&conn
->commit_queue
);
1798 conn
->max_buffsize
= NETIUCV_BUFSIZE_DEFAULT
;
1801 conn
->rx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
,
1802 GFP_KERNEL
| GFP_DMA
);
1803 if (!conn
->rx_buff
) {
1807 conn
->tx_buff
= alloc_skb(NETIUCV_BUFSIZE_DEFAULT
,
1808 GFP_KERNEL
| GFP_DMA
);
1809 if (!conn
->tx_buff
) {
1810 kfree_skb(conn
->rx_buff
);
1814 conn
->fsm
= init_fsm("netiucvconn", conn_state_names
,
1815 conn_event_names
, NR_CONN_STATES
,
1816 NR_CONN_EVENTS
, conn_fsm
, CONN_FSM_LEN
,
1819 kfree_skb(conn
->tx_buff
);
1820 kfree_skb(conn
->rx_buff
);
1824 fsm_settimer(conn
->fsm
, &conn
->timer
);
1825 fsm_newstate(conn
->fsm
, CONN_STATE_INVALID
);
1828 memcpy(conn
->userid
, username
, 9);
1829 fsm_newstate(conn
->fsm
, CONN_STATE_STOPPED
);
1832 conn
->next
= *clist
;
1839 * Release a connection structure and remove it from the
1840 * list of netiucv connections.
1843 netiucv_remove_connection(struct iucv_connection
*conn
)
1845 struct iucv_connection
**clist
= &iucv_connections
;
1847 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1851 if (*clist
== conn
) {
1852 *clist
= conn
->next
;
1854 iucv_unregister_program(conn
->handle
);
1855 conn
->handle
= NULL
;
1857 fsm_deltimer(&conn
->timer
);
1858 kfree_fsm(conn
->fsm
);
1859 kfree_skb(conn
->rx_buff
);
1860 kfree_skb(conn
->tx_buff
);
1863 clist
= &((*clist
)->next
);
1868 * Release everything of a net device.
1871 netiucv_free_netdevice(struct net_device
*dev
)
1873 struct netiucv_priv
*privptr
;
1875 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1880 privptr
= (struct netiucv_priv
*)dev
->priv
;
1883 netiucv_remove_connection(privptr
->conn
);
1885 kfree_fsm(privptr
->fsm
);
1886 privptr
->conn
= NULL
; privptr
->fsm
= NULL
;
1887 /* privptr gets freed by free_netdev() */
1893 * Initialize a net device. (Called from kernel in alloc_netdev())
1896 netiucv_setup_netdevice(struct net_device
*dev
)
1898 memset(dev
->priv
, 0, sizeof(struct netiucv_priv
));
1900 dev
->mtu
= NETIUCV_MTU_DEFAULT
;
1901 dev
->hard_start_xmit
= netiucv_tx
;
1902 dev
->open
= netiucv_open
;
1903 dev
->stop
= netiucv_close
;
1904 dev
->get_stats
= netiucv_stats
;
1905 dev
->change_mtu
= netiucv_change_mtu
;
1906 dev
->destructor
= netiucv_free_netdevice
;
1907 dev
->hard_header_len
= NETIUCV_HDRLEN
;
1909 dev
->type
= ARPHRD_SLIP
;
1910 dev
->tx_queue_len
= NETIUCV_QUEUELEN_DEFAULT
;
1911 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
1912 SET_MODULE_OWNER(dev
);
1916 * Allocate and initialize everything of a net device.
1918 static struct net_device
*
1919 netiucv_init_netdevice(char *username
)
1921 struct netiucv_priv
*privptr
;
1922 struct net_device
*dev
;
1924 dev
= alloc_netdev(sizeof(struct netiucv_priv
), "iucv%d",
1925 netiucv_setup_netdevice
);
1928 if (dev_alloc_name(dev
, dev
->name
) < 0) {
1933 privptr
= (struct netiucv_priv
*)dev
->priv
;
1934 privptr
->fsm
= init_fsm("netiucvdev", dev_state_names
,
1935 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
1936 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
1937 if (!privptr
->fsm
) {
1941 privptr
->conn
= netiucv_new_connection(dev
, username
);
1942 if (!privptr
->conn
) {
1943 kfree_fsm(privptr
->fsm
);
1945 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_new_connection\n");
1948 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
1954 conn_write(struct device_driver
*drv
, const char *buf
, size_t count
)
1959 struct net_device
*dev
;
1961 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1963 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count
);
1964 IUCV_DBF_TEXT(setup
, 2, "conn_write: too long\n");
1968 for (i
=0, p
=(char *)buf
; i
<8 && *p
; i
++, p
++) {
1969 if (isalnum(*p
) || (*p
== '$'))
1971 else if (*p
== '\n') {
1972 /* trailing lf, grr */
1975 PRINT_WARN("netiucv: Invalid character in username!\n");
1976 IUCV_DBF_TEXT_(setup
, 2,
1977 "conn_write: invalid character %c\n", *p
);
1982 username
[i
++] = ' ';
1984 dev
= netiucv_init_netdevice(username
);
1987 "netiucv: Could not allocate network device structure "
1988 "for user '%s'\n", netiucv_printname(username
));
1989 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_init_netdevice\n");
1993 if ((ret
= netiucv_register_device(dev
))) {
1994 IUCV_DBF_TEXT_(setup
, 2,
1995 "ret %d from netiucv_register_device\n", ret
);
2001 (struct device
*)((struct netiucv_priv
*)dev
->priv
)->dev
);
2003 if ((ret
= register_netdev(dev
))) {
2004 netiucv_unregister_device((struct device
*)
2005 ((struct netiucv_priv
*)dev
->priv
)->dev
);
2009 PRINT_INFO("%s: '%s'\n", dev
->name
, netiucv_printname(username
));
2014 PRINT_WARN("netiucv: Could not register '%s'\n", dev
->name
);
2015 IUCV_DBF_TEXT(setup
, 2, "conn_write: could not register\n");
2016 netiucv_free_netdevice(dev
);
2020 DRIVER_ATTR(connection
, 0200, NULL
, conn_write
);
2023 remove_write (struct device_driver
*drv
, const char *buf
, size_t count
)
2025 struct iucv_connection
**clist
= &iucv_connections
;
2026 struct net_device
*ndev
;
2027 struct netiucv_priv
*priv
;
2029 char name
[IFNAMSIZ
];
2033 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2035 if (count
>= IFNAMSIZ
)
2038 for (i
=0, p
=(char *)buf
; i
<count
&& *p
; i
++, p
++) {
2039 if ((*p
== '\n') | (*p
== ' ')) {
2040 /* trailing lf, grr */
2049 ndev
= (*clist
)->netdev
;
2050 priv
= (struct netiucv_priv
*)ndev
->priv
;
2053 if (strncmp(name
, ndev
->name
, count
)) {
2054 clist
= &((*clist
)->next
);
2057 if (ndev
->flags
& (IFF_UP
| IFF_RUNNING
)) {
2059 "netiucv: net device %s active with peer %s\n",
2060 ndev
->name
, priv
->conn
->userid
);
2061 PRINT_WARN("netiucv: %s cannot be removed\n",
2063 IUCV_DBF_TEXT(data
, 2, "remove_write: still active\n");
2066 unregister_netdev(ndev
);
2067 netiucv_unregister_device(dev
);
2070 PRINT_WARN("netiucv: net device %s unknown\n", name
);
2071 IUCV_DBF_TEXT(data
, 2, "remove_write: unknown device\n");
2075 DRIVER_ATTR(remove
, 0200, NULL
, remove_write
);
2078 netiucv_banner(void)
2080 char vbuf
[] = "$Revision: 1.69 $";
2081 char *version
= vbuf
;
2083 if ((version
= strchr(version
, ':'))) {
2084 char *p
= strchr(version
+ 1, '$');
2089 PRINT_INFO("NETIUCV driver Version%s initialized\n", version
);
2095 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2096 while (iucv_connections
) {
2097 struct net_device
*ndev
= iucv_connections
->netdev
;
2098 struct netiucv_priv
*priv
= (struct netiucv_priv
*)ndev
->priv
;
2099 struct device
*dev
= priv
->dev
;
2101 unregister_netdev(ndev
);
2102 netiucv_unregister_device(dev
);
2105 driver_remove_file(&netiucv_driver
, &driver_attr_connection
);
2106 driver_remove_file(&netiucv_driver
, &driver_attr_remove
);
2107 driver_unregister(&netiucv_driver
);
2108 iucv_unregister_dbf_views();
2110 PRINT_INFO("NETIUCV driver unloaded\n");
2119 ret
= iucv_register_dbf_views();
2121 PRINT_WARN("netiucv_init failed, "
2122 "iucv_register_dbf_views rc = %d\n", ret
);
2125 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2126 ret
= driver_register(&netiucv_driver
);
2128 PRINT_ERR("NETIUCV: failed to register driver.\n");
2129 IUCV_DBF_TEXT_(setup
, 2, "ret %d from driver_register\n", ret
);
2130 iucv_unregister_dbf_views();
2134 /* Add entry for specifying connections. */
2135 ret
= driver_create_file(&netiucv_driver
, &driver_attr_connection
);
2137 ret
= driver_create_file(&netiucv_driver
, &driver_attr_remove
);
2140 PRINT_ERR("NETIUCV: failed to add driver attribute.\n");
2141 IUCV_DBF_TEXT_(setup
, 2, "ret %d from driver_create_file\n", ret
);
2142 driver_unregister(&netiucv_driver
);
2143 iucv_unregister_dbf_views();
2148 module_init(netiucv_init
);
2149 module_exit(netiucv_exit
);
2150 MODULE_LICENSE("GPL");