Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  Copyright IBM Corp. 2001, 2007
0004  *  Authors:    Fritz Elfert (felfert@millenux.com)
0005  *          Peter Tiedemann (ptiedem@de.ibm.com)
0006  */
0007 
0008 #ifndef _CTCM_MAIN_H_
0009 #define _CTCM_MAIN_H_
0010 
0011 #include <asm/ccwdev.h>
0012 #include <asm/ccwgroup.h>
0013 
0014 #include <linux/skbuff.h>
0015 #include <linux/netdevice.h>
0016 
0017 #include "fsm.h"
0018 #include "ctcm_dbug.h"
0019 #include "ctcm_mpc.h"
0020 
0021 #define CTC_DRIVER_NAME "ctcm"
0022 #define CTC_DEVICE_NAME "ctc"
0023 #define MPC_DEVICE_NAME "mpc"
0024 #define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d"
0025 #define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d"
0026 
0027 #define CHANNEL_FLAGS_READ  0
0028 #define CHANNEL_FLAGS_WRITE 1
0029 #define CHANNEL_FLAGS_INUSE 2
0030 #define CHANNEL_FLAGS_BUFSIZE_CHANGED   4
0031 #define CHANNEL_FLAGS_FAILED    8
0032 #define CHANNEL_FLAGS_WAITIRQ   16
0033 #define CHANNEL_FLAGS_RWMASK    1
0034 #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
0035 
0036 #define LOG_FLAG_ILLEGALPKT 1
0037 #define LOG_FLAG_ILLEGALSIZE    2
0038 #define LOG_FLAG_OVERRUN    4
0039 #define LOG_FLAG_NOMEM      8
0040 
0041 #define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
0042 
0043 #define CTCM_PR_DEBUG(fmt, arg...) \
0044     do { \
0045         if (do_debug) \
0046             printk(KERN_DEBUG fmt, ##arg); \
0047     } while (0)
0048 
0049 #define CTCM_PR_DBGDATA(fmt, arg...) \
0050     do { \
0051         if (do_debug_data) \
0052             printk(KERN_DEBUG fmt, ##arg); \
0053     } while (0)
0054 
0055 #define CTCM_D3_DUMP(buf, len) \
0056     do { \
0057         if (do_debug_data) \
0058             ctcmpc_dumpit(buf, len); \
0059     } while (0)
0060 
0061 #define CTCM_CCW_DUMP(buf, len) \
0062     do { \
0063         if (do_debug_ccw) \
0064             ctcmpc_dumpit(buf, len); \
0065     } while (0)
0066 
0067 /**
0068  * Enum for classifying detected devices
0069  */
0070 enum ctcm_channel_types {
0071     /* Device is not a channel  */
0072     ctcm_channel_type_none,
0073 
0074     /* Device is a CTC/A */
0075     ctcm_channel_type_parallel,
0076 
0077     /* Device is a FICON channel */
0078     ctcm_channel_type_ficon,
0079 
0080     /* Device is a ESCON channel */
0081     ctcm_channel_type_escon
0082 };
0083 
0084 /*
0085  * CCW commands, used in this driver.
0086  */
0087 #define CCW_CMD_WRITE       0x01
0088 #define CCW_CMD_READ        0x02
0089 #define CCW_CMD_NOOP        0x03
0090 #define CCW_CMD_TIC             0x08
0091 #define CCW_CMD_SENSE_CMD   0x14
0092 #define CCW_CMD_WRITE_CTL   0x17
0093 #define CCW_CMD_SET_EXTENDED    0xc3
0094 #define CCW_CMD_PREPARE     0xe3
0095 
0096 #define CTCM_PROTO_S390     0
0097 #define CTCM_PROTO_LINUX    1
0098 #define CTCM_PROTO_LINUX_TTY    2
0099 #define CTCM_PROTO_OS390    3
0100 #define CTCM_PROTO_MPC      4
0101 #define CTCM_PROTO_MAX      4
0102 
0103 #define CTCM_BUFSIZE_LIMIT  65535
0104 #define CTCM_BUFSIZE_DEFAULT    32768
0105 #define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
0106 
0107 #define CTCM_TIME_1_SEC     1000
0108 #define CTCM_TIME_5_SEC     5000
0109 #define CTCM_TIME_10_SEC    10000
0110 
0111 #define CTCM_INITIAL_BLOCKLEN   2
0112 
0113 #define CTCM_READ       0
0114 #define CTCM_WRITE      1
0115 
0116 #define CTCM_ID_SIZE        20+3
0117 
0118 struct ctcm_profile {
0119     unsigned long maxmulti;
0120     unsigned long maxcqueue;
0121     unsigned long doios_single;
0122     unsigned long doios_multi;
0123     unsigned long txlen;
0124     unsigned long tx_time;
0125     unsigned long send_stamp;
0126 };
0127 
0128 /*
0129  * Definition of one channel
0130  */
0131 struct channel {
0132     struct channel *next;
0133     char id[CTCM_ID_SIZE];
0134     struct ccw_device *cdev;
0135     /*
0136      * Type of this channel.
0137      * CTC/A or Escon for valid channels.
0138      */
0139     enum ctcm_channel_types type;
0140     /*
0141      * Misc. flags. See CHANNEL_FLAGS_... below
0142      */
0143     __u32 flags;
0144     __u16 protocol;     /* protocol of this channel (4 = MPC) */
0145     /*
0146      * I/O and irq related stuff
0147      */
0148     struct ccw1 *ccw;
0149     struct irb *irb;
0150     /*
0151      * RX/TX buffer size
0152      */
0153     int max_bufsize;
0154     struct sk_buff *trans_skb;  /* transmit/receive buffer */
0155     struct sk_buff_head io_queue;   /* universal I/O queue */
0156     struct tasklet_struct ch_tasklet;   /* MPC ONLY */
0157     /*
0158      * TX queue for collecting skb's during busy.
0159      */
0160     struct sk_buff_head collect_queue;
0161     /*
0162      * Amount of data in collect_queue.
0163      */
0164     int collect_len;
0165     /*
0166      * spinlock for collect_queue and collect_len
0167      */
0168     spinlock_t collect_lock;
0169     /*
0170      * Timer for detecting unresposive
0171      * I/O operations.
0172      */
0173     fsm_timer timer;
0174     /* MPC ONLY section begin */
0175     __u32   th_seq_num; /* SNA TH seq number */
0176     __u8    th_seg;
0177     __u32   pdu_seq;
0178     struct sk_buff      *xid_skb;
0179     char            *xid_skb_data;
0180     struct th_header    *xid_th;
0181     struct xid2     *xid;
0182     char            *xid_id;
0183     struct th_header    *rcvd_xid_th;
0184     struct xid2     *rcvd_xid;
0185     char            *rcvd_xid_id;
0186     __u8            in_mpcgroup;
0187     fsm_timer       sweep_timer;
0188     struct sk_buff_head sweep_queue;
0189     struct th_header    *discontact_th;
0190     struct tasklet_struct   ch_disc_tasklet;
0191     /* MPC ONLY section end */
0192 
0193     int retry;      /* retry counter for misc. operations */
0194     fsm_instance *fsm;  /* finite state machine of this channel */
0195     struct net_device *netdev;  /* corresponding net_device */
0196     struct ctcm_profile prof;
0197     __u8 *trans_skb_data;
0198     __u16 logflags;
0199     __u8  sense_rc; /* last unit check sense code report control */
0200 };
0201 
0202 struct ctcm_priv {
0203     struct net_device_stats stats;
0204     unsigned long   tbusy;
0205 
0206     /* The MPC group struct of this interface */
0207     struct  mpc_group   *mpcg;  /* MPC only */
0208     struct  xid2        *xid;   /* MPC only */
0209 
0210     /* The finite state machine of this interface */
0211     fsm_instance *fsm;
0212 
0213     /* The protocol of this device */
0214     __u16 protocol;
0215 
0216     /* Timer for restarting after I/O Errors */
0217     fsm_timer   restart_timer;
0218 
0219     int buffer_size;    /* ctc only */
0220 
0221     struct channel *channel[2];
0222 };
0223 
0224 int ctcm_open(struct net_device *dev);
0225 int ctcm_close(struct net_device *dev);
0226 
0227 extern const struct attribute_group *ctcm_attr_groups[];
0228 
0229 /*
0230  * Compatibility macros for busy handling
0231  * of network devices.
0232  */
0233 static inline void ctcm_clear_busy_do(struct net_device *dev)
0234 {
0235     clear_bit(0, &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
0236     netif_wake_queue(dev);
0237 }
0238 
0239 static inline void ctcm_clear_busy(struct net_device *dev)
0240 {
0241     struct mpc_group *grp;
0242     grp = ((struct ctcm_priv *)dev->ml_priv)->mpcg;
0243 
0244     if (!(grp && grp->in_sweep))
0245         ctcm_clear_busy_do(dev);
0246 }
0247 
0248 
0249 static inline int ctcm_test_and_set_busy(struct net_device *dev)
0250 {
0251     netif_stop_queue(dev);
0252     return test_and_set_bit(0,
0253             &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
0254 }
0255 
0256 extern int loglevel;
0257 extern struct channel *channels;
0258 
0259 void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb);
0260 
0261 /*
0262  * Functions related to setup and device detection.
0263  */
0264 
0265 static inline int ctcm_less_than(char *id1, char *id2)
0266 {
0267     unsigned long dev1, dev2;
0268 
0269     id1 = id1 + 5;
0270     id2 = id2 + 5;
0271 
0272     dev1 = simple_strtoul(id1, &id1, 16);
0273     dev2 = simple_strtoul(id2, &id2, 16);
0274 
0275     return (dev1 < dev2);
0276 }
0277 
0278 int ctcm_ch_alloc_buffer(struct channel *ch);
0279 
0280 static inline int ctcm_checkalloc_buffer(struct channel *ch)
0281 {
0282     if (ch->trans_skb == NULL)
0283         return ctcm_ch_alloc_buffer(ch);
0284     if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) {
0285         dev_kfree_skb(ch->trans_skb);
0286         return ctcm_ch_alloc_buffer(ch);
0287     }
0288     return 0;
0289 }
0290 
0291 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
0292 
0293 /* test if protocol attribute (of struct ctcm_priv or struct channel)
0294  * has MPC protocol setting. Type is not checked
0295  */
0296 #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
0297 
0298 /* test if struct ctcm_priv of struct net_device has MPC protocol setting */
0299 #define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv)
0300 
0301 /*
0302  * Definition of our link level header.
0303  */
0304 struct ll_header {
0305     __u16 length;
0306     __u16 type;
0307     __u16 unused;
0308 };
0309 #define LL_HEADER_LENGTH (sizeof(struct ll_header))
0310 
0311 #endif