2 * $Id: ctcmain.c,v 1.30 2002/12/09 13:56:20 aberg Exp $
4 * CTC / ESCON network driver
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
8 * Fixes by : Jochen Röhrig (roehrig@de.ibm.com)
9 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
10 * Driver Model stuff by : Cornelia Huck <cohuck@de.ibm.com>
13 * - Principles of Operation (IBM doc#: SA22-7201-06)
14 * - Common IO/-Device Commands and Self Description (IBM doc#: SA22-7204-02)
15 * - Common IO/-Device Commands and Self Description (IBM doc#: SN22-5535)
16 * - ESCON Channel-to-Channel Adapter (IBM doc#: SA22-7203-00)
17 * - ESCON I/O Interface (IBM doc#: SA22-7202-029
19 * and the source of the original CTC driver by:
20 * Dieter Wellerdiek (wel@de.ibm.com)
21 * Martin Schwidefsky (schwidefsky@de.ibm.com)
22 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
23 * Jochen Röhrig (roehrig@de.ibm.com)
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2, or (at your option)
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 * RELEASE-TAG: CTC/ESCON network driver $Revision: 1.30 $
45 #include <linux/version.h>
46 #include <linux/module.h>
47 #include <linux/init.h>
48 #include <linux/kernel.h>
49 #include <linux/slab.h>
50 #include <linux/errno.h>
51 #include <linux/types.h>
52 #include <linux/interrupt.h>
53 #include <linux/timer.h>
54 #include <linux/sched.h>
56 #include <linux/signal.h>
57 #include <linux/string.h>
60 #include <linux/if_arp.h>
61 #include <linux/tcp.h>
62 #include <linux/skbuff.h>
63 #include <linux/ctype.h>
67 #include <asm/ccwdev.h>
68 #include <asm/ccwgroup.h>
69 #include <asm/bitops.h>
70 #include <asm/uaccess.h>
72 #include <asm/idals.h>
78 MODULE_AUTHOR("(C) 2000 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
79 MODULE_DESCRIPTION("Linux for S/390 CTC/Escon Driver");
80 MODULE_LICENSE("GPL");
83 * CCW commands, used in this driver.
85 #define CCW_CMD_WRITE 0x01
86 #define CCW_CMD_READ 0x02
87 #define CCW_CMD_SET_EXTENDED 0xc3
88 #define CCW_CMD_PREPARE 0xe3
90 #define CTC_PROTO_S390 0
91 #define CTC_PROTO_LINUX 1
92 #define CTC_PROTO_LINUX_TTY 2
93 #define CTC_PROTO_OS390 3
94 #define CTC_PROTO_MAX 3
96 #define CTC_BUFSIZE_LIMIT 65535
97 #define CTC_BUFSIZE_DEFAULT 32768
99 #define CTC_TIMEOUT_5SEC 5000
101 #define CTC_INITIAL_BLOCKLEN 2
106 #define CTC_ID_SIZE DEVICE_ID_SIZE+3
109 * If running on 64 bit, this must be changed. XXX Why? (bird)
111 typedef unsigned long intparm_t
;
114 unsigned long maxmulti
;
115 unsigned long maxcqueue
;
116 unsigned long doios_single
;
117 unsigned long doios_multi
;
119 unsigned long tx_time
;
120 struct timespec send_stamp
;
124 * Definition of one channel
129 * Pointer to next channel in list.
131 struct channel
*next
;
132 char id
[CTC_ID_SIZE
];
133 struct ccw_device
*cdev
;
136 * Type of this channel.
137 * CTC/A or Escon for valid channels.
139 enum channel_types type
;
142 * Misc. flags. See CHANNEL_FLAGS_... below
147 * The protocol of this channel
152 * I/O and irq related stuff
163 * Transmit/Receive buffer.
165 struct sk_buff
*trans_skb
;
168 * Universal I/O queue.
170 struct sk_buff_head io_queue
;
173 * TX queue for collecting skb's during busy.
175 struct sk_buff_head collect_queue
;
178 * Amount of data in collect_queue.
183 * spinlock for collect_queue and collect_len
185 spinlock_t collect_lock
;
188 * Timer for detecting unresposive
194 * Retry counter for misc. operations.
199 * The finite state machine of this channel
204 * The corresponding net_device this channel
207 struct net_device
*netdev
;
209 struct ctc_profile prof
;
211 unsigned char *trans_skb_data
;
214 #define CHANNEL_FLAGS_READ 0
215 #define CHANNEL_FLAGS_WRITE 1
216 #define CHANNEL_FLAGS_INUSE 2
217 #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
218 #define CHANNEL_FLAGS_RWMASK 1
219 #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
222 * Linked list of all detected channels.
224 static struct channel
*channels
= NULL
;
227 struct net_device_stats stats
;
230 * The finite state machine of this interface.
234 * The protocol of this device
238 * Timer for restarting after I/O Errors
240 fsm_timer restart_timer
;
242 struct channel
*channel
[2];
246 * Definition of our link level header.
253 #define LL_HEADER_LENGTH (sizeof(struct ll_header))
256 * Compatibility macros for busy handling
257 * of network devices.
259 static __inline__
void
260 ctc_clear_busy(struct net_device
* dev
)
262 clear_bit(0, &(((struct ctc_priv
*) dev
->priv
)->tbusy
));
263 netif_wake_queue(dev
);
266 static __inline__
int
267 ctc_test_and_set_busy(struct net_device
* dev
)
269 netif_stop_queue(dev
);
270 return test_and_set_bit(0, &((struct ctc_priv
*) dev
->priv
)->tbusy
);
273 #define SET_DEVICE_START(device, value)
281 static int printed
= 0;
282 char vbuf
[] = "$Revision: 1.30 $";
283 char *version
= vbuf
;
287 if ((version
= strchr(version
, ':'))) {
288 char *p
= strchr(version
+ 1, '$');
293 printk(KERN_INFO
"CTC driver Version%s"
295 " (DEBUG-VERSION, " __DATE__ __TIME__
")"
297 " initialized\n", version
);
302 * Return type of a detected device.
304 static enum channel_types
305 get_channel_type(struct ccw_device_id
*id
)
307 enum channel_types type
= (enum channel_types
) id
->driver_info
;
309 if (type
== channel_type_ficon
)
310 type
= channel_type_escon
;
316 * States of the interface statemachine.
320 DEV_STATE_STARTWAIT_RXTX
,
321 DEV_STATE_STARTWAIT_RX
,
322 DEV_STATE_STARTWAIT_TX
,
323 DEV_STATE_STOPWAIT_RXTX
,
324 DEV_STATE_STOPWAIT_RX
,
325 DEV_STATE_STOPWAIT_TX
,
328 * MUST be always the last element!!
333 static const char *dev_state_names
[] = {
345 * Events of the interface statemachine.
356 * MUST be always the last element!!
361 static const char *dev_event_names
[] = {
372 * Events of the channel statemachine
376 * Events, representing return code of
377 * I/O operations (ccw_device_start, ccw_device_halt et al.)
390 * Events, representing unit-check
394 CH_EVENT_UC_TXTIMEOUT
,
395 CH_EVENT_UC_TXPARITY
,
397 CH_EVENT_UC_RXPARITY
,
402 * Events, representing subchannel-check
407 * Events, representing machine checks
413 * Event, representing normal IRQ
419 * Event, representing timer expiry.
424 * Events, representing commands from upper levels.
430 * MUST be always the last element!!
435 static const char *ch_event_names
[] = {
442 "Status ATTN & BUSY",
446 "Unit check remote reset",
447 "Unit check remote system reset",
448 "Unit check TX timeout",
449 "Unit check TX parity",
450 "Unit check Hardware failure",
451 "Unit check RX parity",
453 "Unit check Unknown",
455 "SubChannel check Unknown",
457 "Machine check failure",
458 "Machine check operational",
470 * States of the channel statemachine.
474 * Channel not assigned to any device,
475 * initial state, direction invalid
480 * Channel assigned but not operating
499 * MUST be always the last element!!
504 static const char *ch_state_names
[] = {
525 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
527 * @param skb The sk_buff to dump.
528 * @param offset Offset relative to skb-data, where to start the dump.
531 ctc_dump_skb(struct sk_buff
*skb
, int offset
)
533 unsigned char *p
= skb
->data
;
535 struct ll_header
*header
;
541 header
= (struct ll_header
*) p
;
544 printk(KERN_DEBUG
"dump:\n");
545 printk(KERN_DEBUG
"blocklen=%d %04x\n", bl
, bl
);
547 printk(KERN_DEBUG
"h->length=%d %04x\n", header
->length
,
549 printk(KERN_DEBUG
"h->type=%04x\n", header
->type
);
550 printk(KERN_DEBUG
"h->unused=%04x\n", header
->unused
);
553 printk(KERN_DEBUG
"data: ");
554 for (i
= 0; i
< bl
; i
++)
555 printk("%02x%s", *p
++, (i
% 16) ? " " : "\n<7>");
560 ctc_dump_skb(struct sk_buff
*skb
, int offset
)
566 * Unpack a just received skb and hand it over to
569 * @param ch The channel where this skb has been received.
570 * @param pskb The received skb.
572 static __inline__
void
573 ctc_unpack_skb(struct channel
*ch
, struct sk_buff
*pskb
)
575 struct net_device
*dev
= ch
->netdev
;
576 struct ctc_priv
*privptr
= (struct ctc_priv
*) dev
->priv
;
578 __u16 len
= *((__u16
*) pskb
->data
);
579 skb_put(pskb
, 2 + LL_HEADER_LENGTH
);
582 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
585 struct ll_header
*header
= (struct ll_header
*) pskb
->data
;
587 skb_pull(pskb
, LL_HEADER_LENGTH
);
588 if ((ch
->protocol
== CTC_PROTO_S390
) &&
589 (header
->type
!= ETH_P_IP
)) {
591 * Check packet type only if we stick strictly
592 * to S/390's protocol of OS390. This only
593 * supports IP. Otherwise allow any packet
597 "%s Illegal packet type 0x%04x "
598 "received, dropping\n", dev
->name
, header
->type
);
599 ctc_dump_skb(pskb
, -6);
600 privptr
->stats
.rx_dropped
++;
601 privptr
->stats
.rx_frame_errors
++;
604 pskb
->protocol
= ntohs(header
->type
);
605 header
->length
-= LL_HEADER_LENGTH
;
606 if ((header
->length
== 0) ||
607 (header
->length
> skb_tailroom(pskb
)) ||
608 (header
->length
> len
)) {
610 "%s Illegal packet size %d "
611 "received (MTU=%d blocklen=%d), "
612 "dropping\n", dev
->name
, header
->length
,
614 ctc_dump_skb(pskb
, -6);
615 privptr
->stats
.rx_dropped
++;
616 privptr
->stats
.rx_length_errors
++;
619 if (header
->length
> skb_tailroom(pskb
)) {
621 "%s Illegal packet size %d "
622 "(beyond the end of received data), "
623 "dropping\n", dev
->name
, header
->length
);
624 ctc_dump_skb(pskb
, -6);
625 privptr
->stats
.rx_dropped
++;
626 privptr
->stats
.rx_length_errors
++;
629 skb_put(pskb
, header
->length
);
630 pskb
->mac
.raw
= pskb
->data
;
631 len
-= (LL_HEADER_LENGTH
+ header
->length
);
632 skb
= dev_alloc_skb(pskb
->len
);
635 "%s Out of memory in ctc_unpack_skb\n",
637 privptr
->stats
.rx_dropped
++;
640 memcpy(skb_put(skb
, pskb
->len
), pskb
->data
, pskb
->len
);
641 skb
->mac
.raw
= skb
->data
;
642 skb
->dev
= pskb
->dev
;
643 skb
->protocol
= pskb
->protocol
;
644 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
645 if (ch
->protocol
== CTC_PROTO_LINUX_TTY
)
646 ctc_tty_netif_rx(skb
);
649 dev
->last_rx
= jiffies
;
650 privptr
->stats
.rx_packets
++;
651 privptr
->stats
.rx_bytes
+= skb
->len
;
653 skb_pull(pskb
, header
->length
);
654 skb_put(pskb
, LL_HEADER_LENGTH
);
660 * Check return code of a preceeding do_IO, halt_IO etc...
662 * @param ch The channel, the error belongs to.
663 * @param return_code The error code to inspect.
666 ccw_check_return_code(struct channel
*ch
, int return_code
)
668 switch (return_code
) {
670 fsm_event(ch
->fsm
, CH_EVENT_IO_SUCCESS
, ch
);
673 printk(KERN_INFO
"%s: Busy !\n", ch
->id
);
674 fsm_event(ch
->fsm
, CH_EVENT_IO_EBUSY
, ch
);
678 "%s: Invalid device called for IO\n", ch
->id
);
679 fsm_event(ch
->fsm
, CH_EVENT_IO_ENODEV
, ch
);
682 printk(KERN_EMERG
"%s: Status pending... \n", ch
->id
);
683 fsm_event(ch
->fsm
, CH_EVENT_IO_EIO
, ch
);
687 "%s: Unknown error in do_IO %04x\n",
688 ch
->id
, return_code
);
689 fsm_event(ch
->fsm
, CH_EVENT_IO_UNKNOWN
, ch
);
694 * Check sense of a unit check.
696 * @param ch The channel, the sense code belongs to.
697 * @param sense The sense code to inspect.
700 ccw_unit_check(struct channel
*ch
, unsigned char sense
)
702 if (sense
& SNS0_INTERVENTION_REQ
) {
704 if (ch
->protocol
!= CTC_PROTO_LINUX_TTY
)
706 "%s: Interface disc. or Sel. reset "
707 "(remote)\n", ch
->id
);
708 fsm_event(ch
->fsm
, CH_EVENT_UC_RCRESET
, ch
);
710 printk(KERN_DEBUG
"%s: System reset (remote)\n",
712 fsm_event(ch
->fsm
, CH_EVENT_UC_RSRESET
, ch
);
714 } else if (sense
& SNS0_EQUIPMENT_CHECK
) {
715 if (sense
& SNS0_BUS_OUT_CHECK
) {
717 "%s: Hardware malfunction (remote)\n",
719 fsm_event(ch
->fsm
, CH_EVENT_UC_HWFAIL
, ch
);
722 "%s: Read-data parity error (remote)\n",
724 fsm_event(ch
->fsm
, CH_EVENT_UC_RXPARITY
, ch
);
726 } else if (sense
& SNS0_BUS_OUT_CHECK
) {
729 "%s: Data-streaming timeout)\n", ch
->id
);
730 fsm_event(ch
->fsm
, CH_EVENT_UC_TXTIMEOUT
, ch
);
733 "%s: Data-transfer parity error\n",
735 fsm_event(ch
->fsm
, CH_EVENT_UC_TXPARITY
, ch
);
737 } else if (sense
& SNS0_CMD_REJECT
) {
738 printk(KERN_WARNING
"%s: Command reject\n", ch
->id
);
739 } else if (sense
== 0) {
740 printk(KERN_DEBUG
"%s: Unit check ZERO\n", ch
->id
);
741 fsm_event(ch
->fsm
, CH_EVENT_UC_ZERO
, ch
);
744 "%s: Unit Check with sense code: %02x\n",
746 fsm_event(ch
->fsm
, CH_EVENT_UC_UNKNOWN
, ch
);
751 ctc_purge_skb_queue(struct sk_buff_head
*q
)
755 while ((skb
= skb_dequeue(q
))) {
756 atomic_dec(&skb
->users
);
757 dev_kfree_skb_irq(skb
);
761 static __inline__
int
762 ctc_checkalloc_buffer(struct channel
*ch
, int warn
)
764 if ((ch
->trans_skb
== NULL
) ||
765 (ch
->flags
& CHANNEL_FLAGS_BUFSIZE_CHANGED
)) {
766 if (ch
->trans_skb
!= NULL
)
767 dev_kfree_skb(ch
->trans_skb
);
768 clear_normalized_cda(&ch
->ccw
[1]);
769 ch
->trans_skb
= __dev_alloc_skb(ch
->max_bufsize
,
770 GFP_ATOMIC
| GFP_DMA
);
771 if (ch
->trans_skb
== NULL
) {
774 "%s: Couldn't alloc %s trans_skb\n",
776 (CHANNEL_DIRECTION(ch
->flags
) == READ
) ?
780 ch
->ccw
[1].count
= ch
->max_bufsize
;
781 if (set_normalized_cda(&ch
->ccw
[1], ch
->trans_skb
->data
)) {
782 dev_kfree_skb(ch
->trans_skb
);
783 ch
->trans_skb
= NULL
;
786 "%s: set_normalized_cda for %s "
787 "trans_skb failed, dropping packets\n",
789 (CHANNEL_DIRECTION(ch
->flags
) == READ
) ?
793 ch
->ccw
[1].count
= 0;
794 ch
->trans_skb_data
= ch
->trans_skb
->data
;
795 ch
->flags
&= ~CHANNEL_FLAGS_BUFSIZE_CHANGED
;
801 * Dummy NOP action for statemachines
804 fsm_action_nop(fsm_instance
* fi
, int event
, void *arg
)
809 * Actions for channel - statemachines.
810 *****************************************************************************/
813 * Normal data has been send. Free the corresponding
814 * skb (it's in io_queue), reset dev->tbusy and
815 * revert to idle state.
817 * @param fi An instance of a channel statemachine.
818 * @param event The event, just happened.
819 * @param arg Generic pointer, casted from channel * upon call.
822 ch_action_txdone(fsm_instance
* fi
, int event
, void *arg
)
824 struct channel
*ch
= (struct channel
*) arg
;
825 struct net_device
*dev
= ch
->netdev
;
826 struct ctc_priv
*privptr
= dev
->priv
;
831 struct timespec done_stamp
= xtime
;
832 unsigned long duration
=
833 (done_stamp
.tv_sec
- ch
->prof
.send_stamp
.tv_sec
) * 1000000 +
834 (done_stamp
.tv_nsec
- ch
->prof
.send_stamp
.tv_nsec
) / 1000;
835 if (duration
> ch
->prof
.tx_time
)
836 ch
->prof
.tx_time
= duration
;
838 if (ch
->irb
->scsw
.count
!= 0)
839 printk(KERN_DEBUG
"%s: TX not complete, remaining %d bytes\n",
840 dev
->name
, ch
->irb
->scsw
.count
);
842 fsm_deltimer(&ch
->timer
);
843 while ((skb
= skb_dequeue(&ch
->io_queue
))) {
844 privptr
->stats
.tx_packets
++;
845 privptr
->stats
.tx_bytes
+= skb
->len
- LL_HEADER_LENGTH
;
847 privptr
->stats
.tx_bytes
+= 2;
850 atomic_dec(&skb
->users
);
851 dev_kfree_skb_irq(skb
);
853 spin_lock(&ch
->collect_lock
);
854 clear_normalized_cda(&ch
->ccw
[4]);
855 if (ch
->collect_len
> 0) {
858 if (ctc_checkalloc_buffer(ch
, 1)) {
859 spin_unlock(&ch
->collect_lock
);
862 ch
->trans_skb
->tail
= ch
->trans_skb
->data
= ch
->trans_skb_data
;
863 ch
->trans_skb
->len
= 0;
864 if (ch
->prof
.maxmulti
< (ch
->collect_len
+ 2))
865 ch
->prof
.maxmulti
= ch
->collect_len
+ 2;
866 if (ch
->prof
.maxcqueue
< skb_queue_len(&ch
->collect_queue
))
867 ch
->prof
.maxcqueue
= skb_queue_len(&ch
->collect_queue
);
868 *((__u16
*) skb_put(ch
->trans_skb
, 2)) = ch
->collect_len
+ 2;
870 while ((skb
= skb_dequeue(&ch
->collect_queue
))) {
871 memcpy(skb_put(ch
->trans_skb
, skb
->len
), skb
->data
,
873 privptr
->stats
.tx_packets
++;
874 privptr
->stats
.tx_bytes
+= skb
->len
- LL_HEADER_LENGTH
;
875 atomic_dec(&skb
->users
);
876 dev_kfree_skb_irq(skb
);
880 spin_unlock(&ch
->collect_lock
);
881 ch
->ccw
[1].count
= ch
->trans_skb
->len
;
882 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
, CH_EVENT_TIMER
, ch
);
883 ch
->prof
.send_stamp
= xtime
;
884 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[0],
885 (intparm_t
) ch
, 0xff, 0);
886 ch
->prof
.doios_multi
++;
888 privptr
->stats
.tx_dropped
+= i
;
889 privptr
->stats
.tx_errors
+= i
;
890 fsm_deltimer(&ch
->timer
);
891 ccw_check_return_code(ch
, rc
);
894 spin_unlock(&ch
->collect_lock
);
895 fsm_newstate(fi
, CH_STATE_TXIDLE
);
901 * Initial data is sent.
902 * Notify device statemachine that we are up and
905 * @param fi An instance of a channel statemachine.
906 * @param event The event, just happened.
907 * @param arg Generic pointer, casted from channel * upon call.
910 ch_action_txidle(fsm_instance
* fi
, int event
, void *arg
)
912 struct channel
*ch
= (struct channel
*) arg
;
914 fsm_deltimer(&ch
->timer
);
915 fsm_newstate(fi
, CH_STATE_TXIDLE
);
916 fsm_event(((struct ctc_priv
*) ch
->netdev
->priv
)->fsm
, DEV_EVENT_TXUP
,
921 * Got normal data, check for sanity, queue it up, allocate new buffer
922 * trigger bottom half, and initiate next read.
924 * @param fi An instance of a channel statemachine.
925 * @param event The event, just happened.
926 * @param arg Generic pointer, casted from channel * upon call.
929 ch_action_rx(fsm_instance
* fi
, int event
, void *arg
)
931 struct channel
*ch
= (struct channel
*) arg
;
932 struct net_device
*dev
= ch
->netdev
;
933 struct ctc_priv
*privptr
= dev
->priv
;
934 int len
= ch
->max_bufsize
- ch
->irb
->scsw
.count
;
935 struct sk_buff
*skb
= ch
->trans_skb
;
936 __u16 block_len
= *((__u16
*) skb
->data
);
940 fsm_deltimer(&ch
->timer
);
942 printk(KERN_DEBUG
"%s: got packet with length %d < 8\n",
944 privptr
->stats
.rx_dropped
++;
945 privptr
->stats
.rx_length_errors
++;
948 if (len
> ch
->max_bufsize
) {
949 printk(KERN_DEBUG
"%s: got packet with length %d > %d\n",
950 dev
->name
, len
, ch
->max_bufsize
);
951 privptr
->stats
.rx_dropped
++;
952 privptr
->stats
.rx_length_errors
++;
957 * VM TCP seems to have a bug sending 2 trailing bytes of garbage.
959 switch (ch
->protocol
) {
961 case CTC_PROTO_OS390
:
962 check_len
= block_len
+ 2;
965 check_len
= block_len
;
968 if ((len
< block_len
) || (len
> check_len
)) {
969 printk(KERN_DEBUG
"%s: got block length %d != rx length %d\n",
970 dev
->name
, block_len
, len
);
971 ctc_dump_skb(skb
, 0);
972 *((__u16
*) skb
->data
) = len
;
973 privptr
->stats
.rx_dropped
++;
974 privptr
->stats
.rx_length_errors
++;
979 *((__u16
*) skb
->data
) = block_len
;
980 ctc_unpack_skb(ch
, skb
);
983 skb
->data
= skb
->tail
= ch
->trans_skb_data
;
985 if (ctc_checkalloc_buffer(ch
, 1))
987 ch
->ccw
[1].count
= ch
->max_bufsize
;
988 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[0], (intparm_t
) ch
, 0xff, 0);
990 ccw_check_return_code(ch
, rc
);
993 static void ch_action_rxidle(fsm_instance
* fi
, int event
, void *arg
);
996 * Initialize connection by sending a __u16 of value 0.
998 * @param fi An instance of a channel statemachine.
999 * @param event The event, just happened.
1000 * @param arg Generic pointer, casted from channel * upon call.
1003 ch_action_firstio(fsm_instance
* fi
, int event
, void *arg
)
1005 struct channel
*ch
= (struct channel
*) arg
;
1008 if (fsm_getstate(fi
) == CH_STATE_TXIDLE
)
1009 printk(KERN_DEBUG
"%s: remote side issued READ?, "
1010 "init ...\n", ch
->id
);
1011 fsm_deltimer(&ch
->timer
);
1012 if (ctc_checkalloc_buffer(ch
, 1))
1014 if ((fsm_getstate(fi
) == CH_STATE_SETUPWAIT
) &&
1015 (ch
->protocol
== CTC_PROTO_OS390
)) {
1016 /* OS/390 resp. z/OS */
1017 if (CHANNEL_DIRECTION(ch
->flags
) == READ
) {
1018 *((__u16
*) ch
->trans_skb
->data
) = CTC_INITIAL_BLOCKLEN
;
1019 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
,
1020 CH_EVENT_TIMER
, ch
);
1021 ch_action_rxidle(fi
, event
, arg
);
1023 struct net_device
*dev
= ch
->netdev
;
1024 fsm_newstate(fi
, CH_STATE_TXIDLE
);
1025 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1026 DEV_EVENT_TXUP
, dev
);
1032 * Don´t setup a timer for receiving the initial RX frame
1033 * if in compatibility mode, since VM TCP delays the initial
1034 * frame until it has some data to send.
1036 if ((CHANNEL_DIRECTION(ch
->flags
) == WRITE
) ||
1037 (ch
->protocol
!= CTC_PROTO_S390
))
1038 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
, CH_EVENT_TIMER
, ch
);
1040 *((__u16
*) ch
->trans_skb
->data
) = CTC_INITIAL_BLOCKLEN
;
1041 ch
->ccw
[1].count
= 2; /* Transfer only length */
1043 fsm_newstate(fi
, (CHANNEL_DIRECTION(ch
->flags
) == READ
)
1044 ? CH_STATE_RXINIT
: CH_STATE_TXINIT
);
1045 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[0], (intparm_t
) ch
, 0xff, 0);
1047 fsm_deltimer(&ch
->timer
);
1048 fsm_newstate(fi
, CH_STATE_SETUPWAIT
);
1049 ccw_check_return_code(ch
, rc
);
1052 * If in compatibility mode since we don´t setup a timer, we
1053 * also signal RX channel up immediately. This enables us
1054 * to send packets early which in turn usually triggers some
1055 * reply from VM TCP which brings up the RX channel to it´s
1058 if ((CHANNEL_DIRECTION(ch
->flags
) == READ
) &&
1059 (ch
->protocol
== CTC_PROTO_S390
)) {
1060 struct net_device
*dev
= ch
->netdev
;
1061 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
, DEV_EVENT_RXUP
,
1067 * Got initial data, check it. If OK,
1068 * notify device statemachine that we are up and
1071 * @param fi An instance of a channel statemachine.
1072 * @param event The event, just happened.
1073 * @param arg Generic pointer, casted from channel * upon call.
1076 ch_action_rxidle(fsm_instance
* fi
, int event
, void *arg
)
1078 struct channel
*ch
= (struct channel
*) arg
;
1079 struct net_device
*dev
= ch
->netdev
;
1083 fsm_deltimer(&ch
->timer
);
1084 buflen
= *((__u16
*) ch
->trans_skb
->data
);
1085 pr_debug("%s: Initial RX count %d\n", dev
->name
, buflen
);
1086 if (buflen
>= CTC_INITIAL_BLOCKLEN
) {
1087 if (ctc_checkalloc_buffer(ch
, 1))
1089 ch
->ccw
[1].count
= ch
->max_bufsize
;
1090 fsm_newstate(fi
, CH_STATE_RXIDLE
);
1091 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[0],
1092 (intparm_t
) ch
, 0xff, 0);
1094 fsm_newstate(fi
, CH_STATE_RXINIT
);
1095 ccw_check_return_code(ch
, rc
);
1097 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1098 DEV_EVENT_RXUP
, dev
);
1100 printk(KERN_DEBUG
"%s: Initial RX count %d not %d\n",
1101 dev
->name
, buflen
, CTC_INITIAL_BLOCKLEN
);
1102 ch_action_firstio(fi
, event
, arg
);
1107 * Set channel into extended mode.
1109 * @param fi An instance of a channel statemachine.
1110 * @param event The event, just happened.
1111 * @param arg Generic pointer, casted from channel * upon call.
1114 ch_action_setmode(fsm_instance
* fi
, int event
, void *arg
)
1116 struct channel
*ch
= (struct channel
*) arg
;
1118 unsigned long saveflags
;
1120 fsm_deltimer(&ch
->timer
);
1121 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
, CH_EVENT_TIMER
, ch
);
1122 fsm_newstate(fi
, CH_STATE_SETUPWAIT
);
1123 if (event
== CH_EVENT_TIMER
)
1124 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1125 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[6], (intparm_t
) ch
, 0xff, 0);
1126 if (event
== CH_EVENT_TIMER
)
1127 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1129 fsm_deltimer(&ch
->timer
);
1130 fsm_newstate(fi
, CH_STATE_STARTWAIT
);
1131 ccw_check_return_code(ch
, rc
);
1139 * @param fi An instance of a channel statemachine.
1140 * @param event The event, just happened.
1141 * @param arg Generic pointer, casted from channel * upon call.
1144 ch_action_start(fsm_instance
* fi
, int event
, void *arg
)
1146 struct channel
*ch
= (struct channel
*) arg
;
1147 unsigned long saveflags
;
1149 struct net_device
*dev
;
1152 printk(KERN_WARNING
"ch_action_start ch=NULL\n");
1155 if (ch
->netdev
== NULL
) {
1156 printk(KERN_WARNING
"ch_action_start dev=NULL, id=%s\n",
1162 pr_debug("%s: %s channel start\n", dev
->name
,
1163 (CHANNEL_DIRECTION(ch
->flags
) == READ
) ? "RX" : "TX");
1165 if (ch
->trans_skb
!= NULL
) {
1166 clear_normalized_cda(&ch
->ccw
[1]);
1167 dev_kfree_skb(ch
->trans_skb
);
1168 ch
->trans_skb
= NULL
;
1170 if (CHANNEL_DIRECTION(ch
->flags
) == READ
) {
1171 ch
->ccw
[1].cmd_code
= CCW_CMD_READ
;
1172 ch
->ccw
[1].flags
= CCW_FLAG_SLI
;
1173 ch
->ccw
[1].count
= 0;
1175 ch
->ccw
[1].cmd_code
= CCW_CMD_WRITE
;
1176 ch
->ccw
[1].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1177 ch
->ccw
[1].count
= 0;
1179 if (ctc_checkalloc_buffer(ch
, 0))
1181 "%s: Could not allocate %s trans_skb, delaying "
1182 "allocation until first transfer\n",
1184 (CHANNEL_DIRECTION(ch
->flags
) == READ
) ? "RX" : "TX");
1186 ch
->ccw
[0].cmd_code
= CCW_CMD_PREPARE
;
1187 ch
->ccw
[0].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1188 ch
->ccw
[0].count
= 0;
1190 ch
->ccw
[2].cmd_code
= CCW_CMD_NOOP
; /* jointed CE + DE */
1191 ch
->ccw
[2].flags
= CCW_FLAG_SLI
;
1192 ch
->ccw
[2].count
= 0;
1194 memcpy(&ch
->ccw
[3], &ch
->ccw
[0], sizeof (struct ccw1
) * 3);
1196 ch
->ccw
[4].flags
&= ~CCW_FLAG_IDA
;
1198 fsm_newstate(fi
, CH_STATE_STARTWAIT
);
1199 fsm_addtimer(&ch
->timer
, 1000, CH_EVENT_TIMER
, ch
);
1200 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1201 rc
= ccw_device_halt(ch
->cdev
, (intparm_t
) ch
);
1202 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1204 fsm_deltimer(&ch
->timer
);
1205 ccw_check_return_code(ch
, rc
);
1207 pr_debug(KERN_DEBUG
"ctc: %s(): leaving\n", __FUNCTION__
);
1211 * Shutdown a channel.
1213 * @param fi An instance of a channel statemachine.
1214 * @param event The event, just happened.
1215 * @param arg Generic pointer, casted from channel * upon call.
1218 ch_action_haltio(fsm_instance
* fi
, int event
, void *arg
)
1220 struct channel
*ch
= (struct channel
*) arg
;
1221 unsigned long saveflags
;
1225 fsm_deltimer(&ch
->timer
);
1226 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
, CH_EVENT_TIMER
, ch
);
1227 if (event
== CH_EVENT_STOP
)
1228 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1229 oldstate
= fsm_getstate(fi
);
1230 fsm_newstate(fi
, CH_STATE_TERM
);
1231 rc
= ccw_device_halt(ch
->cdev
, (intparm_t
) ch
);
1232 if (event
== CH_EVENT_STOP
)
1233 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1235 fsm_deltimer(&ch
->timer
);
1236 fsm_newstate(fi
, oldstate
);
1237 ccw_check_return_code(ch
, rc
);
1242 * A channel has successfully been halted.
1243 * Cleanup it's queue and notify interface statemachine.
1245 * @param fi An instance of a channel statemachine.
1246 * @param event The event, just happened.
1247 * @param arg Generic pointer, casted from channel * upon call.
1250 ch_action_stopped(fsm_instance
* fi
, int event
, void *arg
)
1252 struct channel
*ch
= (struct channel
*) arg
;
1253 struct net_device
*dev
= ch
->netdev
;
1255 fsm_deltimer(&ch
->timer
);
1256 fsm_newstate(fi
, CH_STATE_STOPPED
);
1257 if (ch
->trans_skb
!= NULL
) {
1258 clear_normalized_cda(&ch
->ccw
[1]);
1259 dev_kfree_skb(ch
->trans_skb
);
1260 ch
->trans_skb
= NULL
;
1262 if (CHANNEL_DIRECTION(ch
->flags
) == READ
) {
1263 skb_queue_purge(&ch
->io_queue
);
1264 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1265 DEV_EVENT_RXDOWN
, dev
);
1267 ctc_purge_skb_queue(&ch
->io_queue
);
1268 spin_lock(&ch
->collect_lock
);
1269 ctc_purge_skb_queue(&ch
->collect_queue
);
1270 ch
->collect_len
= 0;
1271 spin_unlock(&ch
->collect_lock
);
1272 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1273 DEV_EVENT_TXDOWN
, dev
);
1278 * A stop command from device statemachine arrived and we are in
1279 * not operational mode. Set state to stopped.
1281 * @param fi An instance of a channel statemachine.
1282 * @param event The event, just happened.
1283 * @param arg Generic pointer, casted from channel * upon call.
1286 ch_action_stop(fsm_instance
* fi
, int event
, void *arg
)
1288 fsm_newstate(fi
, CH_STATE_STOPPED
);
1292 * A machine check for no path, not operational status or gone device has
1294 * Cleanup queue and notify interface statemachine.
1296 * @param fi An instance of a channel statemachine.
1297 * @param event The event, just happened.
1298 * @param arg Generic pointer, casted from channel * upon call.
1301 ch_action_fail(fsm_instance
* fi
, int event
, void *arg
)
1303 struct channel
*ch
= (struct channel
*) arg
;
1304 struct net_device
*dev
= ch
->netdev
;
1306 fsm_deltimer(&ch
->timer
);
1307 fsm_newstate(fi
, CH_STATE_NOTOP
);
1308 if (CHANNEL_DIRECTION(ch
->flags
) == READ
) {
1309 skb_queue_purge(&ch
->io_queue
);
1310 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1311 DEV_EVENT_RXDOWN
, dev
);
1313 ctc_purge_skb_queue(&ch
->io_queue
);
1314 spin_lock(&ch
->collect_lock
);
1315 ctc_purge_skb_queue(&ch
->collect_queue
);
1316 ch
->collect_len
= 0;
1317 spin_unlock(&ch
->collect_lock
);
1318 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1319 DEV_EVENT_TXDOWN
, dev
);
1324 * Handle error during setup of channel.
1326 * @param fi An instance of a channel statemachine.
1327 * @param event The event, just happened.
1328 * @param arg Generic pointer, casted from channel * upon call.
1331 ch_action_setuperr(fsm_instance
* fi
, int event
, void *arg
)
1333 struct channel
*ch
= (struct channel
*) arg
;
1334 struct net_device
*dev
= ch
->netdev
;
1337 * Special case: Got UC_RCRESET on setmode.
1338 * This means that remote side isn't setup. In this case
1339 * simply retry after some 10 secs...
1341 if ((fsm_getstate(fi
) == CH_STATE_SETUPWAIT
) &&
1342 ((event
== CH_EVENT_UC_RCRESET
) ||
1343 (event
== CH_EVENT_UC_RSRESET
))) {
1344 fsm_newstate(fi
, CH_STATE_STARTRETRY
);
1345 fsm_deltimer(&ch
->timer
);
1346 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
, CH_EVENT_TIMER
, ch
);
1347 if (CHANNEL_DIRECTION(ch
->flags
) == READ
) {
1348 int rc
= ccw_device_halt(ch
->cdev
, (intparm_t
) ch
);
1350 ccw_check_return_code(ch
, rc
);
1355 printk(KERN_DEBUG
"%s: Error %s during %s channel setup state=%s\n",
1356 dev
->name
, ch_event_names
[event
],
1357 (CHANNEL_DIRECTION(ch
->flags
) == READ
) ? "RX" : "TX",
1358 fsm_getstate_str(fi
));
1359 if (CHANNEL_DIRECTION(ch
->flags
) == READ
) {
1360 fsm_newstate(fi
, CH_STATE_RXERR
);
1361 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1362 DEV_EVENT_RXDOWN
, dev
);
1364 fsm_newstate(fi
, CH_STATE_TXERR
);
1365 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1366 DEV_EVENT_TXDOWN
, dev
);
1371 * Restart a channel after an error.
1373 * @param fi An instance of a channel statemachine.
1374 * @param event The event, just happened.
1375 * @param arg Generic pointer, casted from channel * upon call.
1378 ch_action_restart(fsm_instance
* fi
, int event
, void *arg
)
1380 unsigned long saveflags
;
1384 struct channel
*ch
= (struct channel
*) arg
;
1385 struct net_device
*dev
= ch
->netdev
;
1387 fsm_deltimer(&ch
->timer
);
1388 printk(KERN_DEBUG
"%s: %s channel restart\n", dev
->name
,
1389 (CHANNEL_DIRECTION(ch
->flags
) == READ
) ? "RX" : "TX");
1390 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
, CH_EVENT_TIMER
, ch
);
1391 oldstate
= fsm_getstate(fi
);
1392 fsm_newstate(fi
, CH_STATE_STARTWAIT
);
1393 if (event
== CH_EVENT_TIMER
)
1394 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1395 rc
= ccw_device_halt(ch
->cdev
, (intparm_t
) ch
);
1396 if (event
== CH_EVENT_TIMER
)
1397 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1399 fsm_deltimer(&ch
->timer
);
1400 fsm_newstate(fi
, oldstate
);
1401 ccw_check_return_code(ch
, rc
);
1406 * Handle error during RX initial handshake (exchange of
1407 * 0-length block header)
1409 * @param fi An instance of a channel statemachine.
1410 * @param event The event, just happened.
1411 * @param arg Generic pointer, casted from channel * upon call.
1414 ch_action_rxiniterr(fsm_instance
* fi
, int event
, void *arg
)
1416 struct channel
*ch
= (struct channel
*) arg
;
1417 struct net_device
*dev
= ch
->netdev
;
1419 if (event
== CH_EVENT_TIMER
) {
1420 fsm_deltimer(&ch
->timer
);
1421 printk(KERN_DEBUG
"%s: Timeout during RX init handshake\n",
1423 if (ch
->retry
++ < 3)
1424 ch_action_restart(fi
, event
, arg
);
1426 fsm_newstate(fi
, CH_STATE_RXERR
);
1427 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1428 DEV_EVENT_RXDOWN
, dev
);
1431 printk(KERN_WARNING
"%s: Error during RX init handshake\n",
1436 * Notify device statemachine if we gave up initialization
1439 * @param fi An instance of a channel statemachine.
1440 * @param event The event, just happened.
1441 * @param arg Generic pointer, casted from channel * upon call.
1444 ch_action_rxinitfail(fsm_instance
* fi
, int event
, void *arg
)
1446 struct channel
*ch
= (struct channel
*) arg
;
1447 struct net_device
*dev
= ch
->netdev
;
1449 fsm_newstate(fi
, CH_STATE_RXERR
);
1450 printk(KERN_WARNING
"%s: RX initialization failed\n", dev
->name
);
1451 printk(KERN_WARNING
"%s: RX <-> RX connection detected\n", dev
->name
);
1452 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
, DEV_EVENT_RXDOWN
, dev
);
1456 * Handle RX Unit check remote reset (remote disconnected)
1458 * @param fi An instance of a channel statemachine.
1459 * @param event The event, just happened.
1460 * @param arg Generic pointer, casted from channel * upon call.
1463 ch_action_rxdisc(fsm_instance
* fi
, int event
, void *arg
)
1465 struct channel
*ch
= (struct channel
*) arg
;
1466 struct channel
*ch2
;
1467 struct net_device
*dev
= ch
->netdev
;
1469 fsm_deltimer(&ch
->timer
);
1470 printk(KERN_DEBUG
"%s: Got remote disconnect, re-initializing ...\n",
1474 * Notify device statemachine
1476 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
, DEV_EVENT_RXDOWN
, dev
);
1477 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
, DEV_EVENT_TXDOWN
, dev
);
1479 fsm_newstate(fi
, CH_STATE_DTERM
);
1480 ch2
= ((struct ctc_priv
*) dev
->priv
)->channel
[WRITE
];
1481 fsm_newstate(ch2
->fsm
, CH_STATE_DTERM
);
1483 ccw_device_halt(ch
->cdev
, (intparm_t
) ch
);
1484 ccw_device_halt(ch2
->cdev
, (intparm_t
) ch2
);
1488 * Handle error during TX channel initialization.
1490 * @param fi An instance of a channel statemachine.
1491 * @param event The event, just happened.
1492 * @param arg Generic pointer, casted from channel * upon call.
1495 ch_action_txiniterr(fsm_instance
* fi
, int event
, void *arg
)
1497 struct channel
*ch
= (struct channel
*) arg
;
1498 struct net_device
*dev
= ch
->netdev
;
1500 if (event
== CH_EVENT_TIMER
) {
1501 fsm_deltimer(&ch
->timer
);
1502 printk(KERN_DEBUG
"%s: Timeout during TX init handshake\n",
1504 if (ch
->retry
++ < 3)
1505 ch_action_restart(fi
, event
, arg
);
1507 fsm_newstate(fi
, CH_STATE_TXERR
);
1508 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1509 DEV_EVENT_TXDOWN
, dev
);
1512 printk(KERN_WARNING
"%s: Error during TX init handshake\n",
1517 * Handle TX timeout by retrying operation.
1519 * @param fi An instance of a channel statemachine.
1520 * @param event The event, just happened.
1521 * @param arg Generic pointer, casted from channel * upon call.
1524 ch_action_txretry(fsm_instance
* fi
, int event
, void *arg
)
1526 struct channel
*ch
= (struct channel
*) arg
;
1527 struct net_device
*dev
= ch
->netdev
;
1528 unsigned long saveflags
;
1530 fsm_deltimer(&ch
->timer
);
1531 if (ch
->retry
++ > 3) {
1532 printk(KERN_DEBUG
"%s: TX retry failed, restarting channel\n",
1534 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1535 DEV_EVENT_TXDOWN
, dev
);
1536 ch_action_restart(fi
, event
, arg
);
1538 struct sk_buff
*skb
;
1540 printk(KERN_DEBUG
"%s: TX retry %d\n", dev
->name
, ch
->retry
);
1541 if ((skb
= skb_peek(&ch
->io_queue
))) {
1544 clear_normalized_cda(&ch
->ccw
[4]);
1545 ch
->ccw
[4].count
= skb
->len
;
1546 if (set_normalized_cda(&ch
->ccw
[4], skb
->data
)) {
1547 printk(KERN_DEBUG
"%s: IDAL alloc failed, "
1548 "restarting channel\n", dev
->name
);
1549 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1550 DEV_EVENT_TXDOWN
, dev
);
1551 ch_action_restart(fi
, event
, arg
);
1554 fsm_addtimer(&ch
->timer
, 1000, CH_EVENT_TIMER
, ch
);
1555 if (event
== CH_EVENT_TIMER
)
1556 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
),
1558 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[3],
1559 (intparm_t
) ch
, 0xff, 0);
1560 if (event
== CH_EVENT_TIMER
)
1561 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
),
1564 fsm_deltimer(&ch
->timer
);
1565 ccw_check_return_code(ch
, rc
);
1566 ctc_purge_skb_queue(&ch
->io_queue
);
1574 * Handle fatal errors during an I/O command.
1576 * @param fi An instance of a channel statemachine.
1577 * @param event The event, just happened.
1578 * @param arg Generic pointer, casted from channel * upon call.
1581 ch_action_iofatal(fsm_instance
* fi
, int event
, void *arg
)
1583 struct channel
*ch
= (struct channel
*) arg
;
1584 struct net_device
*dev
= ch
->netdev
;
1586 fsm_deltimer(&ch
->timer
);
1587 if (CHANNEL_DIRECTION(ch
->flags
) == READ
) {
1588 printk(KERN_DEBUG
"%s: RX I/O error\n", dev
->name
);
1589 fsm_newstate(fi
, CH_STATE_RXERR
);
1590 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1591 DEV_EVENT_RXDOWN
, dev
);
1593 printk(KERN_DEBUG
"%s: TX I/O error\n", dev
->name
);
1594 fsm_newstate(fi
, CH_STATE_TXERR
);
1595 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
,
1596 DEV_EVENT_TXDOWN
, dev
);
1601 ch_action_reinit(fsm_instance
*fi
, int event
, void *arg
)
1603 struct channel
*ch
= (struct channel
*)arg
;
1604 struct net_device
*dev
= ch
->netdev
;
1605 struct ctc_priv
*privptr
= dev
->priv
;
1607 ch_action_iofatal(fi
, event
, arg
);
1608 fsm_addtimer(&privptr
->restart_timer
, 1000, DEV_EVENT_RESTART
, dev
);
1613 * The statemachine for a channel.
1615 static const fsm_node ch_fsm
[] = {
1616 {CH_STATE_STOPPED
, CH_EVENT_STOP
, fsm_action_nop
},
1617 {CH_STATE_STOPPED
, CH_EVENT_START
, ch_action_start
},
1618 {CH_STATE_STOPPED
, CH_EVENT_FINSTAT
, fsm_action_nop
},
1619 {CH_STATE_STOPPED
, CH_EVENT_MC_FAIL
, fsm_action_nop
},
1621 {CH_STATE_NOTOP
, CH_EVENT_STOP
, ch_action_stop
},
1622 {CH_STATE_NOTOP
, CH_EVENT_START
, fsm_action_nop
},
1623 {CH_STATE_NOTOP
, CH_EVENT_FINSTAT
, fsm_action_nop
},
1624 {CH_STATE_NOTOP
, CH_EVENT_MC_FAIL
, fsm_action_nop
},
1625 {CH_STATE_NOTOP
, CH_EVENT_MC_GOOD
, ch_action_start
},
1627 {CH_STATE_STARTWAIT
, CH_EVENT_STOP
, ch_action_haltio
},
1628 {CH_STATE_STARTWAIT
, CH_EVENT_START
, fsm_action_nop
},
1629 {CH_STATE_STARTWAIT
, CH_EVENT_FINSTAT
, ch_action_setmode
},
1630 {CH_STATE_STARTWAIT
, CH_EVENT_TIMER
, ch_action_setuperr
},
1631 {CH_STATE_STARTWAIT
, CH_EVENT_IO_ENODEV
, ch_action_iofatal
},
1632 {CH_STATE_STARTWAIT
, CH_EVENT_IO_EIO
, ch_action_reinit
},
1633 {CH_STATE_STARTWAIT
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1635 {CH_STATE_STARTRETRY
, CH_EVENT_STOP
, ch_action_haltio
},
1636 {CH_STATE_STARTRETRY
, CH_EVENT_TIMER
, ch_action_setmode
},
1637 {CH_STATE_STARTRETRY
, CH_EVENT_FINSTAT
, fsm_action_nop
},
1638 {CH_STATE_STARTRETRY
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1640 {CH_STATE_SETUPWAIT
, CH_EVENT_STOP
, ch_action_haltio
},
1641 {CH_STATE_SETUPWAIT
, CH_EVENT_START
, fsm_action_nop
},
1642 {CH_STATE_SETUPWAIT
, CH_EVENT_FINSTAT
, ch_action_firstio
},
1643 {CH_STATE_SETUPWAIT
, CH_EVENT_UC_RCRESET
, ch_action_setuperr
},
1644 {CH_STATE_SETUPWAIT
, CH_EVENT_UC_RSRESET
, ch_action_setuperr
},
1645 {CH_STATE_SETUPWAIT
, CH_EVENT_TIMER
, ch_action_setmode
},
1646 {CH_STATE_SETUPWAIT
, CH_EVENT_IO_ENODEV
, ch_action_iofatal
},
1647 {CH_STATE_SETUPWAIT
, CH_EVENT_IO_EIO
, ch_action_reinit
},
1648 {CH_STATE_SETUPWAIT
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1650 {CH_STATE_RXINIT
, CH_EVENT_STOP
, ch_action_haltio
},
1651 {CH_STATE_RXINIT
, CH_EVENT_START
, fsm_action_nop
},
1652 {CH_STATE_RXINIT
, CH_EVENT_FINSTAT
, ch_action_rxidle
},
1653 {CH_STATE_RXINIT
, CH_EVENT_UC_RCRESET
, ch_action_rxiniterr
},
1654 {CH_STATE_RXINIT
, CH_EVENT_UC_RSRESET
, ch_action_rxiniterr
},
1655 {CH_STATE_RXINIT
, CH_EVENT_TIMER
, ch_action_rxiniterr
},
1656 {CH_STATE_RXINIT
, CH_EVENT_ATTNBUSY
, ch_action_rxinitfail
},
1657 {CH_STATE_RXINIT
, CH_EVENT_IO_ENODEV
, ch_action_iofatal
},
1658 {CH_STATE_RXINIT
, CH_EVENT_IO_EIO
, ch_action_reinit
},
1659 {CH_STATE_RXINIT
, CH_EVENT_UC_ZERO
, ch_action_firstio
},
1660 {CH_STATE_RXINIT
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1662 {CH_STATE_RXIDLE
, CH_EVENT_STOP
, ch_action_haltio
},
1663 {CH_STATE_RXIDLE
, CH_EVENT_START
, fsm_action_nop
},
1664 {CH_STATE_RXIDLE
, CH_EVENT_FINSTAT
, ch_action_rx
},
1665 {CH_STATE_RXIDLE
, CH_EVENT_UC_RCRESET
, ch_action_rxdisc
},
1666 // { CH_STATE_RXIDLE, CH_EVENT_UC_RSRESET, ch_action_rxretry },
1667 {CH_STATE_RXIDLE
, CH_EVENT_IO_ENODEV
, ch_action_iofatal
},
1668 {CH_STATE_RXIDLE
, CH_EVENT_IO_EIO
, ch_action_reinit
},
1669 {CH_STATE_RXIDLE
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1670 {CH_STATE_RXIDLE
, CH_EVENT_UC_ZERO
, ch_action_rx
},
1672 {CH_STATE_TXINIT
, CH_EVENT_STOP
, ch_action_haltio
},
1673 {CH_STATE_TXINIT
, CH_EVENT_START
, fsm_action_nop
},
1674 {CH_STATE_TXINIT
, CH_EVENT_FINSTAT
, ch_action_txidle
},
1675 {CH_STATE_TXINIT
, CH_EVENT_UC_RCRESET
, ch_action_txiniterr
},
1676 {CH_STATE_TXINIT
, CH_EVENT_UC_RSRESET
, ch_action_txiniterr
},
1677 {CH_STATE_TXINIT
, CH_EVENT_TIMER
, ch_action_txiniterr
},
1678 {CH_STATE_TXINIT
, CH_EVENT_IO_ENODEV
, ch_action_iofatal
},
1679 {CH_STATE_TXINIT
, CH_EVENT_IO_EIO
, ch_action_reinit
},
1680 {CH_STATE_TXINIT
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1682 {CH_STATE_TXIDLE
, CH_EVENT_STOP
, ch_action_haltio
},
1683 {CH_STATE_TXIDLE
, CH_EVENT_START
, fsm_action_nop
},
1684 {CH_STATE_TXIDLE
, CH_EVENT_FINSTAT
, ch_action_firstio
},
1685 {CH_STATE_TXIDLE
, CH_EVENT_UC_RCRESET
, fsm_action_nop
},
1686 {CH_STATE_TXIDLE
, CH_EVENT_UC_RSRESET
, fsm_action_nop
},
1687 {CH_STATE_TXIDLE
, CH_EVENT_IO_ENODEV
, ch_action_iofatal
},
1688 {CH_STATE_TXIDLE
, CH_EVENT_IO_EIO
, ch_action_reinit
},
1689 {CH_STATE_TXIDLE
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1691 {CH_STATE_TERM
, CH_EVENT_STOP
, fsm_action_nop
},
1692 {CH_STATE_TERM
, CH_EVENT_START
, ch_action_restart
},
1693 {CH_STATE_TERM
, CH_EVENT_FINSTAT
, ch_action_stopped
},
1694 {CH_STATE_TERM
, CH_EVENT_UC_RCRESET
, fsm_action_nop
},
1695 {CH_STATE_TERM
, CH_EVENT_UC_RSRESET
, fsm_action_nop
},
1696 {CH_STATE_TERM
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1698 {CH_STATE_DTERM
, CH_EVENT_STOP
, ch_action_haltio
},
1699 {CH_STATE_DTERM
, CH_EVENT_START
, ch_action_restart
},
1700 {CH_STATE_DTERM
, CH_EVENT_FINSTAT
, ch_action_setmode
},
1701 {CH_STATE_DTERM
, CH_EVENT_UC_RCRESET
, fsm_action_nop
},
1702 {CH_STATE_DTERM
, CH_EVENT_UC_RSRESET
, fsm_action_nop
},
1703 {CH_STATE_DTERM
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1705 {CH_STATE_TX
, CH_EVENT_STOP
, ch_action_haltio
},
1706 {CH_STATE_TX
, CH_EVENT_START
, fsm_action_nop
},
1707 {CH_STATE_TX
, CH_EVENT_FINSTAT
, ch_action_txdone
},
1708 {CH_STATE_TX
, CH_EVENT_UC_RCRESET
, ch_action_txretry
},
1709 {CH_STATE_TX
, CH_EVENT_UC_RSRESET
, ch_action_txretry
},
1710 {CH_STATE_TX
, CH_EVENT_TIMER
, ch_action_txretry
},
1711 {CH_STATE_TX
, CH_EVENT_IO_ENODEV
, ch_action_iofatal
},
1712 {CH_STATE_TX
, CH_EVENT_IO_EIO
, ch_action_reinit
},
1713 {CH_STATE_TX
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1715 {CH_STATE_RXERR
, CH_EVENT_STOP
, ch_action_haltio
},
1716 {CH_STATE_TXERR
, CH_EVENT_STOP
, ch_action_haltio
},
1717 {CH_STATE_TXERR
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1718 {CH_STATE_RXERR
, CH_EVENT_MC_FAIL
, ch_action_fail
},
1721 static const int CH_FSM_LEN
= sizeof (ch_fsm
) / sizeof (fsm_node
);
1724 * Functions related to setup and device detection.
1725 *****************************************************************************/
1728 less_than(char *id1
, char *id2
)
1736 dev1
= simple_strtoul(id1
, &id1
, 16);
1737 dev2
= simple_strtoul(id2
, &id2
, 16);
1743 * Add a new channel to the list of channels.
1744 * Keeps the channel list sorted.
1746 * @param cdev The ccw_device to be added.
1747 * @param type The type class of the new channel.
1749 * @return 0 on success, !0 on error.
1752 add_channel(struct ccw_device
*cdev
, enum channel_types type
)
1754 struct channel
**c
= &channels
;
1758 (struct channel
*) kmalloc(sizeof (struct channel
),
1759 GFP_KERNEL
)) == NULL
) {
1760 printk(KERN_WARNING
"ctc: Out of memory in add_channel\n");
1763 memset(ch
, 0, sizeof (struct channel
));
1764 if ((ch
->ccw
= (struct ccw1
*) kmalloc(sizeof (struct ccw1
) * 8,
1765 GFP_KERNEL
| GFP_DMA
)) == NULL
) {
1767 printk(KERN_WARNING
"ctc: Out of memory in add_channel\n");
1772 * "static" ccws are used in the following way:
1774 * ccw[0..2] (Channel program for generic I/O):
1776 * 1: read or write (depending on direction) with fixed
1777 * buffer (idal allocated once when buffer is allocated)
1779 * ccw[3..5] (Channel program for direct write of packets)
1781 * 4: write (idal allocated on every write).
1783 * ccw[6..7] (Channel program for initial channel setup):
1784 * 3: set extended mode
1787 * ch->ccw[0..5] are initialized in ch_action_start because
1788 * the channel's direction is yet unknown here.
1790 ch
->ccw
[6].cmd_code
= CCW_CMD_SET_EXTENDED
;
1791 ch
->ccw
[6].flags
= CCW_FLAG_SLI
;
1792 ch
->ccw
[6].count
= 0;
1795 ch
->ccw
[7].cmd_code
= CCW_CMD_NOOP
;
1796 ch
->ccw
[7].flags
= CCW_FLAG_SLI
;
1797 ch
->ccw
[7].count
= 0;
1801 snprintf(ch
->id
, DEVICE_ID_SIZE
, "ch-%s", cdev
->dev
.bus_id
);
1803 ch
->fsm
= init_fsm(ch
->id
, ch_state_names
,
1804 ch_event_names
, NR_CH_STATES
, NR_CH_EVENTS
,
1805 ch_fsm
, CH_FSM_LEN
, GFP_KERNEL
);
1806 if (ch
->fsm
== NULL
) {
1808 "ctc: Could not create FSM in add_channel\n");
1812 fsm_newstate(ch
->fsm
, CH_STATE_IDLE
);
1813 if ((ch
->irb
= (struct irb
*) kmalloc(sizeof (struct irb
),
1814 GFP_KERNEL
)) == NULL
) {
1815 printk(KERN_WARNING
"ctc: Out of memory in add_channel\n");
1820 memset(ch
->irb
, 0, sizeof (struct irb
));
1821 while (*c
&& less_than((*c
)->id
, ch
->id
))
1823 if (!strncmp((*c
)->id
, ch
->id
, CTC_ID_SIZE
)) {
1825 "ctc: add_channel: device %s already in list, "
1826 "using old entry\n", (*c
)->id
);
1832 fsm_settimer(ch
->fsm
, &ch
->timer
);
1833 skb_queue_head_init(&ch
->io_queue
);
1834 skb_queue_head_init(&ch
->collect_queue
);
1841 * Release a specific channel in the channel list.
1843 * @param ch Pointer to channel struct to be released.
1846 channel_free(struct channel
*ch
)
1848 ch
->flags
&= ~CHANNEL_FLAGS_INUSE
;
1849 fsm_newstate(ch
->fsm
, CH_STATE_IDLE
);
1853 * Remove a specific channel in the channel list.
1855 * @param ch Pointer to channel struct to be released.
1858 channel_remove(struct channel
*ch
)
1860 struct channel
**c
= &channels
;
1869 fsm_deltimer(&ch
->timer
);
1871 clear_normalized_cda(&ch
->ccw
[4]);
1872 if (ch
->trans_skb
!= NULL
) {
1873 clear_normalized_cda(&ch
->ccw
[1]);
1874 dev_kfree_skb(ch
->trans_skb
);
1884 * Get a specific channel from the channel list.
1886 * @param type Type of channel we are interested in.
1887 * @param id Id of channel we are interested in.
1888 * @param direction Direction we want to use this channel for.
1890 * @return Pointer to a channel or NULL if no matching channel available.
1892 static struct channel
1894 channel_get(enum channel_types type
, char *id
, int direction
)
1896 struct channel
*ch
= channels
;
1898 pr_debug("ctc: %s(): searching for ch with id %d and type %d\n",
1899 __FUNCTION__
, id
, type
);
1901 while (ch
&& ((strncmp(ch
->id
, id
, CTC_ID_SIZE
)) || (ch
->type
!= type
))) {
1902 pr_debug("ctc: %s(): ch=0x%p (id=%s, type=%d\n",
1903 __FUNCTION__
, ch
, ch
->id
, ch
->type
);
1906 pr_debug("ctc: %s(): ch=0x%pq (id=%s, type=%d\n",
1907 __FUNCTION__
, ch
, ch
->id
, ch
->type
);
1909 printk(KERN_WARNING
"ctc: %s(): channel with id %s "
1910 "and type %d not found in channel list\n",
1911 __FUNCTION__
, id
, type
);
1913 if (ch
->flags
& CHANNEL_FLAGS_INUSE
)
1916 ch
->flags
|= CHANNEL_FLAGS_INUSE
;
1917 ch
->flags
&= ~CHANNEL_FLAGS_RWMASK
;
1918 ch
->flags
|= (direction
== WRITE
)
1919 ? CHANNEL_FLAGS_WRITE
: CHANNEL_FLAGS_READ
;
1920 fsm_newstate(ch
->fsm
, CH_STATE_STOPPED
);
1927 * Return the channel type by name.
1929 * @param name Name of network interface.
1931 * @return Type class of channel to be used for that interface.
1933 static enum channel_types
inline
1934 extract_channel_media(char *name
)
1936 enum channel_types ret
= channel_type_unknown
;
1939 if (strncmp(name
, "ctc", 3) == 0)
1940 ret
= channel_type_parallel
;
1941 if (strncmp(name
, "escon", 5) == 0)
1942 ret
= channel_type_escon
;
1950 * @param cdev The ccw_device the interrupt is for.
1951 * @param intparm interruption parameter.
1952 * @param irb interruption response block.
1955 ctc_irq_handler(struct ccw_device
*cdev
, unsigned long intparm
, struct irb
*irb
)
1958 struct net_device
*dev
;
1960 ch
= (struct channel
*) intparm
;
1962 * Check for unsolicited interrupts.
1963 * If intparm is NULL, try to get channel from ccw_device.
1966 ch
= container_of(&cdev
, struct channel
, cdev
);
1969 "ctc: Got unsolicited irq: %s c-%02x d-%02x\n",
1970 cdev
->dev
.bus_id
, irb
->scsw
.cstat
,
1976 dev
= (struct net_device
*) (ch
->netdev
);
1979 "ctc: ctc_irq_handler dev = NULL bus_id=%s, ch=0x%p\n",
1980 cdev
->dev
.bus_id
, ch
);
1984 pr_debug("%s: interrupt for device: %s received c-%02x d-%02x\n"
1985 dev
->name
, ch
->id
, irb
->scsw
.cstat
, irb
->scsw
.dstat
);
1987 /* Copy interruption response block. */
1988 memcpy(ch
->irb
, irb
, sizeof(struct irb
));
1990 /* Check for good subchannel return code, otherwise error message */
1991 if (ch
->irb
->scsw
.cstat
) {
1992 fsm_event(ch
->fsm
, CH_EVENT_SC_UNKNOWN
, ch
);
1994 "%s: subchannel check for device: %s - %02x %02x\n",
1995 dev
->name
, ch
->id
, ch
->irb
->scsw
.cstat
,
1996 ch
->irb
->scsw
.dstat
);
2000 /* Check the reason-code of a unit check */
2001 if (ch
->irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) {
2002 ccw_unit_check(ch
, ch
->irb
->ecw
[0]);
2005 if (ch
->irb
->scsw
.dstat
& DEV_STAT_BUSY
) {
2006 if (ch
->irb
->scsw
.dstat
& DEV_STAT_ATTENTION
)
2007 fsm_event(ch
->fsm
, CH_EVENT_ATTNBUSY
, ch
);
2009 fsm_event(ch
->fsm
, CH_EVENT_BUSY
, ch
);
2012 if (ch
->irb
->scsw
.dstat
& DEV_STAT_ATTENTION
) {
2013 fsm_event(ch
->fsm
, CH_EVENT_ATTN
, ch
);
2016 if ((ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
2017 (ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
2018 (ch
->irb
->scsw
.stctl
==
2019 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))
2020 fsm_event(ch
->fsm
, CH_EVENT_FINSTAT
, ch
);
2022 fsm_event(ch
->fsm
, CH_EVENT_IRQ
, ch
);
2027 * Actions for interface - statemachine.
2028 *****************************************************************************/
2031 * Startup channels by sending CH_EVENT_START to each channel.
2033 * @param fi An instance of an interface statemachine.
2034 * @param event The event, just happened.
2035 * @param arg Generic pointer, casted from struct net_device * upon call.
2038 dev_action_start(fsm_instance
* fi
, int event
, void *arg
)
2040 struct net_device
*dev
= (struct net_device
*) arg
;
2041 struct ctc_priv
*privptr
= dev
->priv
;
2044 fsm_deltimer(&privptr
->restart_timer
);
2045 fsm_newstate(fi
, DEV_STATE_STARTWAIT_RXTX
);
2046 for (direction
= READ
; direction
<= WRITE
; direction
++) {
2047 struct channel
*ch
= privptr
->channel
[direction
];
2048 fsm_event(ch
->fsm
, CH_EVENT_START
, ch
);
2053 * Shutdown channels by sending CH_EVENT_STOP to each channel.
2055 * @param fi An instance of an interface statemachine.
2056 * @param event The event, just happened.
2057 * @param arg Generic pointer, casted from struct net_device * upon call.
2060 dev_action_stop(fsm_instance
* fi
, int event
, void *arg
)
2062 struct net_device
*dev
= (struct net_device
*) arg
;
2063 struct ctc_priv
*privptr
= dev
->priv
;
2066 fsm_newstate(fi
, DEV_STATE_STOPWAIT_RXTX
);
2067 for (direction
= READ
; direction
<= WRITE
; direction
++) {
2068 struct channel
*ch
= privptr
->channel
[direction
];
2069 fsm_event(ch
->fsm
, CH_EVENT_STOP
, ch
);
2073 dev_action_restart(fsm_instance
*fi
, int event
, void *arg
)
2075 struct net_device
*dev
= (struct net_device
*)arg
;
2076 struct ctc_priv
*privptr
= dev
->priv
;
2078 printk(KERN_DEBUG
"%s: Restarting\n", dev
->name
);
2079 dev_action_stop(fi
, event
, arg
);
2080 fsm_event(privptr
->fsm
, DEV_EVENT_STOP
, dev
);
2081 fsm_addtimer(&privptr
->restart_timer
, CTC_TIMEOUT_5SEC
,
2082 DEV_EVENT_START
, dev
);
2086 * Called from channel statemachine
2087 * when a channel is up and running.
2089 * @param fi An instance of an interface statemachine.
2090 * @param event The event, just happened.
2091 * @param arg Generic pointer, casted from struct net_device * upon call.
2094 dev_action_chup(fsm_instance
* fi
, int event
, void *arg
)
2096 struct net_device
*dev
= (struct net_device
*) arg
;
2097 struct ctc_priv
*privptr
= dev
->priv
;
2099 switch (fsm_getstate(fi
)) {
2100 case DEV_STATE_STARTWAIT_RXTX
:
2101 if (event
== DEV_EVENT_RXUP
)
2102 fsm_newstate(fi
, DEV_STATE_STARTWAIT_TX
);
2104 fsm_newstate(fi
, DEV_STATE_STARTWAIT_RX
);
2106 case DEV_STATE_STARTWAIT_RX
:
2107 if (event
== DEV_EVENT_RXUP
) {
2108 fsm_newstate(fi
, DEV_STATE_RUNNING
);
2110 "%s: connected with remote side\n", dev
->name
);
2111 if (privptr
->protocol
== CTC_PROTO_LINUX_TTY
)
2112 ctc_tty_setcarrier(dev
, 1);
2113 ctc_clear_busy(dev
);
2116 case DEV_STATE_STARTWAIT_TX
:
2117 if (event
== DEV_EVENT_TXUP
) {
2118 fsm_newstate(fi
, DEV_STATE_RUNNING
);
2120 "%s: connected with remote side\n", dev
->name
);
2121 if (privptr
->protocol
== CTC_PROTO_LINUX_TTY
)
2122 ctc_tty_setcarrier(dev
, 1);
2123 ctc_clear_busy(dev
);
2126 case DEV_STATE_STOPWAIT_TX
:
2127 if (event
== DEV_EVENT_RXUP
)
2128 fsm_newstate(fi
, DEV_STATE_STOPWAIT_RXTX
);
2130 case DEV_STATE_STOPWAIT_RX
:
2131 if (event
== DEV_EVENT_TXUP
)
2132 fsm_newstate(fi
, DEV_STATE_STOPWAIT_RXTX
);
2138 * Called from channel statemachine
2139 * when a channel has been shutdown.
2141 * @param fi An instance of an interface statemachine.
2142 * @param event The event, just happened.
2143 * @param arg Generic pointer, casted from struct net_device * upon call.
2146 dev_action_chdown(fsm_instance
* fi
, int event
, void *arg
)
2148 struct net_device
*dev
= (struct net_device
*) arg
;
2149 struct ctc_priv
*privptr
= dev
->priv
;
2151 switch (fsm_getstate(fi
)) {
2152 case DEV_STATE_RUNNING
:
2153 if (privptr
->protocol
== CTC_PROTO_LINUX_TTY
)
2154 ctc_tty_setcarrier(dev
, 0);
2155 if (event
== DEV_EVENT_TXDOWN
)
2156 fsm_newstate(fi
, DEV_STATE_STARTWAIT_TX
);
2158 fsm_newstate(fi
, DEV_STATE_STARTWAIT_RX
);
2160 case DEV_STATE_STARTWAIT_RX
:
2161 if (event
== DEV_EVENT_TXDOWN
)
2162 fsm_newstate(fi
, DEV_STATE_STARTWAIT_RXTX
);
2164 case DEV_STATE_STARTWAIT_TX
:
2165 if (event
== DEV_EVENT_RXDOWN
)
2166 fsm_newstate(fi
, DEV_STATE_STARTWAIT_RXTX
);
2168 case DEV_STATE_STOPWAIT_RXTX
:
2169 if (event
== DEV_EVENT_TXDOWN
)
2170 fsm_newstate(fi
, DEV_STATE_STOPWAIT_RX
);
2172 fsm_newstate(fi
, DEV_STATE_STOPWAIT_TX
);
2174 case DEV_STATE_STOPWAIT_RX
:
2175 if (event
== DEV_EVENT_RXDOWN
)
2176 fsm_newstate(fi
, DEV_STATE_STOPPED
);
2178 case DEV_STATE_STOPWAIT_TX
:
2179 if (event
== DEV_EVENT_TXDOWN
)
2180 fsm_newstate(fi
, DEV_STATE_STOPPED
);
2185 static const fsm_node dev_fsm
[] = {
2186 {DEV_STATE_STOPPED
, DEV_EVENT_START
, dev_action_start
},
2188 {DEV_STATE_STOPWAIT_RXTX
, DEV_EVENT_START
, dev_action_start
},
2189 {DEV_STATE_STOPWAIT_RXTX
, DEV_EVENT_RXDOWN
, dev_action_chdown
},
2190 {DEV_STATE_STOPWAIT_RXTX
, DEV_EVENT_TXDOWN
, dev_action_chdown
},
2191 {DEV_STATE_STOPWAIT_RXTX
, DEV_EVENT_RESTART
, dev_action_restart
},
2193 {DEV_STATE_STOPWAIT_RX
, DEV_EVENT_START
, dev_action_start
},
2194 {DEV_STATE_STOPWAIT_RX
, DEV_EVENT_RXUP
, dev_action_chup
},
2195 {DEV_STATE_STOPWAIT_RX
, DEV_EVENT_TXUP
, dev_action_chup
},
2196 {DEV_STATE_STOPWAIT_RX
, DEV_EVENT_RXDOWN
, dev_action_chdown
},
2197 {DEV_STATE_STOPWAIT_RX
, DEV_EVENT_RESTART
, dev_action_restart
},
2199 {DEV_STATE_STOPWAIT_TX
, DEV_EVENT_START
, dev_action_start
},
2200 {DEV_STATE_STOPWAIT_TX
, DEV_EVENT_RXUP
, dev_action_chup
},
2201 {DEV_STATE_STOPWAIT_TX
, DEV_EVENT_TXUP
, dev_action_chup
},
2202 {DEV_STATE_STOPWAIT_TX
, DEV_EVENT_TXDOWN
, dev_action_chdown
},
2203 {DEV_STATE_STOPWAIT_TX
, DEV_EVENT_RESTART
, dev_action_restart
},
2205 {DEV_STATE_STARTWAIT_RXTX
, DEV_EVENT_STOP
, dev_action_stop
},
2206 {DEV_STATE_STARTWAIT_RXTX
, DEV_EVENT_RXUP
, dev_action_chup
},
2207 {DEV_STATE_STARTWAIT_RXTX
, DEV_EVENT_TXUP
, dev_action_chup
},
2208 {DEV_STATE_STARTWAIT_RXTX
, DEV_EVENT_RXDOWN
, dev_action_chdown
},
2209 {DEV_STATE_STARTWAIT_RXTX
, DEV_EVENT_TXDOWN
, dev_action_chdown
},
2210 {DEV_STATE_STARTWAIT_RXTX
, DEV_EVENT_RESTART
, dev_action_restart
},
2212 {DEV_STATE_STARTWAIT_TX
, DEV_EVENT_STOP
, dev_action_stop
},
2213 {DEV_STATE_STARTWAIT_TX
, DEV_EVENT_RXUP
, dev_action_chup
},
2214 {DEV_STATE_STARTWAIT_TX
, DEV_EVENT_TXUP
, dev_action_chup
},
2215 {DEV_STATE_STARTWAIT_TX
, DEV_EVENT_RXDOWN
, dev_action_chdown
},
2216 {DEV_STATE_STARTWAIT_TX
, DEV_EVENT_RESTART
, dev_action_restart
},
2218 {DEV_STATE_STARTWAIT_RX
, DEV_EVENT_STOP
, dev_action_stop
},
2219 {DEV_STATE_STARTWAIT_RX
, DEV_EVENT_RXUP
, dev_action_chup
},
2220 {DEV_STATE_STARTWAIT_RX
, DEV_EVENT_TXUP
, dev_action_chup
},
2221 {DEV_STATE_STARTWAIT_RX
, DEV_EVENT_TXDOWN
, dev_action_chdown
},
2222 {DEV_STATE_STARTWAIT_RX
, DEV_EVENT_RESTART
, dev_action_restart
},
2224 {DEV_STATE_RUNNING
, DEV_EVENT_STOP
, dev_action_stop
},
2225 {DEV_STATE_RUNNING
, DEV_EVENT_RXDOWN
, dev_action_chdown
},
2226 {DEV_STATE_RUNNING
, DEV_EVENT_TXDOWN
, dev_action_chdown
},
2227 {DEV_STATE_RUNNING
, DEV_EVENT_TXUP
, fsm_action_nop
},
2228 {DEV_STATE_RUNNING
, DEV_EVENT_RXUP
, fsm_action_nop
},
2229 {DEV_STATE_RUNNING
, DEV_EVENT_RESTART
, dev_action_restart
},
2232 static const int DEV_FSM_LEN
= sizeof (dev_fsm
) / sizeof (fsm_node
);
2235 * Transmit a packet.
2236 * This is a helper function for ctc_tx().
2238 * @param ch Channel to be used for sending.
2239 * @param skb Pointer to struct sk_buff of packet to send.
2240 * The linklevel header has already been set up
2243 * @return 0 on success, -ERRNO on failure. (Never fails.)
2246 transmit_skb(struct channel
*ch
, struct sk_buff
*skb
)
2248 unsigned long saveflags
;
2249 struct ll_header header
;
2252 if (fsm_getstate(ch
->fsm
) != CH_STATE_TXIDLE
) {
2253 int l
= skb
->len
+ LL_HEADER_LENGTH
;
2255 spin_lock_irqsave(&ch
->collect_lock
, saveflags
);
2256 if (ch
->collect_len
+ l
> ch
->max_bufsize
- 2)
2259 atomic_inc(&skb
->users
);
2261 header
.type
= skb
->protocol
;
2263 memcpy(skb_push(skb
, LL_HEADER_LENGTH
), &header
,
2265 skb_queue_tail(&ch
->collect_queue
, skb
);
2266 ch
->collect_len
+= l
;
2268 spin_unlock_irqrestore(&ch
->collect_lock
, saveflags
);
2272 struct sk_buff
*nskb
;
2276 * Protect skb against beeing free'd by upper
2279 atomic_inc(&skb
->users
);
2280 ch
->prof
.txlen
+= skb
->len
;
2281 header
.length
= skb
->len
+ LL_HEADER_LENGTH
;
2282 header
.type
= skb
->protocol
;
2284 memcpy(skb_push(skb
, LL_HEADER_LENGTH
), &header
,
2286 block_len
= skb
->len
+ 2;
2287 *((__u16
*) skb_push(skb
, 2)) = block_len
;
2290 * IDAL support in CTC is broken, so we have to
2291 * care about skb's above 2G ourselves.
2293 hi
= ((unsigned long) skb
->tail
+ LL_HEADER_LENGTH
) >> 31;
2295 nskb
= alloc_skb(skb
->len
, GFP_ATOMIC
| GFP_DMA
);
2297 atomic_dec(&skb
->users
);
2298 skb_pull(skb
, LL_HEADER_LENGTH
+ 2);
2301 memcpy(skb_put(nskb
, skb
->len
),
2302 skb
->data
, skb
->len
);
2303 atomic_inc(&nskb
->users
);
2304 atomic_dec(&skb
->users
);
2305 dev_kfree_skb_irq(skb
);
2310 ch
->ccw
[4].count
= block_len
;
2311 if (set_normalized_cda(&ch
->ccw
[4], skb
->data
)) {
2313 * idal allocation failed, try via copying to
2314 * trans_skb. trans_skb usually has a pre-allocated
2317 if (ctc_checkalloc_buffer(ch
, 1)) {
2319 * Remove our header. It gets added
2320 * again on retransmit.
2322 atomic_dec(&skb
->users
);
2323 skb_pull(skb
, LL_HEADER_LENGTH
+ 2);
2327 ch
->trans_skb
->tail
= ch
->trans_skb
->data
;
2328 ch
->trans_skb
->len
= 0;
2329 ch
->ccw
[1].count
= skb
->len
;
2330 memcpy(skb_put(ch
->trans_skb
, skb
->len
), skb
->data
,
2332 atomic_dec(&skb
->users
);
2333 dev_kfree_skb_irq(skb
);
2336 skb_queue_tail(&ch
->io_queue
, skb
);
2340 fsm_newstate(ch
->fsm
, CH_STATE_TX
);
2341 fsm_addtimer(&ch
->timer
, CTC_TIMEOUT_5SEC
, CH_EVENT_TIMER
, ch
);
2342 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
2343 ch
->prof
.send_stamp
= xtime
;
2344 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[ccw_idx
],
2345 (intparm_t
) ch
, 0xff, 0);
2346 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
2348 ch
->prof
.doios_single
++;
2350 fsm_deltimer(&ch
->timer
);
2351 ccw_check_return_code(ch
, rc
);
2353 skb_dequeue_tail(&ch
->io_queue
);
2355 * Remove our header. It gets added
2356 * again on retransmit.
2358 skb_pull(skb
, LL_HEADER_LENGTH
+ 2);
2361 struct net_device
*dev
= ch
->netdev
;
2362 struct ctc_priv
*privptr
= dev
->priv
;
2363 privptr
->stats
.tx_packets
++;
2364 privptr
->stats
.tx_bytes
+=
2365 skb
->len
- LL_HEADER_LENGTH
;
2374 * Interface API for upper network layers
2375 *****************************************************************************/
2378 * Open an interface.
2379 * Called from generic network layer when ifconfig up is run.
2381 * @param dev Pointer to interface struct.
2383 * @return 0 on success, -ERRNO on failure. (Never fails.)
2386 ctc_open(struct net_device
* dev
)
2389 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
, DEV_EVENT_START
, dev
);
2394 * Close an interface.
2395 * Called from generic network layer when ifconfig down is run.
2397 * @param dev Pointer to interface struct.
2399 * @return 0 on success, -ERRNO on failure. (Never fails.)
2402 ctc_close(struct net_device
* dev
)
2404 SET_DEVICE_START(dev
, 0);
2405 fsm_event(((struct ctc_priv
*) dev
->priv
)->fsm
, DEV_EVENT_STOP
, dev
);
2411 * Start transmission of a packet.
2412 * Called from generic network device layer.
2414 * @param skb Pointer to buffer containing the packet.
2415 * @param dev Pointer to interface struct.
2417 * @return 0 if packet consumed, !0 if packet rejected.
2418 * Note: If we return !0, then the packet is free'd by
2419 * the generic network layer.
2422 ctc_tx(struct sk_buff
*skb
, struct net_device
* dev
)
2425 struct ctc_priv
*privptr
= (struct ctc_priv
*) dev
->priv
;
2428 * Some sanity checks ...
2431 printk(KERN_WARNING
"%s: NULL sk_buff passed\n", dev
->name
);
2432 privptr
->stats
.tx_dropped
++;
2435 if (skb_headroom(skb
) < (LL_HEADER_LENGTH
+ 2)) {
2437 "%s: Got sk_buff with head room < %ld bytes\n",
2438 dev
->name
, LL_HEADER_LENGTH
+ 2);
2440 privptr
->stats
.tx_dropped
++;
2445 * If channels are not running, try to restart them
2446 * notify anybody about a link failure and throw
2449 if (fsm_getstate(privptr
->fsm
) != DEV_STATE_RUNNING
) {
2450 fsm_event(privptr
->fsm
, DEV_EVENT_START
, dev
);
2451 if (privptr
->protocol
== CTC_PROTO_LINUX_TTY
)
2453 dst_link_failure(skb
);
2455 privptr
->stats
.tx_dropped
++;
2456 privptr
->stats
.tx_errors
++;
2457 privptr
->stats
.tx_carrier_errors
++;
2461 if (ctc_test_and_set_busy(dev
))
2464 dev
->trans_start
= jiffies
;
2465 if (transmit_skb(privptr
->channel
[WRITE
], skb
) != 0)
2467 ctc_clear_busy(dev
);
2472 * Sets MTU of an interface.
2474 * @param dev Pointer to interface struct.
2475 * @param new_mtu The new MTU to use for this interface.
2477 * @return 0 on success, -EINVAL if MTU is out of valid range.
2478 * (valid range is 576 .. 65527). If VM is on the
2479 * remote side, maximum MTU is 32760, however this is
2480 * <em>not</em> checked here.
2483 ctc_change_mtu(struct net_device
* dev
, int new_mtu
)
2485 struct ctc_priv
*privptr
= (struct ctc_priv
*) dev
->priv
;
2487 if ((new_mtu
< 576) || (new_mtu
> 65527) ||
2488 (new_mtu
> (privptr
->channel
[READ
]->max_bufsize
-
2489 LL_HEADER_LENGTH
- 2)))
2492 dev
->hard_header_len
= LL_HEADER_LENGTH
+ 2;
2497 * Returns interface statistics of a device.
2499 * @param dev Pointer to interface struct.
2501 * @return Pointer to stats struct of this interface.
2503 static struct net_device_stats
*
2504 ctc_stats(struct net_device
* dev
)
2506 return &((struct ctc_priv
*) dev
->priv
)->stats
;
2512 #define CTRL_BUFSIZE 40
2515 buffer_show(struct device
*dev
, char *buf
)
2517 struct ctc_priv
*priv
;
2519 priv
= dev
->driver_data
;
2522 return sprintf(buf
, "%d\n",
2523 priv
->channel
[READ
]->max_bufsize
);
2527 buffer_write(struct device
*dev
, const char *buf
, size_t count
)
2529 struct ctc_priv
*priv
;
2530 struct net_device
*ndev
;
2533 priv
= dev
->driver_data
;
2536 ndev
= container_of((void *) priv
, struct net_device
, priv
);
2539 sscanf(buf
, "%u", &bs1
);
2541 if (bs1
> CTC_BUFSIZE_LIMIT
)
2543 if ((ndev
->flags
& IFF_RUNNING
) &&
2544 (bs1
< (ndev
->mtu
+ LL_HEADER_LENGTH
+ 2)))
2546 if (bs1
< (576 + LL_HEADER_LENGTH
+ 2))
2549 priv
->channel
[READ
]->max_bufsize
=
2550 priv
->channel
[WRITE
]->max_bufsize
= bs1
;
2551 if (!(ndev
->flags
& IFF_RUNNING
))
2552 ndev
->mtu
= bs1
- LL_HEADER_LENGTH
- 2;
2553 priv
->channel
[READ
]->flags
|= CHANNEL_FLAGS_BUFSIZE_CHANGED
;
2554 priv
->channel
[WRITE
]->flags
|= CHANNEL_FLAGS_BUFSIZE_CHANGED
;
2560 static DEVICE_ATTR(buffer
, 0644, buffer_show
, buffer_write
);
2563 ctc_add_attributes(struct device
*dev
)
2565 return device_create_file(dev
, &dev_attr_buffer
);
2570 ctc_remove_attributes(struct device
*dev
)
2572 device_remove_file(dev
, &dev_attr_buffer
);
2577 /* FIXME: This has to be converted to another interface, as we can only have one
2578 * value per file and can't have atomicity then */
2579 #define STATS_BUFSIZE 2048
2582 ctc_stat_open(struct inode
*inode
, struct file
*file
)
2584 file
->private_data
= kmalloc(STATS_BUFSIZE
, GFP_KERNEL
);
2585 if (file
->private_data
== NULL
)
2592 ctc_stat_close(struct inode
*inode
, struct file
*file
)
2594 kfree(file
->private_data
);
2600 ctc_stat_write(struct file
*file
, const char *buf
, size_t count
, loff_t
* off
)
2602 struct proc_dir_entry
*pde
= PDE(file
->f_dentry
->d_inode
);
2603 struct net_device
*dev
;
2604 struct ctc_priv
*privptr
;
2606 if (!(dev
= find_netdev_by_ino(pde
)))
2608 privptr
= (struct ctc_priv
*) dev
->priv
;
2609 privptr
->channel
[WRITE
]->prof
.maxmulti
= 0;
2610 privptr
->channel
[WRITE
]->prof
.maxcqueue
= 0;
2611 privptr
->channel
[WRITE
]->prof
.doios_single
= 0;
2612 privptr
->channel
[WRITE
]->prof
.doios_multi
= 0;
2613 privptr
->channel
[WRITE
]->prof
.txlen
= 0;
2614 privptr
->channel
[WRITE
]->prof
.tx_time
= 0;
2619 ctc_stat_read(struct file
*file
, char *buf
, size_t count
, loff_t
* off
)
2621 struct proc_dir_entry
*pde
= PDE(file
->f_dentry
->d_inode
);
2622 char *sbuf
= (char *) file
->private_data
;
2623 struct net_device
*dev
;
2624 struct ctc_priv
*privptr
;
2629 if (!(dev
= find_netdev_by_ino(pde
)))
2631 if (off
!= &file
->f_pos
)
2634 privptr
= (struct ctc_priv
*) dev
->priv
;
2636 if (file
->f_pos
== 0) {
2637 p
+= sprintf(p
, "Device FSM state: %s\n",
2638 fsm_getstate_str(privptr
->fsm
));
2639 p
+= sprintf(p
, "RX channel FSM state: %s\n",
2640 fsm_getstate_str(privptr
->channel
[READ
]->fsm
));
2641 p
+= sprintf(p
, "TX channel FSM state: %s\n",
2642 fsm_getstate_str(privptr
->channel
[WRITE
]->fsm
));
2643 p
+= sprintf(p
, "Max. TX buffer used: %ld\n",
2644 privptr
->channel
[WRITE
]->prof
.maxmulti
);
2645 p
+= sprintf(p
, "Max. chained SKBs: %ld\n",
2646 privptr
->channel
[WRITE
]->prof
.maxcqueue
);
2647 p
+= sprintf(p
, "TX single write ops: %ld\n",
2648 privptr
->channel
[WRITE
]->prof
.doios_single
);
2649 p
+= sprintf(p
, "TX multi write ops: %ld\n",
2650 privptr
->channel
[WRITE
]->prof
.doios_multi
);
2651 p
+= sprintf(p
, "Netto bytes written: %ld\n",
2652 privptr
->channel
[WRITE
]->prof
.txlen
);
2653 p
+= sprintf(p
, "Max. TX IO-time: %ld\n",
2654 privptr
->channel
[WRITE
]->prof
.tx_time
);
2658 if (file
->f_pos
< l
) {
2661 ret
= (count
> l
) ? l
: count
;
2662 if (copy_to_user(buf
, p
, ret
))
2669 static struct file_operations ctc_stat_fops
= {
2670 .read
= ctc_stat_read
,
2671 .write
= ctc_stat_write
,
2672 .open
= ctc_stat_open
,
2673 .release
= ctc_stat_close
,
2678 ctc_netdev_unregister(struct net_device
* dev
)
2680 struct ctc_priv
*privptr
;
2684 privptr
= (struct ctc_priv
*) dev
->priv
;
2685 if (privptr
->protocol
!= CTC_PROTO_LINUX_TTY
)
2686 unregister_netdev(dev
);
2688 ctc_tty_unregister_netdev(dev
);
2692 ctc_netdev_register(struct net_device
* dev
)
2694 struct ctc_priv
*privptr
= (struct ctc_priv
*) dev
->priv
;
2695 if (privptr
->protocol
!= CTC_PROTO_LINUX_TTY
)
2696 return register_netdev(dev
);
2698 return ctc_tty_register_netdev(dev
);
2702 ctc_free_netdevice(struct net_device
* dev
, int free_dev
)
2704 struct ctc_priv
*privptr
;
2707 privptr
= dev
->priv
;
2710 kfree_fsm(privptr
->fsm
);
2720 * Initialize everything of the net device except the name and the
2723 static struct net_device
*
2724 ctc_init_netdevice(struct net_device
* dev
, int alloc_device
,
2725 struct ctc_priv
*privptr
)
2731 dev
= kmalloc(sizeof (struct net_device
), GFP_KERNEL
);
2734 memset(dev
, 0, sizeof (struct net_device
));
2737 dev
->priv
= privptr
;
2738 privptr
->fsm
= init_fsm("ctcdev", dev_state_names
,
2739 dev_event_names
, NR_DEV_STATES
, NR_DEV_EVENTS
,
2740 dev_fsm
, DEV_FSM_LEN
, GFP_KERNEL
);
2741 if (privptr
->fsm
== NULL
) {
2746 fsm_newstate(privptr
->fsm
, DEV_STATE_STOPPED
);
2747 fsm_settimer(privptr
->fsm
, &privptr
->restart_timer
);
2748 dev
->mtu
= CTC_BUFSIZE_DEFAULT
- LL_HEADER_LENGTH
- 2;
2749 dev
->hard_start_xmit
= ctc_tx
;
2750 dev
->open
= ctc_open
;
2751 dev
->stop
= ctc_close
;
2752 dev
->get_stats
= ctc_stats
;
2753 dev
->change_mtu
= ctc_change_mtu
;
2754 dev
->hard_header_len
= LL_HEADER_LENGTH
+ 2;
2756 dev
->type
= ARPHRD_SLIP
;
2757 dev
->tx_queue_len
= 100;
2758 SET_DEVICE_START(dev
, 1);
2759 dev_init_buffers(dev
);
2760 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
2765 ctc_proto_show(struct device
*dev
, char *buf
)
2767 struct ctc_priv
*priv
;
2769 priv
= dev
->driver_data
;
2773 return sprintf(buf
, "%d\n", priv
->protocol
);
2777 ctc_proto_store(struct device
*dev
, const char *buf
, size_t count
)
2779 struct ctc_priv
*priv
;
2782 priv
= dev
->driver_data
;
2785 sscanf(buf
, "%u", &value
);
2786 /* TODO: sanity checks */
2787 priv
->protocol
= value
;
2792 static DEVICE_ATTR(protocol
, 0644, ctc_proto_show
, ctc_proto_store
);
2795 ctc_add_files(struct device
*dev
)
2797 return device_create_file(dev
, &dev_attr_protocol
);
2802 ctc_remove_files(struct device
*dev
)
2804 device_remove_file(dev
, &dev_attr_protocol
);
2809 * Add ctc specific attributes.
2810 * Add ctc private data.
2812 * @param cgdev pointer to ccwgroup_device just added
2814 * @returns 0 on success, !0 on failure.
2818 ctc_probe_device(struct ccwgroup_device
*cgdev
)
2820 struct ctc_priv
*priv
;
2823 if (!get_device(&cgdev
->dev
))
2826 priv
= kmalloc(sizeof (struct ctc_priv
), GFP_KERNEL
);
2828 printk(KERN_ERR
"%s: Out of memory\n", __func__
);
2829 put_device(&cgdev
->dev
);
2833 memset(priv
, 0, sizeof (struct ctc_priv
));
2834 rc
= ctc_add_files(&cgdev
->dev
);
2837 put_device(&cgdev
->dev
);
2841 cgdev
->cdev
[0]->handler
= ctc_irq_handler
;
2842 cgdev
->cdev
[1]->handler
= ctc_irq_handler
;
2843 cgdev
->dev
.driver_data
= priv
;
2844 cgdev
->cdev
[0]->dev
.driver_data
= priv
;
2845 cgdev
->cdev
[1]->dev
.driver_data
= priv
;
2846 snprintf(cgdev
->dev
.name
, DEVICE_NAME_SIZE
, "%s",
2847 cu3088_type
[cgdev
->cdev
[0]->id
.driver_info
]);
2854 * Setup an interface.
2856 * @param cgdev Device to be setup.
2858 * @returns 0 on success, !0 on failure.
2861 ctc_new_device(struct ccwgroup_device
*cgdev
)
2863 char read_id
[CTC_ID_SIZE
];
2864 char write_id
[CTC_ID_SIZE
];
2866 enum channel_types type
;
2867 struct ctc_priv
*privptr
;
2868 struct net_device
*dev
;
2870 privptr
= cgdev
->dev
.driver_data
;
2874 type
= get_channel_type(&cgdev
->cdev
[0]->id
);
2876 snprintf(read_id
, DEVICE_ID_SIZE
, "ch-%s", cgdev
->cdev
[0]->dev
.bus_id
);
2877 snprintf(write_id
, DEVICE_ID_SIZE
, "ch-%s", cgdev
->cdev
[1]->dev
.bus_id
);
2879 if (add_channel(cgdev
->cdev
[0], type
))
2881 if (add_channel(cgdev
->cdev
[1], type
))
2884 dev
= ctc_init_netdevice(NULL
, 1, privptr
);
2887 printk(KERN_WARNING
"ctc_init_netdevice failed\n");
2891 if (privptr
->protocol
== CTC_PROTO_LINUX_TTY
)
2892 snprintf(dev
->name
, 8, "ctctty%%d");
2894 snprintf(dev
->name
, 8, "ctc%%d");
2896 for (direction
= READ
; direction
<= WRITE
; direction
++) {
2897 privptr
->channel
[direction
] =
2898 channel_get(type
, direction
== READ
? read_id
: write_id
,
2900 if (privptr
->channel
[direction
] == NULL
) {
2901 if (direction
== WRITE
)
2902 channel_free(privptr
->channel
[READ
]);
2904 ctc_free_netdevice(dev
, 1);
2907 privptr
->channel
[direction
]->netdev
= dev
;
2908 privptr
->channel
[direction
]->protocol
= privptr
->protocol
;
2909 privptr
->channel
[direction
]->max_bufsize
= CTC_BUFSIZE_DEFAULT
;
2911 if (ctc_netdev_register(dev
) != 0) {
2912 ctc_free_netdevice(dev
, 1);
2916 ctc_add_attributes(&cgdev
->dev
);
2918 strncpy(privptr
->fsm
->name
, dev
->name
, sizeof (privptr
->fsm
->name
));
2923 "%s: read: %s, write: %s, proto: %d\n",
2924 dev
->name
, privptr
->channel
[READ
]->id
,
2925 privptr
->channel
[WRITE
]->id
, privptr
->protocol
);
2931 * Shutdown an interface.
2933 * @param cgdev Device to be shut down.
2935 * @returns 0 on success, !0 on failure.
2938 ctc_shutdown_device(struct ccwgroup_device
*cgdev
)
2940 struct ctc_priv
*priv
;
2941 struct net_device
*ndev
;
2944 priv
= cgdev
->dev
.driver_data
;
2947 ndev
= container_of((void *)priv
, struct net_device
, priv
);
2949 /* Close the device */
2951 ndev
->flags
&=~IFF_RUNNING
;
2953 ctc_remove_attributes(&cgdev
->dev
);
2955 channel_free(priv
->channel
[READ
]);
2956 channel_free(priv
->channel
[WRITE
]);
2958 ctc_netdev_unregister(ndev
);
2960 ctc_free_netdevice(ndev
, 1);
2962 kfree_fsm(priv
->fsm
);
2964 channel_remove(priv
->channel
[READ
]);
2965 channel_remove(priv
->channel
[WRITE
]);
2972 ctc_remove_device(struct ccwgroup_device
*cgdev
)
2974 struct ctc_priv
*priv
;
2976 priv
= cgdev
->dev
.driver_data
;
2980 ctc_remove_files(&cgdev
->dev
);
2981 cgdev
->dev
.driver_data
= NULL
;
2983 put_device(&cgdev
->dev
);
2987 static struct ccwgroup_driver ctc_group_driver
= {
2990 .driver_id
= 0xC3E3C3,
2991 .probe
= ctc_probe_device
,
2992 .remove
= ctc_remove_device
,
2993 .set_online
= ctc_new_device
,
2994 .set_offline
= ctc_shutdown_device
,
2998 * Module related routines
2999 *****************************************************************************/
3002 * Prepare to be unloaded. Free IRQ's and release all resources.
3003 * This is called just before this module is unloaded. It is
3004 * <em>not</em> called, if the usage count is !0, so we don't need to check
3010 unregister_cu3088_discipline(&ctc_group_driver
);
3012 printk(KERN_INFO
"CTC driver unloaded\n");
3016 * Initialize module.
3017 * This is called just after the module is loaded.
3019 * @return 0 on success, !0 on error.
3029 ret
= register_cu3088_discipline(&ctc_group_driver
);
3035 module_init(ctc_init
);
3036 module_exit(ctc_exit
);
3038 /* --- This is the END my friend --- */