aboutsummaryrefslogtreecommitdiff
path: root/drivers/s390/net/ctcmain.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/s390/net/ctcmain.c')
-rw-r--r--drivers/s390/net/ctcmain.c3062
1 files changed, 0 insertions, 3062 deletions
diff --git a/drivers/s390/net/ctcmain.c b/drivers/s390/net/ctcmain.c
deleted file mode 100644
index 77a503139e3..00000000000
--- a/drivers/s390/net/ctcmain.c
+++ /dev/null
@@ -1,3062 +0,0 @@
-/*
- * CTC / ESCON network driver
- *
- * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
- * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
- * Fixes by : Jochen Röhrig (roehrig@de.ibm.com)
- * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
- Peter Tiedemann (ptiedem@de.ibm.com)
- * Driver Model stuff by : Cornelia Huck <cornelia.huck@de.ibm.com>
- *
- * Documentation used:
- * - Principles of Operation (IBM doc#: SA22-7201-06)
- * - Common IO/-Device Commands and Self Description (IBM doc#: SA22-7204-02)
- * - Common IO/-Device Commands and Self Description (IBM doc#: SN22-5535)
- * - ESCON Channel-to-Channel Adapter (IBM doc#: SA22-7203-00)
- * - ESCON I/O Interface (IBM doc#: SA22-7202-029
- *
- * and the source of the original CTC driver by:
- * Dieter Wellerdiek (wel@de.ibm.com)
- * Martin Schwidefsky (schwidefsky@de.ibm.com)
- * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
- * Jochen Röhrig (roehrig@de.ibm.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-#undef DEBUG
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/errno.h>
-#include <linux/types.h>
-#include <linux/interrupt.h>
-#include <linux/timer.h>
-#include <linux/bitops.h>
-
-#include <linux/signal.h>
-#include <linux/string.h>
-
-#include <linux/ip.h>
-#include <linux/if_arp.h>
-#include <linux/tcp.h>
-#include <linux/skbuff.h>
-#include <linux/ctype.h>
-#include <net/dst.h>
-
-#include <asm/io.h>
-#include <asm/ccwdev.h>
-#include <asm/ccwgroup.h>
-#include <asm/uaccess.h>
-
-#include <asm/idals.h>
-
-#include "fsm.h"
-#include "cu3088.h"
-
-#include "ctcdbug.h"
-#include "ctcmain.h"
-
-MODULE_AUTHOR("(C) 2000 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
-MODULE_DESCRIPTION("Linux for S/390 CTC/Escon Driver");
-MODULE_LICENSE("GPL");
-/**
- * States of the interface statemachine.
- */
-enum dev_states {
- DEV_STATE_STOPPED,
- DEV_STATE_STARTWAIT_RXTX,
- DEV_STATE_STARTWAIT_RX,
- DEV_STATE_STARTWAIT_TX,
- DEV_STATE_STOPWAIT_RXTX,
- DEV_STATE_STOPWAIT_RX,
- DEV_STATE_STOPWAIT_TX,
- DEV_STATE_RUNNING,
- /**
- * MUST be always the last element!!
- */
- CTC_NR_DEV_STATES
-};
-
-static const char *dev_state_names[] = {
- "Stopped",
- "StartWait RXTX",
- "StartWait RX",
- "StartWait TX",
- "StopWait RXTX",
- "StopWait RX",
- "StopWait TX",
- "Running",
-};
-
-/**
- * Events of the interface statemachine.
- */
-enum dev_events {
- DEV_EVENT_START,
- DEV_EVENT_STOP,
- DEV_EVENT_RXUP,
- DEV_EVENT_TXUP,
- DEV_EVENT_RXDOWN,
- DEV_EVENT_TXDOWN,
- DEV_EVENT_RESTART,
- /**
- * MUST be always the last element!!
- */
- CTC_NR_DEV_EVENTS
-};
-
-static const char *dev_event_names[] = {
- "Start",
- "Stop",
- "RX up",
- "TX up",
- "RX down",
- "TX down",
- "Restart",
-};
-
-/**
- * Events of the channel statemachine
- */
-enum ch_events {
- /**
- * Events, representing return code of
- * I/O operations (ccw_device_start, ccw_device_halt et al.)
- */
- CH_EVENT_IO_SUCCESS,
- CH_EVENT_IO_EBUSY,
- CH_EVENT_IO_ENODEV,
- CH_EVENT_IO_EIO,
- CH_EVENT_IO_UNKNOWN,
-
- CH_EVENT_ATTNBUSY,
- CH_EVENT_ATTN,
- CH_EVENT_BUSY,
-
- /**
- * Events, representing unit-check
- */
- CH_EVENT_UC_RCRESET,
- CH_EVENT_UC_RSRESET,
- CH_EVENT_UC_TXTIMEOUT,
- CH_EVENT_UC_TXPARITY,
- CH_EVENT_UC_HWFAIL,
- CH_EVENT_UC_RXPARITY,
- CH_EVENT_UC_ZERO,
- CH_EVENT_UC_UNKNOWN,
-
- /**
- * Events, representing subchannel-check
- */
- CH_EVENT_SC_UNKNOWN,
-
- /**
- * Events, representing machine checks
- */
- CH_EVENT_MC_FAIL,
- CH_EVENT_MC_GOOD,
-
- /**
- * Event, representing normal IRQ
- */
- CH_EVENT_IRQ,
- CH_EVENT_FINSTAT,
-
- /**
- * Event, representing timer expiry.
- */
- CH_EVENT_TIMER,
-
- /**
- * Events, representing commands from upper levels.
- */
- CH_EVENT_START,
- CH_EVENT_STOP,
-
- /**
- * MUST be always the last element!!
- */
- NR_CH_EVENTS,
-};
-
-/**
- * States of the channel statemachine.
- */
-enum ch_states {
- /**
- * Channel not assigned to any device,
- * initial state, direction invalid
- */
- CH_STATE_IDLE,
-
- /**
- * Channel assigned but not operating
- */
- CH_STATE_STOPPED,
- CH_STATE_STARTWAIT,
- CH_STATE_STARTRETRY,
- CH_STATE_SETUPWAIT,
- CH_STATE_RXINIT,
- CH_STATE_TXINIT,
- CH_STATE_RX,
- CH_STATE_TX,
- CH_STATE_RXIDLE,
- CH_STATE_TXIDLE,
- CH_STATE_RXERR,
- CH_STATE_TXERR,
- CH_STATE_TERM,
- CH_STATE_DTERM,
- CH_STATE_NOTOP,
-
- /**
- * MUST be always the last element!!
- */
- NR_CH_STATES,
-};
-
-static int loglevel = CTC_LOGLEVEL_DEFAULT;
-
-/**
- * Linked list of all detected channels.
- */
-static struct channel *channels = NULL;
-
-/**
- * Print Banner.
- */
-static void
-print_banner(void)
-{
- static int printed = 0;
-
- if (printed)
- return;
-
- printk(KERN_INFO "CTC driver initialized\n");
- printed = 1;
-}
-
-/**
- * Return type of a detected device.
- */
-static enum channel_types
-get_channel_type(struct ccw_device_id *id)
-{
- enum channel_types type = (enum channel_types) id->driver_info;
-
- if (type == channel_type_ficon)
- type = channel_type_escon;
-
- return type;
-}
-
-static const char *ch_event_names[] = {
- "ccw_device success",
- "ccw_device busy",
- "ccw_device enodev",
- "ccw_device ioerr",
- "ccw_device unknown",
-
- "Status ATTN & BUSY",
- "Status ATTN",
- "Status BUSY",
-
- "Unit check remote reset",
- "Unit check remote system reset",
- "Unit check TX timeout",
- "Unit check TX parity",
- "Unit check Hardware failure",
- "Unit check RX parity",
- "Unit check ZERO",
- "Unit check Unknown",
-
- "SubChannel check Unknown",
-
- "Machine check failure",
- "Machine check operational",
-
- "IRQ normal",
- "IRQ final",
-
- "Timer",
-
- "Start",
- "Stop",
-};
-
-static const char *ch_state_names[] = {
- "Idle",
- "Stopped",
- "StartWait",
- "StartRetry",
- "SetupWait",
- "RX init",
- "TX init",
- "RX",
- "TX",
- "RX idle",
- "TX idle",
- "RX error",
- "TX error",
- "Terminating",
- "Restarting",
- "Not operational",
-};
-
-#ifdef DEBUG
-/**
- * Dump header and first 16 bytes of an sk_buff for debugging purposes.
- *
- * @param skb The sk_buff to dump.
- * @param offset Offset relative to skb-data, where to start the dump.
- */
-static void
-ctc_dump_skb(struct sk_buff *skb, int offset)
-{
- unsigned char *p = skb->data;
- __u16 bl;
- struct ll_header *header;
- int i;
-
- if (!(loglevel & CTC_LOGLEVEL_DEBUG))
- return;
- p += offset;
- bl = *((__u16 *) p);
- p += 2;
- header = (struct ll_header *) p;
- p -= 2;
-
- printk(KERN_DEBUG "dump:\n");
- printk(KERN_DEBUG "blocklen=%d %04x\n", bl, bl);
-
- printk(KERN_DEBUG "h->length=%d %04x\n", header->length,
- header->length);
- printk(KERN_DEBUG "h->type=%04x\n", header->type);
- printk(KERN_DEBUG "h->unused=%04x\n", header->unused);
- if (bl > 16)
- bl = 16;
- printk(KERN_DEBUG "data: ");
- for (i = 0; i < bl; i++)
- printk("%02x%s", *p++, (i % 16) ? " " : "\n<7>");
- printk("\n");
-}
-#else
-static inline void
-ctc_dump_skb(struct sk_buff *skb, int offset)
-{
-}
-#endif
-
-/**
- * Unpack a just received skb and hand it over to
- * upper layers.
- *
- * @param ch The channel where this skb has been received.
- * @param pskb The received skb.
- */
-static void
-ctc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
-{
- struct net_device *dev = ch->netdev;
- struct ctc_priv *privptr = (struct ctc_priv *) dev->priv;
- __u16 len = *((__u16 *) pskb->data);
-
- DBF_TEXT(trace, 4, __FUNCTION__);
- skb_put(pskb, 2 + LL_HEADER_LENGTH);
- skb_pull(pskb, 2);
- pskb->dev = dev;
- pskb->ip_summed = CHECKSUM_UNNECESSARY;
- while (len > 0) {
- struct sk_buff *skb;
- struct ll_header *header = (struct ll_header *) pskb->data;
-
- skb_pull(pskb, LL_HEADER_LENGTH);
- if ((ch->protocol == CTC_PROTO_S390) &&
- (header->type != ETH_P_IP)) {
-
-#ifndef DEBUG
- if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
-#endif
- /**
- * Check packet type only if we stick strictly
- * to S/390's protocol of OS390. This only
- * supports IP. Otherwise allow any packet
- * type.
- */
- ctc_pr_warn(
- "%s Illegal packet type 0x%04x received, dropping\n",
- dev->name, header->type);
- ch->logflags |= LOG_FLAG_ILLEGALPKT;
-#ifndef DEBUG
- }
-#endif
-#ifdef DEBUG
- ctc_dump_skb(pskb, -6);
-#endif
- privptr->stats.rx_dropped++;
- privptr->stats.rx_frame_errors++;
- return;
- }
- pskb->protocol = ntohs(header->type);
- if (header->length <= LL_HEADER_LENGTH) {
-#ifndef DEBUG
- if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
-#endif
- ctc_pr_warn(
- "%s Illegal packet size %d "
- "received (MTU=%d blocklen=%d), "
- "dropping\n", dev->name, header->length,
- dev->mtu, len);
- ch->logflags |= LOG_FLAG_ILLEGALSIZE;
-#ifndef DEBUG
- }
-#endif
-#ifdef DEBUG
- ctc_dump_skb(pskb, -6);
-#endif
- privptr->stats.rx_dropped++;
- privptr->stats.rx_length_errors++;
- return;
- }
- header->length -= LL_HEADER_LENGTH;
- len -= LL_HEADER_LENGTH;
- if ((header->length > skb_tailroom(pskb)) ||
- (header->length > len)) {
-#ifndef DEBUG
- if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
-#endif
- ctc_pr_warn(
- "%s Illegal packet size %d "
- "(beyond the end of received data), "
- "dropping\n", dev->name, header->length);
- ch->logflags |= LOG_FLAG_OVERRUN;
-#ifndef DEBUG
- }
-#endif
-#ifdef DEBUG
- ctc_dump_skb(pskb, -6);
-#endif
- privptr->stats.rx_dropped++;
- privptr->stats.rx_length_errors++;
- return;
- }
- skb_put(pskb, header->length);
- skb_reset_mac_header(pskb);
- len -= header->length;
- skb = dev_alloc_skb(pskb->len);
- if (!skb) {
-#ifndef DEBUG
- if (!(ch->logflags & LOG_FLAG_NOMEM)) {
-#endif
- ctc_pr_warn(
- "%s Out of memory in ctc_unpack_skb\n",
- dev->name);
- ch->logflags |= LOG_FLAG_NOMEM;
-#ifndef DEBUG
- }
-#endif
- privptr->stats.rx_dropped++;
- return;
- }
- skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len),
- pskb->len);
- skb_reset_mac_header(skb);
- skb->dev = pskb->dev;
- skb->protocol = pskb->protocol;
- pskb->ip_summed = CHECKSUM_UNNECESSARY;
- /**
- * reset logflags
- */
- ch->logflags = 0;
- privptr->stats.rx_packets++;
- privptr->stats.rx_bytes += skb->len;
- netif_rx_ni(skb);
- dev->last_rx = jiffies;
- if (len > 0) {
- skb_pull(pskb, header->length);
- if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
-#ifndef DEBUG
- if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
-#endif
- ctc_pr_warn(
- "%s Overrun in ctc_unpack_skb\n",
- dev->name);
- ch->logflags |= LOG_FLAG_OVERRUN;
-#ifndef DEBUG
- }
-#endif
- return;
- }
- skb_put(pskb, LL_HEADER_LENGTH);
- }
- }
-}
-
-/**
- * Check return code of a preceeding ccw_device call, halt_IO etc...
- *
- * @param ch The channel, the error belongs to.
- * @param return_code The error code to inspect.
- */
-static void
-ccw_check_return_code(struct channel *ch, int return_code, char *msg)
-{
- DBF_TEXT(trace, 5, __FUNCTION__);
- switch (return_code) {
- case 0:
- fsm_event(ch->fsm, CH_EVENT_IO_SUCCESS, ch);
- break;
- case -EBUSY:
- ctc_pr_warn("%s (%s): Busy !\n", ch->id, msg);
- fsm_event(ch->fsm, CH_EVENT_IO_EBUSY, ch);
- break;
- case -ENODEV:
- ctc_pr_emerg("%s (%s): Invalid device called for IO\n",
- ch->id, msg);
- fsm_event(ch->fsm, CH_EVENT_IO_ENODEV, ch);
- break;
- case -EIO:
- ctc_pr_emerg("%s (%s): Status pending... \n",
- ch->id, msg);
- fsm_event(ch->fsm, CH_EVENT_IO_EIO, ch);
- break;
- default:
- ctc_pr_emerg("%s (%s): Unknown error in do_IO %04x\n",
- ch->id, msg, return_code);
- fsm_event(ch->fsm, CH_EVENT_IO_UNKNOWN, ch);
- }
-}
-
-/**
- * Check sense of a unit check.
- *
- * @param ch The channel, the sense code belongs to.
- * @param sense The sense code to inspect.
- */
-static void
-ccw_unit_check(struct channel *ch, unsigned char sense)
-{
- DBF_TEXT(trace, 5, __FUNCTION__);
- if (sense & SNS0_INTERVENTION_REQ) {
- if (sense & 0x01) {
- ctc_pr_debug("%s: Interface disc. or Sel. reset "
- "(remote)\n", ch->id);
- fsm_event(ch->fsm, CH_EVENT_UC_RCRESET, ch);
- } else {
- ctc_pr_debug("%s: System reset (remote)\n", ch->id);
- fsm_event(ch->fsm, CH_EVENT_UC_RSRESET, ch);
- }
- } else if (sense & SNS0_EQUIPMENT_CHECK) {
- if (sense & SNS0_BUS_OUT_CHECK) {
- ctc_pr_warn("%s: Hardware malfunction (remote)\n",
- ch->id);
- fsm_event(ch->fsm, CH_EVENT_UC_HWFAIL, ch);
- } else {
- ctc_pr_warn("%s: Read-data parity error (remote)\n",
- ch->id);
- fsm_event(ch->fsm, CH_EVENT_UC_RXPARITY, ch);
- }
- } else if (sense & SNS0_BUS_OUT_CHECK) {
- if (sense & 0x04) {
- ctc_pr_warn("%s: Data-streaming timeout)\n", ch->id);
- fsm_event(ch->fsm, CH_EVENT_UC_TXTIMEOUT, ch);
- } else {
- ctc_pr_warn("%s: Data-transfer parity error\n", ch->id);
- fsm_event(ch->fsm, CH_EVENT_UC_TXPARITY, ch);
- }
- } else if (sense & SNS0_CMD_REJECT) {
- ctc_pr_warn("%s: Command reject\n", ch->id);
- } else if (sense == 0) {
- ctc_pr_debug("%s: Unit check ZERO\n", ch->id);
- fsm_event(ch->fsm, CH_EVENT_UC_ZERO, ch);
- } else {
- ctc_pr_warn("%s: Unit Check with sense code: %02x\n",
- ch->id, sense);
- fsm_event(ch->fsm, CH_EVENT_UC_UNKNOWN, ch);
- }
-}
-
-static void
-ctc_purge_skb_queue(struct sk_buff_head *q)
-{
- struct sk_buff *skb;
-
- DBF_TEXT(trace, 5, __FUNCTION__);
-
- while ((skb = skb_dequeue(q))) {
- atomic_dec(&skb->users);
- dev_kfree_skb_irq(skb);
- }
-}
-
-static int
-ctc_checkalloc_buffer(struct channel *ch, int warn)
-{
- DBF_TEXT(trace, 5, __FUNCTION__);
- if ((ch->trans_skb == NULL) ||
- (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED)) {
- if (ch->trans_skb != NULL)
- dev_kfree_skb(ch->trans_skb);
- clear_normalized_cda(&ch->ccw[1]);
- ch->trans_skb = __dev_alloc_skb(ch->max_bufsize,
- GFP_ATOMIC | GFP_DMA);
- if (ch->trans_skb == NULL) {
- if (warn)
- ctc_pr_warn(
- "%s: Couldn't alloc %s trans_skb\n",
- ch->id,
- (CHANNEL_DIRECTION(ch->flags) == READ) ?
- "RX" : "TX");
- return -ENOMEM;
- }
- ch->ccw[1].count = ch->max_bufsize;
- if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
- dev_kfree_skb(ch->trans_skb);
- ch->trans_skb = NULL;
- if (warn)
- ctc_pr_warn(
- "%s: set_normalized_cda for %s "
- "trans_skb failed, dropping packets\n",
- ch->id,
- (CHANNEL_DIRECTION(ch->flags) == READ) ?
- "RX" : "TX");
- return -ENOMEM;
- }
- ch->ccw[1].count = 0;
- ch->trans_skb_data = ch->trans_skb->data;
- ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
- }
- return 0;
-}
-
-/**
- * Dummy NOP action for statemachines
- */
-static void
-fsm_action_nop(fsm_instance * fi, int event, void *arg)
-{
-}
-
-/**
- * Actions for channel - statemachines.
- *****************************************************************************/
-
-/**
- * Normal data has been send. Free the corresponding
- * skb (it's in io_queue), reset dev->tbusy and
- * revert to idle state.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_txdone(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- struct net_device *dev = ch->netdev;
- struct ctc_priv *privptr = dev->priv;
- struct sk_buff *skb;
- int first = 1;
- int i;
- unsigned long duration;
- struct timespec done_stamp = current_kernel_time();
-
- DBF_TEXT(trace, 4, __FUNCTION__);
-
- duration =
- (done_stamp.tv_sec - ch->prof.send_stamp.tv_sec) * 1000000 +
- (done_stamp.tv_nsec - ch->prof.send_stamp.tv_nsec) / 1000;
- if (duration > ch->prof.tx_time)
- ch->prof.tx_time = duration;
-
- if (ch->irb->scsw.count != 0)
- ctc_pr_debug("%s: TX not complete, remaining %d bytes\n",
- dev->name, ch->irb->scsw.count);
- fsm_deltimer(&ch->timer);
- while ((skb = skb_dequeue(&ch->io_queue))) {
- privptr->stats.tx_packets++;
- privptr->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
- if (first) {
- privptr->stats.tx_bytes += 2;
- first = 0;
- }
- atomic_dec(&skb->users);
- dev_kfree_skb_irq(skb);
- }
- spin_lock(&ch->collect_lock);
- clear_normalized_cda(&ch->ccw[4]);
- if (ch->collect_len > 0) {
- int rc;
-
- if (ctc_checkalloc_buffer(ch, 1)) {
- spin_unlock(&ch->collect_lock);
- return;
- }
- ch->trans_skb->data = ch->trans_skb_data;
- skb_reset_tail_pointer(ch->trans_skb);
- ch->trans_skb->len = 0;
- if (ch->prof.maxmulti < (ch->collect_len + 2))
- ch->prof.maxmulti = ch->collect_len + 2;
- if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
- ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
- *((__u16 *) skb_put(ch->trans_skb, 2)) = ch->collect_len + 2;
- i = 0;
- while ((skb = skb_dequeue(&ch->collect_queue))) {
- skb_copy_from_linear_data(skb, skb_put(ch->trans_skb,
- skb->len),
- skb->len);
- privptr->stats.tx_packets++;
- privptr->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
- atomic_dec(&skb->users);
- dev_kfree_skb_irq(skb);
- i++;
- }
- ch->collect_len = 0;
- spin_unlock(&ch->collect_lock);
- ch->ccw[1].count = ch->trans_skb->len;
- fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
- ch->prof.send_stamp = current_kernel_time();
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long) ch, 0xff, 0);
- ch->prof.doios_multi++;
- if (rc != 0) {
- privptr->stats.tx_dropped += i;
- privptr->stats.tx_errors += i;
- fsm_deltimer(&ch->timer);
- ccw_check_return_code(ch, rc, "chained TX");
- }
- } else {
- spin_unlock(&ch->collect_lock);
- fsm_newstate(fi, CH_STATE_TXIDLE);
- }
- ctc_clear_busy(dev);
-}
-
-/**
- * Initial data is sent.
- * Notify device statemachine that we are up and
- * running.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_txidle(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
-
- DBF_TEXT(trace, 4, __FUNCTION__);
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CH_STATE_TXIDLE);
- fsm_event(((struct ctc_priv *) ch->netdev->priv)->fsm, DEV_EVENT_TXUP,
- ch->netdev);
-}
-
-/**
- * Got normal data, check for sanity, queue it up, allocate new buffer
- * trigger bottom half, and initiate next read.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_rx(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- struct net_device *dev = ch->netdev;
- struct ctc_priv *privptr = dev->priv;
- int len = ch->max_bufsize - ch->irb->scsw.count;
- struct sk_buff *skb = ch->trans_skb;
- __u16 block_len = *((__u16 *) skb->data);
- int check_len;
- int rc;
-
- DBF_TEXT(trace, 4, __FUNCTION__);
- fsm_deltimer(&ch->timer);
- if (len < 8) {
- ctc_pr_debug("%s: got packet with length %d < 8\n",
- dev->name, len);
- privptr->stats.rx_dropped++;
- privptr->stats.rx_length_errors++;
- goto again;
- }
- if (len > ch->max_bufsize) {
- ctc_pr_debug("%s: got packet with length %d > %d\n",
- dev->name, len, ch->max_bufsize);
- privptr->stats.rx_dropped++;
- privptr->stats.rx_length_errors++;
- goto again;
- }
-
- /**
- * VM TCP seems to have a bug sending 2 trailing bytes of garbage.
- */
- switch (ch->protocol) {
- case CTC_PROTO_S390:
- case CTC_PROTO_OS390:
- check_len = block_len + 2;
- break;
- default:
- check_len = block_len;
- break;
- }
- if ((len < block_len) || (len > check_len)) {
- ctc_pr_debug("%s: got block length %d != rx length %d\n",
- dev->name, block_len, len);
-#ifdef DEBUG
- ctc_dump_skb(skb, 0);
-#endif
- *((__u16 *) skb->data) = len;
- privptr->stats.rx_dropped++;
- privptr->stats.rx_length_errors++;
- goto again;
- }
- block_len -= 2;
- if (block_len > 0) {
- *((__u16 *) skb->data) = block_len;
- ctc_unpack_skb(ch, skb);
- }
- again:
- skb->data = ch->trans_skb_data;
- skb_reset_tail_pointer(skb);
- skb->len = 0;
- if (ctc_checkalloc_buffer(ch, 1))
- return;
- ch->ccw[1].count = ch->max_bufsize;
- rc = ccw_device_start(ch->cdev, &ch->ccw[0], (unsigned long) ch, 0xff, 0);
- if (rc != 0)
- ccw_check_return_code(ch, rc, "normal RX");
-}
-
-static void ch_action_rxidle(fsm_instance * fi, int event, void *arg);
-
-/**
- * Initialize connection by sending a __u16 of value 0.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_firstio(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- int rc;
-
- DBF_TEXT(trace, 4, __FUNCTION__);
-
- if (fsm_getstate(fi) == CH_STATE_TXIDLE)
- ctc_pr_debug("%s: remote side issued READ?, init ...\n", ch->id);
- fsm_deltimer(&ch->timer);
- if (ctc_checkalloc_buffer(ch, 1))
- return;
- if ((fsm_getstate(fi) == CH_STATE_SETUPWAIT) &&
- (ch->protocol == CTC_PROTO_OS390)) {
- /* OS/390 resp. z/OS */
- if (CHANNEL_DIRECTION(ch->flags) == READ) {
- *((__u16 *) ch->trans_skb->data) = CTC_INITIAL_BLOCKLEN;
- fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC,
- CH_EVENT_TIMER, ch);
- ch_action_rxidle(fi, event, arg);
- } else {
- struct net_device *dev = ch->netdev;
- fsm_newstate(fi, CH_STATE_TXIDLE);
- fsm_event(((struct ctc_priv *) dev->priv)->fsm,
- DEV_EVENT_TXUP, dev);
- }
- return;
- }
-
- /**
- * Don't setup a timer for receiving the initial RX frame
- * if in compatibility mode, since VM TCP delays the initial
- * frame until it has some data to send.
- */
- if ((CHANNEL_DIRECTION(ch->flags) == WRITE) ||
- (ch->protocol != CTC_PROTO_S390))
- fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
-
- *((__u16 *) ch->trans_skb->data) = CTC_INITIAL_BLOCKLEN;
- ch->ccw[1].count = 2; /* Transfer only length */
-
- fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ)
- ? CH_STATE_RXINIT : CH_STATE_TXINIT);
- rc = ccw_device_start(ch->cdev, &ch->ccw[0], (unsigned long) ch, 0xff, 0);
- if (rc != 0) {
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CH_STATE_SETUPWAIT);
- ccw_check_return_code(ch, rc, "init IO");
- }
- /**
- * If in compatibility mode since we don't setup a timer, we
- * also signal RX channel up immediately. This enables us
- * to send packets early which in turn usually triggers some
- * reply from VM TCP which brings up the RX channel to it's
- * final state.
- */
- if ((CHANNEL_DIRECTION(ch->flags) == READ) &&
- (ch->protocol == CTC_PROTO_S390)) {
- struct net_device *dev = ch->netdev;
- fsm_event(((struct ctc_priv *) dev->priv)->fsm, DEV_EVENT_RXUP,
- dev);
- }
-}
-
-/**
- * Got initial data, check it. If OK,
- * notify device statemachine that we are up and
- * running.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_rxidle(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- struct net_device *dev = ch->netdev;
- __u16 buflen;
- int rc;
-
- DBF_TEXT(trace, 4, __FUNCTION__);
- fsm_deltimer(&ch->timer);
- buflen = *((__u16 *) ch->trans_skb->data);
-#ifdef DEBUG
- ctc_pr_debug("%s: Initial RX count %d\n", dev->name, buflen);
-#endif
- if (buflen >= CTC_INITIAL_BLOCKLEN) {
- if (ctc_checkalloc_buffer(ch, 1))
- return;
- ch->ccw[1].count = ch->max_bufsize;
- fsm_newstate(fi, CH_STATE_RXIDLE);
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long) ch, 0xff, 0);
- if (rc != 0) {
- fsm_newstate(fi, CH_STATE_RXINIT);
- ccw_check_return_code(ch, rc, "initial RX");
- } else
- fsm_event(((struct ctc_priv *) dev->priv)->fsm,
- DEV_EVENT_RXUP, dev);
- } else {
- ctc_pr_debug("%s: Initial RX count %d not %d\n",
- dev->name, buflen, CTC_INITIAL_BLOCKLEN);
- ch_action_firstio(fi, event, arg);
- }
-}
-
-/**
- * Set channel into extended mode.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_setmode(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- int rc;
- unsigned long saveflags;
-
- DBF_TEXT(trace, 4, __FUNCTION__);
- fsm_deltimer(&ch->timer);
- fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
- fsm_newstate(fi, CH_STATE_SETUPWAIT);
- saveflags = 0; /* avoids compiler warning with
- spin_unlock_irqrestore */
- if (event == CH_EVENT_TIMER) // only for timer not yet locked
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- rc = ccw_device_start(ch->cdev, &ch->ccw[6], (unsigned long) ch, 0xff, 0);
- if (event == CH_EVENT_TIMER)
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0) {
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CH_STATE_STARTWAIT);
- ccw_check_return_code(ch, rc, "set Mode");
- } else
- ch->retry = 0;
-}
-
-/**
- * Setup channel.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_start(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- unsigned long saveflags;
- int rc;
- struct net_device *dev;
-
- DBF_TEXT(trace, 4, __FUNCTION__);
- if (ch == NULL) {
- ctc_pr_warn("ch_action_start ch=NULL\n");
- return;
- }
- if (ch->netdev == NULL) {
- ctc_pr_warn("ch_action_start dev=NULL, id=%s\n", ch->id);
- return;
- }
- dev = ch->netdev;
-
-#ifdef DEBUG
- ctc_pr_debug("%s: %s channel start\n", dev->name,
- (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
-#endif
-
- if (ch->trans_skb != NULL) {
- clear_normalized_cda(&ch->ccw[1]);
- dev_kfree_skb(ch->trans_skb);
- ch->trans_skb = NULL;
- }
- if (CHANNEL_DIRECTION(ch->flags) == READ) {
- ch->ccw[1].cmd_code = CCW_CMD_READ;
- ch->ccw[1].flags = CCW_FLAG_SLI;
- ch->ccw[1].count = 0;
- } else {
- ch->ccw[1].cmd_code = CCW_CMD_WRITE;
- ch->ccw[1].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
- ch->ccw[1].count = 0;
- }
- if (ctc_checkalloc_buffer(ch, 0)) {
- ctc_pr_notice(
- "%s: Could not allocate %s trans_skb, delaying "
- "allocation until first transfer\n",
- dev->name,
- (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
- }
-
- ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
- ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
- ch->ccw[0].count = 0;
- ch->ccw[0].cda = 0;
- ch->ccw[2].cmd_code = CCW_CMD_NOOP; /* jointed CE + DE */
- ch->ccw[2].flags = CCW_FLAG_SLI;
- ch->ccw[2].count = 0;
- ch->ccw[2].cda = 0;
- memcpy(&ch->ccw[3], &ch->ccw[0], sizeof (struct ccw1) * 3);
- ch->ccw[4].cda = 0;
- ch->ccw[4].flags &= ~CCW_FLAG_IDA;
-
- fsm_newstate(fi, CH_STATE_STARTWAIT);
- fsm_addtimer(&ch->timer, 1000, CH_EVENT_TIMER, ch);
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0) {
- if (rc != -EBUSY)
- fsm_deltimer(&ch->timer);
- ccw_check_return_code(ch, rc, "initial HaltIO");
- }
-#ifdef DEBUG
- ctc_pr_debug("ctc: %s(): leaving\n", __func__);
-#endif
-}
-
-/**
- * Shutdown a channel.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_haltio(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- unsigned long saveflags;
- int rc;
- int oldstate;
-
- DBF_TEXT(trace, 3, __FUNCTION__);
- fsm_deltimer(&ch->timer);
- fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
- saveflags = 0; /* avoids comp warning with
- spin_unlock_irqrestore */
- if (event == CH_EVENT_STOP) // only for STOP not yet locked
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- oldstate = fsm_getstate(fi);
- fsm_newstate(fi, CH_STATE_TERM);
- rc = ccw_device_halt(ch->cdev, (unsigned long) ch);
- if (event == CH_EVENT_STOP)
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0) {
- if (rc != -EBUSY) {
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, oldstate);
- }
- ccw_check_return_code(ch, rc, "HaltIO in ch_action_haltio");
- }
-}
-
-/**
- * A channel has successfully been halted.
- * Cleanup it's queue and notify interface statemachine.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_stopped(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- struct net_device *dev = ch->netdev;
-
- DBF_TEXT(trace, 3, __FUNCTION__);
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CH_STATE_STOPPED);
- if (ch->trans_skb != NULL) {
- clear_normalized_cda(&ch->ccw[1]);
- dev_kfree_skb(ch->trans_skb);
- ch->trans_skb = NULL;
- }
- if (CHANNEL_DIRECTION(ch->flags) == READ) {
- skb_queue_purge(&ch->io_queue);
- fsm_event(((struct ctc_priv *) dev->priv)->fsm,
- DEV_EVENT_RXDOWN, dev);
- } else {
- ctc_purge_skb_queue(&ch->io_queue);
- spin_lock(&ch->collect_lock);
- ctc_purge_skb_queue(&ch->collect_queue);
- ch->collect_len = 0;
- spin_unlock(&ch->collect_lock);
- fsm_event(((struct ctc_priv *) dev->priv)->fsm,
- DEV_EVENT_TXDOWN, dev);
- }
-}
-
-/**
- * A stop command from device statemachine arrived and we are in
- * not operational mode. Set state to stopped.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_stop(fsm_instance * fi, int event, void *arg)
-{
- fsm_newstate(fi, CH_STATE_STOPPED);
-}
-
-/**
- * A machine check for no path, not operational status or gone device has
- * happened.
- * Cleanup queue and notify interface statemachine.
- *
- * @param fi An instance of a channel statemachine.
- * @param event The event, just happened.
- * @param arg Generic pointer, casted from channel * upon call.
- */
-static void
-ch_action_fail(fsm_instance * fi, int event, void *arg)
-{
- struct channel *ch = (struct channel *) arg;
- struct net_device *dev = ch->netdev;
-
- DBF_TEXT(trace, 3, __FUNCTION__);
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CH_STATE_NOTOP);
- if (CHANNEL_DIRECTION(ch->flags) == READ) {
- skb_queue_purge(&ch->io_queue);
- fsm_event(((struct ctc_priv *) dev->priv)->fsm,
- DEV_EVENT_RXDOWN, dev);
- } else {
- ctc_purge_skb_queue(&ch->io_queue);
- spin_lock(&ch->collect_lock);
- ctc_purge_skb_queue(&ch->collect_queue);
- ch->collect_len = 0;
- spin_unlock(&ch->collect_lock);
- fsm_event(((struct ctc_priv *) dev->priv)->fsm,
- DEV_EVENT_TXDOWN, dev);
- }
-}
-
-/**
- * Handle error during setup of channel.
- *
- * @param fi