1
2
3
4
5
6
7
8
9#ifndef _CTCM_MAIN_H_
10#define _CTCM_MAIN_H_
11
12#include <asm/ccwdev.h>
13#include <asm/ccwgroup.h>
14
15#include <linux/skbuff.h>
16#include <linux/netdevice.h>
17
18#include "fsm.h"
19#include "cu3088.h"
20#include "ctcm_dbug.h"
21#include "ctcm_mpc.h"
22
23#define CTC_DRIVER_NAME "ctcm"
24#define CTC_DEVICE_NAME "ctc"
25#define MPC_DEVICE_NAME "mpc"
26#define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d"
27#define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d"
28
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)
37
38#define LOG_FLAG_ILLEGALPKT 1
39#define LOG_FLAG_ILLEGALSIZE 2
40#define LOG_FLAG_OVERRUN 4
41#define LOG_FLAG_NOMEM 8
42
43#define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
44
45#define CTCM_PR_DEBUG(fmt, arg...) \
46 do { \
47 if (do_debug) \
48 printk(KERN_DEBUG fmt, ##arg); \
49 } while (0)
50
51#define CTCM_PR_DBGDATA(fmt, arg...) \
52 do { \
53 if (do_debug_data) \
54 printk(KERN_DEBUG fmt, ##arg); \
55 } while (0)
56
57#define CTCM_D3_DUMP(buf, len) \
58 do { \
59 if (do_debug_data) \
60 ctcmpc_dumpit(buf, len); \
61 } while (0)
62
63#define CTCM_CCW_DUMP(buf, len) \
64 do { \
65 if (do_debug_ccw) \
66 ctcmpc_dumpit(buf, len); \
67 } while (0)
68
69
70
71
72#define CCW_CMD_WRITE 0x01
73#define CCW_CMD_READ 0x02
74#define CCW_CMD_NOOP 0x03
75#define CCW_CMD_TIC 0x08
76#define CCW_CMD_SENSE_CMD 0x14
77#define CCW_CMD_WRITE_CTL 0x17
78#define CCW_CMD_SET_EXTENDED 0xc3
79#define CCW_CMD_PREPARE 0xe3
80
81#define CTCM_PROTO_S390 0
82#define CTCM_PROTO_LINUX 1
83#define CTCM_PROTO_LINUX_TTY 2
84#define CTCM_PROTO_OS390 3
85#define CTCM_PROTO_MPC 4
86#define CTCM_PROTO_MAX 4
87
88#define CTCM_BUFSIZE_LIMIT 65535
89#define CTCM_BUFSIZE_DEFAULT 32768
90#define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
91
92#define CTCM_TIME_1_SEC 1000
93#define CTCM_TIME_5_SEC 5000
94#define CTCM_TIME_10_SEC 10000
95
96#define CTCM_INITIAL_BLOCKLEN 2
97
98#define READ 0
99#define WRITE 1
100
101#define CTCM_ID_SIZE 20+3
102
103struct ctcm_profile {
104 unsigned long maxmulti;
105 unsigned long maxcqueue;
106 unsigned long doios_single;
107 unsigned long doios_multi;
108 unsigned long txlen;
109 unsigned long tx_time;
110 struct timespec send_stamp;
111};
112
113
114
115
116struct channel {
117 struct channel *next;
118 char id[CTCM_ID_SIZE];
119 struct ccw_device *cdev;
120
121
122
123
124 enum channel_types type;
125
126
127
128 __u32 flags;
129 __u16 protocol;
130
131
132
133 struct ccw1 *ccw;
134 struct irb *irb;
135
136
137
138 int max_bufsize;
139 struct sk_buff *trans_skb;
140 struct sk_buff_head io_queue;
141 struct tasklet_struct ch_tasklet;
142
143
144
145 struct sk_buff_head collect_queue;
146
147
148
149 int collect_len;
150
151
152
153 spinlock_t collect_lock;
154
155
156
157
158 fsm_timer timer;
159
160 __u32 th_seq_num;
161 __u8 th_seg;
162 __u32 pdu_seq;
163 struct sk_buff *xid_skb;
164 char *xid_skb_data;
165 struct th_header *xid_th;
166 struct xid2 *xid;
167 char *xid_id;
168 struct th_header *rcvd_xid_th;
169 struct xid2 *rcvd_xid;
170 char *rcvd_xid_id;
171 __u8 in_mpcgroup;
172 fsm_timer sweep_timer;
173 struct sk_buff_head sweep_queue;
174 struct th_header *discontact_th;
175 struct tasklet_struct ch_disc_tasklet;
176
177
178 int retry;
179 fsm_instance *fsm;
180 struct net_device *netdev;
181 struct ctcm_profile prof;
182 __u8 *trans_skb_data;
183 __u16 logflags;
184 __u8 sense_rc;
185};
186
187struct ctcm_priv {
188 struct net_device_stats stats;
189 unsigned long tbusy;
190
191
192 struct mpc_group *mpcg;
193 struct xid2 *xid;
194
195
196 fsm_instance *fsm;
197
198
199 __u16 protocol;
200
201
202 fsm_timer restart_timer;
203
204 int buffer_size;
205
206 struct channel *channel[2];
207};
208
209int ctcm_open(struct net_device *dev);
210int ctcm_close(struct net_device *dev);
211
212
213
214
215int ctcm_add_attributes(struct device *dev);
216void ctcm_remove_attributes(struct device *dev);
217int ctcm_add_files(struct device *dev);
218void ctcm_remove_files(struct device *dev);
219
220
221
222
223
224static inline void ctcm_clear_busy_do(struct net_device *dev)
225{
226 clear_bit(0, &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
227 netif_wake_queue(dev);
228}
229
230static inline void ctcm_clear_busy(struct net_device *dev)
231{
232 struct mpc_group *grp;
233 grp = ((struct ctcm_priv *)dev->ml_priv)->mpcg;
234
235 if (!(grp && grp->in_sweep))
236 ctcm_clear_busy_do(dev);
237}
238
239
240static inline int ctcm_test_and_set_busy(struct net_device *dev)
241{
242 netif_stop_queue(dev);
243 return test_and_set_bit(0,
244 &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
245}
246
247extern int loglevel;
248extern struct channel *channels;
249
250void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb);
251
252
253
254
255
256static inline int ctcm_less_than(char *id1, char *id2)
257{
258 unsigned long dev1, dev2;
259
260 id1 = id1 + 5;
261 id2 = id2 + 5;
262
263 dev1 = simple_strtoul(id1, &id1, 16);
264 dev2 = simple_strtoul(id2, &id2, 16);
265
266 return (dev1 < dev2);
267}
268
269int ctcm_ch_alloc_buffer(struct channel *ch);
270
271static inline int ctcm_checkalloc_buffer(struct channel *ch)
272{
273 if (ch->trans_skb == NULL)
274 return ctcm_ch_alloc_buffer(ch);
275 if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) {
276 dev_kfree_skb(ch->trans_skb);
277 return ctcm_ch_alloc_buffer(ch);
278 }
279 return 0;
280}
281
282struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
283
284
285
286
287#define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
288
289
290#define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv)
291
292static inline gfp_t gfp_type(void)
293{
294 return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
295}
296
297
298
299
300struct ll_header {
301 __u16 length;
302 __u16 type;
303 __u16 unused;
304};
305#define LL_HEADER_LENGTH (sizeof(struct ll_header))
306
307#endif
308