4 * Copyright 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
7 * Sysfs integration and all bugs therein by Cornelia Huck
8 * (cornelia.huck@de.ibm.com)
11 * the source of the original IUCV driver by:
12 * Stefan Hegewald <hegewald@de.ibm.com>
13 * Hartmut Penner <hpenner@de.ibm.com>
14 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
15 * Martin Schwidefsky (schwidefsky@de.ibm.com)
16 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/errno.h>
41 #include <linux/types.h>
42 #include <linux/interrupt.h>
43 #include <linux/timer.h>
44 #include <linux/sched.h>
45 #include <linux/bitops.h>
47 #include <linux/signal.h>
48 #include <linux/string.h>
49 #include <linux/device.h>
52 #include <linux/if_arp.h>
53 #include <linux/tcp.h>
54 #include <linux/skbuff.h>
55 #include <linux/ctype.h>
59 #include <asm/uaccess.h>
61 #include <net/iucv/iucv.h>
65 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
66 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
69 * Debug Facility stuff
71 #define IUCV_DBF_SETUP_NAME "iucv_setup"
72 #define IUCV_DBF_SETUP_LEN 32
73 #define IUCV_DBF_SETUP_PAGES 2
74 #define IUCV_DBF_SETUP_NR_AREAS 1
75 #define IUCV_DBF_SETUP_LEVEL 3
77 #define IUCV_DBF_DATA_NAME "iucv_data"
78 #define IUCV_DBF_DATA_LEN 128
79 #define IUCV_DBF_DATA_PAGES 2
80 #define IUCV_DBF_DATA_NR_AREAS 1
81 #define IUCV_DBF_DATA_LEVEL 2
83 #define IUCV_DBF_TRACE_NAME "iucv_trace"
84 #define IUCV_DBF_TRACE_LEN 16
85 #define IUCV_DBF_TRACE_PAGES 4
86 #define IUCV_DBF_TRACE_NR_AREAS 1
87 #define IUCV_DBF_TRACE_LEVEL 3
89 #define IUCV_DBF_TEXT(name,level,text) \
91 debug_text_event(iucv_dbf_##name,level,text); \
94 #define IUCV_DBF_HEX(name,level,addr,len) \
96 debug_event(iucv_dbf_##name,level,(void*)(addr),len); \
99 DECLARE_PER_CPU(char[256], iucv_dbf_txt_buf
);
101 #define IUCV_DBF_TEXT_(name,level,text...) \
103 char* iucv_dbf_txt_buf = get_cpu_var(iucv_dbf_txt_buf); \
104 sprintf(iucv_dbf_txt_buf, text); \
105 debug_text_event(iucv_dbf_##name,level,iucv_dbf_txt_buf); \
106 put_cpu_var(iucv_dbf_txt_buf); \
109 #define IUCV_DBF_SPRINTF(name,level,text...) \
111 debug_sprintf_event(iucv_dbf_trace, level, ##text ); \
112 debug_sprintf_event(iucv_dbf_trace, level, text ); \
116 * some more debug stuff
118 #define IUCV_HEXDUMP16(importance,header,ptr) \
119 PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
120 "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
121 *(((char*)ptr)),*(((char*)ptr)+1),*(((char*)ptr)+2), \
122 *(((char*)ptr)+3),*(((char*)ptr)+4),*(((char*)ptr)+5), \
123 *(((char*)ptr)+6),*(((char*)ptr)+7),*(((char*)ptr)+8), \
124 *(((char*)ptr)+9),*(((char*)ptr)+10),*(((char*)ptr)+11), \
125 *(((char*)ptr)+12),*(((char*)ptr)+13), \
126 *(((char*)ptr)+14),*(((char*)ptr)+15)); \
127 PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
128 "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
129 *(((char*)ptr)+16),*(((char*)ptr)+17), \
130 *(((char*)ptr)+18),*(((char*)ptr)+19), \
131 *(((char*)ptr)+20),*(((char*)ptr)+21), \
132 *(((char*)ptr)+22),*(((char*)ptr)+23), \
133 *(((char*)ptr)+24),*(((char*)ptr)+25), \
134 *(((char*)ptr)+26),*(((char*)ptr)+27), \
135 *(((char*)ptr)+28),*(((char*)ptr)+29), \
136 *(((char*)ptr)+30),*(((char*)ptr)+31));
138 static inline void iucv_hex_dump(unsigned char *buf
, size_t len
)
142 for (i
= 0; i
< len
; i
++) {
145 printk("%02x ", *(buf
+ i
));
150 #define PRINTK_HEADER " iucv: " /* for debugging */
152 static struct device_driver netiucv_driver
= {
157 static int netiucv_callback_connreq(struct iucv_path
*,
158 u8 ipvmid
[8], u8 ipuser
[16]);
159 static void netiucv_callback_connack(struct iucv_path
*, u8 ipuser
[16]);
160 static void netiucv_callback_connrej(struct iucv_path
*, u8 ipuser
[16]);
161 static void netiucv_callback_connsusp(struct iucv_path
*, u8 ipuser
[16]);
162 static void netiucv_callback_connres(struct iucv_path
*, u8 ipuser
[16]);
163 static void netiucv_callback_rx(struct iucv_path
*, struct iucv_message
*);
164 static void netiucv_callback_txdone(struct iucv_path
*, struct iucv_message
*);
166 static struct iucv_handler netiucv_handler
= {
167 .path_pending
= netiucv_callback_connreq
,
168 .path_complete
= netiucv_callback_connack
,
169 .path_severed
= netiucv_callback_connrej
,
170 .path_quiesced
= netiucv_callback_connsusp
,
171 .path_resumed
= netiucv_callback_connres
,
172 .message_pending
= netiucv_callback_rx
,
173 .message_complete
= netiucv_callback_txdone
177 * Per connection profiling data
179 struct connection_profile
{
180 unsigned long maxmulti
;
181 unsigned long maxcqueue
;
182 unsigned long doios_single
;
183 unsigned long doios_multi
;
185 unsigned long tx_time
;
186 struct timespec send_stamp
;
187 unsigned long tx_pending
;
188 unsigned long tx_max_pending
;
192 * Representation of one iucv connection
194 struct iucv_connection
{
195 struct list_head list
;
196 struct iucv_path
*path
;
197 struct sk_buff
*rx_buff
;
198 struct sk_buff
*tx_buff
;
199 struct sk_buff_head collect_queue
;
200 struct sk_buff_head commit_queue
;
201 spinlock_t collect_lock
;
206 struct net_device
*netdev
;
207 struct connection_profile prof
;
212 * Linked list of all connection structs.
214 static struct list_head iucv_connection_list
=
215 LIST_HEAD_INIT(iucv_connection_list
);
216 static rwlock_t iucv_connection_rwlock
= RW_LOCK_UNLOCKED
;
219 * Representation of event-data for the
220 * connection state machine.
223 struct iucv_connection
*conn
;
228 * Private part of the network device structure
230 struct netiucv_priv
{
231 struct net_device_stats stats
;
234 struct iucv_connection
*conn
;
239 * Link level header for a packet.
245 #define NETIUCV_HDRLEN (sizeof(struct ll_header))
246 #define NETIUCV_BUFSIZE_MAX 32768
247 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
248 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
249 #define NETIUCV_MTU_DEFAULT 9216
250 #define NETIUCV_QUEUELEN_DEFAULT 50
251 #define NETIUCV_TIMEOUT_5SEC 5000
254 * Compatibility macros for busy handling
255 * of network devices.
257 static inline void netiucv_clear_busy(struct net_device
*dev
)
259 struct netiucv_priv
*priv
= netdev_priv(dev
);
260 clear_bit(0, &priv
->tbusy
);
261 netif_wake_queue(dev
);
264 static inline int netiucv_test_and_set_busy(struct net_device
*dev
)
266 struct netiucv_priv
*priv
= netdev_priv(dev
);
267 netif_stop_queue(dev
);
268 return test_and_set_bit(0, &priv
->tbusy
);
271 static u8 iucvMagic
[16] = {
272 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
273 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
277 * Convert an iucv userId to its printable
278 * form (strip whitespace at end).
280 * @param An iucv userId
282 * @returns The printable string (static data!!)
284 static inline char *netiucv_printname(char *name
)
288 memcpy(tmp
, name
, 8);
290 while (*p
&& (!isspace(*p
)))
297 * States of the interface statemachine.
305 * MUST be always the last element!!
310 static const char *dev_state_names
[] = {
318 * Events of the interface statemachine.
326 * MUST be always the last element!!
331 static const char *dev_event_names
[] = {
339 * Events of the connection statemachine
343 * Events, representing callbacks from
344 * lowlevel iucv layer)
355 * Events, representing errors return codes from
356 * calls to lowlevel iucv layer
360 * Event, representing timer expiry.
365 * Events, representing commands from upper levels.
371 * MUST be always the last element!!
376 static const char *conn_event_names
[] = {
377 "Remote connection request",
378 "Remote connection acknowledge",
379 "Remote connection reject",
380 "Connection suspended",
381 "Connection resumed",
392 * States of the connection statemachine.
396 * Connection not assigned to any device,
397 * initial state, invalid
402 * Userid assigned but not operating
407 * Connection registered,
408 * no connection request sent yet,
409 * no connection request received
411 CONN_STATE_STARTWAIT
,
414 * Connection registered and connection request sent,
415 * no acknowledge and no connection request received yet.
417 CONN_STATE_SETUPWAIT
,
420 * Connection up and running idle
425 * Data sent, awaiting CONN_EVENT_TXDONE
430 * Error during registration.
435 * Error during registration.
440 * MUST be always the last element!!
445 static const char *conn_state_names
[] = {
453 "Registration error",
459 * Debug Facility Stuff
461 static debug_info_t
*iucv_dbf_setup
= NULL
;
462 static debug_info_t
*iucv_dbf_data
= NULL
;
463 static debug_info_t
*iucv_dbf_trace
= NULL
;
465 DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf
);
467 static void iucv_unregister_dbf_views(void)
470 debug_unregister(iucv_dbf_setup
);
472 debug_unregister(iucv_dbf_data
);
474 debug_unregister(iucv_dbf_trace
);
476 static int iucv_register_dbf_views(void)
478 iucv_dbf_setup
= debug_register(IUCV_DBF_SETUP_NAME
,
479 IUCV_DBF_SETUP_PAGES
,
480 IUCV_DBF_SETUP_NR_AREAS
,
482 iucv_dbf_data
= debug_register(IUCV_DBF_DATA_NAME
,
484 IUCV_DBF_DATA_NR_AREAS
,
486 iucv_dbf_trace
= debug_register(IUCV_DBF_TRACE_NAME
,
487 IUCV_DBF_TRACE_PAGES
,
488 IUCV_DBF_TRACE_NR_AREAS
,
491 if ((iucv_dbf_setup
== NULL
) || (iucv_dbf_data
== NULL
) ||
492 (iucv_dbf_trace
== NULL
)) {
493 iucv_unregister_dbf_views();
496 debug_register_view(iucv_dbf_setup
, &debug_hex_ascii_view
);
497 debug_set_level(iucv_dbf_setup
, IUCV_DBF_SETUP_LEVEL
);
499 debug_register_view(iucv_dbf_data
, &debug_hex_ascii_view
);
500 debug_set_level(iucv_dbf_data
, IUCV_DBF_DATA_LEVEL
);
502 debug_register_view(iucv_dbf_trace
, &debug_hex_ascii_view
);
503 debug_set_level(iucv_dbf_trace
, IUCV_DBF_TRACE_LEVEL
);
509 * Callback-wrappers, called from lowlevel iucv layer.
512 static void netiucv_callback_rx(struct iucv_path
*path
,
513 struct iucv_message
*msg
)
515 struct iucv_connection
*conn
= path
->private;
516 struct iucv_event ev
;
520 fsm_event(conn
->fsm
, CONN_EVENT_RX
, &ev
);
523 static void netiucv_callback_txdone(struct iucv_path
*path
,
524 struct iucv_message
*msg
)
526 struct iucv_connection
*conn
= path
->private;
527 struct iucv_event ev
;
531 fsm_event(conn
->fsm
, CONN_EVENT_TXDONE
, &ev
);
534 static void netiucv_callback_connack(struct iucv_path
*path
, u8 ipuser
[16])
536 struct iucv_connection
*conn
= path
->private;
538 fsm_event(conn
->fsm
, CONN_EVENT_CONN_ACK
, conn
);
541 static int netiucv_callback_connreq(struct iucv_path
*path
,
542 u8 ipvmid
[8], u8 ipuser
[16])
544 struct iucv_connection
*conn
= path
->private;
545 struct iucv_event ev
;
548 if (memcmp(iucvMagic
, ipuser
, sizeof(ipuser
)))
549 /* ipuser must match iucvMagic. */
552 read_lock_bh(&iucv_connection_rwlock
);
553 list_for_each_entry(conn
, &iucv_connection_list
, list
) {
554 if (strncmp(ipvmid
, conn
->userid
, 8))
556 /* Found a matching connection for this path. */
560 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REQ
, &ev
);
563 read_unlock_bh(&iucv_connection_rwlock
);
567 static void netiucv_callback_connrej(struct iucv_path
*path
, u8 ipuser
[16])
569 struct iucv_connection
*conn
= path
->private;
571 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REJ
, conn
);
574 static void netiucv_callback_connsusp(struct iucv_path
*path
, u8 ipuser
[16])
576 struct iucv_connection
*conn
= path
->private;
578 fsm_event(conn
->fsm
, CONN_EVENT_CONN_SUS
, conn
);
581 static void netiucv_callback_connres(struct iucv_path
*path
, u8 ipuser
[16])
583 struct iucv_connection
*conn
= path
->private;
585 fsm_event(conn
->fsm
, CONN_EVENT_CONN_RES
, conn
);
589 * Dummy NOP action for all statemachines
591 static void fsm_action_nop(fsm_instance
*fi
, int event
, void *arg
)
596 * Actions of the connection statemachine
601 * @conn: The connection where this skb has been received.
602 * @pskb: The received skb.
604 * Unpack a just received skb and hand it over to upper layers.
605 * Helper function for conn_action_rx.
607 static void netiucv_unpack_skb(struct iucv_connection
*conn
,
608 struct sk_buff
*pskb
)
610 struct net_device
*dev
= conn
->netdev
;
611 struct netiucv_priv
*privptr
= netdev_priv(dev
);
614 skb_put(pskb
, NETIUCV_HDRLEN
);
616 pskb
->ip_summed
= CHECKSUM_NONE
;
617 pskb
->protocol
= ntohs(ETH_P_IP
);
621 struct ll_header
*header
= (struct ll_header
*) pskb
->data
;
626 skb_pull(pskb
, NETIUCV_HDRLEN
);
627 header
->next
-= offset
;
628 offset
+= header
->next
;
629 header
->next
-= NETIUCV_HDRLEN
;
630 if (skb_tailroom(pskb
) < header
->next
) {
631 PRINT_WARN("%s: Illegal next field in iucv header: "
633 dev
->name
, header
->next
, skb_tailroom(pskb
));
634 IUCV_DBF_TEXT_(data
, 2, "Illegal next field: %d > %d\n",
635 header
->next
, skb_tailroom(pskb
));
638 skb_put(pskb
, header
->next
);
639 pskb
->mac
.raw
= pskb
->data
;
640 skb
= dev_alloc_skb(pskb
->len
);
642 PRINT_WARN("%s Out of memory in netiucv_unpack_skb\n",
644 IUCV_DBF_TEXT(data
, 2,
645 "Out of memory in netiucv_unpack_skb\n");
646 privptr
->stats
.rx_dropped
++;
649 memcpy(skb_put(skb
, pskb
->len
), pskb
->data
, pskb
->len
);
650 skb
->mac
.raw
= skb
->data
;
651 skb
->dev
= pskb
->dev
;
652 skb
->protocol
= pskb
->protocol
;
653 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
655 * Since receiving is always initiated from a tasklet (in iucv.c),
656 * we must use netif_rx_ni() instead of netif_rx()
659 dev
->last_rx
= jiffies
;
660 privptr
->stats
.rx_packets
++;
661 privptr
->stats
.rx_bytes
+= skb
->len
;
662 skb_pull(pskb
, header
->next
);
663 skb_put(pskb
, NETIUCV_HDRLEN
);
667 static void conn_action_rx(fsm_instance
*fi
, int event
, void *arg
)
669 struct iucv_event
*ev
= arg
;
670 struct iucv_connection
*conn
= ev
->conn
;
671 struct iucv_message
*msg
= ev
->data
;
672 struct netiucv_priv
*privptr
= netdev_priv(conn
->netdev
);
675 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
678 iucv_message_reject(conn
->path
, msg
);
679 PRINT_WARN("Received data for unlinked connection\n");
680 IUCV_DBF_TEXT(data
, 2,
681 "Received data for unlinked connection\n");
684 if (msg
->length
> conn
->max_buffsize
) {
685 iucv_message_reject(conn
->path
, msg
);
686 privptr
->stats
.rx_dropped
++;
687 PRINT_WARN("msglen %d > max_buffsize %d\n",
688 msg
->length
, conn
->max_buffsize
);
689 IUCV_DBF_TEXT_(data
, 2, "msglen %d > max_buffsize %d\n",
690 msg
->length
, conn
->max_buffsize
);
693 conn
->rx_buff
->data
= conn
->rx_buff
->tail
= conn
->rx_buff
->head
;
694 conn
->rx_buff
->len
= 0;
695 rc
= iucv_message_receive(conn
->path
, msg
, 0, conn
->rx_buff
->data
,
697 if (rc
|| msg
->length
< 5) {
698 privptr
->stats
.rx_errors
++;
699 PRINT_WARN("iucv_receive returned %08x\n", rc
);
700 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_receive\n", rc
);
703 netiucv_unpack_skb(conn
, conn
->rx_buff
);
706 static void conn_action_txdone(fsm_instance
*fi
, int event
, void *arg
)
708 struct iucv_event
*ev
= arg
;
709 struct iucv_connection
*conn
= ev
->conn
;
710 struct iucv_message
*msg
= ev
->data
;
711 struct iucv_message txmsg
;
712 struct netiucv_priv
*privptr
= NULL
;
713 u32 single_flag
= msg
->tag
;
718 unsigned long saveflags
;
719 struct ll_header header
;
722 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
724 if (conn
&& conn
->netdev
)
725 privptr
= netdev_priv(conn
->netdev
);
726 conn
->prof
.tx_pending
--;
728 if ((skb
= skb_dequeue(&conn
->commit_queue
))) {
729 atomic_dec(&skb
->users
);
730 dev_kfree_skb_any(skb
);
732 privptr
->stats
.tx_packets
++;
733 privptr
->stats
.tx_bytes
+=
734 (skb
->len
- NETIUCV_HDRLEN
739 conn
->tx_buff
->data
= conn
->tx_buff
->tail
= conn
->tx_buff
->head
;
740 conn
->tx_buff
->len
= 0;
741 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
742 while ((skb
= skb_dequeue(&conn
->collect_queue
))) {
743 header
.next
= conn
->tx_buff
->len
+ skb
->len
+ NETIUCV_HDRLEN
;
744 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
746 memcpy(skb_put(conn
->tx_buff
, skb
->len
), skb
->data
, skb
->len
);
750 atomic_dec(&skb
->users
);
751 dev_kfree_skb_any(skb
);
753 if (conn
->collect_len
> conn
->prof
.maxmulti
)
754 conn
->prof
.maxmulti
= conn
->collect_len
;
755 conn
->collect_len
= 0;
756 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
757 if (conn
->tx_buff
->len
== 0) {
758 fsm_newstate(fi
, CONN_STATE_IDLE
);
763 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
764 conn
->prof
.send_stamp
= xtime
;
767 rc
= iucv_message_send(conn
->path
, &txmsg
, 0, 0,
768 conn
->tx_buff
->data
, conn
->tx_buff
->len
);
769 conn
->prof
.doios_multi
++;
770 conn
->prof
.txlen
+= conn
->tx_buff
->len
;
771 conn
->prof
.tx_pending
++;
772 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
773 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
775 conn
->prof
.tx_pending
--;
776 fsm_newstate(fi
, CONN_STATE_IDLE
);
778 privptr
->stats
.tx_errors
+= txpackets
;
779 PRINT_WARN("iucv_send returned %08x\n", rc
);
780 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
783 privptr
->stats
.tx_packets
+= txpackets
;
784 privptr
->stats
.tx_bytes
+= txbytes
;
786 if (stat_maxcq
> conn
->prof
.maxcqueue
)
787 conn
->prof
.maxcqueue
= stat_maxcq
;
791 static void conn_action_connaccept(fsm_instance
*fi
, int event
, void *arg
)
793 struct iucv_event
*ev
= arg
;
794 struct iucv_connection
*conn
= ev
->conn
;
795 struct iucv_path
*path
= ev
->data
;
796 struct net_device
*netdev
= conn
->netdev
;
797 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
800 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
803 path
->msglim
= NETIUCV_QUEUELEN_DEFAULT
;
805 rc
= iucv_path_accept(path
, &netiucv_handler
, NULL
, conn
);
807 PRINT_WARN("%s: IUCV accept failed with error %d\n",
809 IUCV_DBF_TEXT_(setup
, 2, "rc %d from iucv_accept", rc
);
812 fsm_newstate(fi
, CONN_STATE_IDLE
);
813 netdev
->tx_queue_len
= conn
->path
->msglim
;
814 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
817 static void conn_action_connreject(fsm_instance
*fi
, int event
, void *arg
)
819 struct iucv_event
*ev
= arg
;
820 struct iucv_path
*path
= ev
->data
;
822 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
823 iucv_path_sever(path
, NULL
);
826 static void conn_action_connack(fsm_instance
*fi
, int event
, void *arg
)
828 struct iucv_connection
*conn
= arg
;
829 struct net_device
*netdev
= conn
->netdev
;
830 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
832 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
833 fsm_deltimer(&conn
->timer
);
834 fsm_newstate(fi
, CONN_STATE_IDLE
);
835 netdev
->tx_queue_len
= conn
->path
->msglim
;
836 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
839 static void conn_action_conntimsev(fsm_instance
*fi
, int event
, void *arg
)
841 struct iucv_connection
*conn
= arg
;
843 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
844 fsm_deltimer(&conn
->timer
);
845 iucv_path_sever(conn
->path
, NULL
);
846 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
849 static void conn_action_connsever(fsm_instance
*fi
, int event
, void *arg
)
851 struct iucv_connection
*conn
= arg
;
852 struct net_device
*netdev
= conn
->netdev
;
853 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
855 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
857 fsm_deltimer(&conn
->timer
);
858 iucv_path_sever(conn
->path
, NULL
);
859 PRINT_INFO("%s: Remote dropped connection\n", netdev
->name
);
860 IUCV_DBF_TEXT(data
, 2,
861 "conn_action_connsever: Remote dropped connection\n");
862 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
863 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
866 static void conn_action_start(fsm_instance
*fi
, int event
, void *arg
)
868 struct iucv_connection
*conn
= arg
;
871 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
873 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
874 PRINT_DEBUG("%s('%s'): connecting ...\n",
875 conn
->netdev
->name
, conn
->userid
);
878 * We must set the state before calling iucv_connect because the
879 * callback handler could be called at any point after the connection
883 fsm_newstate(fi
, CONN_STATE_SETUPWAIT
);
884 conn
->path
= iucv_path_alloc(NETIUCV_QUEUELEN_DEFAULT
, 0, GFP_KERNEL
);
885 rc
= iucv_path_connect(conn
->path
, &netiucv_handler
, conn
->userid
,
886 NULL
, iucvMagic
, conn
);
889 conn
->netdev
->tx_queue_len
= conn
->path
->msglim
;
890 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
891 CONN_EVENT_TIMER
, conn
);
894 PRINT_INFO("%s: User %s is currently not available.\n",
896 netiucv_printname(conn
->userid
));
897 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
900 PRINT_INFO("%s: User %s is currently not ready.\n",
902 netiucv_printname(conn
->userid
));
903 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
906 PRINT_WARN("%s: Too many IUCV connections.\n",
908 fsm_newstate(fi
, CONN_STATE_CONNERR
);
911 PRINT_WARN("%s: User %s has too many IUCV connections.\n",
913 netiucv_printname(conn
->userid
));
914 fsm_newstate(fi
, CONN_STATE_CONNERR
);
917 PRINT_WARN("%s: No IUCV authorization in CP directory.\n",
919 fsm_newstate(fi
, CONN_STATE_CONNERR
);
922 PRINT_WARN("%s: iucv_connect returned error %d\n",
923 conn
->netdev
->name
, rc
);
924 fsm_newstate(fi
, CONN_STATE_CONNERR
);
927 IUCV_DBF_TEXT_(setup
, 5, "iucv_connect rc is %d\n", rc
);
932 static void netiucv_purge_skb_queue(struct sk_buff_head
*q
)
936 while ((skb
= skb_dequeue(q
))) {
937 atomic_dec(&skb
->users
);
938 dev_kfree_skb_any(skb
);
942 static void conn_action_stop(fsm_instance
*fi
, int event
, void *arg
)
944 struct iucv_event
*ev
= arg
;
945 struct iucv_connection
*conn
= ev
->conn
;
946 struct net_device
*netdev
= conn
->netdev
;
947 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
949 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
951 fsm_deltimer(&conn
->timer
);
952 fsm_newstate(fi
, CONN_STATE_STOPPED
);
953 netiucv_purge_skb_queue(&conn
->collect_queue
);
955 IUCV_DBF_TEXT(trace
, 5, "calling iucv_path_sever\n");
956 iucv_path_sever(conn
->path
, iucvMagic
);
960 netiucv_purge_skb_queue(&conn
->commit_queue
);
961 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
964 static void conn_action_inval(fsm_instance
*fi
, int event
, void *arg
)
966 struct iucv_connection
*conn
= arg
;
967 struct net_device
*netdev
= conn
->netdev
;
969 PRINT_WARN("%s: Cannot connect without username\n", netdev
->name
);
970 IUCV_DBF_TEXT(data
, 2, "conn_action_inval called\n");
973 static const fsm_node conn_fsm
[] = {
974 { CONN_STATE_INVALID
, CONN_EVENT_START
, conn_action_inval
},
975 { CONN_STATE_STOPPED
, CONN_EVENT_START
, conn_action_start
},
977 { CONN_STATE_STOPPED
, CONN_EVENT_STOP
, conn_action_stop
},
978 { CONN_STATE_STARTWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
979 { CONN_STATE_SETUPWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
980 { CONN_STATE_IDLE
, CONN_EVENT_STOP
, conn_action_stop
},
981 { CONN_STATE_TX
, CONN_EVENT_STOP
, conn_action_stop
},
982 { CONN_STATE_REGERR
, CONN_EVENT_STOP
, conn_action_stop
},
983 { CONN_STATE_CONNERR
, CONN_EVENT_STOP
, conn_action_stop
},
985 { CONN_STATE_STOPPED
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
986 { CONN_STATE_STARTWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
987 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
988 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
989 { CONN_STATE_TX
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
991 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_ACK
, conn_action_connack
},
992 { CONN_STATE_SETUPWAIT
, CONN_EVENT_TIMER
, conn_action_conntimsev
},
994 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
995 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
996 { CONN_STATE_TX
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
998 { CONN_STATE_IDLE
, CONN_EVENT_RX
, conn_action_rx
},
999 { CONN_STATE_TX
, CONN_EVENT_RX
, conn_action_rx
},
1001 { CONN_STATE_TX
, CONN_EVENT_TXDONE
, conn_action_txdone
},
1002 { CONN_STATE_IDLE
, CONN_EVENT_TXDONE
, conn_action_txdone
},
1005 static const int CONN_FSM_LEN
= sizeof(conn_fsm
) / sizeof(fsm_node
);
1009 * Actions for interface - statemachine.
1014 * @fi: An instance of an interface statemachine.
1015 * @event: The event, just happened.
1016 * @arg: Generic pointer, casted from struct net_device * upon call.
1018 * Startup connection by sending CONN_EVENT_START to it.
1020 static void dev_action_start(fsm_instance
*fi
, int event
, void *arg
)
1022 struct net_device
*dev
= arg
;
1023 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1025 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1027 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1028 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, privptr
->conn
);
1032 * Shutdown connection by sending CONN_EVENT_STOP to it.
1034 * @param fi An instance of an interface statemachine.
1035 * @param event The event, just happened.
1036 * @param arg Generic pointer, casted from struct net_device * upon call.
1039 dev_action_stop(fsm_instance
*fi
, int event
, void *arg
)
1041 struct net_device
*dev
= arg
;
1042 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1043 struct iucv_event ev
;
1045 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1047 ev
.conn
= privptr
->conn
;
1049 fsm_newstate(fi
, DEV_STATE_STOPWAIT
);
1050 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_STOP
, &ev
);
1054 * Called from connection statemachine
1055 * when a connection is up and running.
1057 * @param fi An instance of an interface statemachine.
1058 * @param event The event, just happened.
1059 * @param arg Generic pointer, casted from struct net_device * upon call.
1062 dev_action_connup(fsm_instance
*fi
, int event
, void *arg
)
1064 struct net_device
*dev
= arg
;
1065 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1067 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1069 switch (fsm_getstate(fi
)) {
1070 case DEV_STATE_STARTWAIT
:
1071 fsm_newstate(fi
, DEV_STATE_RUNNING
);
1072 PRINT_INFO("%s: connected with remote side %s\n",
1073 dev
->name
, privptr
->conn
->userid
);
1074 IUCV_DBF_TEXT(setup
, 3,
1075 "connection is up and running\n");
1077 case DEV_STATE_STOPWAIT
:
1079 "%s: got connection UP event during shutdown!\n",
1081 IUCV_DBF_TEXT(data
, 2,
1082 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1088 * Called from connection statemachine
1089 * when a connection has been shutdown.
1091 * @param fi An instance of an interface statemachine.
1092 * @param event The event, just happened.
1093 * @param arg Generic pointer, casted from struct net_device * upon call.
1096 dev_action_conndown(fsm_instance
*fi
, int event
, void *arg
)
1098 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1100 switch (fsm_getstate(fi
)) {
1101 case DEV_STATE_RUNNING
:
1102 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1104 case DEV_STATE_STOPWAIT
:
1105 fsm_newstate(fi
, DEV_STATE_STOPPED
);
1106 IUCV_DBF_TEXT(setup
, 3, "connection is down\n");
1111 static const fsm_node dev_fsm
[] = {
1112 { DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
1114 { DEV_STATE_STOPWAIT
, DEV_EVENT_START
, dev_action_start
},
1115 { DEV_STATE_STOPWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1117 { DEV_STATE_STARTWAIT
, DEV_EVENT_STOP
, dev_action_stop
},
1118 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONUP
, dev_action_connup
},
1120 { DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
1121 { DEV_STATE_RUNNING
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1122 { DEV_STATE_RUNNING
, DEV_EVENT_CONUP
, fsm_action_nop
},
1125 static const int DEV_FSM_LEN
= sizeof(dev_fsm
) / sizeof(fsm_node
);
1128 * Transmit a packet.
1129 * This is a helper function for netiucv_tx().
1131 * @param conn Connection to be used for sending.
1132 * @param skb Pointer to struct sk_buff of packet to send.
1133 * The linklevel header has already been set up
1136 * @return 0 on success, -ERRNO on failure. (Never fails.)
1138 static int netiucv_transmit_skb(struct iucv_connection
*conn
,
1139 struct sk_buff
*skb
)
1141 struct iucv_message msg
;
1142 unsigned long saveflags
;
1143 struct ll_header header
;
1146 if (fsm_getstate(conn
->fsm
) != CONN_STATE_IDLE
) {
1147 int l
= skb
->len
+ NETIUCV_HDRLEN
;
1149 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
1150 if (conn
->collect_len
+ l
>
1151 (conn
->max_buffsize
- NETIUCV_HDRLEN
)) {
1153 IUCV_DBF_TEXT(data
, 2,
1154 "EBUSY from netiucv_transmit_skb\n");
1156 atomic_inc(&skb
->users
);
1157 skb_queue_tail(&conn
->collect_queue
, skb
);
1158 conn
->collect_len
+= l
;
1161 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
1163 struct sk_buff
*nskb
= skb
;
1165 * Copy the skb to a new allocated skb in lowmem only if the
1166 * data is located above 2G in memory or tailroom is < 2.
1169 ((unsigned long)(skb
->tail
+ NETIUCV_HDRLEN
)) >> 31;
1171 if (hi
|| (skb_tailroom(skb
) < 2)) {
1172 nskb
= alloc_skb(skb
->len
+ NETIUCV_HDRLEN
+
1173 NETIUCV_HDRLEN
, GFP_ATOMIC
| GFP_DMA
);
1175 PRINT_WARN("%s: Could not allocate tx_skb\n",
1176 conn
->netdev
->name
);
1177 IUCV_DBF_TEXT(data
, 2, "alloc_skb failed\n");
1181 skb_reserve(nskb
, NETIUCV_HDRLEN
);
1182 memcpy(skb_put(nskb
, skb
->len
),
1183 skb
->data
, skb
->len
);
1188 * skb now is below 2G and has enough room. Add headers.
1190 header
.next
= nskb
->len
+ NETIUCV_HDRLEN
;
1191 memcpy(skb_push(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1193 memcpy(skb_put(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1195 fsm_newstate(conn
->fsm
, CONN_STATE_TX
);
1196 conn
->prof
.send_stamp
= xtime
;
1200 rc
= iucv_message_send(conn
->path
, &msg
, 0, 0,
1201 nskb
->data
, nskb
->len
);
1202 conn
->prof
.doios_single
++;
1203 conn
->prof
.txlen
+= skb
->len
;
1204 conn
->prof
.tx_pending
++;
1205 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
1206 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
1208 struct netiucv_priv
*privptr
;
1209 fsm_newstate(conn
->fsm
, CONN_STATE_IDLE
);
1210 conn
->prof
.tx_pending
--;
1211 privptr
= netdev_priv(conn
->netdev
);
1213 privptr
->stats
.tx_errors
++;
1215 dev_kfree_skb(nskb
);
1218 * Remove our headers. They get added
1219 * again on retransmit.
1221 skb_pull(skb
, NETIUCV_HDRLEN
);
1222 skb_trim(skb
, skb
->len
- NETIUCV_HDRLEN
);
1224 PRINT_WARN("iucv_send returned %08x\n", rc
);
1225 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
1229 atomic_inc(&nskb
->users
);
1230 skb_queue_tail(&conn
->commit_queue
, nskb
);
1238 * Interface API for upper network layers
1242 * Open an interface.
1243 * Called from generic network layer when ifconfig up is run.
1245 * @param dev Pointer to interface struct.
1247 * @return 0 on success, -ERRNO on failure. (Never fails.)
1249 static int netiucv_open(struct net_device
*dev
)
1251 struct netiucv_priv
*priv
= netdev_priv(dev
);
1253 fsm_event(priv
->fsm
, DEV_EVENT_START
, dev
);
1258 * Close an interface.
1259 * Called from generic network layer when ifconfig down is run.
1261 * @param dev Pointer to interface struct.
1263 * @return 0 on success, -ERRNO on failure. (Never fails.)
1265 static int netiucv_close(struct net_device
*dev
)
1267 struct netiucv_priv
*priv
= netdev_priv(dev
);
1269 fsm_event(priv
->fsm
, DEV_EVENT_STOP
, dev
);
1274 * Start transmission of a packet.
1275 * Called from generic network device layer.
1277 * @param skb Pointer to buffer containing the packet.
1278 * @param dev Pointer to interface struct.
1280 * @return 0 if packet consumed, !0 if packet rejected.
1281 * Note: If we return !0, then the packet is free'd by
1282 * the generic network layer.
1284 static int netiucv_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1286 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1289 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1291 * Some sanity checks ...
1294 PRINT_WARN("%s: NULL sk_buff passed\n", dev
->name
);
1295 IUCV_DBF_TEXT(data
, 2, "netiucv_tx: skb is NULL\n");
1296 privptr
->stats
.tx_dropped
++;
1299 if (skb_headroom(skb
) < NETIUCV_HDRLEN
) {
1300 PRINT_WARN("%s: Got sk_buff with head room < %ld bytes\n",
1301 dev
->name
, NETIUCV_HDRLEN
);
1302 IUCV_DBF_TEXT(data
, 2,
1303 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1305 privptr
->stats
.tx_dropped
++;
1310 * If connection is not running, try to restart it
1311 * and throw away packet.
1313 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
1314 fsm_event(privptr
->fsm
, DEV_EVENT_START
, dev
);
1316 privptr
->stats
.tx_dropped
++;
1317 privptr
->stats
.tx_errors
++;
1318 privptr
->stats
.tx_carrier_errors
++;
1322 if (netiucv_test_and_set_busy(dev
)) {
1323 IUCV_DBF_TEXT(data
, 2, "EBUSY from netiucv_tx\n");
1326 dev
->trans_start
= jiffies
;
1327 rc
= netiucv_transmit_skb(privptr
->conn
, skb
) != 0;
1328 netiucv_clear_busy(dev
);
1334 * @dev: Pointer to interface struct.
1336 * Returns interface statistics of a device.
1338 * Returns pointer to stats struct of this interface.
1340 static struct net_device_stats
*netiucv_stats (struct net_device
* dev
)
1342 struct netiucv_priv
*priv
= netdev_priv(dev
);
1344 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1345 return &priv
->stats
;
1349 * netiucv_change_mtu
1350 * @dev: Pointer to interface struct.
1351 * @new_mtu: The new MTU to use for this interface.
1353 * Sets MTU of an interface.
1355 * Returns 0 on success, -EINVAL if MTU is out of valid range.
1356 * (valid range is 576 .. NETIUCV_MTU_MAX).
1358 static int netiucv_change_mtu(struct net_device
* dev
, int new_mtu
)
1360 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1361 if (new_mtu
< 576 || new_mtu
> NETIUCV_MTU_MAX
) {
1362 IUCV_DBF_TEXT(setup
, 2, "given MTU out of valid range\n");
1370 * attributes in sysfs
1373 static ssize_t
user_show(struct device
*dev
, struct device_attribute
*attr
,
1376 struct netiucv_priv
*priv
= dev
->driver_data
;
1378 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1379 return sprintf(buf
, "%s\n", netiucv_printname(priv
->conn
->userid
));
1382 static ssize_t
user_write(struct device
*dev
, struct device_attribute
*attr
,
1383 const char *buf
, size_t count
)
1385 struct netiucv_priv
*priv
= dev
->driver_data
;
1386 struct net_device
*ndev
= priv
->conn
->netdev
;
1391 struct iucv_connection
*cp
;
1393 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1395 PRINT_WARN("netiucv: username too long (%d)!\n", (int) count
);
1396 IUCV_DBF_TEXT_(setup
, 2,
1397 "%d is length of username\n", (int) count
);
1401 tmp
= strsep((char **) &buf
, "\n");
1402 for (i
= 0, p
= tmp
; i
< 8 && *p
; i
++, p
++) {
1403 if (isalnum(*p
) || (*p
== '$')) {
1404 username
[i
]= toupper(*p
);
1408 /* trailing lf, grr */
1411 PRINT_WARN("netiucv: Invalid char %c in username!\n", *p
);
1412 IUCV_DBF_TEXT_(setup
, 2,
1413 "username: invalid character %c\n", *p
);
1417 username
[i
++] = ' ';
1420 if (memcmp(username
, priv
->conn
->userid
, 9) &&
1421 (ndev
->flags
& (IFF_UP
| IFF_RUNNING
))) {
1422 /* username changed while the interface is active. */
1423 PRINT_WARN("netiucv: device %s active, connected to %s\n",
1424 dev
->bus_id
, priv
->conn
->userid
);
1425 PRINT_WARN("netiucv: user cannot be updated\n");
1426 IUCV_DBF_TEXT(setup
, 2, "user_write: device active\n");
1429 read_lock_bh(&iucv_connection_rwlock
);
1430 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
1431 if (!strncmp(username
, cp
->userid
, 9) && cp
->netdev
!= ndev
) {
1432 read_unlock_bh(&iucv_connection_rwlock
);
1433 PRINT_WARN("netiucv: Connection to %s already "
1434 "exists\n", username
);
1438 read_unlock_bh(&iucv_connection_rwlock
);
1439 memcpy(priv
->conn
->userid
, username
, 9);
1443 static DEVICE_ATTR(user
, 0644, user_show
, user_write
);
1445 static ssize_t
buffer_show (struct device
*dev
, struct device_attribute
*attr
,
1447 { struct netiucv_priv
*priv
= dev
->driver_data
;
1449 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1450 return sprintf(buf
, "%d\n", priv
->conn
->max_buffsize
);
1453 static ssize_t
buffer_write (struct device
*dev
, struct device_attribute
*attr
,
1454 const char *buf
, size_t count
)
1456 struct netiucv_priv
*priv
= dev
->driver_data
;
1457 struct net_device
*ndev
= priv
->conn
->netdev
;
1461 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1465 bs1
= simple_strtoul(buf
, &e
, 0);
1467 if (e
&& (!isspace(*e
))) {
1468 PRINT_WARN("netiucv: Invalid character in buffer!\n");
1469 IUCV_DBF_TEXT_(setup
, 2, "buffer_write: invalid char %c\n", *e
);
1472 if (bs1
> NETIUCV_BUFSIZE_MAX
) {
1473 PRINT_WARN("netiucv: Given buffer size %d too large.\n",
1475 IUCV_DBF_TEXT_(setup
, 2,
1476 "buffer_write: buffer size %d too large\n",
1480 if ((ndev
->flags
& IFF_RUNNING
) &&
1481 (bs1
< (ndev
->mtu
+ NETIUCV_HDRLEN
+ 2))) {
1482 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1484 IUCV_DBF_TEXT_(setup
, 2,
1485 "buffer_write: buffer size %d too small\n",
1489 if (bs1
< (576 + NETIUCV_HDRLEN
+ NETIUCV_HDRLEN
)) {
1490 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1492 IUCV_DBF_TEXT_(setup
, 2,
1493 "buffer_write: buffer size %d too small\n",
1498 priv
->conn
->max_buffsize
= bs1
;
1499 if (!(ndev
->flags
& IFF_RUNNING
))
1500 ndev
->mtu
= bs1
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
;
1506 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
1508 static ssize_t
dev_fsm_show (struct device
*dev
, struct device_attribute
*attr
,
1511 struct netiucv_priv
*priv
= dev
->driver_data
;
1513 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1514 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->fsm
));
1517 static DEVICE_ATTR(device_fsm_state
, 0444, dev_fsm_show
, NULL
);
1519 static ssize_t
conn_fsm_show (struct device
*dev
,
1520 struct device_attribute
*attr
, char *buf
)
1522 struct netiucv_priv
*priv
= dev
->driver_data
;
1524 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1525 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->conn
->fsm
));
1528 static DEVICE_ATTR(connection_fsm_state
, 0444, conn_fsm_show
, NULL
);
1530 static ssize_t
maxmulti_show (struct device
*dev
,
1531 struct device_attribute
*attr
, char *buf
)
1533 struct netiucv_priv
*priv
= dev
->driver_data
;
1535 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1536 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxmulti
);
1539 static ssize_t
maxmulti_write (struct device
*dev
,
1540 struct device_attribute
*attr
,
1541 const char *buf
, size_t count
)
1543 struct netiucv_priv
*priv
= dev
->driver_data
;
1545 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1546 priv
->conn
->prof
.maxmulti
= 0;
1550 static DEVICE_ATTR(max_tx_buffer_used
, 0644, maxmulti_show
, maxmulti_write
);
1552 static ssize_t
maxcq_show (struct device
*dev
, struct device_attribute
*attr
,
1555 struct netiucv_priv
*priv
= dev
->driver_data
;
1557 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1558 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxcqueue
);
1561 static ssize_t
maxcq_write (struct device
*dev
, struct device_attribute
*attr
,
1562 const char *buf
, size_t count
)
1564 struct netiucv_priv
*priv
= dev
->driver_data
;
1566 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1567 priv
->conn
->prof
.maxcqueue
= 0;
1571 static DEVICE_ATTR(max_chained_skbs
, 0644, maxcq_show
, maxcq_write
);
1573 static ssize_t
sdoio_show (struct device
*dev
, struct device_attribute
*attr
,
1576 struct netiucv_priv
*priv
= dev
->driver_data
;
1578 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1579 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_single
);
1582 static ssize_t
sdoio_write (struct device
*dev
, struct device_attribute
*attr
,
1583 const char *buf
, size_t count
)
1585 struct netiucv_priv
*priv
= dev
->driver_data
;
1587 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1588 priv
->conn
->prof
.doios_single
= 0;
1592 static DEVICE_ATTR(tx_single_write_ops
, 0644, sdoio_show
, sdoio_write
);
1594 static ssize_t
mdoio_show (struct device
*dev
, struct device_attribute
*attr
,
1597 struct netiucv_priv
*priv
= dev
->driver_data
;
1599 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1600 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_multi
);
1603 static ssize_t
mdoio_write (struct device
*dev
, struct device_attribute
*attr
,
1604 const char *buf
, size_t count
)
1606 struct netiucv_priv
*priv
= dev
->driver_data
;
1608 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1609 priv
->conn
->prof
.doios_multi
= 0;
1613 static DEVICE_ATTR(tx_multi_write_ops
, 0644, mdoio_show
, mdoio_write
);
1615 static ssize_t
txlen_show (struct device
*dev
, struct device_attribute
*attr
,
1618 struct netiucv_priv
*priv
= dev
->driver_data
;
1620 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1621 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.txlen
);
1624 static ssize_t
txlen_write (struct device
*dev
, struct device_attribute
*attr
,
1625 const char *buf
, size_t count
)
1627 struct netiucv_priv
*priv
= dev
->driver_data
;
1629 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1630 priv
->conn
->prof
.txlen
= 0;
1634 static DEVICE_ATTR(netto_bytes
, 0644, txlen_show
, txlen_write
);
1636 static ssize_t
txtime_show (struct device
*dev
, struct device_attribute
*attr
,
1639 struct netiucv_priv
*priv
= dev
->driver_data
;
1641 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1642 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_time
);
1645 static ssize_t
txtime_write (struct device
*dev
, struct device_attribute
*attr
,
1646 const char *buf
, size_t count
)
1648 struct netiucv_priv
*priv
= dev
->driver_data
;
1650 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1651 priv
->conn
->prof
.tx_time
= 0;
1655 static DEVICE_ATTR(max_tx_io_time
, 0644, txtime_show
, txtime_write
);
1657 static ssize_t
txpend_show (struct device
*dev
, struct device_attribute
*attr
,
1660 struct netiucv_priv
*priv
= dev
->driver_data
;
1662 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1663 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_pending
);
1666 static ssize_t
txpend_write (struct device
*dev
, struct device_attribute
*attr
,
1667 const char *buf
, size_t count
)
1669 struct netiucv_priv
*priv
= dev
->driver_data
;
1671 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1672 priv
->conn
->prof
.tx_pending
= 0;
1676 static DEVICE_ATTR(tx_pending
, 0644, txpend_show
, txpend_write
);
1678 static ssize_t
txmpnd_show (struct device
*dev
, struct device_attribute
*attr
,
1681 struct netiucv_priv
*priv
= dev
->driver_data
;
1683 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1684 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_max_pending
);
1687 static ssize_t
txmpnd_write (struct device
*dev
, struct device_attribute
*attr
,
1688 const char *buf
, size_t count
)
1690 struct netiucv_priv
*priv
= dev
->driver_data
;
1692 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1693 priv
->conn
->prof
.tx_max_pending
= 0;
1697 static DEVICE_ATTR(tx_max_pending
, 0644, txmpnd_show
, txmpnd_write
);
1699 static struct attribute
*netiucv_attrs
[] = {
1700 &dev_attr_buffer
.attr
,
1701 &dev_attr_user
.attr
,
1705 static struct attribute_group netiucv_attr_group
= {
1706 .attrs
= netiucv_attrs
,
1709 static struct attribute
*netiucv_stat_attrs
[] = {
1710 &dev_attr_device_fsm_state
.attr
,
1711 &dev_attr_connection_fsm_state
.attr
,
1712 &dev_attr_max_tx_buffer_used
.attr
,
1713 &dev_attr_max_chained_skbs
.attr
,
1714 &dev_attr_tx_single_write_ops
.attr
,
1715 &dev_attr_tx_multi_write_ops
.attr
,
1716 &dev_attr_netto_bytes
.attr
,
1717 &dev_attr_max_tx_io_time
.attr
,
1718 &dev_attr_tx_pending
.attr
,
1719 &dev_attr_tx_max_pending
.attr
,
1723 static struct attribute_group netiucv_stat_attr_group
= {
1725 .attrs
= netiucv_stat_attrs
,
1728 static inline int netiucv_add_files(struct device
*dev
)
1732 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1733 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_attr_group
);
1736 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1738 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1742 static inline void netiucv_remove_files(struct device
*dev
)
1744 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1745 sysfs_remove_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1746 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1749 static int netiucv_register_device(struct net_device
*ndev
)
1751 struct netiucv_priv
*priv
= netdev_priv(ndev
);
1752 struct device
*dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1756 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1759 snprintf(dev
->bus_id
, BUS_ID_SIZE
, "net%s", ndev
->name
);
1760 dev
->bus
= &iucv_bus
;
1761 dev
->parent
= iucv_root
;
1763 * The release function could be called after the
1764 * module has been unloaded. It's _only_ task is to
1765 * free the struct. Therefore, we specify kfree()
1766 * directly here. (Probably a little bit obfuscating
1767 * but legitime ...).
1769 dev
->release
= (void (*)(struct device
*))kfree
;
1770 dev
->driver
= &netiucv_driver
;
1774 ret
= device_register(dev
);
1778 ret
= netiucv_add_files(dev
);
1782 dev
->driver_data
= priv
;
1786 device_unregister(dev
);
1790 static void netiucv_unregister_device(struct device
*dev
)
1792 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1793 netiucv_remove_files(dev
);
1794 device_unregister(dev
);
1798 * Allocate and initialize a new connection structure.
1799 * Add it to the list of netiucv connections;
1801 static struct iucv_connection
*netiucv_new_connection(struct net_device
*dev
,
1804 struct iucv_connection
*conn
;
1806 conn
= kzalloc(sizeof(*conn
), GFP_KERNEL
);
1809 skb_queue_head_init(&conn
->collect_queue
);
1810 skb_queue_head_init(&conn
->commit_queue
);
1811 spin_lock_init(&conn
->collect_lock
);
1812 conn
->max_buffsize
= NETIUCV_BUFSIZE_DEFAULT
;
1815 conn
->rx_buff
= alloc_skb(conn
->max_buffsize
, GFP_KERNEL
| GFP_DMA
);
1818 conn
->tx_buff
= alloc_skb(conn
->max_buffsize
, GFP_KERNEL
| GFP_DMA
);
1821 conn
->fsm
= init_fsm("netiucvconn", conn_state_names
,
1822 conn_event_names
, NR_CONN_STATES
,
1823 NR_CONN_EVENTS
, conn_fsm
, CONN_FSM_LEN
,
1828 fsm_settimer(conn
->fsm
, &conn
->timer
);
1829 fsm_newstate(conn
->fsm
, CONN_STATE_INVALID
);
1832 memcpy(conn
->userid
, username
, 9);
1833 fsm_newstate(conn
->fsm
, CONN_STATE_STOPPED
);
1836 write_lock_bh(&iucv_connection_rwlock
);
1837 list_add_tail(&conn
->list
, &iucv_connection_list
);
1838 write_unlock_bh(&iucv_connection_rwlock
);
1842 kfree_skb(conn
->tx_buff
);
1844 kfree_skb(conn
->rx_buff
);
1852 * Release a connection structure and remove it from the
1853 * list of netiucv connections.
1855 static void netiucv_remove_connection(struct iucv_connection
*conn
)
1857 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1858 write_lock_bh(&iucv_connection_rwlock
);
1859 list_del_init(&conn
->list
);
1860 write_unlock_bh(&iucv_connection_rwlock
);
1862 iucv_path_sever(conn
->path
, iucvMagic
);
1866 fsm_deltimer(&conn
->timer
);
1867 kfree_fsm(conn
->fsm
);
1868 kfree_skb(conn
->rx_buff
);
1869 kfree_skb(conn
->tx_buff
);
1873 * Release everything of a net device.
1875 static void netiucv_free_netdevice(struct net_device
*dev
)
1877 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1879 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1886 netiucv_remove_connection(privptr
->conn
);
1888 kfree_fsm(privptr
->fsm
);
1889 privptr
->conn
= NULL
; privptr
->fsm
= NULL
;
1890 /* privptr gets freed by free_netdev() */
1896 * Initialize a net device. (Called from kernel in alloc_netdev())
1898 static void netiucv_setup_netdevice(struct net_device
*dev
)
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
*netiucv_init_netdevice(char *username
)
1920 struct netiucv_priv
*privptr
;
1921 struct net_device
*dev
;
1923 dev
= alloc_netdev(sizeof(struct netiucv_priv
), "iucv%d",
1924 netiucv_setup_netdevice
);
1927 if (dev_alloc_name(dev
, dev
->name
) < 0)
1930 privptr
= netdev_priv(dev
);
1931 privptr
->fsm
= init_fsm("netiucvdev", dev_state_names
,
1932 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
1933 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
1937 privptr
->conn
= netiucv_new_connection(dev
, username
);
1938 if (!privptr
->conn
) {
1939 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_new_connection\n");
1942 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
1946 kfree_fsm(privptr
->fsm
);
1952 static ssize_t
conn_write(struct device_driver
*drv
,
1953 const char *buf
, size_t count
)
1958 struct net_device
*dev
;
1959 struct netiucv_priv
*priv
;
1960 struct iucv_connection
*cp
;
1962 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1964 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count
);
1965 IUCV_DBF_TEXT(setup
, 2, "conn_write: too long\n");
1969 for (i
= 0, p
= buf
; i
< 8 && *p
; i
++, p
++) {
1970 if (isalnum(*p
) || *p
== '$') {
1971 username
[i
] = toupper(*p
);
1975 /* trailing lf, grr */
1977 PRINT_WARN("netiucv: Invalid character in username!\n");
1978 IUCV_DBF_TEXT_(setup
, 2,
1979 "conn_write: invalid character %c\n", *p
);
1983 username
[i
++] = ' ';
1986 read_lock_bh(&iucv_connection_rwlock
);
1987 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
1988 if (!strncmp(username
, cp
->userid
, 9)) {
1989 read_unlock_bh(&iucv_connection_rwlock
);
1990 PRINT_WARN("netiucv: Connection to %s already "
1991 "exists\n", username
);
1995 read_unlock_bh(&iucv_connection_rwlock
);
1997 dev
= netiucv_init_netdevice(username
);
1999 PRINT_WARN("netiucv: Could not allocate network device "
2000 "structure for user '%s'\n",
2001 netiucv_printname(username
));
2002 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_init_netdevice\n");
2006 rc
= netiucv_register_device(dev
);
2008 IUCV_DBF_TEXT_(setup
, 2,
2009 "ret %d from netiucv_register_device\n", rc
);
2014 priv
= netdev_priv(dev
);
2015 SET_NETDEV_DEV(dev
, priv
->dev
);
2017 rc
= register_netdev(dev
);
2021 PRINT_INFO("%s: '%s'\n", dev
->name
, netiucv_printname(username
));
2026 netiucv_unregister_device(priv
->dev
);
2028 PRINT_WARN("netiucv: Could not register '%s'\n", dev
->name
);
2029 IUCV_DBF_TEXT(setup
, 2, "conn_write: could not register\n");
2030 netiucv_free_netdevice(dev
);
2034 static DRIVER_ATTR(connection
, 0200, NULL
, conn_write
);
2036 static ssize_t
remove_write (struct device_driver
*drv
,
2037 const char *buf
, size_t count
)
2039 struct iucv_connection
*cp
;
2040 struct net_device
*ndev
;
2041 struct netiucv_priv
*priv
;
2043 char name
[IFNAMSIZ
];
2047 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2049 if (count
>= IFNAMSIZ
)
2050 count
= IFNAMSIZ
- 1;;
2052 for (i
= 0, p
= buf
; i
< count
&& *p
; i
++, p
++) {
2053 if (*p
== '\n' || *p
== ' ')
2054 /* trailing lf, grr */
2060 read_lock_bh(&iucv_connection_rwlock
);
2061 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
2063 priv
= netdev_priv(ndev
);
2065 if (strncmp(name
, ndev
->name
, count
))
2067 read_unlock_bh(&iucv_connection_rwlock
);
2068 if (ndev
->flags
& (IFF_UP
| IFF_RUNNING
)) {
2069 PRINT_WARN("netiucv: net device %s active with peer "
2070 "%s\n", ndev
->name
, priv
->conn
->userid
);
2071 PRINT_WARN("netiucv: %s cannot be removed\n",
2073 IUCV_DBF_TEXT(data
, 2, "remove_write: still active\n");
2076 unregister_netdev(ndev
);
2077 netiucv_unregister_device(dev
);
2080 read_unlock_bh(&iucv_connection_rwlock
);
2081 PRINT_WARN("netiucv: net device %s unknown\n", name
);
2082 IUCV_DBF_TEXT(data
, 2, "remove_write: unknown device\n");
2086 static DRIVER_ATTR(remove
, 0200, NULL
, remove_write
);
2088 static struct attribute
* netiucv_drv_attrs
[] = {
2089 &driver_attr_connection
.attr
,
2090 &driver_attr_remove
.attr
,
2094 static struct attribute_group netiucv_drv_attr_group
= {
2095 .attrs
= netiucv_drv_attrs
,
2098 static void netiucv_banner(void)
2100 PRINT_INFO("NETIUCV driver initialized\n");
2103 static void __exit
netiucv_exit(void)
2105 struct iucv_connection
*cp
;
2106 struct net_device
*ndev
;
2107 struct netiucv_priv
*priv
;
2110 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2111 while (!list_empty(&iucv_connection_list
)) {
2112 cp
= list_entry(iucv_connection_list
.next
,
2113 struct iucv_connection
, list
);
2114 list_del(&cp
->list
);
2116 priv
= netdev_priv(ndev
);
2119 unregister_netdev(ndev
);
2120 netiucv_unregister_device(dev
);
2123 sysfs_remove_group(&netiucv_driver
.kobj
, &netiucv_drv_attr_group
);
2124 driver_unregister(&netiucv_driver
);
2125 iucv_unregister(&netiucv_handler
, 1);
2126 iucv_unregister_dbf_views();
2128 PRINT_INFO("NETIUCV driver unloaded\n");
2132 static int __init
netiucv_init(void)
2136 rc
= iucv_register_dbf_views();
2139 rc
= iucv_register(&netiucv_handler
, 1);
2142 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2143 rc
= driver_register(&netiucv_driver
);
2145 PRINT_ERR("NETIUCV: failed to register driver.\n");
2146 IUCV_DBF_TEXT_(setup
, 2, "ret %d from driver_register\n", rc
);
2150 rc
= sysfs_create_group(&netiucv_driver
.kobj
, &netiucv_drv_attr_group
);
2152 PRINT_ERR("NETIUCV: failed to add driver attributes.\n");
2153 IUCV_DBF_TEXT_(setup
, 2,
2154 "ret %d - netiucv_drv_attr_group\n", rc
);
2161 driver_unregister(&netiucv_driver
);
2163 iucv_unregister(&netiucv_handler
, 1);
2165 iucv_unregister_dbf_views();
2170 module_init(netiucv_init
);
2171 module_exit(netiucv_exit
);
2172 MODULE_LICENSE("GPL");