1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright IBM Corp. 2001, 2009
8 * Original netiucv driver:
9 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
10 * Sysfs integration and all bugs therein:
11 * Cornelia Huck (cornelia.huck@de.ibm.com)
13 * Ursula Braun (ursula.braun@de.ibm.com)
16 * the source of the original IUCV driver by:
17 * Stefan Hegewald <hegewald@de.ibm.com>
18 * Hartmut Penner <hpenner@de.ibm.com>
19 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
20 * Martin Schwidefsky (schwidefsky@de.ibm.com)
21 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
24 #define KMSG_COMPONENT "netiucv"
25 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/errno.h>
34 #include <linux/types.h>
35 #include <linux/interrupt.h>
36 #include <linux/timer.h>
37 #include <linux/bitops.h>
39 #include <linux/signal.h>
40 #include <linux/string.h>
41 #include <linux/device.h>
44 #include <linux/if_arp.h>
45 #include <linux/tcp.h>
46 #include <linux/skbuff.h>
47 #include <linux/ctype.h>
51 #include <linux/uaccess.h>
52 #include <asm/ebcdic.h>
54 #include <net/iucv/iucv.h>
58 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
59 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
62 * Debug Facility stuff
64 #define IUCV_DBF_SETUP_NAME "iucv_setup"
65 #define IUCV_DBF_SETUP_LEN 64
66 #define IUCV_DBF_SETUP_PAGES 2
67 #define IUCV_DBF_SETUP_NR_AREAS 1
68 #define IUCV_DBF_SETUP_LEVEL 3
70 #define IUCV_DBF_DATA_NAME "iucv_data"
71 #define IUCV_DBF_DATA_LEN 128
72 #define IUCV_DBF_DATA_PAGES 2
73 #define IUCV_DBF_DATA_NR_AREAS 1
74 #define IUCV_DBF_DATA_LEVEL 2
76 #define IUCV_DBF_TRACE_NAME "iucv_trace"
77 #define IUCV_DBF_TRACE_LEN 16
78 #define IUCV_DBF_TRACE_PAGES 4
79 #define IUCV_DBF_TRACE_NR_AREAS 1
80 #define IUCV_DBF_TRACE_LEVEL 3
82 #define IUCV_DBF_TEXT(name,level,text) \
84 debug_text_event(iucv_dbf_##name,level,text); \
87 #define IUCV_DBF_HEX(name,level,addr,len) \
89 debug_event(iucv_dbf_##name,level,(void*)(addr),len); \
92 DECLARE_PER_CPU(char[256], iucv_dbf_txt_buf
);
94 #define IUCV_DBF_TEXT_(name, level, text...) \
96 if (debug_level_enabled(iucv_dbf_##name, level)) { \
97 char* __buf = get_cpu_var(iucv_dbf_txt_buf); \
98 sprintf(__buf, text); \
99 debug_text_event(iucv_dbf_##name, level, __buf); \
100 put_cpu_var(iucv_dbf_txt_buf); \
104 #define IUCV_DBF_SPRINTF(name,level,text...) \
106 debug_sprintf_event(iucv_dbf_trace, level, ##text ); \
107 debug_sprintf_event(iucv_dbf_trace, level, text ); \
111 * some more debug stuff
113 #define PRINTK_HEADER " iucv: " /* for debugging */
115 static struct device_driver netiucv_driver
= {
116 .owner
= THIS_MODULE
,
122 * Per connection profiling data
124 struct connection_profile
{
125 unsigned long maxmulti
;
126 unsigned long maxcqueue
;
127 unsigned long doios_single
;
128 unsigned long doios_multi
;
130 unsigned long tx_time
;
131 unsigned long send_stamp
;
132 unsigned long tx_pending
;
133 unsigned long tx_max_pending
;
137 * Representation of one iucv connection
139 struct iucv_connection
{
140 struct list_head list
;
141 struct iucv_path
*path
;
142 struct sk_buff
*rx_buff
;
143 struct sk_buff
*tx_buff
;
144 struct sk_buff_head collect_queue
;
145 struct sk_buff_head commit_queue
;
146 spinlock_t collect_lock
;
151 struct net_device
*netdev
;
152 struct connection_profile prof
;
158 * Linked list of all connection structs.
160 static LIST_HEAD(iucv_connection_list
);
161 static DEFINE_RWLOCK(iucv_connection_rwlock
);
164 * Representation of event-data for the
165 * connection state machine.
168 struct iucv_connection
*conn
;
173 * Private part of the network device structure
175 struct netiucv_priv
{
176 struct net_device_stats stats
;
179 struct iucv_connection
*conn
;
184 * Link level header for a packet.
190 #define NETIUCV_HDRLEN (sizeof(struct ll_header))
191 #define NETIUCV_BUFSIZE_MAX 65537
192 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
193 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
194 #define NETIUCV_MTU_DEFAULT 9216
195 #define NETIUCV_QUEUELEN_DEFAULT 50
196 #define NETIUCV_TIMEOUT_5SEC 5000
199 * Compatibility macros for busy handling
200 * of network devices.
202 static void netiucv_clear_busy(struct net_device
*dev
)
204 struct netiucv_priv
*priv
= netdev_priv(dev
);
205 clear_bit(0, &priv
->tbusy
);
206 netif_wake_queue(dev
);
209 static int netiucv_test_and_set_busy(struct net_device
*dev
)
211 struct netiucv_priv
*priv
= netdev_priv(dev
);
212 netif_stop_queue(dev
);
213 return test_and_set_bit(0, &priv
->tbusy
);
216 static u8 iucvMagic_ascii
[16] = {
217 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
218 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
221 static u8 iucvMagic_ebcdic
[16] = {
222 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
223 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
227 * Convert an iucv userId to its printable
228 * form (strip whitespace at end).
230 * @param An iucv userId
232 * @returns The printable string (static data!!)
234 static char *netiucv_printname(char *name
, int len
)
238 memcpy(tmp
, name
, len
);
240 while (*p
&& ((p
- tmp
) < len
) && (!isspace(*p
)))
246 static char *netiucv_printuser(struct iucv_connection
*conn
)
248 static char tmp_uid
[9];
249 static char tmp_udat
[17];
250 static char buf
[100];
252 if (memcmp(conn
->userdata
, iucvMagic_ebcdic
, 16)) {
255 memcpy(tmp_uid
, netiucv_printname(conn
->userid
, 8), 8);
256 memcpy(tmp_udat
, conn
->userdata
, 16);
257 EBCASC(tmp_udat
, 16);
258 memcpy(tmp_udat
, netiucv_printname(tmp_udat
, 16), 16);
259 sprintf(buf
, "%s.%s", tmp_uid
, tmp_udat
);
262 return netiucv_printname(conn
->userid
, 8);
266 * States of the interface statemachine.
274 * MUST be always the last element!!
279 static const char *dev_state_names
[] = {
287 * Events of the interface statemachine.
295 * MUST be always the last element!!
300 static const char *dev_event_names
[] = {
308 * Events of the connection statemachine
312 * Events, representing callbacks from
313 * lowlevel iucv layer)
324 * Events, representing errors return codes from
325 * calls to lowlevel iucv layer
329 * Event, representing timer expiry.
334 * Events, representing commands from upper levels.
340 * MUST be always the last element!!
345 static const char *conn_event_names
[] = {
346 "Remote connection request",
347 "Remote connection acknowledge",
348 "Remote connection reject",
349 "Connection suspended",
350 "Connection resumed",
361 * States of the connection statemachine.
365 * Connection not assigned to any device,
366 * initial state, invalid
371 * Userid assigned but not operating
376 * Connection registered,
377 * no connection request sent yet,
378 * no connection request received
380 CONN_STATE_STARTWAIT
,
383 * Connection registered and connection request sent,
384 * no acknowledge and no connection request received yet.
386 CONN_STATE_SETUPWAIT
,
389 * Connection up and running idle
394 * Data sent, awaiting CONN_EVENT_TXDONE
399 * Error during registration.
404 * Error during registration.
409 * MUST be always the last element!!
414 static const char *conn_state_names
[] = {
422 "Registration error",
428 * Debug Facility Stuff
430 static debug_info_t
*iucv_dbf_setup
= NULL
;
431 static debug_info_t
*iucv_dbf_data
= NULL
;
432 static debug_info_t
*iucv_dbf_trace
= NULL
;
434 DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf
);
436 static void iucv_unregister_dbf_views(void)
438 debug_unregister(iucv_dbf_setup
);
439 debug_unregister(iucv_dbf_data
);
440 debug_unregister(iucv_dbf_trace
);
442 static int iucv_register_dbf_views(void)
444 iucv_dbf_setup
= debug_register(IUCV_DBF_SETUP_NAME
,
445 IUCV_DBF_SETUP_PAGES
,
446 IUCV_DBF_SETUP_NR_AREAS
,
448 iucv_dbf_data
= debug_register(IUCV_DBF_DATA_NAME
,
450 IUCV_DBF_DATA_NR_AREAS
,
452 iucv_dbf_trace
= debug_register(IUCV_DBF_TRACE_NAME
,
453 IUCV_DBF_TRACE_PAGES
,
454 IUCV_DBF_TRACE_NR_AREAS
,
457 if ((iucv_dbf_setup
== NULL
) || (iucv_dbf_data
== NULL
) ||
458 (iucv_dbf_trace
== NULL
)) {
459 iucv_unregister_dbf_views();
462 debug_register_view(iucv_dbf_setup
, &debug_hex_ascii_view
);
463 debug_set_level(iucv_dbf_setup
, IUCV_DBF_SETUP_LEVEL
);
465 debug_register_view(iucv_dbf_data
, &debug_hex_ascii_view
);
466 debug_set_level(iucv_dbf_data
, IUCV_DBF_DATA_LEVEL
);
468 debug_register_view(iucv_dbf_trace
, &debug_hex_ascii_view
);
469 debug_set_level(iucv_dbf_trace
, IUCV_DBF_TRACE_LEVEL
);
475 * Callback-wrappers, called from lowlevel iucv layer.
478 static void netiucv_callback_rx(struct iucv_path
*path
,
479 struct iucv_message
*msg
)
481 struct iucv_connection
*conn
= path
->private;
482 struct iucv_event ev
;
486 fsm_event(conn
->fsm
, CONN_EVENT_RX
, &ev
);
489 static void netiucv_callback_txdone(struct iucv_path
*path
,
490 struct iucv_message
*msg
)
492 struct iucv_connection
*conn
= path
->private;
493 struct iucv_event ev
;
497 fsm_event(conn
->fsm
, CONN_EVENT_TXDONE
, &ev
);
500 static void netiucv_callback_connack(struct iucv_path
*path
, u8 ipuser
[16])
502 struct iucv_connection
*conn
= path
->private;
504 fsm_event(conn
->fsm
, CONN_EVENT_CONN_ACK
, conn
);
507 static int netiucv_callback_connreq(struct iucv_path
*path
, u8
*ipvmid
,
510 struct iucv_connection
*conn
= path
->private;
511 struct iucv_event ev
;
512 static char tmp_user
[9];
513 static char tmp_udat
[17];
517 memcpy(tmp_user
, netiucv_printname(ipvmid
, 8), 8);
518 memcpy(tmp_udat
, ipuser
, 16);
519 EBCASC(tmp_udat
, 16);
520 read_lock_bh(&iucv_connection_rwlock
);
521 list_for_each_entry(conn
, &iucv_connection_list
, list
) {
522 if (strncmp(ipvmid
, conn
->userid
, 8) ||
523 strncmp(ipuser
, conn
->userdata
, 16))
525 /* Found a matching connection for this path. */
529 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REQ
, &ev
);
532 IUCV_DBF_TEXT_(setup
, 2, "Connection requested for %s.%s\n",
533 tmp_user
, netiucv_printname(tmp_udat
, 16));
534 read_unlock_bh(&iucv_connection_rwlock
);
538 static void netiucv_callback_connrej(struct iucv_path
*path
, u8
*ipuser
)
540 struct iucv_connection
*conn
= path
->private;
542 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REJ
, conn
);
545 static void netiucv_callback_connsusp(struct iucv_path
*path
, u8
*ipuser
)
547 struct iucv_connection
*conn
= path
->private;
549 fsm_event(conn
->fsm
, CONN_EVENT_CONN_SUS
, conn
);
552 static void netiucv_callback_connres(struct iucv_path
*path
, u8
*ipuser
)
554 struct iucv_connection
*conn
= path
->private;
556 fsm_event(conn
->fsm
, CONN_EVENT_CONN_RES
, conn
);
560 * NOP action for statemachines
562 static void netiucv_action_nop(fsm_instance
*fi
, int event
, void *arg
)
567 * Actions of the connection statemachine
572 * @conn: The connection where this skb has been received.
573 * @pskb: The received skb.
575 * Unpack a just received skb and hand it over to upper layers.
576 * Helper function for conn_action_rx.
578 static void netiucv_unpack_skb(struct iucv_connection
*conn
,
579 struct sk_buff
*pskb
)
581 struct net_device
*dev
= conn
->netdev
;
582 struct netiucv_priv
*privptr
= netdev_priv(dev
);
585 skb_put(pskb
, NETIUCV_HDRLEN
);
587 pskb
->ip_summed
= CHECKSUM_NONE
;
588 pskb
->protocol
= cpu_to_be16(ETH_P_IP
);
592 struct ll_header
*header
= (struct ll_header
*) pskb
->data
;
597 skb_pull(pskb
, NETIUCV_HDRLEN
);
598 header
->next
-= offset
;
599 offset
+= header
->next
;
600 header
->next
-= NETIUCV_HDRLEN
;
601 if (skb_tailroom(pskb
) < header
->next
) {
602 IUCV_DBF_TEXT_(data
, 2, "Illegal next field: %d > %d\n",
603 header
->next
, skb_tailroom(pskb
));
606 skb_put(pskb
, header
->next
);
607 skb_reset_mac_header(pskb
);
608 skb
= dev_alloc_skb(pskb
->len
);
610 IUCV_DBF_TEXT(data
, 2,
611 "Out of memory in netiucv_unpack_skb\n");
612 privptr
->stats
.rx_dropped
++;
615 skb_copy_from_linear_data(pskb
, skb_put(skb
, pskb
->len
),
617 skb_reset_mac_header(skb
);
618 skb
->dev
= pskb
->dev
;
619 skb
->protocol
= pskb
->protocol
;
620 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
621 privptr
->stats
.rx_packets
++;
622 privptr
->stats
.rx_bytes
+= skb
->len
;
624 skb_pull(pskb
, header
->next
);
625 skb_put(pskb
, NETIUCV_HDRLEN
);
629 static void conn_action_rx(fsm_instance
*fi
, int event
, void *arg
)
631 struct iucv_event
*ev
= arg
;
632 struct iucv_connection
*conn
= ev
->conn
;
633 struct iucv_message
*msg
= ev
->data
;
634 struct netiucv_priv
*privptr
= netdev_priv(conn
->netdev
);
637 IUCV_DBF_TEXT(trace
, 4, __func__
);
640 iucv_message_reject(conn
->path
, msg
);
641 IUCV_DBF_TEXT(data
, 2,
642 "Received data for unlinked connection\n");
645 if (msg
->length
> conn
->max_buffsize
) {
646 iucv_message_reject(conn
->path
, msg
);
647 privptr
->stats
.rx_dropped
++;
648 IUCV_DBF_TEXT_(data
, 2, "msglen %d > max_buffsize %d\n",
649 msg
->length
, conn
->max_buffsize
);
652 conn
->rx_buff
->data
= conn
->rx_buff
->head
;
653 skb_reset_tail_pointer(conn
->rx_buff
);
654 conn
->rx_buff
->len
= 0;
655 rc
= iucv_message_receive(conn
->path
, msg
, 0, conn
->rx_buff
->data
,
657 if (rc
|| msg
->length
< 5) {
658 privptr
->stats
.rx_errors
++;
659 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_receive\n", rc
);
662 netiucv_unpack_skb(conn
, conn
->rx_buff
);
665 static void conn_action_txdone(fsm_instance
*fi
, int event
, void *arg
)
667 struct iucv_event
*ev
= arg
;
668 struct iucv_connection
*conn
= ev
->conn
;
669 struct iucv_message
*msg
= ev
->data
;
670 struct iucv_message txmsg
;
671 struct netiucv_priv
*privptr
= NULL
;
672 u32 single_flag
= msg
->tag
;
677 unsigned long saveflags
;
678 struct ll_header header
;
681 IUCV_DBF_TEXT(trace
, 4, __func__
);
683 if (!conn
|| !conn
->netdev
) {
684 IUCV_DBF_TEXT(data
, 2,
685 "Send confirmation for unlinked connection\n");
688 privptr
= netdev_priv(conn
->netdev
);
689 conn
->prof
.tx_pending
--;
691 if ((skb
= skb_dequeue(&conn
->commit_queue
))) {
692 refcount_dec(&skb
->users
);
694 privptr
->stats
.tx_packets
++;
695 privptr
->stats
.tx_bytes
+=
696 (skb
->len
- NETIUCV_HDRLEN
699 dev_kfree_skb_any(skb
);
702 conn
->tx_buff
->data
= conn
->tx_buff
->head
;
703 skb_reset_tail_pointer(conn
->tx_buff
);
704 conn
->tx_buff
->len
= 0;
705 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
706 while ((skb
= skb_dequeue(&conn
->collect_queue
))) {
707 header
.next
= conn
->tx_buff
->len
+ skb
->len
+ NETIUCV_HDRLEN
;
708 skb_put_data(conn
->tx_buff
, &header
, NETIUCV_HDRLEN
);
709 skb_copy_from_linear_data(skb
,
710 skb_put(conn
->tx_buff
, skb
->len
),
715 refcount_dec(&skb
->users
);
716 dev_kfree_skb_any(skb
);
718 if (conn
->collect_len
> conn
->prof
.maxmulti
)
719 conn
->prof
.maxmulti
= conn
->collect_len
;
720 conn
->collect_len
= 0;
721 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
722 if (conn
->tx_buff
->len
== 0) {
723 fsm_newstate(fi
, CONN_STATE_IDLE
);
728 skb_put_data(conn
->tx_buff
, &header
, NETIUCV_HDRLEN
);
729 conn
->prof
.send_stamp
= jiffies
;
732 rc
= iucv_message_send(conn
->path
, &txmsg
, 0, 0,
733 conn
->tx_buff
->data
, conn
->tx_buff
->len
);
734 conn
->prof
.doios_multi
++;
735 conn
->prof
.txlen
+= conn
->tx_buff
->len
;
736 conn
->prof
.tx_pending
++;
737 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
738 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
740 conn
->prof
.tx_pending
--;
741 fsm_newstate(fi
, CONN_STATE_IDLE
);
743 privptr
->stats
.tx_errors
+= txpackets
;
744 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
747 privptr
->stats
.tx_packets
+= txpackets
;
748 privptr
->stats
.tx_bytes
+= txbytes
;
750 if (stat_maxcq
> conn
->prof
.maxcqueue
)
751 conn
->prof
.maxcqueue
= stat_maxcq
;
755 static struct iucv_handler netiucv_handler
= {
756 .path_pending
= netiucv_callback_connreq
,
757 .path_complete
= netiucv_callback_connack
,
758 .path_severed
= netiucv_callback_connrej
,
759 .path_quiesced
= netiucv_callback_connsusp
,
760 .path_resumed
= netiucv_callback_connres
,
761 .message_pending
= netiucv_callback_rx
,
762 .message_complete
= netiucv_callback_txdone
,
765 static void conn_action_connaccept(fsm_instance
*fi
, int event
, void *arg
)
767 struct iucv_event
*ev
= arg
;
768 struct iucv_connection
*conn
= ev
->conn
;
769 struct iucv_path
*path
= ev
->data
;
770 struct net_device
*netdev
= conn
->netdev
;
771 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
774 IUCV_DBF_TEXT(trace
, 3, __func__
);
777 path
->msglim
= NETIUCV_QUEUELEN_DEFAULT
;
779 rc
= iucv_path_accept(path
, &netiucv_handler
, conn
->userdata
, conn
);
781 IUCV_DBF_TEXT_(setup
, 2, "rc %d from iucv_accept", rc
);
784 fsm_newstate(fi
, CONN_STATE_IDLE
);
785 netdev
->tx_queue_len
= conn
->path
->msglim
;
786 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
789 static void conn_action_connreject(fsm_instance
*fi
, int event
, void *arg
)
791 struct iucv_event
*ev
= arg
;
792 struct iucv_path
*path
= ev
->data
;
794 IUCV_DBF_TEXT(trace
, 3, __func__
);
795 iucv_path_sever(path
, NULL
);
798 static void conn_action_connack(fsm_instance
*fi
, int event
, void *arg
)
800 struct iucv_connection
*conn
= arg
;
801 struct net_device
*netdev
= conn
->netdev
;
802 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
804 IUCV_DBF_TEXT(trace
, 3, __func__
);
805 fsm_deltimer(&conn
->timer
);
806 fsm_newstate(fi
, CONN_STATE_IDLE
);
807 netdev
->tx_queue_len
= conn
->path
->msglim
;
808 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
811 static void conn_action_conntimsev(fsm_instance
*fi
, int event
, void *arg
)
813 struct iucv_connection
*conn
= arg
;
815 IUCV_DBF_TEXT(trace
, 3, __func__
);
816 fsm_deltimer(&conn
->timer
);
817 iucv_path_sever(conn
->path
, conn
->userdata
);
818 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
821 static void conn_action_connsever(fsm_instance
*fi
, int event
, void *arg
)
823 struct iucv_connection
*conn
= arg
;
824 struct net_device
*netdev
= conn
->netdev
;
825 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
827 IUCV_DBF_TEXT(trace
, 3, __func__
);
829 fsm_deltimer(&conn
->timer
);
830 iucv_path_sever(conn
->path
, conn
->userdata
);
831 dev_info(privptr
->dev
, "The peer z/VM guest %s has closed the "
832 "connection\n", netiucv_printuser(conn
));
833 IUCV_DBF_TEXT(data
, 2,
834 "conn_action_connsever: Remote dropped connection\n");
835 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
836 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
839 static void conn_action_start(fsm_instance
*fi
, int event
, void *arg
)
841 struct iucv_connection
*conn
= arg
;
842 struct net_device
*netdev
= conn
->netdev
;
843 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
846 IUCV_DBF_TEXT(trace
, 3, __func__
);
848 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
851 * We must set the state before calling iucv_connect because the
852 * callback handler could be called at any point after the connection
856 fsm_newstate(fi
, CONN_STATE_SETUPWAIT
);
857 conn
->path
= iucv_path_alloc(NETIUCV_QUEUELEN_DEFAULT
, 0, GFP_KERNEL
);
858 IUCV_DBF_TEXT_(setup
, 2, "%s: connecting to %s ...\n",
859 netdev
->name
, netiucv_printuser(conn
));
861 rc
= iucv_path_connect(conn
->path
, &netiucv_handler
, conn
->userid
,
862 NULL
, conn
->userdata
, conn
);
865 netdev
->tx_queue_len
= conn
->path
->msglim
;
866 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
867 CONN_EVENT_TIMER
, conn
);
870 dev_warn(privptr
->dev
,
871 "The IUCV device failed to connect to z/VM guest %s\n",
872 netiucv_printname(conn
->userid
, 8));
873 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
876 dev_warn(privptr
->dev
,
877 "The IUCV device failed to connect to the peer on z/VM"
878 " guest %s\n", netiucv_printname(conn
->userid
, 8));
879 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
882 dev_err(privptr
->dev
,
883 "Connecting the IUCV device would exceed the maximum"
884 " number of IUCV connections\n");
885 fsm_newstate(fi
, CONN_STATE_CONNERR
);
888 dev_err(privptr
->dev
,
889 "z/VM guest %s has too many IUCV connections"
890 " to connect with the IUCV device\n",
891 netiucv_printname(conn
->userid
, 8));
892 fsm_newstate(fi
, CONN_STATE_CONNERR
);
895 dev_err(privptr
->dev
,
896 "The IUCV device cannot connect to a z/VM guest with no"
897 " IUCV authorization\n");
898 fsm_newstate(fi
, CONN_STATE_CONNERR
);
901 dev_err(privptr
->dev
,
902 "Connecting the IUCV device failed with error %d\n",
904 fsm_newstate(fi
, CONN_STATE_CONNERR
);
907 IUCV_DBF_TEXT_(setup
, 5, "iucv_connect rc is %d\n", rc
);
912 static void netiucv_purge_skb_queue(struct sk_buff_head
*q
)
916 while ((skb
= skb_dequeue(q
))) {
917 refcount_dec(&skb
->users
);
918 dev_kfree_skb_any(skb
);
922 static void conn_action_stop(fsm_instance
*fi
, int event
, void *arg
)
924 struct iucv_event
*ev
= arg
;
925 struct iucv_connection
*conn
= ev
->conn
;
926 struct net_device
*netdev
= conn
->netdev
;
927 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
929 IUCV_DBF_TEXT(trace
, 3, __func__
);
931 fsm_deltimer(&conn
->timer
);
932 fsm_newstate(fi
, CONN_STATE_STOPPED
);
933 netiucv_purge_skb_queue(&conn
->collect_queue
);
935 IUCV_DBF_TEXT(trace
, 5, "calling iucv_path_sever\n");
936 iucv_path_sever(conn
->path
, conn
->userdata
);
940 netiucv_purge_skb_queue(&conn
->commit_queue
);
941 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
944 static void conn_action_inval(fsm_instance
*fi
, int event
, void *arg
)
946 struct iucv_connection
*conn
= arg
;
947 struct net_device
*netdev
= conn
->netdev
;
949 IUCV_DBF_TEXT_(data
, 2, "%s('%s'): conn_action_inval called\n",
950 netdev
->name
, conn
->userid
);
953 static const fsm_node conn_fsm
[] = {
954 { CONN_STATE_INVALID
, CONN_EVENT_START
, conn_action_inval
},
955 { CONN_STATE_STOPPED
, CONN_EVENT_START
, conn_action_start
},
957 { CONN_STATE_STOPPED
, CONN_EVENT_STOP
, conn_action_stop
},
958 { CONN_STATE_STARTWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
959 { CONN_STATE_SETUPWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
960 { CONN_STATE_IDLE
, CONN_EVENT_STOP
, conn_action_stop
},
961 { CONN_STATE_TX
, CONN_EVENT_STOP
, conn_action_stop
},
962 { CONN_STATE_REGERR
, CONN_EVENT_STOP
, conn_action_stop
},
963 { CONN_STATE_CONNERR
, CONN_EVENT_STOP
, conn_action_stop
},
965 { CONN_STATE_STOPPED
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
966 { CONN_STATE_STARTWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
967 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
968 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
969 { CONN_STATE_TX
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
971 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_ACK
, conn_action_connack
},
972 { CONN_STATE_SETUPWAIT
, CONN_EVENT_TIMER
, conn_action_conntimsev
},
974 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
975 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
976 { CONN_STATE_TX
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
978 { CONN_STATE_IDLE
, CONN_EVENT_RX
, conn_action_rx
},
979 { CONN_STATE_TX
, CONN_EVENT_RX
, conn_action_rx
},
981 { CONN_STATE_TX
, CONN_EVENT_TXDONE
, conn_action_txdone
},
982 { CONN_STATE_IDLE
, CONN_EVENT_TXDONE
, conn_action_txdone
},
985 static const int CONN_FSM_LEN
= sizeof(conn_fsm
) / sizeof(fsm_node
);
989 * Actions for interface - statemachine.
994 * @fi: An instance of an interface statemachine.
995 * @event: The event, just happened.
996 * @arg: Generic pointer, casted from struct net_device * upon call.
998 * Startup connection by sending CONN_EVENT_START to it.
1000 static void dev_action_start(fsm_instance
*fi
, int event
, void *arg
)
1002 struct net_device
*dev
= arg
;
1003 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1005 IUCV_DBF_TEXT(trace
, 3, __func__
);
1007 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1008 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, privptr
->conn
);
1012 * Shutdown connection by sending CONN_EVENT_STOP to it.
1014 * @param fi An instance of an interface statemachine.
1015 * @param event The event, just happened.
1016 * @param arg Generic pointer, casted from struct net_device * upon call.
1019 dev_action_stop(fsm_instance
*fi
, int event
, void *arg
)
1021 struct net_device
*dev
= arg
;
1022 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1023 struct iucv_event ev
;
1025 IUCV_DBF_TEXT(trace
, 3, __func__
);
1027 ev
.conn
= privptr
->conn
;
1029 fsm_newstate(fi
, DEV_STATE_STOPWAIT
);
1030 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_STOP
, &ev
);
1034 * Called from connection statemachine
1035 * when a connection is up and running.
1037 * @param fi An instance of an interface statemachine.
1038 * @param event The event, just happened.
1039 * @param arg Generic pointer, casted from struct net_device * upon call.
1042 dev_action_connup(fsm_instance
*fi
, int event
, void *arg
)
1044 struct net_device
*dev
= arg
;
1045 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1047 IUCV_DBF_TEXT(trace
, 3, __func__
);
1049 switch (fsm_getstate(fi
)) {
1050 case DEV_STATE_STARTWAIT
:
1051 fsm_newstate(fi
, DEV_STATE_RUNNING
);
1052 dev_info(privptr
->dev
,
1053 "The IUCV device has been connected"
1054 " successfully to %s\n",
1055 netiucv_printuser(privptr
->conn
));
1056 IUCV_DBF_TEXT(setup
, 3,
1057 "connection is up and running\n");
1059 case DEV_STATE_STOPWAIT
:
1060 IUCV_DBF_TEXT(data
, 2,
1061 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1067 * Called from connection statemachine
1068 * when a connection has been shutdown.
1070 * @param fi An instance of an interface statemachine.
1071 * @param event The event, just happened.
1072 * @param arg Generic pointer, casted from struct net_device * upon call.
1075 dev_action_conndown(fsm_instance
*fi
, int event
, void *arg
)
1077 IUCV_DBF_TEXT(trace
, 3, __func__
);
1079 switch (fsm_getstate(fi
)) {
1080 case DEV_STATE_RUNNING
:
1081 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1083 case DEV_STATE_STOPWAIT
:
1084 fsm_newstate(fi
, DEV_STATE_STOPPED
);
1085 IUCV_DBF_TEXT(setup
, 3, "connection is down\n");
1090 static const fsm_node dev_fsm
[] = {
1091 { DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
1093 { DEV_STATE_STOPWAIT
, DEV_EVENT_START
, dev_action_start
},
1094 { DEV_STATE_STOPWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1096 { DEV_STATE_STARTWAIT
, DEV_EVENT_STOP
, dev_action_stop
},
1097 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONUP
, dev_action_connup
},
1099 { DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
1100 { DEV_STATE_RUNNING
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1101 { DEV_STATE_RUNNING
, DEV_EVENT_CONUP
, netiucv_action_nop
},
1104 static const int DEV_FSM_LEN
= sizeof(dev_fsm
) / sizeof(fsm_node
);
1107 * Transmit a packet.
1108 * This is a helper function for netiucv_tx().
1110 * @param conn Connection to be used for sending.
1111 * @param skb Pointer to struct sk_buff of packet to send.
1112 * The linklevel header has already been set up
1115 * @return 0 on success, -ERRNO on failure. (Never fails.)
1117 static int netiucv_transmit_skb(struct iucv_connection
*conn
,
1118 struct sk_buff
*skb
)
1120 struct iucv_message msg
;
1121 unsigned long saveflags
;
1122 struct ll_header header
;
1125 if (fsm_getstate(conn
->fsm
) != CONN_STATE_IDLE
) {
1126 int l
= skb
->len
+ NETIUCV_HDRLEN
;
1128 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
1129 if (conn
->collect_len
+ l
>
1130 (conn
->max_buffsize
- NETIUCV_HDRLEN
)) {
1132 IUCV_DBF_TEXT(data
, 2,
1133 "EBUSY from netiucv_transmit_skb\n");
1135 refcount_inc(&skb
->users
);
1136 skb_queue_tail(&conn
->collect_queue
, skb
);
1137 conn
->collect_len
+= l
;
1140 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
1142 struct sk_buff
*nskb
= skb
;
1144 * Copy the skb to a new allocated skb in lowmem only if the
1145 * data is located above 2G in memory or tailroom is < 2.
1147 unsigned long hi
= ((unsigned long)(skb_tail_pointer(skb
) +
1148 NETIUCV_HDRLEN
)) >> 31;
1150 if (hi
|| (skb_tailroom(skb
) < 2)) {
1151 nskb
= alloc_skb(skb
->len
+ NETIUCV_HDRLEN
+
1152 NETIUCV_HDRLEN
, GFP_ATOMIC
| GFP_DMA
);
1154 IUCV_DBF_TEXT(data
, 2, "alloc_skb failed\n");
1158 skb_reserve(nskb
, NETIUCV_HDRLEN
);
1159 skb_put_data(nskb
, skb
->data
, skb
->len
);
1164 * skb now is below 2G and has enough room. Add headers.
1166 header
.next
= nskb
->len
+ NETIUCV_HDRLEN
;
1167 memcpy(skb_push(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1169 skb_put_data(nskb
, &header
, NETIUCV_HDRLEN
);
1171 fsm_newstate(conn
->fsm
, CONN_STATE_TX
);
1172 conn
->prof
.send_stamp
= jiffies
;
1176 rc
= iucv_message_send(conn
->path
, &msg
, 0, 0,
1177 nskb
->data
, nskb
->len
);
1178 conn
->prof
.doios_single
++;
1179 conn
->prof
.txlen
+= skb
->len
;
1180 conn
->prof
.tx_pending
++;
1181 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
1182 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
1184 struct netiucv_priv
*privptr
;
1185 fsm_newstate(conn
->fsm
, CONN_STATE_IDLE
);
1186 conn
->prof
.tx_pending
--;
1187 privptr
= netdev_priv(conn
->netdev
);
1189 privptr
->stats
.tx_errors
++;
1191 dev_kfree_skb(nskb
);
1194 * Remove our headers. They get added
1195 * again on retransmit.
1197 skb_pull(skb
, NETIUCV_HDRLEN
);
1198 skb_trim(skb
, skb
->len
- NETIUCV_HDRLEN
);
1200 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
1204 refcount_inc(&nskb
->users
);
1205 skb_queue_tail(&conn
->commit_queue
, nskb
);
1213 * Interface API for upper network layers
1217 * Open an interface.
1218 * Called from generic network layer when ifconfig up is run.
1220 * @param dev Pointer to interface struct.
1222 * @return 0 on success, -ERRNO on failure. (Never fails.)
1224 static int netiucv_open(struct net_device
*dev
)
1226 struct netiucv_priv
*priv
= netdev_priv(dev
);
1228 fsm_event(priv
->fsm
, DEV_EVENT_START
, dev
);
1233 * Close an interface.
1234 * Called from generic network layer when ifconfig down is run.
1236 * @param dev Pointer to interface struct.
1238 * @return 0 on success, -ERRNO on failure. (Never fails.)
1240 static int netiucv_close(struct net_device
*dev
)
1242 struct netiucv_priv
*priv
= netdev_priv(dev
);
1244 fsm_event(priv
->fsm
, DEV_EVENT_STOP
, dev
);
1249 * Start transmission of a packet.
1250 * Called from generic network device layer.
1252 static netdev_tx_t
netiucv_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1254 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1257 IUCV_DBF_TEXT(trace
, 4, __func__
);
1259 * Some sanity checks ...
1262 IUCV_DBF_TEXT(data
, 2, "netiucv_tx: skb is NULL\n");
1263 privptr
->stats
.tx_dropped
++;
1264 return NETDEV_TX_OK
;
1266 if (skb_headroom(skb
) < NETIUCV_HDRLEN
) {
1267 IUCV_DBF_TEXT(data
, 2,
1268 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1270 privptr
->stats
.tx_dropped
++;
1271 return NETDEV_TX_OK
;
1275 * If connection is not running, try to restart it
1276 * and throw away packet.
1278 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
1280 privptr
->stats
.tx_dropped
++;
1281 privptr
->stats
.tx_errors
++;
1282 privptr
->stats
.tx_carrier_errors
++;
1283 return NETDEV_TX_OK
;
1286 if (netiucv_test_and_set_busy(dev
)) {
1287 IUCV_DBF_TEXT(data
, 2, "EBUSY from netiucv_tx\n");
1288 return NETDEV_TX_BUSY
;
1290 netif_trans_update(dev
);
1291 rc
= netiucv_transmit_skb(privptr
->conn
, skb
);
1292 netiucv_clear_busy(dev
);
1293 return rc
? NETDEV_TX_BUSY
: NETDEV_TX_OK
;
1298 * @dev: Pointer to interface struct.
1300 * Returns interface statistics of a device.
1302 * Returns pointer to stats struct of this interface.
1304 static struct net_device_stats
*netiucv_stats (struct net_device
* dev
)
1306 struct netiucv_priv
*priv
= netdev_priv(dev
);
1308 IUCV_DBF_TEXT(trace
, 5, __func__
);
1309 return &priv
->stats
;
1313 * attributes in sysfs
1316 static ssize_t
user_show(struct device
*dev
, struct device_attribute
*attr
,
1319 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1321 IUCV_DBF_TEXT(trace
, 5, __func__
);
1322 return sysfs_emit(buf
, "%s\n", netiucv_printuser(priv
->conn
));
1325 static int netiucv_check_user(const char *buf
, size_t count
, char *username
,
1331 p
= strchr(buf
, '.');
1332 if ((p
&& ((count
> 26) ||
1334 (buf
+ count
- p
> 18))) ||
1335 (!p
&& (count
> 9))) {
1336 IUCV_DBF_TEXT(setup
, 2, "conn_write: too long\n");
1340 for (i
= 0, p
= buf
; i
< 8 && *p
&& *p
!= '.'; i
++, p
++) {
1341 if (isalnum(*p
) || *p
== '$') {
1342 username
[i
] = toupper(*p
);
1346 /* trailing lf, grr */
1348 IUCV_DBF_TEXT_(setup
, 2,
1349 "conn_write: invalid character %02x\n", *p
);
1353 username
[i
++] = ' ';
1358 for (i
= 0; i
< 16 && *p
; i
++, p
++) {
1361 userdata
[i
] = toupper(*p
);
1363 while (i
> 0 && i
< 16)
1364 userdata
[i
++] = ' ';
1366 memcpy(userdata
, iucvMagic_ascii
, 16);
1367 userdata
[16] = '\0';
1368 ASCEBC(userdata
, 16);
1373 static ssize_t
user_write(struct device
*dev
, struct device_attribute
*attr
,
1374 const char *buf
, size_t count
)
1376 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1377 struct net_device
*ndev
= priv
->conn
->netdev
;
1381 struct iucv_connection
*cp
;
1383 IUCV_DBF_TEXT(trace
, 3, __func__
);
1384 rc
= netiucv_check_user(buf
, count
, username
, userdata
);
1388 if (memcmp(username
, priv
->conn
->userid
, 9) &&
1389 (ndev
->flags
& (IFF_UP
| IFF_RUNNING
))) {
1390 /* username changed while the interface is active. */
1391 IUCV_DBF_TEXT(setup
, 2, "user_write: device active\n");
1394 read_lock_bh(&iucv_connection_rwlock
);
1395 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
1396 if (!strncmp(username
, cp
->userid
, 9) &&
1397 !strncmp(userdata
, cp
->userdata
, 17) && cp
->netdev
!= ndev
) {
1398 read_unlock_bh(&iucv_connection_rwlock
);
1399 IUCV_DBF_TEXT_(setup
, 2, "user_write: Connection to %s "
1400 "already exists\n", netiucv_printuser(cp
));
1404 read_unlock_bh(&iucv_connection_rwlock
);
1405 memcpy(priv
->conn
->userid
, username
, 9);
1406 memcpy(priv
->conn
->userdata
, userdata
, 17);
1410 static DEVICE_ATTR(user
, 0644, user_show
, user_write
);
1412 static ssize_t
buffer_show (struct device
*dev
, struct device_attribute
*attr
,
1415 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1417 IUCV_DBF_TEXT(trace
, 5, __func__
);
1418 return sysfs_emit(buf
, "%d\n", priv
->conn
->max_buffsize
);
1421 static ssize_t
buffer_write (struct device
*dev
, struct device_attribute
*attr
,
1422 const char *buf
, size_t count
)
1424 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1425 struct net_device
*ndev
= priv
->conn
->netdev
;
1429 IUCV_DBF_TEXT(trace
, 3, __func__
);
1433 rc
= kstrtouint(buf
, 0, &bs1
);
1435 if (rc
== -EINVAL
) {
1436 IUCV_DBF_TEXT_(setup
, 2, "buffer_write: invalid char %s\n",
1440 if ((rc
== -ERANGE
) || (bs1
> NETIUCV_BUFSIZE_MAX
)) {
1441 IUCV_DBF_TEXT_(setup
, 2,
1442 "buffer_write: buffer size %d too large\n",
1446 if ((ndev
->flags
& IFF_RUNNING
) &&
1447 (bs1
< (ndev
->mtu
+ NETIUCV_HDRLEN
+ 2))) {
1448 IUCV_DBF_TEXT_(setup
, 2,
1449 "buffer_write: buffer size %d too small\n",
1453 if (bs1
< (576 + NETIUCV_HDRLEN
+ NETIUCV_HDRLEN
)) {
1454 IUCV_DBF_TEXT_(setup
, 2,
1455 "buffer_write: buffer size %d too small\n",
1460 priv
->conn
->max_buffsize
= bs1
;
1461 if (!(ndev
->flags
& IFF_RUNNING
))
1462 ndev
->mtu
= bs1
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
;
1468 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
1470 static ssize_t
dev_fsm_show (struct device
*dev
, struct device_attribute
*attr
,
1473 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1475 IUCV_DBF_TEXT(trace
, 5, __func__
);
1476 return sysfs_emit(buf
, "%s\n", fsm_getstate_str(priv
->fsm
));
1479 static DEVICE_ATTR(device_fsm_state
, 0444, dev_fsm_show
, NULL
);
1481 static ssize_t
conn_fsm_show (struct device
*dev
,
1482 struct device_attribute
*attr
, char *buf
)
1484 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1486 IUCV_DBF_TEXT(trace
, 5, __func__
);
1487 return sysfs_emit(buf
, "%s\n", fsm_getstate_str(priv
->conn
->fsm
));
1490 static DEVICE_ATTR(connection_fsm_state
, 0444, conn_fsm_show
, NULL
);
1492 static ssize_t
maxmulti_show (struct device
*dev
,
1493 struct device_attribute
*attr
, char *buf
)
1495 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1497 IUCV_DBF_TEXT(trace
, 5, __func__
);
1498 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.maxmulti
);
1501 static ssize_t
maxmulti_write (struct device
*dev
,
1502 struct device_attribute
*attr
,
1503 const char *buf
, size_t count
)
1505 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1507 IUCV_DBF_TEXT(trace
, 4, __func__
);
1508 priv
->conn
->prof
.maxmulti
= 0;
1512 static DEVICE_ATTR(max_tx_buffer_used
, 0644, maxmulti_show
, maxmulti_write
);
1514 static ssize_t
maxcq_show (struct device
*dev
, struct device_attribute
*attr
,
1517 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1519 IUCV_DBF_TEXT(trace
, 5, __func__
);
1520 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.maxcqueue
);
1523 static ssize_t
maxcq_write (struct device
*dev
, struct device_attribute
*attr
,
1524 const char *buf
, size_t count
)
1526 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1528 IUCV_DBF_TEXT(trace
, 4, __func__
);
1529 priv
->conn
->prof
.maxcqueue
= 0;
1533 static DEVICE_ATTR(max_chained_skbs
, 0644, maxcq_show
, maxcq_write
);
1535 static ssize_t
sdoio_show (struct device
*dev
, struct device_attribute
*attr
,
1538 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1540 IUCV_DBF_TEXT(trace
, 5, __func__
);
1541 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.doios_single
);
1544 static ssize_t
sdoio_write (struct device
*dev
, struct device_attribute
*attr
,
1545 const char *buf
, size_t count
)
1547 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1549 IUCV_DBF_TEXT(trace
, 4, __func__
);
1550 priv
->conn
->prof
.doios_single
= 0;
1554 static DEVICE_ATTR(tx_single_write_ops
, 0644, sdoio_show
, sdoio_write
);
1556 static ssize_t
mdoio_show (struct device
*dev
, struct device_attribute
*attr
,
1559 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1561 IUCV_DBF_TEXT(trace
, 5, __func__
);
1562 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.doios_multi
);
1565 static ssize_t
mdoio_write (struct device
*dev
, struct device_attribute
*attr
,
1566 const char *buf
, size_t count
)
1568 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1570 IUCV_DBF_TEXT(trace
, 5, __func__
);
1571 priv
->conn
->prof
.doios_multi
= 0;
1575 static DEVICE_ATTR(tx_multi_write_ops
, 0644, mdoio_show
, mdoio_write
);
1577 static ssize_t
txlen_show (struct device
*dev
, struct device_attribute
*attr
,
1580 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1582 IUCV_DBF_TEXT(trace
, 5, __func__
);
1583 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.txlen
);
1586 static ssize_t
txlen_write (struct device
*dev
, struct device_attribute
*attr
,
1587 const char *buf
, size_t count
)
1589 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1591 IUCV_DBF_TEXT(trace
, 4, __func__
);
1592 priv
->conn
->prof
.txlen
= 0;
1596 static DEVICE_ATTR(netto_bytes
, 0644, txlen_show
, txlen_write
);
1598 static ssize_t
txtime_show (struct device
*dev
, struct device_attribute
*attr
,
1601 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1603 IUCV_DBF_TEXT(trace
, 5, __func__
);
1604 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.tx_time
);
1607 static ssize_t
txtime_write (struct device
*dev
, struct device_attribute
*attr
,
1608 const char *buf
, size_t count
)
1610 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1612 IUCV_DBF_TEXT(trace
, 4, __func__
);
1613 priv
->conn
->prof
.tx_time
= 0;
1617 static DEVICE_ATTR(max_tx_io_time
, 0644, txtime_show
, txtime_write
);
1619 static ssize_t
txpend_show (struct device
*dev
, struct device_attribute
*attr
,
1622 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1624 IUCV_DBF_TEXT(trace
, 5, __func__
);
1625 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.tx_pending
);
1628 static ssize_t
txpend_write (struct device
*dev
, struct device_attribute
*attr
,
1629 const char *buf
, size_t count
)
1631 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1633 IUCV_DBF_TEXT(trace
, 4, __func__
);
1634 priv
->conn
->prof
.tx_pending
= 0;
1638 static DEVICE_ATTR(tx_pending
, 0644, txpend_show
, txpend_write
);
1640 static ssize_t
txmpnd_show (struct device
*dev
, struct device_attribute
*attr
,
1643 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1645 IUCV_DBF_TEXT(trace
, 5, __func__
);
1646 return sysfs_emit(buf
, "%ld\n", priv
->conn
->prof
.tx_max_pending
);
1649 static ssize_t
txmpnd_write (struct device
*dev
, struct device_attribute
*attr
,
1650 const char *buf
, size_t count
)
1652 struct netiucv_priv
*priv
= dev_get_drvdata(dev
);
1654 IUCV_DBF_TEXT(trace
, 4, __func__
);
1655 priv
->conn
->prof
.tx_max_pending
= 0;
1659 static DEVICE_ATTR(tx_max_pending
, 0644, txmpnd_show
, txmpnd_write
);
1661 static struct attribute
*netiucv_attrs
[] = {
1662 &dev_attr_buffer
.attr
,
1663 &dev_attr_user
.attr
,
1667 static struct attribute_group netiucv_attr_group
= {
1668 .attrs
= netiucv_attrs
,
1671 static struct attribute
*netiucv_stat_attrs
[] = {
1672 &dev_attr_device_fsm_state
.attr
,
1673 &dev_attr_connection_fsm_state
.attr
,
1674 &dev_attr_max_tx_buffer_used
.attr
,
1675 &dev_attr_max_chained_skbs
.attr
,
1676 &dev_attr_tx_single_write_ops
.attr
,
1677 &dev_attr_tx_multi_write_ops
.attr
,
1678 &dev_attr_netto_bytes
.attr
,
1679 &dev_attr_max_tx_io_time
.attr
,
1680 &dev_attr_tx_pending
.attr
,
1681 &dev_attr_tx_max_pending
.attr
,
1685 static struct attribute_group netiucv_stat_attr_group
= {
1687 .attrs
= netiucv_stat_attrs
,
1690 static const struct attribute_group
*netiucv_attr_groups
[] = {
1691 &netiucv_stat_attr_group
,
1692 &netiucv_attr_group
,
1696 static int netiucv_register_device(struct net_device
*ndev
)
1698 struct netiucv_priv
*priv
= netdev_priv(ndev
);
1702 IUCV_DBF_TEXT(trace
, 3, __func__
);
1704 dev
= iucv_alloc_device(netiucv_attr_groups
, &netiucv_driver
, NULL
,
1705 "net%s", ndev
->name
);
1709 ret
= device_register(dev
);
1715 dev_set_drvdata(dev
, priv
);
1719 static void netiucv_unregister_device(struct device
*dev
)
1721 IUCV_DBF_TEXT(trace
, 3, __func__
);
1722 device_unregister(dev
);
1726 * Allocate and initialize a new connection structure.
1727 * Add it to the list of netiucv connections;
1729 static struct iucv_connection
*netiucv_new_connection(struct net_device
*dev
,
1733 struct iucv_connection
*conn
;
1735 conn
= kzalloc(sizeof(*conn
), GFP_KERNEL
);
1738 skb_queue_head_init(&conn
->collect_queue
);
1739 skb_queue_head_init(&conn
->commit_queue
);
1740 spin_lock_init(&conn
->collect_lock
);
1741 conn
->max_buffsize
= NETIUCV_BUFSIZE_DEFAULT
;
1744 conn
->rx_buff
= alloc_skb(conn
->max_buffsize
, GFP_KERNEL
| GFP_DMA
);
1747 conn
->tx_buff
= alloc_skb(conn
->max_buffsize
, GFP_KERNEL
| GFP_DMA
);
1750 conn
->fsm
= init_fsm("netiucvconn", conn_state_names
,
1751 conn_event_names
, NR_CONN_STATES
,
1752 NR_CONN_EVENTS
, conn_fsm
, CONN_FSM_LEN
,
1757 fsm_settimer(conn
->fsm
, &conn
->timer
);
1758 fsm_newstate(conn
->fsm
, CONN_STATE_INVALID
);
1761 memcpy(conn
->userdata
, userdata
, 17);
1763 memcpy(conn
->userid
, username
, 9);
1764 fsm_newstate(conn
->fsm
, CONN_STATE_STOPPED
);
1767 write_lock_bh(&iucv_connection_rwlock
);
1768 list_add_tail(&conn
->list
, &iucv_connection_list
);
1769 write_unlock_bh(&iucv_connection_rwlock
);
1773 kfree_skb(conn
->tx_buff
);
1775 kfree_skb(conn
->rx_buff
);
1783 * Release a connection structure and remove it from the
1784 * list of netiucv connections.
1786 static void netiucv_remove_connection(struct iucv_connection
*conn
)
1789 IUCV_DBF_TEXT(trace
, 3, __func__
);
1790 write_lock_bh(&iucv_connection_rwlock
);
1791 list_del_init(&conn
->list
);
1792 write_unlock_bh(&iucv_connection_rwlock
);
1793 fsm_deltimer(&conn
->timer
);
1794 netiucv_purge_skb_queue(&conn
->collect_queue
);
1796 iucv_path_sever(conn
->path
, conn
->userdata
);
1800 netiucv_purge_skb_queue(&conn
->commit_queue
);
1801 kfree_fsm(conn
->fsm
);
1802 kfree_skb(conn
->rx_buff
);
1803 kfree_skb(conn
->tx_buff
);
1807 * Release everything of a net device.
1809 static void netiucv_free_netdevice(struct net_device
*dev
)
1811 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1813 IUCV_DBF_TEXT(trace
, 3, __func__
);
1820 netiucv_remove_connection(privptr
->conn
);
1822 kfree_fsm(privptr
->fsm
);
1823 privptr
->conn
= NULL
; privptr
->fsm
= NULL
;
1824 /* privptr gets freed by free_netdev() */
1829 * Initialize a net device. (Called from kernel in alloc_netdev())
1831 static const struct net_device_ops netiucv_netdev_ops
= {
1832 .ndo_open
= netiucv_open
,
1833 .ndo_stop
= netiucv_close
,
1834 .ndo_get_stats
= netiucv_stats
,
1835 .ndo_start_xmit
= netiucv_tx
,
1838 static void netiucv_setup_netdevice(struct net_device
*dev
)
1840 dev
->mtu
= NETIUCV_MTU_DEFAULT
;
1842 dev
->max_mtu
= NETIUCV_MTU_MAX
;
1843 dev
->needs_free_netdev
= true;
1844 dev
->priv_destructor
= netiucv_free_netdevice
;
1845 dev
->hard_header_len
= NETIUCV_HDRLEN
;
1847 dev
->type
= ARPHRD_SLIP
;
1848 dev
->tx_queue_len
= NETIUCV_QUEUELEN_DEFAULT
;
1849 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
1850 dev
->netdev_ops
= &netiucv_netdev_ops
;
1854 * Allocate and initialize everything of a net device.
1856 static struct net_device
*netiucv_init_netdevice(char *username
, char *userdata
)
1858 struct netiucv_priv
*privptr
;
1859 struct net_device
*dev
;
1861 dev
= alloc_netdev(sizeof(struct netiucv_priv
), "iucv%d",
1862 NET_NAME_UNKNOWN
, netiucv_setup_netdevice
);
1866 if (dev_alloc_name(dev
, dev
->name
) < 0)
1869 privptr
= netdev_priv(dev
);
1870 privptr
->fsm
= init_fsm("netiucvdev", dev_state_names
,
1871 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
1872 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
1876 privptr
->conn
= netiucv_new_connection(dev
, username
, userdata
);
1877 if (!privptr
->conn
) {
1878 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_new_connection\n");
1881 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
1885 kfree_fsm(privptr
->fsm
);
1892 static ssize_t
connection_store(struct device_driver
*drv
, const char *buf
,
1898 struct net_device
*dev
;
1899 struct netiucv_priv
*priv
;
1900 struct iucv_connection
*cp
;
1902 IUCV_DBF_TEXT(trace
, 3, __func__
);
1903 rc
= netiucv_check_user(buf
, count
, username
, userdata
);
1907 read_lock_bh(&iucv_connection_rwlock
);
1908 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
1909 if (!strncmp(username
, cp
->userid
, 9) &&
1910 !strncmp(userdata
, cp
->userdata
, 17)) {
1911 read_unlock_bh(&iucv_connection_rwlock
);
1912 IUCV_DBF_TEXT_(setup
, 2, "conn_write: Connection to %s "
1913 "already exists\n", netiucv_printuser(cp
));
1917 read_unlock_bh(&iucv_connection_rwlock
);
1919 dev
= netiucv_init_netdevice(username
, userdata
);
1921 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_init_netdevice\n");
1925 rc
= netiucv_register_device(dev
);
1928 IUCV_DBF_TEXT_(setup
, 2,
1929 "ret %d from netiucv_register_device\n", rc
);
1934 priv
= netdev_priv(dev
);
1935 SET_NETDEV_DEV(dev
, priv
->dev
);
1937 rc
= register_netdevice(dev
);
1942 dev_info(priv
->dev
, "The IUCV interface to %s has been established "
1944 netiucv_printuser(priv
->conn
));
1949 netiucv_unregister_device(priv
->dev
);
1951 netiucv_free_netdevice(dev
);
1954 static DRIVER_ATTR_WO(connection
);
1956 static ssize_t
remove_store(struct device_driver
*drv
, const char *buf
,
1959 struct iucv_connection
*cp
;
1960 struct net_device
*ndev
;
1961 struct netiucv_priv
*priv
;
1963 char name
[IFNAMSIZ
];
1967 IUCV_DBF_TEXT(trace
, 3, __func__
);
1969 if (count
>= IFNAMSIZ
)
1970 count
= IFNAMSIZ
- 1;
1972 for (i
= 0, p
= buf
; i
< count
&& *p
; i
++, p
++) {
1973 if (*p
== '\n' || *p
== ' ')
1974 /* trailing lf, grr */
1980 read_lock_bh(&iucv_connection_rwlock
);
1981 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
1983 priv
= netdev_priv(ndev
);
1985 if (strncmp(name
, ndev
->name
, count
))
1987 read_unlock_bh(&iucv_connection_rwlock
);
1988 if (ndev
->flags
& (IFF_UP
| IFF_RUNNING
)) {
1989 dev_warn(dev
, "The IUCV device is connected"
1990 " to %s and cannot be removed\n",
1991 priv
->conn
->userid
);
1992 IUCV_DBF_TEXT(data
, 2, "remove_write: still active\n");
1995 unregister_netdev(ndev
);
1996 netiucv_unregister_device(dev
);
1999 read_unlock_bh(&iucv_connection_rwlock
);
2000 IUCV_DBF_TEXT(data
, 2, "remove_write: unknown device\n");
2003 static DRIVER_ATTR_WO(remove
);
2005 static struct attribute
* netiucv_drv_attrs
[] = {
2006 &driver_attr_connection
.attr
,
2007 &driver_attr_remove
.attr
,
2011 static struct attribute_group netiucv_drv_attr_group
= {
2012 .attrs
= netiucv_drv_attrs
,
2015 static const struct attribute_group
*netiucv_drv_attr_groups
[] = {
2016 &netiucv_drv_attr_group
,
2020 static void netiucv_banner(void)
2022 pr_info("driver initialized\n");
2025 static void __exit
netiucv_exit(void)
2027 struct iucv_connection
*cp
;
2028 struct net_device
*ndev
;
2029 struct netiucv_priv
*priv
;
2032 IUCV_DBF_TEXT(trace
, 3, __func__
);
2033 while (!list_empty(&iucv_connection_list
)) {
2034 cp
= list_entry(iucv_connection_list
.next
,
2035 struct iucv_connection
, list
);
2037 priv
= netdev_priv(ndev
);
2040 unregister_netdev(ndev
);
2041 netiucv_unregister_device(dev
);
2044 driver_unregister(&netiucv_driver
);
2045 iucv_unregister(&netiucv_handler
, 1);
2046 iucv_unregister_dbf_views();
2048 pr_info("driver unloaded\n");
2052 static int __init
netiucv_init(void)
2056 rc
= iucv_register_dbf_views();
2059 rc
= iucv_register(&netiucv_handler
, 1);
2062 IUCV_DBF_TEXT(trace
, 3, __func__
);
2063 netiucv_driver
.groups
= netiucv_drv_attr_groups
;
2064 rc
= driver_register(&netiucv_driver
);
2066 IUCV_DBF_TEXT_(setup
, 2, "ret %d from driver_register\n", rc
);
2074 iucv_unregister(&netiucv_handler
, 1);
2076 iucv_unregister_dbf_views();
2081 module_init(netiucv_init
);
2082 module_exit(netiucv_exit
);
2083 MODULE_LICENSE("GPL");