4 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
7 * Sysfs integration and all bugs therein by Cornelia Huck
8 * (cornelia.huck@de.ibm.com)
11 * the source of the original IUCV driver by:
12 * Stefan Hegewald <hegewald@de.ibm.com>
13 * Hartmut Penner <hpenner@de.ibm.com>
14 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
15 * Martin Schwidefsky (schwidefsky@de.ibm.com)
16 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/errno.h>
41 #include <linux/types.h>
42 #include <linux/interrupt.h>
43 #include <linux/timer.h>
44 #include <linux/sched.h>
45 #include <linux/bitops.h>
47 #include <linux/signal.h>
48 #include <linux/string.h>
49 #include <linux/device.h>
52 #include <linux/if_arp.h>
53 #include <linux/tcp.h>
54 #include <linux/skbuff.h>
55 #include <linux/ctype.h>
59 #include <asm/uaccess.h>
65 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
66 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
69 #define PRINTK_HEADER " iucv: " /* for debugging */
71 static struct device_driver netiucv_driver = {
77 * Per connection profiling data
79 struct connection_profile {
80 unsigned long maxmulti;
81 unsigned long maxcqueue;
82 unsigned long doios_single;
83 unsigned long doios_multi;
85 unsigned long tx_time;
86 struct timespec send_stamp;
87 unsigned long tx_pending;
88 unsigned long tx_max_pending;
92 * Representation of one iucv connection
94 struct iucv_connection {
95 struct iucv_connection *next;
98 struct sk_buff *rx_buff;
99 struct sk_buff *tx_buff;
100 struct sk_buff_head collect_queue;
101 struct sk_buff_head commit_queue;
102 spinlock_t collect_lock;
107 struct net_device *netdev;
108 struct connection_profile prof;
113 * Linked list of all connection structs.
115 struct iucv_connection_struct {
116 struct iucv_connection *iucv_connections;
117 rwlock_t iucv_rwlock;
120 static struct iucv_connection_struct iucv_conns;
123 * Representation of event-data for the
124 * connection state machine.
127 struct iucv_connection *conn;
132 * Private part of the network device structure
134 struct netiucv_priv {
135 struct net_device_stats stats;
138 struct iucv_connection *conn;
143 * Link level header for a packet.
145 typedef struct ll_header_t {
149 #define NETIUCV_HDRLEN (sizeof(ll_header))
150 #define NETIUCV_BUFSIZE_MAX 32768
151 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
152 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
153 #define NETIUCV_MTU_DEFAULT 9216
154 #define NETIUCV_QUEUELEN_DEFAULT 50
155 #define NETIUCV_TIMEOUT_5SEC 5000
158 * Compatibility macros for busy handling
159 * of network devices.
161 static __inline__ void netiucv_clear_busy(struct net_device *dev)
163 clear_bit(0, &(((struct netiucv_priv *)dev->priv)->tbusy));
164 netif_wake_queue(dev);
167 static __inline__ int netiucv_test_and_set_busy(struct net_device *dev)
169 netif_stop_queue(dev);
170 return test_and_set_bit(0, &((struct netiucv_priv *)dev->priv)->tbusy);
173 static __u8 iucv_host[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
174 static __u8 iucvMagic[16] = {
175 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
176 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
180 * This mask means the 16-byte IUCV "magic" and the origin userid must
181 * match exactly as specified in order to give connection_pending()
184 static __u8 netiucv_mask[] = {
185 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
186 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
187 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
191 * Convert an iucv userId to its printable
192 * form (strip whitespace at end).
194 * @param An iucv userId
196 * @returns The printable string (static data!!)
198 static __inline__ char *
199 netiucv_printname(char *name)
203 memcpy(tmp, name, 8);
205 while (*p && (!isspace(*p)))
212 * States of the interface statemachine.
220 * MUST be always the last element!!
225 static const char *dev_state_names[] = {
233 * Events of the interface statemachine.
241 * MUST be always the last element!!
246 static const char *dev_event_names[] = {
254 * Events of the connection statemachine
258 * Events, representing callbacks from
259 * lowlevel iucv layer)
270 * Events, representing errors return codes from
271 * calls to lowlevel iucv layer
275 * Event, representing timer expiry.
280 * Events, representing commands from upper levels.
286 * MUST be always the last element!!
291 static const char *conn_event_names[] = {
292 "Remote connection request",
293 "Remote connection acknowledge",
294 "Remote connection reject",
295 "Connection suspended",
296 "Connection resumed",
307 * States of the connection statemachine.
311 * Connection not assigned to any device,
312 * initial state, invalid
317 * Userid assigned but not operating
322 * Connection registered,
323 * no connection request sent yet,
324 * no connection request received
326 CONN_STATE_STARTWAIT,
329 * Connection registered and connection request sent,
330 * no acknowledge and no connection request received yet.
332 CONN_STATE_SETUPWAIT,
335 * Connection up and running idle
340 * Data sent, awaiting CONN_EVENT_TXDONE
345 * Error during registration.
350 * Error during registration.
355 * MUST be always the last element!!
360 static const char *conn_state_names[] = {
368 "Registration error",
374 * Debug Facility Stuff
376 static debug_info_t *iucv_dbf_setup = NULL;
377 static debug_info_t *iucv_dbf_data = NULL;
378 static debug_info_t *iucv_dbf_trace = NULL;
380 DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf);
383 iucv_unregister_dbf_views(void)
386 debug_unregister(iucv_dbf_setup);
388 debug_unregister(iucv_dbf_data);
390 debug_unregister(iucv_dbf_trace);
393 iucv_register_dbf_views(void)
395 iucv_dbf_setup = debug_register(IUCV_DBF_SETUP_NAME,
396 IUCV_DBF_SETUP_PAGES,
397 IUCV_DBF_SETUP_NR_AREAS,
399 iucv_dbf_data = debug_register(IUCV_DBF_DATA_NAME,
401 IUCV_DBF_DATA_NR_AREAS,
403 iucv_dbf_trace = debug_register(IUCV_DBF_TRACE_NAME,
404 IUCV_DBF_TRACE_PAGES,
405 IUCV_DBF_TRACE_NR_AREAS,
408 if ((iucv_dbf_setup == NULL) || (iucv_dbf_data == NULL) ||
409 (iucv_dbf_trace == NULL)) {
410 iucv_unregister_dbf_views();
413 debug_register_view(iucv_dbf_setup, &debug_hex_ascii_view);
414 debug_set_level(iucv_dbf_setup, IUCV_DBF_SETUP_LEVEL);
416 debug_register_view(iucv_dbf_data, &debug_hex_ascii_view);
417 debug_set_level(iucv_dbf_data, IUCV_DBF_DATA_LEVEL);
419 debug_register_view(iucv_dbf_trace, &debug_hex_ascii_view);
420 debug_set_level(iucv_dbf_trace, IUCV_DBF_TRACE_LEVEL);
426 * Callback-wrappers, called from lowlevel iucv layer.
427 *****************************************************************************/
430 netiucv_callback_rx(iucv_MessagePending *eib, void *pgm_data)
432 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
433 struct iucv_event ev;
436 ev.data = (void *)eib;
438 fsm_event(conn->fsm, CONN_EVENT_RX, &ev);
442 netiucv_callback_txdone(iucv_MessageComplete *eib, void *pgm_data)
444 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
445 struct iucv_event ev;
448 ev.data = (void *)eib;
449 fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev);
453 netiucv_callback_connack(iucv_ConnectionComplete *eib, void *pgm_data)
455 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
456 struct iucv_event ev;
459 ev.data = (void *)eib;
460 fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, &ev);
464 netiucv_callback_connreq(iucv_ConnectionPending *eib, void *pgm_data)
466 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
467 struct iucv_event ev;
470 ev.data = (void *)eib;
471 fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev);
475 netiucv_callback_connrej(iucv_ConnectionSevered *eib, void *pgm_data)
477 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
478 struct iucv_event ev;
481 ev.data = (void *)eib;
482 fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, &ev);
486 netiucv_callback_connsusp(iucv_ConnectionQuiesced *eib, void *pgm_data)
488 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
489 struct iucv_event ev;
492 ev.data = (void *)eib;
493 fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, &ev);
497 netiucv_callback_connres(iucv_ConnectionResumed *eib, void *pgm_data)
499 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
500 struct iucv_event ev;
503 ev.data = (void *)eib;
504 fsm_event(conn->fsm, CONN_EVENT_CONN_RES, &ev);
507 static iucv_interrupt_ops_t netiucv_ops = {
508 .ConnectionPending = netiucv_callback_connreq,
509 .ConnectionComplete = netiucv_callback_connack,
510 .ConnectionSevered = netiucv_callback_connrej,
511 .ConnectionQuiesced = netiucv_callback_connsusp,
512 .ConnectionResumed = netiucv_callback_connres,
513 .MessagePending = netiucv_callback_rx,
514 .MessageComplete = netiucv_callback_txdone
518 * Dummy NOP action for all statemachines
521 fsm_action_nop(fsm_instance *fi, int event, void *arg)
526 * Actions of the connection statemachine
527 *****************************************************************************/
530 * Helper function for conn_action_rx()
531 * Unpack a just received skb and hand it over to
534 * @param conn The connection where this skb has been received.
535 * @param pskb The received skb.
537 //static __inline__ void
539 netiucv_unpack_skb(struct iucv_connection *conn, struct sk_buff *pskb)
541 struct net_device *dev = conn->netdev;
542 struct netiucv_priv *privptr = dev->priv;
545 skb_put(pskb, NETIUCV_HDRLEN);
547 pskb->ip_summed = CHECKSUM_NONE;
548 pskb->protocol = ntohs(ETH_P_IP);
552 ll_header *header = (ll_header *)pskb->data;
557 skb_pull(pskb, NETIUCV_HDRLEN);
558 header->next -= offset;
559 offset += header->next;
560 header->next -= NETIUCV_HDRLEN;
561 if (skb_tailroom(pskb) < header->next) {
562 PRINT_WARN("%s: Illegal next field in iucv header: "
564 dev->name, header->next, skb_tailroom(pskb));
565 IUCV_DBF_TEXT_(data, 2, "Illegal next field: %d > %d\n",
566 header->next, skb_tailroom(pskb));
569 skb_put(pskb, header->next);
570 pskb->mac.raw = pskb->data;
571 skb = dev_alloc_skb(pskb->len);
573 PRINT_WARN("%s Out of memory in netiucv_unpack_skb\n",
575 IUCV_DBF_TEXT(data, 2,
576 "Out of memory in netiucv_unpack_skb\n");
577 privptr->stats.rx_dropped++;
580 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
581 skb->mac.raw = skb->data;
582 skb->dev = pskb->dev;
583 skb->protocol = pskb->protocol;
584 pskb->ip_summed = CHECKSUM_UNNECESSARY;
586 * Since receiving is always initiated from a tasklet (in iucv.c),
587 * we must use netif_rx_ni() instead of netif_rx()
590 dev->last_rx = jiffies;
591 privptr->stats.rx_packets++;
592 privptr->stats.rx_bytes += skb->len;
593 skb_pull(pskb, header->next);
594 skb_put(pskb, NETIUCV_HDRLEN);
599 conn_action_rx(fsm_instance *fi, int event, void *arg)
601 struct iucv_event *ev = (struct iucv_event *)arg;
602 struct iucv_connection *conn = ev->conn;
603 iucv_MessagePending *eib = (iucv_MessagePending *)ev->data;
604 struct netiucv_priv *privptr =(struct netiucv_priv *)conn->netdev->priv;
606 __u32 msglen = eib->ln1msg2.ipbfln1f;
609 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
612 /* FRITZ: How to tell iucv LL to drop the msg? */
613 PRINT_WARN("Received data for unlinked connection\n");
614 IUCV_DBF_TEXT(data, 2,
615 "Received data for unlinked connection\n");
618 if (msglen > conn->max_buffsize) {
619 /* FRITZ: How to tell iucv LL to drop the msg? */
620 privptr->stats.rx_dropped++;
621 PRINT_WARN("msglen %d > max_buffsize %d\n",
622 msglen, conn->max_buffsize);
623 IUCV_DBF_TEXT_(data, 2, "msglen %d > max_buffsize %d\n",
624 msglen, conn->max_buffsize);
627 conn->rx_buff->data = conn->rx_buff->tail = conn->rx_buff->head;
628 conn->rx_buff->len = 0;
629 rc = iucv_receive(conn->pathid, eib->ipmsgid, eib->iptrgcls,
630 conn->rx_buff->data, msglen, NULL, NULL, NULL);
631 if (rc || msglen < 5) {
632 privptr->stats.rx_errors++;
633 PRINT_WARN("iucv_receive returned %08x\n", rc);
634 IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_receive\n", rc);
637 netiucv_unpack_skb(conn, conn->rx_buff);
641 conn_action_txdone(fsm_instance *fi, int event, void *arg)
643 struct iucv_event *ev = (struct iucv_event *)arg;
644 struct iucv_connection *conn = ev->conn;
645 iucv_MessageComplete *eib = (iucv_MessageComplete *)ev->data;
646 struct netiucv_priv *privptr = NULL;
647 /* Shut up, gcc! skb is always below 2G. */
648 __u32 single_flag = eib->ipmsgtag;
651 __u32 stat_maxcq = 0;
653 unsigned long saveflags;
656 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
658 if (conn && conn->netdev && conn->netdev->priv)
659 privptr = (struct netiucv_priv *)conn->netdev->priv;
660 conn->prof.tx_pending--;
662 if ((skb = skb_dequeue(&conn->commit_queue))) {
663 atomic_dec(&skb->users);
664 dev_kfree_skb_any(skb);
666 privptr->stats.tx_packets++;
667 privptr->stats.tx_bytes +=
668 (skb->len - NETIUCV_HDRLEN
673 conn->tx_buff->data = conn->tx_buff->tail = conn->tx_buff->head;
674 conn->tx_buff->len = 0;
675 spin_lock_irqsave(&conn->collect_lock, saveflags);
676 while ((skb = skb_dequeue(&conn->collect_queue))) {
677 header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN;
678 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
680 memcpy(skb_put(conn->tx_buff, skb->len), skb->data, skb->len);
684 atomic_dec(&skb->users);
685 dev_kfree_skb_any(skb);
687 if (conn->collect_len > conn->prof.maxmulti)
688 conn->prof.maxmulti = conn->collect_len;
689 conn->collect_len = 0;
690 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
691 if (conn->tx_buff->len) {
695 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
698 conn->prof.send_stamp = xtime;
699 rc = iucv_send(conn->pathid, NULL, 0, 0, 0, 0,
700 conn->tx_buff->data, conn->tx_buff->len);
701 conn->prof.doios_multi++;
702 conn->prof.txlen += conn->tx_buff->len;
703 conn->prof.tx_pending++;
704 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
705 conn->prof.tx_max_pending = conn->prof.tx_pending;
707 conn->prof.tx_pending--;
708 fsm_newstate(fi, CONN_STATE_IDLE);
710 privptr->stats.tx_errors += txpackets;
711 PRINT_WARN("iucv_send returned %08x\n", rc);
712 IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc);
715 privptr->stats.tx_packets += txpackets;
716 privptr->stats.tx_bytes += txbytes;
718 if (stat_maxcq > conn->prof.maxcqueue)
719 conn->prof.maxcqueue = stat_maxcq;
722 fsm_newstate(fi, CONN_STATE_IDLE);
726 conn_action_connaccept(fsm_instance *fi, int event, void *arg)
728 struct iucv_event *ev = (struct iucv_event *)arg;
729 struct iucv_connection *conn = ev->conn;
730 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
731 struct net_device *netdev = conn->netdev;
732 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
737 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
739 rc = iucv_accept(eib->ippathid, NETIUCV_QUEUELEN_DEFAULT, udata, 0,
740 conn->handle, conn, NULL, &msglimit);
742 PRINT_WARN("%s: IUCV accept failed with error %d\n",
744 IUCV_DBF_TEXT_(setup, 2, "rc %d from iucv_accept", rc);
747 fsm_newstate(fi, CONN_STATE_IDLE);
748 conn->pathid = eib->ippathid;
749 netdev->tx_queue_len = msglimit;
750 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
754 conn_action_connreject(fsm_instance *fi, int event, void *arg)
756 struct iucv_event *ev = (struct iucv_event *)arg;
757 struct iucv_connection *conn = ev->conn;
758 struct net_device *netdev = conn->netdev;
759 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
762 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
764 iucv_sever(eib->ippathid, udata);
765 if (eib->ippathid != conn->pathid) {
766 PRINT_INFO("%s: IR Connection Pending; "
767 "pathid %d does not match original pathid %d\n",
768 netdev->name, eib->ippathid, conn->pathid);
769 IUCV_DBF_TEXT_(data, 2,
770 "connreject: IR pathid %d, conn. pathid %d\n",
771 eib->ippathid, conn->pathid);
772 iucv_sever(conn->pathid, udata);
777 conn_action_connack(fsm_instance *fi, int event, void *arg)
779 struct iucv_event *ev = (struct iucv_event *)arg;
780 struct iucv_connection *conn = ev->conn;
781 iucv_ConnectionComplete *eib = (iucv_ConnectionComplete *)ev->data;
782 struct net_device *netdev = conn->netdev;
783 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
785 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
787 fsm_deltimer(&conn->timer);
788 fsm_newstate(fi, CONN_STATE_IDLE);
789 if (eib->ippathid != conn->pathid) {
790 PRINT_INFO("%s: IR Connection Complete; "
791 "pathid %d does not match original pathid %d\n",
792 netdev->name, eib->ippathid, conn->pathid);
793 IUCV_DBF_TEXT_(data, 2,
794 "connack: IR pathid %d, conn. pathid %d\n",
795 eib->ippathid, conn->pathid);
796 conn->pathid = eib->ippathid;
798 netdev->tx_queue_len = eib->ipmsglim;
799 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
803 conn_action_conntimsev(fsm_instance *fi, int event, void *arg)
805 struct iucv_connection *conn = (struct iucv_connection *)arg;
808 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
810 fsm_deltimer(&conn->timer);
811 iucv_sever(conn->pathid, udata);
812 fsm_newstate(fi, CONN_STATE_STARTWAIT);
816 conn_action_connsever(fsm_instance *fi, int event, void *arg)
818 struct iucv_event *ev = (struct iucv_event *)arg;
819 struct iucv_connection *conn = ev->conn;
820 struct net_device *netdev = conn->netdev;
821 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
824 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
826 fsm_deltimer(&conn->timer);
827 iucv_sever(conn->pathid, udata);
828 PRINT_INFO("%s: Remote dropped connection\n", netdev->name);
829 IUCV_DBF_TEXT(data, 2,
830 "conn_action_connsever: Remote dropped connection\n");
831 fsm_newstate(fi, CONN_STATE_STARTWAIT);
832 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
836 conn_action_start(fsm_instance *fi, int event, void *arg)
838 struct iucv_event *ev = (struct iucv_event *)arg;
839 struct iucv_connection *conn = ev->conn;
843 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
846 IUCV_DBF_TEXT(trace, 5, "calling iucv_register_program\n");
848 iucv_register_program(iucvMagic, conn->userid,
851 fsm_newstate(fi, CONN_STATE_STARTWAIT);
853 fsm_newstate(fi, CONN_STATE_REGERR);
855 IUCV_DBF_TEXT(setup, 2,
856 "NULL from iucv_register_program\n");
860 PRINT_DEBUG("%s('%s'): registered successfully\n",
861 conn->netdev->name, conn->userid);
864 PRINT_DEBUG("%s('%s'): connecting ...\n",
865 conn->netdev->name, conn->userid);
867 /* We must set the state before calling iucv_connect because the callback
868 * handler could be called at any point after the connection request is
871 fsm_newstate(fi, CONN_STATE_SETUPWAIT);
872 rc = iucv_connect(&(conn->pathid), NETIUCV_QUEUELEN_DEFAULT, iucvMagic,
873 conn->userid, iucv_host, 0, NULL, &msglimit,
877 conn->netdev->tx_queue_len = msglimit;
878 fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC,
879 CONN_EVENT_TIMER, conn);
882 PRINT_INFO("%s: User %s is currently not available.\n",
884 netiucv_printname(conn->userid));
885 fsm_newstate(fi, CONN_STATE_STARTWAIT);
888 PRINT_INFO("%s: User %s is currently not ready.\n",
890 netiucv_printname(conn->userid));
891 fsm_newstate(fi, CONN_STATE_STARTWAIT);
894 PRINT_WARN("%s: Too many IUCV connections.\n",
896 fsm_newstate(fi, CONN_STATE_CONNERR);
900 "%s: User %s has too many IUCV connections.\n",
902 netiucv_printname(conn->userid));
903 fsm_newstate(fi, CONN_STATE_CONNERR);
907 "%s: No IUCV authorization in CP directory.\n",
909 fsm_newstate(fi, CONN_STATE_CONNERR);
912 PRINT_WARN("%s: iucv_connect returned error %d\n",
913 conn->netdev->name, rc);
914 fsm_newstate(fi, CONN_STATE_CONNERR);
917 IUCV_DBF_TEXT_(setup, 5, "iucv_connect rc is %d\n", rc);
918 IUCV_DBF_TEXT(trace, 5, "calling iucv_unregister_program\n");
919 iucv_unregister_program(conn->handle);
924 netiucv_purge_skb_queue(struct sk_buff_head *q)
928 while ((skb = skb_dequeue(q))) {
929 atomic_dec(&skb->users);
930 dev_kfree_skb_any(skb);
935 conn_action_stop(fsm_instance *fi, int event, void *arg)
937 struct iucv_event *ev = (struct iucv_event *)arg;
938 struct iucv_connection *conn = ev->conn;
939 struct net_device *netdev = conn->netdev;
940 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
942 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
944 fsm_deltimer(&conn->timer);
945 fsm_newstate(fi, CONN_STATE_STOPPED);
946 netiucv_purge_skb_queue(&conn->collect_queue);
948 IUCV_DBF_TEXT(trace, 5, "calling iucv_unregister_program\n");
949 iucv_unregister_program(conn->handle);
951 netiucv_purge_skb_queue(&conn->commit_queue);
952 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
956 conn_action_inval(fsm_instance *fi, int event, void *arg)
958 struct iucv_event *ev = (struct iucv_event *)arg;
959 struct iucv_connection *conn = ev->conn;
960 struct net_device *netdev = conn->netdev;
962 PRINT_WARN("%s: Cannot connect without username\n",
964 IUCV_DBF_TEXT(data, 2, "conn_action_inval called\n");
967 static const fsm_node conn_fsm[] = {
968 { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval },
969 { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start },
971 { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop },
972 { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop },
973 { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop },
974 { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop },
975 { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop },
976 { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop },
977 { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop },
979 { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject },
980 { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
981 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
982 { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject },
983 { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject },
985 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack },
986 { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev },
988 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever },
989 { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever },
990 { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever },
992 { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx },
993 { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx },
995 { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone },
996 { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone },
999 static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node);
1003 * Actions for interface - statemachine.
1004 *****************************************************************************/
1007 * Startup connection by sending CONN_EVENT_START to it.
1009 * @param fi An instance of an interface statemachine.
1010 * @param event The event, just happened.
1011 * @param arg Generic pointer, casted from struct net_device * upon call.
1014 dev_action_start(fsm_instance *fi, int event, void *arg)
1016 struct net_device *dev = (struct net_device *)arg;
1017 struct netiucv_priv *privptr = dev->priv;
1018 struct iucv_event ev;
1020 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1022 ev.conn = privptr->conn;
1023 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1024 fsm_event(privptr->conn->fsm, CONN_EVENT_START, &ev);
1028 * Shutdown connection by sending CONN_EVENT_STOP to it.
1030 * @param fi An instance of an interface statemachine.
1031 * @param event The event, just happened.
1032 * @param arg Generic pointer, casted from struct net_device * upon call.
1035 dev_action_stop(fsm_instance *fi, int event, void *arg)
1037 struct net_device *dev = (struct net_device *)arg;
1038 struct netiucv_priv *privptr = dev->priv;
1039 struct iucv_event ev;
1041 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1043 ev.conn = privptr->conn;
1045 fsm_newstate(fi, DEV_STATE_STOPWAIT);
1046 fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev);
1050 * Called from connection statemachine
1051 * when a connection is up and running.
1053 * @param fi An instance of an interface statemachine.
1054 * @param event The event, just happened.
1055 * @param arg Generic pointer, casted from struct net_device * upon call.
1058 dev_action_connup(fsm_instance *fi, int event, void *arg)
1060 struct net_device *dev = (struct net_device *)arg;
1061 struct netiucv_priv *privptr = dev->priv;
1063 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1065 switch (fsm_getstate(fi)) {
1066 case DEV_STATE_STARTWAIT:
1067 fsm_newstate(fi, DEV_STATE_RUNNING);
1068 PRINT_INFO("%s: connected with remote side %s\n",
1069 dev->name, privptr->conn->userid);
1070 IUCV_DBF_TEXT(setup, 3,
1071 "connection is up and running\n");
1073 case DEV_STATE_STOPWAIT:
1075 "%s: got connection UP event during shutdown!\n",
1077 IUCV_DBF_TEXT(data, 2,
1078 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1084 * Called from connection statemachine
1085 * when a connection has been shutdown.
1087 * @param fi An instance of an interface statemachine.
1088 * @param event The event, just happened.
1089 * @param arg Generic pointer, casted from struct net_device * upon call.
1092 dev_action_conndown(fsm_instance *fi, int event, void *arg)
1094 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1096 switch (fsm_getstate(fi)) {
1097 case DEV_STATE_RUNNING:
1098 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1100 case DEV_STATE_STOPWAIT:
1101 fsm_newstate(fi, DEV_STATE_STOPPED);
1102 IUCV_DBF_TEXT(setup, 3, "connection is down\n");
1107 static const fsm_node dev_fsm[] = {
1108 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
1110 { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start },
1111 { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown },
1113 { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop },
1114 { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup },
1116 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
1117 { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown },
1118 { DEV_STATE_RUNNING, DEV_EVENT_CONUP, fsm_action_nop },
1121 static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node);
1124 * Transmit a packet.
1125 * This is a helper function for netiucv_tx().
1127 * @param conn Connection to be used for sending.
1128 * @param skb Pointer to struct sk_buff of packet to send.
1129 * The linklevel header has already been set up
1132 * @return 0 on success, -ERRNO on failure. (Never fails.)
1135 netiucv_transmit_skb(struct iucv_connection *conn, struct sk_buff *skb) {
1136 unsigned long saveflags;
1140 if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) {
1141 int l = skb->len + NETIUCV_HDRLEN;
1143 spin_lock_irqsave(&conn->collect_lock, saveflags);
1144 if (conn->collect_len + l >
1145 (conn->max_buffsize - NETIUCV_HDRLEN)) {
1147 IUCV_DBF_TEXT(data, 2,
1148 "EBUSY from netiucv_transmit_skb\n");
1150 atomic_inc(&skb->users);
1151 skb_queue_tail(&conn->collect_queue, skb);
1152 conn->collect_len += l;
1154 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
1156 struct sk_buff *nskb = skb;
1158 * Copy the skb to a new allocated skb in lowmem only if the
1159 * data is located above 2G in memory or tailroom is < 2.
1162 ((unsigned long)(skb->tail + NETIUCV_HDRLEN)) >> 31;
1164 if (hi || (skb_tailroom(skb) < 2)) {
1165 nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
1166 NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
1168 PRINT_WARN("%s: Could not allocate tx_skb\n",
1169 conn->netdev->name);
1170 IUCV_DBF_TEXT(data, 2, "alloc_skb failed\n");
1174 skb_reserve(nskb, NETIUCV_HDRLEN);
1175 memcpy(skb_put(nskb, skb->len),
1176 skb->data, skb->len);
1181 * skb now is below 2G and has enough room. Add headers.
1183 header.next = nskb->len + NETIUCV_HDRLEN;
1184 memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1186 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1188 fsm_newstate(conn->fsm, CONN_STATE_TX);
1189 conn->prof.send_stamp = xtime;
1191 rc = iucv_send(conn->pathid, NULL, 0, 0, 1 /* single_flag */,
1192 0, nskb->data, nskb->len);
1193 /* Shut up, gcc! nskb is always below 2G. */
1194 conn->prof.doios_single++;
1195 conn->prof.txlen += skb->len;
1196 conn->prof.tx_pending++;
1197 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
1198 conn->prof.tx_max_pending = conn->prof.tx_pending;
1200 struct netiucv_priv *privptr;
1201 fsm_newstate(conn->fsm, CONN_STATE_IDLE);
1202 conn->prof.tx_pending--;
1203 privptr = (struct netiucv_priv *)conn->netdev->priv;
1205 privptr->stats.tx_errors++;
1207 dev_kfree_skb(nskb);
1210 * Remove our headers. They get added
1211 * again on retransmit.
1213 skb_pull(skb, NETIUCV_HDRLEN);
1214 skb_trim(skb, skb->len - NETIUCV_HDRLEN);
1216 PRINT_WARN("iucv_send returned %08x\n", rc);
1217 IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc);
1221 atomic_inc(&nskb->users);
1222 skb_queue_tail(&conn->commit_queue, nskb);
1230 * Interface API for upper network layers
1231 *****************************************************************************/
1234 * Open an interface.
1235 * Called from generic network layer when ifconfig up is run.
1237 * @param dev Pointer to interface struct.
1239 * @return 0 on success, -ERRNO on failure. (Never fails.)
1242 netiucv_open(struct net_device *dev) {
1243 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_START,dev);
1248 * Close an interface.
1249 * Called from generic network layer when ifconfig down is run.
1251 * @param dev Pointer to interface struct.
1253 * @return 0 on success, -ERRNO on failure. (Never fails.)
1256 netiucv_close(struct net_device *dev) {
1257 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_STOP, dev);
1262 * Start transmission of a packet.
1263 * Called from generic network device layer.
1265 * @param skb Pointer to buffer containing the packet.
1266 * @param dev Pointer to interface struct.
1268 * @return 0 if packet consumed, !0 if packet rejected.
1269 * Note: If we return !0, then the packet is free'd by
1270 * the generic network layer.
1272 static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1275 struct netiucv_priv *privptr = dev->priv;
1277 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1279 * Some sanity checks ...
1282 PRINT_WARN("%s: NULL sk_buff passed\n", dev->name);
1283 IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n");
1284 privptr->stats.tx_dropped++;
1287 if (skb_headroom(skb) < NETIUCV_HDRLEN) {
1288 PRINT_WARN("%s: Got sk_buff with head room < %ld bytes\n",
1289 dev->name, NETIUCV_HDRLEN);
1290 IUCV_DBF_TEXT(data, 2,
1291 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1293 privptr->stats.tx_dropped++;
1298 * If connection is not running, try to restart it
1299 * and throw away packet.
1301 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1302 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1304 privptr->stats.tx_dropped++;
1305 privptr->stats.tx_errors++;
1306 privptr->stats.tx_carrier_errors++;
1310 if (netiucv_test_and_set_busy(dev)) {
1311 IUCV_DBF_TEXT(data, 2, "EBUSY from netiucv_tx\n");
1314 dev->trans_start = jiffies;
1315 if (netiucv_transmit_skb(privptr->conn, skb))
1317 netiucv_clear_busy(dev);
1322 * Returns interface statistics of a device.
1324 * @param dev Pointer to interface struct.
1326 * @return Pointer to stats struct of this interface.
1328 static struct net_device_stats *
1329 netiucv_stats (struct net_device * dev)
1331 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1332 return &((struct netiucv_priv *)dev->priv)->stats;
1336 * Sets MTU of an interface.
1338 * @param dev Pointer to interface struct.
1339 * @param new_mtu The new MTU to use for this interface.
1341 * @return 0 on success, -EINVAL if MTU is out of valid range.
1342 * (valid range is 576 .. NETIUCV_MTU_MAX).
1345 netiucv_change_mtu (struct net_device * dev, int new_mtu)
1347 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1348 if ((new_mtu < 576) || (new_mtu > NETIUCV_MTU_MAX)) {
1349 IUCV_DBF_TEXT(setup, 2, "given MTU out of valid range\n");
1357 * attributes in sysfs
1358 *****************************************************************************/
1361 user_show (struct device *dev, struct device_attribute *attr, char *buf)
1363 struct netiucv_priv *priv = dev->driver_data;
1365 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1366 return sprintf(buf, "%s\n", netiucv_printname(priv->conn->userid));
1370 user_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1372 struct netiucv_priv *priv = dev->driver_data;
1373 struct net_device *ndev = priv->conn->netdev;
1378 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1379 unsigned long flags;
1381 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1383 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count);
1384 IUCV_DBF_TEXT_(setup, 2,
1385 "%d is length of username\n", (int)count);
1389 tmp = strsep((char **) &buf, "\n");
1390 for (i=0, p=tmp; i<8 && *p; i++, p++) {
1391 if (isalnum(*p) || (*p == '$'))
1392 username[i]= toupper(*p);
1393 else if (*p == '\n') {
1394 /* trailing lf, grr */
1397 PRINT_WARN("netiucv: Invalid char %c in username!\n",
1399 IUCV_DBF_TEXT_(setup, 2,
1400 "username: invalid character %c\n",
1406 username[i++] = ' ';
1409 if (memcmp(username, priv->conn->userid, 9)) {
1410 /* username changed */
1411 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1413 "netiucv: device %s active, connected to %s\n",
1414 dev->bus_id, priv->conn->userid);
1415 PRINT_WARN("netiucv: user cannot be updated\n");
1416 IUCV_DBF_TEXT(setup, 2, "user_write: device active\n");
1420 read_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
1422 if (!strncmp(username, (*clist)->userid, 9) ||
1423 ((*clist)->netdev != ndev))
1425 clist = &((*clist)->next);
1427 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1429 PRINT_WARN("netiucv: Connection to %s already exists\n",
1433 memcpy(priv->conn->userid, username, 9);
1439 static DEVICE_ATTR(user, 0644, user_show, user_write);
1442 buffer_show (struct device *dev, struct device_attribute *attr, char *buf)
1444 struct netiucv_priv *priv = dev->driver_data;
1446 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1447 return sprintf(buf, "%d\n", priv->conn->max_buffsize);
1451 buffer_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1453 struct netiucv_priv *priv = dev->driver_data;
1454 struct net_device *ndev = priv->conn->netdev;
1458 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1462 bs1 = simple_strtoul(buf, &e, 0);
1464 if (e && (!isspace(*e))) {
1465 PRINT_WARN("netiucv: Invalid character in buffer!\n");
1466 IUCV_DBF_TEXT_(setup, 2, "buffer_write: invalid char %c\n", *e);
1469 if (bs1 > NETIUCV_BUFSIZE_MAX) {
1470 PRINT_WARN("netiucv: Given buffer size %d too large.\n",
1472 IUCV_DBF_TEXT_(setup, 2,
1473 "buffer_write: buffer size %d too large\n",
1477 if ((ndev->flags & IFF_RUNNING) &&
1478 (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2))) {
1479 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1481 IUCV_DBF_TEXT_(setup, 2,
1482 "buffer_write: buffer size %d too small\n",
1486 if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN)) {
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",
1495 priv->conn->max_buffsize = bs1;
1496 if (!(ndev->flags & IFF_RUNNING))
1497 ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN;
1503 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
1506 dev_fsm_show (struct device *dev, struct device_attribute *attr, char *buf)
1508 struct netiucv_priv *priv = dev->driver_data;
1510 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1511 return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm));
1514 static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL);
1517 conn_fsm_show (struct device *dev, struct device_attribute *attr, char *buf)
1519 struct netiucv_priv *priv = dev->driver_data;
1521 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1522 return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm));
1525 static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL);
1528 maxmulti_show (struct device *dev, struct device_attribute *attr, char *buf)
1530 struct netiucv_priv *priv = dev->driver_data;
1532 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1533 return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti);
1537 maxmulti_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1539 struct netiucv_priv *priv = dev->driver_data;
1541 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1542 priv->conn->prof.maxmulti = 0;
1546 static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write);
1549 maxcq_show (struct device *dev, struct device_attribute *attr, char *buf)
1551 struct netiucv_priv *priv = dev->driver_data;
1553 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1554 return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue);
1558 maxcq_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1560 struct netiucv_priv *priv = dev->driver_data;
1562 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1563 priv->conn->prof.maxcqueue = 0;
1567 static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write);
1570 sdoio_show (struct device *dev, struct device_attribute *attr, char *buf)
1572 struct netiucv_priv *priv = dev->driver_data;
1574 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1575 return sprintf(buf, "%ld\n", priv->conn->prof.doios_single);
1579 sdoio_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1581 struct netiucv_priv *priv = dev->driver_data;
1583 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1584 priv->conn->prof.doios_single = 0;
1588 static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write);
1591 mdoio_show (struct device *dev, struct device_attribute *attr, char *buf)
1593 struct netiucv_priv *priv = dev->driver_data;
1595 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1596 return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi);
1600 mdoio_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1602 struct netiucv_priv *priv = dev->driver_data;
1604 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1605 priv->conn->prof.doios_multi = 0;
1609 static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write);
1612 txlen_show (struct device *dev, struct device_attribute *attr, char *buf)
1614 struct netiucv_priv *priv = dev->driver_data;
1616 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1617 return sprintf(buf, "%ld\n", priv->conn->prof.txlen);
1621 txlen_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1623 struct netiucv_priv *priv = dev->driver_data;
1625 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1626 priv->conn->prof.txlen = 0;
1630 static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write);
1633 txtime_show (struct device *dev, struct device_attribute *attr, char *buf)
1635 struct netiucv_priv *priv = dev->driver_data;
1637 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1638 return sprintf(buf, "%ld\n", priv->conn->prof.tx_time);
1642 txtime_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1644 struct netiucv_priv *priv = dev->driver_data;
1646 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1647 priv->conn->prof.tx_time = 0;
1651 static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write);
1654 txpend_show (struct device *dev, struct device_attribute *attr, char *buf)
1656 struct netiucv_priv *priv = dev->driver_data;
1658 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1659 return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending);
1663 txpend_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1665 struct netiucv_priv *priv = dev->driver_data;
1667 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1668 priv->conn->prof.tx_pending = 0;
1672 static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write);
1675 txmpnd_show (struct device *dev, struct device_attribute *attr, char *buf)
1677 struct netiucv_priv *priv = dev->driver_data;
1679 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1680 return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending);
1684 txmpnd_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1686 struct netiucv_priv *priv = dev->driver_data;
1688 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1689 priv->conn->prof.tx_max_pending = 0;
1693 static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write);
1695 static struct attribute *netiucv_attrs[] = {
1696 &dev_attr_buffer.attr,
1697 &dev_attr_user.attr,
1701 static struct attribute_group netiucv_attr_group = {
1702 .attrs = netiucv_attrs,
1705 static struct attribute *netiucv_stat_attrs[] = {
1706 &dev_attr_device_fsm_state.attr,
1707 &dev_attr_connection_fsm_state.attr,
1708 &dev_attr_max_tx_buffer_used.attr,
1709 &dev_attr_max_chained_skbs.attr,
1710 &dev_attr_tx_single_write_ops.attr,
1711 &dev_attr_tx_multi_write_ops.attr,
1712 &dev_attr_netto_bytes.attr,
1713 &dev_attr_max_tx_io_time.attr,
1714 &dev_attr_tx_pending.attr,
1715 &dev_attr_tx_max_pending.attr,
1719 static struct attribute_group netiucv_stat_attr_group = {
1721 .attrs = netiucv_stat_attrs,
1725 netiucv_add_files(struct device *dev)
1729 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1730 ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group);
1733 ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group);
1735 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1740 netiucv_remove_files(struct device *dev)
1742 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1743 sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group);
1744 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1748 netiucv_register_device(struct net_device *ndev)
1750 struct netiucv_priv *priv = ndev->priv;
1751 struct device *dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1755 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1758 snprintf(dev->bus_id, BUS_ID_SIZE, "net%s", ndev->name);
1759 dev->bus = &iucv_bus;
1760 dev->parent = iucv_root;
1762 * The release function could be called after the
1763 * module has been unloaded. It's _only_ task is to
1764 * free the struct. Therefore, we specify kfree()
1765 * directly here. (Probably a little bit obfuscating
1766 * but legitime ...).
1768 dev->release = (void (*)(struct device *))kfree;
1769 dev->driver = &netiucv_driver;
1773 ret = device_register(dev);
1777 ret = netiucv_add_files(dev);
1781 dev->driver_data = priv;
1785 device_unregister(dev);
1790 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 *
1802 netiucv_new_connection(struct net_device *dev, char *username)
1804 unsigned long flags;
1805 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1806 struct iucv_connection *conn =
1807 kzalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1810 skb_queue_head_init(&conn->collect_queue);
1811 skb_queue_head_init(&conn->commit_queue);
1812 spin_lock_init(&conn->collect_lock);
1813 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1816 conn->rx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1817 GFP_KERNEL | GFP_DMA);
1818 if (!conn->rx_buff) {
1822 conn->tx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1823 GFP_KERNEL | GFP_DMA);
1824 if (!conn->tx_buff) {
1825 kfree_skb(conn->rx_buff);
1829 conn->fsm = init_fsm("netiucvconn", conn_state_names,
1830 conn_event_names, NR_CONN_STATES,
1831 NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN,
1834 kfree_skb(conn->tx_buff);
1835 kfree_skb(conn->rx_buff);
1839 fsm_settimer(conn->fsm, &conn->timer);
1840 fsm_newstate(conn->fsm, CONN_STATE_INVALID);
1843 memcpy(conn->userid, username, 9);
1844 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1847 write_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
1848 conn->next = *clist;
1850 write_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1856 * Release a connection structure and remove it from the
1857 * list of netiucv connections.
1860 netiucv_remove_connection(struct iucv_connection *conn)
1862 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1863 unsigned long flags;
1865 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1868 write_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
1870 if (*clist == conn) {
1871 *clist = conn->next;
1872 write_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1874 iucv_unregister_program(conn->handle);
1875 conn->handle = NULL;
1877 fsm_deltimer(&conn->timer);
1878 kfree_fsm(conn->fsm);
1879 kfree_skb(conn->rx_buff);
1880 kfree_skb(conn->tx_buff);
1883 clist = &((*clist)->next);
1885 write_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1889 * Release everything of a net device.
1892 netiucv_free_netdevice(struct net_device *dev)
1894 struct netiucv_priv *privptr;
1896 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1901 privptr = (struct netiucv_priv *)dev->priv;
1904 netiucv_remove_connection(privptr->conn);
1906 kfree_fsm(privptr->fsm);
1907 privptr->conn = NULL; privptr->fsm = NULL;
1908 /* privptr gets freed by free_netdev() */
1914 * Initialize a net device. (Called from kernel in alloc_netdev())
1917 netiucv_setup_netdevice(struct net_device *dev)
1919 memset(dev->priv, 0, sizeof(struct netiucv_priv));
1921 dev->mtu = NETIUCV_MTU_DEFAULT;
1922 dev->hard_start_xmit = netiucv_tx;
1923 dev->open = netiucv_open;
1924 dev->stop = netiucv_close;
1925 dev->get_stats = netiucv_stats;
1926 dev->change_mtu = netiucv_change_mtu;
1927 dev->destructor = netiucv_free_netdevice;
1928 dev->hard_header_len = NETIUCV_HDRLEN;
1930 dev->type = ARPHRD_SLIP;
1931 dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT;
1932 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1933 SET_MODULE_OWNER(dev);
1937 * Allocate and initialize everything of a net device.
1939 static struct net_device *
1940 netiucv_init_netdevice(char *username)
1942 struct netiucv_priv *privptr;
1943 struct net_device *dev;
1945 dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d",
1946 netiucv_setup_netdevice);
1949 if (dev_alloc_name(dev, dev->name) < 0) {
1954 privptr = (struct netiucv_priv *)dev->priv;
1955 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
1956 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
1957 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
1958 if (!privptr->fsm) {
1962 privptr->conn = netiucv_new_connection(dev, username);
1963 if (!privptr->conn) {
1964 kfree_fsm(privptr->fsm);
1966 IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_new_connection\n");
1969 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
1975 conn_write(struct device_driver *drv, const char *buf, size_t count)
1980 struct net_device *dev;
1981 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1982 unsigned long flags;
1984 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1986 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count);
1987 IUCV_DBF_TEXT(setup, 2, "conn_write: too long\n");
1991 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) {
1992 if (isalnum(*p) || (*p == '$'))
1993 username[i]= toupper(*p);
1994 else if (*p == '\n') {
1995 /* trailing lf, grr */
1998 PRINT_WARN("netiucv: Invalid character in username!\n");
1999 IUCV_DBF_TEXT_(setup, 2,
2000 "conn_write: invalid character %c\n", *p);
2005 username[i++] = ' ';
2008 read_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
2010 if (!strncmp(username, (*clist)->userid, 9))
2012 clist = &((*clist)->next);
2014 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
2016 PRINT_WARN("netiucv: Connection to %s already exists\n",
2020 dev = netiucv_init_netdevice(username);
2023 "netiucv: Could not allocate network device structure "
2024 "for user '%s'\n", netiucv_printname(username));
2025 IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_init_netdevice\n");
2029 if ((ret = netiucv_register_device(dev))) {
2030 IUCV_DBF_TEXT_(setup, 2,
2031 "ret %d from netiucv_register_device\n", ret);
2037 (struct device*)((struct netiucv_priv*)dev->priv)->dev);
2039 if ((ret = register_netdev(dev))) {
2040 netiucv_unregister_device((struct device*)
2041 ((struct netiucv_priv*)dev->priv)->dev);
2045 PRINT_INFO("%s: '%s'\n", dev->name, netiucv_printname(username));
2050 PRINT_WARN("netiucv: Could not register '%s'\n", dev->name);
2051 IUCV_DBF_TEXT(setup, 2, "conn_write: could not register\n");
2052 netiucv_free_netdevice(dev);
2056 DRIVER_ATTR(connection, 0200, NULL, conn_write);
2059 remove_write (struct device_driver *drv, const char *buf, size_t count)
2061 struct iucv_connection **clist = &iucv_conns.iucv_connections;
2062 unsigned long flags;
2063 struct net_device *ndev;
2064 struct netiucv_priv *priv;
2066 char name[IFNAMSIZ];
2070 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2072 if (count >= IFNAMSIZ)
2073 count = IFNAMSIZ - 1;;
2075 for (i=0, p=(char *)buf; i<count && *p; i++, p++) {
2076 if ((*p == '\n') || (*p == ' ')) {
2077 /* trailing lf, grr */
2085 read_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
2087 ndev = (*clist)->netdev;
2088 priv = (struct netiucv_priv*)ndev->priv;
2091 if (strncmp(name, ndev->name, count)) {
2092 clist = &((*clist)->next);
2095 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
2096 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
2098 "netiucv: net device %s active with peer %s\n",
2099 ndev->name, priv->conn->userid);
2100 PRINT_WARN("netiucv: %s cannot be removed\n",
2102 IUCV_DBF_TEXT(data, 2, "remove_write: still active\n");
2105 unregister_netdev(ndev);
2106 netiucv_unregister_device(dev);
2109 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
2110 PRINT_WARN("netiucv: net device %s unknown\n", name);
2111 IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n");
2115 DRIVER_ATTR(remove, 0200, NULL, remove_write);
2118 netiucv_banner(void)
2120 PRINT_INFO("NETIUCV driver initialized\n");
2126 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2127 while (iucv_conns.iucv_connections) {
2128 struct net_device *ndev = iucv_conns.iucv_connections->netdev;
2129 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv;
2130 struct device *dev = priv->dev;
2132 unregister_netdev(ndev);
2133 netiucv_unregister_device(dev);
2136 driver_remove_file(&netiucv_driver, &driver_attr_connection);
2137 driver_remove_file(&netiucv_driver, &driver_attr_remove);
2138 driver_unregister(&netiucv_driver);
2139 iucv_unregister_dbf_views();
2141 PRINT_INFO("NETIUCV driver unloaded\n");
2150 ret = iucv_register_dbf_views();
2152 PRINT_WARN("netiucv_init failed, "
2153 "iucv_register_dbf_views rc = %d\n", ret);
2156 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2157 ret = driver_register(&netiucv_driver);
2159 PRINT_ERR("NETIUCV: failed to register driver.\n");
2160 IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_register\n", ret);
2161 iucv_unregister_dbf_views();
2165 /* Add entry for specifying connections. */
2166 ret = driver_create_file(&netiucv_driver, &driver_attr_connection);
2168 ret = driver_create_file(&netiucv_driver, &driver_attr_remove);
2170 rwlock_init(&iucv_conns.iucv_rwlock);
2172 PRINT_ERR("NETIUCV: failed to add driver attribute.\n");
2173 IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_create_file\n", ret);
2174 driver_unregister(&netiucv_driver);
2175 iucv_unregister_dbf_views();
2180 module_init(netiucv_init);
2181 module_exit(netiucv_exit);
2182 MODULE_LICENSE("GPL");