Linux-libre 2.6.32.42-gnu1
[librecmc/linux-libre.git] / drivers / s390 / net / ctcm_main.h
1 /*
2  *      drivers/s390/net/ctcm_main.h
3  *
4  *      Copyright IBM Corp. 2001, 2007
5  *      Authors:        Fritz Elfert (felfert@millenux.com)
6  *                      Peter Tiedemann (ptiedem@de.ibm.com)
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  * CCW commands, used in this driver.
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
103 struct 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  * Definition of one channel
115  */
116 struct channel {
117         struct channel *next;
118         char id[CTCM_ID_SIZE];
119         struct ccw_device *cdev;
120         /*
121          * Type of this channel.
122          * CTC/A or Escon for valid channels.
123          */
124         enum channel_types type;
125         /*
126          * Misc. flags. See CHANNEL_FLAGS_... below
127          */
128         __u32 flags;
129         __u16 protocol;         /* protocol of this channel (4 = MPC) */
130         /*
131          * I/O and irq related stuff
132          */
133         struct ccw1 *ccw;
134         struct irb *irb;
135         /*
136          * RX/TX buffer size
137          */
138         int max_bufsize;
139         struct sk_buff *trans_skb;      /* transmit/receive buffer */
140         struct sk_buff_head io_queue;   /* universal I/O queue */
141         struct tasklet_struct ch_tasklet;       /* MPC ONLY */
142         /*
143          * TX queue for collecting skb's during busy.
144          */
145         struct sk_buff_head collect_queue;
146         /*
147          * Amount of data in collect_queue.
148          */
149         int collect_len;
150         /*
151          * spinlock for collect_queue and collect_len
152          */
153         spinlock_t collect_lock;
154         /*
155          * Timer for detecting unresposive
156          * I/O operations.
157          */
158         fsm_timer timer;
159         /* MPC ONLY section begin */
160         __u32   th_seq_num;     /* SNA TH seq number */
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         /* MPC ONLY section end */
177
178         int retry;              /* retry counter for misc. operations */
179         fsm_instance *fsm;      /* finite state machine of this channel */
180         struct net_device *netdev;      /* corresponding net_device */
181         struct ctcm_profile prof;
182         __u8 *trans_skb_data;
183         __u16 logflags;
184         __u8  sense_rc; /* last unit check sense code report control */
185 };
186
187 struct ctcm_priv {
188         struct net_device_stats stats;
189         unsigned long   tbusy;
190
191         /* The MPC group struct of this interface */
192         struct  mpc_group       *mpcg;  /* MPC only */
193         struct  xid2            *xid;   /* MPC only */
194
195         /* The finite state machine of this interface */
196         fsm_instance *fsm;
197
198         /* The protocol of this device */
199         __u16 protocol;
200
201         /* Timer for restarting after I/O Errors */
202         fsm_timer       restart_timer;
203
204         int buffer_size;        /* ctc only */
205
206         struct channel *channel[2];
207 };
208
209 int ctcm_open(struct net_device *dev);
210 int ctcm_close(struct net_device *dev);
211
212 /*
213  * prototypes for non-static sysfs functions
214  */
215 int ctcm_add_attributes(struct device *dev);
216 void ctcm_remove_attributes(struct device *dev);
217 int ctcm_add_files(struct device *dev);
218 void ctcm_remove_files(struct device *dev);
219
220 /*
221  * Compatibility macros for busy handling
222  * of network devices.
223  */
224 static 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
230 static 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
240 static 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
247 extern int loglevel;
248 extern struct channel *channels;
249
250 void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb);
251
252 /*
253  * Functions related to setup and device detection.
254  */
255
256 static 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
269 int ctcm_ch_alloc_buffer(struct channel *ch);
270
271 static 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
282 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
283
284 /* test if protocol attribute (of struct ctcm_priv or struct channel)
285  * has MPC protocol setting. Type is not checked
286  */
287 #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
288
289 /* test if struct ctcm_priv of struct net_device has MPC protocol setting */
290 #define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv)
291
292 static inline gfp_t gfp_type(void)
293 {
294         return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
295 }
296
297 /*
298  * Definition of our link level header.
299  */
300 struct ll_header {
301         __u16 length;
302         __u16 type;
303         __u16 unused;
304 };
305 #define LL_HEADER_LENGTH (sizeof(struct ll_header))
306
307 #endif