1293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* 2293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Copyright IBM Corp. 2001, 2007 3293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Authors: Fritz Elfert (felfert@millenux.com) 4293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Peter Tiedemann (ptiedem@de.ibm.com) 5293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 6293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 7293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#ifndef _CTCM_MAIN_H_ 8293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define _CTCM_MAIN_H_ 9293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 10293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#include <asm/ccwdev.h> 11293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#include <asm/ccwgroup.h> 12293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 13293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#include <linux/skbuff.h> 14293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#include <linux/netdevice.h> 15293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 16293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#include "fsm.h" 17293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#include "ctcm_dbug.h" 18293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#include "ctcm_mpc.h" 19293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 20293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTC_DRIVER_NAME "ctcm" 21293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTC_DEVICE_NAME "ctc" 22293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define MPC_DEVICE_NAME "mpc" 23aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann#define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d" 24aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann#define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d" 25293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 26293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_FLAGS_READ 0 27293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_FLAGS_WRITE 1 28293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_FLAGS_INUSE 2 29293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_FLAGS_BUFSIZE_CHANGED 4 30293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_FLAGS_FAILED 8 31293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_FLAGS_WAITIRQ 16 32293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_FLAGS_RWMASK 1 33293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK) 34293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 35293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define LOG_FLAG_ILLEGALPKT 1 36293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define LOG_FLAG_ILLEGALSIZE 2 37293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define LOG_FLAG_OVERRUN 4 38293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define LOG_FLAG_NOMEM 8 39293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 40293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg) 41293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 42aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann#define CTCM_PR_DEBUG(fmt, arg...) \ 43aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann do { \ 44aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann if (do_debug) \ 45aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann printk(KERN_DEBUG fmt, ##arg); \ 46aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann } while (0) 47aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann 48aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann#define CTCM_PR_DBGDATA(fmt, arg...) \ 49aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann do { \ 50aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann if (do_debug_data) \ 51aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann printk(KERN_DEBUG fmt, ##arg); \ 52aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann } while (0) 53aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann 54aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann#define CTCM_D3_DUMP(buf, len) \ 55aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann do { \ 56aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann if (do_debug_data) \ 57aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann ctcmpc_dumpit(buf, len); \ 58aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann } while (0) 59aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann 60aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann#define CTCM_CCW_DUMP(buf, len) \ 61aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann do { \ 62aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann if (do_debug_ccw) \ 63aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann ctcmpc_dumpit(buf, len); \ 64aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann } while (0) 65aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann 660ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun/** 670ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun * Enum for classifying detected devices 680ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun */ 690ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braunenum ctcm_channel_types { 700ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun /* Device is not a channel */ 710ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun ctcm_channel_type_none, 720ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun 730ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun /* Device is a CTC/A */ 740ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun ctcm_channel_type_parallel, 750ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun 760ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun /* Device is a FICON channel */ 770ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun ctcm_channel_type_ficon, 780ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun 790ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun /* Device is a ESCON channel */ 800ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun ctcm_channel_type_escon 810ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun}; 820ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun 83293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* 84293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * CCW commands, used in this driver. 85293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 86293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_WRITE 0x01 87293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_READ 0x02 88293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_NOOP 0x03 89293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_TIC 0x08 90293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_SENSE_CMD 0x14 91293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_WRITE_CTL 0x17 92293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_SET_EXTENDED 0xc3 93293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CCW_CMD_PREPARE 0xe3 94293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 95293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_PROTO_S390 0 96293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_PROTO_LINUX 1 97293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_PROTO_LINUX_TTY 2 98293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_PROTO_OS390 3 99293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_PROTO_MPC 4 100293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_PROTO_MAX 4 101293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 102293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_BUFSIZE_LIMIT 65535 103293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_BUFSIZE_DEFAULT 32768 104293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT 105293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 106293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_TIME_1_SEC 1000 107293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_TIME_5_SEC 5000 108293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_TIME_10_SEC 10000 109293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 110293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define CTCM_INITIAL_BLOCKLEN 2 111293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 1123c09e2647b5e1f1f9fd383971468823c2505e1b0Ursula Braun#define CTCM_READ 0 1133c09e2647b5e1f1f9fd383971468823c2505e1b0Ursula Braun#define CTCM_WRITE 1 114293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 1152a0217d5c7d22d6dd28f8ae5d20b06d24dc426b8Kay Sievers#define CTCM_ID_SIZE 20+3 116293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 117293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstruct ctcm_profile { 118293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long maxmulti; 119293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long maxcqueue; 120293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long doios_single; 121293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long doios_multi; 122293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long txlen; 123293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long tx_time; 124293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct timespec send_stamp; 125293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann}; 126293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 127293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* 128293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Definition of one channel 129293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 130293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstruct channel { 131293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct channel *next; 132293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann char id[CTCM_ID_SIZE]; 133293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct ccw_device *cdev; 134293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 135293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Type of this channel. 136293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * CTC/A or Escon for valid channels. 137293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 1380ca8cc6fe7e1acd42a8a3741473ad7540f13893aUrsula Braun enum ctcm_channel_types type; 139293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 140293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Misc. flags. See CHANNEL_FLAGS_... below 141293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 142293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u32 flags; 143293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u16 protocol; /* protocol of this channel (4 = MPC) */ 144293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 145293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * I/O and irq related stuff 146293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 147293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct ccw1 *ccw; 148293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct irb *irb; 149293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 150293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * RX/TX buffer size 151293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 152293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann int max_bufsize; 153293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct sk_buff *trans_skb; /* transmit/receive buffer */ 154293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct sk_buff_head io_queue; /* universal I/O queue */ 155293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct tasklet_struct ch_tasklet; /* MPC ONLY */ 156293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 157293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * TX queue for collecting skb's during busy. 158293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 159293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct sk_buff_head collect_queue; 160293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 161293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Amount of data in collect_queue. 162293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 163293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann int collect_len; 164293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 165293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * spinlock for collect_queue and collect_len 166293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 167293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann spinlock_t collect_lock; 168293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* 169293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Timer for detecting unresposive 170293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * I/O operations. 171293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 172293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann fsm_timer timer; 173293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* MPC ONLY section begin */ 174293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u32 th_seq_num; /* SNA TH seq number */ 175293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u8 th_seg; 176293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u32 pdu_seq; 177293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct sk_buff *xid_skb; 178293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann char *xid_skb_data; 179293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct th_header *xid_th; 180293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct xid2 *xid; 181293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann char *xid_id; 182293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct th_header *rcvd_xid_th; 183293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct xid2 *rcvd_xid; 184293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann char *rcvd_xid_id; 185293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u8 in_mpcgroup; 186293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann fsm_timer sweep_timer; 187293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct sk_buff_head sweep_queue; 188293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct th_header *discontact_th; 189293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct tasklet_struct ch_disc_tasklet; 190293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* MPC ONLY section end */ 191293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 192293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann int retry; /* retry counter for misc. operations */ 193293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann fsm_instance *fsm; /* finite state machine of this channel */ 194293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct net_device *netdev; /* corresponding net_device */ 195293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct ctcm_profile prof; 196aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann __u8 *trans_skb_data; 197293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u16 logflags; 198aa3f2cb63086e474a2ac3836d01fc6d9db393846Peter Tiedemann __u8 sense_rc; /* last unit check sense code report control */ 199293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann}; 200293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 201293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstruct ctcm_priv { 202293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct net_device_stats stats; 203293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long tbusy; 204293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 205293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* The MPC group struct of this interface */ 206293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct mpc_group *mpcg; /* MPC only */ 207293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct xid2 *xid; /* MPC only */ 208293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 209293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* The finite state machine of this interface */ 210293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann fsm_instance *fsm; 211293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 212293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* The protocol of this device */ 213293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u16 protocol; 214293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 215293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann /* Timer for restarting after I/O Errors */ 216293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann fsm_timer restart_timer; 217293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 218293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann int buffer_size; /* ctc only */ 219293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 220293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct channel *channel[2]; 221293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann}; 222293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 223293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannint ctcm_open(struct net_device *dev); 224293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannint ctcm_close(struct net_device *dev); 225293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 22620cdffa437f51f3afdf41e431ca17014434d3037Sebastian Ottextern const struct attribute_group *ctcm_attr_groups[]; 227293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 228293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* 229293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Compatibility macros for busy handling 230293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * of network devices. 231293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 232293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstatic inline void ctcm_clear_busy_do(struct net_device *dev) 233293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann{ 234261893d30b0ddb5587f9143df18a6efed39a7ed6Peter Tiedemann clear_bit(0, &(((struct ctcm_priv *)dev->ml_priv)->tbusy)); 235293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann netif_wake_queue(dev); 236293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann} 237293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 238293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstatic inline void ctcm_clear_busy(struct net_device *dev) 239293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann{ 240293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann struct mpc_group *grp; 241261893d30b0ddb5587f9143df18a6efed39a7ed6Peter Tiedemann grp = ((struct ctcm_priv *)dev->ml_priv)->mpcg; 242293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 243293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann if (!(grp && grp->in_sweep)) 244293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann ctcm_clear_busy_do(dev); 245293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann} 246293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 247293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 248293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstatic inline int ctcm_test_and_set_busy(struct net_device *dev) 249293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann{ 250293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann netif_stop_queue(dev); 251261893d30b0ddb5587f9143df18a6efed39a7ed6Peter Tiedemann return test_and_set_bit(0, 252261893d30b0ddb5587f9143df18a6efed39a7ed6Peter Tiedemann &(((struct ctcm_priv *)dev->ml_priv)->tbusy)); 253293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann} 254293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 255293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannextern int loglevel; 256293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannextern struct channel *channels; 257293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 258293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannvoid ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb); 259293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 260293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* 261293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Functions related to setup and device detection. 262293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 263293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 264293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstatic inline int ctcm_less_than(char *id1, char *id2) 265293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann{ 266293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann unsigned long dev1, dev2; 267293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 268293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann id1 = id1 + 5; 269293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann id2 = id2 + 5; 270293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 271293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann dev1 = simple_strtoul(id1, &id1, 16); 272293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann dev2 = simple_strtoul(id2, &id2, 16); 273293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 274293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann return (dev1 < dev2); 275293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann} 276293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 277293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannint ctcm_ch_alloc_buffer(struct channel *ch); 278293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 279293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstatic inline int ctcm_checkalloc_buffer(struct channel *ch) 280293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann{ 281293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann if (ch->trans_skb == NULL) 282293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann return ctcm_ch_alloc_buffer(ch); 283293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) { 284293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann dev_kfree_skb(ch->trans_skb); 285293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann return ctcm_ch_alloc_buffer(ch); 286293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann } 287293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann return 0; 288293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann} 289293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 290293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstruct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv); 291293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 292293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* test if protocol attribute (of struct ctcm_priv or struct channel) 293293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * has MPC protocol setting. Type is not checked 294293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 295293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC) 296293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 297293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* test if struct ctcm_priv of struct net_device has MPC protocol setting */ 298261893d30b0ddb5587f9143df18a6efed39a7ed6Peter Tiedemann#define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv) 299293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 300293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstatic inline gfp_t gfp_type(void) 301293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann{ 302293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; 303293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann} 304293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 305293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann/* 306293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann * Definition of our link level header. 307293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann */ 308293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemannstruct ll_header { 309293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u16 length; 310293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u16 type; 311293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann __u16 unused; 312293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann}; 313293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#define LL_HEADER_LENGTH (sizeof(struct ll_header)) 314293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann 315293d984f0e3604c04dcdbf00117ddc1e5d4b1909Peter Tiedemann#endif 316