2 * $Id: ctcmain.c,v 1.59 2004/04/21 17:10:13 ptiedem 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.59 $
45 #include <linux/module.h>
46 #include <linux/init.h>
47 #include <linux/kernel.h>
48 #include <linux/slab.h>
49 #include <linux/errno.h>
50 #include <linux/types.h>
51 #include <linux/interrupt.h>
52 #include <linux/timer.h>
53 #include <linux/sched.h>
55 #include <linux/signal.h>
56 #include <linux/string.h>
59 #include <linux/if_arp.h>
60 #include <linux/tcp.h>
61 #include <linux/skbuff.h>
62 #include <linux/ctype.h>
66 #include <asm/ccwdev.h>
67 #include <asm/ccwgroup.h>
68 #include <asm/bitops.h>
69 #include <asm/uaccess.h>
71 #include <asm/idals.h>
77 MODULE_AUTHOR("(C) 2000 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
78 MODULE_DESCRIPTION("Linux for S/390 CTC/Escon Driver");
79 MODULE_LICENSE("GPL");
82 * CCW commands, used in this driver.
84 #define CCW_CMD_WRITE 0x01
85 #define CCW_CMD_READ 0x02
86 #define CCW_CMD_SET_EXTENDED 0xc3
87 #define CCW_CMD_PREPARE 0xe3
89 #define CTC_PROTO_S390 0
90 #define CTC_PROTO_LINUX 1
91 #define CTC_PROTO_LINUX_TTY 2
92 #define CTC_PROTO_OS390 3
93 #define CTC_PROTO_MAX 3
95 #define CTC_BUFSIZE_LIMIT 65535
96 #define CTC_BUFSIZE_DEFAULT 32768
98 #define CTC_TIMEOUT_5SEC 5000
100 #define CTC_INITIAL_BLOCKLEN 2
105 #define CTC_ID_SIZE BUS_ID_SIZE+3
109 unsigned long maxmulti;
110 unsigned long maxcqueue;
111 unsigned long doios_single;
112 unsigned long doios_multi;
114 unsigned long tx_time;
115 struct timespec send_stamp;
119 * Definition of one channel
124 * Pointer to next channel in list.
126 struct channel *next;
127 char id[CTC_ID_SIZE];
128 struct ccw_device *cdev;
131 * Type of this channel.
132 * CTC/A or Escon for valid channels.
134 enum channel_types type;
137 * Misc. flags. See CHANNEL_FLAGS_... below
142 * The protocol of this channel
147 * I/O and irq related stuff
158 * Transmit/Receive buffer.
160 struct sk_buff *trans_skb;
163 * Universal I/O queue.
165 struct sk_buff_head io_queue;
168 * TX queue for collecting skb's during busy.
170 struct sk_buff_head collect_queue;
173 * Amount of data in collect_queue.
178 * spinlock for collect_queue and collect_len
180 spinlock_t collect_lock;
183 * Timer for detecting unresposive
189 * Retry counter for misc. operations.
194 * The finite state machine of this channel
199 * The corresponding net_device this channel
202 struct net_device *netdev;
204 struct ctc_profile prof;
206 unsigned char *trans_skb_data;
211 #define CHANNEL_FLAGS_READ 0
212 #define CHANNEL_FLAGS_WRITE 1
213 #define CHANNEL_FLAGS_INUSE 2
214 #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
215 #define CHANNEL_FLAGS_FAILED 8
216 #define CHANNEL_FLAGS_WAITIRQ 16
217 #define CHANNEL_FLAGS_RWMASK 1
218 #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
220 #define LOG_FLAG_ILLEGALPKT 1
221 #define LOG_FLAG_ILLEGALSIZE 2
222 #define LOG_FLAG_OVERRUN 4
223 #define LOG_FLAG_NOMEM 8
225 #define CTC_LOGLEVEL_INFO 1
226 #define CTC_LOGLEVEL_NOTICE 2
227 #define CTC_LOGLEVEL_WARN 4
228 #define CTC_LOGLEVEL_EMERG 8
229 #define CTC_LOGLEVEL_ERR 16
230 #define CTC_LOGLEVEL_DEBUG 32
231 #define CTC_LOGLEVEL_CRIT 64
233 #define CTC_LOGLEVEL_DEFAULT \
234 (CTC_LOGLEVEL_INFO | CTC_LOGLEVEL_NOTICE | CTC_LOGLEVEL_WARN | CTC_LOGLEVEL_CRIT)
236 #define CTC_LOGLEVEL_MAX ((CTC_LOGLEVEL_CRIT<<1)-1)
238 static int loglevel = CTC_LOGLEVEL_DEFAULT;
240 #define ctc_pr_debug(fmt, arg...) \
241 do { if (loglevel & CTC_LOGLEVEL_DEBUG) printk(KERN_DEBUG fmt,##arg); } while (0)
243 #define ctc_pr_info(fmt, arg...) \
244 do { if (loglevel & CTC_LOGLEVEL_INFO) printk(KERN_INFO fmt,##arg); } while (0)
246 #define ctc_pr_notice(fmt, arg...) \
247 do { if (loglevel & CTC_LOGLEVEL_NOTICE) printk(KERN_NOTICE fmt,##arg); } while (0)
249 #define ctc_pr_warn(fmt, arg...) \
250 do { if (loglevel & CTC_LOGLEVEL_WARN) printk(KERN_WARNING fmt,##arg); } while (0)
252 #define ctc_pr_emerg(fmt, arg...) \
253 do { if (loglevel & CTC_LOGLEVEL_EMERG) printk(KERN_EMERG fmt,##arg); } while (0)
255 #define ctc_pr_err(fmt, arg...) \
256 do { if (loglevel & CTC_LOGLEVEL_ERR) printk(KERN_ERR fmt,##arg); } while (0)
258 #define ctc_pr_crit(fmt, arg...) \
259 do { if (loglevel & CTC_LOGLEVEL_CRIT) printk(KERN_CRIT fmt,##arg); } while (0)
262 * Linked list of all detected channels.
264 static struct channel *channels = NULL;
267 struct net_device_stats stats;
270 * The finite state machine of this interface.
274 * The protocol of this device
278 * Timer for restarting after I/O Errors
280 fsm_timer restart_timer;
282 struct channel *channel[2];
286 * Definition of our link level header.
293 #define LL_HEADER_LENGTH (sizeof(struct ll_header))
296 * Compatibility macros for busy handling
297 * of network devices.
299 static __inline__ void
300 ctc_clear_busy(struct net_device * dev)
302 clear_bit(0, &(((struct ctc_priv *) dev->priv)->tbusy));
303 if (((struct ctc_priv *)dev->priv)->protocol != CTC_PROTO_LINUX_TTY)
304 netif_wake_queue(dev);
307 static __inline__ int
308 ctc_test_and_set_busy(struct net_device * dev)
310 if (((struct ctc_priv *)dev->priv)->protocol != CTC_PROTO_LINUX_TTY)
311 netif_stop_queue(dev);
312 return test_and_set_bit(0, &((struct ctc_priv *) dev->priv)->tbusy);
321 static int printed = 0;
322 char vbuf[] = "$Revision: 1.59 $";
323 char *version = vbuf;
327 if ((version = strchr(version, ':'))) {
328 char *p = strchr(version + 1, '$');
333 printk(KERN_INFO "CTC driver Version%s"
335 " (DEBUG-VERSION, " __DATE__ __TIME__ ")"
337 " initialized\n", version);
342 * Return type of a detected device.
344 static enum channel_types
345 get_channel_type(struct ccw_device_id *id)
347 enum channel_types type = (enum channel_types) id->driver_info;
349 if (type == channel_type_ficon)
350 type = channel_type_escon;
356 * States of the interface statemachine.
360 DEV_STATE_STARTWAIT_RXTX,
361 DEV_STATE_STARTWAIT_RX,
362 DEV_STATE_STARTWAIT_TX,
363 DEV_STATE_STOPWAIT_RXTX,
364 DEV_STATE_STOPWAIT_RX,
365 DEV_STATE_STOPWAIT_TX,
368 * MUST be always the last element!!
373 static const char *dev_state_names[] = {
385 * Events of the interface statemachine.
396 * MUST be always the last element!!
401 static const char *dev_event_names[] = {
412 * Events of the channel statemachine
416 * Events, representing return code of
417 * I/O operations (ccw_device_start, ccw_device_halt et al.)
430 * Events, representing unit-check
434 CH_EVENT_UC_TXTIMEOUT,
435 CH_EVENT_UC_TXPARITY,
437 CH_EVENT_UC_RXPARITY,
442 * Events, representing subchannel-check
447 * Events, representing machine checks
453 * Event, representing normal IRQ
459 * Event, representing timer expiry.
464 * Events, representing commands from upper levels.
470 * MUST be always the last element!!
475 static const char *ch_event_names[] = {
476 "ccw_device success",
480 "ccw_device unknown",
482 "Status ATTN & BUSY",
486 "Unit check remote reset",
487 "Unit check remote system reset",
488 "Unit check TX timeout",
489 "Unit check TX parity",
490 "Unit check Hardware failure",
491 "Unit check RX parity",
493 "Unit check Unknown",
495 "SubChannel check Unknown",
497 "Machine check failure",
498 "Machine check operational",
510 * States of the channel statemachine.
514 * Channel not assigned to any device,
515 * initial state, direction invalid
520 * Channel assigned but not operating
539 * MUST be always the last element!!
544 static const char *ch_state_names[] = {
565 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
567 * @param skb The sk_buff to dump.
568 * @param offset Offset relative to skb-data, where to start the dump.
571 ctc_dump_skb(struct sk_buff *skb, int offset)
573 unsigned char *p = skb->data;
575 struct ll_header *header;
578 if (!(loglevel & CTC_LOGLEVEL_DEBUG))
583 header = (struct ll_header *) p;
586 printk(KERN_DEBUG "dump:\n");
587 printk(KERN_DEBUG "blocklen=%d %04x\n", bl, bl);
589 printk(KERN_DEBUG "h->length=%d %04x\n", header->length,
591 printk(KERN_DEBUG "h->type=%04x\n", header->type);
592 printk(KERN_DEBUG "h->unused=%04x\n", header->unused);
595 printk(KERN_DEBUG "data: ");
596 for (i = 0; i < bl; i++)
597 printk("%02x%s", *p++, (i % 16) ? " " : "\n<7>");
602 ctc_dump_skb(struct sk_buff *skb, int offset)
608 * Unpack a just received skb and hand it over to
611 * @param ch The channel where this skb has been received.
612 * @param pskb The received skb.
614 static __inline__ void
615 ctc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
617 struct net_device *dev = ch->netdev;
618 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
620 __u16 len = *((__u16 *) pskb->data);
621 skb_put(pskb, 2 + LL_HEADER_LENGTH);
624 pskb->ip_summed = CHECKSUM_UNNECESSARY;
627 struct ll_header *header = (struct ll_header *) pskb->data;
629 skb_pull(pskb, LL_HEADER_LENGTH);
630 if ((ch->protocol == CTC_PROTO_S390) &&
631 (header->type != ETH_P_IP)) {
634 if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
637 * Check packet type only if we stick strictly
638 * to S/390's protocol of OS390. This only
639 * supports IP. Otherwise allow any packet
643 "%s Illegal packet type 0x%04x received, dropping\n",
644 dev->name, header->type);
645 ch->logflags |= LOG_FLAG_ILLEGALPKT;
650 ctc_dump_skb(pskb, -6);
652 privptr->stats.rx_dropped++;
653 privptr->stats.rx_frame_errors++;
656 pskb->protocol = ntohs(header->type);
657 if (header->length <= LL_HEADER_LENGTH) {
659 if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
662 "%s Illegal packet size %d "
663 "received (MTU=%d blocklen=%d), "
664 "dropping\n", dev->name, header->length,
666 ch->logflags |= LOG_FLAG_ILLEGALSIZE;
671 ctc_dump_skb(pskb, -6);
673 privptr->stats.rx_dropped++;
674 privptr->stats.rx_length_errors++;
677 header->length -= LL_HEADER_LENGTH;
678 len -= LL_HEADER_LENGTH;
679 if ((header->length > skb_tailroom(pskb)) ||
680 (header->length > len)) {
682 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
685 "%s Illegal packet size %d "
686 "(beyond the end of received data), "
687 "dropping\n", dev->name, header->length);
688 ch->logflags |= LOG_FLAG_OVERRUN;
693 ctc_dump_skb(pskb, -6);
695 privptr->stats.rx_dropped++;
696 privptr->stats.rx_length_errors++;
699 skb_put(pskb, header->length);
700 pskb->mac.raw = pskb->data;
701 len -= header->length;
702 skb = dev_alloc_skb(pskb->len);
705 if (!(ch->logflags & LOG_FLAG_NOMEM)) {
708 "%s Out of memory in ctc_unpack_skb\n",
710 ch->logflags |= LOG_FLAG_NOMEM;
714 privptr->stats.rx_dropped++;
717 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
718 skb->mac.raw = skb->data;
719 skb->dev = pskb->dev;
720 skb->protocol = pskb->protocol;
721 pskb->ip_summed = CHECKSUM_UNNECESSARY;
722 if (ch->protocol == CTC_PROTO_LINUX_TTY)
723 ctc_tty_netif_rx(skb);
727 * Successful rx; reset logflags
730 dev->last_rx = jiffies;
731 privptr->stats.rx_packets++;
732 privptr->stats.rx_bytes += skb->len;
734 skb_pull(pskb, header->length);
735 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
737 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
740 "%s Overrun in ctc_unpack_skb\n",
742 ch->logflags |= LOG_FLAG_OVERRUN;
748 skb_put(pskb, LL_HEADER_LENGTH);
754 * Check return code of a preceeding ccw_device call, halt_IO etc...
756 * @param ch The channel, the error belongs to.
757 * @param return_code The error code to inspect.
760 ccw_check_return_code(struct channel *ch, int return_code, char *msg)
762 switch (return_code) {
764 fsm_event(ch->fsm, CH_EVENT_IO_SUCCESS, ch);
767 ctc_pr_warn("%s (%s): Busy !\n", ch->id, msg);
768 fsm_event(ch->fsm, CH_EVENT_IO_EBUSY, ch);
771 ctc_pr_emerg("%s (%s): Invalid device called for IO\n",
773 fsm_event(ch->fsm, CH_EVENT_IO_ENODEV, ch);
776 ctc_pr_emerg("%s (%s): Status pending... \n",
778 fsm_event(ch->fsm, CH_EVENT_IO_EIO, ch);
781 ctc_pr_emerg("%s (%s): Unknown error in do_IO %04x\n",
782 ch->id, msg, return_code);
783 fsm_event(ch->fsm, CH_EVENT_IO_UNKNOWN, ch);
788 * Check sense of a unit check.
790 * @param ch The channel, the sense code belongs to.
791 * @param sense The sense code to inspect.
794 ccw_unit_check(struct channel *ch, unsigned char sense)
796 if (sense & SNS0_INTERVENTION_REQ) {
798 if (ch->protocol != CTC_PROTO_LINUX_TTY)
799 ctc_pr_debug("%s: Interface disc. or Sel. reset "
800 "(remote)\n", ch->id);
801 fsm_event(ch->fsm, CH_EVENT_UC_RCRESET, ch);
803 ctc_pr_debug("%s: System reset (remote)\n", ch->id);
804 fsm_event(ch->fsm, CH_EVENT_UC_RSRESET, ch);
806 } else if (sense & SNS0_EQUIPMENT_CHECK) {
807 if (sense & SNS0_BUS_OUT_CHECK) {
808 ctc_pr_warn("%s: Hardware malfunction (remote)\n",
810 fsm_event(ch->fsm, CH_EVENT_UC_HWFAIL, ch);
812 ctc_pr_warn("%s: Read-data parity error (remote)\n",
814 fsm_event(ch->fsm, CH_EVENT_UC_RXPARITY, ch);
816 } else if (sense & SNS0_BUS_OUT_CHECK) {
818 ctc_pr_warn("%s: Data-streaming timeout)\n", ch->id);
819 fsm_event(ch->fsm, CH_EVENT_UC_TXTIMEOUT, ch);
821 ctc_pr_warn("%s: Data-transfer parity error\n", ch->id);
822 fsm_event(ch->fsm, CH_EVENT_UC_TXPARITY, ch);
824 } else if (sense & SNS0_CMD_REJECT) {
825 ctc_pr_warn("%s: Command reject\n", ch->id);
826 } else if (sense == 0) {
827 ctc_pr_debug("%s: Unit check ZERO\n", ch->id);
828 fsm_event(ch->fsm, CH_EVENT_UC_ZERO, ch);
830 ctc_pr_warn("%s: Unit Check with sense code: %02x\n",
832 fsm_event(ch->fsm, CH_EVENT_UC_UNKNOWN, ch);
837 ctc_purge_skb_queue(struct sk_buff_head *q)
841 while ((skb = skb_dequeue(q))) {
842 atomic_dec(&skb->users);
843 dev_kfree_skb_irq(skb);
847 static __inline__ int
848 ctc_checkalloc_buffer(struct channel *ch, int warn)
850 if ((ch->trans_skb == NULL) ||
851 (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED)) {
852 if (ch->trans_skb != NULL)
853 dev_kfree_skb(ch->trans_skb);
854 clear_normalized_cda(&ch->ccw[1]);
855 ch->trans_skb = __dev_alloc_skb(ch->max_bufsize,
856 GFP_ATOMIC | GFP_DMA);
857 if (ch->trans_skb == NULL) {
860 "%s: Couldn't alloc %s trans_skb\n",
862 (CHANNEL_DIRECTION(ch->flags) == READ) ?
866 ch->ccw[1].count = ch->max_bufsize;
867 if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
868 dev_kfree_skb(ch->trans_skb);
869 ch->trans_skb = NULL;
872 "%s: set_normalized_cda for %s "
873 "trans_skb failed, dropping packets\n",
875 (CHANNEL_DIRECTION(ch->flags) == READ) ?
879 ch->ccw[1].count = 0;
880 ch->trans_skb_data = ch->trans_skb->data;
881 ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
887 * Dummy NOP action for statemachines
890 fsm_action_nop(fsm_instance * fi, int event, void *arg)
895 * Actions for channel - statemachines.
896 *****************************************************************************/
899 * Normal data has been send. Free the corresponding
900 * skb (it's in io_queue), reset dev->tbusy and
901 * revert to idle state.
903 * @param fi An instance of a channel statemachine.
904 * @param event The event, just happened.
905 * @param arg Generic pointer, casted from channel * upon call.
908 ch_action_txdone(fsm_instance * fi, int event, void *arg)
910 struct channel *ch = (struct channel *) arg;
911 struct net_device *dev = ch->netdev;
912 struct ctc_priv *privptr = dev->priv;
917 struct timespec done_stamp = xtime;
918 unsigned long duration =
919 (done_stamp.tv_sec - ch->prof.send_stamp.tv_sec) * 1000000 +
920 (done_stamp.tv_nsec - ch->prof.send_stamp.tv_nsec) / 1000;
921 if (duration > ch->prof.tx_time)
922 ch->prof.tx_time = duration;
924 if (ch->irb->scsw.count != 0)
925 ctc_pr_debug("%s: TX not complete, remaining %d bytes\n",
926 dev->name, ch->irb->scsw.count);
927 fsm_deltimer(&ch->timer);
928 while ((skb = skb_dequeue(&ch->io_queue))) {
929 privptr->stats.tx_packets++;
930 privptr->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
932 privptr->stats.tx_bytes += 2;
935 atomic_dec(&skb->users);
936 dev_kfree_skb_irq(skb);
938 spin_lock(&ch->collect_lock);
939 clear_normalized_cda(&ch->ccw[4]);
940 if (ch->collect_len > 0) {
943 if (ctc_checkalloc_buffer(ch, 1)) {
944 spin_unlock(&ch->collect_lock);
947 ch->trans_skb->tail = ch->trans_skb->data = ch->trans_skb_data;
948 ch->trans_skb->len = 0;
949 if (ch->prof.maxmulti < (ch->collect_len + 2))
950 ch->prof.maxmulti = ch->collect_len + 2;
951 if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
952 ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
953 *((__u16 *) skb_put(ch->trans_skb, 2)) = ch->collect_len + 2;
955 while ((skb = skb_dequeue(&ch->collect_queue))) {
956 memcpy(skb_put(ch->trans_skb, skb->len), skb->data,
958 privptr->stats.tx_packets++;
959 privptr->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
960 atomic_dec(&skb->users);
961 dev_kfree_skb_irq(skb);
965 spin_unlock(&ch->collect_lock);
966 ch->ccw[1].count = ch->trans_skb->len;
967 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
968 ch->prof.send_stamp = xtime;
969 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
970 (unsigned long) ch, 0xff, 0);
971 ch->prof.doios_multi++;
973 privptr->stats.tx_dropped += i;
974 privptr->stats.tx_errors += i;
975 fsm_deltimer(&ch->timer);
976 ccw_check_return_code(ch, rc, "chained TX");
979 spin_unlock(&ch->collect_lock);
980 fsm_newstate(fi, CH_STATE_TXIDLE);
986 * Initial data is sent.
987 * Notify device statemachine that we are up and
990 * @param fi An instance of a channel statemachine.
991 * @param event The event, just happened.
992 * @param arg Generic pointer, casted from channel * upon call.
995 ch_action_txidle(fsm_instance * fi, int event, void *arg)
997 struct channel *ch = (struct channel *) arg;
999 fsm_deltimer(&ch->timer);
1000 fsm_newstate(fi, CH_STATE_TXIDLE);
1001 fsm_event(((struct ctc_priv *) ch->netdev->priv)->fsm, DEV_EVENT_TXUP,
1006 * Got normal data, check for sanity, queue it up, allocate new buffer
1007 * trigger bottom half, and initiate next read.
1009 * @param fi An instance of a channel statemachine.
1010 * @param event The event, just happened.
1011 * @param arg Generic pointer, casted from channel * upon call.
1014 ch_action_rx(fsm_instance * fi, int event, void *arg)
1016 struct channel *ch = (struct channel *) arg;
1017 struct net_device *dev = ch->netdev;
1018 struct ctc_priv *privptr = dev->priv;
1019 int len = ch->max_bufsize - ch->irb->scsw.count;
1020 struct sk_buff *skb = ch->trans_skb;
1021 __u16 block_len = *((__u16 *) skb->data);
1025 fsm_deltimer(&ch->timer);
1027 ctc_pr_debug("%s: got packet with length %d < 8\n",
1029 privptr->stats.rx_dropped++;
1030 privptr->stats.rx_length_errors++;
1033 if (len > ch->max_bufsize) {
1034 ctc_pr_debug("%s: got packet with length %d > %d\n",
1035 dev->name, len, ch->max_bufsize);
1036 privptr->stats.rx_dropped++;
1037 privptr->stats.rx_length_errors++;
1042 * VM TCP seems to have a bug sending 2 trailing bytes of garbage.
1044 switch (ch->protocol) {
1045 case CTC_PROTO_S390:
1046 case CTC_PROTO_OS390:
1047 check_len = block_len + 2;
1050 check_len = block_len;
1053 if ((len < block_len) || (len > check_len)) {
1054 ctc_pr_debug("%s: got block length %d != rx length %d\n",
1055 dev->name, block_len, len);
1057 ctc_dump_skb(skb, 0);
1059 *((__u16 *) skb->data) = len;
1060 privptr->stats.rx_dropped++;
1061 privptr->stats.rx_length_errors++;
1065 if (block_len > 0) {
1066 *((__u16 *) skb->data) = block_len;
1067 ctc_unpack_skb(ch, skb);
1070 skb->data = skb->tail = ch->trans_skb_data;
1072 if (ctc_checkalloc_buffer(ch, 1))
1074 ch->ccw[1].count = ch->max_bufsize;
1075 rc = ccw_device_start(ch->cdev, &ch->ccw[0], (unsigned long) ch, 0xff, 0);
1077 ccw_check_return_code(ch, rc, "normal RX");
1080 static void ch_action_rxidle(fsm_instance * fi, int event, void *arg);
1083 * Initialize connection by sending a __u16 of value 0.
1085 * @param fi An instance of a channel statemachine.
1086 * @param event The event, just happened.
1087 * @param arg Generic pointer, casted from channel * upon call.
1090 ch_action_firstio(fsm_instance * fi, int event, void *arg)
1092 struct channel *ch = (struct channel *) arg;
1095 if (fsm_getstate(fi) == CH_STATE_TXIDLE)
1096 ctc_pr_debug("%s: remote side issued READ?, init ...\n", ch->id);
1097 fsm_deltimer(&ch->timer);
1098 if (ctc_checkalloc_buffer(ch, 1))
1100 if ((fsm_getstate(fi) == CH_STATE_SETUPWAIT) &&
1101 (ch->protocol == CTC_PROTO_OS390)) {
1102 /* OS/390 resp. z/OS */
1103 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1104 *((__u16 *) ch->trans_skb->data) = CTC_INITIAL_BLOCKLEN;
1105 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC,
1106 CH_EVENT_TIMER, ch);
1107 ch_action_rxidle(fi, event, arg);
1109 struct net_device *dev = ch->netdev;
1110 fsm_newstate(fi, CH_STATE_TXIDLE);
1111 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1112 DEV_EVENT_TXUP, dev);
1118 * Don´t setup a timer for receiving the initial RX frame
1119 * if in compatibility mode, since VM TCP delays the initial
1120 * frame until it has some data to send.
1122 if ((CHANNEL_DIRECTION(ch->flags) == WRITE) ||
1123 (ch->protocol != CTC_PROTO_S390))
1124 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1126 *((__u16 *) ch->trans_skb->data) = CTC_INITIAL_BLOCKLEN;
1127 ch->ccw[1].count = 2; /* Transfer only length */
1129 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ)
1130 ? CH_STATE_RXINIT : CH_STATE_TXINIT);
1131 rc = ccw_device_start(ch->cdev, &ch->ccw[0], (unsigned long) ch, 0xff, 0);
1133 fsm_deltimer(&ch->timer);
1134 fsm_newstate(fi, CH_STATE_SETUPWAIT);
1135 ccw_check_return_code(ch, rc, "init IO");
1138 * If in compatibility mode since we don´t setup a timer, we
1139 * also signal RX channel up immediately. This enables us
1140 * to send packets early which in turn usually triggers some
1141 * reply from VM TCP which brings up the RX channel to it´s
1144 if ((CHANNEL_DIRECTION(ch->flags) == READ) &&
1145 (ch->protocol == CTC_PROTO_S390)) {
1146 struct net_device *dev = ch->netdev;
1147 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_RXUP,
1153 * Got initial data, check it. If OK,
1154 * notify device statemachine that we are up and
1157 * @param fi An instance of a channel statemachine.
1158 * @param event The event, just happened.
1159 * @param arg Generic pointer, casted from channel * upon call.
1162 ch_action_rxidle(fsm_instance * fi, int event, void *arg)
1164 struct channel *ch = (struct channel *) arg;
1165 struct net_device *dev = ch->netdev;
1169 fsm_deltimer(&ch->timer);
1170 buflen = *((__u16 *) ch->trans_skb->data);
1172 ctc_pr_debug("%s: Initial RX count %d\n", dev->name, buflen);
1174 if (buflen >= CTC_INITIAL_BLOCKLEN) {
1175 if (ctc_checkalloc_buffer(ch, 1))
1177 ch->ccw[1].count = ch->max_bufsize;
1178 fsm_newstate(fi, CH_STATE_RXIDLE);
1179 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
1180 (unsigned long) ch, 0xff, 0);
1182 fsm_newstate(fi, CH_STATE_RXINIT);
1183 ccw_check_return_code(ch, rc, "initial RX");
1185 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1186 DEV_EVENT_RXUP, dev);
1188 ctc_pr_debug("%s: Initial RX count %d not %d\n",
1189 dev->name, buflen, CTC_INITIAL_BLOCKLEN);
1190 ch_action_firstio(fi, event, arg);
1195 * Set channel into extended mode.
1197 * @param fi An instance of a channel statemachine.
1198 * @param event The event, just happened.
1199 * @param arg Generic pointer, casted from channel * upon call.
1202 ch_action_setmode(fsm_instance * fi, int event, void *arg)
1204 struct channel *ch = (struct channel *) arg;
1206 unsigned long saveflags;
1208 fsm_deltimer(&ch->timer);
1209 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1210 fsm_newstate(fi, CH_STATE_SETUPWAIT);
1211 if (event == CH_EVENT_TIMER)
1212 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1213 rc = ccw_device_start(ch->cdev, &ch->ccw[6], (unsigned long) ch, 0xff, 0);
1214 if (event == CH_EVENT_TIMER)
1215 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1217 fsm_deltimer(&ch->timer);
1218 fsm_newstate(fi, CH_STATE_STARTWAIT);
1219 ccw_check_return_code(ch, rc, "set Mode");
1227 * @param fi An instance of a channel statemachine.
1228 * @param event The event, just happened.
1229 * @param arg Generic pointer, casted from channel * upon call.
1232 ch_action_start(fsm_instance * fi, int event, void *arg)
1234 struct channel *ch = (struct channel *) arg;
1235 unsigned long saveflags;
1237 struct net_device *dev;
1240 ctc_pr_warn("ch_action_start ch=NULL\n");
1243 if (ch->netdev == NULL) {
1244 ctc_pr_warn("ch_action_start dev=NULL, id=%s\n", ch->id);
1250 ctc_pr_debug("%s: %s channel start\n", dev->name,
1251 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
1254 if (ch->trans_skb != NULL) {
1255 clear_normalized_cda(&ch->ccw[1]);
1256 dev_kfree_skb(ch->trans_skb);
1257 ch->trans_skb = NULL;
1259 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1260 ch->ccw[1].cmd_code = CCW_CMD_READ;
1261 ch->ccw[1].flags = CCW_FLAG_SLI;
1262 ch->ccw[1].count = 0;
1264 ch->ccw[1].cmd_code = CCW_CMD_WRITE;
1265 ch->ccw[1].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1266 ch->ccw[1].count = 0;
1268 if (ctc_checkalloc_buffer(ch, 0)) {
1270 "%s: Could not allocate %s trans_skb, delaying "
1271 "allocation until first transfer\n",
1273 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
1276 ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
1277 ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1278 ch->ccw[0].count = 0;
1280 ch->ccw[2].cmd_code = CCW_CMD_NOOP; /* jointed CE + DE */
1281 ch->ccw[2].flags = CCW_FLAG_SLI;
1282 ch->ccw[2].count = 0;
1284 memcpy(&ch->ccw[3], &ch->ccw[0], sizeof (struct ccw1) * 3);
1286 ch->ccw[4].flags &= ~CCW_FLAG_IDA;
1288 fsm_newstate(fi, CH_STATE_STARTWAIT);
1289 fsm_addtimer(&ch->timer, 1000, CH_EVENT_TIMER, ch);
1290 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1291 rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1292 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1295 fsm_deltimer(&ch->timer);
1296 ccw_check_return_code(ch, rc, "initial HaltIO");
1299 ctc_pr_debug("ctc: %s(): leaving\n", __func__);
1304 * Shutdown a channel.
1306 * @param fi An instance of a channel statemachine.
1307 * @param event The event, just happened.
1308 * @param arg Generic pointer, casted from channel * upon call.
1311 ch_action_haltio(fsm_instance * fi, int event, void *arg)
1313 struct channel *ch = (struct channel *) arg;
1314 unsigned long saveflags;
1318 fsm_deltimer(&ch->timer);
1319 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1320 if (event == CH_EVENT_STOP)
1321 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1322 oldstate = fsm_getstate(fi);
1323 fsm_newstate(fi, CH_STATE_TERM);
1324 rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1325 if (event == CH_EVENT_STOP)
1326 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1329 fsm_deltimer(&ch->timer);
1330 fsm_newstate(fi, oldstate);
1332 ccw_check_return_code(ch, rc, "HaltIO in ch_action_haltio");
1337 * A channel has successfully been halted.
1338 * Cleanup it's queue and notify interface statemachine.
1340 * @param fi An instance of a channel statemachine.
1341 * @param event The event, just happened.
1342 * @param arg Generic pointer, casted from channel * upon call.
1345 ch_action_stopped(fsm_instance * fi, int event, void *arg)
1347 struct channel *ch = (struct channel *) arg;
1348 struct net_device *dev = ch->netdev;
1350 fsm_deltimer(&ch->timer);
1351 fsm_newstate(fi, CH_STATE_STOPPED);
1352 if (ch->trans_skb != NULL) {
1353 clear_normalized_cda(&ch->ccw[1]);
1354 dev_kfree_skb(ch->trans_skb);
1355 ch->trans_skb = NULL;
1357 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1358 skb_queue_purge(&ch->io_queue);
1359 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1360 DEV_EVENT_RXDOWN, dev);
1362 ctc_purge_skb_queue(&ch->io_queue);
1363 spin_lock(&ch->collect_lock);
1364 ctc_purge_skb_queue(&ch->collect_queue);
1365 ch->collect_len = 0;
1366 spin_unlock(&ch->collect_lock);
1367 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1368 DEV_EVENT_TXDOWN, dev);
1373 * A stop command from device statemachine arrived and we are in
1374 * not operational mode. Set state to stopped.
1376 * @param fi An instance of a channel statemachine.
1377 * @param event The event, just happened.
1378 * @param arg Generic pointer, casted from channel * upon call.
1381 ch_action_stop(fsm_instance * fi, int event, void *arg)
1383 fsm_newstate(fi, CH_STATE_STOPPED);
1387 * A machine check for no path, not operational status or gone device has
1389 * Cleanup queue and notify interface statemachine.
1391 * @param fi An instance of a channel statemachine.
1392 * @param event The event, just happened.
1393 * @param arg Generic pointer, casted from channel * upon call.
1396 ch_action_fail(fsm_instance * fi, int event, void *arg)
1398 struct channel *ch = (struct channel *) arg;
1399 struct net_device *dev = ch->netdev;
1401 fsm_deltimer(&ch->timer);
1402 fsm_newstate(fi, CH_STATE_NOTOP);
1403 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1404 skb_queue_purge(&ch->io_queue);
1405 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1406 DEV_EVENT_RXDOWN, dev);
1408 ctc_purge_skb_queue(&ch->io_queue);
1409 spin_lock(&ch->collect_lock);
1410 ctc_purge_skb_queue(&ch->collect_queue);
1411 ch->collect_len = 0;
1412 spin_unlock(&ch->collect_lock);
1413 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1414 DEV_EVENT_TXDOWN, dev);
1419 * Handle error during setup of channel.
1421 * @param fi An instance of a channel statemachine.
1422 * @param event The event, just happened.
1423 * @param arg Generic pointer, casted from channel * upon call.
1426 ch_action_setuperr(fsm_instance * fi, int event, void *arg)
1428 struct channel *ch = (struct channel *) arg;
1429 struct net_device *dev = ch->netdev;
1432 * Special case: Got UC_RCRESET on setmode.
1433 * This means that remote side isn't setup. In this case
1434 * simply retry after some 10 secs...
1436 if ((fsm_getstate(fi) == CH_STATE_SETUPWAIT) &&
1437 ((event == CH_EVENT_UC_RCRESET) ||
1438 (event == CH_EVENT_UC_RSRESET))) {
1439 fsm_newstate(fi, CH_STATE_STARTRETRY);
1440 fsm_deltimer(&ch->timer);
1441 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1442 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1443 int rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1445 ccw_check_return_code(
1446 ch, rc, "HaltIO in ch_action_setuperr");
1451 ctc_pr_debug("%s: Error %s during %s channel setup state=%s\n",
1452 dev->name, ch_event_names[event],
1453 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX",
1454 fsm_getstate_str(fi));
1455 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1456 fsm_newstate(fi, CH_STATE_RXERR);
1457 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1458 DEV_EVENT_RXDOWN, dev);
1460 fsm_newstate(fi, CH_STATE_TXERR);
1461 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1462 DEV_EVENT_TXDOWN, dev);
1467 * Restart a channel after an error.
1469 * @param fi An instance of a channel statemachine.
1470 * @param event The event, just happened.
1471 * @param arg Generic pointer, casted from channel * upon call.
1474 ch_action_restart(fsm_instance * fi, int event, void *arg)
1476 unsigned long saveflags;
1480 struct channel *ch = (struct channel *) arg;
1481 struct net_device *dev = ch->netdev;
1483 fsm_deltimer(&ch->timer);
1484 ctc_pr_debug("%s: %s channel restart\n", dev->name,
1485 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
1486 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1487 oldstate = fsm_getstate(fi);
1488 fsm_newstate(fi, CH_STATE_STARTWAIT);
1489 if (event == CH_EVENT_TIMER)
1490 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1491 rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1492 if (event == CH_EVENT_TIMER)
1493 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1496 fsm_deltimer(&ch->timer);
1497 fsm_newstate(fi, oldstate);
1499 ccw_check_return_code(ch, rc, "HaltIO in ch_action_restart");
1504 * Handle error during RX initial handshake (exchange of
1505 * 0-length block header)
1507 * @param fi An instance of a channel statemachine.
1508 * @param event The event, just happened.
1509 * @param arg Generic pointer, casted from channel * upon call.
1512 ch_action_rxiniterr(fsm_instance * fi, int event, void *arg)
1514 struct channel *ch = (struct channel *) arg;
1515 struct net_device *dev = ch->netdev;
1517 if (event == CH_EVENT_TIMER) {
1518 fsm_deltimer(&ch->timer);
1519 ctc_pr_debug("%s: Timeout during RX init handshake\n", dev->name);
1520 if (ch->retry++ < 3)
1521 ch_action_restart(fi, event, arg);
1523 fsm_newstate(fi, CH_STATE_RXERR);
1524 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1525 DEV_EVENT_RXDOWN, dev);
1528 ctc_pr_warn("%s: Error during RX init handshake\n", dev->name);
1532 * Notify device statemachine if we gave up initialization
1535 * @param fi An instance of a channel statemachine.
1536 * @param event The event, just happened.
1537 * @param arg Generic pointer, casted from channel * upon call.
1540 ch_action_rxinitfail(fsm_instance * fi, int event, void *arg)
1542 struct channel *ch = (struct channel *) arg;
1543 struct net_device *dev = ch->netdev;
1545 fsm_newstate(fi, CH_STATE_RXERR);
1546 ctc_pr_warn("%s: RX initialization failed\n", dev->name);
1547 ctc_pr_warn("%s: RX <-> RX connection detected\n", dev->name);
1548 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_RXDOWN, dev);
1552 * Handle RX Unit check remote reset (remote disconnected)
1554 * @param fi An instance of a channel statemachine.
1555 * @param event The event, just happened.
1556 * @param arg Generic pointer, casted from channel * upon call.
1559 ch_action_rxdisc(fsm_instance * fi, int event, void *arg)
1561 struct channel *ch = (struct channel *) arg;
1562 struct channel *ch2;
1563 struct net_device *dev = ch->netdev;
1565 fsm_deltimer(&ch->timer);
1566 ctc_pr_debug("%s: Got remote disconnect, re-initializing ...\n",
1570 * Notify device statemachine
1572 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_RXDOWN, dev);
1573 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_TXDOWN, dev);
1575 fsm_newstate(fi, CH_STATE_DTERM);
1576 ch2 = ((struct ctc_priv *) dev->priv)->channel[WRITE];
1577 fsm_newstate(ch2->fsm, CH_STATE_DTERM);
1579 ccw_device_halt(ch->cdev, (unsigned long) ch);
1580 ccw_device_halt(ch2->cdev, (unsigned long) ch2);
1584 * Handle error during TX channel initialization.
1586 * @param fi An instance of a channel statemachine.
1587 * @param event The event, just happened.
1588 * @param arg Generic pointer, casted from channel * upon call.
1591 ch_action_txiniterr(fsm_instance * fi, int event, void *arg)
1593 struct channel *ch = (struct channel *) arg;
1594 struct net_device *dev = ch->netdev;
1596 if (event == CH_EVENT_TIMER) {
1597 fsm_deltimer(&ch->timer);
1598 ctc_pr_debug("%s: Timeout during TX init handshake\n", dev->name);
1599 if (ch->retry++ < 3)
1600 ch_action_restart(fi, event, arg);
1602 fsm_newstate(fi, CH_STATE_TXERR);
1603 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1604 DEV_EVENT_TXDOWN, dev);
1607 ctc_pr_warn("%s: Error during TX init handshake\n", dev->name);
1611 * Handle TX timeout by retrying operation.
1613 * @param fi An instance of a channel statemachine.
1614 * @param event The event, just happened.
1615 * @param arg Generic pointer, casted from channel * upon call.
1618 ch_action_txretry(fsm_instance * fi, int event, void *arg)
1620 struct channel *ch = (struct channel *) arg;
1621 struct net_device *dev = ch->netdev;
1622 unsigned long saveflags;
1624 fsm_deltimer(&ch->timer);
1625 if (ch->retry++ > 3) {
1626 ctc_pr_debug("%s: TX retry failed, restarting channel\n",
1628 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1629 DEV_EVENT_TXDOWN, dev);
1630 ch_action_restart(fi, event, arg);
1632 struct sk_buff *skb;
1634 ctc_pr_debug("%s: TX retry %d\n", dev->name, ch->retry);
1635 if ((skb = skb_peek(&ch->io_queue))) {
1638 clear_normalized_cda(&ch->ccw[4]);
1639 ch->ccw[4].count = skb->len;
1640 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
1642 "%s: IDAL alloc failed, chan restart\n",
1644 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1645 DEV_EVENT_TXDOWN, dev);
1646 ch_action_restart(fi, event, arg);
1649 fsm_addtimer(&ch->timer, 1000, CH_EVENT_TIMER, ch);
1650 if (event == CH_EVENT_TIMER)
1651 spin_lock_irqsave(get_ccwdev_lock(ch->cdev),
1653 rc = ccw_device_start(ch->cdev, &ch->ccw[3],
1654 (unsigned long) ch, 0xff, 0);
1655 if (event == CH_EVENT_TIMER)
1656 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev),
1659 fsm_deltimer(&ch->timer);
1660 ccw_check_return_code(ch, rc, "TX in ch_action_txretry");
1661 ctc_purge_skb_queue(&ch->io_queue);
1669 * Handle fatal errors during an I/O command.
1671 * @param fi An instance of a channel statemachine.
1672 * @param event The event, just happened.
1673 * @param arg Generic pointer, casted from channel * upon call.
1676 ch_action_iofatal(fsm_instance * fi, int event, void *arg)
1678 struct channel *ch = (struct channel *) arg;
1679 struct net_device *dev = ch->netdev;
1681 fsm_deltimer(&ch->timer);
1682 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1683 ctc_pr_debug("%s: RX I/O error\n", dev->name);
1684 fsm_newstate(fi, CH_STATE_RXERR);
1685 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1686 DEV_EVENT_RXDOWN, dev);
1688 ctc_pr_debug("%s: TX I/O error\n", dev->name);
1689 fsm_newstate(fi, CH_STATE_TXERR);
1690 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1691 DEV_EVENT_TXDOWN, dev);
1696 ch_action_reinit(fsm_instance *fi, int event, void *arg)
1698 struct channel *ch = (struct channel *)arg;
1699 struct net_device *dev = ch->netdev;
1700 struct ctc_priv *privptr = dev->priv;
1702 ch_action_iofatal(fi, event, arg);
1703 fsm_addtimer(&privptr->restart_timer, 1000, DEV_EVENT_RESTART, dev);
1708 * The statemachine for a channel.
1710 static const fsm_node ch_fsm[] = {
1711 {CH_STATE_STOPPED, CH_EVENT_STOP, fsm_action_nop },
1712 {CH_STATE_STOPPED, CH_EVENT_START, ch_action_start },
1713 {CH_STATE_STOPPED, CH_EVENT_FINSTAT, fsm_action_nop },
1714 {CH_STATE_STOPPED, CH_EVENT_MC_FAIL, fsm_action_nop },
1716 {CH_STATE_NOTOP, CH_EVENT_STOP, ch_action_stop },
1717 {CH_STATE_NOTOP, CH_EVENT_START, fsm_action_nop },
1718 {CH_STATE_NOTOP, CH_EVENT_FINSTAT, fsm_action_nop },
1719 {CH_STATE_NOTOP, CH_EVENT_MC_FAIL, fsm_action_nop },
1720 {CH_STATE_NOTOP, CH_EVENT_MC_GOOD, ch_action_start },
1722 {CH_STATE_STARTWAIT, CH_EVENT_STOP, ch_action_haltio },
1723 {CH_STATE_STARTWAIT, CH_EVENT_START, fsm_action_nop },
1724 {CH_STATE_STARTWAIT, CH_EVENT_FINSTAT, ch_action_setmode },
1725 {CH_STATE_STARTWAIT, CH_EVENT_TIMER, ch_action_setuperr },
1726 {CH_STATE_STARTWAIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1727 {CH_STATE_STARTWAIT, CH_EVENT_IO_EIO, ch_action_reinit },
1728 {CH_STATE_STARTWAIT, CH_EVENT_MC_FAIL, ch_action_fail },
1730 {CH_STATE_STARTRETRY, CH_EVENT_STOP, ch_action_haltio },
1731 {CH_STATE_STARTRETRY, CH_EVENT_TIMER, ch_action_setmode },
1732 {CH_STATE_STARTRETRY, CH_EVENT_FINSTAT, fsm_action_nop },
1733 {CH_STATE_STARTRETRY, CH_EVENT_MC_FAIL, ch_action_fail },
1735 {CH_STATE_SETUPWAIT, CH_EVENT_STOP, ch_action_haltio },
1736 {CH_STATE_SETUPWAIT, CH_EVENT_START, fsm_action_nop },
1737 {CH_STATE_SETUPWAIT, CH_EVENT_FINSTAT, ch_action_firstio },
1738 {CH_STATE_SETUPWAIT, CH_EVENT_UC_RCRESET, ch_action_setuperr },
1739 {CH_STATE_SETUPWAIT, CH_EVENT_UC_RSRESET, ch_action_setuperr },
1740 {CH_STATE_SETUPWAIT, CH_EVENT_TIMER, ch_action_setmode },
1741 {CH_STATE_SETUPWAIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1742 {CH_STATE_SETUPWAIT, CH_EVENT_IO_EIO, ch_action_reinit },
1743 {CH_STATE_SETUPWAIT, CH_EVENT_MC_FAIL, ch_action_fail },
1745 {CH_STATE_RXINIT, CH_EVENT_STOP, ch_action_haltio },
1746 {CH_STATE_RXINIT, CH_EVENT_START, fsm_action_nop },
1747 {CH_STATE_RXINIT, CH_EVENT_FINSTAT, ch_action_rxidle },
1748 {CH_STATE_RXINIT, CH_EVENT_UC_RCRESET, ch_action_rxiniterr },
1749 {CH_STATE_RXINIT, CH_EVENT_UC_RSRESET, ch_action_rxiniterr },
1750 {CH_STATE_RXINIT, CH_EVENT_TIMER, ch_action_rxiniterr },
1751 {CH_STATE_RXINIT, CH_EVENT_ATTNBUSY, ch_action_rxinitfail },
1752 {CH_STATE_RXINIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1753 {CH_STATE_RXINIT, CH_EVENT_IO_EIO, ch_action_reinit },
1754 {CH_STATE_RXINIT, CH_EVENT_UC_ZERO, ch_action_firstio },
1755 {CH_STATE_RXINIT, CH_EVENT_MC_FAIL, ch_action_fail },
1757 {CH_STATE_RXIDLE, CH_EVENT_STOP, ch_action_haltio },
1758 {CH_STATE_RXIDLE, CH_EVENT_START, fsm_action_nop },
1759 {CH_STATE_RXIDLE, CH_EVENT_FINSTAT, ch_action_rx },
1760 {CH_STATE_RXIDLE, CH_EVENT_UC_RCRESET, ch_action_rxdisc },
1761 // {CH_STATE_RXIDLE, CH_EVENT_UC_RSRESET, ch_action_rxretry },
1762 {CH_STATE_RXIDLE, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1763 {CH_STATE_RXIDLE, CH_EVENT_IO_EIO, ch_action_reinit },
1764 {CH_STATE_RXIDLE, CH_EVENT_MC_FAIL, ch_action_fail },
1765 {CH_STATE_RXIDLE, CH_EVENT_UC_ZERO, ch_action_rx },
1767 {CH_STATE_TXINIT, CH_EVENT_STOP, ch_action_haltio },
1768 {CH_STATE_TXINIT, CH_EVENT_START, fsm_action_nop },
1769 {CH_STATE_TXINIT, CH_EVENT_FINSTAT, ch_action_txidle },
1770 {CH_STATE_TXINIT, CH_EVENT_UC_RCRESET, ch_action_txiniterr },
1771 {CH_STATE_TXINIT, CH_EVENT_UC_RSRESET, ch_action_txiniterr },
1772 {CH_STATE_TXINIT, CH_EVENT_TIMER, ch_action_txiniterr },
1773 {CH_STATE_TXINIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1774 {CH_STATE_TXINIT, CH_EVENT_IO_EIO, ch_action_reinit },
1775 {CH_STATE_TXINIT, CH_EVENT_MC_FAIL, ch_action_fail },
1777 {CH_STATE_TXIDLE, CH_EVENT_STOP, ch_action_haltio },
1778 {CH_STATE_TXIDLE, CH_EVENT_START, fsm_action_nop },
1779 {CH_STATE_TXIDLE, CH_EVENT_FINSTAT, ch_action_firstio },
1780 {CH_STATE_TXIDLE, CH_EVENT_UC_RCRESET, fsm_action_nop },
1781 {CH_STATE_TXIDLE, CH_EVENT_UC_RSRESET, fsm_action_nop },
1782 {CH_STATE_TXIDLE, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1783 {CH_STATE_TXIDLE, CH_EVENT_IO_EIO, ch_action_reinit },
1784 {CH_STATE_TXIDLE, CH_EVENT_MC_FAIL, ch_action_fail },
1786 {CH_STATE_TERM, CH_EVENT_STOP, fsm_action_nop },
1787 {CH_STATE_TERM, CH_EVENT_START, ch_action_restart },
1788 {CH_STATE_TERM, CH_EVENT_FINSTAT, ch_action_stopped },
1789 {CH_STATE_TERM, CH_EVENT_UC_RCRESET, fsm_action_nop },
1790 {CH_STATE_TERM, CH_EVENT_UC_RSRESET, fsm_action_nop },
1791 {CH_STATE_TERM, CH_EVENT_MC_FAIL, ch_action_fail },
1793 {CH_STATE_DTERM, CH_EVENT_STOP, ch_action_haltio },
1794 {CH_STATE_DTERM, CH_EVENT_START, ch_action_restart },
1795 {CH_STATE_DTERM, CH_EVENT_FINSTAT, ch_action_setmode },
1796 {CH_STATE_DTERM, CH_EVENT_UC_RCRESET, fsm_action_nop },
1797 {CH_STATE_DTERM, CH_EVENT_UC_RSRESET, fsm_action_nop },
1798 {CH_STATE_DTERM, CH_EVENT_MC_FAIL, ch_action_fail },
1800 {CH_STATE_TX, CH_EVENT_STOP, ch_action_haltio },
1801 {CH_STATE_TX, CH_EVENT_START, fsm_action_nop },
1802 {CH_STATE_TX, CH_EVENT_FINSTAT, ch_action_txdone },
1803 {CH_STATE_TX, CH_EVENT_UC_RCRESET, ch_action_txretry },
1804 {CH_STATE_TX, CH_EVENT_UC_RSRESET, ch_action_txretry },
1805 {CH_STATE_TX, CH_EVENT_TIMER, ch_action_txretry },
1806 {CH_STATE_TX, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1807 {CH_STATE_TX, CH_EVENT_IO_EIO, ch_action_reinit },
1808 {CH_STATE_TX, CH_EVENT_MC_FAIL, ch_action_fail },
1810 {CH_STATE_RXERR, CH_EVENT_STOP, ch_action_haltio },
1811 {CH_STATE_TXERR, CH_EVENT_STOP, ch_action_haltio },
1812 {CH_STATE_TXERR, CH_EVENT_MC_FAIL, ch_action_fail },
1813 {CH_STATE_RXERR, CH_EVENT_MC_FAIL, ch_action_fail },
1816 static const int CH_FSM_LEN = sizeof (ch_fsm) / sizeof (fsm_node);
1819 * Functions related to setup and device detection.
1820 *****************************************************************************/
1823 less_than(char *id1, char *id2)
1827 for (i = 0; i < 5; i++) {
1831 dev1 = simple_strtoul(id1, &id1, 16);
1832 dev2 = simple_strtoul(id2, &id2, 16);
1834 return (dev1 < dev2);
1838 * Add a new channel to the list of channels.
1839 * Keeps the channel list sorted.
1841 * @param cdev The ccw_device to be added.
1842 * @param type The type class of the new channel.
1844 * @return 0 on success, !0 on error.
1847 add_channel(struct ccw_device *cdev, enum channel_types type)
1849 struct channel **c = &channels;
1853 (struct channel *) kmalloc(sizeof (struct channel),
1854 GFP_KERNEL)) == NULL) {
1855 ctc_pr_warn("ctc: Out of memory in add_channel\n");
1858 memset(ch, 0, sizeof (struct channel));
1859 if ((ch->ccw = (struct ccw1 *) kmalloc(sizeof (struct ccw1) * 8,
1860 GFP_KERNEL | GFP_DMA)) == NULL) {
1862 ctc_pr_warn("ctc: Out of memory in add_channel\n");
1867 * "static" ccws are used in the following way:
1869 * ccw[0..2] (Channel program for generic I/O):
1871 * 1: read or write (depending on direction) with fixed
1872 * buffer (idal allocated once when buffer is allocated)
1874 * ccw[3..5] (Channel program for direct write of packets)
1876 * 4: write (idal allocated on every write).
1878 * ccw[6..7] (Channel program for initial channel setup):
1879 * 3: set extended mode
1882 * ch->ccw[0..5] are initialized in ch_action_start because
1883 * the channel's direction is yet unknown here.
1885 ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED;
1886 ch->ccw[6].flags = CCW_FLAG_SLI;
1887 ch->ccw[6].count = 0;
1890 ch->ccw[7].cmd_code = CCW_CMD_NOOP;
1891 ch->ccw[7].flags = CCW_FLAG_SLI;
1892 ch->ccw[7].count = 0;
1896 snprintf(ch->id, CTC_ID_SIZE, "ch-%s", cdev->dev.bus_id);
1898 loglevel = CTC_LOGLEVEL_DEFAULT;
1899 ch->fsm = init_fsm(ch->id, ch_state_names,
1900 ch_event_names, NR_CH_STATES, NR_CH_EVENTS,
1901 ch_fsm, CH_FSM_LEN, GFP_KERNEL);
1902 if (ch->fsm == NULL) {
1903 ctc_pr_warn("ctc: Could not create FSM in add_channel\n");
1907 fsm_newstate(ch->fsm, CH_STATE_IDLE);
1908 if ((ch->irb = (struct irb *) kmalloc(sizeof (struct irb),
1909 GFP_KERNEL)) == NULL) {
1910 ctc_pr_warn("ctc: Out of memory in add_channel\n");
1915 memset(ch->irb, 0, sizeof (struct irb));
1916 while (*c && less_than((*c)->id, ch->id))
1918 if (!strncmp((*c)->id, ch->id, CTC_ID_SIZE)) {
1920 "ctc: add_channel: device %s already in list, "
1921 "using old entry\n", (*c)->id);
1927 fsm_settimer(ch->fsm, &ch->timer);
1928 skb_queue_head_init(&ch->io_queue);
1929 skb_queue_head_init(&ch->collect_queue);
1936 * Release a specific channel in the channel list.
1938 * @param ch Pointer to channel struct to be released.
1941 channel_free(struct channel *ch)
1943 ch->flags &= ~CHANNEL_FLAGS_INUSE;
1944 fsm_newstate(ch->fsm, CH_STATE_IDLE);
1948 * Remove a specific channel in the channel list.
1950 * @param ch Pointer to channel struct to be released.
1953 channel_remove(struct channel *ch)
1955 struct channel **c = &channels;
1964 fsm_deltimer(&ch->timer);
1966 clear_normalized_cda(&ch->ccw[4]);
1967 if (ch->trans_skb != NULL) {
1968 clear_normalized_cda(&ch->ccw[1]);
1969 dev_kfree_skb(ch->trans_skb);
1979 * Get a specific channel from the channel list.
1981 * @param type Type of channel we are interested in.
1982 * @param id Id of channel we are interested in.
1983 * @param direction Direction we want to use this channel for.
1985 * @return Pointer to a channel or NULL if no matching channel available.
1987 static struct channel
1989 channel_get(enum channel_types type, char *id, int direction)
1991 struct channel *ch = channels;
1994 ctc_pr_debug("ctc: %s(): searching for ch with id %s and type %d\n",
1995 __func__, id, type);
1998 while (ch && ((strncmp(ch->id, id, CTC_ID_SIZE)) || (ch->type != type))) {
2000 ctc_pr_debug("ctc: %s(): ch=0x%p (id=%s, type=%d\n",
2001 __func__, ch, ch->id, ch->type);
2006 ctc_pr_debug("ctc: %s(): ch=0x%pq (id=%s, type=%d\n",
2007 __func__, ch, ch->id, ch->type);
2010 ctc_pr_warn("ctc: %s(): channel with id %s "
2011 "and type %d not found in channel list\n",
2012 __func__, id, type);
2014 if (ch->flags & CHANNEL_FLAGS_INUSE)
2017 ch->flags |= CHANNEL_FLAGS_INUSE;
2018 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
2019 ch->flags |= (direction == WRITE)
2020 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
2021 fsm_newstate(ch->fsm, CH_STATE_STOPPED);
2028 * Return the channel type by name.
2030 * @param name Name of network interface.
2032 * @return Type class of channel to be used for that interface.
2034 static enum channel_types inline
2035 extract_channel_media(char *name)
2037 enum channel_types ret = channel_type_unknown;
2040 if (strncmp(name, "ctc", 3) == 0)
2041 ret = channel_type_parallel;
2042 if (strncmp(name, "escon", 5) == 0)
2043 ret = channel_type_escon;
2049 __ctc_check_irb_error(struct ccw_device *cdev, struct irb *irb)
2054 switch (PTR_ERR(irb)) {
2056 ctc_pr_warn("i/o-error on device %s\n", cdev->dev.bus_id);
2057 // CTC_DBF_TEXT(trace, 2, "ckirberr");
2058 // CTC_DBF_TEXT_(trace, 2, " rc%d", -EIO);
2061 ctc_pr_warn("timeout on device %s\n", cdev->dev.bus_id);
2062 // CTC_DBF_TEXT(trace, 2, "ckirberr");
2063 // CTC_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
2066 ctc_pr_warn("unknown error %ld on device %s\n", PTR_ERR(irb),
2068 // CTC_DBF_TEXT(trace, 2, "ckirberr");
2069 // CTC_DBF_TEXT(trace, 2, " rc???");
2071 return PTR_ERR(irb);
2077 * @param cdev The ccw_device the interrupt is for.
2078 * @param intparm interruption parameter.
2079 * @param irb interruption response block.
2082 ctc_irq_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
2085 struct net_device *dev;
2086 struct ctc_priv *priv;
2088 if (__ctc_check_irb_error(cdev, irb))
2091 /* Check for unsolicited interrupts. */
2092 if (!cdev->dev.driver_data) {
2093 ctc_pr_warn("ctc: Got unsolicited irq: %s c-%02x d-%02x\n",
2094 cdev->dev.bus_id, irb->scsw.cstat,
2099 priv = ((struct ccwgroup_device *)cdev->dev.driver_data)
2102 /* Try to extract channel from driver data. */
2103 if (priv->channel[READ]->cdev == cdev)
2104 ch = priv->channel[READ];
2105 else if (priv->channel[WRITE]->cdev == cdev)
2106 ch = priv->channel[WRITE];
2108 ctc_pr_err("ctc: Can't determine channel for interrupt, "
2109 "device %s\n", cdev->dev.bus_id);
2113 dev = (struct net_device *) (ch->netdev);
2115 ctc_pr_crit("ctc: ctc_irq_handler dev=NULL bus_id=%s, ch=0x%p\n",
2116 cdev->dev.bus_id, ch);
2121 ctc_pr_debug("%s: interrupt for device: %s received c-%02x d-%02x\n",
2122 dev->name, ch->id, irb->scsw.cstat, irb->scsw.dstat);
2125 /* Copy interruption response block. */
2126 memcpy(ch->irb, irb, sizeof(struct irb));
2128 /* Check for good subchannel return code, otherwise error message */
2129 if (ch->irb->scsw.cstat) {
2130 fsm_event(ch->fsm, CH_EVENT_SC_UNKNOWN, ch);
2131 ctc_pr_warn("%s: subchannel check for device: %s - %02x %02x\n",
2132 dev->name, ch->id, ch->irb->scsw.cstat,
2133 ch->irb->scsw.dstat);
2137 /* Check the reason-code of a unit check */
2138 if (ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
2139 ccw_unit_check(ch, ch->irb->ecw[0]);
2142 if (ch->irb->scsw.dstat & DEV_STAT_BUSY) {
2143 if (ch->irb->scsw.dstat & DEV_STAT_ATTENTION)
2144 fsm_event(ch->fsm, CH_EVENT_ATTNBUSY, ch);
2146 fsm_event(ch->fsm, CH_EVENT_BUSY, ch);
2149 if (ch->irb->scsw.dstat & DEV_STAT_ATTENTION) {
2150 fsm_event(ch->fsm, CH_EVENT_ATTN, ch);
2153 if ((ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
2154 (ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
2155 (ch->irb->scsw.stctl ==
2156 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
2157 fsm_event(ch->fsm, CH_EVENT_FINSTAT, ch);
2159 fsm_event(ch->fsm, CH_EVENT_IRQ, ch);
2164 * Actions for interface - statemachine.
2165 *****************************************************************************/
2168 * Startup channels by sending CH_EVENT_START to each channel.
2170 * @param fi An instance of an interface statemachine.
2171 * @param event The event, just happened.
2172 * @param arg Generic pointer, casted from struct net_device * upon call.
2175 dev_action_start(fsm_instance * fi, int event, void *arg)
2177 struct net_device *dev = (struct net_device *) arg;
2178 struct ctc_priv *privptr = dev->priv;
2181 fsm_deltimer(&privptr->restart_timer);
2182 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2183 for (direction = READ; direction <= WRITE; direction++) {
2184 struct channel *ch = privptr->channel[direction];
2185 fsm_event(ch->fsm, CH_EVENT_START, ch);
2190 * Shutdown channels by sending CH_EVENT_STOP to each channel.
2192 * @param fi An instance of an interface statemachine.
2193 * @param event The event, just happened.
2194 * @param arg Generic pointer, casted from struct net_device * upon call.
2197 dev_action_stop(fsm_instance * fi, int event, void *arg)
2199 struct net_device *dev = (struct net_device *) arg;
2200 struct ctc_priv *privptr = dev->priv;
2203 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2204 for (direction = READ; direction <= WRITE; direction++) {
2205 struct channel *ch = privptr->channel[direction];
2206 fsm_event(ch->fsm, CH_EVENT_STOP, ch);
2210 dev_action_restart(fsm_instance *fi, int event, void *arg)
2212 struct net_device *dev = (struct net_device *)arg;
2213 struct ctc_priv *privptr = dev->priv;
2215 ctc_pr_debug("%s: Restarting\n", dev->name);
2216 dev_action_stop(fi, event, arg);
2217 fsm_event(privptr->fsm, DEV_EVENT_STOP, dev);
2218 fsm_addtimer(&privptr->restart_timer, CTC_TIMEOUT_5SEC,
2219 DEV_EVENT_START, dev);
2223 * Called from channel statemachine
2224 * when a channel is up and running.
2226 * @param fi An instance of an interface statemachine.
2227 * @param event The event, just happened.
2228 * @param arg Generic pointer, casted from struct net_device * upon call.
2231 dev_action_chup(fsm_instance * fi, int event, void *arg)
2233 struct net_device *dev = (struct net_device *) arg;
2234 struct ctc_priv *privptr = dev->priv;
2236 switch (fsm_getstate(fi)) {
2237 case DEV_STATE_STARTWAIT_RXTX:
2238 if (event == DEV_EVENT_RXUP)
2239 fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
2241 fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
2243 case DEV_STATE_STARTWAIT_RX:
2244 if (event == DEV_EVENT_RXUP) {
2245 fsm_newstate(fi, DEV_STATE_RUNNING);
2246 ctc_pr_info("%s: connected with remote side\n",
2248 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2249 ctc_tty_setcarrier(dev, 1);
2250 ctc_clear_busy(dev);
2253 case DEV_STATE_STARTWAIT_TX:
2254 if (event == DEV_EVENT_TXUP) {
2255 fsm_newstate(fi, DEV_STATE_RUNNING);
2256 ctc_pr_info("%s: connected with remote side\n",
2258 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2259 ctc_tty_setcarrier(dev, 1);
2260 ctc_clear_busy(dev);
2263 case DEV_STATE_STOPWAIT_TX:
2264 if (event == DEV_EVENT_RXUP)
2265 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2267 case DEV_STATE_STOPWAIT_RX:
2268 if (event == DEV_EVENT_TXUP)
2269 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2275 * Called from channel statemachine
2276 * when a channel has been shutdown.
2278 * @param fi An instance of an interface statemachine.
2279 * @param event The event, just happened.
2280 * @param arg Generic pointer, casted from struct net_device * upon call.
2283 dev_action_chdown(fsm_instance * fi, int event, void *arg)
2285 struct net_device *dev = (struct net_device *) arg;
2286 struct ctc_priv *privptr = dev->priv;
2288 switch (fsm_getstate(fi)) {
2289 case DEV_STATE_RUNNING:
2290 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2291 ctc_tty_setcarrier(dev, 0);
2292 if (event == DEV_EVENT_TXDOWN)
2293 fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
2295 fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
2297 case DEV_STATE_STARTWAIT_RX:
2298 if (event == DEV_EVENT_TXDOWN)
2299 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2301 case DEV_STATE_STARTWAIT_TX:
2302 if (event == DEV_EVENT_RXDOWN)
2303 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2305 case DEV_STATE_STOPWAIT_RXTX:
2306 if (event == DEV_EVENT_TXDOWN)
2307 fsm_newstate(fi, DEV_STATE_STOPWAIT_RX);
2309 fsm_newstate(fi, DEV_STATE_STOPWAIT_TX);
2311 case DEV_STATE_STOPWAIT_RX:
2312 if (event == DEV_EVENT_RXDOWN)
2313 fsm_newstate(fi, DEV_STATE_STOPPED);
2315 case DEV_STATE_STOPWAIT_TX:
2316 if (event == DEV_EVENT_TXDOWN)
2317 fsm_newstate(fi, DEV_STATE_STOPPED);
2322 static const fsm_node dev_fsm[] = {
2323 {DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start},
2325 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_START, dev_action_start },
2326 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
2327 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
2328 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
2330 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_START, dev_action_start },
2331 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
2332 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
2333 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXDOWN, dev_action_chdown },
2334 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
2336 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_START, dev_action_start },
2337 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
2338 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
2339 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXDOWN, dev_action_chdown },
2340 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
2342 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_STOP, dev_action_stop },
2343 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXUP, dev_action_chup },
2344 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXUP, dev_action_chup },
2345 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
2346 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
2347 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
2349 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_STOP, dev_action_stop },
2350 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
2351 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
2352 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXDOWN, dev_action_chdown },
2353 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
2355 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_STOP, dev_action_stop },
2356 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
2357 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
2358 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXDOWN, dev_action_chdown },
2359 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
2361 {DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
2362 {DEV_STATE_RUNNING, DEV_EVENT_RXDOWN, dev_action_chdown },
2363 {DEV_STATE_RUNNING, DEV_EVENT_TXDOWN, dev_action_chdown },
2364 {DEV_STATE_RUNNING, DEV_EVENT_TXUP, fsm_action_nop },
2365 {DEV_STATE_RUNNING, DEV_EVENT_RXUP, fsm_action_nop },
2366 {DEV_STATE_RUNNING, DEV_EVENT_RESTART, dev_action_restart },
2369 static const int DEV_FSM_LEN = sizeof (dev_fsm) / sizeof (fsm_node);
2372 * Transmit a packet.
2373 * This is a helper function for ctc_tx().
2375 * @param ch Channel to be used for sending.
2376 * @param skb Pointer to struct sk_buff of packet to send.
2377 * The linklevel header has already been set up
2380 * @return 0 on success, -ERRNO on failure. (Never fails.)
2383 transmit_skb(struct channel *ch, struct sk_buff *skb)
2385 unsigned long saveflags;
2386 struct ll_header header;
2389 if (fsm_getstate(ch->fsm) != CH_STATE_TXIDLE) {
2390 int l = skb->len + LL_HEADER_LENGTH;
2392 spin_lock_irqsave(&ch->collect_lock, saveflags);
2393 if (ch->collect_len + l > ch->max_bufsize - 2)
2396 atomic_inc(&skb->users);
2398 header.type = skb->protocol;
2400 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
2402 skb_queue_tail(&ch->collect_queue, skb);
2403 ch->collect_len += l;
2405 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
2409 struct sk_buff *nskb;
2413 * Protect skb against beeing free'd by upper
2416 atomic_inc(&skb->users);
2417 ch->prof.txlen += skb->len;
2418 header.length = skb->len + LL_HEADER_LENGTH;
2419 header.type = skb->protocol;
2421 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
2423 block_len = skb->len + 2;
2424 *((__u16 *) skb_push(skb, 2)) = block_len;
2427 * IDAL support in CTC is broken, so we have to
2428 * care about skb's above 2G ourselves.
2430 hi = ((unsigned long) skb->tail + LL_HEADER_LENGTH) >> 31;
2432 nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
2434 atomic_dec(&skb->users);
2435 skb_pull(skb, LL_HEADER_LENGTH + 2);
2438 memcpy(skb_put(nskb, skb->len),
2439 skb->data, skb->len);
2440 atomic_inc(&nskb->users);
2441 atomic_dec(&skb->users);
2442 dev_kfree_skb_irq(skb);
2447 ch->ccw[4].count = block_len;
2448 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
2450 * idal allocation failed, try via copying to
2451 * trans_skb. trans_skb usually has a pre-allocated
2454 if (ctc_checkalloc_buffer(ch, 1)) {
2456 * Remove our header. It gets added
2457 * again on retransmit.
2459 atomic_dec(&skb->users);
2460 skb_pull(skb, LL_HEADER_LENGTH + 2);
2464 ch->trans_skb->tail = ch->trans_skb->data;
2465 ch->trans_skb->len = 0;
2466 ch->ccw[1].count = skb->len;
2467 memcpy(skb_put(ch->trans_skb, skb->len), skb->data,
2469 atomic_dec(&skb->users);
2470 dev_kfree_skb_irq(skb);
2473 skb_queue_tail(&ch->io_queue, skb);
2477 fsm_newstate(ch->fsm, CH_STATE_TX);
2478 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
2479 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
2480 ch->prof.send_stamp = xtime;
2481 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
2482 (unsigned long) ch, 0xff, 0);
2483 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
2485 ch->prof.doios_single++;
2487 fsm_deltimer(&ch->timer);
2488 ccw_check_return_code(ch, rc, "single skb TX");
2490 skb_dequeue_tail(&ch->io_queue);
2492 * Remove our header. It gets added
2493 * again on retransmit.
2495 skb_pull(skb, LL_HEADER_LENGTH + 2);
2498 struct net_device *dev = ch->netdev;
2499 struct ctc_priv *privptr = dev->priv;
2500 privptr->stats.tx_packets++;
2501 privptr->stats.tx_bytes +=
2502 skb->len - LL_HEADER_LENGTH;
2511 * Interface API for upper network layers
2512 *****************************************************************************/
2515 * Open an interface.
2516 * Called from generic network layer when ifconfig up is run.
2518 * @param dev Pointer to interface struct.
2520 * @return 0 on success, -ERRNO on failure. (Never fails.)
2523 ctc_open(struct net_device * dev)
2525 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_START, dev);
2530 * Close an interface.
2531 * Called from generic network layer when ifconfig down is run.
2533 * @param dev Pointer to interface struct.
2535 * @return 0 on success, -ERRNO on failure. (Never fails.)
2538 ctc_close(struct net_device * dev)
2540 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_STOP, dev);
2545 * Start transmission of a packet.
2546 * Called from generic network device layer.
2548 * @param skb Pointer to buffer containing the packet.
2549 * @param dev Pointer to interface struct.
2551 * @return 0 if packet consumed, !0 if packet rejected.
2552 * Note: If we return !0, then the packet is free'd by
2553 * the generic network layer.
2556 ctc_tx(struct sk_buff *skb, struct net_device * dev)
2559 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
2562 * Some sanity checks ...
2565 ctc_pr_warn("%s: NULL sk_buff passed\n", dev->name);
2566 privptr->stats.tx_dropped++;
2569 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
2570 ctc_pr_warn("%s: Got sk_buff with head room < %ld bytes\n",
2571 dev->name, LL_HEADER_LENGTH + 2);
2573 privptr->stats.tx_dropped++;
2578 * If channels are not running, try to restart them
2579 * and throw away packet.
2581 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
2582 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
2583 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2586 privptr->stats.tx_dropped++;
2587 privptr->stats.tx_errors++;
2588 privptr->stats.tx_carrier_errors++;
2592 if (ctc_test_and_set_busy(dev))
2595 dev->trans_start = jiffies;
2596 if (transmit_skb(privptr->channel[WRITE], skb) != 0)
2598 ctc_clear_busy(dev);
2603 * Sets MTU of an interface.
2605 * @param dev Pointer to interface struct.
2606 * @param new_mtu The new MTU to use for this interface.
2608 * @return 0 on success, -EINVAL if MTU is out of valid range.
2609 * (valid range is 576 .. 65527). If VM is on the
2610 * remote side, maximum MTU is 32760, however this is
2611 * <em>not</em> checked here.
2614 ctc_change_mtu(struct net_device * dev, int new_mtu)
2616 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
2618 if ((new_mtu < 576) || (new_mtu > 65527) ||
2619 (new_mtu > (privptr->channel[READ]->max_bufsize -
2620 LL_HEADER_LENGTH - 2)))
2623 dev->hard_header_len = LL_HEADER_LENGTH + 2;
2628 * Returns interface statistics of a device.
2630 * @param dev Pointer to interface struct.
2632 * @return Pointer to stats struct of this interface.
2634 static struct net_device_stats *
2635 ctc_stats(struct net_device * dev)
2637 return &((struct ctc_priv *) dev->priv)->stats;
2644 buffer_show(struct device *dev, char *buf)
2646 struct ctc_priv *priv;
2648 priv = dev->driver_data;
2651 return sprintf(buf, "%d\n",
2652 priv->channel[READ]->max_bufsize);
2656 buffer_write(struct device *dev, const char *buf, size_t count)
2658 struct ctc_priv *priv;
2659 struct net_device *ndev;
2662 priv = dev->driver_data;
2665 ndev = priv->channel[READ]->netdev;
2668 sscanf(buf, "%u", &bs1);
2670 if (bs1 > CTC_BUFSIZE_LIMIT)
2672 if ((ndev->flags & IFF_RUNNING) &&
2673 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
2675 if (bs1 < (576 + LL_HEADER_LENGTH + 2))
2678 priv->channel[READ]->max_bufsize =
2679 priv->channel[WRITE]->max_bufsize = bs1;
2680 if (!(ndev->flags & IFF_RUNNING))
2681 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
2682 priv->channel[READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
2683 priv->channel[WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
2690 loglevel_show(struct device *dev, char *buf)
2692 struct ctc_priv *priv;
2694 priv = dev->driver_data;
2697 return sprintf(buf, "%d\n", loglevel);
2701 loglevel_write(struct device *dev, const char *buf, size_t count)
2703 struct ctc_priv *priv;
2706 priv = dev->driver_data;
2709 sscanf(buf, "%i", &ll1);
2711 if ((ll1 > CTC_LOGLEVEL_MAX) || (ll1 < 0))
2718 ctc_print_statistics(struct ctc_priv *priv)
2725 sbuf = (char *)kmalloc(2048, GFP_KERNEL);
2730 p += sprintf(p, " Device FSM state: %s\n",
2731 fsm_getstate_str(priv->fsm));
2732 p += sprintf(p, " RX channel FSM state: %s\n",
2733 fsm_getstate_str(priv->channel[READ]->fsm));
2734 p += sprintf(p, " TX channel FSM state: %s\n",
2735 fsm_getstate_str(priv->channel[WRITE]->fsm));
2736 p += sprintf(p, " Max. TX buffer used: %ld\n",
2737 priv->channel[WRITE]->prof.maxmulti);
2738 p += sprintf(p, " Max. chained SKBs: %ld\n",
2739 priv->channel[WRITE]->prof.maxcqueue);
2740 p += sprintf(p, " TX single write ops: %ld\n",
2741 priv->channel[WRITE]->prof.doios_single);
2742 p += sprintf(p, " TX multi write ops: %ld\n",
2743 priv->channel[WRITE]->prof.doios_multi);
2744 p += sprintf(p, " Netto bytes written: %ld\n",
2745 priv->channel[WRITE]->prof.txlen);
2746 p += sprintf(p, " Max. TX IO-time: %ld\n",
2747 priv->channel[WRITE]->prof.tx_time);
2749 ctc_pr_debug("Statistics for %s:\n%s",
2750 priv->channel[WRITE]->netdev->name, sbuf);
2756 stats_show(struct device *dev, char *buf)
2758 struct ctc_priv *priv = dev->driver_data;
2761 ctc_print_statistics(priv);
2762 return sprintf(buf, "0\n");
2766 stats_write(struct device *dev, const char *buf, size_t count)
2768 struct ctc_priv *priv = dev->driver_data;
2771 /* Reset statistics */
2772 memset(&priv->channel[WRITE]->prof, 0,
2773 sizeof(priv->channel[WRITE]->prof));
2777 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
2778 static DEVICE_ATTR(loglevel, 0644, loglevel_show, loglevel_write);
2779 static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
2782 ctc_add_attributes(struct device *dev)
2784 device_create_file(dev, &dev_attr_buffer);
2785 device_create_file(dev, &dev_attr_loglevel);
2786 device_create_file(dev, &dev_attr_stats);
2791 ctc_remove_attributes(struct device *dev)
2793 device_remove_file(dev, &dev_attr_stats);
2794 device_remove_file(dev, &dev_attr_loglevel);
2795 device_remove_file(dev, &dev_attr_buffer);
2800 ctc_netdev_unregister(struct net_device * dev)
2802 struct ctc_priv *privptr;
2806 privptr = (struct ctc_priv *) dev->priv;
2807 if (privptr->protocol != CTC_PROTO_LINUX_TTY)
2808 unregister_netdev(dev);
2810 ctc_tty_unregister_netdev(dev);
2814 ctc_netdev_register(struct net_device * dev)
2816 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
2817 if (privptr->protocol != CTC_PROTO_LINUX_TTY)
2818 return register_netdev(dev);
2820 return ctc_tty_register_netdev(dev);
2824 ctc_free_netdevice(struct net_device * dev, int free_dev)
2826 struct ctc_priv *privptr;
2829 privptr = dev->priv;
2832 kfree_fsm(privptr->fsm);
2842 * Initialize everything of the net device except the name and the
2845 static struct net_device *
2846 ctc_init_netdevice(struct net_device * dev, int alloc_device,
2847 struct ctc_priv *privptr)
2853 dev = kmalloc(sizeof (struct net_device), GFP_KERNEL);
2856 memset(dev, 0, sizeof (struct net_device));
2859 dev->priv = privptr;
2860 privptr->fsm = init_fsm("ctcdev", dev_state_names,
2861 dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS,
2862 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
2863 if (privptr->fsm == NULL) {
2868 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
2869 fsm_settimer(privptr->fsm, &privptr->restart_timer);
2870 dev->mtu = CTC_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
2871 dev->hard_start_xmit = ctc_tx;
2872 dev->open = ctc_open;
2873 dev->stop = ctc_close;
2874 dev->get_stats = ctc_stats;
2875 dev->change_mtu = ctc_change_mtu;
2876 dev->hard_header_len = LL_HEADER_LENGTH + 2;
2878 dev->type = ARPHRD_SLIP;
2879 dev->tx_queue_len = 100;
2880 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2881 SET_MODULE_OWNER(dev);
2886 ctc_proto_show(struct device *dev, char *buf)
2888 struct ctc_priv *priv;
2890 priv = dev->driver_data;
2894 return sprintf(buf, "%d\n", priv->protocol);
2898 ctc_proto_store(struct device *dev, const char *buf, size_t count)
2900 struct ctc_priv *priv;
2903 pr_debug("%s() called\n", __FUNCTION__);
2905 priv = dev->driver_data;
2908 sscanf(buf, "%u", &value);
2909 if ((value < 0) || (value > CTC_PROTO_MAX))
2911 priv->protocol = value;
2916 static DEVICE_ATTR(protocol, 0644, ctc_proto_show, ctc_proto_store);
2919 ctc_type_show(struct device *dev, char *buf)
2921 struct ccwgroup_device *cgdev;
2923 cgdev = to_ccwgroupdev(dev);
2927 return sprintf(buf, "%s\n", cu3088_type[cgdev->cdev[0]->id.driver_info]);
2930 static DEVICE_ATTR(type, 0444, ctc_type_show, NULL);
2932 static struct attribute *ctc_attr[] = {
2933 &dev_attr_protocol.attr,
2934 &dev_attr_type.attr,
2938 static struct attribute_group ctc_attr_group = {
2943 ctc_add_files(struct device *dev)
2945 pr_debug("%s() called\n", __FUNCTION__);
2947 return sysfs_create_group(&dev->kobj, &ctc_attr_group);
2951 ctc_remove_files(struct device *dev)
2953 pr_debug("%s() called\n", __FUNCTION__);
2955 sysfs_remove_group(&dev->kobj, &ctc_attr_group);
2959 * Add ctc specific attributes.
2960 * Add ctc private data.
2962 * @param cgdev pointer to ccwgroup_device just added
2964 * @returns 0 on success, !0 on failure.
2968 ctc_probe_device(struct ccwgroup_device *cgdev)
2970 struct ctc_priv *priv;
2973 pr_debug("%s() called\n", __FUNCTION__);
2975 if (!get_device(&cgdev->dev))
2978 priv = kmalloc(sizeof (struct ctc_priv), GFP_KERNEL);
2980 ctc_pr_err("%s: Out of memory\n", __func__);
2981 put_device(&cgdev->dev);
2985 memset(priv, 0, sizeof (struct ctc_priv));
2986 rc = ctc_add_files(&cgdev->dev);
2989 put_device(&cgdev->dev);
2993 cgdev->cdev[0]->handler = ctc_irq_handler;
2994 cgdev->cdev[1]->handler = ctc_irq_handler;
2995 cgdev->dev.driver_data = priv;
3002 * Setup an interface.
3004 * @param cgdev Device to be setup.
3006 * @returns 0 on success, !0 on failure.
3009 ctc_new_device(struct ccwgroup_device *cgdev)
3011 char read_id[CTC_ID_SIZE];
3012 char write_id[CTC_ID_SIZE];
3014 enum channel_types type;
3015 struct ctc_priv *privptr;
3016 struct net_device *dev;
3019 pr_debug("%s() called\n", __FUNCTION__);
3021 privptr = cgdev->dev.driver_data;
3025 type = get_channel_type(&cgdev->cdev[0]->id);
3027 snprintf(read_id, CTC_ID_SIZE, "ch-%s", cgdev->cdev[0]->dev.bus_id);
3028 snprintf(write_id, CTC_ID_SIZE, "ch-%s", cgdev->cdev[1]->dev.bus_id);
3030 if (add_channel(cgdev->cdev[0], type))
3032 if (add_channel(cgdev->cdev[1], type))
3035 ret = ccw_device_set_online(cgdev->cdev[0]);
3038 "ccw_device_set_online (cdev[0]) failed with ret = %d\n", ret);
3041 ret = ccw_device_set_online(cgdev->cdev[1]);
3044 "ccw_device_set_online (cdev[1]) failed with ret = %d\n", ret);
3047 dev = ctc_init_netdevice(NULL, 1, privptr);
3050 ctc_pr_warn("ctc_init_netdevice failed\n");
3054 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
3055 snprintf(dev->name, 8, "ctctty%%d");
3057 snprintf(dev->name, 8, "ctc%%d");
3059 for (direction = READ; direction <= WRITE; direction++) {
3060 privptr->channel[direction] =
3061 channel_get(type, direction == READ ? read_id : write_id,
3063 if (privptr->channel[direction] == NULL) {
3064 if (direction == WRITE)
3065 channel_free(privptr->channel[READ]);
3067 ctc_free_netdevice(dev, 1);
3070 privptr->channel[direction]->netdev = dev;
3071 privptr->channel[direction]->protocol = privptr->protocol;
3072 privptr->channel[direction]->max_bufsize = CTC_BUFSIZE_DEFAULT;
3075 SET_NETDEV_DEV(dev, &cgdev->dev);
3077 if (ctc_netdev_register(dev) != 0) {
3078 ctc_free_netdevice(dev, 1);
3082 ctc_add_attributes(&cgdev->dev);
3084 strlcpy(privptr->fsm->name, dev->name, sizeof (privptr->fsm->name));
3088 ctc_pr_info("%s: read: %s, write: %s, proto: %d\n",
3089 dev->name, privptr->channel[READ]->id,
3090 privptr->channel[WRITE]->id, privptr->protocol);
3094 ccw_device_set_offline(cgdev->cdev[1]);
3095 ccw_device_set_offline(cgdev->cdev[0]);
3101 * Shutdown an interface.
3103 * @param cgdev Device to be shut down.
3105 * @returns 0 on success, !0 on failure.
3108 ctc_shutdown_device(struct ccwgroup_device *cgdev)
3110 struct ctc_priv *priv;
3111 struct net_device *ndev;
3114 pr_debug("%s() called\n", __FUNCTION__);
3116 priv = cgdev->dev.driver_data;
3121 if (priv->channel[READ]) {
3122 ndev = priv->channel[READ]->netdev;
3124 /* Close the device */
3126 ndev->flags &=~IFF_RUNNING;
3128 ctc_remove_attributes(&cgdev->dev);
3130 channel_free(priv->channel[READ]);
3132 if (priv->channel[WRITE])
3133 channel_free(priv->channel[WRITE]);
3136 ctc_netdev_unregister(ndev);
3138 ctc_free_netdevice(ndev, 1);
3142 kfree_fsm(priv->fsm);
3144 ccw_device_set_offline(cgdev->cdev[1]);
3145 ccw_device_set_offline(cgdev->cdev[0]);
3147 if (priv->channel[READ])
3148 channel_remove(priv->channel[READ]);
3149 if (priv->channel[WRITE])
3150 channel_remove(priv->channel[WRITE]);
3152 priv->channel[READ] = priv->channel[WRITE] = NULL;
3159 ctc_remove_device(struct ccwgroup_device *cgdev)
3161 struct ctc_priv *priv;
3163 pr_debug("%s() called\n", __FUNCTION__);
3165 priv = cgdev->dev.driver_data;
3168 if (cgdev->state == CCWGROUP_ONLINE)
3169 ctc_shutdown_device(cgdev);
3170 ctc_remove_files(&cgdev->dev);
3171 cgdev->dev.driver_data = NULL;
3173 put_device(&cgdev->dev);
3176 static struct ccwgroup_driver ctc_group_driver = {
3177 .owner = THIS_MODULE,
3180 .driver_id = 0xC3E3C3,
3181 .probe = ctc_probe_device,
3182 .remove = ctc_remove_device,
3183 .set_online = ctc_new_device,
3184 .set_offline = ctc_shutdown_device,
3188 * Module related routines
3189 *****************************************************************************/
3192 * Prepare to be unloaded. Free IRQ's and release all resources.
3193 * This is called just before this module is unloaded. It is
3194 * <em>not</em> called, if the usage count is !0, so we don't need to check
3200 unregister_cu3088_discipline(&ctc_group_driver);
3202 ctc_pr_info("CTC driver unloaded\n");
3206 * Initialize module.
3207 * This is called just after the module is loaded.
3209 * @return 0 on success, !0 on error.
3219 ret = register_cu3088_discipline(&ctc_group_driver);
3225 module_init(ctc_init);
3226 module_exit(ctc_exit);
3228 /* --- This is the END my friend --- */