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/bitops.h>
46 #include <linux/signal.h>
47 #include <linux/string.h>
48 #include <linux/device.h>
51 #include <linux/if_arp.h>
52 #include <linux/tcp.h>
53 #include <linux/skbuff.h>
54 #include <linux/ctype.h>
58 #include <asm/uaccess.h>
60 #include <net/iucv/iucv.h>
64 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
65 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
68 * Debug Facility stuff
70 #define IUCV_DBF_SETUP_NAME "iucv_setup"
71 #define IUCV_DBF_SETUP_LEN 32
72 #define IUCV_DBF_SETUP_PAGES 2
73 #define IUCV_DBF_SETUP_NR_AREAS 1
74 #define IUCV_DBF_SETUP_LEVEL 3
76 #define IUCV_DBF_DATA_NAME "iucv_data"
77 #define IUCV_DBF_DATA_LEN 128
78 #define IUCV_DBF_DATA_PAGES 2
79 #define IUCV_DBF_DATA_NR_AREAS 1
80 #define IUCV_DBF_DATA_LEVEL 2
82 #define IUCV_DBF_TRACE_NAME "iucv_trace"
83 #define IUCV_DBF_TRACE_LEN 16
84 #define IUCV_DBF_TRACE_PAGES 4
85 #define IUCV_DBF_TRACE_NR_AREAS 1
86 #define IUCV_DBF_TRACE_LEVEL 3
88 #define IUCV_DBF_TEXT(name,level,text) \
90 debug_text_event(iucv_dbf_##name,level,text); \
93 #define IUCV_DBF_HEX(name,level,addr,len) \
95 debug_event(iucv_dbf_##name,level,(void*)(addr),len); \
98 DECLARE_PER_CPU(char[256], iucv_dbf_txt_buf
);
100 #define IUCV_DBF_TEXT_(name,level,text...) \
102 char* iucv_dbf_txt_buf = get_cpu_var(iucv_dbf_txt_buf); \
103 sprintf(iucv_dbf_txt_buf, text); \
104 debug_text_event(iucv_dbf_##name,level,iucv_dbf_txt_buf); \
105 put_cpu_var(iucv_dbf_txt_buf); \
108 #define IUCV_DBF_SPRINTF(name,level,text...) \
110 debug_sprintf_event(iucv_dbf_trace, level, ##text ); \
111 debug_sprintf_event(iucv_dbf_trace, level, text ); \
115 * some more debug stuff
117 #define IUCV_HEXDUMP16(importance,header,ptr) \
118 PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
119 "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
120 *(((char*)ptr)),*(((char*)ptr)+1),*(((char*)ptr)+2), \
121 *(((char*)ptr)+3),*(((char*)ptr)+4),*(((char*)ptr)+5), \
122 *(((char*)ptr)+6),*(((char*)ptr)+7),*(((char*)ptr)+8), \
123 *(((char*)ptr)+9),*(((char*)ptr)+10),*(((char*)ptr)+11), \
124 *(((char*)ptr)+12),*(((char*)ptr)+13), \
125 *(((char*)ptr)+14),*(((char*)ptr)+15)); \
126 PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
127 "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
128 *(((char*)ptr)+16),*(((char*)ptr)+17), \
129 *(((char*)ptr)+18),*(((char*)ptr)+19), \
130 *(((char*)ptr)+20),*(((char*)ptr)+21), \
131 *(((char*)ptr)+22),*(((char*)ptr)+23), \
132 *(((char*)ptr)+24),*(((char*)ptr)+25), \
133 *(((char*)ptr)+26),*(((char*)ptr)+27), \
134 *(((char*)ptr)+28),*(((char*)ptr)+29), \
135 *(((char*)ptr)+30),*(((char*)ptr)+31));
137 static inline void iucv_hex_dump(unsigned char *buf
, size_t len
)
141 for (i
= 0; i
< len
; i
++) {
144 printk("%02x ", *(buf
+ i
));
149 #define PRINTK_HEADER " iucv: " /* for debugging */
151 static struct device_driver netiucv_driver
= {
156 static int netiucv_callback_connreq(struct iucv_path
*,
157 u8 ipvmid
[8], u8 ipuser
[16]);
158 static void netiucv_callback_connack(struct iucv_path
*, u8 ipuser
[16]);
159 static void netiucv_callback_connrej(struct iucv_path
*, u8 ipuser
[16]);
160 static void netiucv_callback_connsusp(struct iucv_path
*, u8 ipuser
[16]);
161 static void netiucv_callback_connres(struct iucv_path
*, u8 ipuser
[16]);
162 static void netiucv_callback_rx(struct iucv_path
*, struct iucv_message
*);
163 static void netiucv_callback_txdone(struct iucv_path
*, struct iucv_message
*);
165 static struct iucv_handler netiucv_handler
= {
166 .path_pending
= netiucv_callback_connreq
,
167 .path_complete
= netiucv_callback_connack
,
168 .path_severed
= netiucv_callback_connrej
,
169 .path_quiesced
= netiucv_callback_connsusp
,
170 .path_resumed
= netiucv_callback_connres
,
171 .message_pending
= netiucv_callback_rx
,
172 .message_complete
= netiucv_callback_txdone
176 * Per connection profiling data
178 struct connection_profile
{
179 unsigned long maxmulti
;
180 unsigned long maxcqueue
;
181 unsigned long doios_single
;
182 unsigned long doios_multi
;
184 unsigned long tx_time
;
185 struct timespec send_stamp
;
186 unsigned long tx_pending
;
187 unsigned long tx_max_pending
;
191 * Representation of one iucv connection
193 struct iucv_connection
{
194 struct list_head list
;
195 struct iucv_path
*path
;
196 struct sk_buff
*rx_buff
;
197 struct sk_buff
*tx_buff
;
198 struct sk_buff_head collect_queue
;
199 struct sk_buff_head commit_queue
;
200 spinlock_t collect_lock
;
205 struct net_device
*netdev
;
206 struct connection_profile prof
;
211 * Linked list of all connection structs.
213 static struct list_head iucv_connection_list
=
214 LIST_HEAD_INIT(iucv_connection_list
);
215 static DEFINE_RWLOCK(iucv_connection_rwlock
);
218 * Representation of event-data for the
219 * connection state machine.
222 struct iucv_connection
*conn
;
227 * Private part of the network device structure
229 struct netiucv_priv
{
230 struct net_device_stats stats
;
233 struct iucv_connection
*conn
;
238 * Link level header for a packet.
244 #define NETIUCV_HDRLEN (sizeof(struct ll_header))
245 #define NETIUCV_BUFSIZE_MAX 32768
246 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
247 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
248 #define NETIUCV_MTU_DEFAULT 9216
249 #define NETIUCV_QUEUELEN_DEFAULT 50
250 #define NETIUCV_TIMEOUT_5SEC 5000
253 * Compatibility macros for busy handling
254 * of network devices.
256 static inline void netiucv_clear_busy(struct net_device
*dev
)
258 struct netiucv_priv
*priv
= netdev_priv(dev
);
259 clear_bit(0, &priv
->tbusy
);
260 netif_wake_queue(dev
);
263 static inline int netiucv_test_and_set_busy(struct net_device
*dev
)
265 struct netiucv_priv
*priv
= netdev_priv(dev
);
266 netif_stop_queue(dev
);
267 return test_and_set_bit(0, &priv
->tbusy
);
270 static u8 iucvMagic
[16] = {
271 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
272 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
276 * Convert an iucv userId to its printable
277 * form (strip whitespace at end).
279 * @param An iucv userId
281 * @returns The printable string (static data!!)
283 static inline char *netiucv_printname(char *name
)
287 memcpy(tmp
, name
, 8);
289 while (*p
&& (!isspace(*p
)))
296 * States of the interface statemachine.
304 * MUST be always the last element!!
309 static const char *dev_state_names
[] = {
317 * Events of the interface statemachine.
325 * MUST be always the last element!!
330 static const char *dev_event_names
[] = {
338 * Events of the connection statemachine
342 * Events, representing callbacks from
343 * lowlevel iucv layer)
354 * Events, representing errors return codes from
355 * calls to lowlevel iucv layer
359 * Event, representing timer expiry.
364 * Events, representing commands from upper levels.
370 * MUST be always the last element!!
375 static const char *conn_event_names
[] = {
376 "Remote connection request",
377 "Remote connection acknowledge",
378 "Remote connection reject",
379 "Connection suspended",
380 "Connection resumed",
391 * States of the connection statemachine.
395 * Connection not assigned to any device,
396 * initial state, invalid
401 * Userid assigned but not operating
406 * Connection registered,
407 * no connection request sent yet,
408 * no connection request received
410 CONN_STATE_STARTWAIT
,
413 * Connection registered and connection request sent,
414 * no acknowledge and no connection request received yet.
416 CONN_STATE_SETUPWAIT
,
419 * Connection up and running idle
424 * Data sent, awaiting CONN_EVENT_TXDONE
429 * Error during registration.
434 * Error during registration.
439 * MUST be always the last element!!
444 static const char *conn_state_names
[] = {
452 "Registration error",
458 * Debug Facility Stuff
460 static debug_info_t
*iucv_dbf_setup
= NULL
;
461 static debug_info_t
*iucv_dbf_data
= NULL
;
462 static debug_info_t
*iucv_dbf_trace
= NULL
;
464 DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf
);
466 static void iucv_unregister_dbf_views(void)
469 debug_unregister(iucv_dbf_setup
);
471 debug_unregister(iucv_dbf_data
);
473 debug_unregister(iucv_dbf_trace
);
475 static int iucv_register_dbf_views(void)
477 iucv_dbf_setup
= debug_register(IUCV_DBF_SETUP_NAME
,
478 IUCV_DBF_SETUP_PAGES
,
479 IUCV_DBF_SETUP_NR_AREAS
,
481 iucv_dbf_data
= debug_register(IUCV_DBF_DATA_NAME
,
483 IUCV_DBF_DATA_NR_AREAS
,
485 iucv_dbf_trace
= debug_register(IUCV_DBF_TRACE_NAME
,
486 IUCV_DBF_TRACE_PAGES
,
487 IUCV_DBF_TRACE_NR_AREAS
,
490 if ((iucv_dbf_setup
== NULL
) || (iucv_dbf_data
== NULL
) ||
491 (iucv_dbf_trace
== NULL
)) {
492 iucv_unregister_dbf_views();
495 debug_register_view(iucv_dbf_setup
, &debug_hex_ascii_view
);
496 debug_set_level(iucv_dbf_setup
, IUCV_DBF_SETUP_LEVEL
);
498 debug_register_view(iucv_dbf_data
, &debug_hex_ascii_view
);
499 debug_set_level(iucv_dbf_data
, IUCV_DBF_DATA_LEVEL
);
501 debug_register_view(iucv_dbf_trace
, &debug_hex_ascii_view
);
502 debug_set_level(iucv_dbf_trace
, IUCV_DBF_TRACE_LEVEL
);
508 * Callback-wrappers, called from lowlevel iucv layer.
511 static void netiucv_callback_rx(struct iucv_path
*path
,
512 struct iucv_message
*msg
)
514 struct iucv_connection
*conn
= path
->private;
515 struct iucv_event ev
;
519 fsm_event(conn
->fsm
, CONN_EVENT_RX
, &ev
);
522 static void netiucv_callback_txdone(struct iucv_path
*path
,
523 struct iucv_message
*msg
)
525 struct iucv_connection
*conn
= path
->private;
526 struct iucv_event ev
;
530 fsm_event(conn
->fsm
, CONN_EVENT_TXDONE
, &ev
);
533 static void netiucv_callback_connack(struct iucv_path
*path
, u8 ipuser
[16])
535 struct iucv_connection
*conn
= path
->private;
537 fsm_event(conn
->fsm
, CONN_EVENT_CONN_ACK
, conn
);
540 static int netiucv_callback_connreq(struct iucv_path
*path
,
541 u8 ipvmid
[8], u8 ipuser
[16])
543 struct iucv_connection
*conn
= path
->private;
544 struct iucv_event ev
;
547 if (memcmp(iucvMagic
, ipuser
, sizeof(ipuser
)))
548 /* ipuser must match iucvMagic. */
551 read_lock_bh(&iucv_connection_rwlock
);
552 list_for_each_entry(conn
, &iucv_connection_list
, list
) {
553 if (strncmp(ipvmid
, conn
->userid
, 8))
555 /* Found a matching connection for this path. */
559 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REQ
, &ev
);
562 read_unlock_bh(&iucv_connection_rwlock
);
566 static void netiucv_callback_connrej(struct iucv_path
*path
, u8 ipuser
[16])
568 struct iucv_connection
*conn
= path
->private;
570 fsm_event(conn
->fsm
, CONN_EVENT_CONN_REJ
, conn
);
573 static void netiucv_callback_connsusp(struct iucv_path
*path
, u8 ipuser
[16])
575 struct iucv_connection
*conn
= path
->private;
577 fsm_event(conn
->fsm
, CONN_EVENT_CONN_SUS
, conn
);
580 static void netiucv_callback_connres(struct iucv_path
*path
, u8 ipuser
[16])
582 struct iucv_connection
*conn
= path
->private;
584 fsm_event(conn
->fsm
, CONN_EVENT_CONN_RES
, conn
);
588 * Dummy NOP action for all statemachines
590 static void fsm_action_nop(fsm_instance
*fi
, int event
, void *arg
)
595 * Actions of the connection statemachine
600 * @conn: The connection where this skb has been received.
601 * @pskb: The received skb.
603 * Unpack a just received skb and hand it over to upper layers.
604 * Helper function for conn_action_rx.
606 static void netiucv_unpack_skb(struct iucv_connection
*conn
,
607 struct sk_buff
*pskb
)
609 struct net_device
*dev
= conn
->netdev
;
610 struct netiucv_priv
*privptr
= netdev_priv(dev
);
613 skb_put(pskb
, NETIUCV_HDRLEN
);
615 pskb
->ip_summed
= CHECKSUM_NONE
;
616 pskb
->protocol
= ntohs(ETH_P_IP
);
620 struct ll_header
*header
= (struct ll_header
*) pskb
->data
;
625 skb_pull(pskb
, NETIUCV_HDRLEN
);
626 header
->next
-= offset
;
627 offset
+= header
->next
;
628 header
->next
-= NETIUCV_HDRLEN
;
629 if (skb_tailroom(pskb
) < header
->next
) {
630 PRINT_WARN("%s: Illegal next field in iucv header: "
632 dev
->name
, header
->next
, skb_tailroom(pskb
));
633 IUCV_DBF_TEXT_(data
, 2, "Illegal next field: %d > %d\n",
634 header
->next
, skb_tailroom(pskb
));
637 skb_put(pskb
, header
->next
);
638 skb_reset_mac_header(pskb
);
639 skb
= dev_alloc_skb(pskb
->len
);
641 PRINT_WARN("%s Out of memory in netiucv_unpack_skb\n",
643 IUCV_DBF_TEXT(data
, 2,
644 "Out of memory in netiucv_unpack_skb\n");
645 privptr
->stats
.rx_dropped
++;
648 skb_copy_from_linear_data(pskb
, skb_put(skb
, pskb
->len
),
650 skb_reset_mac_header(skb
);
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
->head
;
694 skb_reset_tail_pointer(conn
->rx_buff
);
695 conn
->rx_buff
->len
= 0;
696 rc
= iucv_message_receive(conn
->path
, msg
, 0, conn
->rx_buff
->data
,
698 if (rc
|| msg
->length
< 5) {
699 privptr
->stats
.rx_errors
++;
700 PRINT_WARN("iucv_receive returned %08x\n", rc
);
701 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_receive\n", rc
);
704 netiucv_unpack_skb(conn
, conn
->rx_buff
);
707 static void conn_action_txdone(fsm_instance
*fi
, int event
, void *arg
)
709 struct iucv_event
*ev
= arg
;
710 struct iucv_connection
*conn
= ev
->conn
;
711 struct iucv_message
*msg
= ev
->data
;
712 struct iucv_message txmsg
;
713 struct netiucv_priv
*privptr
= NULL
;
714 u32 single_flag
= msg
->tag
;
719 unsigned long saveflags
;
720 struct ll_header header
;
723 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
725 if (conn
&& conn
->netdev
)
726 privptr
= netdev_priv(conn
->netdev
);
727 conn
->prof
.tx_pending
--;
729 if ((skb
= skb_dequeue(&conn
->commit_queue
))) {
730 atomic_dec(&skb
->users
);
731 dev_kfree_skb_any(skb
);
733 privptr
->stats
.tx_packets
++;
734 privptr
->stats
.tx_bytes
+=
735 (skb
->len
- NETIUCV_HDRLEN
740 conn
->tx_buff
->data
= conn
->tx_buff
->head
;
741 skb_reset_tail_pointer(conn
->tx_buff
);
742 conn
->tx_buff
->len
= 0;
743 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
744 while ((skb
= skb_dequeue(&conn
->collect_queue
))) {
745 header
.next
= conn
->tx_buff
->len
+ skb
->len
+ NETIUCV_HDRLEN
;
746 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
,
748 skb_copy_from_linear_data(skb
,
749 skb_put(conn
->tx_buff
, skb
->len
),
754 atomic_dec(&skb
->users
);
755 dev_kfree_skb_any(skb
);
757 if (conn
->collect_len
> conn
->prof
.maxmulti
)
758 conn
->prof
.maxmulti
= conn
->collect_len
;
759 conn
->collect_len
= 0;
760 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
761 if (conn
->tx_buff
->len
== 0) {
762 fsm_newstate(fi
, CONN_STATE_IDLE
);
767 memcpy(skb_put(conn
->tx_buff
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
768 conn
->prof
.send_stamp
= xtime
;
771 rc
= iucv_message_send(conn
->path
, &txmsg
, 0, 0,
772 conn
->tx_buff
->data
, conn
->tx_buff
->len
);
773 conn
->prof
.doios_multi
++;
774 conn
->prof
.txlen
+= conn
->tx_buff
->len
;
775 conn
->prof
.tx_pending
++;
776 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
777 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
779 conn
->prof
.tx_pending
--;
780 fsm_newstate(fi
, CONN_STATE_IDLE
);
782 privptr
->stats
.tx_errors
+= txpackets
;
783 PRINT_WARN("iucv_send returned %08x\n", rc
);
784 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
787 privptr
->stats
.tx_packets
+= txpackets
;
788 privptr
->stats
.tx_bytes
+= txbytes
;
790 if (stat_maxcq
> conn
->prof
.maxcqueue
)
791 conn
->prof
.maxcqueue
= stat_maxcq
;
795 static void conn_action_connaccept(fsm_instance
*fi
, int event
, void *arg
)
797 struct iucv_event
*ev
= arg
;
798 struct iucv_connection
*conn
= ev
->conn
;
799 struct iucv_path
*path
= ev
->data
;
800 struct net_device
*netdev
= conn
->netdev
;
801 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
804 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
807 path
->msglim
= NETIUCV_QUEUELEN_DEFAULT
;
809 rc
= iucv_path_accept(path
, &netiucv_handler
, NULL
, conn
);
811 PRINT_WARN("%s: IUCV accept failed with error %d\n",
813 IUCV_DBF_TEXT_(setup
, 2, "rc %d from iucv_accept", rc
);
816 fsm_newstate(fi
, CONN_STATE_IDLE
);
817 netdev
->tx_queue_len
= conn
->path
->msglim
;
818 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
821 static void conn_action_connreject(fsm_instance
*fi
, int event
, void *arg
)
823 struct iucv_event
*ev
= arg
;
824 struct iucv_path
*path
= ev
->data
;
826 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
827 iucv_path_sever(path
, NULL
);
830 static void conn_action_connack(fsm_instance
*fi
, int event
, void *arg
)
832 struct iucv_connection
*conn
= arg
;
833 struct net_device
*netdev
= conn
->netdev
;
834 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
836 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
837 fsm_deltimer(&conn
->timer
);
838 fsm_newstate(fi
, CONN_STATE_IDLE
);
839 netdev
->tx_queue_len
= conn
->path
->msglim
;
840 fsm_event(privptr
->fsm
, DEV_EVENT_CONUP
, netdev
);
843 static void conn_action_conntimsev(fsm_instance
*fi
, int event
, void *arg
)
845 struct iucv_connection
*conn
= arg
;
847 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
848 fsm_deltimer(&conn
->timer
);
849 iucv_path_sever(conn
->path
, NULL
);
850 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
853 static void conn_action_connsever(fsm_instance
*fi
, int event
, void *arg
)
855 struct iucv_connection
*conn
= arg
;
856 struct net_device
*netdev
= conn
->netdev
;
857 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
859 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
861 fsm_deltimer(&conn
->timer
);
862 iucv_path_sever(conn
->path
, NULL
);
863 PRINT_INFO("%s: Remote dropped connection\n", netdev
->name
);
864 IUCV_DBF_TEXT(data
, 2,
865 "conn_action_connsever: Remote dropped connection\n");
866 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
867 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
870 static void conn_action_start(fsm_instance
*fi
, int event
, void *arg
)
872 struct iucv_connection
*conn
= arg
;
875 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
877 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
878 PRINT_DEBUG("%s('%s'): connecting ...\n",
879 conn
->netdev
->name
, conn
->userid
);
882 * We must set the state before calling iucv_connect because the
883 * callback handler could be called at any point after the connection
887 fsm_newstate(fi
, CONN_STATE_SETUPWAIT
);
888 conn
->path
= iucv_path_alloc(NETIUCV_QUEUELEN_DEFAULT
, 0, GFP_KERNEL
);
889 rc
= iucv_path_connect(conn
->path
, &netiucv_handler
, conn
->userid
,
890 NULL
, iucvMagic
, conn
);
893 conn
->netdev
->tx_queue_len
= conn
->path
->msglim
;
894 fsm_addtimer(&conn
->timer
, NETIUCV_TIMEOUT_5SEC
,
895 CONN_EVENT_TIMER
, conn
);
898 PRINT_INFO("%s: User %s is currently not available.\n",
900 netiucv_printname(conn
->userid
));
901 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
904 PRINT_INFO("%s: User %s is currently not ready.\n",
906 netiucv_printname(conn
->userid
));
907 fsm_newstate(fi
, CONN_STATE_STARTWAIT
);
910 PRINT_WARN("%s: Too many IUCV connections.\n",
912 fsm_newstate(fi
, CONN_STATE_CONNERR
);
915 PRINT_WARN("%s: User %s has too many IUCV connections.\n",
917 netiucv_printname(conn
->userid
));
918 fsm_newstate(fi
, CONN_STATE_CONNERR
);
921 PRINT_WARN("%s: No IUCV authorization in CP directory.\n",
923 fsm_newstate(fi
, CONN_STATE_CONNERR
);
926 PRINT_WARN("%s: iucv_connect returned error %d\n",
927 conn
->netdev
->name
, rc
);
928 fsm_newstate(fi
, CONN_STATE_CONNERR
);
931 IUCV_DBF_TEXT_(setup
, 5, "iucv_connect rc is %d\n", rc
);
936 static void netiucv_purge_skb_queue(struct sk_buff_head
*q
)
940 while ((skb
= skb_dequeue(q
))) {
941 atomic_dec(&skb
->users
);
942 dev_kfree_skb_any(skb
);
946 static void conn_action_stop(fsm_instance
*fi
, int event
, void *arg
)
948 struct iucv_event
*ev
= arg
;
949 struct iucv_connection
*conn
= ev
->conn
;
950 struct net_device
*netdev
= conn
->netdev
;
951 struct netiucv_priv
*privptr
= netdev_priv(netdev
);
953 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
955 fsm_deltimer(&conn
->timer
);
956 fsm_newstate(fi
, CONN_STATE_STOPPED
);
957 netiucv_purge_skb_queue(&conn
->collect_queue
);
959 IUCV_DBF_TEXT(trace
, 5, "calling iucv_path_sever\n");
960 iucv_path_sever(conn
->path
, iucvMagic
);
964 netiucv_purge_skb_queue(&conn
->commit_queue
);
965 fsm_event(privptr
->fsm
, DEV_EVENT_CONDOWN
, netdev
);
968 static void conn_action_inval(fsm_instance
*fi
, int event
, void *arg
)
970 struct iucv_connection
*conn
= arg
;
971 struct net_device
*netdev
= conn
->netdev
;
973 PRINT_WARN("%s: Cannot connect without username\n", netdev
->name
);
974 IUCV_DBF_TEXT(data
, 2, "conn_action_inval called\n");
977 static const fsm_node conn_fsm
[] = {
978 { CONN_STATE_INVALID
, CONN_EVENT_START
, conn_action_inval
},
979 { CONN_STATE_STOPPED
, CONN_EVENT_START
, conn_action_start
},
981 { CONN_STATE_STOPPED
, CONN_EVENT_STOP
, conn_action_stop
},
982 { CONN_STATE_STARTWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
983 { CONN_STATE_SETUPWAIT
, CONN_EVENT_STOP
, conn_action_stop
},
984 { CONN_STATE_IDLE
, CONN_EVENT_STOP
, conn_action_stop
},
985 { CONN_STATE_TX
, CONN_EVENT_STOP
, conn_action_stop
},
986 { CONN_STATE_REGERR
, CONN_EVENT_STOP
, conn_action_stop
},
987 { CONN_STATE_CONNERR
, CONN_EVENT_STOP
, conn_action_stop
},
989 { CONN_STATE_STOPPED
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
990 { CONN_STATE_STARTWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
991 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REQ
, conn_action_connaccept
},
992 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
993 { CONN_STATE_TX
, CONN_EVENT_CONN_REQ
, conn_action_connreject
},
995 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_ACK
, conn_action_connack
},
996 { CONN_STATE_SETUPWAIT
, CONN_EVENT_TIMER
, conn_action_conntimsev
},
998 { CONN_STATE_SETUPWAIT
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
999 { CONN_STATE_IDLE
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
1000 { CONN_STATE_TX
, CONN_EVENT_CONN_REJ
, conn_action_connsever
},
1002 { CONN_STATE_IDLE
, CONN_EVENT_RX
, conn_action_rx
},
1003 { CONN_STATE_TX
, CONN_EVENT_RX
, conn_action_rx
},
1005 { CONN_STATE_TX
, CONN_EVENT_TXDONE
, conn_action_txdone
},
1006 { CONN_STATE_IDLE
, CONN_EVENT_TXDONE
, conn_action_txdone
},
1009 static const int CONN_FSM_LEN
= sizeof(conn_fsm
) / sizeof(fsm_node
);
1013 * Actions for interface - statemachine.
1018 * @fi: An instance of an interface statemachine.
1019 * @event: The event, just happened.
1020 * @arg: Generic pointer, casted from struct net_device * upon call.
1022 * Startup connection by sending CONN_EVENT_START to it.
1024 static void dev_action_start(fsm_instance
*fi
, int event
, void *arg
)
1026 struct net_device
*dev
= arg
;
1027 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1029 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1031 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1032 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_START
, privptr
->conn
);
1036 * Shutdown connection by sending CONN_EVENT_STOP to it.
1038 * @param fi An instance of an interface statemachine.
1039 * @param event The event, just happened.
1040 * @param arg Generic pointer, casted from struct net_device * upon call.
1043 dev_action_stop(fsm_instance
*fi
, int event
, void *arg
)
1045 struct net_device
*dev
= arg
;
1046 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1047 struct iucv_event ev
;
1049 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1051 ev
.conn
= privptr
->conn
;
1053 fsm_newstate(fi
, DEV_STATE_STOPWAIT
);
1054 fsm_event(privptr
->conn
->fsm
, CONN_EVENT_STOP
, &ev
);
1058 * Called from connection statemachine
1059 * when a connection is up and running.
1061 * @param fi An instance of an interface statemachine.
1062 * @param event The event, just happened.
1063 * @param arg Generic pointer, casted from struct net_device * upon call.
1066 dev_action_connup(fsm_instance
*fi
, int event
, void *arg
)
1068 struct net_device
*dev
= arg
;
1069 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1071 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1073 switch (fsm_getstate(fi
)) {
1074 case DEV_STATE_STARTWAIT
:
1075 fsm_newstate(fi
, DEV_STATE_RUNNING
);
1076 PRINT_INFO("%s: connected with remote side %s\n",
1077 dev
->name
, privptr
->conn
->userid
);
1078 IUCV_DBF_TEXT(setup
, 3,
1079 "connection is up and running\n");
1081 case DEV_STATE_STOPWAIT
:
1083 "%s: got connection UP event during shutdown!\n",
1085 IUCV_DBF_TEXT(data
, 2,
1086 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1092 * Called from connection statemachine
1093 * when a connection has been shutdown.
1095 * @param fi An instance of an interface statemachine.
1096 * @param event The event, just happened.
1097 * @param arg Generic pointer, casted from struct net_device * upon call.
1100 dev_action_conndown(fsm_instance
*fi
, int event
, void *arg
)
1102 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1104 switch (fsm_getstate(fi
)) {
1105 case DEV_STATE_RUNNING
:
1106 fsm_newstate(fi
, DEV_STATE_STARTWAIT
);
1108 case DEV_STATE_STOPWAIT
:
1109 fsm_newstate(fi
, DEV_STATE_STOPPED
);
1110 IUCV_DBF_TEXT(setup
, 3, "connection is down\n");
1115 static const fsm_node dev_fsm
[] = {
1116 { DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
1118 { DEV_STATE_STOPWAIT
, DEV_EVENT_START
, dev_action_start
},
1119 { DEV_STATE_STOPWAIT
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1121 { DEV_STATE_STARTWAIT
, DEV_EVENT_STOP
, dev_action_stop
},
1122 { DEV_STATE_STARTWAIT
, DEV_EVENT_CONUP
, dev_action_connup
},
1124 { DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
1125 { DEV_STATE_RUNNING
, DEV_EVENT_CONDOWN
, dev_action_conndown
},
1126 { DEV_STATE_RUNNING
, DEV_EVENT_CONUP
, fsm_action_nop
},
1129 static const int DEV_FSM_LEN
= sizeof(dev_fsm
) / sizeof(fsm_node
);
1132 * Transmit a packet.
1133 * This is a helper function for netiucv_tx().
1135 * @param conn Connection to be used for sending.
1136 * @param skb Pointer to struct sk_buff of packet to send.
1137 * The linklevel header has already been set up
1140 * @return 0 on success, -ERRNO on failure. (Never fails.)
1142 static int netiucv_transmit_skb(struct iucv_connection
*conn
,
1143 struct sk_buff
*skb
)
1145 struct iucv_message msg
;
1146 unsigned long saveflags
;
1147 struct ll_header header
;
1150 if (fsm_getstate(conn
->fsm
) != CONN_STATE_IDLE
) {
1151 int l
= skb
->len
+ NETIUCV_HDRLEN
;
1153 spin_lock_irqsave(&conn
->collect_lock
, saveflags
);
1154 if (conn
->collect_len
+ l
>
1155 (conn
->max_buffsize
- NETIUCV_HDRLEN
)) {
1157 IUCV_DBF_TEXT(data
, 2,
1158 "EBUSY from netiucv_transmit_skb\n");
1160 atomic_inc(&skb
->users
);
1161 skb_queue_tail(&conn
->collect_queue
, skb
);
1162 conn
->collect_len
+= l
;
1165 spin_unlock_irqrestore(&conn
->collect_lock
, saveflags
);
1167 struct sk_buff
*nskb
= skb
;
1169 * Copy the skb to a new allocated skb in lowmem only if the
1170 * data is located above 2G in memory or tailroom is < 2.
1172 unsigned long hi
= ((unsigned long)(skb_tail_pointer(skb
) +
1173 NETIUCV_HDRLEN
)) >> 31;
1175 if (hi
|| (skb_tailroom(skb
) < 2)) {
1176 nskb
= alloc_skb(skb
->len
+ NETIUCV_HDRLEN
+
1177 NETIUCV_HDRLEN
, GFP_ATOMIC
| GFP_DMA
);
1179 PRINT_WARN("%s: Could not allocate tx_skb\n",
1180 conn
->netdev
->name
);
1181 IUCV_DBF_TEXT(data
, 2, "alloc_skb failed\n");
1185 skb_reserve(nskb
, NETIUCV_HDRLEN
);
1186 memcpy(skb_put(nskb
, skb
->len
),
1187 skb
->data
, skb
->len
);
1192 * skb now is below 2G and has enough room. Add headers.
1194 header
.next
= nskb
->len
+ NETIUCV_HDRLEN
;
1195 memcpy(skb_push(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1197 memcpy(skb_put(nskb
, NETIUCV_HDRLEN
), &header
, NETIUCV_HDRLEN
);
1199 fsm_newstate(conn
->fsm
, CONN_STATE_TX
);
1200 conn
->prof
.send_stamp
= xtime
;
1204 rc
= iucv_message_send(conn
->path
, &msg
, 0, 0,
1205 nskb
->data
, nskb
->len
);
1206 conn
->prof
.doios_single
++;
1207 conn
->prof
.txlen
+= skb
->len
;
1208 conn
->prof
.tx_pending
++;
1209 if (conn
->prof
.tx_pending
> conn
->prof
.tx_max_pending
)
1210 conn
->prof
.tx_max_pending
= conn
->prof
.tx_pending
;
1212 struct netiucv_priv
*privptr
;
1213 fsm_newstate(conn
->fsm
, CONN_STATE_IDLE
);
1214 conn
->prof
.tx_pending
--;
1215 privptr
= netdev_priv(conn
->netdev
);
1217 privptr
->stats
.tx_errors
++;
1219 dev_kfree_skb(nskb
);
1222 * Remove our headers. They get added
1223 * again on retransmit.
1225 skb_pull(skb
, NETIUCV_HDRLEN
);
1226 skb_trim(skb
, skb
->len
- NETIUCV_HDRLEN
);
1228 PRINT_WARN("iucv_send returned %08x\n", rc
);
1229 IUCV_DBF_TEXT_(data
, 2, "rc %d from iucv_send\n", rc
);
1233 atomic_inc(&nskb
->users
);
1234 skb_queue_tail(&conn
->commit_queue
, nskb
);
1242 * Interface API for upper network layers
1246 * Open an interface.
1247 * Called from generic network layer when ifconfig up is run.
1249 * @param dev Pointer to interface struct.
1251 * @return 0 on success, -ERRNO on failure. (Never fails.)
1253 static int netiucv_open(struct net_device
*dev
)
1255 struct netiucv_priv
*priv
= netdev_priv(dev
);
1257 fsm_event(priv
->fsm
, DEV_EVENT_START
, dev
);
1262 * Close an interface.
1263 * Called from generic network layer when ifconfig down is run.
1265 * @param dev Pointer to interface struct.
1267 * @return 0 on success, -ERRNO on failure. (Never fails.)
1269 static int netiucv_close(struct net_device
*dev
)
1271 struct netiucv_priv
*priv
= netdev_priv(dev
);
1273 fsm_event(priv
->fsm
, DEV_EVENT_STOP
, dev
);
1278 * Start transmission of a packet.
1279 * Called from generic network device layer.
1281 * @param skb Pointer to buffer containing the packet.
1282 * @param dev Pointer to interface struct.
1284 * @return 0 if packet consumed, !0 if packet rejected.
1285 * Note: If we return !0, then the packet is free'd by
1286 * the generic network layer.
1288 static int netiucv_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1290 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1293 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1295 * Some sanity checks ...
1298 PRINT_WARN("%s: NULL sk_buff passed\n", dev
->name
);
1299 IUCV_DBF_TEXT(data
, 2, "netiucv_tx: skb is NULL\n");
1300 privptr
->stats
.tx_dropped
++;
1303 if (skb_headroom(skb
) < NETIUCV_HDRLEN
) {
1304 PRINT_WARN("%s: Got sk_buff with head room < %ld bytes\n",
1305 dev
->name
, NETIUCV_HDRLEN
);
1306 IUCV_DBF_TEXT(data
, 2,
1307 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1309 privptr
->stats
.tx_dropped
++;
1314 * If connection is not running, try to restart it
1315 * and throw away packet.
1317 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
1319 fsm_event(privptr
->fsm
, DEV_EVENT_START
, dev
);
1321 privptr
->stats
.tx_dropped
++;
1322 privptr
->stats
.tx_errors
++;
1323 privptr
->stats
.tx_carrier_errors
++;
1327 if (netiucv_test_and_set_busy(dev
)) {
1328 IUCV_DBF_TEXT(data
, 2, "EBUSY from netiucv_tx\n");
1331 dev
->trans_start
= jiffies
;
1332 rc
= netiucv_transmit_skb(privptr
->conn
, skb
) != 0;
1333 netiucv_clear_busy(dev
);
1339 * @dev: Pointer to interface struct.
1341 * Returns interface statistics of a device.
1343 * Returns pointer to stats struct of this interface.
1345 static struct net_device_stats
*netiucv_stats (struct net_device
* dev
)
1347 struct netiucv_priv
*priv
= netdev_priv(dev
);
1349 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1350 return &priv
->stats
;
1354 * netiucv_change_mtu
1355 * @dev: Pointer to interface struct.
1356 * @new_mtu: The new MTU to use for this interface.
1358 * Sets MTU of an interface.
1360 * Returns 0 on success, -EINVAL if MTU is out of valid range.
1361 * (valid range is 576 .. NETIUCV_MTU_MAX).
1363 static int netiucv_change_mtu(struct net_device
* dev
, int new_mtu
)
1365 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1366 if (new_mtu
< 576 || new_mtu
> NETIUCV_MTU_MAX
) {
1367 IUCV_DBF_TEXT(setup
, 2, "given MTU out of valid range\n");
1375 * attributes in sysfs
1378 static ssize_t
user_show(struct device
*dev
, struct device_attribute
*attr
,
1381 struct netiucv_priv
*priv
= dev
->driver_data
;
1383 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1384 return sprintf(buf
, "%s\n", netiucv_printname(priv
->conn
->userid
));
1387 static ssize_t
user_write(struct device
*dev
, struct device_attribute
*attr
,
1388 const char *buf
, size_t count
)
1390 struct netiucv_priv
*priv
= dev
->driver_data
;
1391 struct net_device
*ndev
= priv
->conn
->netdev
;
1396 struct iucv_connection
*cp
;
1398 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1400 PRINT_WARN("netiucv: username too long (%d)!\n", (int) count
);
1401 IUCV_DBF_TEXT_(setup
, 2,
1402 "%d is length of username\n", (int) count
);
1406 tmp
= strsep((char **) &buf
, "\n");
1407 for (i
= 0, p
= tmp
; i
< 8 && *p
; i
++, p
++) {
1408 if (isalnum(*p
) || (*p
== '$')) {
1409 username
[i
]= toupper(*p
);
1413 /* trailing lf, grr */
1416 PRINT_WARN("netiucv: Invalid char %c in username!\n", *p
);
1417 IUCV_DBF_TEXT_(setup
, 2,
1418 "username: invalid character %c\n", *p
);
1422 username
[i
++] = ' ';
1425 if (memcmp(username
, priv
->conn
->userid
, 9) &&
1426 (ndev
->flags
& (IFF_UP
| IFF_RUNNING
))) {
1427 /* username changed while the interface is active. */
1428 PRINT_WARN("netiucv: device %s active, connected to %s\n",
1429 dev
->bus_id
, priv
->conn
->userid
);
1430 PRINT_WARN("netiucv: user cannot be updated\n");
1431 IUCV_DBF_TEXT(setup
, 2, "user_write: device active\n");
1434 read_lock_bh(&iucv_connection_rwlock
);
1435 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
1436 if (!strncmp(username
, cp
->userid
, 9) && cp
->netdev
!= ndev
) {
1437 read_unlock_bh(&iucv_connection_rwlock
);
1438 PRINT_WARN("netiucv: Connection to %s already "
1439 "exists\n", username
);
1443 read_unlock_bh(&iucv_connection_rwlock
);
1444 memcpy(priv
->conn
->userid
, username
, 9);
1448 static DEVICE_ATTR(user
, 0644, user_show
, user_write
);
1450 static ssize_t
buffer_show (struct device
*dev
, struct device_attribute
*attr
,
1452 { struct netiucv_priv
*priv
= dev
->driver_data
;
1454 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1455 return sprintf(buf
, "%d\n", priv
->conn
->max_buffsize
);
1458 static ssize_t
buffer_write (struct device
*dev
, struct device_attribute
*attr
,
1459 const char *buf
, size_t count
)
1461 struct netiucv_priv
*priv
= dev
->driver_data
;
1462 struct net_device
*ndev
= priv
->conn
->netdev
;
1466 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1470 bs1
= simple_strtoul(buf
, &e
, 0);
1472 if (e
&& (!isspace(*e
))) {
1473 PRINT_WARN("netiucv: Invalid character in buffer!\n");
1474 IUCV_DBF_TEXT_(setup
, 2, "buffer_write: invalid char %c\n", *e
);
1477 if (bs1
> NETIUCV_BUFSIZE_MAX
) {
1478 PRINT_WARN("netiucv: Given buffer size %d too large.\n",
1480 IUCV_DBF_TEXT_(setup
, 2,
1481 "buffer_write: buffer size %d too large\n",
1485 if ((ndev
->flags
& IFF_RUNNING
) &&
1486 (bs1
< (ndev
->mtu
+ NETIUCV_HDRLEN
+ 2))) {
1487 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1489 IUCV_DBF_TEXT_(setup
, 2,
1490 "buffer_write: buffer size %d too small\n",
1494 if (bs1
< (576 + NETIUCV_HDRLEN
+ NETIUCV_HDRLEN
)) {
1495 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1497 IUCV_DBF_TEXT_(setup
, 2,
1498 "buffer_write: buffer size %d too small\n",
1503 priv
->conn
->max_buffsize
= bs1
;
1504 if (!(ndev
->flags
& IFF_RUNNING
))
1505 ndev
->mtu
= bs1
- NETIUCV_HDRLEN
- NETIUCV_HDRLEN
;
1511 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
1513 static ssize_t
dev_fsm_show (struct device
*dev
, struct device_attribute
*attr
,
1516 struct netiucv_priv
*priv
= dev
->driver_data
;
1518 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1519 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->fsm
));
1522 static DEVICE_ATTR(device_fsm_state
, 0444, dev_fsm_show
, NULL
);
1524 static ssize_t
conn_fsm_show (struct device
*dev
,
1525 struct device_attribute
*attr
, char *buf
)
1527 struct netiucv_priv
*priv
= dev
->driver_data
;
1529 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1530 return sprintf(buf
, "%s\n", fsm_getstate_str(priv
->conn
->fsm
));
1533 static DEVICE_ATTR(connection_fsm_state
, 0444, conn_fsm_show
, NULL
);
1535 static ssize_t
maxmulti_show (struct device
*dev
,
1536 struct device_attribute
*attr
, char *buf
)
1538 struct netiucv_priv
*priv
= dev
->driver_data
;
1540 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1541 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxmulti
);
1544 static ssize_t
maxmulti_write (struct device
*dev
,
1545 struct device_attribute
*attr
,
1546 const char *buf
, size_t count
)
1548 struct netiucv_priv
*priv
= dev
->driver_data
;
1550 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1551 priv
->conn
->prof
.maxmulti
= 0;
1555 static DEVICE_ATTR(max_tx_buffer_used
, 0644, maxmulti_show
, maxmulti_write
);
1557 static ssize_t
maxcq_show (struct device
*dev
, struct device_attribute
*attr
,
1560 struct netiucv_priv
*priv
= dev
->driver_data
;
1562 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1563 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.maxcqueue
);
1566 static ssize_t
maxcq_write (struct device
*dev
, struct device_attribute
*attr
,
1567 const char *buf
, size_t count
)
1569 struct netiucv_priv
*priv
= dev
->driver_data
;
1571 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1572 priv
->conn
->prof
.maxcqueue
= 0;
1576 static DEVICE_ATTR(max_chained_skbs
, 0644, maxcq_show
, maxcq_write
);
1578 static ssize_t
sdoio_show (struct device
*dev
, struct device_attribute
*attr
,
1581 struct netiucv_priv
*priv
= dev
->driver_data
;
1583 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1584 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_single
);
1587 static ssize_t
sdoio_write (struct device
*dev
, struct device_attribute
*attr
,
1588 const char *buf
, size_t count
)
1590 struct netiucv_priv
*priv
= dev
->driver_data
;
1592 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1593 priv
->conn
->prof
.doios_single
= 0;
1597 static DEVICE_ATTR(tx_single_write_ops
, 0644, sdoio_show
, sdoio_write
);
1599 static ssize_t
mdoio_show (struct device
*dev
, struct device_attribute
*attr
,
1602 struct netiucv_priv
*priv
= dev
->driver_data
;
1604 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1605 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.doios_multi
);
1608 static ssize_t
mdoio_write (struct device
*dev
, struct device_attribute
*attr
,
1609 const char *buf
, size_t count
)
1611 struct netiucv_priv
*priv
= dev
->driver_data
;
1613 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1614 priv
->conn
->prof
.doios_multi
= 0;
1618 static DEVICE_ATTR(tx_multi_write_ops
, 0644, mdoio_show
, mdoio_write
);
1620 static ssize_t
txlen_show (struct device
*dev
, struct device_attribute
*attr
,
1623 struct netiucv_priv
*priv
= dev
->driver_data
;
1625 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1626 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.txlen
);
1629 static ssize_t
txlen_write (struct device
*dev
, struct device_attribute
*attr
,
1630 const char *buf
, size_t count
)
1632 struct netiucv_priv
*priv
= dev
->driver_data
;
1634 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1635 priv
->conn
->prof
.txlen
= 0;
1639 static DEVICE_ATTR(netto_bytes
, 0644, txlen_show
, txlen_write
);
1641 static ssize_t
txtime_show (struct device
*dev
, struct device_attribute
*attr
,
1644 struct netiucv_priv
*priv
= dev
->driver_data
;
1646 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1647 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_time
);
1650 static ssize_t
txtime_write (struct device
*dev
, struct device_attribute
*attr
,
1651 const char *buf
, size_t count
)
1653 struct netiucv_priv
*priv
= dev
->driver_data
;
1655 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1656 priv
->conn
->prof
.tx_time
= 0;
1660 static DEVICE_ATTR(max_tx_io_time
, 0644, txtime_show
, txtime_write
);
1662 static ssize_t
txpend_show (struct device
*dev
, struct device_attribute
*attr
,
1665 struct netiucv_priv
*priv
= dev
->driver_data
;
1667 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1668 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_pending
);
1671 static ssize_t
txpend_write (struct device
*dev
, struct device_attribute
*attr
,
1672 const char *buf
, size_t count
)
1674 struct netiucv_priv
*priv
= dev
->driver_data
;
1676 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1677 priv
->conn
->prof
.tx_pending
= 0;
1681 static DEVICE_ATTR(tx_pending
, 0644, txpend_show
, txpend_write
);
1683 static ssize_t
txmpnd_show (struct device
*dev
, struct device_attribute
*attr
,
1686 struct netiucv_priv
*priv
= dev
->driver_data
;
1688 IUCV_DBF_TEXT(trace
, 5, __FUNCTION__
);
1689 return sprintf(buf
, "%ld\n", priv
->conn
->prof
.tx_max_pending
);
1692 static ssize_t
txmpnd_write (struct device
*dev
, struct device_attribute
*attr
,
1693 const char *buf
, size_t count
)
1695 struct netiucv_priv
*priv
= dev
->driver_data
;
1697 IUCV_DBF_TEXT(trace
, 4, __FUNCTION__
);
1698 priv
->conn
->prof
.tx_max_pending
= 0;
1702 static DEVICE_ATTR(tx_max_pending
, 0644, txmpnd_show
, txmpnd_write
);
1704 static struct attribute
*netiucv_attrs
[] = {
1705 &dev_attr_buffer
.attr
,
1706 &dev_attr_user
.attr
,
1710 static struct attribute_group netiucv_attr_group
= {
1711 .attrs
= netiucv_attrs
,
1714 static struct attribute
*netiucv_stat_attrs
[] = {
1715 &dev_attr_device_fsm_state
.attr
,
1716 &dev_attr_connection_fsm_state
.attr
,
1717 &dev_attr_max_tx_buffer_used
.attr
,
1718 &dev_attr_max_chained_skbs
.attr
,
1719 &dev_attr_tx_single_write_ops
.attr
,
1720 &dev_attr_tx_multi_write_ops
.attr
,
1721 &dev_attr_netto_bytes
.attr
,
1722 &dev_attr_max_tx_io_time
.attr
,
1723 &dev_attr_tx_pending
.attr
,
1724 &dev_attr_tx_max_pending
.attr
,
1728 static struct attribute_group netiucv_stat_attr_group
= {
1730 .attrs
= netiucv_stat_attrs
,
1733 static inline int netiucv_add_files(struct device
*dev
)
1737 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1738 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_attr_group
);
1741 ret
= sysfs_create_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1743 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1747 static inline void netiucv_remove_files(struct device
*dev
)
1749 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1750 sysfs_remove_group(&dev
->kobj
, &netiucv_stat_attr_group
);
1751 sysfs_remove_group(&dev
->kobj
, &netiucv_attr_group
);
1754 static int netiucv_register_device(struct net_device
*ndev
)
1756 struct netiucv_priv
*priv
= netdev_priv(ndev
);
1757 struct device
*dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1761 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1764 snprintf(dev
->bus_id
, BUS_ID_SIZE
, "net%s", ndev
->name
);
1765 dev
->bus
= &iucv_bus
;
1766 dev
->parent
= iucv_root
;
1768 * The release function could be called after the
1769 * module has been unloaded. It's _only_ task is to
1770 * free the struct. Therefore, we specify kfree()
1771 * directly here. (Probably a little bit obfuscating
1772 * but legitime ...).
1774 dev
->release
= (void (*)(struct device
*))kfree
;
1775 dev
->driver
= &netiucv_driver
;
1779 ret
= device_register(dev
);
1783 ret
= netiucv_add_files(dev
);
1787 dev
->driver_data
= priv
;
1791 device_unregister(dev
);
1795 static void netiucv_unregister_device(struct device
*dev
)
1797 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1798 netiucv_remove_files(dev
);
1799 device_unregister(dev
);
1803 * Allocate and initialize a new connection structure.
1804 * Add it to the list of netiucv connections;
1806 static struct iucv_connection
*netiucv_new_connection(struct net_device
*dev
,
1809 struct iucv_connection
*conn
;
1811 conn
= kzalloc(sizeof(*conn
), GFP_KERNEL
);
1814 skb_queue_head_init(&conn
->collect_queue
);
1815 skb_queue_head_init(&conn
->commit_queue
);
1816 spin_lock_init(&conn
->collect_lock
);
1817 conn
->max_buffsize
= NETIUCV_BUFSIZE_DEFAULT
;
1820 conn
->rx_buff
= alloc_skb(conn
->max_buffsize
, GFP_KERNEL
| GFP_DMA
);
1823 conn
->tx_buff
= alloc_skb(conn
->max_buffsize
, GFP_KERNEL
| GFP_DMA
);
1826 conn
->fsm
= init_fsm("netiucvconn", conn_state_names
,
1827 conn_event_names
, NR_CONN_STATES
,
1828 NR_CONN_EVENTS
, conn_fsm
, CONN_FSM_LEN
,
1833 fsm_settimer(conn
->fsm
, &conn
->timer
);
1834 fsm_newstate(conn
->fsm
, CONN_STATE_INVALID
);
1837 memcpy(conn
->userid
, username
, 9);
1838 fsm_newstate(conn
->fsm
, CONN_STATE_STOPPED
);
1841 write_lock_bh(&iucv_connection_rwlock
);
1842 list_add_tail(&conn
->list
, &iucv_connection_list
);
1843 write_unlock_bh(&iucv_connection_rwlock
);
1847 kfree_skb(conn
->tx_buff
);
1849 kfree_skb(conn
->rx_buff
);
1857 * Release a connection structure and remove it from the
1858 * list of netiucv connections.
1860 static void netiucv_remove_connection(struct iucv_connection
*conn
)
1862 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1863 write_lock_bh(&iucv_connection_rwlock
);
1864 list_del_init(&conn
->list
);
1865 write_unlock_bh(&iucv_connection_rwlock
);
1866 fsm_deltimer(&conn
->timer
);
1867 netiucv_purge_skb_queue(&conn
->collect_queue
);
1869 iucv_path_sever(conn
->path
, iucvMagic
);
1873 netiucv_purge_skb_queue(&conn
->commit_queue
);
1874 kfree_fsm(conn
->fsm
);
1875 kfree_skb(conn
->rx_buff
);
1876 kfree_skb(conn
->tx_buff
);
1880 * Release everything of a net device.
1882 static void netiucv_free_netdevice(struct net_device
*dev
)
1884 struct netiucv_priv
*privptr
= netdev_priv(dev
);
1886 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1893 netiucv_remove_connection(privptr
->conn
);
1895 kfree_fsm(privptr
->fsm
);
1896 privptr
->conn
= NULL
; privptr
->fsm
= NULL
;
1897 /* privptr gets freed by free_netdev() */
1903 * Initialize a net device. (Called from kernel in alloc_netdev())
1905 static void netiucv_setup_netdevice(struct net_device
*dev
)
1907 dev
->mtu
= NETIUCV_MTU_DEFAULT
;
1908 dev
->hard_start_xmit
= netiucv_tx
;
1909 dev
->open
= netiucv_open
;
1910 dev
->stop
= netiucv_close
;
1911 dev
->get_stats
= netiucv_stats
;
1912 dev
->change_mtu
= netiucv_change_mtu
;
1913 dev
->destructor
= netiucv_free_netdevice
;
1914 dev
->hard_header_len
= NETIUCV_HDRLEN
;
1916 dev
->type
= ARPHRD_SLIP
;
1917 dev
->tx_queue_len
= NETIUCV_QUEUELEN_DEFAULT
;
1918 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
1919 SET_MODULE_OWNER(dev
);
1923 * Allocate and initialize everything of a net device.
1925 static struct net_device
*netiucv_init_netdevice(char *username
)
1927 struct netiucv_priv
*privptr
;
1928 struct net_device
*dev
;
1930 dev
= alloc_netdev(sizeof(struct netiucv_priv
), "iucv%d",
1931 netiucv_setup_netdevice
);
1934 if (dev_alloc_name(dev
, dev
->name
) < 0)
1937 privptr
= netdev_priv(dev
);
1938 privptr
->fsm
= init_fsm("netiucvdev", dev_state_names
,
1939 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
1940 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
1944 privptr
->conn
= netiucv_new_connection(dev
, username
);
1945 if (!privptr
->conn
) {
1946 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_new_connection\n");
1949 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
1953 kfree_fsm(privptr
->fsm
);
1959 static ssize_t
conn_write(struct device_driver
*drv
,
1960 const char *buf
, size_t count
)
1965 struct net_device
*dev
;
1966 struct netiucv_priv
*priv
;
1967 struct iucv_connection
*cp
;
1969 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
1971 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count
);
1972 IUCV_DBF_TEXT(setup
, 2, "conn_write: too long\n");
1976 for (i
= 0, p
= buf
; i
< 8 && *p
; i
++, p
++) {
1977 if (isalnum(*p
) || *p
== '$') {
1978 username
[i
] = toupper(*p
);
1982 /* trailing lf, grr */
1984 PRINT_WARN("netiucv: Invalid character in username!\n");
1985 IUCV_DBF_TEXT_(setup
, 2,
1986 "conn_write: invalid character %c\n", *p
);
1990 username
[i
++] = ' ';
1993 read_lock_bh(&iucv_connection_rwlock
);
1994 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
1995 if (!strncmp(username
, cp
->userid
, 9)) {
1996 read_unlock_bh(&iucv_connection_rwlock
);
1997 PRINT_WARN("netiucv: Connection to %s already "
1998 "exists\n", username
);
2002 read_unlock_bh(&iucv_connection_rwlock
);
2004 dev
= netiucv_init_netdevice(username
);
2006 PRINT_WARN("netiucv: Could not allocate network device "
2007 "structure for user '%s'\n",
2008 netiucv_printname(username
));
2009 IUCV_DBF_TEXT(setup
, 2, "NULL from netiucv_init_netdevice\n");
2013 rc
= netiucv_register_device(dev
);
2015 IUCV_DBF_TEXT_(setup
, 2,
2016 "ret %d from netiucv_register_device\n", rc
);
2021 priv
= netdev_priv(dev
);
2022 SET_NETDEV_DEV(dev
, priv
->dev
);
2024 rc
= register_netdev(dev
);
2028 PRINT_INFO("%s: '%s'\n", dev
->name
, netiucv_printname(username
));
2033 netiucv_unregister_device(priv
->dev
);
2035 PRINT_WARN("netiucv: Could not register '%s'\n", dev
->name
);
2036 IUCV_DBF_TEXT(setup
, 2, "conn_write: could not register\n");
2037 netiucv_free_netdevice(dev
);
2041 static DRIVER_ATTR(connection
, 0200, NULL
, conn_write
);
2043 static ssize_t
remove_write (struct device_driver
*drv
,
2044 const char *buf
, size_t count
)
2046 struct iucv_connection
*cp
;
2047 struct net_device
*ndev
;
2048 struct netiucv_priv
*priv
;
2050 char name
[IFNAMSIZ
];
2054 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2056 if (count
>= IFNAMSIZ
)
2057 count
= IFNAMSIZ
- 1;;
2059 for (i
= 0, p
= buf
; i
< count
&& *p
; i
++, p
++) {
2060 if (*p
== '\n' || *p
== ' ')
2061 /* trailing lf, grr */
2067 read_lock_bh(&iucv_connection_rwlock
);
2068 list_for_each_entry(cp
, &iucv_connection_list
, list
) {
2070 priv
= netdev_priv(ndev
);
2072 if (strncmp(name
, ndev
->name
, count
))
2074 read_unlock_bh(&iucv_connection_rwlock
);
2075 if (ndev
->flags
& (IFF_UP
| IFF_RUNNING
)) {
2076 PRINT_WARN("netiucv: net device %s active with peer "
2077 "%s\n", ndev
->name
, priv
->conn
->userid
);
2078 PRINT_WARN("netiucv: %s cannot be removed\n",
2080 IUCV_DBF_TEXT(data
, 2, "remove_write: still active\n");
2083 unregister_netdev(ndev
);
2084 netiucv_unregister_device(dev
);
2087 read_unlock_bh(&iucv_connection_rwlock
);
2088 PRINT_WARN("netiucv: net device %s unknown\n", name
);
2089 IUCV_DBF_TEXT(data
, 2, "remove_write: unknown device\n");
2093 static DRIVER_ATTR(remove
, 0200, NULL
, remove_write
);
2095 static struct attribute
* netiucv_drv_attrs
[] = {
2096 &driver_attr_connection
.attr
,
2097 &driver_attr_remove
.attr
,
2101 static struct attribute_group netiucv_drv_attr_group
= {
2102 .attrs
= netiucv_drv_attrs
,
2105 static void netiucv_banner(void)
2107 PRINT_INFO("NETIUCV driver initialized\n");
2110 static void __exit
netiucv_exit(void)
2112 struct iucv_connection
*cp
;
2113 struct net_device
*ndev
;
2114 struct netiucv_priv
*priv
;
2117 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2118 while (!list_empty(&iucv_connection_list
)) {
2119 cp
= list_entry(iucv_connection_list
.next
,
2120 struct iucv_connection
, list
);
2122 priv
= netdev_priv(ndev
);
2125 unregister_netdev(ndev
);
2126 netiucv_unregister_device(dev
);
2129 sysfs_remove_group(&netiucv_driver
.kobj
, &netiucv_drv_attr_group
);
2130 driver_unregister(&netiucv_driver
);
2131 iucv_unregister(&netiucv_handler
, 1);
2132 iucv_unregister_dbf_views();
2134 PRINT_INFO("NETIUCV driver unloaded\n");
2138 static int __init
netiucv_init(void)
2142 rc
= iucv_register_dbf_views();
2145 rc
= iucv_register(&netiucv_handler
, 1);
2148 IUCV_DBF_TEXT(trace
, 3, __FUNCTION__
);
2149 rc
= driver_register(&netiucv_driver
);
2151 PRINT_ERR("NETIUCV: failed to register driver.\n");
2152 IUCV_DBF_TEXT_(setup
, 2, "ret %d from driver_register\n", rc
);
2156 rc
= sysfs_create_group(&netiucv_driver
.kobj
, &netiucv_drv_attr_group
);
2158 PRINT_ERR("NETIUCV: failed to add driver attributes.\n");
2159 IUCV_DBF_TEXT_(setup
, 2,
2160 "ret %d - netiucv_drv_attr_group\n", rc
);
2167 driver_unregister(&netiucv_driver
);
2169 iucv_unregister(&netiucv_handler
, 1);
2171 iucv_unregister_dbf_views();
2176 module_init(netiucv_init
);
2177 module_exit(netiucv_exit
);
2178 MODULE_LICENSE("GPL");