diff options
author | Hansjoerg Lipp <hjlipp@web.de> | 2006-03-26 04:38:29 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-26 11:57:05 -0500 |
commit | 6fd5ea63f85e30fda55b80939b4f379ea5db62b1 (patch) | |
tree | e1f3d46ccb136535b0e7a6818b394c1d57173a24 /drivers | |
parent | 0a34eb8f55a71678c379b47c25f562050c80efcc (diff) |
[PATCH] isdn4linux: Siemens Gigaset drivers - common module
And: Tilman Schmidt <tilman@imap.cc>
This patch adds the common include file for the Siemens Gigaset drivers,
providing definitions used by all of the Gigaset ISDN driver source files. It
also adds the main source file of the gigaset module which manages common
functions not specific to the type of connection to the device.
Signed-off-by: Hansjoerg Lipp <hjlipp@web.de>
Signed-off-by: Tilman Schmidt <tilman@imap.cc>
Cc: Karsten Keil <kkeil@suse.de>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/isdn/gigaset/common.c | 1203 | ||||
-rw-r--r-- | drivers/isdn/gigaset/gigaset.h | 938 |
2 files changed, 2141 insertions, 0 deletions
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c new file mode 100644 index 000000000000..64371995c1a9 --- /dev/null +++ b/drivers/isdn/gigaset/common.c | |||
@@ -0,0 +1,1203 @@ | |||
1 | /* | ||
2 | * Stuff used by all variants of the driver | ||
3 | * | ||
4 | * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, | ||
5 | * Hansjoerg Lipp <hjlipp@web.de>, | ||
6 | * Tilman Schmidt <tilman@imap.cc>. | ||
7 | * | ||
8 | * ===================================================================== | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License as | ||
11 | * published by the Free Software Foundation; either version 2 of | ||
12 | * the License, or (at your option) any later version. | ||
13 | * ===================================================================== | ||
14 | * ToDo: ... | ||
15 | * ===================================================================== | ||
16 | * Version: $Id: common.c,v 1.104.4.22 2006/02/04 18:28:16 hjlipp Exp $ | ||
17 | * ===================================================================== | ||
18 | */ | ||
19 | |||
20 | #include "gigaset.h" | ||
21 | #include <linux/ctype.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/moduleparam.h> | ||
24 | |||
25 | /* Version Information */ | ||
26 | #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers <Eilers.Stefan@epost.de>" | ||
27 | #define DRIVER_DESC "Driver for Gigaset 307x" | ||
28 | |||
29 | /* Module parameters */ | ||
30 | int gigaset_debuglevel = DEBUG_DEFAULT; | ||
31 | EXPORT_SYMBOL_GPL(gigaset_debuglevel); | ||
32 | module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR); | ||
33 | MODULE_PARM_DESC(debug, "debug level"); | ||
34 | |||
35 | /*====================================================================== | ||
36 | Prototypes of internal functions | ||
37 | */ | ||
38 | |||
39 | //static void gigaset_process_response(int resp_code, int parameter, | ||
40 | // struct at_state_t *at_state, | ||
41 | // unsigned char ** pstring); | ||
42 | static struct cardstate *alloc_cs(struct gigaset_driver *drv); | ||
43 | static void free_cs(struct cardstate *cs); | ||
44 | static void make_valid(struct cardstate *cs, unsigned mask); | ||
45 | static void make_invalid(struct cardstate *cs, unsigned mask); | ||
46 | |||
47 | #define VALID_MINOR 0x01 | ||
48 | #define VALID_ID 0x02 | ||
49 | #define ASSIGNED 0x04 | ||
50 | |||
51 | /* bitwise byte inversion table */ | ||
52 | __u8 gigaset_invtab[256] = { | ||
53 | 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, | ||
54 | 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, | ||
55 | 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, | ||
56 | 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, | ||
57 | 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, | ||
58 | 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, | ||
59 | 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, | ||
60 | 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, | ||
61 | 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, | ||
62 | 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, | ||
63 | 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, | ||
64 | 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, | ||
65 | 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, | ||
66 | 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, | ||
67 | 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, | ||
68 | 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, | ||
69 | 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, | ||
70 | 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, | ||
71 | 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, | ||
72 | 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, | ||
73 | 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, | ||
74 | 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, | ||
75 | 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, | ||
76 | 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, | ||
77 | 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, | ||
78 | 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, | ||
79 | 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, | ||
80 | 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, | ||
81 | 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, | ||
82 | 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, | ||
83 | 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, | ||
84 | 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff | ||
85 | }; | ||
86 | EXPORT_SYMBOL_GPL(gigaset_invtab); | ||
87 | |||
88 | void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, | ||
89 | size_t len, const unsigned char *buf, int from_user) | ||
90 | { | ||
91 | unsigned char outbuf[80]; | ||
92 | unsigned char inbuf[80 - 1]; | ||
93 | size_t numin; | ||
94 | const unsigned char *in; | ||
95 | size_t space = sizeof outbuf - 1; | ||
96 | unsigned char *out = outbuf; | ||
97 | |||
98 | if (!from_user) { | ||
99 | in = buf; | ||
100 | numin = len; | ||
101 | } else { | ||
102 | numin = len < sizeof inbuf ? len : sizeof inbuf; | ||
103 | in = inbuf; | ||
104 | if (copy_from_user(inbuf, (const unsigned char __user *) buf, numin)) { | ||
105 | strncpy(inbuf, "<FAULT>", sizeof inbuf); | ||
106 | numin = sizeof "<FAULT>" - 1; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | for (; numin && space; --numin, ++in) { | ||
111 | --space; | ||
112 | if (*in >= 32) | ||
113 | *out++ = *in; | ||
114 | else { | ||
115 | *out++ = '^'; | ||
116 | if (space) { | ||
117 | *out++ = '@' + *in; | ||
118 | --space; | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | *out = 0; | ||
123 | |||
124 | dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf); | ||
125 | } | ||
126 | EXPORT_SYMBOL_GPL(gigaset_dbg_buffer); | ||
127 | |||
128 | static int setflags(struct cardstate *cs, unsigned flags, unsigned delay) | ||
129 | { | ||
130 | int r; | ||
131 | |||
132 | r = cs->ops->set_modem_ctrl(cs, cs->control_state, flags); | ||
133 | cs->control_state = flags; | ||
134 | if (r < 0) | ||
135 | return r; | ||
136 | |||
137 | if (delay) { | ||
138 | set_current_state(TASK_INTERRUPTIBLE); | ||
139 | schedule_timeout(delay * HZ / 1000); | ||
140 | } | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | int gigaset_enterconfigmode(struct cardstate *cs) | ||
146 | { | ||
147 | int i, r; | ||
148 | |||
149 | if (!atomic_read(&cs->connected)) { | ||
150 | err("not connected!"); | ||
151 | return -1; | ||
152 | } | ||
153 | |||
154 | cs->control_state = TIOCM_RTS; //FIXME | ||
155 | |||
156 | r = setflags(cs, TIOCM_DTR, 200); | ||
157 | if (r < 0) | ||
158 | goto error; | ||
159 | r = setflags(cs, 0, 200); | ||
160 | if (r < 0) | ||
161 | goto error; | ||
162 | for (i = 0; i < 5; ++i) { | ||
163 | r = setflags(cs, TIOCM_RTS, 100); | ||
164 | if (r < 0) | ||
165 | goto error; | ||
166 | r = setflags(cs, 0, 100); | ||
167 | if (r < 0) | ||
168 | goto error; | ||
169 | } | ||
170 | r = setflags(cs, TIOCM_RTS|TIOCM_DTR, 800); | ||
171 | if (r < 0) | ||
172 | goto error; | ||
173 | |||
174 | return 0; | ||
175 | |||
176 | error: | ||
177 | err("error %d on setuartbits!\n", -r); | ||
178 | cs->control_state = TIOCM_RTS|TIOCM_DTR; // FIXME is this a good value? | ||
179 | cs->ops->set_modem_ctrl(cs, 0, TIOCM_RTS|TIOCM_DTR); | ||
180 | |||
181 | return -1; //r | ||
182 | } | ||
183 | |||
184 | static int test_timeout(struct at_state_t *at_state) | ||
185 | { | ||
186 | if (!at_state->timer_expires) | ||
187 | return 0; | ||
188 | |||
189 | if (--at_state->timer_expires) { | ||
190 | dbg(DEBUG_MCMD, "decreased timer of %p to %lu", | ||
191 | at_state, at_state->timer_expires); | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL, | ||
196 | atomic_read(&at_state->timer_index), NULL)) { | ||
197 | //FIXME what should we do? | ||
198 | } | ||
199 | |||
200 | return 1; | ||
201 | } | ||
202 | |||
203 | static void timer_tick(unsigned long data) | ||
204 | { | ||
205 | struct cardstate *cs = (struct cardstate *) data; | ||
206 | unsigned long flags; | ||
207 | unsigned channel; | ||
208 | struct at_state_t *at_state; | ||
209 | int timeout = 0; | ||
210 | |||
211 | spin_lock_irqsave(&cs->lock, flags); | ||
212 | |||
213 | for (channel = 0; channel < cs->channels; ++channel) | ||
214 | if (test_timeout(&cs->bcs[channel].at_state)) | ||
215 | timeout = 1; | ||
216 | |||
217 | if (test_timeout(&cs->at_state)) | ||
218 | timeout = 1; | ||
219 | |||
220 | list_for_each_entry(at_state, &cs->temp_at_states, list) | ||
221 | if (test_timeout(at_state)) | ||
222 | timeout = 1; | ||
223 | |||
224 | if (atomic_read(&cs->running)) { | ||
225 | mod_timer(&cs->timer, jiffies + GIG_TICK); | ||
226 | if (timeout) { | ||
227 | dbg(DEBUG_CMD, "scheduling timeout"); | ||
228 | tasklet_schedule(&cs->event_tasklet); | ||
229 | } | ||
230 | } | ||
231 | |||
232 | spin_unlock_irqrestore(&cs->lock, flags); | ||
233 | } | ||
234 | |||
235 | int gigaset_get_channel(struct bc_state *bcs) | ||
236 | { | ||
237 | unsigned long flags; | ||
238 | |||
239 | spin_lock_irqsave(&bcs->cs->lock, flags); | ||
240 | if (bcs->use_count) { | ||
241 | dbg(DEBUG_ANY, "could not allocate channel %d", bcs->channel); | ||
242 | spin_unlock_irqrestore(&bcs->cs->lock, flags); | ||
243 | return 0; | ||
244 | } | ||
245 | ++bcs->use_count; | ||
246 | bcs->busy = 1; | ||
247 | dbg(DEBUG_ANY, "allocated channel %d", bcs->channel); | ||
248 | spin_unlock_irqrestore(&bcs->cs->lock, flags); | ||
249 | return 1; | ||
250 | } | ||
251 | |||
252 | void gigaset_free_channel(struct bc_state *bcs) | ||
253 | { | ||
254 | unsigned long flags; | ||
255 | |||
256 | spin_lock_irqsave(&bcs->cs->lock, flags); | ||
257 | if (!bcs->busy) { | ||
258 | dbg(DEBUG_ANY, "could not free channel %d", bcs->channel); | ||
259 | spin_unlock_irqrestore(&bcs->cs->lock, flags); | ||
260 | return; | ||
261 | } | ||
262 | --bcs->use_count; | ||
263 | bcs->busy = 0; | ||
264 | dbg(DEBUG_ANY, "freed channel %d", bcs->channel); | ||
265 | spin_unlock_irqrestore(&bcs->cs->lock, flags); | ||
266 | } | ||
267 | |||
268 | int gigaset_get_channels(struct cardstate *cs) | ||
269 | { | ||
270 | unsigned long flags; | ||
271 | int i; | ||
272 | |||
273 | spin_lock_irqsave(&cs->lock, flags); | ||
274 | for (i = 0; i < cs->channels; ++i) | ||
275 | if (cs->bcs[i].use_count) { | ||
276 | spin_unlock_irqrestore(&cs->lock, flags); | ||
277 | dbg(DEBUG_ANY, "could not allocated all channels"); | ||
278 | return 0; | ||
279 | } | ||
280 | for (i = 0; i < cs->channels; ++i) | ||
281 | ++cs->bcs[i].use_count; | ||
282 | spin_unlock_irqrestore(&cs->lock, flags); | ||
283 | |||
284 | dbg(DEBUG_ANY, "allocated all channels"); | ||
285 | |||
286 | return 1; | ||
287 | } | ||
288 | |||
289 | void gigaset_free_channels(struct cardstate *cs) | ||
290 | { | ||
291 | unsigned long flags; | ||
292 | int i; | ||
293 | |||
294 | dbg(DEBUG_ANY, "unblocking all channels"); | ||
295 | spin_lock_irqsave(&cs->lock, flags); | ||
296 | for (i = 0; i < cs->channels; ++i) | ||
297 | --cs->bcs[i].use_count; | ||
298 | spin_unlock_irqrestore(&cs->lock, flags); | ||
299 | } | ||
300 | |||
301 | void gigaset_block_channels(struct cardstate *cs) | ||
302 | { | ||
303 | unsigned long flags; | ||
304 | int i; | ||
305 | |||
306 | dbg(DEBUG_ANY, "blocking all channels"); | ||
307 | spin_lock_irqsave(&cs->lock, flags); | ||
308 | for (i = 0; i < cs->channels; ++i) | ||
309 | ++cs->bcs[i].use_count; | ||
310 | spin_unlock_irqrestore(&cs->lock, flags); | ||
311 | } | ||
312 | |||
313 | static void clear_events(struct cardstate *cs) | ||
314 | { | ||
315 | struct event_t *ev; | ||
316 | unsigned head, tail; | ||
317 | |||
318 | /* no locking needed (no reader/writer allowed) */ | ||
319 | |||
320 | head = atomic_read(&cs->ev_head); | ||
321 | tail = atomic_read(&cs->ev_tail); | ||
322 | |||
323 | while (tail != head) { | ||
324 | ev = cs->events + head; | ||
325 | kfree(ev->ptr); | ||
326 | |||
327 | head = (head + 1) % MAX_EVENTS; | ||
328 | } | ||
329 | |||
330 | atomic_set(&cs->ev_head, tail); | ||
331 | } | ||
332 | |||
333 | struct event_t *gigaset_add_event(struct cardstate *cs, | ||
334 | struct at_state_t *at_state, int type, | ||
335 | void *ptr, int parameter, void *arg) | ||
336 | { | ||
337 | unsigned long flags; | ||
338 | unsigned next, tail; | ||
339 | struct event_t *event = NULL; | ||
340 | |||
341 | spin_lock_irqsave(&cs->ev_lock, flags); | ||
342 | |||
343 | tail = atomic_read(&cs->ev_tail); | ||
344 | next = (tail + 1) % MAX_EVENTS; | ||
345 | if (unlikely(next == atomic_read(&cs->ev_head))) | ||
346 | err("event queue full"); | ||
347 | else { | ||
348 | event = cs->events + tail; | ||
349 | event->type = type; | ||
350 | event->at_state = at_state; | ||
351 | event->cid = -1; | ||
352 | event->ptr = ptr; | ||
353 | event->arg = arg; | ||
354 | event->parameter = parameter; | ||
355 | atomic_set(&cs->ev_tail, next); | ||
356 | } | ||
357 | |||
358 | spin_unlock_irqrestore(&cs->ev_lock, flags); | ||
359 | |||
360 | return event; | ||
361 | } | ||
362 | EXPORT_SYMBOL_GPL(gigaset_add_event); | ||
363 | |||
364 | static void free_strings(struct at_state_t *at_state) | ||
365 | { | ||
366 | int i; | ||
367 | |||
368 | for (i = 0; i < STR_NUM; ++i) { | ||
369 | kfree(at_state->str_var[i]); | ||
370 | at_state->str_var[i] = NULL; | ||
371 | } | ||
372 | } | ||
373 | |||
374 | static void clear_at_state(struct at_state_t *at_state) | ||
375 | { | ||
376 | free_strings(at_state); | ||
377 | } | ||
378 | |||
379 | static void dealloc_at_states(struct cardstate *cs) | ||
380 | { | ||
381 | struct at_state_t *cur, *next; | ||
382 | |||
383 | list_for_each_entry_safe(cur, next, &cs->temp_at_states, list) { | ||
384 | list_del(&cur->list); | ||
385 | free_strings(cur); | ||
386 | kfree(cur); | ||
387 | } | ||
388 | } | ||
389 | |||
390 | static void gigaset_freebcs(struct bc_state *bcs) | ||
391 | { | ||
392 | int i; | ||
393 | |||
394 | dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel); | ||
395 | if (!bcs->cs->ops->freebcshw(bcs)) { | ||
396 | dbg(DEBUG_INIT, "failed"); | ||
397 | } | ||
398 | |||
399 | dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel); | ||
400 | clear_at_state(&bcs->at_state); | ||
401 | dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel); | ||
402 | |||
403 | if (bcs->skb) | ||
404 | dev_kfree_skb(bcs->skb); | ||
405 | for (i = 0; i < AT_NUM; ++i) { | ||
406 | kfree(bcs->commands[i]); | ||
407 | bcs->commands[i] = NULL; | ||
408 | } | ||
409 | } | ||
410 | |||
411 | void gigaset_freecs(struct cardstate *cs) | ||
412 | { | ||
413 | int i; | ||
414 | unsigned long flags; | ||
415 | |||
416 | if (!cs) | ||
417 | return; | ||
418 | |||
419 | down(&cs->sem); | ||
420 | |||
421 | if (!cs->bcs) | ||
422 | goto f_cs; | ||
423 | if (!cs->inbuf) | ||
424 | goto f_bcs; | ||
425 | |||
426 | spin_lock_irqsave(&cs->lock, flags); | ||
427 | atomic_set(&cs->running, 0); | ||
428 | spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are not rescheduled below */ | ||
429 | |||
430 | tasklet_kill(&cs->event_tasklet); | ||
431 | del_timer_sync(&cs->timer); | ||
432 | |||
433 | switch (cs->cs_init) { | ||
434 | default: | ||
435 | gigaset_if_free(cs); | ||
436 | |||
437 | dbg(DEBUG_INIT, "clearing hw"); | ||
438 | cs->ops->freecshw(cs); | ||
439 | |||
440 | //FIXME cmdbuf | ||
441 | |||
442 | /* fall through */ | ||
443 | case 2: /* error in initcshw */ | ||
444 | /* Deregister from LL */ | ||
445 | make_invalid(cs, VALID_ID); | ||
446 | dbg(DEBUG_INIT, "clearing iif"); | ||
447 | gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD); | ||
448 | |||
449 | /* fall through */ | ||
450 | case 1: /* error when regestering to LL */ | ||
451 | dbg(DEBUG_INIT, "clearing at_state"); | ||
452 | clear_at_state(&cs->at_state); | ||
453 | dealloc_at_states(cs); | ||
454 | |||
455 | /* fall through */ | ||
456 | case 0: /* error in one call to initbcs */ | ||
457 | for (i = 0; i < cs->channels; ++i) { | ||
458 | dbg(DEBUG_INIT, "clearing bcs[%d]", i); | ||
459 | gigaset_freebcs(cs->bcs + i); | ||
460 | } | ||
461 | |||
462 | clear_events(cs); | ||
463 | dbg(DEBUG_INIT, "freeing inbuf"); | ||
464 | kfree(cs->inbuf); | ||
465 | } | ||
466 | f_bcs: dbg(DEBUG_INIT, "freeing bcs[]"); | ||
467 | kfree(cs->bcs); | ||
468 | f_cs: dbg(DEBUG_INIT, "freeing cs"); | ||
469 | up(&cs->sem); | ||
470 | free_cs(cs); | ||
471 | } | ||
472 | EXPORT_SYMBOL_GPL(gigaset_freecs); | ||
473 | |||
474 | void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, | ||
475 | struct cardstate *cs, int cid) | ||
476 | { | ||
477 | int i; | ||
478 | |||
479 | INIT_LIST_HEAD(&at_state->list); | ||
480 | at_state->waiting = 0; | ||
481 | at_state->getstring = 0; | ||
482 | at_state->pending_commands = 0; | ||
483 | at_state->timer_expires = 0; | ||
484 | at_state->timer_active = 0; | ||
485 | atomic_set(&at_state->timer_index, 0); | ||
486 | atomic_set(&at_state->seq_index, 0); | ||
487 | at_state->ConState = 0; | ||
488 | for (i = 0; i < STR_NUM; ++i) | ||
489 | at_state->str_var[i] = NULL; | ||
490 | at_state->int_var[VAR_ZDLE] = 0; | ||
491 | at_state->int_var[VAR_ZCTP] = -1; | ||
492 | at_state->int_var[VAR_ZSAU] = ZSAU_NULL; | ||
493 | at_state->cs = cs; | ||
494 | at_state->bcs = bcs; | ||
495 | at_state->cid = cid; | ||
496 | if (!cid) | ||
497 | at_state->replystruct = cs->tabnocid; | ||
498 | else | ||
499 | at_state->replystruct = cs->tabcid; | ||
500 | } | ||
501 | |||
502 | |||
503 | static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs, | ||
504 | struct cardstate *cs, int inputstate) | ||
505 | /* inbuf->read must be allocated before! */ | ||
506 | { | ||
507 | atomic_set(&inbuf->head, 0); | ||
508 | atomic_set(&inbuf->tail, 0); | ||
509 | inbuf->cs = cs; | ||
510 | inbuf->bcs = bcs; /*base driver: NULL*/ | ||
511 | inbuf->rcvbuf = NULL; //FIXME | ||
512 | inbuf->inputstate = inputstate; | ||
513 | } | ||
514 | |||
515 | /* Initialize the b-channel structure */ | ||
516 | static struct bc_state *gigaset_initbcs(struct bc_state *bcs, | ||
517 | struct cardstate *cs, int channel) | ||
518 | { | ||
519 | int i; | ||
520 | |||
521 | bcs->tx_skb = NULL; //FIXME -> hw part | ||
522 | |||
523 | skb_queue_head_init(&bcs->squeue); | ||
524 | |||
525 | bcs->corrupted = 0; | ||
526 | bcs->trans_down = 0; | ||
527 | bcs->trans_up = 0; | ||
528 | |||
529 | dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel); | ||
530 | gigaset_at_init(&bcs->at_state, bcs, cs, -1); | ||
531 | |||
532 | bcs->rcvbytes = 0; | ||
533 | |||
534 | #ifdef CONFIG_GIGASET_DEBUG | ||
535 | bcs->emptycount = 0; | ||
536 | #endif | ||
537 | |||
538 | dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel); | ||
539 | bcs->fcs = PPP_INITFCS; | ||
540 | bcs->inputstate = 0; | ||
541 | if (cs->ignoreframes) { | ||
542 | bcs->inputstate |= INS_skip_frame; | ||
543 | bcs->skb = NULL; | ||
544 | } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) | ||
545 | skb_reserve(bcs->skb, HW_HDR_LEN); | ||
546 | else { | ||
547 | warn("could not allocate skb"); | ||
548 | bcs->inputstate |= INS_skip_frame; | ||
549 | } | ||
550 | |||
551 | bcs->channel = channel; | ||
552 | bcs->cs = cs; | ||
553 | |||
554 | bcs->chstate = 0; | ||
555 | bcs->use_count = 1; | ||
556 | bcs->busy = 0; | ||
557 | bcs->ignore = cs->ignoreframes; | ||
558 | |||
559 | for (i = 0; i < AT_NUM; ++i) | ||
560 | bcs->commands[i] = NULL; | ||
561 | |||
562 | dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel); | ||
563 | if (cs->ops->initbcshw(bcs)) | ||
564 | return bcs; | ||
565 | |||
566 | //error: | ||
567 | dbg(DEBUG_INIT, " failed"); | ||
568 | |||
569 | dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel); | ||
570 | if (bcs->skb) | ||
571 | dev_kfree_skb(bcs->skb); | ||
572 | |||
573 | return NULL; | ||
574 | } | ||
575 | |||
576 | /* gigaset_initcs | ||
577 | * Allocate and initialize cardstate structure for Gigaset driver | ||
578 | * Calls hardware dependent gigaset_initcshw() function | ||
579 | * Calls B channel initialization function gigaset_initbcs() for each B channel | ||
580 | * parameters: | ||
581 | * drv hardware driver the device belongs to | ||
582 | * channels number of B channels supported by device | ||
583 | * onechannel !=0: B channel data and AT commands share one communication channel | ||
584 | * ==0: B channels have separate communication channels | ||
585 | * ignoreframes number of frames to ignore after setting up B channel | ||
586 | * cidmode !=0: start in CallID mode | ||
587 | * modulename name of driver module (used for I4L registration) | ||
588 | * return value: | ||
589 | * pointer to cardstate structure | ||
590 | */ | ||
591 | struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, | ||
592 | int onechannel, int ignoreframes, | ||
593 | int cidmode, const char *modulename) | ||
594 | { | ||
595 | struct cardstate *cs = NULL; | ||
596 | int i; | ||
597 | |||
598 | dbg(DEBUG_INIT, "allocating cs"); | ||
599 | cs = alloc_cs(drv); | ||
600 | if (!cs) | ||
601 | goto error; | ||
602 | dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1); | ||
603 | cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL); | ||
604 | if (!cs->bcs) | ||
605 | goto error; | ||
606 | dbg(DEBUG_INIT, "allocating inbuf"); | ||
607 | cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL); | ||
608 | if (!cs->inbuf) | ||
609 | goto error; | ||
610 | |||
611 | cs->cs_init = 0; | ||
612 | cs->channels = channels; | ||
613 | cs->onechannel = onechannel; | ||
614 | cs->ignoreframes = ignoreframes; | ||
615 | INIT_LIST_HEAD(&cs->temp_at_states); | ||
616 | atomic_set(&cs->running, 0); | ||
617 | init_timer(&cs->timer); /* clear next & prev */ | ||
618 | spin_lock_init(&cs->ev_lock); | ||
619 | atomic_set(&cs->ev_tail, 0); | ||
620 | atomic_set(&cs->ev_head, 0); | ||
621 | init_MUTEX_LOCKED(&cs->sem); | ||
622 | tasklet_init(&cs->event_tasklet, &gigaset_handle_event, (unsigned long) cs); | ||
623 | atomic_set(&cs->commands_pending, 0); | ||
624 | cs->cur_at_seq = 0; | ||
625 | cs->gotfwver = -1; | ||
626 | cs->open_count = 0; | ||
627 | cs->tty = NULL; | ||
628 | atomic_set(&cs->cidmode, cidmode != 0); | ||
629 | |||
630 | //if(onechannel) { //FIXME | ||
631 | cs->tabnocid = gigaset_tab_nocid_m10x; | ||
632 | cs->tabcid = gigaset_tab_cid_m10x; | ||
633 | //} else { | ||
634 | // cs->tabnocid = gigaset_tab_nocid; | ||
635 | // cs->tabcid = gigaset_tab_cid; | ||
636 | //} | ||
637 | |||
638 | init_waitqueue_head(&cs->waitqueue); | ||
639 | cs->waiting = 0; | ||
640 | |||
641 | atomic_set(&cs->mode, M_UNKNOWN); | ||
642 | atomic_set(&cs->mstate, MS_UNINITIALIZED); | ||
643 | |||
644 | for (i = 0; i < channels; ++i) { | ||
645 | dbg(DEBUG_INIT, "setting up bcs[%d].read", i); | ||
646 | if (!gigaset_initbcs(cs->bcs + i, cs, i)) | ||
647 | goto error; | ||
648 | } | ||
649 | |||
650 | ++cs->cs_init; | ||
651 | |||
652 | dbg(DEBUG_INIT, "setting up at_state"); | ||
653 | spin_lock_init(&cs->lock); | ||
654 | gigaset_at_init(&cs->at_state, NULL, cs, 0); | ||
655 | cs->dle = 0; | ||
656 | cs->cbytes = 0; | ||
657 | |||
658 | dbg(DEBUG_INIT, "setting up inbuf"); | ||
659 | if (onechannel) { //FIXME distinction necessary? | ||
660 | gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command); | ||
661 | } else | ||
662 | gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command); | ||
663 | |||
664 | atomic_set(&cs->connected, 0); | ||
665 | |||
666 | dbg(DEBUG_INIT, "setting up cmdbuf"); | ||
667 | cs->cmdbuf = cs->lastcmdbuf = NULL; | ||
668 | spin_lock_init(&cs->cmdlock); | ||
669 | cs->curlen = 0; | ||
670 | cs->cmdbytes = 0; | ||
671 | |||
672 | /* | ||
673 | * Tell the ISDN4Linux subsystem (the LL) that | ||
674 | * a driver for a USB-Device is available ! | ||
675 | * If this is done, "isdnctrl" is able to bind a device for this driver even | ||
676 | * if no physical usb-device is currently connected. | ||
677 | * But this device will just be accessable if a physical USB device is connected | ||
678 | * (via "gigaset_probe") . | ||
679 | */ | ||
680 | dbg(DEBUG_INIT, "setting up iif"); | ||
681 | if (!gigaset_register_to_LL(cs, modulename)) { | ||
682 | err("register_isdn=>error"); | ||
683 | goto error; | ||
684 | } | ||
685 | |||
686 | make_valid(cs, VALID_ID); | ||
687 | ++cs->cs_init; | ||
688 | dbg(DEBUG_INIT, "setting up hw"); | ||
689 | if (!cs->ops->initcshw(cs)) | ||
690 | goto error; | ||
691 | |||
692 | ++cs->cs_init; | ||
693 | |||
694 | gigaset_if_init(cs); | ||
695 | |||
696 | atomic_set(&cs->running, 1); | ||
697 | cs->timer.data = (unsigned long) cs; | ||
698 | cs->timer.function = timer_tick; | ||
699 | cs->timer.expires = jiffies + GIG_TICK; | ||
700 | /* FIXME: can jiffies increase too much until the timer is added? | ||
701 | * Same problem(?) with mod_timer() in timer_tick(). */ | ||
702 | add_timer(&cs->timer); | ||
703 | |||
704 | dbg(DEBUG_INIT, "cs initialized!"); | ||
705 | up(&cs->sem); | ||
706 | return cs; | ||
707 | |||
708 | error: if (cs) | ||
709 | up(&cs->sem); | ||
710 | dbg(DEBUG_INIT, "failed"); | ||
711 | gigaset_freecs(cs); | ||
712 | return NULL; | ||
713 | } | ||
714 | EXPORT_SYMBOL_GPL(gigaset_initcs); | ||
715 | |||
716 | /* ReInitialize the b-channel structure */ /* e.g. called on hangup, disconnect */ | ||
717 | void gigaset_bcs_reinit(struct bc_state *bcs) | ||
718 | { | ||
719 | struct sk_buff *skb; | ||
720 | struct cardstate *cs = bcs->cs; | ||
721 | unsigned long flags; | ||
722 | |||
723 | while ((skb = skb_dequeue(&bcs->squeue)) != NULL) | ||
724 | dev_kfree_skb(skb); | ||
725 | |||
726 | spin_lock_irqsave(&cs->lock, flags); //FIXME | ||
727 | clear_at_state(&bcs->at_state); | ||
728 | bcs->at_state.ConState = 0; | ||
729 | bcs->at_state.timer_active = 0; | ||
730 | bcs->at_state.timer_expires = 0; | ||
731 | bcs->at_state.cid = -1; /* No CID defined */ | ||
732 | spin_unlock_irqrestore(&cs->lock, flags); | ||
733 | |||
734 | bcs->inputstate = 0; | ||
735 | |||
736 | #ifdef CONFIG_GIGASET_DEBUG | ||
737 | bcs->emptycount = 0; | ||
738 | #endif | ||
739 | |||
740 | bcs->fcs = PPP_INITFCS; | ||
741 | bcs->chstate = 0; | ||
742 | |||
743 | bcs->ignore = cs->ignoreframes; | ||
744 | if (bcs->ignore) | ||
745 | bcs->inputstate |= INS_skip_frame; | ||
746 | |||
747 | |||
748 | cs->ops->reinitbcshw(bcs); | ||
749 | } | ||
750 | |||
751 | static void cleanup_cs(struct cardstate *cs) | ||
752 | { | ||
753 | struct cmdbuf_t *cb, *tcb; | ||
754 | int i; | ||
755 | unsigned long flags; | ||
756 | |||
757 | spin_lock_irqsave(&cs->lock, flags); | ||
758 | |||
759 | atomic_set(&cs->mode, M_UNKNOWN); | ||
760 | atomic_set(&cs->mstate, MS_UNINITIALIZED); | ||
761 | |||
762 | clear_at_state(&cs->at_state); | ||
763 | dealloc_at_states(cs); | ||
764 | free_strings(&cs->at_state); | ||
765 | gigaset_at_init(&cs->at_state, NULL, cs, 0); | ||
766 | |||
767 | kfree(cs->inbuf->rcvbuf); | ||
768 | cs->inbuf->rcvbuf = NULL; | ||
769 | cs->inbuf->inputstate = INS_command; | ||
770 | atomic_set(&cs->inbuf->head, 0); | ||
771 | atomic_set(&cs->inbuf->tail, 0); | ||
772 | |||
773 | cb = cs->cmdbuf; | ||
774 | while (cb) { | ||
775 | tcb = cb; | ||
776 | cb = cb->next; | ||
777 | kfree(tcb); | ||
778 | } | ||
779 | cs->cmdbuf = cs->lastcmdbuf = NULL; | ||
780 | cs->curlen = 0; | ||
781 | cs->cmdbytes = 0; | ||
782 | cs->gotfwver = -1; | ||
783 | cs->dle = 0; | ||
784 | cs->cur_at_seq = 0; | ||
785 | atomic_set(&cs->commands_pending, 0); | ||
786 | cs->cbytes = 0; | ||
787 | |||
788 | spin_unlock_irqrestore(&cs->lock, flags); | ||
789 | |||
790 | for (i = 0; i < cs->channels; ++i) { | ||
791 | gigaset_freebcs(cs->bcs + i); | ||
792 | if (!gigaset_initbcs(cs->bcs + i, cs, i)) | ||
793 | break; //FIXME error handling | ||
794 | } | ||
795 | |||
796 | if (cs->waiting) { | ||
797 | cs->cmd_result = -ENODEV; | ||
798 | cs->waiting = 0; | ||
799 | wake_up_interruptible(&cs->waitqueue); | ||
800 | } | ||
801 | } | ||
802 | |||
803 | |||
804 | int gigaset_start(struct cardstate *cs) | ||
805 | { | ||
806 | if (down_interruptible(&cs->sem)) | ||
807 | return 0; | ||
808 | //info("USB device for Gigaset 307x now attached to Dev %d", ucs->minor); | ||
809 | |||
810 | atomic_set(&cs->connected, 1); | ||
811 | |||
812 | if (atomic_read(&cs->mstate) != MS_LOCKED) { | ||
813 | cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS); | ||
814 | cs->ops->baud_rate(cs, B115200); | ||
815 | cs->ops->set_line_ctrl(cs, CS8); | ||
816 | cs->control_state = TIOCM_DTR|TIOCM_RTS; | ||
817 | } else { | ||
818 | //FIXME use some saved values? | ||
819 | } | ||
820 | |||
821 | cs->waiting = 1; | ||
822 | |||
823 | if (!gigaset_add_event(cs, &cs->at_state, EV_START, NULL, 0, NULL)) { | ||
824 | cs->waiting = 0; | ||
825 | //FIXME what should we do? | ||
826 | goto error; | ||
827 | } | ||
828 | |||
829 | dbg(DEBUG_CMD, "scheduling START"); | ||
830 | gigaset_schedule_event(cs); | ||
831 | |||
832 | wait_event(cs->waitqueue, !cs->waiting); | ||
833 | |||
834 | up(&cs->sem); | ||
835 | return 1; | ||
836 | |||
837 | error: | ||
838 | up(&cs->sem); | ||
839 | return 0; | ||
840 | } | ||
841 | EXPORT_SYMBOL_GPL(gigaset_start); | ||
842 | |||
843 | void gigaset_shutdown(struct cardstate *cs) | ||
844 | { | ||
845 | down(&cs->sem); | ||
846 | |||
847 | cs->waiting = 1; | ||
848 | |||
849 | if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL)) { | ||
850 | //FIXME what should we do? | ||
851 | goto exit; | ||
852 | } | ||
853 | |||
854 | dbg(DEBUG_CMD, "scheduling SHUTDOWN"); | ||
855 | gigaset_schedule_event(cs); | ||
856 | |||
857 | if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { | ||
858 | warn("aborted"); | ||
859 | //FIXME | ||
860 | } | ||
861 | |||
862 | if (atomic_read(&cs->mstate) != MS_LOCKED) { | ||
863 | //FIXME? | ||
864 | //gigaset_baud_rate(cs, B115200); | ||
865 | //gigaset_set_line_ctrl(cs, CS8); | ||
866 | //gigaset_set_modem_ctrl(cs, TIOCM_DTR|TIOCM_RTS, 0); | ||
867 | //cs->control_state = 0; | ||
868 | } else { | ||
869 | //FIXME use some saved values? | ||
870 | } | ||
871 | |||
872 | cleanup_cs(cs); | ||
873 | |||
874 | exit: | ||
875 | up(&cs->sem); | ||
876 | } | ||
877 | EXPORT_SYMBOL_GPL(gigaset_shutdown); | ||
878 | |||
879 | void gigaset_stop(struct cardstate *cs) | ||
880 | { | ||
881 | down(&cs->sem); | ||
882 | |||
883 | atomic_set(&cs->connected, 0); | ||
884 | |||
885 | cs->waiting = 1; | ||
886 | |||
887 | if (!gigaset_add_event(cs, &cs->at_state, EV_STOP, NULL, 0, NULL)) { | ||
888 | //FIXME what should we do? | ||
889 | goto exit; | ||
890 | } | ||
891 | |||
892 | dbg(DEBUG_CMD, "scheduling STOP"); | ||
893 | gigaset_schedule_event(cs); | ||
894 | |||
895 | if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { | ||
896 | warn("aborted"); | ||
897 | //FIXME | ||
898 | } | ||
899 | |||
900 | /* Tell the LL that the device is not available .. */ | ||
901 | gigaset_i4l_cmd(cs, ISDN_STAT_STOP); // FIXME move to event layer? | ||
902 | |||
903 | cleanup_cs(cs); | ||
904 | |||
905 | exit: | ||
906 | up(&cs->sem); | ||
907 | } | ||
908 | EXPORT_SYMBOL_GPL(gigaset_stop); | ||
909 | |||
910 | static LIST_HEAD(drivers); | ||
911 | static spinlock_t driver_lock = SPIN_LOCK_UNLOCKED; | ||
912 | |||
913 | struct cardstate *gigaset_get_cs_by_id(int id) | ||
914 | { | ||
915 | unsigned long flags; | ||
916 | static struct cardstate *ret = NULL; | ||
917 | static struct cardstate *cs; | ||
918 | struct gigaset_driver *drv; | ||
919 | unsigned i; | ||
920 | |||
921 | spin_lock_irqsave(&driver_lock, flags); | ||
922 | list_for_each_entry(drv, &drivers, list) { | ||
923 | spin_lock(&drv->lock); | ||
924 | for (i = 0; i < drv->minors; ++i) { | ||
925 | if (drv->flags[i] & VALID_ID) { | ||
926 | cs = drv->cs + i; | ||
927 | if (cs->myid == id) | ||
928 | ret = cs; | ||
929 | } | ||
930 | if (ret) | ||
931 | break; | ||
932 | } | ||
933 | spin_unlock(&drv->lock); | ||
934 | if (ret) | ||
935 | break; | ||
936 | } | ||
937 | spin_unlock_irqrestore(&driver_lock, flags); | ||
938 | return ret; | ||
939 | } | ||
940 | |||
941 | void gigaset_debugdrivers(void) | ||
942 | { | ||
943 | unsigned long flags; | ||
944 | static struct cardstate *cs; | ||
945 | struct gigaset_driver *drv; | ||
946 | unsigned i; | ||
947 | |||
948 | spin_lock_irqsave(&driver_lock, flags); | ||
949 | list_for_each_entry(drv, &drivers, list) { | ||
950 | dbg(DEBUG_DRIVER, "driver %p", drv); | ||
951 | spin_lock(&drv->lock); | ||
952 | for (i = 0; i < drv->minors; ++i) { | ||
953 | dbg(DEBUG_DRIVER, " index %u", i); | ||
954 | dbg(DEBUG_DRIVER, " flags 0x%02x", drv->flags[i]); | ||
955 | cs = drv->cs + i; | ||
956 | dbg(DEBUG_DRIVER, " cardstate %p", cs); | ||
957 | dbg(DEBUG_DRIVER, " minor_index %u", cs->minor_index); | ||
958 | dbg(DEBUG_DRIVER, " driver %p", cs->driver); | ||
959 | dbg(DEBUG_DRIVER, " i4l id %d", cs->myid); | ||
960 | } | ||
961 | spin_unlock(&drv->lock); | ||
962 | } | ||
963 | spin_unlock_irqrestore(&driver_lock, flags); | ||
964 | } | ||
965 | EXPORT_SYMBOL_GPL(gigaset_debugdrivers); | ||
966 | |||
967 | struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty) | ||
968 | { | ||
969 | if (tty->index < 0 || tty->index >= tty->driver->num) | ||
970 | return NULL; | ||
971 | return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start); | ||
972 | } | ||
973 | |||
974 | struct cardstate *gigaset_get_cs_by_minor(unsigned minor) | ||
975 | { | ||
976 | unsigned long flags; | ||
977 | static struct cardstate *ret = NULL; | ||
978 | struct gigaset_driver *drv; | ||
979 | unsigned index; | ||
980 | |||
981 | spin_lock_irqsave(&driver_lock, flags); | ||
982 | list_for_each_entry(drv, &drivers, list) { | ||
983 | if (minor < drv->minor || minor >= drv->minor + drv->minors) | ||
984 | continue; | ||
985 | index = minor - drv->minor; | ||
986 | spin_lock(&drv->lock); | ||
987 | if (drv->flags[index] & VALID_MINOR) | ||
988 | ret = drv->cs + index; | ||
989 | spin_unlock(&drv->lock); | ||
990 | if (ret) | ||
991 | break; | ||
992 | } | ||
993 | spin_unlock_irqrestore(&driver_lock, flags); | ||
994 | return ret; | ||
995 | } | ||
996 | |||
997 | void gigaset_freedriver(struct gigaset_driver *drv) | ||
998 | { | ||
999 | unsigned long flags; | ||
1000 | |||
1001 | spin_lock_irqsave(&driver_lock, flags); | ||
1002 | list_del(&drv->list); | ||
1003 | spin_unlock_irqrestore(&driver_lock, flags); | ||
1004 | |||
1005 | gigaset_if_freedriver(drv); | ||
1006 | module_put(drv->owner); | ||
1007 | |||
1008 | kfree(drv->cs); | ||
1009 | kfree(drv->flags); | ||
1010 | kfree(drv); | ||
1011 | } | ||
1012 | EXPORT_SYMBOL_GPL(gigaset_freedriver); | ||
1013 | |||
1014 | /* gigaset_initdriver | ||
1015 | * Allocate and initialize gigaset_driver structure. Initialize interface. | ||
1016 | * parameters: | ||
1017 | * minor First minor number | ||
1018 | * minors Number of minors this driver can handle | ||
1019 | * procname Name of the driver (e.g. for /proc/tty/drivers, path in /proc/driver) | ||
1020 | * devname Name of the device files (prefix without minor number) | ||
1021 | * devfsname Devfs name of the device files without %d | ||
1022 | * return value: | ||
1023 | * Pointer to the gigaset_driver structure on success, NULL on failure. | ||
1024 | */ | ||
1025 | struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, | ||
1026 | const char *procname, | ||
1027 | const char *devname, | ||
1028 | const char *devfsname, | ||
1029 | const struct gigaset_ops *ops, | ||
1030 | struct module *owner) | ||
1031 | { | ||
1032 | struct gigaset_driver *drv; | ||
1033 | unsigned long flags; | ||
1034 | unsigned i; | ||
1035 | |||
1036 | drv = kmalloc(sizeof *drv, GFP_KERNEL); | ||
1037 | if (!drv) | ||
1038 | return NULL; | ||
1039 | if (!try_module_get(owner)) | ||
1040 | return NULL; | ||
1041 | |||
1042 | drv->cs = NULL; | ||
1043 | drv->have_tty = 0; | ||
1044 | drv->minor = minor; | ||
1045 | drv->minors = minors; | ||
1046 | spin_lock_init(&drv->lock); | ||
1047 | drv->blocked = 0; | ||
1048 | drv->ops = ops; | ||
1049 | drv->owner = owner; | ||
1050 | INIT_LIST_HEAD(&drv->list); | ||
1051 | |||
1052 | drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL); | ||
1053 | if (!drv->cs) | ||
1054 | goto out1; | ||
1055 | drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL); | ||
1056 | if (!drv->flags) | ||
1057 | goto out2; | ||
1058 | |||
1059 | for (i = 0; i < minors; ++i) { | ||
1060 | drv->flags[i] = 0; | ||
1061 | drv->cs[i].driver = drv; | ||
1062 | drv->cs[i].ops = drv->ops; | ||
1063 | drv->cs[i].minor_index = i; | ||
1064 | } | ||
1065 | |||
1066 | gigaset_if_initdriver(drv, procname, devname, devfsname); | ||
1067 | |||
1068 | spin_lock_irqsave(&driver_lock, flags); | ||
1069 | list_add(&drv->list, &drivers); | ||
1070 | spin_unlock_irqrestore(&driver_lock, flags); | ||
1071 | |||
1072 | return drv; | ||
1073 | |||
1074 | out2: | ||
1075 | kfree(drv->cs); | ||
1076 | out1: | ||
1077 | kfree(drv); | ||
1078 | module_put(owner); | ||
1079 | return NULL; | ||
1080 | } | ||
1081 | EXPORT_SYMBOL_GPL(gigaset_initdriver); | ||
1082 | |||
1083 | static struct cardstate *alloc_cs(struct gigaset_driver *drv) | ||
1084 | { | ||
1085 | unsigned long flags; | ||
1086 | unsigned i; | ||
1087 | static struct cardstate *ret = NULL; | ||
1088 | |||
1089 | spin_lock_irqsave(&drv->lock, flags); | ||
1090 | for (i = 0; i < drv->minors; ++i) { | ||
1091 | if (!(drv->flags[i] & VALID_MINOR)) { | ||
1092 | drv->flags[i] = VALID_MINOR; | ||
1093 | ret = drv->cs + i; | ||
1094 | } | ||
1095 | if (ret) | ||
1096 | break; | ||
1097 | } | ||
1098 | spin_unlock_irqrestore(&drv->lock, flags); | ||
1099 | return ret; | ||
1100 | } | ||
1101 | |||
1102 | static void free_cs(struct cardstate *cs) | ||
1103 | { | ||
1104 | unsigned long flags; | ||
1105 | struct gigaset_driver *drv = cs->driver; | ||
1106 | spin_lock_irqsave(&drv->lock, flags); | ||
1107 | drv->flags[cs->minor_index] = 0; | ||
1108 | spin_unlock_irqrestore(&drv->lock, flags); | ||
1109 | } | ||
1110 | |||
1111 | static void make_valid(struct cardstate *cs, unsigned mask) | ||
1112 | { | ||
1113 | unsigned long flags; | ||
1114 | struct gigaset_driver *drv = cs->driver; | ||
1115 | spin_lock_irqsave(&drv->lock, flags); | ||
1116 | drv->flags[cs->minor_index] |= mask; | ||
1117 | spin_unlock_irqrestore(&drv->lock, flags); | ||
1118 | } | ||
1119 | |||
1120 | static void make_invalid(struct cardstate *cs, unsigned mask) | ||
1121 | { | ||
1122 | unsigned long flags; | ||
1123 | struct gigaset_driver *drv = cs->driver; | ||
1124 | spin_lock_irqsave(&drv->lock, flags); | ||
1125 | drv->flags[cs->minor_index] &= ~mask; | ||
1126 | spin_unlock_irqrestore(&drv->lock, flags); | ||
1127 | } | ||
1128 | |||
1129 | /* For drivers without fixed assignment device<->cardstate (usb) */ | ||
1130 | struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv) | ||
1131 | { | ||
1132 | unsigned long flags; | ||
1133 | struct cardstate *cs = NULL; | ||
1134 | unsigned i; | ||
1135 | |||
1136 | spin_lock_irqsave(&drv->lock, flags); | ||
1137 | if (drv->blocked) | ||
1138 | goto exit; | ||
1139 | for (i = 0; i < drv->minors; ++i) { | ||
1140 | if ((drv->flags[i] & VALID_MINOR) && | ||
1141 | !(drv->flags[i] & ASSIGNED)) { | ||
1142 | drv->flags[i] |= ASSIGNED; | ||
1143 | cs = drv->cs + i; | ||
1144 | break; | ||
1145 | } | ||
1146 | } | ||
1147 | exit: | ||
1148 | spin_unlock_irqrestore(&drv->lock, flags); | ||
1149 | return cs; | ||
1150 | } | ||
1151 | EXPORT_SYMBOL_GPL(gigaset_getunassignedcs); | ||
1152 | |||
1153 | void gigaset_unassign(struct cardstate *cs) | ||
1154 | { | ||
1155 | unsigned long flags; | ||
1156 | unsigned *minor_flags; | ||
1157 | struct gigaset_driver *drv; | ||
1158 | |||
1159 | if (!cs) | ||
1160 | return; | ||
1161 | drv = cs->driver; | ||
1162 | spin_lock_irqsave(&drv->lock, flags); | ||
1163 | minor_flags = drv->flags + cs->minor_index; | ||
1164 | if (*minor_flags & VALID_MINOR) | ||
1165 | *minor_flags &= ~ASSIGNED; | ||
1166 | spin_unlock_irqrestore(&drv->lock, flags); | ||
1167 | } | ||
1168 | EXPORT_SYMBOL_GPL(gigaset_unassign); | ||
1169 | |||
1170 | void gigaset_blockdriver(struct gigaset_driver *drv) | ||
1171 | { | ||
1172 | unsigned long flags; | ||
1173 | spin_lock_irqsave(&drv->lock, flags); | ||
1174 | drv->blocked = 1; | ||
1175 | spin_unlock_irqrestore(&drv->lock, flags); | ||
1176 | } | ||
1177 | EXPORT_SYMBOL_GPL(gigaset_blockdriver); | ||
1178 | |||
1179 | static int __init gigaset_init_module(void) | ||
1180 | { | ||
1181 | /* in accordance with the principle of least astonishment, | ||
1182 | * setting the 'debug' parameter to 1 activates a sensible | ||
1183 | * set of default debug levels | ||
1184 | */ | ||
1185 | if (gigaset_debuglevel == 1) | ||
1186 | gigaset_debuglevel = DEBUG_DEFAULT; | ||
1187 | |||
1188 | info(DRIVER_AUTHOR); | ||
1189 | info(DRIVER_DESC); | ||
1190 | return 0; | ||
1191 | } | ||
1192 | |||
1193 | static void __exit gigaset_exit_module(void) | ||
1194 | { | ||
1195 | } | ||
1196 | |||
1197 | module_init(gigaset_init_module); | ||
1198 | module_exit(gigaset_exit_module); | ||
1199 | |||
1200 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
1201 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
1202 | |||
1203 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h new file mode 100644 index 000000000000..729edcdb6dac --- /dev/null +++ b/drivers/isdn/gigaset/gigaset.h | |||
@@ -0,0 +1,938 @@ | |||
1 | /* Siemens Gigaset 307x driver | ||
2 | * Common header file for all connection variants | ||
3 | * | ||
4 | * Written by Stefan Eilers <Eilers.Stefan@epost.de> | ||
5 | * and Hansjoerg Lipp <hjlipp@web.de> | ||
6 | * | ||
7 | * Version: $Id: gigaset.h,v 1.97.4.26 2006/02/04 18:28:16 hjlipp Exp $ | ||
8 | * =========================================================================== | ||
9 | */ | ||
10 | |||
11 | #ifndef GIGASET_H | ||
12 | #define GIGASET_H | ||
13 | |||
14 | #include <linux/config.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/compiler.h> | ||
17 | #include <linux/types.h> | ||
18 | #include <asm/atomic.h> | ||
19 | #include <linux/spinlock.h> | ||
20 | #include <linux/isdnif.h> | ||
21 | #include <linux/usb.h> | ||
22 | #include <linux/skbuff.h> | ||
23 | #include <linux/netdevice.h> | ||
24 | #include <linux/ppp_defs.h> | ||
25 | #include <linux/timer.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/tty.h> | ||
28 | #include <linux/tty_driver.h> | ||
29 | #include <linux/list.h> | ||
30 | |||
31 | #define GIG_VERSION {0,5,0,0} | ||
32 | #define GIG_COMPAT {0,4,0,0} | ||
33 | |||
34 | #define MAX_REC_PARAMS 10 /* Max. number of params in response string */ | ||
35 | #define MAX_RESP_SIZE 512 /* Max. size of a response string */ | ||
36 | #define HW_HDR_LEN 2 /* Header size used to store ack info */ | ||
37 | |||
38 | #define MAX_EVENTS 64 /* size of event queue */ | ||
39 | |||
40 | #define RBUFSIZE 8192 | ||
41 | #define SBUFSIZE 4096 /* sk_buff payload size */ | ||
42 | |||
43 | #define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */ | ||
44 | #define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */ | ||
45 | |||
46 | /* compile time options */ | ||
47 | #define GIG_MAJOR 0 | ||
48 | |||
49 | #define GIG_MAYINITONDIAL | ||
50 | #define GIG_RETRYCID | ||
51 | #define GIG_X75 | ||
52 | |||
53 | #define MAX_TIMER_INDEX 1000 | ||
54 | #define MAX_SEQ_INDEX 1000 | ||
55 | |||
56 | #define GIG_TICK (HZ / 10) | ||
57 | |||
58 | /* timeout values (unit: 1 sec) */ | ||
59 | #define INIT_TIMEOUT 1 | ||
60 | |||
61 | /* timeout values (unit: 0.1 sec) */ | ||
62 | #define RING_TIMEOUT 3 /* for additional parameters to RING */ | ||
63 | #define BAS_TIMEOUT 20 /* for response to Base USB ops */ | ||
64 | #define ATRDY_TIMEOUT 3 /* for HD_READY_SEND_ATDATA */ | ||
65 | |||
66 | #define BAS_RETRY 3 /* max. retries for base USB ops */ | ||
67 | |||
68 | #define MAXACT 3 | ||
69 | |||
70 | #define IFNULL(a) if (unlikely(!(a))) | ||
71 | #define IFNULLRET(a) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); return; } | ||
72 | #define IFNULLRETVAL(a,b) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); return (b); } | ||
73 | #define IFNULLCONT(a) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); continue; } | ||
74 | #define IFNULLGOTO(a,b) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); goto b; } | ||
75 | |||
76 | extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */ | ||
77 | |||
78 | /* any combination of these can be given with the 'debug=' parameter to insmod, e.g. | ||
79 | * 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and DEBUG_INTR. */ | ||
80 | enum debuglevel { /* up to 24 bits (atomic_t) */ | ||
81 | DEBUG_REG = 0x0002, /* serial port I/O register operations */ | ||
82 | DEBUG_OPEN = 0x0004, /* open/close serial port */ | ||
83 | DEBUG_INTR = 0x0008, /* interrupt processing */ | ||
84 | DEBUG_INTR_DUMP = 0x0010, /* Activating hexdump debug output on interrupt | ||
85 | requests, not available as run-time option */ | ||
86 | DEBUG_CMD = 0x00020, /* sent/received LL commands */ | ||
87 | DEBUG_STREAM = 0x00040, /* application data stream I/O events */ | ||
88 | DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */ | ||
89 | DEBUG_LLDATA = 0x00100, /* sent/received LL data */ | ||
90 | DEBUG_INTR_0 = 0x00200, /* serial port output interrupt processing */ | ||
91 | DEBUG_DRIVER = 0x00400, /* driver structure */ | ||
92 | DEBUG_HDLC = 0x00800, /* M10x HDLC processing */ | ||
93 | DEBUG_WRITE = 0x01000, /* M105 data write */ | ||
94 | DEBUG_TRANSCMD = 0x02000, /*AT-COMMANDS+RESPONSES*/ | ||
95 | DEBUG_MCMD = 0x04000, /*COMMANDS THAT ARE SENT VERY OFTEN*/ | ||
96 | DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data structures */ | ||
97 | DEBUG_LOCK = 0x10000, /* semaphore operations */ | ||
98 | DEBUG_OUTPUT = 0x20000, /* output to device */ | ||
99 | DEBUG_ISO = 0x40000, /* isochronous transfers */ | ||
100 | DEBUG_IF = 0x80000, /* character device operations */ | ||
101 | DEBUG_USBREQ = 0x100000, /* USB communication (except payload data) */ | ||
102 | DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when MS_LOCKED */ | ||
103 | |||
104 | DEBUG_ANY = 0x3fffff, /* print message if any of the others is activated */ | ||
105 | }; | ||
106 | |||
107 | #ifdef CONFIG_GIGASET_DEBUG | ||
108 | #define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ) | ||
109 | //#define DEBUG_DEFAULT (DEBUG_LOCK | DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUF_IF | DEBUG_DRIVER | DEBUG_OUTPUT | DEBUG_INTR) | ||
110 | #else | ||
111 | #define DEBUG_DEFAULT 0 | ||
112 | #endif | ||
113 | |||
114 | /* redefine syslog macros to prepend module name instead of entire source path */ | ||
115 | /* The space before the comma in ", ##" is needed by gcc 2.95 */ | ||
116 | #undef info | ||
117 | #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) | ||
118 | |||
119 | #undef notice | ||
120 | #define notice(format, arg...) printk(KERN_NOTICE "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) | ||
121 | |||
122 | #undef warn | ||
123 | #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) | ||
124 | |||
125 | #undef err | ||
126 | #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) | ||
127 | |||
128 | #undef dbg | ||
129 | #ifdef CONFIG_GIGASET_DEBUG | ||
130 | #define dbg(level, format, arg...) do { if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \ | ||
131 | printk(KERN_DEBUG "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg); } while (0) | ||
132 | #else | ||
133 | #define dbg(level, format, arg...) do {} while (0) | ||
134 | #endif | ||
135 | |||
136 | void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, | ||
137 | size_t len, const unsigned char *buf, int from_user); | ||
138 | |||
139 | /* connection state */ | ||
140 | #define ZSAU_NONE 0 | ||
141 | #define ZSAU_DISCONNECT_IND 4 | ||
142 | #define ZSAU_OUTGOING_CALL_PROCEEDING 1 | ||
143 | #define ZSAU_PROCEEDING 1 | ||
144 | #define ZSAU_CALL_DELIVERED 2 | ||
145 | #define ZSAU_ACTIVE 3 | ||
146 | #define ZSAU_NULL 5 | ||
147 | #define ZSAU_DISCONNECT_REQ 6 | ||
148 | #define ZSAU_UNKNOWN -1 | ||
149 | |||
150 | /* USB control transfer requests */ | ||
151 | #define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT) | ||
152 | #define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT) | ||
153 | |||
154 | /* int-in-events 3070 */ | ||
155 | #define HD_B1_FLOW_CONTROL 0x80 | ||
156 | #define HD_B2_FLOW_CONTROL 0x81 | ||
157 | #define HD_RECEIVEATDATA_ACK (0x35) // 3070 // att: HD_RECEIVE>>AT<<DATA_ACK | ||
158 | #define HD_READY_SEND_ATDATA (0x36) // 3070 | ||
159 | #define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070 | ||
160 | #define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070 | ||
161 | #define HD_DEVICE_INIT_OK (0x11) // ISurf USB + 3070 | ||
162 | #define HD_OPEN_B1CHANNEL_ACK (0x51) // ISurf USB + 3070 | ||
163 | #define HD_OPEN_B2CHANNEL_ACK (0x52) // ISurf USB + 3070 | ||
164 | #define HD_CLOSE_B1CHANNEL_ACK (0x53) // ISurf USB + 3070 | ||
165 | #define HD_CLOSE_B2CHANNEL_ACK (0x54) // ISurf USB + 3070 | ||
166 | // Powermangment | ||
167 | #define HD_SUSPEND_END (0x61) // ISurf USB | ||
168 | // Configuration | ||
169 | #define HD_RESET_INTERRUPT_PIPE_ACK (0xFF) // ISurf USB + 3070 | ||
170 | |||
171 | /* control requests 3070 */ | ||
172 | #define HD_OPEN_B1CHANNEL (0x23) // ISurf USB + 3070 | ||
173 | #define HD_CLOSE_B1CHANNEL (0x24) // ISurf USB + 3070 | ||
174 | #define HD_OPEN_B2CHANNEL (0x25) // ISurf USB + 3070 | ||
175 | #define HD_CLOSE_B2CHANNEL (0x26) // ISurf USB + 3070 | ||
176 | #define HD_RESET_INTERRUPT_PIPE (0x27) // ISurf USB + 3070 | ||
177 | #define HD_DEVICE_INIT_ACK (0x34) // ISurf USB + 3070 | ||
178 | #define HD_WRITE_ATMESSAGE (0x12) // 3070 | ||
179 | #define HD_READ_ATMESSAGE (0x13) // 3070 | ||
180 | #define HD_OPEN_ATCHANNEL (0x28) // 3070 | ||
181 | #define HD_CLOSE_ATCHANNEL (0x29) // 3070 | ||
182 | |||
183 | /* USB frames for isochronous transfer */ | ||
184 | #define BAS_FRAMETIME 1 /* number of milliseconds between frames */ | ||
185 | #define BAS_NUMFRAMES 8 /* number of frames per URB */ | ||
186 | #define BAS_MAXFRAME 16 /* allocated bytes per frame */ | ||
187 | #define BAS_NORMFRAME 8 /* send size without flow control */ | ||
188 | #define BAS_HIGHFRAME 10 /* " " with positive flow control */ | ||
189 | #define BAS_LOWFRAME 5 /* " " with negative flow control */ | ||
190 | #define BAS_CORRFRAMES 4 /* flow control multiplicator */ | ||
191 | |||
192 | #define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES) /* size of isochronous input buffer per URB */ | ||
193 | #define BAS_OUTBUFSIZE 4096 /* size of common isochronous output buffer */ | ||
194 | #define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isochronous output buffer */ | ||
195 | |||
196 | #define BAS_INURBS 3 | ||
197 | #define BAS_OUTURBS 3 | ||
198 | |||
199 | /* variable commands in struct bc_state */ | ||
200 | #define AT_ISO 0 | ||
201 | #define AT_DIAL 1 | ||
202 | #define AT_MSN 2 | ||
203 | #define AT_BC 3 | ||
204 | #define AT_PROTO 4 | ||
205 | #define AT_TYPE 5 | ||
206 | #define AT_HLC 6 | ||
207 | #define AT_NUM 7 | ||
208 | |||
209 | /* variables in struct at_state_t */ | ||
210 | #define VAR_ZSAU 0 | ||
211 | #define VAR_ZDLE 1 | ||
212 | #define VAR_ZVLS 2 | ||
213 | #define VAR_ZCTP 3 | ||
214 | #define VAR_NUM 4 | ||
215 | |||
216 | #define STR_NMBR 0 | ||
217 | #define STR_ZCPN 1 | ||
218 | #define STR_ZCON 2 | ||
219 | #define STR_ZBC 3 | ||
220 | #define STR_ZHLC 4 | ||
221 | #define STR_NUM 5 | ||
222 | |||
223 | #define EV_TIMEOUT -105 | ||
224 | #define EV_IF_VER -106 | ||
225 | #define EV_PROC_CIDMODE -107 | ||
226 | #define EV_SHUTDOWN -108 | ||
227 | #define EV_START -110 | ||
228 | #define EV_STOP -111 | ||
229 | #define EV_IF_LOCK -112 | ||
230 | #define EV_PROTO_L2 -113 | ||
231 | #define EV_ACCEPT -114 | ||
232 | #define EV_DIAL -115 | ||
233 | #define EV_HUP -116 | ||
234 | #define EV_BC_OPEN -117 | ||
235 | #define EV_BC_CLOSED -118 | ||
236 | |||
237 | /* input state */ | ||
238 | #define INS_command 0x0001 | ||
239 | #define INS_DLE_char 0x0002 | ||
240 | #define INS_byte_stuff 0x0004 | ||
241 | #define INS_have_data 0x0008 | ||
242 | #define INS_skip_frame 0x0010 | ||
243 | #define INS_DLE_command 0x0020 | ||
244 | #define INS_flag_hunt 0x0040 | ||
245 | |||
246 | /* channel state */ | ||
247 | #define CHS_D_UP 0x01 | ||
248 | #define CHS_B_UP 0x02 | ||
249 | #define CHS_NOTIFY_LL 0x04 | ||
250 | |||
251 | #define ICALL_REJECT 0 | ||
252 | #define ICALL_ACCEPT 1 | ||
253 | #define ICALL_IGNORE 2 | ||
254 | |||
255 | /* device state */ | ||
256 | #define MS_UNINITIALIZED 0 | ||
257 | #define MS_INIT 1 | ||
258 | #define MS_LOCKED 2 | ||
259 | #define MS_SHUTDOWN 3 | ||
260 | #define MS_RECOVER 4 | ||
261 | #define MS_READY 5 | ||
262 | |||
263 | /* mode */ | ||
264 | #define M_UNKNOWN 0 | ||
265 | #define M_CONFIG 1 | ||
266 | #define M_UNIMODEM 2 | ||
267 | #define M_CID 3 | ||
268 | |||
269 | /* start mode */ | ||
270 | #define SM_LOCKED 0 | ||
271 | #define SM_ISDN 1 /* default */ | ||
272 | |||
273 | struct gigaset_ops; | ||
274 | struct gigaset_driver; | ||
275 | |||
276 | struct usb_cardstate; | ||
277 | struct ser_cardstate; | ||
278 | struct bas_cardstate; | ||
279 | |||
280 | struct bc_state; | ||
281 | struct usb_bc_state; | ||
282 | struct ser_bc_state; | ||
283 | struct bas_bc_state; | ||
284 | |||
285 | struct reply_t { | ||
286 | int resp_code; /* RSP_XXXX */ | ||
287 | int min_ConState; /* <0 => ignore */ | ||
288 | int max_ConState; /* <0 => ignore */ | ||
289 | int parameter; /* e.g. ZSAU_XXXX <0: ignore*/ | ||
290 | int new_ConState; /* <0 => ignore */ | ||
291 | int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/ | ||
292 | int action[MAXACT]; /* ACT_XXXX */ | ||
293 | char *command; /* NULL==none */ | ||
294 | }; | ||
295 | |||
296 | extern struct reply_t gigaset_tab_cid_m10x[]; | ||
297 | extern struct reply_t gigaset_tab_nocid_m10x[]; | ||
298 | |||
299 | struct inbuf_t { | ||
300 | unsigned char *rcvbuf; /* usb-gigaset receive buffer */ | ||
301 | struct bc_state *bcs; | ||
302 | struct cardstate *cs; | ||
303 | int inputstate; | ||
304 | |||
305 | atomic_t head, tail; | ||
306 | unsigned char data[RBUFSIZE]; | ||
307 | }; | ||
308 | |||
309 | /* isochronous write buffer structure | ||
310 | * circular buffer with pad area for extraction of complete USB frames | ||
311 | * - data[read..nextread-1] is valid data already submitted to the USB subsystem | ||
312 | * - data[nextread..write-1] is valid data yet to be sent | ||
313 | * - data[write] is the next byte to write to | ||
314 | * - in byte-oriented L2 procotols, it is completely free | ||
315 | * - in bit-oriented L2 procotols, it may contain a partial byte of valid data | ||
316 | * - data[write+1..read-1] is free | ||
317 | * - wbits is the number of valid data bits in data[write], starting at the LSB | ||
318 | * - writesem is the semaphore for writing to the buffer: | ||
319 | * if writesem <= 0, data[write..read-1] is currently being written to | ||
320 | * - idle contains the byte value to repeat when the end of valid data is | ||
321 | * reached; if nextread==write (buffer contains no data to send), either the | ||
322 | * BAS_OUTBUFPAD bytes immediately before data[write] (if write>=BAS_OUTBUFPAD) | ||
323 | * or those of the pad area (if write<BAS_OUTBUFPAD) are also filled with that | ||
324 | * value | ||
325 | * - optionally, the following statistics on the buffer's usage can be collected: | ||
326 | * maxfill: maximum number of bytes occupied | ||
327 | * idlefills: number of times a frame of idle bytes is prepared | ||
328 | * emptygets: number of times the buffer was empty when a data frame was requested | ||
329 | * backtoback: number of times two data packets were entered into the buffer | ||
330 | * without intervening idle flags | ||
331 | * nakedback: set if no idle flags have been inserted since the last data packet | ||
332 | */ | ||
333 | struct isowbuf_t { | ||
334 | atomic_t read; | ||
335 | atomic_t nextread; | ||
336 | atomic_t write; | ||
337 | atomic_t writesem; | ||
338 | int wbits; | ||
339 | unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD]; | ||
340 | unsigned char idle; | ||
341 | }; | ||
342 | |||
343 | /* isochronous write URB context structure | ||
344 | * data to be stored along with the URB and retrieved when it is returned | ||
345 | * as completed by the USB subsystem | ||
346 | * - urb: pointer to the URB itself | ||
347 | * - bcs: pointer to the B Channel control structure | ||
348 | * - limit: end of write buffer area covered by this URB | ||
349 | */ | ||
350 | struct isow_urbctx_t { | ||
351 | struct urb *urb; | ||
352 | struct bc_state *bcs; | ||
353 | int limit; | ||
354 | }; | ||
355 | |||
356 | /* AT state structure | ||
357 | * data associated with the state of an ISDN connection, whether or not | ||
358 | * it is currently assigned a B channel | ||
359 | */ | ||
360 | struct at_state_t { | ||
361 | struct list_head list; | ||
362 | int waiting; | ||
363 | int getstring; | ||
364 | atomic_t timer_index; | ||
365 | unsigned long timer_expires; | ||
366 | int timer_active; | ||
367 | unsigned int ConState; /* State of connection */ | ||
368 | struct reply_t *replystruct; | ||
369 | int cid; | ||
370 | int int_var[VAR_NUM]; /* see VAR_XXXX */ | ||
371 | char *str_var[STR_NUM]; /* see STR_XXXX */ | ||
372 | unsigned pending_commands; /* see PC_XXXX */ | ||
373 | atomic_t seq_index; | ||
374 | |||
375 | struct cardstate *cs; | ||
376 | struct bc_state *bcs; | ||
377 | }; | ||
378 | |||
379 | struct resp_type_t { | ||
380 | unsigned char *response; | ||
381 | int resp_code; /* RSP_XXXX */ | ||
382 | int type; /* RT_XXXX */ | ||
383 | }; | ||
384 | |||
385 | struct prot_skb { | ||
386 | atomic_t empty; | ||
387 | struct semaphore *sem; | ||
388 | struct sk_buff *skb; | ||
389 | }; | ||
390 | |||
391 | struct event_t { | ||
392 | int type; | ||
393 | void *ptr, *arg; | ||
394 | int parameter; | ||
395 | int cid; | ||
396 | struct at_state_t *at_state; | ||
397 | }; | ||
398 | |||
399 | /* This buffer holds all information about the used B-Channel */ | ||
400 | struct bc_state { | ||
401 | struct sk_buff *tx_skb; /* Current transfer buffer to modem */ | ||
402 | struct sk_buff_head squeue; /* B-Channel send Queue */ | ||
403 | |||
404 | /* Variables for debugging .. */ | ||
405 | int corrupted; /* Counter for corrupted packages */ | ||
406 | int trans_down; /* Counter of packages (downstream) */ | ||
407 | int trans_up; /* Counter of packages (upstream) */ | ||
408 | |||
409 | struct at_state_t at_state; | ||
410 | unsigned long rcvbytes; | ||
411 | |||
412 | __u16 fcs; | ||
413 | struct sk_buff *skb; | ||
414 | int inputstate; /* see INS_XXXX */ | ||
415 | |||
416 | int channel; | ||
417 | |||
418 | struct cardstate *cs; | ||
419 | |||
420 | unsigned chstate; /* bitmap (CHS_*) */ | ||
421 | int ignore; | ||
422 | unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */ | ||
423 | char *commands[AT_NUM]; /* see AT_XXXX */ | ||
424 | |||
425 | #ifdef CONFIG_GIGASET_DEBUG | ||
426 | int emptycount; | ||
427 | #endif | ||
428 | int busy; | ||
429 | int use_count; | ||
430 | |||
431 | /* hardware drivers */ | ||
432 | union { | ||
433 | struct ser_bc_state *ser; /* private data of serial hardware driver */ | ||
434 | struct usb_bc_state *usb; /* private data of usb hardware driver */ | ||
435 | struct bas_bc_state *bas; | ||
436 | } hw; | ||
437 | }; | ||
438 | |||
439 | struct cardstate { | ||
440 | struct gigaset_driver *driver; | ||
441 | unsigned minor_index; | ||
442 | |||
443 | const struct gigaset_ops *ops; | ||
444 | |||
445 | /* Stuff to handle communication */ | ||
446 | //wait_queue_head_t initwait; | ||
447 | wait_queue_head_t waitqueue; | ||
448 | int waiting; | ||
449 | atomic_t mode; /* see M_XXXX */ | ||
450 | atomic_t mstate; /* Modem state: see MS_XXXX */ | ||
451 | /* only changed by the event layer */ | ||
452 | int cmd_result; | ||
453 | |||
454 | int channels; | ||
455 | struct bc_state *bcs; /* Array of struct bc_state */ | ||
456 | |||
457 | int onechannel; /* data and commands transmitted in one stream (M10x) */ | ||
458 | |||
459 | spinlock_t lock; | ||
460 | struct at_state_t at_state; /* at_state_t for cid == 0 */ | ||
461 | struct list_head temp_at_states; /* list of temporary "struct at_state_t"s without B channel */ | ||
462 | |||
463 | struct inbuf_t *inbuf; | ||
464 | |||
465 | struct cmdbuf_t *cmdbuf, *lastcmdbuf; | ||
466 | spinlock_t cmdlock; | ||
467 | unsigned curlen, cmdbytes; | ||
468 | |||
469 | unsigned open_count; | ||
470 | struct tty_struct *tty; | ||
471 | struct tasklet_struct if_wake_tasklet; | ||
472 | unsigned control_state; | ||
473 | |||
474 | unsigned fwver[4]; | ||
475 | int gotfwver; | ||
476 | |||
477 | atomic_t running; /* !=0 if events are handled */ | ||
478 | atomic_t connected; /* !=0 if hardware is connected */ | ||
479 | |||
480 | atomic_t cidmode; | ||
481 | |||
482 | int myid; /* id for communication with LL */ | ||
483 | isdn_if iif; | ||
484 | |||
485 | struct reply_t *tabnocid; | ||
486 | struct reply_t *tabcid; | ||
487 | int cs_init; | ||
488 | int ignoreframes; /* frames to ignore after setting up the B channel */ | ||
489 | struct semaphore sem; /* locks this structure: */ | ||
490 | /* connected is not changed, */ | ||
491 | /* hardware_up is not changed, */ | ||
492 | /* MState is not changed to or from MS_LOCKED */ | ||
493 | |||
494 | struct timer_list timer; | ||
495 | int retry_count; | ||
496 | int dle; /* !=0 if modem commands/responses are dle encoded */ | ||
497 | int cur_at_seq; /* sequence of AT commands being processed */ | ||
498 | int curchannel; /* channel, those commands are meant for */ | ||
499 | atomic_t commands_pending; /* flag(s) in xxx.commands_pending have been set */ | ||
500 | struct tasklet_struct event_tasklet; /* tasklet for serializing AT commands. Scheduled | ||
501 | * -> for modem reponses (and incomming data for M10x) | ||
502 | * -> on timeout | ||
503 | * -> after setting bits in xxx.at_state.pending_command | ||
504 | * (e.g. command from LL) */ | ||
505 | struct tasklet_struct write_tasklet; /* tasklet for serial output | ||
506 | * (not used in base driver) */ | ||
507 | |||
508 | /* event queue */ | ||
509 | struct event_t events[MAX_EVENTS]; | ||
510 | atomic_t ev_tail, ev_head; | ||
511 | spinlock_t ev_lock; | ||
512 | |||
513 | /* current modem response */ | ||
514 | unsigned char respdata[MAX_RESP_SIZE]; | ||
515 | unsigned cbytes; | ||
516 | |||
517 | /* hardware drivers */ | ||
518 | union { | ||
519 | struct usb_cardstate *usb; /* private data of USB hardware driver */ | ||
520 | struct ser_cardstate *ser; /* private data of serial hardware driver */ | ||
521 | struct bas_cardstate *bas; /* private data of base hardware driver */ | ||
522 | } hw; | ||
523 | }; | ||
524 | |||
525 | struct gigaset_driver { | ||
526 | struct list_head list; | ||
527 | spinlock_t lock; /* locks minor tables and blocked */ | ||
528 | //struct semaphore sem; /* locks this structure */ | ||
529 | struct tty_driver *tty; | ||
530 | unsigned have_tty; | ||
531 | unsigned minor; | ||
532 | unsigned minors; | ||
533 | struct cardstate *cs; | ||
534 | unsigned *flags; | ||
535 | int blocked; | ||
536 | |||
537 | const struct gigaset_ops *ops; | ||
538 | struct module *owner; | ||
539 | }; | ||
540 | |||
541 | struct cmdbuf_t { | ||
542 | struct cmdbuf_t *next, *prev; | ||
543 | int len, offset; | ||
544 | struct tasklet_struct *wake_tasklet; | ||
545 | unsigned char buf[0]; | ||
546 | }; | ||
547 | |||
548 | struct bas_bc_state { | ||
549 | /* isochronous output state */ | ||
550 | atomic_t running; | ||
551 | atomic_t corrbytes; | ||
552 | spinlock_t isooutlock; | ||
553 | struct isow_urbctx_t isoouturbs[BAS_OUTURBS]; | ||
554 | struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl; | ||
555 | struct isowbuf_t *isooutbuf; | ||
556 | unsigned numsub; /* submitted URB counter (for diagnostic messages only) */ | ||
557 | struct tasklet_struct sent_tasklet; | ||
558 | |||
559 | /* isochronous input state */ | ||
560 | spinlock_t isoinlock; | ||
561 | struct urb *isoinurbs[BAS_INURBS]; | ||
562 | unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS]; | ||
563 | struct urb *isoindone; /* completed isoc read URB */ | ||
564 | int loststatus; /* status of dropped URB */ | ||
565 | unsigned isoinlost; /* number of bytes lost */ | ||
566 | /* state of bit unstuffing algorithm (in addition to BC_state.inputstate) */ | ||
567 | unsigned seqlen; /* number of '1' bits not yet unstuffed */ | ||
568 | unsigned inbyte, inbits; /* collected bits for next byte */ | ||
569 | /* statistics */ | ||
570 | unsigned goodbytes; /* bytes correctly received */ | ||
571 | unsigned alignerrs; /* frames with incomplete byte at end */ | ||
572 | unsigned fcserrs; /* FCS errors */ | ||
573 | unsigned frameerrs; /* framing errors */ | ||
574 | unsigned giants; /* long frames */ | ||
575 | unsigned runts; /* short frames */ | ||
576 | unsigned aborts; /* HDLC aborts */ | ||
577 | unsigned shared0s; /* '0' bits shared between flags */ | ||
578 | unsigned stolen0s; /* '0' stuff bits also serving as leading flag bits */ | ||
579 | struct tasklet_struct rcvd_tasklet; | ||
580 | }; | ||
581 | |||
582 | struct gigaset_ops { | ||
583 | /* Called from ev-layer.c/interface.c for sending AT commands to the device */ | ||
584 | int (*write_cmd)(struct cardstate *cs, | ||
585 | const unsigned char *buf, int len, | ||
586 | struct tasklet_struct *wake_tasklet); | ||
587 | |||
588 | /* Called from interface.c for additional device control */ | ||
589 | int (*write_room)(struct cardstate *cs); | ||
590 | int (*chars_in_buffer)(struct cardstate *cs); | ||
591 | int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]); | ||
592 | |||
593 | /* Called from ev-layer.c after setting up connection | ||
594 | * Should call gigaset_bchannel_up(), when finished. */ | ||
595 | int (*init_bchannel)(struct bc_state *bcs); | ||
596 | |||
597 | /* Called from ev-layer.c after hanging up | ||
598 | * Should call gigaset_bchannel_down(), when finished. */ | ||
599 | int (*close_bchannel)(struct bc_state *bcs); | ||
600 | |||
601 | /* Called by gigaset_initcs() for setting up bcs->hw.xxx */ | ||
602 | int (*initbcshw)(struct bc_state *bcs); | ||
603 | |||
604 | /* Called by gigaset_freecs() for freeing bcs->hw.xxx */ | ||
605 | int (*freebcshw)(struct bc_state *bcs); | ||
606 | |||
607 | /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting bcs->hw.xxx */ | ||
608 | void (*reinitbcshw)(struct bc_state *bcs); | ||
609 | |||
610 | /* Called by gigaset_initcs() for setting up cs->hw.xxx */ | ||
611 | int (*initcshw)(struct cardstate *cs); | ||
612 | |||
613 | /* Called by gigaset_freecs() for freeing cs->hw.xxx */ | ||
614 | void (*freecshw)(struct cardstate *cs); | ||
615 | |||
616 | ///* Called by gigaset_stop() for killing URBs, shutting down the device, ... | ||
617 | // hardwareup: ==0: don't try to shut down the device, hardware is really not accessible | ||
618 | // !=0: hardware still up */ | ||
619 | //void (*stophw)(struct cardstate *cs, int hardwareup); | ||
620 | |||
621 | /* Called from common.c/interface.c for additional serial port control */ | ||
622 | int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state, unsigned new_state); | ||
623 | int (*baud_rate)(struct cardstate *cs, unsigned cflag); | ||
624 | int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag); | ||
625 | |||
626 | /* Called from i4l.c to put an skb into the send-queue. */ | ||
627 | int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb); | ||
628 | |||
629 | /* Called from ev-layer.c to process a block of data | ||
630 | * received through the common/control channel. */ | ||
631 | void (*handle_input)(struct inbuf_t *inbuf); | ||
632 | |||
633 | }; | ||
634 | |||
635 | /* = Common structures and definitions ======================================= */ | ||
636 | |||
637 | /* Parser states for DLE-Event: | ||
638 | * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "." | ||
639 | * <DLE_FLAG>: 0x10 | ||
640 | * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+ | ||
641 | */ | ||
642 | #define DLE_FLAG 0x10 | ||
643 | |||
644 | /* =========================================================================== | ||
645 | * Functions implemented in asyncdata.c | ||
646 | */ | ||
647 | |||
648 | /* Called from i4l.c to put an skb into the send-queue. | ||
649 | * After sending gigaset_skb_sent() should be called. */ | ||
650 | int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb); | ||
651 | |||
652 | /* Called from ev-layer.c to process a block of data | ||
653 | * received through the common/control channel. */ | ||
654 | void gigaset_m10x_input(struct inbuf_t *inbuf); | ||
655 | |||
656 | /* =========================================================================== | ||
657 | * Functions implemented in isocdata.c | ||
658 | */ | ||
659 | |||
660 | /* Called from i4l.c to put an skb into the send-queue. | ||
661 | * After sending gigaset_skb_sent() should be called. */ | ||
662 | int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb); | ||
663 | |||
664 | /* Called from ev-layer.c to process a block of data | ||
665 | * received through the common/control channel. */ | ||
666 | void gigaset_isoc_input(struct inbuf_t *inbuf); | ||
667 | |||
668 | /* Called from bas-gigaset.c to process a block of data | ||
669 | * received through the isochronous channel */ | ||
670 | void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs); | ||
671 | |||
672 | /* Called from bas-gigaset.c to put a block of data | ||
673 | * into the isochronous output buffer */ | ||
674 | int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len); | ||
675 | |||
676 | /* Called from bas-gigaset.c to initialize the isochronous output buffer */ | ||
677 | void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle); | ||
678 | |||
679 | /* Called from bas-gigaset.c to retrieve a block of bytes for sending */ | ||
680 | int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size); | ||
681 | |||
682 | /* =========================================================================== | ||
683 | * Functions implemented in i4l.c/gigaset.h | ||
684 | */ | ||
685 | |||
686 | /* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */ | ||
687 | int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid); | ||
688 | |||
689 | /* Called from xxx-gigaset.c to indicate completion of sending an skb */ | ||
690 | void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb); | ||
691 | |||
692 | /* Called from common.c/ev-layer.c to indicate events relevant to the LL */ | ||
693 | int gigaset_isdn_icall(struct at_state_t *at_state); | ||
694 | int gigaset_isdn_setup_accept(struct at_state_t *at_state); | ||
695 | int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data); | ||
696 | |||
697 | void gigaset_i4l_cmd(struct cardstate *cs, int cmd); | ||
698 | void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd); | ||
699 | |||
700 | |||
701 | static inline void gigaset_isdn_rcv_err(struct bc_state *bcs) | ||
702 | { | ||
703 | isdn_ctrl response; | ||
704 | |||
705 | /* error -> LL */ | ||
706 | dbg(DEBUG_CMD, "sending L1ERR"); | ||
707 | response.driver = bcs->cs->myid; | ||
708 | response.command = ISDN_STAT_L1ERR; | ||
709 | response.arg = bcs->channel; | ||
710 | response.parm.errcode = ISDN_STAT_L1ERR_RECV; | ||
711 | bcs->cs->iif.statcallb(&response); | ||
712 | } | ||
713 | |||
714 | /* =========================================================================== | ||
715 | * Functions implemented in ev-layer.c | ||
716 | */ | ||
717 | |||
718 | /* tasklet called from common.c to process queued events */ | ||
719 | void gigaset_handle_event(unsigned long data); | ||
720 | |||
721 | /* called from isocdata.c / asyncdata.c | ||
722 | * when a complete modem response line has been received */ | ||
723 | void gigaset_handle_modem_response(struct cardstate *cs); | ||
724 | |||
725 | /* =========================================================================== | ||
726 | * Functions implemented in proc.c | ||
727 | */ | ||
728 | |||
729 | /* initialize sysfs for device */ | ||
730 | void gigaset_init_dev_sysfs(struct usb_interface *interface); | ||
731 | void gigaset_free_dev_sysfs(struct usb_interface *interface); | ||
732 | |||
733 | /* =========================================================================== | ||
734 | * Functions implemented in common.c/gigaset.h | ||
735 | */ | ||
736 | |||
737 | void gigaset_bcs_reinit(struct bc_state *bcs); | ||
738 | void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, | ||
739 | struct cardstate *cs, int cid); | ||
740 | int gigaset_get_channel(struct bc_state *bcs); | ||
741 | void gigaset_free_channel(struct bc_state *bcs); | ||
742 | int gigaset_get_channels(struct cardstate *cs); | ||
743 | void gigaset_free_channels(struct cardstate *cs); | ||
744 | void gigaset_block_channels(struct cardstate *cs); | ||
745 | |||
746 | /* Allocate and initialize driver structure. */ | ||
747 | struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, | ||
748 | const char *procname, | ||
749 | const char *devname, | ||
750 | const char *devfsname, | ||
751 | const struct gigaset_ops *ops, | ||
752 | struct module *owner); | ||
753 | |||
754 | /* Deallocate driver structure. */ | ||
755 | void gigaset_freedriver(struct gigaset_driver *drv); | ||
756 | void gigaset_debugdrivers(void); | ||
757 | struct cardstate *gigaset_get_cs_by_minor(unsigned minor); | ||
758 | struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty); | ||
759 | struct cardstate *gigaset_get_cs_by_id(int id); | ||
760 | |||
761 | /* For drivers without fixed assignment device<->cardstate (usb) */ | ||
762 | struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv); | ||
763 | void gigaset_unassign(struct cardstate *cs); | ||
764 | void gigaset_blockdriver(struct gigaset_driver *drv); | ||
765 | |||
766 | /* Allocate and initialize card state. Calls hardware dependent gigaset_init[b]cs(). */ | ||
767 | struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, | ||
768 | int onechannel, int ignoreframes, | ||
769 | int cidmode, const char *modulename); | ||
770 | |||
771 | /* Free card state. Calls hardware dependent gigaset_free[b]cs(). */ | ||
772 | void gigaset_freecs(struct cardstate *cs); | ||
773 | |||
774 | /* Tell common.c that hardware and driver are ready. */ | ||
775 | int gigaset_start(struct cardstate *cs); | ||
776 | |||
777 | /* Tell common.c that the device is not present any more. */ | ||
778 | void gigaset_stop(struct cardstate *cs); | ||
779 | |||
780 | /* Tell common.c that the driver is being unloaded. */ | ||
781 | void gigaset_shutdown(struct cardstate *cs); | ||
782 | |||
783 | /* Tell common.c that an skb has been sent. */ | ||
784 | void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb); | ||
785 | |||
786 | /* Append event to the queue. | ||
787 | * Returns NULL on failure or a pointer to the event on success. | ||
788 | * ptr must be kmalloc()ed (and not be freed by the caller). | ||
789 | */ | ||
790 | struct event_t *gigaset_add_event(struct cardstate *cs, | ||
791 | struct at_state_t *at_state, int type, | ||
792 | void *ptr, int parameter, void *arg); | ||
793 | |||
794 | /* Called on CONFIG1 command from frontend. */ | ||
795 | int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode | ||
796 | |||
797 | /* cs->lock must not be locked */ | ||
798 | static inline void gigaset_schedule_event(struct cardstate *cs) | ||
799 | { | ||
800 | unsigned long flags; | ||
801 | spin_lock_irqsave(&cs->lock, flags); | ||
802 | if (atomic_read(&cs->running)) | ||
803 | tasklet_schedule(&cs->event_tasklet); | ||
804 | spin_unlock_irqrestore(&cs->lock, flags); | ||
805 | } | ||
806 | |||
807 | /* Tell common.c that B channel has been closed. */ | ||
808 | /* cs->lock must not be locked */ | ||
809 | static inline void gigaset_bchannel_down(struct bc_state *bcs) | ||
810 | { | ||
811 | gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL); | ||
812 | |||
813 | dbg(DEBUG_CMD, "scheduling BC_CLOSED"); | ||
814 | gigaset_schedule_event(bcs->cs); | ||
815 | } | ||
816 | |||
817 | /* Tell common.c that B channel has been opened. */ | ||
818 | /* cs->lock must not be locked */ | ||
819 | static inline void gigaset_bchannel_up(struct bc_state *bcs) | ||
820 | { | ||
821 | gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL); | ||
822 | |||
823 | dbg(DEBUG_CMD, "scheduling BC_OPEN"); | ||
824 | gigaset_schedule_event(bcs->cs); | ||
825 | } | ||
826 | |||
827 | /* handling routines for sk_buff */ | ||
828 | /* ============================= */ | ||
829 | |||
830 | /* private version of __skb_put() | ||
831 | * append 'len' bytes to the content of 'skb', already knowing that the | ||
832 | * existing buffer can accomodate them | ||
833 | * returns a pointer to the location where the new bytes should be copied to | ||
834 | * This function does not take any locks so it must be called with the | ||
835 | * appropriate locks held only. | ||
836 | */ | ||
837 | static inline unsigned char *gigaset_skb_put_quick(struct sk_buff *skb, | ||
838 | unsigned int len) | ||
839 | { | ||
840 | unsigned char *tmp = skb->tail; | ||
841 | /*SKB_LINEAR_ASSERT(skb);*/ /* not needed here */ | ||
842 | skb->tail += len; | ||
843 | skb->len += len; | ||
844 | return tmp; | ||
845 | } | ||
846 | |||
847 | /* pass received skb to LL | ||
848 | * Warning: skb must not be accessed anymore! | ||
849 | */ | ||
850 | static inline void gigaset_rcv_skb(struct sk_buff *skb, | ||
851 | struct cardstate *cs, | ||
852 | struct bc_state *bcs) | ||
853 | { | ||
854 | cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb); | ||
855 | bcs->trans_down++; | ||
856 | } | ||
857 | |||
858 | /* handle reception of corrupted skb | ||
859 | * Warning: skb must not be accessed anymore! | ||
860 | */ | ||
861 | static inline void gigaset_rcv_error(struct sk_buff *procskb, | ||
862 | struct cardstate *cs, | ||
863 | struct bc_state *bcs) | ||
864 | { | ||
865 | if (procskb) | ||
866 | dev_kfree_skb(procskb); | ||
867 | |||
868 | if (bcs->ignore) | ||
869 | --bcs->ignore; | ||
870 | else { | ||
871 | ++bcs->corrupted; | ||
872 | gigaset_isdn_rcv_err(bcs); | ||
873 | } | ||
874 | } | ||
875 | |||
876 | |||
877 | /* bitwise byte inversion table */ | ||
878 | extern __u8 gigaset_invtab[]; /* in common.c */ | ||
879 | |||
880 | |||
881 | /* append received bytes to inbuf */ | ||
882 | static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf, | ||
883 | const unsigned char *src, | ||
884 | unsigned numbytes) | ||
885 | { | ||
886 | unsigned n, head, tail, bytesleft; | ||
887 | |||
888 | dbg(DEBUG_INTR, "received %u bytes", numbytes); | ||
889 | |||
890 | if (!numbytes) | ||
891 | return 0; | ||
892 | |||
893 | bytesleft = numbytes; | ||
894 | tail = atomic_read(&inbuf->tail); | ||
895 | head = atomic_read(&inbuf->head); | ||
896 | dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); | ||
897 | |||
898 | while (bytesleft) { | ||
899 | if (head > tail) | ||
900 | n = head - 1 - tail; | ||
901 | else if (head == 0) | ||
902 | n = (RBUFSIZE-1) - tail; | ||
903 | else | ||
904 | n = RBUFSIZE - tail; | ||
905 | if (!n) { | ||
906 | err("buffer overflow (%u bytes lost)", bytesleft); | ||
907 | break; | ||
908 | } | ||
909 | if (n > bytesleft) | ||
910 | n = bytesleft; | ||
911 | memcpy(inbuf->data + tail, src, n); | ||
912 | bytesleft -= n; | ||
913 | tail = (tail + n) % RBUFSIZE; | ||
914 | src += n; | ||
915 | } | ||
916 | dbg(DEBUG_INTR, "setting tail to %u", tail); | ||
917 | atomic_set(&inbuf->tail, tail); | ||
918 | return numbytes != bytesleft; | ||
919 | } | ||
920 | |||
921 | /* =========================================================================== | ||
922 | * Functions implemented in interface.c | ||
923 | */ | ||
924 | |||
925 | /* initialize interface */ | ||
926 | void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, | ||
927 | const char *devname, const char *devfsname); | ||
928 | /* release interface */ | ||
929 | void gigaset_if_freedriver(struct gigaset_driver *drv); | ||
930 | /* add minor */ | ||
931 | void gigaset_if_init(struct cardstate *cs); | ||
932 | /* remove minor */ | ||
933 | void gigaset_if_free(struct cardstate *cs); | ||
934 | /* device received data */ | ||
935 | void gigaset_if_receive(struct cardstate *cs, | ||
936 | unsigned char *buffer, size_t len); | ||
937 | |||
938 | #endif | ||