]>
Commit | Line | Data |
---|---|---|
293d984f PT |
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" | |
293d984f | 25 | #define MPC_DEVICE_NAME "mpc" |
aa3f2cb6 PT |
26 | #define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d" |
27 | #define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d" | |
293d984f PT |
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 | #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) | |
50 | ||
aa3f2cb6 PT |
51 | #define CTCM_PR_DEBUG(fmt, arg...) \ |
52 | do { \ | |
53 | if (do_debug) \ | |
54 | printk(KERN_DEBUG fmt, ##arg); \ | |
55 | } while (0) | |
56 | ||
57 | #define CTCM_PR_DBGDATA(fmt, arg...) \ | |
58 | do { \ | |
59 | if (do_debug_data) \ | |
60 | printk(KERN_DEBUG fmt, ##arg); \ | |
61 | } while (0) | |
62 | ||
63 | #define CTCM_D3_DUMP(buf, len) \ | |
64 | do { \ | |
65 | if (do_debug_data) \ | |
66 | ctcmpc_dumpit(buf, len); \ | |
67 | } while (0) | |
68 | ||
69 | #define CTCM_CCW_DUMP(buf, len) \ | |
70 | do { \ | |
71 | if (do_debug_ccw) \ | |
72 | ctcmpc_dumpit(buf, len); \ | |
73 | } while (0) | |
74 | ||
293d984f PT |
75 | /* |
76 | * CCW commands, used in this driver. | |
77 | */ | |
78 | #define CCW_CMD_WRITE 0x01 | |
79 | #define CCW_CMD_READ 0x02 | |
80 | #define CCW_CMD_NOOP 0x03 | |
81 | #define CCW_CMD_TIC 0x08 | |
82 | #define CCW_CMD_SENSE_CMD 0x14 | |
83 | #define CCW_CMD_WRITE_CTL 0x17 | |
84 | #define CCW_CMD_SET_EXTENDED 0xc3 | |
85 | #define CCW_CMD_PREPARE 0xe3 | |
86 | ||
87 | #define CTCM_PROTO_S390 0 | |
88 | #define CTCM_PROTO_LINUX 1 | |
89 | #define CTCM_PROTO_LINUX_TTY 2 | |
90 | #define CTCM_PROTO_OS390 3 | |
91 | #define CTCM_PROTO_MPC 4 | |
92 | #define CTCM_PROTO_MAX 4 | |
93 | ||
94 | #define CTCM_BUFSIZE_LIMIT 65535 | |
95 | #define CTCM_BUFSIZE_DEFAULT 32768 | |
96 | #define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT | |
97 | ||
98 | #define CTCM_TIME_1_SEC 1000 | |
99 | #define CTCM_TIME_5_SEC 5000 | |
100 | #define CTCM_TIME_10_SEC 10000 | |
101 | ||
102 | #define CTCM_INITIAL_BLOCKLEN 2 | |
103 | ||
104 | #define READ 0 | |
105 | #define WRITE 1 | |
106 | ||
107 | #define CTCM_ID_SIZE BUS_ID_SIZE+3 | |
108 | ||
109 | struct ctcm_profile { | |
110 | unsigned long maxmulti; | |
111 | unsigned long maxcqueue; | |
112 | unsigned long doios_single; | |
113 | unsigned long doios_multi; | |
114 | unsigned long txlen; | |
115 | unsigned long tx_time; | |
116 | struct timespec send_stamp; | |
117 | }; | |
118 | ||
119 | /* | |
120 | * Definition of one channel | |
121 | */ | |
122 | struct channel { | |
123 | struct channel *next; | |
124 | char id[CTCM_ID_SIZE]; | |
125 | struct ccw_device *cdev; | |
126 | /* | |
127 | * Type of this channel. | |
128 | * CTC/A or Escon for valid channels. | |
129 | */ | |
130 | enum channel_types type; | |
131 | /* | |
132 | * Misc. flags. See CHANNEL_FLAGS_... below | |
133 | */ | |
134 | __u32 flags; | |
135 | __u16 protocol; /* protocol of this channel (4 = MPC) */ | |
136 | /* | |
137 | * I/O and irq related stuff | |
138 | */ | |
139 | struct ccw1 *ccw; | |
140 | struct irb *irb; | |
141 | /* | |
142 | * RX/TX buffer size | |
143 | */ | |
144 | int max_bufsize; | |
145 | struct sk_buff *trans_skb; /* transmit/receive buffer */ | |
146 | struct sk_buff_head io_queue; /* universal I/O queue */ | |
147 | struct tasklet_struct ch_tasklet; /* MPC ONLY */ | |
148 | /* | |
149 | * TX queue for collecting skb's during busy. | |
150 | */ | |
151 | struct sk_buff_head collect_queue; | |
152 | /* | |
153 | * Amount of data in collect_queue. | |
154 | */ | |
155 | int collect_len; | |
156 | /* | |
157 | * spinlock for collect_queue and collect_len | |
158 | */ | |
159 | spinlock_t collect_lock; | |
160 | /* | |
161 | * Timer for detecting unresposive | |
162 | * I/O operations. | |
163 | */ | |
164 | fsm_timer timer; | |
165 | /* MPC ONLY section begin */ | |
166 | __u32 th_seq_num; /* SNA TH seq number */ | |
167 | __u8 th_seg; | |
168 | __u32 pdu_seq; | |
169 | struct sk_buff *xid_skb; | |
170 | char *xid_skb_data; | |
171 | struct th_header *xid_th; | |
172 | struct xid2 *xid; | |
173 | char *xid_id; | |
174 | struct th_header *rcvd_xid_th; | |
175 | struct xid2 *rcvd_xid; | |
176 | char *rcvd_xid_id; | |
177 | __u8 in_mpcgroup; | |
178 | fsm_timer sweep_timer; | |
179 | struct sk_buff_head sweep_queue; | |
180 | struct th_header *discontact_th; | |
181 | struct tasklet_struct ch_disc_tasklet; | |
182 | /* MPC ONLY section end */ | |
183 | ||
184 | int retry; /* retry counter for misc. operations */ | |
185 | fsm_instance *fsm; /* finite state machine of this channel */ | |
186 | struct net_device *netdev; /* corresponding net_device */ | |
187 | struct ctcm_profile prof; | |
aa3f2cb6 | 188 | __u8 *trans_skb_data; |
293d984f | 189 | __u16 logflags; |
aa3f2cb6 | 190 | __u8 sense_rc; /* last unit check sense code report control */ |
293d984f PT |
191 | }; |
192 | ||
193 | struct ctcm_priv { | |
194 | struct net_device_stats stats; | |
195 | unsigned long tbusy; | |
196 | ||
197 | /* The MPC group struct of this interface */ | |
198 | struct mpc_group *mpcg; /* MPC only */ | |
199 | struct xid2 *xid; /* MPC only */ | |
200 | ||
201 | /* The finite state machine of this interface */ | |
202 | fsm_instance *fsm; | |
203 | ||
204 | /* The protocol of this device */ | |
205 | __u16 protocol; | |
206 | ||
207 | /* Timer for restarting after I/O Errors */ | |
208 | fsm_timer restart_timer; | |
209 | ||
210 | int buffer_size; /* ctc only */ | |
211 | ||
212 | struct channel *channel[2]; | |
213 | }; | |
214 | ||
215 | int ctcm_open(struct net_device *dev); | |
216 | int ctcm_close(struct net_device *dev); | |
217 | ||
218 | /* | |
219 | * prototypes for non-static sysfs functions | |
220 | */ | |
221 | int ctcm_add_attributes(struct device *dev); | |
222 | void ctcm_remove_attributes(struct device *dev); | |
223 | int ctcm_add_files(struct device *dev); | |
224 | void ctcm_remove_files(struct device *dev); | |
225 | ||
226 | /* | |
227 | * Compatibility macros for busy handling | |
228 | * of network devices. | |
229 | */ | |
230 | static inline void ctcm_clear_busy_do(struct net_device *dev) | |
231 | { | |
261893d3 | 232 | clear_bit(0, &(((struct ctcm_priv *)dev->ml_priv)->tbusy)); |
293d984f PT |
233 | netif_wake_queue(dev); |
234 | } | |
235 | ||
236 | static inline void ctcm_clear_busy(struct net_device *dev) | |
237 | { | |
238 | struct mpc_group *grp; | |
261893d3 | 239 | grp = ((struct ctcm_priv *)dev->ml_priv)->mpcg; |
293d984f PT |
240 | |
241 | if (!(grp && grp->in_sweep)) | |
242 | ctcm_clear_busy_do(dev); | |
243 | } | |
244 | ||
245 | ||
246 | static inline int ctcm_test_and_set_busy(struct net_device *dev) | |
247 | { | |
248 | netif_stop_queue(dev); | |
261893d3 PT |
249 | return test_and_set_bit(0, |
250 | &(((struct ctcm_priv *)dev->ml_priv)->tbusy)); | |
293d984f PT |
251 | } |
252 | ||
253 | extern int loglevel; | |
254 | extern struct channel *channels; | |
255 | ||
256 | void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb); | |
257 | ||
258 | /* | |
259 | * Functions related to setup and device detection. | |
260 | */ | |
261 | ||
262 | static inline int ctcm_less_than(char *id1, char *id2) | |
263 | { | |
264 | unsigned long dev1, dev2; | |
265 | ||
266 | id1 = id1 + 5; | |
267 | id2 = id2 + 5; | |
268 | ||
269 | dev1 = simple_strtoul(id1, &id1, 16); | |
270 | dev2 = simple_strtoul(id2, &id2, 16); | |
271 | ||
272 | return (dev1 < dev2); | |
273 | } | |
274 | ||
275 | int ctcm_ch_alloc_buffer(struct channel *ch); | |
276 | ||
277 | static inline int ctcm_checkalloc_buffer(struct channel *ch) | |
278 | { | |
279 | if (ch->trans_skb == NULL) | |
280 | return ctcm_ch_alloc_buffer(ch); | |
281 | if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) { | |
282 | dev_kfree_skb(ch->trans_skb); | |
283 | return ctcm_ch_alloc_buffer(ch); | |
284 | } | |
285 | return 0; | |
286 | } | |
287 | ||
288 | struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv); | |
289 | ||
290 | /* test if protocol attribute (of struct ctcm_priv or struct channel) | |
291 | * has MPC protocol setting. Type is not checked | |
292 | */ | |
293 | #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC) | |
294 | ||
295 | /* test if struct ctcm_priv of struct net_device has MPC protocol setting */ | |
261893d3 | 296 | #define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv) |
293d984f PT |
297 | |
298 | static inline gfp_t gfp_type(void) | |
299 | { | |
300 | return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; | |
301 | } | |
302 | ||
303 | /* | |
304 | * Definition of our link level header. | |
305 | */ | |
306 | struct ll_header { | |
307 | __u16 length; | |
308 | __u16 type; | |
309 | __u16 unused; | |
310 | }; | |
311 | #define LL_HEADER_LENGTH (sizeof(struct ll_header)) | |
312 | ||
313 | #endif |