2 * drivers/s390/net/ctcm_main.h
4 * Copyright IBM Corp. 2001, 2007
5 * Authors: Fritz Elfert (felfert@millenux.com)
6 * Peter Tiedemann (ptiedem@de.ibm.com)
12 #include <asm/ccwdev.h>
13 #include <asm/ccwgroup.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
20 #include "ctcm_dbug.h"
23 #define CTC_DRIVER_NAME "ctcm"
24 #define CTC_DEVICE_NAME "ctc"
25 #define CTC_DEVICE_GENE "ctc%d"
26 #define MPC_DEVICE_NAME "mpc"
27 #define MPC_DEVICE_GENE "mpc%d"
29 #define CHANNEL_FLAGS_READ 0
30 #define CHANNEL_FLAGS_WRITE 1
31 #define CHANNEL_FLAGS_INUSE 2
32 #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
33 #define CHANNEL_FLAGS_FAILED 8
34 #define CHANNEL_FLAGS_WAITIRQ 16
35 #define CHANNEL_FLAGS_RWMASK 1
36 #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
38 #define LOG_FLAG_ILLEGALPKT 1
39 #define LOG_FLAG_ILLEGALSIZE 2
40 #define LOG_FLAG_OVERRUN 4
41 #define LOG_FLAG_NOMEM 8
43 #define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
44 #define ctcm_pr_info(fmt, arg...) printk(KERN_INFO fmt, ##arg)
45 #define ctcm_pr_notice(fmt, arg...) printk(KERN_NOTICE fmt, ##arg)
46 #define ctcm_pr_warn(fmt, arg...) printk(KERN_WARNING fmt, ##arg)
47 #define ctcm_pr_emerg(fmt, arg...) printk(KERN_EMERG fmt, ##arg)
48 #define ctcm_pr_err(fmt, arg...) printk(KERN_ERR fmt, ##arg)
49 #define ctcm_pr_crit(fmt, arg...) printk(KERN_CRIT fmt, ##arg)
52 * CCW commands, used in this driver.
54 #define CCW_CMD_WRITE 0x01
55 #define CCW_CMD_READ 0x02
56 #define CCW_CMD_NOOP 0x03
57 #define CCW_CMD_TIC 0x08
58 #define CCW_CMD_SENSE_CMD 0x14
59 #define CCW_CMD_WRITE_CTL 0x17
60 #define CCW_CMD_SET_EXTENDED 0xc3
61 #define CCW_CMD_PREPARE 0xe3
63 #define CTCM_PROTO_S390 0
64 #define CTCM_PROTO_LINUX 1
65 #define CTCM_PROTO_LINUX_TTY 2
66 #define CTCM_PROTO_OS390 3
67 #define CTCM_PROTO_MPC 4
68 #define CTCM_PROTO_MAX 4
70 #define CTCM_BUFSIZE_LIMIT 65535
71 #define CTCM_BUFSIZE_DEFAULT 32768
72 #define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
74 #define CTCM_TIME_1_SEC 1000
75 #define CTCM_TIME_5_SEC 5000
76 #define CTCM_TIME_10_SEC 10000
78 #define CTCM_INITIAL_BLOCKLEN 2
83 #define CTCM_ID_SIZE BUS_ID_SIZE+3
86 unsigned long maxmulti;
87 unsigned long maxcqueue;
88 unsigned long doios_single;
89 unsigned long doios_multi;
91 unsigned long tx_time;
92 struct timespec send_stamp;
96 * Definition of one channel
100 char id[CTCM_ID_SIZE];
101 struct ccw_device *cdev;
103 * Type of this channel.
104 * CTC/A or Escon for valid channels.
106 enum channel_types type;
108 * Misc. flags. See CHANNEL_FLAGS_... below
111 __u16 protocol; /* protocol of this channel (4 = MPC) */
113 * I/O and irq related stuff
121 struct sk_buff *trans_skb; /* transmit/receive buffer */
122 struct sk_buff_head io_queue; /* universal I/O queue */
123 struct tasklet_struct ch_tasklet; /* MPC ONLY */
125 * TX queue for collecting skb's during busy.
127 struct sk_buff_head collect_queue;
129 * Amount of data in collect_queue.
133 * spinlock for collect_queue and collect_len
135 spinlock_t collect_lock;
137 * Timer for detecting unresposive
141 /* MPC ONLY section begin */
142 __u32 th_seq_num; /* SNA TH seq number */
145 struct sk_buff *xid_skb;
147 struct th_header *xid_th;
150 struct th_header *rcvd_xid_th;
151 struct xid2 *rcvd_xid;
154 fsm_timer sweep_timer;
155 struct sk_buff_head sweep_queue;
156 struct th_header *discontact_th;
157 struct tasklet_struct ch_disc_tasklet;
158 /* MPC ONLY section end */
160 int retry; /* retry counter for misc. operations */
161 fsm_instance *fsm; /* finite state machine of this channel */
162 struct net_device *netdev; /* corresponding net_device */
163 struct ctcm_profile prof;
164 unsigned char *trans_skb_data;
169 struct net_device_stats stats;
172 /* The MPC group struct of this interface */
173 struct mpc_group *mpcg; /* MPC only */
174 struct xid2 *xid; /* MPC only */
176 /* The finite state machine of this interface */
179 /* The protocol of this device */
182 /* Timer for restarting after I/O Errors */
183 fsm_timer restart_timer;
185 int buffer_size; /* ctc only */
187 struct channel *channel[2];
190 int ctcm_open(struct net_device *dev);
191 int ctcm_close(struct net_device *dev);
194 * prototypes for non-static sysfs functions
196 int ctcm_add_attributes(struct device *dev);
197 void ctcm_remove_attributes(struct device *dev);
198 int ctcm_add_files(struct device *dev);
199 void ctcm_remove_files(struct device *dev);
202 * Compatibility macros for busy handling
203 * of network devices.
205 static inline void ctcm_clear_busy_do(struct net_device *dev)
207 clear_bit(0, &(((struct ctcm_priv *)dev->priv)->tbusy));
208 netif_wake_queue(dev);
211 static inline void ctcm_clear_busy(struct net_device *dev)
213 struct mpc_group *grp;
214 grp = ((struct ctcm_priv *)dev->priv)->mpcg;
216 if (!(grp && grp->in_sweep))
217 ctcm_clear_busy_do(dev);
221 static inline int ctcm_test_and_set_busy(struct net_device *dev)
223 netif_stop_queue(dev);
224 return test_and_set_bit(0, &(((struct ctcm_priv *)dev->priv)->tbusy));
228 extern struct channel *channels;
230 void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb);
233 * Functions related to setup and device detection.
236 static inline int ctcm_less_than(char *id1, char *id2)
238 unsigned long dev1, dev2;
243 dev1 = simple_strtoul(id1, &id1, 16);
244 dev2 = simple_strtoul(id2, &id2, 16);
246 return (dev1 < dev2);
249 int ctcm_ch_alloc_buffer(struct channel *ch);
251 static inline int ctcm_checkalloc_buffer(struct channel *ch)
253 if (ch->trans_skb == NULL)
254 return ctcm_ch_alloc_buffer(ch);
255 if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) {
256 dev_kfree_skb(ch->trans_skb);
257 return ctcm_ch_alloc_buffer(ch);
262 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
264 /* test if protocol attribute (of struct ctcm_priv or struct channel)
265 * has MPC protocol setting. Type is not checked
267 #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
269 /* test if struct ctcm_priv of struct net_device has MPC protocol setting */
270 #define IS_MPCDEV(d) IS_MPC((struct ctcm_priv *)d->priv)
272 static inline gfp_t gfp_type(void)
274 return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
278 * Definition of our link level header.
285 #define LL_HEADER_LENGTH (sizeof(struct ll_header))