2 * $Id: ctcmain.c,v 1.78 2005/09/07 12:18:02 pavlic 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 Peter Tiedemann (ptiedem@de.ibm.com)
11 * Driver Model stuff by : Cornelia Huck <cohuck@de.ibm.com>
14 * - Principles of Operation (IBM doc#: SA22-7201-06)
15 * - Common IO/-Device Commands and Self Description (IBM doc#: SA22-7204-02)
16 * - Common IO/-Device Commands and Self Description (IBM doc#: SN22-5535)
17 * - ESCON Channel-to-Channel Adapter (IBM doc#: SA22-7203-00)
18 * - ESCON I/O Interface (IBM doc#: SA22-7202-029
20 * and the source of the original CTC driver by:
21 * Dieter Wellerdiek (wel@de.ibm.com)
22 * Martin Schwidefsky (schwidefsky@de.ibm.com)
23 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
24 * Jochen Röhrig (roehrig@de.ibm.com)
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2, or (at your option)
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40 * RELEASE-TAG: CTC/ESCON network driver $Revision: 1.78 $
44 #include <linux/module.h>
45 #include <linux/init.h>
46 #include <linux/kernel.h>
47 #include <linux/slab.h>
48 #include <linux/errno.h>
49 #include <linux/types.h>
50 #include <linux/interrupt.h>
51 #include <linux/timer.h>
52 #include <linux/sched.h>
53 #include <linux/bitops.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/uaccess.h>
70 #include <asm/idals.h>
79 MODULE_AUTHOR("(C) 2000 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
80 MODULE_DESCRIPTION("Linux for S/390 CTC/Escon Driver");
81 MODULE_LICENSE("GPL");
83 * States of the interface statemachine.
87 DEV_STATE_STARTWAIT_RXTX,
88 DEV_STATE_STARTWAIT_RX,
89 DEV_STATE_STARTWAIT_TX,
90 DEV_STATE_STOPWAIT_RXTX,
91 DEV_STATE_STOPWAIT_RX,
92 DEV_STATE_STOPWAIT_TX,
95 * MUST be always the last element!!
100 static const char *dev_state_names[] = {
112 * Events of the interface statemachine.
123 * MUST be always the last element!!
128 static const char *dev_event_names[] = {
139 * Events of the channel statemachine
143 * Events, representing return code of
144 * I/O operations (ccw_device_start, ccw_device_halt et al.)
157 * Events, representing unit-check
161 CH_EVENT_UC_TXTIMEOUT,
162 CH_EVENT_UC_TXPARITY,
164 CH_EVENT_UC_RXPARITY,
169 * Events, representing subchannel-check
174 * Events, representing machine checks
180 * Event, representing normal IRQ
186 * Event, representing timer expiry.
191 * Events, representing commands from upper levels.
197 * MUST be always the last element!!
203 * States of the channel statemachine.
207 * Channel not assigned to any device,
208 * initial state, direction invalid
213 * Channel assigned but not operating
232 * MUST be always the last element!!
237 static int loglevel = CTC_LOGLEVEL_DEFAULT;
240 * Linked list of all detected channels.
242 static struct channel *channels = NULL;
250 static int printed = 0;
251 char vbuf[] = "$Revision: 1.78 $";
252 char *version = vbuf;
256 if ((version = strchr(version, ':'))) {
257 char *p = strchr(version + 1, '$');
262 printk(KERN_INFO "CTC driver Version%s"
264 " (DEBUG-VERSION, " __DATE__ __TIME__ ")"
266 " initialized\n", version);
271 * Return type of a detected device.
273 static enum channel_types
274 get_channel_type(struct ccw_device_id *id)
276 enum channel_types type = (enum channel_types) id->driver_info;
278 if (type == channel_type_ficon)
279 type = channel_type_escon;
284 static const char *ch_event_names[] = {
285 "ccw_device success",
289 "ccw_device unknown",
291 "Status ATTN & BUSY",
295 "Unit check remote reset",
296 "Unit check remote system reset",
297 "Unit check TX timeout",
298 "Unit check TX parity",
299 "Unit check Hardware failure",
300 "Unit check RX parity",
302 "Unit check Unknown",
304 "SubChannel check Unknown",
306 "Machine check failure",
307 "Machine check operational",
318 static const char *ch_state_names[] = {
339 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
341 * @param skb The sk_buff to dump.
342 * @param offset Offset relative to skb-data, where to start the dump.
345 ctc_dump_skb(struct sk_buff *skb, int offset)
347 unsigned char *p = skb->data;
349 struct ll_header *header;
352 if (!(loglevel & CTC_LOGLEVEL_DEBUG))
357 header = (struct ll_header *) p;
360 printk(KERN_DEBUG "dump:\n");
361 printk(KERN_DEBUG "blocklen=%d %04x\n", bl, bl);
363 printk(KERN_DEBUG "h->length=%d %04x\n", header->length,
365 printk(KERN_DEBUG "h->type=%04x\n", header->type);
366 printk(KERN_DEBUG "h->unused=%04x\n", header->unused);
369 printk(KERN_DEBUG "data: ");
370 for (i = 0; i < bl; i++)
371 printk("%02x%s", *p++, (i % 16) ? " " : "\n<7>");
376 ctc_dump_skb(struct sk_buff *skb, int offset)
382 * Unpack a just received skb and hand it over to
385 * @param ch The channel where this skb has been received.
386 * @param pskb The received skb.
388 static __inline__ void
389 ctc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
391 struct net_device *dev = ch->netdev;
392 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
393 __u16 len = *((__u16 *) pskb->data);
395 DBF_TEXT(trace, 4, __FUNCTION__);
396 skb_put(pskb, 2 + LL_HEADER_LENGTH);
399 pskb->ip_summed = CHECKSUM_UNNECESSARY;
402 struct ll_header *header = (struct ll_header *) pskb->data;
404 skb_pull(pskb, LL_HEADER_LENGTH);
405 if ((ch->protocol == CTC_PROTO_S390) &&
406 (header->type != ETH_P_IP)) {
409 if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
412 * Check packet type only if we stick strictly
413 * to S/390's protocol of OS390. This only
414 * supports IP. Otherwise allow any packet
418 "%s Illegal packet type 0x%04x received, dropping\n",
419 dev->name, header->type);
420 ch->logflags |= LOG_FLAG_ILLEGALPKT;
425 ctc_dump_skb(pskb, -6);
427 privptr->stats.rx_dropped++;
428 privptr->stats.rx_frame_errors++;
431 pskb->protocol = ntohs(header->type);
432 if (header->length <= LL_HEADER_LENGTH) {
434 if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
437 "%s Illegal packet size %d "
438 "received (MTU=%d blocklen=%d), "
439 "dropping\n", dev->name, header->length,
441 ch->logflags |= LOG_FLAG_ILLEGALSIZE;
446 ctc_dump_skb(pskb, -6);
448 privptr->stats.rx_dropped++;
449 privptr->stats.rx_length_errors++;
452 header->length -= LL_HEADER_LENGTH;
453 len -= LL_HEADER_LENGTH;
454 if ((header->length > skb_tailroom(pskb)) ||
455 (header->length > len)) {
457 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
460 "%s Illegal packet size %d "
461 "(beyond the end of received data), "
462 "dropping\n", dev->name, header->length);
463 ch->logflags |= LOG_FLAG_OVERRUN;
468 ctc_dump_skb(pskb, -6);
470 privptr->stats.rx_dropped++;
471 privptr->stats.rx_length_errors++;
474 skb_put(pskb, header->length);
475 pskb->mac.raw = pskb->data;
476 len -= header->length;
477 skb = dev_alloc_skb(pskb->len);
480 if (!(ch->logflags & LOG_FLAG_NOMEM)) {
483 "%s Out of memory in ctc_unpack_skb\n",
485 ch->logflags |= LOG_FLAG_NOMEM;
489 privptr->stats.rx_dropped++;
492 memcpy(skb_put(skb, pskb->len), pskb->data, pskb->len);
493 skb->mac.raw = skb->data;
494 skb->dev = pskb->dev;
495 skb->protocol = pskb->protocol;
496 pskb->ip_summed = CHECKSUM_UNNECESSARY;
497 if (ch->protocol == CTC_PROTO_LINUX_TTY)
498 ctc_tty_netif_rx(skb);
502 * Successful rx; reset logflags
505 dev->last_rx = jiffies;
506 privptr->stats.rx_packets++;
507 privptr->stats.rx_bytes += skb->len;
509 skb_pull(pskb, header->length);
510 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
512 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
515 "%s Overrun in ctc_unpack_skb\n",
517 ch->logflags |= LOG_FLAG_OVERRUN;
523 skb_put(pskb, LL_HEADER_LENGTH);
529 * Check return code of a preceeding ccw_device call, halt_IO etc...
531 * @param ch The channel, the error belongs to.
532 * @param return_code The error code to inspect.
535 ccw_check_return_code(struct channel *ch, int return_code, char *msg)
537 DBF_TEXT(trace, 5, __FUNCTION__);
538 switch (return_code) {
540 fsm_event(ch->fsm, CH_EVENT_IO_SUCCESS, ch);
543 ctc_pr_warn("%s (%s): Busy !\n", ch->id, msg);
544 fsm_event(ch->fsm, CH_EVENT_IO_EBUSY, ch);
547 ctc_pr_emerg("%s (%s): Invalid device called for IO\n",
549 fsm_event(ch->fsm, CH_EVENT_IO_ENODEV, ch);
552 ctc_pr_emerg("%s (%s): Status pending... \n",
554 fsm_event(ch->fsm, CH_EVENT_IO_EIO, ch);
557 ctc_pr_emerg("%s (%s): Unknown error in do_IO %04x\n",
558 ch->id, msg, return_code);
559 fsm_event(ch->fsm, CH_EVENT_IO_UNKNOWN, ch);
564 * Check sense of a unit check.
566 * @param ch The channel, the sense code belongs to.
567 * @param sense The sense code to inspect.
570 ccw_unit_check(struct channel *ch, unsigned char sense)
572 DBF_TEXT(trace, 5, __FUNCTION__);
573 if (sense & SNS0_INTERVENTION_REQ) {
575 if (ch->protocol != CTC_PROTO_LINUX_TTY)
576 ctc_pr_debug("%s: Interface disc. or Sel. reset "
577 "(remote)\n", ch->id);
578 fsm_event(ch->fsm, CH_EVENT_UC_RCRESET, ch);
580 ctc_pr_debug("%s: System reset (remote)\n", ch->id);
581 fsm_event(ch->fsm, CH_EVENT_UC_RSRESET, ch);
583 } else if (sense & SNS0_EQUIPMENT_CHECK) {
584 if (sense & SNS0_BUS_OUT_CHECK) {
585 ctc_pr_warn("%s: Hardware malfunction (remote)\n",
587 fsm_event(ch->fsm, CH_EVENT_UC_HWFAIL, ch);
589 ctc_pr_warn("%s: Read-data parity error (remote)\n",
591 fsm_event(ch->fsm, CH_EVENT_UC_RXPARITY, ch);
593 } else if (sense & SNS0_BUS_OUT_CHECK) {
595 ctc_pr_warn("%s: Data-streaming timeout)\n", ch->id);
596 fsm_event(ch->fsm, CH_EVENT_UC_TXTIMEOUT, ch);
598 ctc_pr_warn("%s: Data-transfer parity error\n", ch->id);
599 fsm_event(ch->fsm, CH_EVENT_UC_TXPARITY, ch);
601 } else if (sense & SNS0_CMD_REJECT) {
602 ctc_pr_warn("%s: Command reject\n", ch->id);
603 } else if (sense == 0) {
604 ctc_pr_debug("%s: Unit check ZERO\n", ch->id);
605 fsm_event(ch->fsm, CH_EVENT_UC_ZERO, ch);
607 ctc_pr_warn("%s: Unit Check with sense code: %02x\n",
609 fsm_event(ch->fsm, CH_EVENT_UC_UNKNOWN, ch);
614 ctc_purge_skb_queue(struct sk_buff_head *q)
618 DBF_TEXT(trace, 5, __FUNCTION__);
620 while ((skb = skb_dequeue(q))) {
621 atomic_dec(&skb->users);
622 dev_kfree_skb_irq(skb);
626 static __inline__ int
627 ctc_checkalloc_buffer(struct channel *ch, int warn)
629 DBF_TEXT(trace, 5, __FUNCTION__);
630 if ((ch->trans_skb == NULL) ||
631 (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED)) {
632 if (ch->trans_skb != NULL)
633 dev_kfree_skb(ch->trans_skb);
634 clear_normalized_cda(&ch->ccw[1]);
635 ch->trans_skb = __dev_alloc_skb(ch->max_bufsize,
636 GFP_ATOMIC | GFP_DMA);
637 if (ch->trans_skb == NULL) {
640 "%s: Couldn't alloc %s trans_skb\n",
642 (CHANNEL_DIRECTION(ch->flags) == READ) ?
646 ch->ccw[1].count = ch->max_bufsize;
647 if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
648 dev_kfree_skb(ch->trans_skb);
649 ch->trans_skb = NULL;
652 "%s: set_normalized_cda for %s "
653 "trans_skb failed, dropping packets\n",
655 (CHANNEL_DIRECTION(ch->flags) == READ) ?
659 ch->ccw[1].count = 0;
660 ch->trans_skb_data = ch->trans_skb->data;
661 ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
667 * Dummy NOP action for statemachines
670 fsm_action_nop(fsm_instance * fi, int event, void *arg)
675 * Actions for channel - statemachines.
676 *****************************************************************************/
679 * Normal data has been send. Free the corresponding
680 * skb (it's in io_queue), reset dev->tbusy and
681 * revert to idle state.
683 * @param fi An instance of a channel statemachine.
684 * @param event The event, just happened.
685 * @param arg Generic pointer, casted from channel * upon call.
688 ch_action_txdone(fsm_instance * fi, int event, void *arg)
690 struct channel *ch = (struct channel *) arg;
691 struct net_device *dev = ch->netdev;
692 struct ctc_priv *privptr = dev->priv;
696 unsigned long duration;
697 struct timespec done_stamp = xtime;
699 DBF_TEXT(trace, 4, __FUNCTION__);
702 (done_stamp.tv_sec - ch->prof.send_stamp.tv_sec) * 1000000 +
703 (done_stamp.tv_nsec - ch->prof.send_stamp.tv_nsec) / 1000;
704 if (duration > ch->prof.tx_time)
705 ch->prof.tx_time = duration;
707 if (ch->irb->scsw.count != 0)
708 ctc_pr_debug("%s: TX not complete, remaining %d bytes\n",
709 dev->name, ch->irb->scsw.count);
710 fsm_deltimer(&ch->timer);
711 while ((skb = skb_dequeue(&ch->io_queue))) {
712 privptr->stats.tx_packets++;
713 privptr->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
715 privptr->stats.tx_bytes += 2;
718 atomic_dec(&skb->users);
719 dev_kfree_skb_irq(skb);
721 spin_lock(&ch->collect_lock);
722 clear_normalized_cda(&ch->ccw[4]);
723 if (ch->collect_len > 0) {
726 if (ctc_checkalloc_buffer(ch, 1)) {
727 spin_unlock(&ch->collect_lock);
730 ch->trans_skb->tail = ch->trans_skb->data = ch->trans_skb_data;
731 ch->trans_skb->len = 0;
732 if (ch->prof.maxmulti < (ch->collect_len + 2))
733 ch->prof.maxmulti = ch->collect_len + 2;
734 if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
735 ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
736 *((__u16 *) skb_put(ch->trans_skb, 2)) = ch->collect_len + 2;
738 while ((skb = skb_dequeue(&ch->collect_queue))) {
739 memcpy(skb_put(ch->trans_skb, skb->len), skb->data,
741 privptr->stats.tx_packets++;
742 privptr->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
743 atomic_dec(&skb->users);
744 dev_kfree_skb_irq(skb);
748 spin_unlock(&ch->collect_lock);
749 ch->ccw[1].count = ch->trans_skb->len;
750 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
751 ch->prof.send_stamp = xtime;
752 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
753 (unsigned long) ch, 0xff, 0);
754 ch->prof.doios_multi++;
756 privptr->stats.tx_dropped += i;
757 privptr->stats.tx_errors += i;
758 fsm_deltimer(&ch->timer);
759 ccw_check_return_code(ch, rc, "chained TX");
762 spin_unlock(&ch->collect_lock);
763 fsm_newstate(fi, CH_STATE_TXIDLE);
769 * Initial data is sent.
770 * Notify device statemachine that we are up and
773 * @param fi An instance of a channel statemachine.
774 * @param event The event, just happened.
775 * @param arg Generic pointer, casted from channel * upon call.
778 ch_action_txidle(fsm_instance * fi, int event, void *arg)
780 struct channel *ch = (struct channel *) arg;
782 DBF_TEXT(trace, 4, __FUNCTION__);
783 fsm_deltimer(&ch->timer);
784 fsm_newstate(fi, CH_STATE_TXIDLE);
785 fsm_event(((struct ctc_priv *) ch->netdev->priv)->fsm, DEV_EVENT_TXUP,
790 * Got normal data, check for sanity, queue it up, allocate new buffer
791 * trigger bottom half, and initiate next read.
793 * @param fi An instance of a channel statemachine.
794 * @param event The event, just happened.
795 * @param arg Generic pointer, casted from channel * upon call.
798 ch_action_rx(fsm_instance * fi, int event, void *arg)
800 struct channel *ch = (struct channel *) arg;
801 struct net_device *dev = ch->netdev;
802 struct ctc_priv *privptr = dev->priv;
803 int len = ch->max_bufsize - ch->irb->scsw.count;
804 struct sk_buff *skb = ch->trans_skb;
805 __u16 block_len = *((__u16 *) skb->data);
809 DBF_TEXT(trace, 4, __FUNCTION__);
810 fsm_deltimer(&ch->timer);
812 ctc_pr_debug("%s: got packet with length %d < 8\n",
814 privptr->stats.rx_dropped++;
815 privptr->stats.rx_length_errors++;
818 if (len > ch->max_bufsize) {
819 ctc_pr_debug("%s: got packet with length %d > %d\n",
820 dev->name, len, ch->max_bufsize);
821 privptr->stats.rx_dropped++;
822 privptr->stats.rx_length_errors++;
827 * VM TCP seems to have a bug sending 2 trailing bytes of garbage.
829 switch (ch->protocol) {
831 case CTC_PROTO_OS390:
832 check_len = block_len + 2;
835 check_len = block_len;
838 if ((len < block_len) || (len > check_len)) {
839 ctc_pr_debug("%s: got block length %d != rx length %d\n",
840 dev->name, block_len, len);
842 ctc_dump_skb(skb, 0);
844 *((__u16 *) skb->data) = len;
845 privptr->stats.rx_dropped++;
846 privptr->stats.rx_length_errors++;
851 *((__u16 *) skb->data) = block_len;
852 ctc_unpack_skb(ch, skb);
855 skb->data = skb->tail = ch->trans_skb_data;
857 if (ctc_checkalloc_buffer(ch, 1))
859 ch->ccw[1].count = ch->max_bufsize;
860 rc = ccw_device_start(ch->cdev, &ch->ccw[0], (unsigned long) ch, 0xff, 0);
862 ccw_check_return_code(ch, rc, "normal RX");
865 static void ch_action_rxidle(fsm_instance * fi, int event, void *arg);
868 * Initialize connection by sending a __u16 of value 0.
870 * @param fi An instance of a channel statemachine.
871 * @param event The event, just happened.
872 * @param arg Generic pointer, casted from channel * upon call.
875 ch_action_firstio(fsm_instance * fi, int event, void *arg)
877 struct channel *ch = (struct channel *) arg;
880 DBF_TEXT(trace, 4, __FUNCTION__);
882 if (fsm_getstate(fi) == CH_STATE_TXIDLE)
883 ctc_pr_debug("%s: remote side issued READ?, init ...\n", ch->id);
884 fsm_deltimer(&ch->timer);
885 if (ctc_checkalloc_buffer(ch, 1))
887 if ((fsm_getstate(fi) == CH_STATE_SETUPWAIT) &&
888 (ch->protocol == CTC_PROTO_OS390)) {
889 /* OS/390 resp. z/OS */
890 if (CHANNEL_DIRECTION(ch->flags) == READ) {
891 *((__u16 *) ch->trans_skb->data) = CTC_INITIAL_BLOCKLEN;
892 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC,
894 ch_action_rxidle(fi, event, arg);
896 struct net_device *dev = ch->netdev;
897 fsm_newstate(fi, CH_STATE_TXIDLE);
898 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
899 DEV_EVENT_TXUP, dev);
905 * Don´t setup a timer for receiving the initial RX frame
906 * if in compatibility mode, since VM TCP delays the initial
907 * frame until it has some data to send.
909 if ((CHANNEL_DIRECTION(ch->flags) == WRITE) ||
910 (ch->protocol != CTC_PROTO_S390))
911 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
913 *((__u16 *) ch->trans_skb->data) = CTC_INITIAL_BLOCKLEN;
914 ch->ccw[1].count = 2; /* Transfer only length */
916 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ)
917 ? CH_STATE_RXINIT : CH_STATE_TXINIT);
918 rc = ccw_device_start(ch->cdev, &ch->ccw[0], (unsigned long) ch, 0xff, 0);
920 fsm_deltimer(&ch->timer);
921 fsm_newstate(fi, CH_STATE_SETUPWAIT);
922 ccw_check_return_code(ch, rc, "init IO");
925 * If in compatibility mode since we don´t setup a timer, we
926 * also signal RX channel up immediately. This enables us
927 * to send packets early which in turn usually triggers some
928 * reply from VM TCP which brings up the RX channel to it´s
931 if ((CHANNEL_DIRECTION(ch->flags) == READ) &&
932 (ch->protocol == CTC_PROTO_S390)) {
933 struct net_device *dev = ch->netdev;
934 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_RXUP,
940 * Got initial data, check it. If OK,
941 * notify device statemachine that we are up and
944 * @param fi An instance of a channel statemachine.
945 * @param event The event, just happened.
946 * @param arg Generic pointer, casted from channel * upon call.
949 ch_action_rxidle(fsm_instance * fi, int event, void *arg)
951 struct channel *ch = (struct channel *) arg;
952 struct net_device *dev = ch->netdev;
956 DBF_TEXT(trace, 4, __FUNCTION__);
957 fsm_deltimer(&ch->timer);
958 buflen = *((__u16 *) ch->trans_skb->data);
960 ctc_pr_debug("%s: Initial RX count %d\n", dev->name, buflen);
962 if (buflen >= CTC_INITIAL_BLOCKLEN) {
963 if (ctc_checkalloc_buffer(ch, 1))
965 ch->ccw[1].count = ch->max_bufsize;
966 fsm_newstate(fi, CH_STATE_RXIDLE);
967 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
968 (unsigned long) ch, 0xff, 0);
970 fsm_newstate(fi, CH_STATE_RXINIT);
971 ccw_check_return_code(ch, rc, "initial RX");
973 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
974 DEV_EVENT_RXUP, dev);
976 ctc_pr_debug("%s: Initial RX count %d not %d\n",
977 dev->name, buflen, CTC_INITIAL_BLOCKLEN);
978 ch_action_firstio(fi, event, arg);
983 * Set channel into extended mode.
985 * @param fi An instance of a channel statemachine.
986 * @param event The event, just happened.
987 * @param arg Generic pointer, casted from channel * upon call.
990 ch_action_setmode(fsm_instance * fi, int event, void *arg)
992 struct channel *ch = (struct channel *) arg;
994 unsigned long saveflags;
996 DBF_TEXT(trace, 4, __FUNCTION__);
997 fsm_deltimer(&ch->timer);
998 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
999 fsm_newstate(fi, CH_STATE_SETUPWAIT);
1000 saveflags = 0; /* avoids compiler warning with
1001 spin_unlock_irqrestore */
1002 if (event == CH_EVENT_TIMER) // only for timer not yet locked
1003 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1004 rc = ccw_device_start(ch->cdev, &ch->ccw[6], (unsigned long) ch, 0xff, 0);
1005 if (event == CH_EVENT_TIMER)
1006 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1008 fsm_deltimer(&ch->timer);
1009 fsm_newstate(fi, CH_STATE_STARTWAIT);
1010 ccw_check_return_code(ch, rc, "set Mode");
1018 * @param fi An instance of a channel statemachine.
1019 * @param event The event, just happened.
1020 * @param arg Generic pointer, casted from channel * upon call.
1023 ch_action_start(fsm_instance * fi, int event, void *arg)
1025 struct channel *ch = (struct channel *) arg;
1026 unsigned long saveflags;
1028 struct net_device *dev;
1030 DBF_TEXT(trace, 4, __FUNCTION__);
1032 ctc_pr_warn("ch_action_start ch=NULL\n");
1035 if (ch->netdev == NULL) {
1036 ctc_pr_warn("ch_action_start dev=NULL, id=%s\n", ch->id);
1042 ctc_pr_debug("%s: %s channel start\n", dev->name,
1043 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
1046 if (ch->trans_skb != NULL) {
1047 clear_normalized_cda(&ch->ccw[1]);
1048 dev_kfree_skb(ch->trans_skb);
1049 ch->trans_skb = NULL;
1051 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1052 ch->ccw[1].cmd_code = CCW_CMD_READ;
1053 ch->ccw[1].flags = CCW_FLAG_SLI;
1054 ch->ccw[1].count = 0;
1056 ch->ccw[1].cmd_code = CCW_CMD_WRITE;
1057 ch->ccw[1].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1058 ch->ccw[1].count = 0;
1060 if (ctc_checkalloc_buffer(ch, 0)) {
1062 "%s: Could not allocate %s trans_skb, delaying "
1063 "allocation until first transfer\n",
1065 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
1068 ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
1069 ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1070 ch->ccw[0].count = 0;
1072 ch->ccw[2].cmd_code = CCW_CMD_NOOP; /* jointed CE + DE */
1073 ch->ccw[2].flags = CCW_FLAG_SLI;
1074 ch->ccw[2].count = 0;
1076 memcpy(&ch->ccw[3], &ch->ccw[0], sizeof (struct ccw1) * 3);
1078 ch->ccw[4].flags &= ~CCW_FLAG_IDA;
1080 fsm_newstate(fi, CH_STATE_STARTWAIT);
1081 fsm_addtimer(&ch->timer, 1000, CH_EVENT_TIMER, ch);
1082 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1083 rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1084 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1087 fsm_deltimer(&ch->timer);
1088 ccw_check_return_code(ch, rc, "initial HaltIO");
1091 ctc_pr_debug("ctc: %s(): leaving\n", __func__);
1096 * Shutdown a channel.
1098 * @param fi An instance of a channel statemachine.
1099 * @param event The event, just happened.
1100 * @param arg Generic pointer, casted from channel * upon call.
1103 ch_action_haltio(fsm_instance * fi, int event, void *arg)
1105 struct channel *ch = (struct channel *) arg;
1106 unsigned long saveflags;
1110 DBF_TEXT(trace, 3, __FUNCTION__);
1111 fsm_deltimer(&ch->timer);
1112 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1113 saveflags = 0; /* avoids comp warning with
1114 spin_unlock_irqrestore */
1115 if (event == CH_EVENT_STOP) // only for STOP not yet locked
1116 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1117 oldstate = fsm_getstate(fi);
1118 fsm_newstate(fi, CH_STATE_TERM);
1119 rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1120 if (event == CH_EVENT_STOP)
1121 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1124 fsm_deltimer(&ch->timer);
1125 fsm_newstate(fi, oldstate);
1127 ccw_check_return_code(ch, rc, "HaltIO in ch_action_haltio");
1132 * A channel has successfully been halted.
1133 * Cleanup it's queue and notify interface statemachine.
1135 * @param fi An instance of a channel statemachine.
1136 * @param event The event, just happened.
1137 * @param arg Generic pointer, casted from channel * upon call.
1140 ch_action_stopped(fsm_instance * fi, int event, void *arg)
1142 struct channel *ch = (struct channel *) arg;
1143 struct net_device *dev = ch->netdev;
1145 DBF_TEXT(trace, 3, __FUNCTION__);
1146 fsm_deltimer(&ch->timer);
1147 fsm_newstate(fi, CH_STATE_STOPPED);
1148 if (ch->trans_skb != NULL) {
1149 clear_normalized_cda(&ch->ccw[1]);
1150 dev_kfree_skb(ch->trans_skb);
1151 ch->trans_skb = NULL;
1153 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1154 skb_queue_purge(&ch->io_queue);
1155 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1156 DEV_EVENT_RXDOWN, dev);
1158 ctc_purge_skb_queue(&ch->io_queue);
1159 spin_lock(&ch->collect_lock);
1160 ctc_purge_skb_queue(&ch->collect_queue);
1161 ch->collect_len = 0;
1162 spin_unlock(&ch->collect_lock);
1163 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1164 DEV_EVENT_TXDOWN, dev);
1169 * A stop command from device statemachine arrived and we are in
1170 * not operational mode. Set state to stopped.
1172 * @param fi An instance of a channel statemachine.
1173 * @param event The event, just happened.
1174 * @param arg Generic pointer, casted from channel * upon call.
1177 ch_action_stop(fsm_instance * fi, int event, void *arg)
1179 fsm_newstate(fi, CH_STATE_STOPPED);
1183 * A machine check for no path, not operational status or gone device has
1185 * Cleanup queue and notify interface statemachine.
1187 * @param fi An instance of a channel statemachine.
1188 * @param event The event, just happened.
1189 * @param arg Generic pointer, casted from channel * upon call.
1192 ch_action_fail(fsm_instance * fi, int event, void *arg)
1194 struct channel *ch = (struct channel *) arg;
1195 struct net_device *dev = ch->netdev;
1197 DBF_TEXT(trace, 3, __FUNCTION__);
1198 fsm_deltimer(&ch->timer);
1199 fsm_newstate(fi, CH_STATE_NOTOP);
1200 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1201 skb_queue_purge(&ch->io_queue);
1202 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1203 DEV_EVENT_RXDOWN, dev);
1205 ctc_purge_skb_queue(&ch->io_queue);
1206 spin_lock(&ch->collect_lock);
1207 ctc_purge_skb_queue(&ch->collect_queue);
1208 ch->collect_len = 0;
1209 spin_unlock(&ch->collect_lock);
1210 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1211 DEV_EVENT_TXDOWN, dev);
1216 * Handle error during setup of channel.
1218 * @param fi An instance of a channel statemachine.
1219 * @param event The event, just happened.
1220 * @param arg Generic pointer, casted from channel * upon call.
1223 ch_action_setuperr(fsm_instance * fi, int event, void *arg)
1225 struct channel *ch = (struct channel *) arg;
1226 struct net_device *dev = ch->netdev;
1228 DBF_TEXT(setup, 3, __FUNCTION__);
1230 * Special case: Got UC_RCRESET on setmode.
1231 * This means that remote side isn't setup. In this case
1232 * simply retry after some 10 secs...
1234 if ((fsm_getstate(fi) == CH_STATE_SETUPWAIT) &&
1235 ((event == CH_EVENT_UC_RCRESET) ||
1236 (event == CH_EVENT_UC_RSRESET))) {
1237 fsm_newstate(fi, CH_STATE_STARTRETRY);
1238 fsm_deltimer(&ch->timer);
1239 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1240 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1241 int rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1243 ccw_check_return_code(
1244 ch, rc, "HaltIO in ch_action_setuperr");
1249 ctc_pr_debug("%s: Error %s during %s channel setup state=%s\n",
1250 dev->name, ch_event_names[event],
1251 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX",
1252 fsm_getstate_str(fi));
1253 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1254 fsm_newstate(fi, CH_STATE_RXERR);
1255 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1256 DEV_EVENT_RXDOWN, dev);
1258 fsm_newstate(fi, CH_STATE_TXERR);
1259 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1260 DEV_EVENT_TXDOWN, dev);
1265 * Restart a channel after an error.
1267 * @param fi An instance of a channel statemachine.
1268 * @param event The event, just happened.
1269 * @param arg Generic pointer, casted from channel * upon call.
1272 ch_action_restart(fsm_instance * fi, int event, void *arg)
1274 unsigned long saveflags;
1278 struct channel *ch = (struct channel *) arg;
1279 struct net_device *dev = ch->netdev;
1281 DBF_TEXT(trace, 3, __FUNCTION__);
1282 fsm_deltimer(&ch->timer);
1283 ctc_pr_debug("%s: %s channel restart\n", dev->name,
1284 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
1285 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
1286 oldstate = fsm_getstate(fi);
1287 fsm_newstate(fi, CH_STATE_STARTWAIT);
1288 saveflags = 0; /* avoids compiler warning with
1289 spin_unlock_irqrestore */
1290 if (event == CH_EVENT_TIMER) // only for timer not yet locked
1291 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1292 rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
1293 if (event == CH_EVENT_TIMER)
1294 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1297 fsm_deltimer(&ch->timer);
1298 fsm_newstate(fi, oldstate);
1300 ccw_check_return_code(ch, rc, "HaltIO in ch_action_restart");
1305 * Handle error during RX initial handshake (exchange of
1306 * 0-length block header)
1308 * @param fi An instance of a channel statemachine.
1309 * @param event The event, just happened.
1310 * @param arg Generic pointer, casted from channel * upon call.
1313 ch_action_rxiniterr(fsm_instance * fi, int event, void *arg)
1315 struct channel *ch = (struct channel *) arg;
1316 struct net_device *dev = ch->netdev;
1318 DBF_TEXT(setup, 3, __FUNCTION__);
1319 if (event == CH_EVENT_TIMER) {
1320 fsm_deltimer(&ch->timer);
1321 ctc_pr_debug("%s: Timeout during RX init handshake\n", dev->name);
1322 if (ch->retry++ < 3)
1323 ch_action_restart(fi, event, arg);
1325 fsm_newstate(fi, CH_STATE_RXERR);
1326 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1327 DEV_EVENT_RXDOWN, dev);
1330 ctc_pr_warn("%s: Error during RX init handshake\n", dev->name);
1334 * Notify device statemachine if we gave up initialization
1337 * @param fi An instance of a channel statemachine.
1338 * @param event The event, just happened.
1339 * @param arg Generic pointer, casted from channel * upon call.
1342 ch_action_rxinitfail(fsm_instance * fi, int event, void *arg)
1344 struct channel *ch = (struct channel *) arg;
1345 struct net_device *dev = ch->netdev;
1347 DBF_TEXT(setup, 3, __FUNCTION__);
1348 fsm_newstate(fi, CH_STATE_RXERR);
1349 ctc_pr_warn("%s: RX initialization failed\n", dev->name);
1350 ctc_pr_warn("%s: RX <-> RX connection detected\n", dev->name);
1351 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_RXDOWN, dev);
1355 * Handle RX Unit check remote reset (remote disconnected)
1357 * @param fi An instance of a channel statemachine.
1358 * @param event The event, just happened.
1359 * @param arg Generic pointer, casted from channel * upon call.
1362 ch_action_rxdisc(fsm_instance * fi, int event, void *arg)
1364 struct channel *ch = (struct channel *) arg;
1365 struct channel *ch2;
1366 struct net_device *dev = ch->netdev;
1368 DBF_TEXT(trace, 3, __FUNCTION__);
1369 fsm_deltimer(&ch->timer);
1370 ctc_pr_debug("%s: Got remote disconnect, re-initializing ...\n",
1374 * Notify device statemachine
1376 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_RXDOWN, dev);
1377 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_TXDOWN, dev);
1379 fsm_newstate(fi, CH_STATE_DTERM);
1380 ch2 = ((struct ctc_priv *) dev->priv)->channel[WRITE];
1381 fsm_newstate(ch2->fsm, CH_STATE_DTERM);
1383 ccw_device_halt(ch->cdev, (unsigned long) ch);
1384 ccw_device_halt(ch2->cdev, (unsigned long) ch2);
1388 * Handle error during TX channel initialization.
1390 * @param fi An instance of a channel statemachine.
1391 * @param event The event, just happened.
1392 * @param arg Generic pointer, casted from channel * upon call.
1395 ch_action_txiniterr(fsm_instance * fi, int event, void *arg)
1397 struct channel *ch = (struct channel *) arg;
1398 struct net_device *dev = ch->netdev;
1400 DBF_TEXT(setup, 2, __FUNCTION__);
1401 if (event == CH_EVENT_TIMER) {
1402 fsm_deltimer(&ch->timer);
1403 ctc_pr_debug("%s: Timeout during TX init handshake\n", dev->name);
1404 if (ch->retry++ < 3)
1405 ch_action_restart(fi, event, arg);
1407 fsm_newstate(fi, CH_STATE_TXERR);
1408 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1409 DEV_EVENT_TXDOWN, dev);
1412 ctc_pr_warn("%s: Error during TX init handshake\n", dev->name);
1416 * Handle TX timeout by retrying operation.
1418 * @param fi An instance of a channel statemachine.
1419 * @param event The event, just happened.
1420 * @param arg Generic pointer, casted from channel * upon call.
1423 ch_action_txretry(fsm_instance * fi, int event, void *arg)
1425 struct channel *ch = (struct channel *) arg;
1426 struct net_device *dev = ch->netdev;
1427 unsigned long saveflags;
1429 DBF_TEXT(trace, 4, __FUNCTION__);
1430 fsm_deltimer(&ch->timer);
1431 if (ch->retry++ > 3) {
1432 ctc_pr_debug("%s: TX retry failed, restarting channel\n",
1434 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1435 DEV_EVENT_TXDOWN, dev);
1436 ch_action_restart(fi, event, arg);
1438 struct sk_buff *skb;
1440 ctc_pr_debug("%s: TX retry %d\n", dev->name, ch->retry);
1441 if ((skb = skb_peek(&ch->io_queue))) {
1444 clear_normalized_cda(&ch->ccw[4]);
1445 ch->ccw[4].count = skb->len;
1446 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
1448 "%s: IDAL alloc failed, chan restart\n",
1450 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1451 DEV_EVENT_TXDOWN, dev);
1452 ch_action_restart(fi, event, arg);
1455 fsm_addtimer(&ch->timer, 1000, CH_EVENT_TIMER, ch);
1456 saveflags = 0; /* avoids compiler warning with
1457 spin_unlock_irqrestore */
1458 if (event == CH_EVENT_TIMER) // only for TIMER not yet locked
1459 spin_lock_irqsave(get_ccwdev_lock(ch->cdev),
1461 rc = ccw_device_start(ch->cdev, &ch->ccw[3],
1462 (unsigned long) ch, 0xff, 0);
1463 if (event == CH_EVENT_TIMER)
1464 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev),
1467 fsm_deltimer(&ch->timer);
1468 ccw_check_return_code(ch, rc, "TX in ch_action_txretry");
1469 ctc_purge_skb_queue(&ch->io_queue);
1477 * Handle fatal errors during an I/O command.
1479 * @param fi An instance of a channel statemachine.
1480 * @param event The event, just happened.
1481 * @param arg Generic pointer, casted from channel * upon call.
1484 ch_action_iofatal(fsm_instance * fi, int event, void *arg)
1486 struct channel *ch = (struct channel *) arg;
1487 struct net_device *dev = ch->netdev;
1489 DBF_TEXT(trace, 3, __FUNCTION__);
1490 fsm_deltimer(&ch->timer);
1491 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1492 ctc_pr_debug("%s: RX I/O error\n", dev->name);
1493 fsm_newstate(fi, CH_STATE_RXERR);
1494 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1495 DEV_EVENT_RXDOWN, dev);
1497 ctc_pr_debug("%s: TX I/O error\n", dev->name);
1498 fsm_newstate(fi, CH_STATE_TXERR);
1499 fsm_event(((struct ctc_priv *) dev->priv)->fsm,
1500 DEV_EVENT_TXDOWN, dev);
1505 ch_action_reinit(fsm_instance *fi, int event, void *arg)
1507 struct channel *ch = (struct channel *)arg;
1508 struct net_device *dev = ch->netdev;
1509 struct ctc_priv *privptr = dev->priv;
1511 DBF_TEXT(trace, 4, __FUNCTION__);
1512 ch_action_iofatal(fi, event, arg);
1513 fsm_addtimer(&privptr->restart_timer, 1000, DEV_EVENT_RESTART, dev);
1517 * The statemachine for a channel.
1519 static const fsm_node ch_fsm[] = {
1520 {CH_STATE_STOPPED, CH_EVENT_STOP, fsm_action_nop },
1521 {CH_STATE_STOPPED, CH_EVENT_START, ch_action_start },
1522 {CH_STATE_STOPPED, CH_EVENT_FINSTAT, fsm_action_nop },
1523 {CH_STATE_STOPPED, CH_EVENT_MC_FAIL, fsm_action_nop },
1525 {CH_STATE_NOTOP, CH_EVENT_STOP, ch_action_stop },
1526 {CH_STATE_NOTOP, CH_EVENT_START, fsm_action_nop },
1527 {CH_STATE_NOTOP, CH_EVENT_FINSTAT, fsm_action_nop },
1528 {CH_STATE_NOTOP, CH_EVENT_MC_FAIL, fsm_action_nop },
1529 {CH_STATE_NOTOP, CH_EVENT_MC_GOOD, ch_action_start },
1531 {CH_STATE_STARTWAIT, CH_EVENT_STOP, ch_action_haltio },
1532 {CH_STATE_STARTWAIT, CH_EVENT_START, fsm_action_nop },
1533 {CH_STATE_STARTWAIT, CH_EVENT_FINSTAT, ch_action_setmode },
1534 {CH_STATE_STARTWAIT, CH_EVENT_TIMER, ch_action_setuperr },
1535 {CH_STATE_STARTWAIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1536 {CH_STATE_STARTWAIT, CH_EVENT_IO_EIO, ch_action_reinit },
1537 {CH_STATE_STARTWAIT, CH_EVENT_MC_FAIL, ch_action_fail },
1539 {CH_STATE_STARTRETRY, CH_EVENT_STOP, ch_action_haltio },
1540 {CH_STATE_STARTRETRY, CH_EVENT_TIMER, ch_action_setmode },
1541 {CH_STATE_STARTRETRY, CH_EVENT_FINSTAT, fsm_action_nop },
1542 {CH_STATE_STARTRETRY, CH_EVENT_MC_FAIL, ch_action_fail },
1544 {CH_STATE_SETUPWAIT, CH_EVENT_STOP, ch_action_haltio },
1545 {CH_STATE_SETUPWAIT, CH_EVENT_START, fsm_action_nop },
1546 {CH_STATE_SETUPWAIT, CH_EVENT_FINSTAT, ch_action_firstio },
1547 {CH_STATE_SETUPWAIT, CH_EVENT_UC_RCRESET, ch_action_setuperr },
1548 {CH_STATE_SETUPWAIT, CH_EVENT_UC_RSRESET, ch_action_setuperr },
1549 {CH_STATE_SETUPWAIT, CH_EVENT_TIMER, ch_action_setmode },
1550 {CH_STATE_SETUPWAIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1551 {CH_STATE_SETUPWAIT, CH_EVENT_IO_EIO, ch_action_reinit },
1552 {CH_STATE_SETUPWAIT, CH_EVENT_MC_FAIL, ch_action_fail },
1554 {CH_STATE_RXINIT, CH_EVENT_STOP, ch_action_haltio },
1555 {CH_STATE_RXINIT, CH_EVENT_START, fsm_action_nop },
1556 {CH_STATE_RXINIT, CH_EVENT_FINSTAT, ch_action_rxidle },
1557 {CH_STATE_RXINIT, CH_EVENT_UC_RCRESET, ch_action_rxiniterr },
1558 {CH_STATE_RXINIT, CH_EVENT_UC_RSRESET, ch_action_rxiniterr },
1559 {CH_STATE_RXINIT, CH_EVENT_TIMER, ch_action_rxiniterr },
1560 {CH_STATE_RXINIT, CH_EVENT_ATTNBUSY, ch_action_rxinitfail },
1561 {CH_STATE_RXINIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1562 {CH_STATE_RXINIT, CH_EVENT_IO_EIO, ch_action_reinit },
1563 {CH_STATE_RXINIT, CH_EVENT_UC_ZERO, ch_action_firstio },
1564 {CH_STATE_RXINIT, CH_EVENT_MC_FAIL, ch_action_fail },
1566 {CH_STATE_RXIDLE, CH_EVENT_STOP, ch_action_haltio },
1567 {CH_STATE_RXIDLE, CH_EVENT_START, fsm_action_nop },
1568 {CH_STATE_RXIDLE, CH_EVENT_FINSTAT, ch_action_rx },
1569 {CH_STATE_RXIDLE, CH_EVENT_UC_RCRESET, ch_action_rxdisc },
1570 // {CH_STATE_RXIDLE, CH_EVENT_UC_RSRESET, ch_action_rxretry },
1571 {CH_STATE_RXIDLE, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1572 {CH_STATE_RXIDLE, CH_EVENT_IO_EIO, ch_action_reinit },
1573 {CH_STATE_RXIDLE, CH_EVENT_MC_FAIL, ch_action_fail },
1574 {CH_STATE_RXIDLE, CH_EVENT_UC_ZERO, ch_action_rx },
1576 {CH_STATE_TXINIT, CH_EVENT_STOP, ch_action_haltio },
1577 {CH_STATE_TXINIT, CH_EVENT_START, fsm_action_nop },
1578 {CH_STATE_TXINIT, CH_EVENT_FINSTAT, ch_action_txidle },
1579 {CH_STATE_TXINIT, CH_EVENT_UC_RCRESET, ch_action_txiniterr },
1580 {CH_STATE_TXINIT, CH_EVENT_UC_RSRESET, ch_action_txiniterr },
1581 {CH_STATE_TXINIT, CH_EVENT_TIMER, ch_action_txiniterr },
1582 {CH_STATE_TXINIT, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1583 {CH_STATE_TXINIT, CH_EVENT_IO_EIO, ch_action_reinit },
1584 {CH_STATE_TXINIT, CH_EVENT_MC_FAIL, ch_action_fail },
1586 {CH_STATE_TXIDLE, CH_EVENT_STOP, ch_action_haltio },
1587 {CH_STATE_TXIDLE, CH_EVENT_START, fsm_action_nop },
1588 {CH_STATE_TXIDLE, CH_EVENT_FINSTAT, ch_action_firstio },
1589 {CH_STATE_TXIDLE, CH_EVENT_UC_RCRESET, fsm_action_nop },
1590 {CH_STATE_TXIDLE, CH_EVENT_UC_RSRESET, fsm_action_nop },
1591 {CH_STATE_TXIDLE, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1592 {CH_STATE_TXIDLE, CH_EVENT_IO_EIO, ch_action_reinit },
1593 {CH_STATE_TXIDLE, CH_EVENT_MC_FAIL, ch_action_fail },
1595 {CH_STATE_TERM, CH_EVENT_STOP, fsm_action_nop },
1596 {CH_STATE_TERM, CH_EVENT_START, ch_action_restart },
1597 {CH_STATE_TERM, CH_EVENT_FINSTAT, ch_action_stopped },
1598 {CH_STATE_TERM, CH_EVENT_UC_RCRESET, fsm_action_nop },
1599 {CH_STATE_TERM, CH_EVENT_UC_RSRESET, fsm_action_nop },
1600 {CH_STATE_TERM, CH_EVENT_MC_FAIL, ch_action_fail },
1602 {CH_STATE_DTERM, CH_EVENT_STOP, ch_action_haltio },
1603 {CH_STATE_DTERM, CH_EVENT_START, ch_action_restart },
1604 {CH_STATE_DTERM, CH_EVENT_FINSTAT, ch_action_setmode },
1605 {CH_STATE_DTERM, CH_EVENT_UC_RCRESET, fsm_action_nop },
1606 {CH_STATE_DTERM, CH_EVENT_UC_RSRESET, fsm_action_nop },
1607 {CH_STATE_DTERM, CH_EVENT_MC_FAIL, ch_action_fail },
1609 {CH_STATE_TX, CH_EVENT_STOP, ch_action_haltio },
1610 {CH_STATE_TX, CH_EVENT_START, fsm_action_nop },
1611 {CH_STATE_TX, CH_EVENT_FINSTAT, ch_action_txdone },
1612 {CH_STATE_TX, CH_EVENT_UC_RCRESET, ch_action_txretry },
1613 {CH_STATE_TX, CH_EVENT_UC_RSRESET, ch_action_txretry },
1614 {CH_STATE_TX, CH_EVENT_TIMER, ch_action_txretry },
1615 {CH_STATE_TX, CH_EVENT_IO_ENODEV, ch_action_iofatal },
1616 {CH_STATE_TX, CH_EVENT_IO_EIO, ch_action_reinit },
1617 {CH_STATE_TX, CH_EVENT_MC_FAIL, ch_action_fail },
1619 {CH_STATE_RXERR, CH_EVENT_STOP, ch_action_haltio },
1620 {CH_STATE_TXERR, CH_EVENT_STOP, ch_action_haltio },
1621 {CH_STATE_TXERR, CH_EVENT_MC_FAIL, ch_action_fail },
1622 {CH_STATE_RXERR, CH_EVENT_MC_FAIL, ch_action_fail },
1625 static const int CH_FSM_LEN = sizeof (ch_fsm) / sizeof (fsm_node);
1628 * Functions related to setup and device detection.
1629 *****************************************************************************/
1632 less_than(char *id1, char *id2)
1636 for (i = 0; i < 5; i++) {
1640 dev1 = simple_strtoul(id1, &id1, 16);
1641 dev2 = simple_strtoul(id2, &id2, 16);
1643 return (dev1 < dev2);
1647 * Add a new channel to the list of channels.
1648 * Keeps the channel list sorted.
1650 * @param cdev The ccw_device to be added.
1651 * @param type The type class of the new channel.
1653 * @return 0 on success, !0 on error.
1656 add_channel(struct ccw_device *cdev, enum channel_types type)
1658 struct channel **c = &channels;
1661 DBF_TEXT(trace, 2, __FUNCTION__);
1663 (struct channel *) kmalloc(sizeof (struct channel),
1664 GFP_KERNEL)) == NULL) {
1665 ctc_pr_warn("ctc: Out of memory in add_channel\n");
1668 memset(ch, 0, sizeof (struct channel));
1669 if ((ch->ccw = (struct ccw1 *) kmalloc(8*sizeof(struct ccw1),
1670 GFP_KERNEL | GFP_DMA)) == NULL) {
1672 ctc_pr_warn("ctc: Out of memory in add_channel\n");
1676 memset(ch->ccw, 0, 8*sizeof(struct ccw1)); // assure all flags and counters are reset
1679 * "static" ccws are used in the following way:
1681 * ccw[0..2] (Channel program for generic I/O):
1683 * 1: read or write (depending on direction) with fixed
1684 * buffer (idal allocated once when buffer is allocated)
1686 * ccw[3..5] (Channel program for direct write of packets)
1688 * 4: write (idal allocated on every write).
1690 * ccw[6..7] (Channel program for initial channel setup):
1691 * 6: set extended mode
1694 * ch->ccw[0..5] are initialized in ch_action_start because
1695 * the channel's direction is yet unknown here.
1697 ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED;
1698 ch->ccw[6].flags = CCW_FLAG_SLI;
1700 ch->ccw[7].cmd_code = CCW_CMD_NOOP;
1701 ch->ccw[7].flags = CCW_FLAG_SLI;
1704 snprintf(ch->id, CTC_ID_SIZE, "ch-%s", cdev->dev.bus_id);
1706 ch->fsm = init_fsm(ch->id, ch_state_names,
1707 ch_event_names, NR_CH_STATES, NR_CH_EVENTS,
1708 ch_fsm, CH_FSM_LEN, GFP_KERNEL);
1709 if (ch->fsm == NULL) {
1710 ctc_pr_warn("ctc: Could not create FSM in add_channel\n");
1715 fsm_newstate(ch->fsm, CH_STATE_IDLE);
1716 if ((ch->irb = (struct irb *) kmalloc(sizeof (struct irb),
1717 GFP_KERNEL)) == NULL) {
1718 ctc_pr_warn("ctc: Out of memory in add_channel\n");
1724 memset(ch->irb, 0, sizeof (struct irb));
1725 while (*c && less_than((*c)->id, ch->id))
1727 if (*c && (!strncmp((*c)->id, ch->id, CTC_ID_SIZE))) {
1729 "ctc: add_channel: device %s already in list, "
1730 "using old entry\n", (*c)->id);
1737 fsm_settimer(ch->fsm, &ch->timer);
1738 skb_queue_head_init(&ch->io_queue);
1739 skb_queue_head_init(&ch->collect_queue);
1746 * Release a specific channel in the channel list.
1748 * @param ch Pointer to channel struct to be released.
1751 channel_free(struct channel *ch)
1753 ch->flags &= ~CHANNEL_FLAGS_INUSE;
1754 fsm_newstate(ch->fsm, CH_STATE_IDLE);
1758 * Remove a specific channel in the channel list.
1760 * @param ch Pointer to channel struct to be released.
1763 channel_remove(struct channel *ch)
1765 struct channel **c = &channels;
1767 DBF_TEXT(trace, 2, __FUNCTION__);
1775 fsm_deltimer(&ch->timer);
1777 clear_normalized_cda(&ch->ccw[4]);
1778 if (ch->trans_skb != NULL) {
1779 clear_normalized_cda(&ch->ccw[1]);
1780 dev_kfree_skb(ch->trans_skb);
1792 * Get a specific channel from the channel list.
1794 * @param type Type of channel we are interested in.
1795 * @param id Id of channel we are interested in.
1796 * @param direction Direction we want to use this channel for.
1798 * @return Pointer to a channel or NULL if no matching channel available.
1800 static struct channel
1802 channel_get(enum channel_types type, char *id, int direction)
1804 struct channel *ch = channels;
1806 DBF_TEXT(trace, 3, __FUNCTION__);
1808 ctc_pr_debug("ctc: %s(): searching for ch with id %s and type %d\n",
1809 __func__, id, type);
1812 while (ch && ((strncmp(ch->id, id, CTC_ID_SIZE)) || (ch->type != type))) {
1814 ctc_pr_debug("ctc: %s(): ch=0x%p (id=%s, type=%d\n",
1815 __func__, ch, ch->id, ch->type);
1820 ctc_pr_debug("ctc: %s(): ch=0x%pq (id=%s, type=%d\n",
1821 __func__, ch, ch->id, ch->type);
1824 ctc_pr_warn("ctc: %s(): channel with id %s "
1825 "and type %d not found in channel list\n",
1826 __func__, id, type);
1828 if (ch->flags & CHANNEL_FLAGS_INUSE)
1831 ch->flags |= CHANNEL_FLAGS_INUSE;
1832 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
1833 ch->flags |= (direction == WRITE)
1834 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
1835 fsm_newstate(ch->fsm, CH_STATE_STOPPED);
1842 * Return the channel type by name.
1844 * @param name Name of network interface.
1846 * @return Type class of channel to be used for that interface.
1848 static enum channel_types inline
1849 extract_channel_media(char *name)
1851 enum channel_types ret = channel_type_unknown;
1854 if (strncmp(name, "ctc", 3) == 0)
1855 ret = channel_type_parallel;
1856 if (strncmp(name, "escon", 5) == 0)
1857 ret = channel_type_escon;
1863 __ctc_check_irb_error(struct ccw_device *cdev, struct irb *irb)
1868 switch (PTR_ERR(irb)) {
1870 ctc_pr_warn("i/o-error on device %s\n", cdev->dev.bus_id);
1871 // CTC_DBF_TEXT(trace, 2, "ckirberr");
1872 // CTC_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1875 ctc_pr_warn("timeout on device %s\n", cdev->dev.bus_id);
1876 // CTC_DBF_TEXT(trace, 2, "ckirberr");
1877 // CTC_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
1880 ctc_pr_warn("unknown error %ld on device %s\n", PTR_ERR(irb),
1882 // CTC_DBF_TEXT(trace, 2, "ckirberr");
1883 // CTC_DBF_TEXT(trace, 2, " rc???");
1885 return PTR_ERR(irb);
1891 * @param cdev The ccw_device the interrupt is for.
1892 * @param intparm interruption parameter.
1893 * @param irb interruption response block.
1896 ctc_irq_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1899 struct net_device *dev;
1900 struct ctc_priv *priv;
1902 DBF_TEXT(trace, 5, __FUNCTION__);
1903 if (__ctc_check_irb_error(cdev, irb))
1906 /* Check for unsolicited interrupts. */
1907 if (!cdev->dev.driver_data) {
1908 ctc_pr_warn("ctc: Got unsolicited irq: %s c-%02x d-%02x\n",
1909 cdev->dev.bus_id, irb->scsw.cstat,
1914 priv = ((struct ccwgroup_device *)cdev->dev.driver_data)
1917 /* Try to extract channel from driver data. */
1918 if (priv->channel[READ]->cdev == cdev)
1919 ch = priv->channel[READ];
1920 else if (priv->channel[WRITE]->cdev == cdev)
1921 ch = priv->channel[WRITE];
1923 ctc_pr_err("ctc: Can't determine channel for interrupt, "
1924 "device %s\n", cdev->dev.bus_id);
1928 dev = (struct net_device *) (ch->netdev);
1930 ctc_pr_crit("ctc: ctc_irq_handler dev=NULL bus_id=%s, ch=0x%p\n",
1931 cdev->dev.bus_id, ch);
1936 ctc_pr_debug("%s: interrupt for device: %s received c-%02x d-%02x\n",
1937 dev->name, ch->id, irb->scsw.cstat, irb->scsw.dstat);
1940 /* Copy interruption response block. */
1941 memcpy(ch->irb, irb, sizeof(struct irb));
1943 /* Check for good subchannel return code, otherwise error message */
1944 if (ch->irb->scsw.cstat) {
1945 fsm_event(ch->fsm, CH_EVENT_SC_UNKNOWN, ch);
1946 ctc_pr_warn("%s: subchannel check for device: %s - %02x %02x\n",
1947 dev->name, ch->id, ch->irb->scsw.cstat,
1948 ch->irb->scsw.dstat);
1952 /* Check the reason-code of a unit check */
1953 if (ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
1954 ccw_unit_check(ch, ch->irb->ecw[0]);
1957 if (ch->irb->scsw.dstat & DEV_STAT_BUSY) {
1958 if (ch->irb->scsw.dstat & DEV_STAT_ATTENTION)
1959 fsm_event(ch->fsm, CH_EVENT_ATTNBUSY, ch);
1961 fsm_event(ch->fsm, CH_EVENT_BUSY, ch);
1964 if (ch->irb->scsw.dstat & DEV_STAT_ATTENTION) {
1965 fsm_event(ch->fsm, CH_EVENT_ATTN, ch);
1968 if ((ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
1969 (ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
1970 (ch->irb->scsw.stctl ==
1971 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
1972 fsm_event(ch->fsm, CH_EVENT_FINSTAT, ch);
1974 fsm_event(ch->fsm, CH_EVENT_IRQ, ch);
1979 * Actions for interface - statemachine.
1980 *****************************************************************************/
1983 * Startup channels by sending CH_EVENT_START to each channel.
1985 * @param fi An instance of an interface statemachine.
1986 * @param event The event, just happened.
1987 * @param arg Generic pointer, casted from struct net_device * upon call.
1990 dev_action_start(fsm_instance * fi, int event, void *arg)
1992 struct net_device *dev = (struct net_device *) arg;
1993 struct ctc_priv *privptr = dev->priv;
1996 DBF_TEXT(setup, 3, __FUNCTION__);
1997 fsm_deltimer(&privptr->restart_timer);
1998 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
1999 for (direction = READ; direction <= WRITE; direction++) {
2000 struct channel *ch = privptr->channel[direction];
2001 fsm_event(ch->fsm, CH_EVENT_START, ch);
2006 * Shutdown channels by sending CH_EVENT_STOP to each channel.
2008 * @param fi An instance of an interface statemachine.
2009 * @param event The event, just happened.
2010 * @param arg Generic pointer, casted from struct net_device * upon call.
2013 dev_action_stop(fsm_instance * fi, int event, void *arg)
2015 struct net_device *dev = (struct net_device *) arg;
2016 struct ctc_priv *privptr = dev->priv;
2019 DBF_TEXT(trace, 3, __FUNCTION__);
2020 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2021 for (direction = READ; direction <= WRITE; direction++) {
2022 struct channel *ch = privptr->channel[direction];
2023 fsm_event(ch->fsm, CH_EVENT_STOP, ch);
2027 dev_action_restart(fsm_instance *fi, int event, void *arg)
2029 struct net_device *dev = (struct net_device *)arg;
2030 struct ctc_priv *privptr = dev->priv;
2032 DBF_TEXT(trace, 3, __FUNCTION__);
2033 ctc_pr_debug("%s: Restarting\n", dev->name);
2034 dev_action_stop(fi, event, arg);
2035 fsm_event(privptr->fsm, DEV_EVENT_STOP, dev);
2036 fsm_addtimer(&privptr->restart_timer, CTC_TIMEOUT_5SEC,
2037 DEV_EVENT_START, dev);
2041 * Called from channel statemachine
2042 * when a channel is up and running.
2044 * @param fi An instance of an interface statemachine.
2045 * @param event The event, just happened.
2046 * @param arg Generic pointer, casted from struct net_device * upon call.
2049 dev_action_chup(fsm_instance * fi, int event, void *arg)
2051 struct net_device *dev = (struct net_device *) arg;
2052 struct ctc_priv *privptr = dev->priv;
2054 DBF_TEXT(trace, 3, __FUNCTION__);
2055 switch (fsm_getstate(fi)) {
2056 case DEV_STATE_STARTWAIT_RXTX:
2057 if (event == DEV_EVENT_RXUP)
2058 fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
2060 fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
2062 case DEV_STATE_STARTWAIT_RX:
2063 if (event == DEV_EVENT_RXUP) {
2064 fsm_newstate(fi, DEV_STATE_RUNNING);
2065 ctc_pr_info("%s: connected with remote side\n",
2067 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2068 ctc_tty_setcarrier(dev, 1);
2069 ctc_clear_busy(dev);
2072 case DEV_STATE_STARTWAIT_TX:
2073 if (event == DEV_EVENT_TXUP) {
2074 fsm_newstate(fi, DEV_STATE_RUNNING);
2075 ctc_pr_info("%s: connected with remote side\n",
2077 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2078 ctc_tty_setcarrier(dev, 1);
2079 ctc_clear_busy(dev);
2082 case DEV_STATE_STOPWAIT_TX:
2083 if (event == DEV_EVENT_RXUP)
2084 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2086 case DEV_STATE_STOPWAIT_RX:
2087 if (event == DEV_EVENT_TXUP)
2088 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2094 * Called from channel statemachine
2095 * when a channel has been shutdown.
2097 * @param fi An instance of an interface statemachine.
2098 * @param event The event, just happened.
2099 * @param arg Generic pointer, casted from struct net_device * upon call.
2102 dev_action_chdown(fsm_instance * fi, int event, void *arg)
2104 struct net_device *dev = (struct net_device *) arg;
2105 struct ctc_priv *privptr = dev->priv;
2107 DBF_TEXT(trace, 3, __FUNCTION__);
2108 switch (fsm_getstate(fi)) {
2109 case DEV_STATE_RUNNING:
2110 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2111 ctc_tty_setcarrier(dev, 0);
2112 if (event == DEV_EVENT_TXDOWN)
2113 fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
2115 fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
2117 case DEV_STATE_STARTWAIT_RX:
2118 if (event == DEV_EVENT_TXDOWN)
2119 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2121 case DEV_STATE_STARTWAIT_TX:
2122 if (event == DEV_EVENT_RXDOWN)
2123 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2125 case DEV_STATE_STOPWAIT_RXTX:
2126 if (event == DEV_EVENT_TXDOWN)
2127 fsm_newstate(fi, DEV_STATE_STOPWAIT_RX);
2129 fsm_newstate(fi, DEV_STATE_STOPWAIT_TX);
2131 case DEV_STATE_STOPWAIT_RX:
2132 if (event == DEV_EVENT_RXDOWN)
2133 fsm_newstate(fi, DEV_STATE_STOPPED);
2135 case DEV_STATE_STOPWAIT_TX:
2136 if (event == DEV_EVENT_TXDOWN)
2137 fsm_newstate(fi, DEV_STATE_STOPPED);
2142 static const fsm_node dev_fsm[] = {
2143 {DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start},
2145 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_START, dev_action_start },
2146 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
2147 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
2148 {DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
2150 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_START, dev_action_start },
2151 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
2152 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
2153 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXDOWN, dev_action_chdown },
2154 {DEV_STATE_STOPWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
2156 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_START, dev_action_start },
2157 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
2158 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
2159 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXDOWN, dev_action_chdown },
2160 {DEV_STATE_STOPWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
2162 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_STOP, dev_action_stop },
2163 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXUP, dev_action_chup },
2164 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXUP, dev_action_chup },
2165 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
2166 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
2167 {DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
2169 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_STOP, dev_action_stop },
2170 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
2171 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
2172 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXDOWN, dev_action_chdown },
2173 {DEV_STATE_STARTWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
2175 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_STOP, dev_action_stop },
2176 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
2177 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
2178 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXDOWN, dev_action_chdown },
2179 {DEV_STATE_STARTWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
2181 {DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
2182 {DEV_STATE_RUNNING, DEV_EVENT_RXDOWN, dev_action_chdown },
2183 {DEV_STATE_RUNNING, DEV_EVENT_TXDOWN, dev_action_chdown },
2184 {DEV_STATE_RUNNING, DEV_EVENT_TXUP, fsm_action_nop },
2185 {DEV_STATE_RUNNING, DEV_EVENT_RXUP, fsm_action_nop },
2186 {DEV_STATE_RUNNING, DEV_EVENT_RESTART, dev_action_restart },
2189 static const int DEV_FSM_LEN = sizeof (dev_fsm) / sizeof (fsm_node);
2192 * Transmit a packet.
2193 * This is a helper function for ctc_tx().
2195 * @param ch Channel to be used for sending.
2196 * @param skb Pointer to struct sk_buff of packet to send.
2197 * The linklevel header has already been set up
2200 * @return 0 on success, -ERRNO on failure. (Never fails.)
2203 transmit_skb(struct channel *ch, struct sk_buff *skb)
2205 unsigned long saveflags;
2206 struct ll_header header;
2209 DBF_TEXT(trace, 5, __FUNCTION__);
2210 /* we need to acquire the lock for testing the state
2211 * otherwise we can have an IRQ changing the state to
2212 * TXIDLE after the test but before acquiring the lock.
2214 spin_lock_irqsave(&ch->collect_lock, saveflags);
2215 if (fsm_getstate(ch->fsm) != CH_STATE_TXIDLE) {
2216 int l = skb->len + LL_HEADER_LENGTH;
2218 if (ch->collect_len + l > ch->max_bufsize - 2) {
2219 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
2222 atomic_inc(&skb->users);
2224 header.type = skb->protocol;
2226 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
2228 skb_queue_tail(&ch->collect_queue, skb);
2229 ch->collect_len += l;
2231 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
2235 struct sk_buff *nskb;
2237 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
2239 * Protect skb against beeing free'd by upper
2242 atomic_inc(&skb->users);
2243 ch->prof.txlen += skb->len;
2244 header.length = skb->len + LL_HEADER_LENGTH;
2245 header.type = skb->protocol;
2247 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
2249 block_len = skb->len + 2;
2250 *((__u16 *) skb_push(skb, 2)) = block_len;
2253 * IDAL support in CTC is broken, so we have to
2254 * care about skb's above 2G ourselves.
2256 hi = ((unsigned long) skb->tail + LL_HEADER_LENGTH) >> 31;
2258 nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
2260 atomic_dec(&skb->users);
2261 skb_pull(skb, LL_HEADER_LENGTH + 2);
2262 ctc_clear_busy(ch->netdev);
2265 memcpy(skb_put(nskb, skb->len),
2266 skb->data, skb->len);
2267 atomic_inc(&nskb->users);
2268 atomic_dec(&skb->users);
2269 dev_kfree_skb_irq(skb);
2274 ch->ccw[4].count = block_len;
2275 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
2277 * idal allocation failed, try via copying to
2278 * trans_skb. trans_skb usually has a pre-allocated
2281 if (ctc_checkalloc_buffer(ch, 1)) {
2283 * Remove our header. It gets added
2284 * again on retransmit.
2286 atomic_dec(&skb->users);
2287 skb_pull(skb, LL_HEADER_LENGTH + 2);
2288 ctc_clear_busy(ch->netdev);
2292 ch->trans_skb->tail = ch->trans_skb->data;
2293 ch->trans_skb->len = 0;
2294 ch->ccw[1].count = skb->len;
2295 memcpy(skb_put(ch->trans_skb, skb->len), skb->data,
2297 atomic_dec(&skb->users);
2298 dev_kfree_skb_irq(skb);
2301 skb_queue_tail(&ch->io_queue, skb);
2305 fsm_newstate(ch->fsm, CH_STATE_TX);
2306 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
2307 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
2308 ch->prof.send_stamp = xtime;
2309 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
2310 (unsigned long) ch, 0xff, 0);
2311 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
2313 ch->prof.doios_single++;
2315 fsm_deltimer(&ch->timer);
2316 ccw_check_return_code(ch, rc, "single skb TX");
2318 skb_dequeue_tail(&ch->io_queue);
2320 * Remove our header. It gets added
2321 * again on retransmit.
2323 skb_pull(skb, LL_HEADER_LENGTH + 2);
2326 struct net_device *dev = ch->netdev;
2327 struct ctc_priv *privptr = dev->priv;
2328 privptr->stats.tx_packets++;
2329 privptr->stats.tx_bytes +=
2330 skb->len - LL_HEADER_LENGTH;
2335 ctc_clear_busy(ch->netdev);
2340 * Interface API for upper network layers
2341 *****************************************************************************/
2344 * Open an interface.
2345 * Called from generic network layer when ifconfig up is run.
2347 * @param dev Pointer to interface struct.
2349 * @return 0 on success, -ERRNO on failure. (Never fails.)
2352 ctc_open(struct net_device * dev)
2354 DBF_TEXT(trace, 5, __FUNCTION__);
2355 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_START, dev);
2360 * Close an interface.
2361 * Called from generic network layer when ifconfig down is run.
2363 * @param dev Pointer to interface struct.
2365 * @return 0 on success, -ERRNO on failure. (Never fails.)
2368 ctc_close(struct net_device * dev)
2370 DBF_TEXT(trace, 5, __FUNCTION__);
2371 fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_STOP, dev);
2376 * Start transmission of a packet.
2377 * Called from generic network device layer.
2379 * @param skb Pointer to buffer containing the packet.
2380 * @param dev Pointer to interface struct.
2382 * @return 0 if packet consumed, !0 if packet rejected.
2383 * Note: If we return !0, then the packet is free'd by
2384 * the generic network layer.
2387 ctc_tx(struct sk_buff *skb, struct net_device * dev)
2390 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
2392 DBF_TEXT(trace, 5, __FUNCTION__);
2394 * Some sanity checks ...
2397 ctc_pr_warn("%s: NULL sk_buff passed\n", dev->name);
2398 privptr->stats.tx_dropped++;
2401 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
2402 ctc_pr_warn("%s: Got sk_buff with head room < %ld bytes\n",
2403 dev->name, LL_HEADER_LENGTH + 2);
2405 privptr->stats.tx_dropped++;
2410 * If channels are not running, try to restart them
2411 * and throw away packet.
2413 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
2414 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
2415 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2418 privptr->stats.tx_dropped++;
2419 privptr->stats.tx_errors++;
2420 privptr->stats.tx_carrier_errors++;
2424 if (ctc_test_and_set_busy(dev))
2427 dev->trans_start = jiffies;
2428 if (transmit_skb(privptr->channel[WRITE], skb) != 0)
2434 * Sets MTU of an interface.
2436 * @param dev Pointer to interface struct.
2437 * @param new_mtu The new MTU to use for this interface.
2439 * @return 0 on success, -EINVAL if MTU is out of valid range.
2440 * (valid range is 576 .. 65527). If VM is on the
2441 * remote side, maximum MTU is 32760, however this is
2442 * <em>not</em> checked here.
2445 ctc_change_mtu(struct net_device * dev, int new_mtu)
2447 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
2449 DBF_TEXT(trace, 3, __FUNCTION__);
2450 if ((new_mtu < 576) || (new_mtu > 65527) ||
2451 (new_mtu > (privptr->channel[READ]->max_bufsize -
2452 LL_HEADER_LENGTH - 2)))
2455 dev->hard_header_len = LL_HEADER_LENGTH + 2;
2460 * Returns interface statistics of a device.
2462 * @param dev Pointer to interface struct.
2464 * @return Pointer to stats struct of this interface.
2466 static struct net_device_stats *
2467 ctc_stats(struct net_device * dev)
2469 return &((struct ctc_priv *) dev->priv)->stats;
2477 buffer_show(struct device *dev, struct device_attribute *attr, char *buf)
2479 struct ctc_priv *priv;
2481 priv = dev->driver_data;
2484 return sprintf(buf, "%d\n",
2489 buffer_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2491 struct ctc_priv *priv;
2492 struct net_device *ndev;
2496 DBF_TEXT(trace, 3, __FUNCTION__);
2497 DBF_TEXT(trace, 3, buf);
2498 priv = dev->driver_data;
2500 DBF_TEXT(trace, 3, "bfnopriv");
2504 sscanf(buf, "%u", &bs1);
2505 if (bs1 > CTC_BUFSIZE_LIMIT)
2507 if (bs1 < (576 + LL_HEADER_LENGTH + 2))
2509 priv->buffer_size = bs1; // just to overwrite the default
2511 ndev = priv->channel[READ]->netdev;
2513 DBF_TEXT(trace, 3, "bfnondev");
2517 if ((ndev->flags & IFF_RUNNING) &&
2518 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
2521 priv->channel[READ]->max_bufsize = bs1;
2522 priv->channel[WRITE]->max_bufsize = bs1;
2523 if (!(ndev->flags & IFF_RUNNING))
2524 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
2525 priv->channel[READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
2526 priv->channel[WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
2528 sprintf(buffer, "%d",priv->buffer_size);
2529 DBF_TEXT(trace, 3, buffer);
2533 DBF_TEXT(trace, 3, "buff_err");
2538 loglevel_show(struct device *dev, struct device_attribute *attr, char *buf)
2540 return sprintf(buf, "%d\n", loglevel);
2544 loglevel_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2548 DBF_TEXT(trace, 5, __FUNCTION__);
2549 sscanf(buf, "%i", &ll1);
2551 if ((ll1 > CTC_LOGLEVEL_MAX) || (ll1 < 0))
2558 ctc_print_statistics(struct ctc_priv *priv)
2563 DBF_TEXT(trace, 4, __FUNCTION__);
2566 sbuf = (char *)kmalloc(2048, GFP_KERNEL);
2571 p += sprintf(p, " Device FSM state: %s\n",
2572 fsm_getstate_str(priv->fsm));
2573 p += sprintf(p, " RX channel FSM state: %s\n",
2574 fsm_getstate_str(priv->channel[READ]->fsm));
2575 p += sprintf(p, " TX channel FSM state: %s\n",
2576 fsm_getstate_str(priv->channel[WRITE]->fsm));
2577 p += sprintf(p, " Max. TX buffer used: %ld\n",
2578 priv->channel[WRITE]->prof.maxmulti);
2579 p += sprintf(p, " Max. chained SKBs: %ld\n",
2580 priv->channel[WRITE]->prof.maxcqueue);
2581 p += sprintf(p, " TX single write ops: %ld\n",
2582 priv->channel[WRITE]->prof.doios_single);
2583 p += sprintf(p, " TX multi write ops: %ld\n",
2584 priv->channel[WRITE]->prof.doios_multi);
2585 p += sprintf(p, " Netto bytes written: %ld\n",
2586 priv->channel[WRITE]->prof.txlen);
2587 p += sprintf(p, " Max. TX IO-time: %ld\n",
2588 priv->channel[WRITE]->prof.tx_time);
2590 ctc_pr_debug("Statistics for %s:\n%s",
2591 priv->channel[WRITE]->netdev->name, sbuf);
2597 stats_show(struct device *dev, struct device_attribute *attr, char *buf)
2599 struct ctc_priv *priv = dev->driver_data;
2602 ctc_print_statistics(priv);
2603 return sprintf(buf, "0\n");
2607 stats_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2609 struct ctc_priv *priv = dev->driver_data;
2612 /* Reset statistics */
2613 memset(&priv->channel[WRITE]->prof, 0,
2614 sizeof(priv->channel[WRITE]->prof));
2619 ctc_netdev_unregister(struct net_device * dev)
2621 struct ctc_priv *privptr;
2625 privptr = (struct ctc_priv *) dev->priv;
2626 if (privptr->protocol != CTC_PROTO_LINUX_TTY)
2627 unregister_netdev(dev);
2629 ctc_tty_unregister_netdev(dev);
2633 ctc_netdev_register(struct net_device * dev)
2635 struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
2636 if (privptr->protocol != CTC_PROTO_LINUX_TTY)
2637 return register_netdev(dev);
2639 return ctc_tty_register_netdev(dev);
2643 ctc_free_netdevice(struct net_device * dev, int free_dev)
2645 struct ctc_priv *privptr;
2648 privptr = dev->priv;
2651 kfree_fsm(privptr->fsm);
2661 ctc_proto_show(struct device *dev, struct device_attribute *attr, char *buf)
2663 struct ctc_priv *priv;
2665 priv = dev->driver_data;
2669 return sprintf(buf, "%d\n", priv->protocol);
2673 ctc_proto_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2675 struct ctc_priv *priv;
2678 DBF_TEXT(trace, 3, __FUNCTION__);
2679 pr_debug("%s() called\n", __FUNCTION__);
2681 priv = dev->driver_data;
2684 sscanf(buf, "%u", &value);
2685 if ((value < 0) || (value > CTC_PROTO_MAX))
2687 priv->protocol = value;
2693 ctc_type_show(struct device *dev, struct device_attribute *attr, char *buf)
2695 struct ccwgroup_device *cgdev;
2697 cgdev = to_ccwgroupdev(dev);
2701 return sprintf(buf, "%s\n", cu3088_type[cgdev->cdev[0]->id.driver_info]);
2704 static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write);
2705 static DEVICE_ATTR(protocol, 0644, ctc_proto_show, ctc_proto_store);
2706 static DEVICE_ATTR(type, 0444, ctc_type_show, NULL);
2708 static DEVICE_ATTR(loglevel, 0644, loglevel_show, loglevel_write);
2709 static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
2711 static struct attribute *ctc_attr[] = {
2712 &dev_attr_protocol.attr,
2713 &dev_attr_type.attr,
2714 &dev_attr_buffer.attr,
2718 static struct attribute_group ctc_attr_group = {
2723 ctc_add_attributes(struct device *dev)
2725 device_create_file(dev, &dev_attr_loglevel);
2726 device_create_file(dev, &dev_attr_stats);
2731 ctc_remove_attributes(struct device *dev)
2733 device_remove_file(dev, &dev_attr_stats);
2734 device_remove_file(dev, &dev_attr_loglevel);
2738 ctc_add_files(struct device *dev)
2740 pr_debug("%s() called\n", __FUNCTION__);
2742 return sysfs_create_group(&dev->kobj, &ctc_attr_group);
2746 ctc_remove_files(struct device *dev)
2748 pr_debug("%s() called\n", __FUNCTION__);
2750 sysfs_remove_group(&dev->kobj, &ctc_attr_group);
2754 * Add ctc specific attributes.
2755 * Add ctc private data.
2757 * @param cgdev pointer to ccwgroup_device just added
2759 * @returns 0 on success, !0 on failure.
2762 ctc_probe_device(struct ccwgroup_device *cgdev)
2764 struct ctc_priv *priv;
2768 pr_debug("%s() called\n", __FUNCTION__);
2769 DBF_TEXT(setup, 3, __FUNCTION__);
2771 if (!get_device(&cgdev->dev))
2774 priv = kmalloc(sizeof (struct ctc_priv), GFP_KERNEL);
2776 ctc_pr_err("%s: Out of memory\n", __func__);
2777 put_device(&cgdev->dev);
2781 memset(priv, 0, sizeof (struct ctc_priv));
2782 rc = ctc_add_files(&cgdev->dev);
2785 put_device(&cgdev->dev);
2788 priv->buffer_size = CTC_BUFSIZE_DEFAULT;
2789 cgdev->cdev[0]->handler = ctc_irq_handler;
2790 cgdev->cdev[1]->handler = ctc_irq_handler;
2791 cgdev->dev.driver_data = priv;
2793 sprintf(buffer, "%p", priv);
2794 DBF_TEXT(data, 3, buffer);
2796 sprintf(buffer, "%u", (unsigned int)sizeof(struct ctc_priv));
2797 DBF_TEXT(data, 3, buffer);
2799 sprintf(buffer, "%p", &channels);
2800 DBF_TEXT(data, 3, buffer);
2802 sprintf(buffer, "%u", (unsigned int)sizeof(struct channel));
2803 DBF_TEXT(data, 3, buffer);
2809 * Initialize everything of the net device except the name and the
2812 static struct net_device *
2813 ctc_init_netdevice(struct net_device * dev, int alloc_device,
2814 struct ctc_priv *privptr)
2819 DBF_TEXT(setup, 3, __FUNCTION__);
2822 dev = kmalloc(sizeof (struct net_device), GFP_KERNEL);
2825 memset(dev, 0, sizeof (struct net_device));
2828 dev->priv = privptr;
2829 privptr->fsm = init_fsm("ctcdev", dev_state_names,
2830 dev_event_names, CTC_NR_DEV_STATES, CTC_NR_DEV_EVENTS,
2831 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
2832 if (privptr->fsm == NULL) {
2837 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
2838 fsm_settimer(privptr->fsm, &privptr->restart_timer);
2840 dev->mtu = CTC_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
2841 dev->hard_start_xmit = ctc_tx;
2842 dev->open = ctc_open;
2843 dev->stop = ctc_close;
2844 dev->get_stats = ctc_stats;
2845 dev->change_mtu = ctc_change_mtu;
2846 dev->hard_header_len = LL_HEADER_LENGTH + 2;
2848 dev->type = ARPHRD_SLIP;
2849 dev->tx_queue_len = 100;
2850 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2851 SET_MODULE_OWNER(dev);
2858 * Setup an interface.
2860 * @param cgdev Device to be setup.
2862 * @returns 0 on success, !0 on failure.
2865 ctc_new_device(struct ccwgroup_device *cgdev)
2867 char read_id[CTC_ID_SIZE];
2868 char write_id[CTC_ID_SIZE];
2870 enum channel_types type;
2871 struct ctc_priv *privptr;
2872 struct net_device *dev;
2876 pr_debug("%s() called\n", __FUNCTION__);
2877 DBF_TEXT(setup, 3, __FUNCTION__);
2879 privptr = cgdev->dev.driver_data;
2883 sprintf(buffer, "%d", privptr->buffer_size);
2884 DBF_TEXT(setup, 3, buffer);
2886 type = get_channel_type(&cgdev->cdev[0]->id);
2888 snprintf(read_id, CTC_ID_SIZE, "ch-%s", cgdev->cdev[0]->dev.bus_id);
2889 snprintf(write_id, CTC_ID_SIZE, "ch-%s", cgdev->cdev[1]->dev.bus_id);
2891 if (add_channel(cgdev->cdev[0], type))
2893 if (add_channel(cgdev->cdev[1], type))
2896 ret = ccw_device_set_online(cgdev->cdev[0]);
2899 "ccw_device_set_online (cdev[0]) failed with ret = %d\n", ret);
2902 ret = ccw_device_set_online(cgdev->cdev[1]);
2905 "ccw_device_set_online (cdev[1]) failed with ret = %d\n", ret);
2908 dev = ctc_init_netdevice(NULL, 1, privptr);
2911 ctc_pr_warn("ctc_init_netdevice failed\n");
2915 if (privptr->protocol == CTC_PROTO_LINUX_TTY)
2916 strlcpy(dev->name, "ctctty%d", IFNAMSIZ);
2918 strlcpy(dev->name, "ctc%d", IFNAMSIZ);
2920 for (direction = READ; direction <= WRITE; direction++) {
2921 privptr->channel[direction] =
2922 channel_get(type, direction == READ ? read_id : write_id,
2924 if (privptr->channel[direction] == NULL) {
2925 if (direction == WRITE)
2926 channel_free(privptr->channel[READ]);
2928 ctc_free_netdevice(dev, 1);
2931 privptr->channel[direction]->netdev = dev;
2932 privptr->channel[direction]->protocol = privptr->protocol;
2933 privptr->channel[direction]->max_bufsize = privptr->buffer_size;
2936 SET_NETDEV_DEV(dev, &cgdev->dev);
2938 if (ctc_netdev_register(dev) != 0) {
2939 ctc_free_netdevice(dev, 1);
2943 ctc_add_attributes(&cgdev->dev);
2945 strlcpy(privptr->fsm->name, dev->name, sizeof (privptr->fsm->name));
2949 ctc_pr_info("%s: read: %s, write: %s, proto: %d\n",
2950 dev->name, privptr->channel[READ]->id,
2951 privptr->channel[WRITE]->id, privptr->protocol);
2955 ccw_device_set_offline(cgdev->cdev[1]);
2956 ccw_device_set_offline(cgdev->cdev[0]);
2962 * Shutdown an interface.
2964 * @param cgdev Device to be shut down.
2966 * @returns 0 on success, !0 on failure.
2969 ctc_shutdown_device(struct ccwgroup_device *cgdev)
2971 struct ctc_priv *priv;
2972 struct net_device *ndev;
2974 DBF_TEXT(setup, 3, __FUNCTION__);
2975 pr_debug("%s() called\n", __FUNCTION__);
2978 priv = cgdev->dev.driver_data;
2983 if (priv->channel[READ]) {
2984 ndev = priv->channel[READ]->netdev;
2986 /* Close the device */
2988 ndev->flags &=~IFF_RUNNING;
2990 ctc_remove_attributes(&cgdev->dev);
2992 channel_free(priv->channel[READ]);
2994 if (priv->channel[WRITE])
2995 channel_free(priv->channel[WRITE]);
2998 ctc_netdev_unregister(ndev);
3000 ctc_free_netdevice(ndev, 1);
3004 kfree_fsm(priv->fsm);
3006 ccw_device_set_offline(cgdev->cdev[1]);
3007 ccw_device_set_offline(cgdev->cdev[0]);
3009 if (priv->channel[READ])
3010 channel_remove(priv->channel[READ]);
3011 if (priv->channel[WRITE])
3012 channel_remove(priv->channel[WRITE]);
3013 priv->channel[READ] = priv->channel[WRITE] = NULL;
3020 ctc_remove_device(struct ccwgroup_device *cgdev)
3022 struct ctc_priv *priv;
3024 pr_debug("%s() called\n", __FUNCTION__);
3025 DBF_TEXT(setup, 3, __FUNCTION__);
3027 priv = cgdev->dev.driver_data;
3030 if (cgdev->state == CCWGROUP_ONLINE)
3031 ctc_shutdown_device(cgdev);
3032 ctc_remove_files(&cgdev->dev);
3033 cgdev->dev.driver_data = NULL;
3035 put_device(&cgdev->dev);
3038 static struct ccwgroup_driver ctc_group_driver = {
3039 .owner = THIS_MODULE,
3042 .driver_id = 0xC3E3C3,
3043 .probe = ctc_probe_device,
3044 .remove = ctc_remove_device,
3045 .set_online = ctc_new_device,
3046 .set_offline = ctc_shutdown_device,
3050 * Module related routines
3051 *****************************************************************************/
3054 * Prepare to be unloaded. Free IRQ's and release all resources.
3055 * This is called just before this module is unloaded. It is
3056 * <em>not</em> called, if the usage count is !0, so we don't need to check
3062 DBF_TEXT(setup, 3, __FUNCTION__);
3063 unregister_cu3088_discipline(&ctc_group_driver);
3065 ctc_unregister_dbf_views();
3066 ctc_pr_info("CTC driver unloaded\n");
3070 * Initialize module.
3071 * This is called just after the module is loaded.
3073 * @return 0 on success, !0 on error.
3080 loglevel = CTC_LOGLEVEL_DEFAULT;
3082 DBF_TEXT(setup, 3, __FUNCTION__);
3086 ret = ctc_register_dbf_views();
3088 ctc_pr_crit("ctc_init failed with ctc_register_dbf_views rc = %d\n", ret);
3092 ret = register_cu3088_discipline(&ctc_group_driver);
3095 ctc_unregister_dbf_views();
3100 module_init(ctc_init);
3101 module_exit(ctc_exit);
3103 /* --- This is the END my friend --- */