2 * $Id: netiucv.c,v 1.66 2005/05/11 08:10:17 holzheu Exp $
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
9 * Driverfs integration and all bugs therein by Cornelia Huck(cohuck@de.ibm.com)
12 * the source of the original IUCV driver by:
13 * Stefan Hegewald <hegewald@de.ibm.com>
14 * Hartmut Penner <hpenner@de.ibm.com>
15 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
16 * Martin Schwidefsky (schwidefsky@de.ibm.com)
17 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2, or (at your option)
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 * RELEASE-TAG: IUCV network driver $Revision: 1.66 $
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/kernel.h>
42 #include <linux/slab.h>
43 #include <linux/errno.h>
44 #include <linux/types.h>
45 #include <linux/interrupt.h>
46 #include <linux/timer.h>
47 #include <linux/sched.h>
48 #include <linux/bitops.h>
50 #include <linux/signal.h>
51 #include <linux/string.h>
52 #include <linux/device.h>
55 #include <linux/if_arp.h>
56 #include <linux/tcp.h>
57 #include <linux/skbuff.h>
58 #include <linux/ctype.h>
62 #include <asm/uaccess.h>
68 ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)");
69 MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver");
72 #define PRINTK_HEADER " iucv: " /* for debugging */
74 static struct device_driver netiucv_driver = {
80 * Per connection profiling data
82 struct connection_profile {
83 unsigned long maxmulti;
84 unsigned long maxcqueue;
85 unsigned long doios_single;
86 unsigned long doios_multi;
88 unsigned long tx_time;
89 struct timespec send_stamp;
90 unsigned long tx_pending;
91 unsigned long tx_max_pending;
95 * Representation of one iucv connection
97 struct iucv_connection {
98 struct iucv_connection *next;
101 struct sk_buff *rx_buff;
102 struct sk_buff *tx_buff;
103 struct sk_buff_head collect_queue;
104 struct sk_buff_head commit_queue;
105 spinlock_t collect_lock;
110 struct net_device *netdev;
111 struct connection_profile prof;
116 * Linked list of all connection structs.
118 static struct iucv_connection *iucv_connections;
121 * Representation of event-data for the
122 * connection state machine.
125 struct iucv_connection *conn;
130 * Private part of the network device structure
132 struct netiucv_priv {
133 struct net_device_stats stats;
136 struct iucv_connection *conn;
141 * Link level header for a packet.
143 typedef struct ll_header_t {
147 #define NETIUCV_HDRLEN (sizeof(ll_header))
148 #define NETIUCV_BUFSIZE_MAX 32768
149 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
150 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
151 #define NETIUCV_MTU_DEFAULT 9216
152 #define NETIUCV_QUEUELEN_DEFAULT 50
153 #define NETIUCV_TIMEOUT_5SEC 5000
156 * Compatibility macros for busy handling
157 * of network devices.
159 static __inline__ void netiucv_clear_busy(struct net_device *dev)
161 clear_bit(0, &(((struct netiucv_priv *)dev->priv)->tbusy));
162 netif_wake_queue(dev);
165 static __inline__ int netiucv_test_and_set_busy(struct net_device *dev)
167 netif_stop_queue(dev);
168 return test_and_set_bit(0, &((struct netiucv_priv *)dev->priv)->tbusy);
171 static __u8 iucv_host[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
172 static __u8 iucvMagic[16] = {
173 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
174 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
178 * This mask means the 16-byte IUCV "magic" and the origin userid must
179 * match exactly as specified in order to give connection_pending()
182 static __u8 netiucv_mask[] = {
183 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
184 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
185 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
189 * Convert an iucv userId to its printable
190 * form (strip whitespace at end).
192 * @param An iucv userId
194 * @returns The printable string (static data!!)
196 static __inline__ char *
197 netiucv_printname(char *name)
201 memcpy(tmp, name, 8);
203 while (*p && (!isspace(*p)))
210 * States of the interface statemachine.
218 * MUST be always the last element!!
223 static const char *dev_state_names[] = {
231 * Events of the interface statemachine.
239 * MUST be always the last element!!
244 static const char *dev_event_names[] = {
252 * Events of the connection statemachine
256 * Events, representing callbacks from
257 * lowlevel iucv layer)
268 * Events, representing errors return codes from
269 * calls to lowlevel iucv layer
273 * Event, representing timer expiry.
278 * Events, representing commands from upper levels.
284 * MUST be always the last element!!
289 static const char *conn_event_names[] = {
290 "Remote connection request",
291 "Remote connection acknowledge",
292 "Remote connection reject",
293 "Connection suspended",
294 "Connection resumed",
305 * States of the connection statemachine.
309 * Connection not assigned to any device,
310 * initial state, invalid
315 * Userid assigned but not operating
320 * Connection registered,
321 * no connection request sent yet,
322 * no connection request received
324 CONN_STATE_STARTWAIT,
327 * Connection registered and connection request sent,
328 * no acknowledge and no connection request received yet.
330 CONN_STATE_SETUPWAIT,
333 * Connection up and running idle
338 * Data sent, awaiting CONN_EVENT_TXDONE
343 * Error during registration.
348 * Error during registration.
353 * MUST be always the last element!!
358 static const char *conn_state_names[] = {
366 "Registration error",
372 * Debug Facility Stuff
374 static debug_info_t *iucv_dbf_setup = NULL;
375 static debug_info_t *iucv_dbf_data = NULL;
376 static debug_info_t *iucv_dbf_trace = NULL;
378 DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf);
381 iucv_unregister_dbf_views(void)
384 debug_unregister(iucv_dbf_setup);
386 debug_unregister(iucv_dbf_data);
388 debug_unregister(iucv_dbf_trace);
391 iucv_register_dbf_views(void)
393 iucv_dbf_setup = debug_register(IUCV_DBF_SETUP_NAME,
394 IUCV_DBF_SETUP_PAGES,
395 IUCV_DBF_SETUP_NR_AREAS,
397 iucv_dbf_data = debug_register(IUCV_DBF_DATA_NAME,
399 IUCV_DBF_DATA_NR_AREAS,
401 iucv_dbf_trace = debug_register(IUCV_DBF_TRACE_NAME,
402 IUCV_DBF_TRACE_PAGES,
403 IUCV_DBF_TRACE_NR_AREAS,
406 if ((iucv_dbf_setup == NULL) || (iucv_dbf_data == NULL) ||
407 (iucv_dbf_trace == NULL)) {
408 iucv_unregister_dbf_views();
411 debug_register_view(iucv_dbf_setup, &debug_hex_ascii_view);
412 debug_set_level(iucv_dbf_setup, IUCV_DBF_SETUP_LEVEL);
414 debug_register_view(iucv_dbf_data, &debug_hex_ascii_view);
415 debug_set_level(iucv_dbf_data, IUCV_DBF_DATA_LEVEL);
417 debug_register_view(iucv_dbf_trace, &debug_hex_ascii_view);
418 debug_set_level(iucv_dbf_trace, IUCV_DBF_TRACE_LEVEL);
424 * Callback-wrappers, called from lowlevel iucv layer.
425 *****************************************************************************/
428 netiucv_callback_rx(iucv_MessagePending *eib, void *pgm_data)
430 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
431 struct iucv_event ev;
434 ev.data = (void *)eib;
436 fsm_event(conn->fsm, CONN_EVENT_RX, &ev);
440 netiucv_callback_txdone(iucv_MessageComplete *eib, void *pgm_data)
442 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
443 struct iucv_event ev;
446 ev.data = (void *)eib;
447 fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev);
451 netiucv_callback_connack(iucv_ConnectionComplete *eib, void *pgm_data)
453 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
454 struct iucv_event ev;
457 ev.data = (void *)eib;
458 fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, &ev);
462 netiucv_callback_connreq(iucv_ConnectionPending *eib, void *pgm_data)
464 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
465 struct iucv_event ev;
468 ev.data = (void *)eib;
469 fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev);
473 netiucv_callback_connrej(iucv_ConnectionSevered *eib, void *pgm_data)
475 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
476 struct iucv_event ev;
479 ev.data = (void *)eib;
480 fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, &ev);
484 netiucv_callback_connsusp(iucv_ConnectionQuiesced *eib, void *pgm_data)
486 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
487 struct iucv_event ev;
490 ev.data = (void *)eib;
491 fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, &ev);
495 netiucv_callback_connres(iucv_ConnectionResumed *eib, void *pgm_data)
497 struct iucv_connection *conn = (struct iucv_connection *)pgm_data;
498 struct iucv_event ev;
501 ev.data = (void *)eib;
502 fsm_event(conn->fsm, CONN_EVENT_CONN_RES, &ev);
505 static iucv_interrupt_ops_t netiucv_ops = {
506 .ConnectionPending = netiucv_callback_connreq,
507 .ConnectionComplete = netiucv_callback_connack,
508 .ConnectionSevered = netiucv_callback_connrej,
509 .ConnectionQuiesced = netiucv_callback_connsusp,
510 .ConnectionResumed = netiucv_callback_connres,
511 .MessagePending = netiucv_callback_rx,
512 .MessageComplete = netiucv_callback_txdone
516 * Dummy NOP action for all statemachines
519 fsm_action_nop(fsm_instance *fi, int event, void *arg)
524 * Actions of the connection statemachine
525 *****************************************************************************/
528 * Helper function for conn_action_rx()
529 * Unpack a just received skb and hand it over to
532 * @param conn The connection where this skb has been received.
533 * @param pskb The received skb.
535 //static __inline__ void
537 netiucv_unpack_skb(struct iucv_connection *conn, struct sk_buff *pskb)
539 struct net_device *dev = conn->netdev;
540 struct netiucv_priv *privptr = dev->priv;
543 skb_put(pskb, NETIUCV_HDRLEN);
545 pskb->ip_summed = CHECKSUM_NONE;
546 pskb->protocol = ntohs(ETH_P_IP);
550 ll_header *header = (ll_header *)pskb->data;
555 skb_pull(pskb, NETIUCV_HDRLEN);
556 header->next -= offset;
557 offset += header->next;
558 header->next -= NETIUCV_HDRLEN;
559 if (skb_tailroom(pskb) < header->next) {
560 PRINT_WARN("%s: Illegal next field in iucv header: "
562 dev->name, header->next, skb_tailroom(pskb));
563 IUCV_DBF_TEXT_(data, 2, "Illegal next field: %d > %d\n",
564 header->next, skb_tailroom(pskb));
567 skb_put(pskb, header->next);
568 pskb->mac.raw = pskb->data;
569 skb = dev_alloc_skb(pskb->len);
571 PRINT_WARN("%s Out of memory in netiucv_unpack_skb\n",
573 IUCV_DBF_TEXT(data, 2,
574 "Out of memory in netiucv_unpack_skb\n");
575 privptr->stats.rx_dropped++;
578 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
579 skb->mac.raw = skb->data;
580 skb->dev = pskb->dev;
581 skb->protocol = pskb->protocol;
582 pskb->ip_summed = CHECKSUM_UNNECESSARY;
584 * Since receiving is always initiated from a tasklet (in iucv.c),
585 * we must use netif_rx_ni() instead of netif_rx()
588 dev->last_rx = jiffies;
589 privptr->stats.rx_packets++;
590 privptr->stats.rx_bytes += skb->len;
591 skb_pull(pskb, header->next);
592 skb_put(pskb, NETIUCV_HDRLEN);
597 conn_action_rx(fsm_instance *fi, int event, void *arg)
599 struct iucv_event *ev = (struct iucv_event *)arg;
600 struct iucv_connection *conn = ev->conn;
601 iucv_MessagePending *eib = (iucv_MessagePending *)ev->data;
602 struct netiucv_priv *privptr =(struct netiucv_priv *)conn->netdev->priv;
604 __u32 msglen = eib->ln1msg2.ipbfln1f;
607 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
610 /* FRITZ: How to tell iucv LL to drop the msg? */
611 PRINT_WARN("Received data for unlinked connection\n");
612 IUCV_DBF_TEXT(data, 2,
613 "Received data for unlinked connection\n");
616 if (msglen > conn->max_buffsize) {
617 /* FRITZ: How to tell iucv LL to drop the msg? */
618 privptr->stats.rx_dropped++;
619 PRINT_WARN("msglen %d > max_buffsize %d\n",
620 msglen, conn->max_buffsize);
621 IUCV_DBF_TEXT_(data, 2, "msglen %d > max_buffsize %d\n",
622 msglen, conn->max_buffsize);
625 conn->rx_buff->data = conn->rx_buff->tail = conn->rx_buff->head;
626 conn->rx_buff->len = 0;
627 rc = iucv_receive(conn->pathid, eib->ipmsgid, eib->iptrgcls,
628 conn->rx_buff->data, msglen, NULL, NULL, NULL);
629 if (rc || msglen < 5) {
630 privptr->stats.rx_errors++;
631 PRINT_WARN("iucv_receive returned %08x\n", rc);
632 IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_receive\n", rc);
635 netiucv_unpack_skb(conn, conn->rx_buff);
639 conn_action_txdone(fsm_instance *fi, int event, void *arg)
641 struct iucv_event *ev = (struct iucv_event *)arg;
642 struct iucv_connection *conn = ev->conn;
643 iucv_MessageComplete *eib = (iucv_MessageComplete *)ev->data;
644 struct netiucv_priv *privptr = NULL;
645 /* Shut up, gcc! skb is always below 2G. */
646 __u32 single_flag = eib->ipmsgtag;
649 __u32 stat_maxcq = 0;
651 unsigned long saveflags;
654 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
656 if (conn && conn->netdev && conn->netdev->priv)
657 privptr = (struct netiucv_priv *)conn->netdev->priv;
658 conn->prof.tx_pending--;
660 if ((skb = skb_dequeue(&conn->commit_queue))) {
661 atomic_dec(&skb->users);
662 dev_kfree_skb_any(skb);
664 privptr->stats.tx_packets++;
665 privptr->stats.tx_bytes +=
666 (skb->len - NETIUCV_HDRLEN
671 conn->tx_buff->data = conn->tx_buff->tail = conn->tx_buff->head;
672 conn->tx_buff->len = 0;
673 spin_lock_irqsave(&conn->collect_lock, saveflags);
674 while ((skb = skb_dequeue(&conn->collect_queue))) {
675 header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN;
676 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
678 memcpy(skb_put(conn->tx_buff, skb->len), skb->data, skb->len);
682 atomic_dec(&skb->users);
683 dev_kfree_skb_any(skb);
685 if (conn->collect_len > conn->prof.maxmulti)
686 conn->prof.maxmulti = conn->collect_len;
687 conn->collect_len = 0;
688 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
689 if (conn->tx_buff->len) {
693 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header,
696 conn->prof.send_stamp = xtime;
697 rc = iucv_send(conn->pathid, NULL, 0, 0, 0, 0,
698 conn->tx_buff->data, conn->tx_buff->len);
699 conn->prof.doios_multi++;
700 conn->prof.txlen += conn->tx_buff->len;
701 conn->prof.tx_pending++;
702 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
703 conn->prof.tx_max_pending = conn->prof.tx_pending;
705 conn->prof.tx_pending--;
706 fsm_newstate(fi, CONN_STATE_IDLE);
708 privptr->stats.tx_errors += txpackets;
709 PRINT_WARN("iucv_send returned %08x\n", rc);
710 IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc);
713 privptr->stats.tx_packets += txpackets;
714 privptr->stats.tx_bytes += txbytes;
716 if (stat_maxcq > conn->prof.maxcqueue)
717 conn->prof.maxcqueue = stat_maxcq;
720 fsm_newstate(fi, CONN_STATE_IDLE);
724 conn_action_connaccept(fsm_instance *fi, int event, void *arg)
726 struct iucv_event *ev = (struct iucv_event *)arg;
727 struct iucv_connection *conn = ev->conn;
728 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
729 struct net_device *netdev = conn->netdev;
730 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
735 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
737 rc = iucv_accept(eib->ippathid, NETIUCV_QUEUELEN_DEFAULT, udata, 0,
738 conn->handle, conn, NULL, &msglimit);
740 PRINT_WARN("%s: IUCV accept failed with error %d\n",
742 IUCV_DBF_TEXT_(setup, 2, "rc %d from iucv_accept", rc);
745 fsm_newstate(fi, CONN_STATE_IDLE);
746 conn->pathid = eib->ippathid;
747 netdev->tx_queue_len = msglimit;
748 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
752 conn_action_connreject(fsm_instance *fi, int event, void *arg)
754 struct iucv_event *ev = (struct iucv_event *)arg;
755 struct iucv_connection *conn = ev->conn;
756 struct net_device *netdev = conn->netdev;
757 iucv_ConnectionPending *eib = (iucv_ConnectionPending *)ev->data;
760 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
762 iucv_sever(eib->ippathid, udata);
763 if (eib->ippathid != conn->pathid) {
764 PRINT_INFO("%s: IR Connection Pending; "
765 "pathid %d does not match original pathid %d\n",
766 netdev->name, eib->ippathid, conn->pathid);
767 IUCV_DBF_TEXT_(data, 2,
768 "connreject: IR pathid %d, conn. pathid %d\n",
769 eib->ippathid, conn->pathid);
770 iucv_sever(conn->pathid, udata);
775 conn_action_connack(fsm_instance *fi, int event, void *arg)
777 struct iucv_event *ev = (struct iucv_event *)arg;
778 struct iucv_connection *conn = ev->conn;
779 iucv_ConnectionComplete *eib = (iucv_ConnectionComplete *)ev->data;
780 struct net_device *netdev = conn->netdev;
781 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
783 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
785 fsm_deltimer(&conn->timer);
786 fsm_newstate(fi, CONN_STATE_IDLE);
787 if (eib->ippathid != conn->pathid) {
788 PRINT_INFO("%s: IR Connection Complete; "
789 "pathid %d does not match original pathid %d\n",
790 netdev->name, eib->ippathid, conn->pathid);
791 IUCV_DBF_TEXT_(data, 2,
792 "connack: IR pathid %d, conn. pathid %d\n",
793 eib->ippathid, conn->pathid);
794 conn->pathid = eib->ippathid;
796 netdev->tx_queue_len = eib->ipmsglim;
797 fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev);
801 conn_action_conntimsev(fsm_instance *fi, int event, void *arg)
803 struct iucv_connection *conn = (struct iucv_connection *)arg;
806 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
808 fsm_deltimer(&conn->timer);
809 iucv_sever(conn->pathid, udata);
810 fsm_newstate(fi, CONN_STATE_STARTWAIT);
814 conn_action_connsever(fsm_instance *fi, int event, void *arg)
816 struct iucv_event *ev = (struct iucv_event *)arg;
817 struct iucv_connection *conn = ev->conn;
818 struct net_device *netdev = conn->netdev;
819 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
822 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
824 fsm_deltimer(&conn->timer);
825 iucv_sever(conn->pathid, udata);
826 PRINT_INFO("%s: Remote dropped connection\n", netdev->name);
827 IUCV_DBF_TEXT(data, 2,
828 "conn_action_connsever: Remote dropped connection\n");
829 fsm_newstate(fi, CONN_STATE_STARTWAIT);
830 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
834 conn_action_start(fsm_instance *fi, int event, void *arg)
836 struct iucv_event *ev = (struct iucv_event *)arg;
837 struct iucv_connection *conn = ev->conn;
841 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
844 IUCV_DBF_TEXT(trace, 5, "calling iucv_register_program\n");
846 iucv_register_program(iucvMagic, conn->userid,
849 fsm_newstate(fi, CONN_STATE_STARTWAIT);
851 fsm_newstate(fi, CONN_STATE_REGERR);
853 IUCV_DBF_TEXT(setup, 2,
854 "NULL from iucv_register_program\n");
858 PRINT_DEBUG("%s('%s'): registered successfully\n",
859 conn->netdev->name, conn->userid);
862 PRINT_DEBUG("%s('%s'): connecting ...\n",
863 conn->netdev->name, conn->userid);
865 /* We must set the state before calling iucv_connect because the callback
866 * handler could be called at any point after the connection request is
869 fsm_newstate(fi, CONN_STATE_SETUPWAIT);
870 rc = iucv_connect(&(conn->pathid), NETIUCV_QUEUELEN_DEFAULT, iucvMagic,
871 conn->userid, iucv_host, 0, NULL, &msglimit,
875 conn->netdev->tx_queue_len = msglimit;
876 fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC,
877 CONN_EVENT_TIMER, conn);
880 PRINT_INFO("%s: User %s is currently not available.\n",
882 netiucv_printname(conn->userid));
883 fsm_newstate(fi, CONN_STATE_STARTWAIT);
886 PRINT_INFO("%s: User %s is currently not ready.\n",
888 netiucv_printname(conn->userid));
889 fsm_newstate(fi, CONN_STATE_STARTWAIT);
892 PRINT_WARN("%s: Too many IUCV connections.\n",
894 fsm_newstate(fi, CONN_STATE_CONNERR);
898 "%s: User %s has too many IUCV connections.\n",
900 netiucv_printname(conn->userid));
901 fsm_newstate(fi, CONN_STATE_CONNERR);
905 "%s: No IUCV authorization in CP directory.\n",
907 fsm_newstate(fi, CONN_STATE_CONNERR);
910 PRINT_WARN("%s: iucv_connect returned error %d\n",
911 conn->netdev->name, rc);
912 fsm_newstate(fi, CONN_STATE_CONNERR);
915 IUCV_DBF_TEXT_(setup, 5, "iucv_connect rc is %d\n", rc);
916 IUCV_DBF_TEXT(trace, 5, "calling iucv_unregister_program\n");
917 iucv_unregister_program(conn->handle);
922 netiucv_purge_skb_queue(struct sk_buff_head *q)
926 while ((skb = skb_dequeue(q))) {
927 atomic_dec(&skb->users);
928 dev_kfree_skb_any(skb);
933 conn_action_stop(fsm_instance *fi, int event, void *arg)
935 struct iucv_event *ev = (struct iucv_event *)arg;
936 struct iucv_connection *conn = ev->conn;
937 struct net_device *netdev = conn->netdev;
938 struct netiucv_priv *privptr = (struct netiucv_priv *)netdev->priv;
940 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
942 fsm_deltimer(&conn->timer);
943 fsm_newstate(fi, CONN_STATE_STOPPED);
944 netiucv_purge_skb_queue(&conn->collect_queue);
946 IUCV_DBF_TEXT(trace, 5, "calling iucv_unregister_program\n");
947 iucv_unregister_program(conn->handle);
949 netiucv_purge_skb_queue(&conn->commit_queue);
950 fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev);
954 conn_action_inval(fsm_instance *fi, int event, void *arg)
956 struct iucv_event *ev = (struct iucv_event *)arg;
957 struct iucv_connection *conn = ev->conn;
958 struct net_device *netdev = conn->netdev;
960 PRINT_WARN("%s: Cannot connect without username\n",
962 IUCV_DBF_TEXT(data, 2, "conn_action_inval called\n");
965 static const fsm_node conn_fsm[] = {
966 { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval },
967 { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start },
969 { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop },
970 { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop },
971 { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop },
972 { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop },
973 { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop },
974 { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop },
975 { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop },
977 { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject },
978 { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
979 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept },
980 { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject },
981 { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject },
983 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack },
984 { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev },
986 { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever },
987 { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever },
988 { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever },
990 { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx },
991 { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx },
993 { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone },
994 { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone },
997 static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node);
1001 * Actions for interface - statemachine.
1002 *****************************************************************************/
1005 * Startup connection by sending CONN_EVENT_START to it.
1007 * @param fi An instance of an interface statemachine.
1008 * @param event The event, just happened.
1009 * @param arg Generic pointer, casted from struct net_device * upon call.
1012 dev_action_start(fsm_instance *fi, int event, void *arg)
1014 struct net_device *dev = (struct net_device *)arg;
1015 struct netiucv_priv *privptr = dev->priv;
1016 struct iucv_event ev;
1018 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1020 ev.conn = privptr->conn;
1021 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1022 fsm_event(privptr->conn->fsm, CONN_EVENT_START, &ev);
1026 * Shutdown connection by sending CONN_EVENT_STOP to it.
1028 * @param fi An instance of an interface statemachine.
1029 * @param event The event, just happened.
1030 * @param arg Generic pointer, casted from struct net_device * upon call.
1033 dev_action_stop(fsm_instance *fi, int event, void *arg)
1035 struct net_device *dev = (struct net_device *)arg;
1036 struct netiucv_priv *privptr = dev->priv;
1037 struct iucv_event ev;
1039 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1041 ev.conn = privptr->conn;
1043 fsm_newstate(fi, DEV_STATE_STOPWAIT);
1044 fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev);
1048 * Called from connection statemachine
1049 * when a connection is up and running.
1051 * @param fi An instance of an interface statemachine.
1052 * @param event The event, just happened.
1053 * @param arg Generic pointer, casted from struct net_device * upon call.
1056 dev_action_connup(fsm_instance *fi, int event, void *arg)
1058 struct net_device *dev = (struct net_device *)arg;
1059 struct netiucv_priv *privptr = dev->priv;
1061 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1063 switch (fsm_getstate(fi)) {
1064 case DEV_STATE_STARTWAIT:
1065 fsm_newstate(fi, DEV_STATE_RUNNING);
1066 PRINT_INFO("%s: connected with remote side %s\n",
1067 dev->name, privptr->conn->userid);
1068 IUCV_DBF_TEXT(setup, 3,
1069 "connection is up and running\n");
1071 case DEV_STATE_STOPWAIT:
1073 "%s: got connection UP event during shutdown!\n",
1075 IUCV_DBF_TEXT(data, 2,
1076 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1082 * Called from connection statemachine
1083 * when a connection has been shutdown.
1085 * @param fi An instance of an interface statemachine.
1086 * @param event The event, just happened.
1087 * @param arg Generic pointer, casted from struct net_device * upon call.
1090 dev_action_conndown(fsm_instance *fi, int event, void *arg)
1092 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1094 switch (fsm_getstate(fi)) {
1095 case DEV_STATE_RUNNING:
1096 fsm_newstate(fi, DEV_STATE_STARTWAIT);
1098 case DEV_STATE_STOPWAIT:
1099 fsm_newstate(fi, DEV_STATE_STOPPED);
1100 IUCV_DBF_TEXT(setup, 3, "connection is down\n");
1105 static const fsm_node dev_fsm[] = {
1106 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
1108 { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start },
1109 { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown },
1111 { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop },
1112 { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup },
1114 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
1115 { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown },
1116 { DEV_STATE_RUNNING, DEV_EVENT_CONUP, fsm_action_nop },
1119 static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node);
1122 * Transmit a packet.
1123 * This is a helper function for netiucv_tx().
1125 * @param conn Connection to be used for sending.
1126 * @param skb Pointer to struct sk_buff of packet to send.
1127 * The linklevel header has already been set up
1130 * @return 0 on success, -ERRNO on failure. (Never fails.)
1133 netiucv_transmit_skb(struct iucv_connection *conn, struct sk_buff *skb) {
1134 unsigned long saveflags;
1138 if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) {
1139 int l = skb->len + NETIUCV_HDRLEN;
1141 spin_lock_irqsave(&conn->collect_lock, saveflags);
1142 if (conn->collect_len + l >
1143 (conn->max_buffsize - NETIUCV_HDRLEN)) {
1145 IUCV_DBF_TEXT(data, 2,
1146 "EBUSY from netiucv_transmit_skb\n");
1148 atomic_inc(&skb->users);
1149 skb_queue_tail(&conn->collect_queue, skb);
1150 conn->collect_len += l;
1152 spin_unlock_irqrestore(&conn->collect_lock, saveflags);
1154 struct sk_buff *nskb = skb;
1156 * Copy the skb to a new allocated skb in lowmem only if the
1157 * data is located above 2G in memory or tailroom is < 2.
1160 ((unsigned long)(skb->tail + NETIUCV_HDRLEN)) >> 31;
1162 if (hi || (skb_tailroom(skb) < 2)) {
1163 nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
1164 NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
1166 PRINT_WARN("%s: Could not allocate tx_skb\n",
1167 conn->netdev->name);
1168 IUCV_DBF_TEXT(data, 2, "alloc_skb failed\n");
1172 skb_reserve(nskb, NETIUCV_HDRLEN);
1173 memcpy(skb_put(nskb, skb->len),
1174 skb->data, skb->len);
1179 * skb now is below 2G and has enough room. Add headers.
1181 header.next = nskb->len + NETIUCV_HDRLEN;
1182 memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1184 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1186 fsm_newstate(conn->fsm, CONN_STATE_TX);
1187 conn->prof.send_stamp = xtime;
1189 rc = iucv_send(conn->pathid, NULL, 0, 0, 1 /* single_flag */,
1190 0, nskb->data, nskb->len);
1191 /* Shut up, gcc! nskb is always below 2G. */
1192 conn->prof.doios_single++;
1193 conn->prof.txlen += skb->len;
1194 conn->prof.tx_pending++;
1195 if (conn->prof.tx_pending > conn->prof.tx_max_pending)
1196 conn->prof.tx_max_pending = conn->prof.tx_pending;
1198 struct netiucv_priv *privptr;
1199 fsm_newstate(conn->fsm, CONN_STATE_IDLE);
1200 conn->prof.tx_pending--;
1201 privptr = (struct netiucv_priv *)conn->netdev->priv;
1203 privptr->stats.tx_errors++;
1205 dev_kfree_skb(nskb);
1208 * Remove our headers. They get added
1209 * again on retransmit.
1211 skb_pull(skb, NETIUCV_HDRLEN);
1212 skb_trim(skb, skb->len - NETIUCV_HDRLEN);
1214 PRINT_WARN("iucv_send returned %08x\n", rc);
1215 IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc);
1219 atomic_inc(&nskb->users);
1220 skb_queue_tail(&conn->commit_queue, nskb);
1228 * Interface API for upper network layers
1229 *****************************************************************************/
1232 * Open an interface.
1233 * Called from generic network layer when ifconfig up is run.
1235 * @param dev Pointer to interface struct.
1237 * @return 0 on success, -ERRNO on failure. (Never fails.)
1240 netiucv_open(struct net_device *dev) {
1241 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_START,dev);
1246 * Close an interface.
1247 * Called from generic network layer when ifconfig down is run.
1249 * @param dev Pointer to interface struct.
1251 * @return 0 on success, -ERRNO on failure. (Never fails.)
1254 netiucv_close(struct net_device *dev) {
1255 fsm_event(((struct netiucv_priv *)dev->priv)->fsm, DEV_EVENT_STOP, dev);
1260 * Start transmission of a packet.
1261 * Called from generic network device layer.
1263 * @param skb Pointer to buffer containing the packet.
1264 * @param dev Pointer to interface struct.
1266 * @return 0 if packet consumed, !0 if packet rejected.
1267 * Note: If we return !0, then the packet is free'd by
1268 * the generic network layer.
1270 static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1273 struct netiucv_priv *privptr = dev->priv;
1275 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1277 * Some sanity checks ...
1280 PRINT_WARN("%s: NULL sk_buff passed\n", dev->name);
1281 IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n");
1282 privptr->stats.tx_dropped++;
1285 if (skb_headroom(skb) < NETIUCV_HDRLEN) {
1286 PRINT_WARN("%s: Got sk_buff with head room < %ld bytes\n",
1287 dev->name, NETIUCV_HDRLEN);
1288 IUCV_DBF_TEXT(data, 2,
1289 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1291 privptr->stats.tx_dropped++;
1296 * If connection is not running, try to restart it
1297 * and throw away packet.
1299 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1300 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1302 privptr->stats.tx_dropped++;
1303 privptr->stats.tx_errors++;
1304 privptr->stats.tx_carrier_errors++;
1308 if (netiucv_test_and_set_busy(dev)) {
1309 IUCV_DBF_TEXT(data, 2, "EBUSY from netiucv_tx\n");
1312 dev->trans_start = jiffies;
1313 if (netiucv_transmit_skb(privptr->conn, skb))
1315 netiucv_clear_busy(dev);
1320 * Returns interface statistics of a device.
1322 * @param dev Pointer to interface struct.
1324 * @return Pointer to stats struct of this interface.
1326 static struct net_device_stats *
1327 netiucv_stats (struct net_device * dev)
1329 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1330 return &((struct netiucv_priv *)dev->priv)->stats;
1334 * Sets MTU of an interface.
1336 * @param dev Pointer to interface struct.
1337 * @param new_mtu The new MTU to use for this interface.
1339 * @return 0 on success, -EINVAL if MTU is out of valid range.
1340 * (valid range is 576 .. NETIUCV_MTU_MAX).
1343 netiucv_change_mtu (struct net_device * dev, int new_mtu)
1345 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1346 if ((new_mtu < 576) || (new_mtu > NETIUCV_MTU_MAX)) {
1347 IUCV_DBF_TEXT(setup, 2, "given MTU out of valid range\n");
1355 * attributes in sysfs
1356 *****************************************************************************/
1359 user_show (struct device *dev, struct device_attribute *attr, char *buf)
1361 struct netiucv_priv *priv = dev->driver_data;
1363 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1364 return sprintf(buf, "%s\n", netiucv_printname(priv->conn->userid));
1368 user_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1370 struct netiucv_priv *priv = dev->driver_data;
1371 struct net_device *ndev = priv->conn->netdev;
1377 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1379 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count);
1380 IUCV_DBF_TEXT_(setup, 2,
1381 "%d is length of username\n", (int)count);
1385 tmp = strsep((char **) &buf, "\n");
1386 for (i=0, p=tmp; i<8 && *p; i++, p++) {
1387 if (isalnum(*p) || (*p == '$'))
1389 else if (*p == '\n') {
1390 /* trailing lf, grr */
1393 PRINT_WARN("netiucv: Invalid char %c in username!\n",
1395 IUCV_DBF_TEXT_(setup, 2,
1396 "username: invalid character %c\n",
1402 username[i++] = ' ';
1405 if (memcmp(username, priv->conn->userid, 8)) {
1406 /* username changed */
1407 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1409 "netiucv: device %s active, connected to %s\n",
1410 dev->bus_id, priv->conn->userid);
1411 PRINT_WARN("netiucv: user cannot be updated\n");
1412 IUCV_DBF_TEXT(setup, 2, "user_write: device active\n");
1416 memcpy(priv->conn->userid, username, 9);
1422 static DEVICE_ATTR(user, 0644, user_show, user_write);
1425 buffer_show (struct device *dev, struct device_attribute *attr, char *buf)
1427 struct netiucv_priv *priv = dev->driver_data;
1429 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1430 return sprintf(buf, "%d\n", priv->conn->max_buffsize);
1434 buffer_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1436 struct netiucv_priv *priv = dev->driver_data;
1437 struct net_device *ndev = priv->conn->netdev;
1441 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1445 bs1 = simple_strtoul(buf, &e, 0);
1447 if (e && (!isspace(*e))) {
1448 PRINT_WARN("netiucv: Invalid character in buffer!\n");
1449 IUCV_DBF_TEXT_(setup, 2, "buffer_write: invalid char %c\n", *e);
1452 if (bs1 > NETIUCV_BUFSIZE_MAX) {
1453 PRINT_WARN("netiucv: Given buffer size %d too large.\n",
1455 IUCV_DBF_TEXT_(setup, 2,
1456 "buffer_write: buffer size %d too large\n",
1460 if ((ndev->flags & IFF_RUNNING) &&
1461 (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2))) {
1462 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1464 IUCV_DBF_TEXT_(setup, 2,
1465 "buffer_write: buffer size %d too small\n",
1469 if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN)) {
1470 PRINT_WARN("netiucv: Given buffer size %d too small.\n",
1472 IUCV_DBF_TEXT_(setup, 2,
1473 "buffer_write: buffer size %d too small\n",
1478 priv->conn->max_buffsize = bs1;
1479 if (!(ndev->flags & IFF_RUNNING))
1480 ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN;
1486 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
1489 dev_fsm_show (struct device *dev, struct device_attribute *attr, char *buf)
1491 struct netiucv_priv *priv = dev->driver_data;
1493 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1494 return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm));
1497 static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL);
1500 conn_fsm_show (struct device *dev, struct device_attribute *attr, char *buf)
1502 struct netiucv_priv *priv = dev->driver_data;
1504 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1505 return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm));
1508 static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL);
1511 maxmulti_show (struct device *dev, struct device_attribute *attr, char *buf)
1513 struct netiucv_priv *priv = dev->driver_data;
1515 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1516 return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti);
1520 maxmulti_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1522 struct netiucv_priv *priv = dev->driver_data;
1524 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1525 priv->conn->prof.maxmulti = 0;
1529 static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write);
1532 maxcq_show (struct device *dev, struct device_attribute *attr, char *buf)
1534 struct netiucv_priv *priv = dev->driver_data;
1536 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1537 return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue);
1541 maxcq_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1543 struct netiucv_priv *priv = dev->driver_data;
1545 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1546 priv->conn->prof.maxcqueue = 0;
1550 static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write);
1553 sdoio_show (struct device *dev, struct device_attribute *attr, char *buf)
1555 struct netiucv_priv *priv = dev->driver_data;
1557 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1558 return sprintf(buf, "%ld\n", priv->conn->prof.doios_single);
1562 sdoio_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1564 struct netiucv_priv *priv = dev->driver_data;
1566 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1567 priv->conn->prof.doios_single = 0;
1571 static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write);
1574 mdoio_show (struct device *dev, struct device_attribute *attr, char *buf)
1576 struct netiucv_priv *priv = dev->driver_data;
1578 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1579 return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi);
1583 mdoio_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1585 struct netiucv_priv *priv = dev->driver_data;
1587 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1588 priv->conn->prof.doios_multi = 0;
1592 static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write);
1595 txlen_show (struct device *dev, struct device_attribute *attr, char *buf)
1597 struct netiucv_priv *priv = dev->driver_data;
1599 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1600 return sprintf(buf, "%ld\n", priv->conn->prof.txlen);
1604 txlen_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1606 struct netiucv_priv *priv = dev->driver_data;
1608 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1609 priv->conn->prof.txlen = 0;
1613 static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write);
1616 txtime_show (struct device *dev, struct device_attribute *attr, char *buf)
1618 struct netiucv_priv *priv = dev->driver_data;
1620 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1621 return sprintf(buf, "%ld\n", priv->conn->prof.tx_time);
1625 txtime_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1627 struct netiucv_priv *priv = dev->driver_data;
1629 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1630 priv->conn->prof.tx_time = 0;
1634 static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write);
1637 txpend_show (struct device *dev, struct device_attribute *attr, char *buf)
1639 struct netiucv_priv *priv = dev->driver_data;
1641 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1642 return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending);
1646 txpend_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1648 struct netiucv_priv *priv = dev->driver_data;
1650 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1651 priv->conn->prof.tx_pending = 0;
1655 static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write);
1658 txmpnd_show (struct device *dev, struct device_attribute *attr, char *buf)
1660 struct netiucv_priv *priv = dev->driver_data;
1662 IUCV_DBF_TEXT(trace, 5, __FUNCTION__);
1663 return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending);
1667 txmpnd_write (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1669 struct netiucv_priv *priv = dev->driver_data;
1671 IUCV_DBF_TEXT(trace, 4, __FUNCTION__);
1672 priv->conn->prof.tx_max_pending = 0;
1676 static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write);
1678 static struct attribute *netiucv_attrs[] = {
1679 &dev_attr_buffer.attr,
1680 &dev_attr_user.attr,
1684 static struct attribute_group netiucv_attr_group = {
1685 .attrs = netiucv_attrs,
1688 static struct attribute *netiucv_stat_attrs[] = {
1689 &dev_attr_device_fsm_state.attr,
1690 &dev_attr_connection_fsm_state.attr,
1691 &dev_attr_max_tx_buffer_used.attr,
1692 &dev_attr_max_chained_skbs.attr,
1693 &dev_attr_tx_single_write_ops.attr,
1694 &dev_attr_tx_multi_write_ops.attr,
1695 &dev_attr_netto_bytes.attr,
1696 &dev_attr_max_tx_io_time.attr,
1697 &dev_attr_tx_pending.attr,
1698 &dev_attr_tx_max_pending.attr,
1702 static struct attribute_group netiucv_stat_attr_group = {
1704 .attrs = netiucv_stat_attrs,
1708 netiucv_add_files(struct device *dev)
1712 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1713 ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group);
1716 ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group);
1718 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1723 netiucv_remove_files(struct device *dev)
1725 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1726 sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group);
1727 sysfs_remove_group(&dev->kobj, &netiucv_attr_group);
1731 netiucv_register_device(struct net_device *ndev)
1733 struct netiucv_priv *priv = ndev->priv;
1734 struct device *dev = kmalloc(sizeof(struct device), GFP_KERNEL);
1738 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1741 memset(dev, 0, sizeof(struct device));
1742 snprintf(dev->bus_id, BUS_ID_SIZE, "net%s", ndev->name);
1743 dev->bus = &iucv_bus;
1744 dev->parent = iucv_root;
1746 * The release function could be called after the
1747 * module has been unloaded. It's _only_ task is to
1748 * free the struct. Therefore, we specify kfree()
1749 * directly here. (Probably a little bit obfuscating
1750 * but legitime ...).
1752 dev->release = (void (*)(struct device *))kfree;
1753 dev->driver = &netiucv_driver;
1757 ret = device_register(dev);
1761 ret = netiucv_add_files(dev);
1765 dev->driver_data = priv;
1769 device_unregister(dev);
1774 netiucv_unregister_device(struct device *dev)
1776 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1777 netiucv_remove_files(dev);
1778 device_unregister(dev);
1782 * Allocate and initialize a new connection structure.
1783 * Add it to the list of netiucv connections;
1785 static struct iucv_connection *
1786 netiucv_new_connection(struct net_device *dev, char *username)
1788 struct iucv_connection **clist = &iucv_connections;
1789 struct iucv_connection *conn =
1790 (struct iucv_connection *)
1791 kmalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1794 memset(conn, 0, sizeof(struct iucv_connection));
1795 skb_queue_head_init(&conn->collect_queue);
1796 skb_queue_head_init(&conn->commit_queue);
1797 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1800 conn->rx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1801 GFP_KERNEL | GFP_DMA);
1802 if (!conn->rx_buff) {
1806 conn->tx_buff = alloc_skb(NETIUCV_BUFSIZE_DEFAULT,
1807 GFP_KERNEL | GFP_DMA);
1808 if (!conn->tx_buff) {
1809 kfree_skb(conn->rx_buff);
1813 conn->fsm = init_fsm("netiucvconn", conn_state_names,
1814 conn_event_names, NR_CONN_STATES,
1815 NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN,
1818 kfree_skb(conn->tx_buff);
1819 kfree_skb(conn->rx_buff);
1823 fsm_settimer(conn->fsm, &conn->timer);
1824 fsm_newstate(conn->fsm, CONN_STATE_INVALID);
1827 memcpy(conn->userid, username, 9);
1828 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1831 conn->next = *clist;
1838 * Release a connection structure and remove it from the
1839 * list of netiucv connections.
1842 netiucv_remove_connection(struct iucv_connection *conn)
1844 struct iucv_connection **clist = &iucv_connections;
1846 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1850 if (*clist == conn) {
1851 *clist = conn->next;
1853 iucv_unregister_program(conn->handle);
1854 conn->handle = NULL;
1856 fsm_deltimer(&conn->timer);
1857 kfree_fsm(conn->fsm);
1858 kfree_skb(conn->rx_buff);
1859 kfree_skb(conn->tx_buff);
1862 clist = &((*clist)->next);
1867 * Release everything of a net device.
1870 netiucv_free_netdevice(struct net_device *dev)
1872 struct netiucv_priv *privptr;
1874 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1879 privptr = (struct netiucv_priv *)dev->priv;
1882 netiucv_remove_connection(privptr->conn);
1884 kfree_fsm(privptr->fsm);
1885 privptr->conn = NULL; privptr->fsm = NULL;
1886 /* privptr gets freed by free_netdev() */
1892 * Initialize a net device. (Called from kernel in alloc_netdev())
1895 netiucv_setup_netdevice(struct net_device *dev)
1897 memset(dev->priv, 0, sizeof(struct netiucv_priv));
1899 dev->mtu = NETIUCV_MTU_DEFAULT;
1900 dev->hard_start_xmit = netiucv_tx;
1901 dev->open = netiucv_open;
1902 dev->stop = netiucv_close;
1903 dev->get_stats = netiucv_stats;
1904 dev->change_mtu = netiucv_change_mtu;
1905 dev->destructor = netiucv_free_netdevice;
1906 dev->hard_header_len = NETIUCV_HDRLEN;
1908 dev->type = ARPHRD_SLIP;
1909 dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT;
1910 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1911 SET_MODULE_OWNER(dev);
1915 * Allocate and initialize everything of a net device.
1917 static struct net_device *
1918 netiucv_init_netdevice(char *username)
1920 struct netiucv_priv *privptr;
1921 struct net_device *dev;
1923 dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d",
1924 netiucv_setup_netdevice);
1927 if (dev_alloc_name(dev, dev->name) < 0) {
1932 privptr = (struct netiucv_priv *)dev->priv;
1933 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
1934 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
1935 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
1936 if (!privptr->fsm) {
1940 privptr->conn = netiucv_new_connection(dev, username);
1941 if (!privptr->conn) {
1942 kfree_fsm(privptr->fsm);
1944 IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_new_connection\n");
1947 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
1953 conn_write(struct device_driver *drv, const char *buf, size_t count)
1958 struct net_device *dev;
1960 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1962 PRINT_WARN("netiucv: username too long (%d)!\n", (int)count);
1963 IUCV_DBF_TEXT(setup, 2, "conn_write: too long\n");
1967 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) {
1968 if (isalnum(*p) || (*p == '$'))
1970 else if (*p == '\n') {
1971 /* trailing lf, grr */
1974 PRINT_WARN("netiucv: Invalid character in username!\n");
1975 IUCV_DBF_TEXT_(setup, 2,
1976 "conn_write: invalid character %c\n", *p);
1981 username[i++] = ' ';
1983 dev = netiucv_init_netdevice(username);
1986 "netiucv: Could not allocate network device structure "
1987 "for user '%s'\n", netiucv_printname(username));
1988 IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_init_netdevice\n");
1992 if ((ret = netiucv_register_device(dev))) {
1993 IUCV_DBF_TEXT_(setup, 2,
1994 "ret %d from netiucv_register_device\n", ret);
2000 (struct device*)((struct netiucv_priv*)dev->priv)->dev);
2002 if ((ret = register_netdev(dev))) {
2003 netiucv_unregister_device((struct device*)
2004 ((struct netiucv_priv*)dev->priv)->dev);
2008 PRINT_INFO("%s: '%s'\n", dev->name, netiucv_printname(username));
2013 PRINT_WARN("netiucv: Could not register '%s'\n", dev->name);
2014 IUCV_DBF_TEXT(setup, 2, "conn_write: could not register\n");
2015 netiucv_free_netdevice(dev);
2019 DRIVER_ATTR(connection, 0200, NULL, conn_write);
2022 remove_write (struct device_driver *drv, const char *buf, size_t count)
2024 struct iucv_connection **clist = &iucv_connections;
2025 struct net_device *ndev;
2026 struct netiucv_priv *priv;
2028 char name[IFNAMSIZ];
2032 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2034 if (count >= IFNAMSIZ)
2037 for (i=0, p=(char *)buf; i<count && *p; i++, p++) {
2038 if ((*p == '\n') | (*p == ' ')) {
2039 /* trailing lf, grr */
2048 ndev = (*clist)->netdev;
2049 priv = (struct netiucv_priv*)ndev->priv;
2052 if (strncmp(name, ndev->name, count)) {
2053 clist = &((*clist)->next);
2056 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
2058 "netiucv: net device %s active with peer %s\n",
2059 ndev->name, priv->conn->userid);
2060 PRINT_WARN("netiucv: %s cannot be removed\n",
2062 IUCV_DBF_TEXT(data, 2, "remove_write: still active\n");
2065 unregister_netdev(ndev);
2066 netiucv_unregister_device(dev);
2069 PRINT_WARN("netiucv: net device %s unknown\n", name);
2070 IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n");
2074 DRIVER_ATTR(remove, 0200, NULL, remove_write);
2077 netiucv_banner(void)
2079 char vbuf[] = "$Revision: 1.66 $";
2080 char *version = vbuf;
2082 if ((version = strchr(version, ':'))) {
2083 char *p = strchr(version + 1, '$');
2088 PRINT_INFO("NETIUCV driver Version%s initialized\n", version);
2094 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2095 while (iucv_connections) {
2096 struct net_device *ndev = iucv_connections->netdev;
2097 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv;
2098 struct device *dev = priv->dev;
2100 unregister_netdev(ndev);
2101 netiucv_unregister_device(dev);
2104 driver_remove_file(&netiucv_driver, &driver_attr_connection);
2105 driver_remove_file(&netiucv_driver, &driver_attr_remove);
2106 driver_unregister(&netiucv_driver);
2107 iucv_unregister_dbf_views();
2109 PRINT_INFO("NETIUCV driver unloaded\n");
2118 ret = iucv_register_dbf_views();
2120 PRINT_WARN("netiucv_init failed, "
2121 "iucv_register_dbf_views rc = %d\n", ret);
2124 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2125 ret = driver_register(&netiucv_driver);
2127 PRINT_ERR("NETIUCV: failed to register driver.\n");
2128 IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_register\n", ret);
2129 iucv_unregister_dbf_views();
2133 /* Add entry for specifying connections. */
2134 ret = driver_create_file(&netiucv_driver, &driver_attr_connection);
2136 ret = driver_create_file(&netiucv_driver, &driver_attr_remove);
2139 PRINT_ERR("NETIUCV: failed to add driver attribute.\n");
2140 IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_create_file\n", ret);
2141 driver_unregister(&netiucv_driver);
2142 iucv_unregister_dbf_views();
2147 module_init(netiucv_init);
2148 module_exit(netiucv_exit);
2149 MODULE_LICENSE("GPL");