aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor_core@ameritech.net>2006-04-29 01:11:23 -0400
committerDmitry Torokhov <dtor_core@ameritech.net>2006-04-29 01:11:23 -0400
commit7b7e394185014e0f3bd8989cac937003f20ef9ce (patch)
tree3beda5f979bba0aa9822534e239cf1b45f3be69c /drivers/isdn
parentddc5d3414593e4d7ad7fbd33e7f7517fcc234544 (diff)
parent693f7d362055261882659475d2ef022e32edbff1 (diff)
Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers/isdn')
-rw-r--r--drivers/isdn/gigaset/Kconfig4
-rw-r--r--drivers/isdn/gigaset/asyncdata.c132
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c1321
-rw-r--r--drivers/isdn/gigaset/common.c504
-rw-r--r--drivers/isdn/gigaset/ev-layer.c670
-rw-r--r--drivers/isdn/gigaset/gigaset.h601
-rw-r--r--drivers/isdn/gigaset/i4l.c229
-rw-r--r--drivers/isdn/gigaset/interface.c235
-rw-r--r--drivers/isdn/gigaset/isocdata.c139
-rw-r--r--drivers/isdn/gigaset/proc.c51
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c455
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c185
-rw-r--r--drivers/isdn/hisax/avma1_cs.c182
-rw-r--r--drivers/isdn/hisax/elsa_cs.c112
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c143
-rw-r--r--drivers/isdn/hisax/teles_cs.c121
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c20
17 files changed, 2412 insertions, 2692 deletions
diff --git a/drivers/isdn/gigaset/Kconfig b/drivers/isdn/gigaset/Kconfig
index 53c4fb62ed85..5b203fe21dcd 100644
--- a/drivers/isdn/gigaset/Kconfig
+++ b/drivers/isdn/gigaset/Kconfig
@@ -3,8 +3,8 @@ menu "Siemens Gigaset"
3 3
4config ISDN_DRV_GIGASET 4config ISDN_DRV_GIGASET
5 tristate "Siemens Gigaset support (isdn)" 5 tristate "Siemens Gigaset support (isdn)"
6 depends on ISDN_I4L && m 6 depends on ISDN_I4L
7# depends on ISDN_I4L && MODULES 7 select CRC_CCITT
8 help 8 help
9 Say m here if you have a Gigaset or Sinus isdn device. 9 Say m here if you have a Gigaset or Sinus isdn device.
10 10
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index 171f8b703d61..ce3cd77094b3 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (c) 2005 by Tilman Schmidt <tilman@imap.cc>, 4 * Copyright (c) 2005 by Tilman Schmidt <tilman@imap.cc>,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Stefan Eilers <Eilers.Stefan@epost.de>. 6 * Stefan Eilers.
7 * 7 *
8 * ===================================================================== 8 * =====================================================================
9 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
@@ -11,10 +11,6 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: asyncdata.c,v 1.2.2.7 2005/11/13 23:05:18 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
@@ -45,7 +41,7 @@ static inline int muststuff(unsigned char c)
45 * number of processed bytes 41 * number of processed bytes
46 */ 42 */
47static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes, 43static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
48 struct inbuf_t *inbuf) 44 struct inbuf_t *inbuf)
49{ 45{
50 struct cardstate *cs = inbuf->cs; 46 struct cardstate *cs = inbuf->cs;
51 unsigned cbytes = cs->cbytes; 47 unsigned cbytes = cs->cbytes;
@@ -55,10 +51,11 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
55 for (;;) { 51 for (;;) {
56 cs->respdata[cbytes] = c; 52 cs->respdata[cbytes] = c;
57 if (c == 10 || c == 13) { 53 if (c == 10 || c == 13) {
58 dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", 54 gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
59 __func__, cbytes); 55 __func__, cbytes);
60 cs->cbytes = cbytes; 56 cs->cbytes = cbytes;
61 gigaset_handle_modem_response(cs); /* can change cs->dle */ 57 gigaset_handle_modem_response(cs); /* can change
58 cs->dle */
62 cbytes = 0; 59 cbytes = 0;
63 60
64 if (cs->dle && 61 if (cs->dle &&
@@ -71,7 +68,7 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
71 if (cbytes < MAX_RESP_SIZE - 1) 68 if (cbytes < MAX_RESP_SIZE - 1)
72 cbytes++; 69 cbytes++;
73 else 70 else
74 warn("response too large"); 71 dev_warn(cs->dev, "response too large\n");
75 } 72 }
76 73
77 if (!numbytes) 74 if (!numbytes)
@@ -96,11 +93,12 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
96 * number of processed bytes 93 * number of processed bytes
97 */ 94 */
98static inline int lock_loop(unsigned char *src, int numbytes, 95static inline int lock_loop(unsigned char *src, int numbytes,
99 struct inbuf_t *inbuf) 96 struct inbuf_t *inbuf)
100{ 97{
101 struct cardstate *cs = inbuf->cs; 98 struct cardstate *cs = inbuf->cs;
102 99
103 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response", numbytes, src, 0); 100 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response",
101 numbytes, src);
104 gigaset_if_receive(cs, src, numbytes); 102 gigaset_if_receive(cs, src, numbytes);
105 103
106 return numbytes; 104 return numbytes;
@@ -115,24 +113,18 @@ static inline int lock_loop(unsigned char *src, int numbytes,
115 * numbytes (all bytes processed) on error --FIXME 113 * numbytes (all bytes processed) on error --FIXME
116 */ 114 */
117static inline int hdlc_loop(unsigned char c, unsigned char *src, int numbytes, 115static inline int hdlc_loop(unsigned char c, unsigned char *src, int numbytes,
118 struct inbuf_t *inbuf) 116 struct inbuf_t *inbuf)
119{ 117{
120 struct cardstate *cs = inbuf->cs; 118 struct cardstate *cs = inbuf->cs;
121 struct bc_state *bcs = inbuf->bcs; 119 struct bc_state *bcs = inbuf->bcs;
122 int inputstate; 120 int inputstate = bcs->inputstate;
123 __u16 fcs; 121 __u16 fcs = bcs->fcs;
124 struct sk_buff *skb; 122 struct sk_buff *skb = bcs->skb;
125 unsigned char error; 123 unsigned char error;
126 struct sk_buff *compskb; 124 struct sk_buff *compskb;
127 int startbytes = numbytes; 125 int startbytes = numbytes;
128 int l; 126 int l;
129 127
130 IFNULLRETVAL(bcs, numbytes);
131 inputstate = bcs->inputstate;
132 fcs = bcs->fcs;
133 skb = bcs->skb;
134 IFNULLRETVAL(skb, numbytes);
135
136 if (unlikely(inputstate & INS_byte_stuff)) { 128 if (unlikely(inputstate & INS_byte_stuff)) {
137 inputstate &= ~INS_byte_stuff; 129 inputstate &= ~INS_byte_stuff;
138 goto byte_stuff; 130 goto byte_stuff;
@@ -156,39 +148,37 @@ byte_stuff:
156 c ^= PPP_TRANS; 148 c ^= PPP_TRANS;
157#ifdef CONFIG_GIGASET_DEBUG 149#ifdef CONFIG_GIGASET_DEBUG
158 if (unlikely(!muststuff(c))) 150 if (unlikely(!muststuff(c)))
159 dbg(DEBUG_HDLC, 151 gig_dbg(DEBUG_HDLC, "byte stuffed: 0x%02x", c);
160 "byte stuffed: 0x%02x", c);
161#endif 152#endif
162 } else if (unlikely(c == PPP_FLAG)) { 153 } else if (unlikely(c == PPP_FLAG)) {
163 if (unlikely(inputstate & INS_skip_frame)) { 154 if (unlikely(inputstate & INS_skip_frame)) {
164 if (!(inputstate & INS_have_data)) { /* 7E 7E */ 155 if (!(inputstate & INS_have_data)) { /* 7E 7E */
165 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
166#ifdef CONFIG_GIGASET_DEBUG 156#ifdef CONFIG_GIGASET_DEBUG
167 ++bcs->emptycount; 157 ++bcs->emptycount;
168#endif 158#endif
169 } else 159 } else
170 dbg(DEBUG_HDLC, 160 gig_dbg(DEBUG_HDLC,
171 "7e----------------------------"); 161 "7e----------------------------");
172 162
173 /* end of frame */ 163 /* end of frame */
174 error = 1; 164 error = 1;
175 gigaset_rcv_error(NULL, cs, bcs); 165 gigaset_rcv_error(NULL, cs, bcs);
176 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */ 166 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */
177 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
178#ifdef CONFIG_GIGASET_DEBUG 167#ifdef CONFIG_GIGASET_DEBUG
179 ++bcs->emptycount; 168 ++bcs->emptycount;
180#endif 169#endif
181 break; 170 break;
182 } else { 171 } else {
183 dbg(DEBUG_HDLC, 172 gig_dbg(DEBUG_HDLC,
184 "7e----------------------------"); 173 "7e----------------------------");
185 174
186 /* end of frame */ 175 /* end of frame */
187 error = 0; 176 error = 0;
188 177
189 if (unlikely(fcs != PPP_GOODFCS)) { 178 if (unlikely(fcs != PPP_GOODFCS)) {
190 err("Packet checksum at %lu failed, " 179 dev_err(cs->dev,
191 "packet is corrupted (%u bytes)!", 180 "Packet checksum at %lu failed, "
181 "packet is corrupted (%u bytes)!\n",
192 bcs->rcvbytes, skb->len); 182 bcs->rcvbytes, skb->len);
193 compskb = NULL; 183 compskb = NULL;
194 gigaset_rcv_error(compskb, cs, bcs); 184 gigaset_rcv_error(compskb, cs, bcs);
@@ -202,9 +192,11 @@ byte_stuff:
202 skb = NULL; 192 skb = NULL;
203 inputstate |= INS_skip_frame; 193 inputstate |= INS_skip_frame;
204 if (l == 1) { 194 if (l == 1) {
205 err("invalid packet size (1)!"); 195 dev_err(cs->dev,
196 "invalid packet size (1)!\n");
206 error = 1; 197 error = 1;
207 gigaset_rcv_error(NULL, cs, bcs); 198 gigaset_rcv_error(NULL,
199 cs, bcs);
208 } 200 }
209 } 201 }
210 if (likely(!(error || 202 if (likely(!(error ||
@@ -227,7 +219,8 @@ byte_stuff:
227 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) { 219 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) {
228 skb_reserve(skb, HW_HDR_LEN); 220 skb_reserve(skb, HW_HDR_LEN);
229 } else { 221 } else {
230 warn("could not allocate new skb"); 222 dev_warn(cs->dev,
223 "could not allocate new skb\n");
231 inputstate |= INS_skip_frame; 224 inputstate |= INS_skip_frame;
232 } 225 }
233 226
@@ -235,7 +228,7 @@ byte_stuff:
235#ifdef CONFIG_GIGASET_DEBUG 228#ifdef CONFIG_GIGASET_DEBUG
236 } else if (unlikely(muststuff(c))) { 229 } else if (unlikely(muststuff(c))) {
237 /* Should not happen. Possible after ZDLE=1<CR><LF>. */ 230 /* Should not happen. Possible after ZDLE=1<CR><LF>. */
238 dbg(DEBUG_HDLC, "not byte stuffed: 0x%02x", c); 231 gig_dbg(DEBUG_HDLC, "not byte stuffed: 0x%02x", c);
239#endif 232#endif
240 } 233 }
241 234
@@ -243,8 +236,8 @@ byte_stuff:
243 236
244#ifdef CONFIG_GIGASET_DEBUG 237#ifdef CONFIG_GIGASET_DEBUG
245 if (unlikely(!(inputstate & INS_have_data))) { 238 if (unlikely(!(inputstate & INS_have_data))) {
246 dbg(DEBUG_HDLC, 239 gig_dbg(DEBUG_HDLC, "7e (%d x) ================",
247 "7e (%d x) ================", bcs->emptycount); 240 bcs->emptycount);
248 bcs->emptycount = 0; 241 bcs->emptycount = 0;
249 } 242 }
250#endif 243#endif
@@ -253,14 +246,13 @@ byte_stuff:
253 246
254 if (likely(!(inputstate & INS_skip_frame))) { 247 if (likely(!(inputstate & INS_skip_frame))) {
255 if (unlikely(skb->len == SBUFSIZE)) { 248 if (unlikely(skb->len == SBUFSIZE)) {
256 warn("received packet too long"); 249 dev_warn(cs->dev, "received packet too long\n");
257 dev_kfree_skb_any(skb); 250 dev_kfree_skb_any(skb);
258 skb = NULL; 251 skb = NULL;
259 inputstate |= INS_skip_frame; 252 inputstate |= INS_skip_frame;
260 break; 253 break;
261 } 254 }
262 *gigaset_skb_put_quick(skb, 1) = c; 255 *__skb_put(skb, 1) = c;
263 /* *__skb_put (skb, 1) = c; */
264 fcs = crc_ccitt_byte(fcs, c); 256 fcs = crc_ccitt_byte(fcs, c);
265 } 257 }
266 258
@@ -289,19 +281,14 @@ byte_stuff:
289 * numbytes (all bytes processed) on error --FIXME 281 * numbytes (all bytes processed) on error --FIXME
290 */ 282 */
291static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes, 283static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
292 struct inbuf_t *inbuf) 284 struct inbuf_t *inbuf)
293{ 285{
294 struct cardstate *cs = inbuf->cs; 286 struct cardstate *cs = inbuf->cs;
295 struct bc_state *bcs = inbuf->bcs; 287 struct bc_state *bcs = inbuf->bcs;
296 int inputstate; 288 int inputstate = bcs->inputstate;
297 struct sk_buff *skb; 289 struct sk_buff *skb = bcs->skb;
298 int startbytes = numbytes; 290 int startbytes = numbytes;
299 291
300 IFNULLRETVAL(bcs, numbytes);
301 inputstate = bcs->inputstate;
302 skb = bcs->skb;
303 IFNULLRETVAL(skb, numbytes);
304
305 for (;;) { 292 for (;;) {
306 /* add character */ 293 /* add character */
307 inputstate |= INS_have_data; 294 inputstate |= INS_have_data;
@@ -309,13 +296,13 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
309 if (likely(!(inputstate & INS_skip_frame))) { 296 if (likely(!(inputstate & INS_skip_frame))) {
310 if (unlikely(skb->len == SBUFSIZE)) { 297 if (unlikely(skb->len == SBUFSIZE)) {
311 //FIXME just pass skb up and allocate a new one 298 //FIXME just pass skb up and allocate a new one
312 warn("received packet too long"); 299 dev_warn(cs->dev, "received packet too long\n");
313 dev_kfree_skb_any(skb); 300 dev_kfree_skb_any(skb);
314 skb = NULL; 301 skb = NULL;
315 inputstate |= INS_skip_frame; 302 inputstate |= INS_skip_frame;
316 break; 303 break;
317 } 304 }
318 *gigaset_skb_put_quick(skb, 1) = gigaset_invtab[c]; 305 *__skb_put(skb, 1) = gigaset_invtab[c];
319 } 306 }
320 307
321 if (unlikely(!numbytes)) 308 if (unlikely(!numbytes))
@@ -343,7 +330,7 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
343 != NULL)) { 330 != NULL)) {
344 skb_reserve(skb, HW_HDR_LEN); 331 skb_reserve(skb, HW_HDR_LEN);
345 } else { 332 } else {
346 warn("could not allocate new skb"); 333 dev_warn(cs->dev, "could not allocate new skb\n");
347 inputstate |= INS_skip_frame; 334 inputstate |= INS_skip_frame;
348 } 335 }
349 } 336 }
@@ -364,13 +351,13 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
364 351
365 head = atomic_read(&inbuf->head); 352 head = atomic_read(&inbuf->head);
366 tail = atomic_read(&inbuf->tail); 353 tail = atomic_read(&inbuf->tail);
367 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); 354 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
368 355
369 if (head != tail) { 356 if (head != tail) {
370 cs = inbuf->cs; 357 cs = inbuf->cs;
371 src = inbuf->data + head; 358 src = inbuf->data + head;
372 numbytes = (head > tail ? RBUFSIZE : tail) - head; 359 numbytes = (head > tail ? RBUFSIZE : tail) - head;
373 dbg(DEBUG_INTR, "processing %u bytes", numbytes); 360 gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
374 361
375 while (numbytes) { 362 while (numbytes) {
376 if (atomic_read(&cs->mstate) == MS_LOCKED) { 363 if (atomic_read(&cs->mstate) == MS_LOCKED) {
@@ -392,8 +379,7 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
392 379
393 if (!(inbuf->inputstate & INS_DLE_char)) { 380 if (!(inbuf->inputstate & INS_DLE_char)) {
394 381
395 /* FIXME Einfach je nach Modus Funktionszeiger in cs setzen [hier+hdlc_loop]? */ 382 /* FIXME use function pointers? */
396 /* FIXME Spart folgendes "if" und ermoeglicht andere Protokolle */
397 if (inbuf->inputstate & INS_command) 383 if (inbuf->inputstate & INS_command)
398 procbytes = cmd_loop(c, src, numbytes, inbuf); 384 procbytes = cmd_loop(c, src, numbytes, inbuf);
399 else if (inbuf->bcs->proto2 == ISDN_PROTO_L2_HDLC) 385 else if (inbuf->bcs->proto2 == ISDN_PROTO_L2_HDLC)
@@ -403,13 +389,14 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
403 389
404 src += procbytes; 390 src += procbytes;
405 numbytes -= procbytes; 391 numbytes -= procbytes;
406 } else { /* DLE-char */ 392 } else { /* DLE char */
407 inbuf->inputstate &= ~INS_DLE_char; 393 inbuf->inputstate &= ~INS_DLE_char;
408 switch (c) { 394 switch (c) {
409 case 'X': /*begin of command*/ 395 case 'X': /*begin of command*/
410#ifdef CONFIG_GIGASET_DEBUG 396#ifdef CONFIG_GIGASET_DEBUG
411 if (inbuf->inputstate & INS_command) 397 if (inbuf->inputstate & INS_command)
412 err("received <DLE> 'X' in command mode"); 398 dev_err(cs->dev,
399 "received <DLE> 'X' in command mode\n");
413#endif 400#endif
414 inbuf->inputstate |= 401 inbuf->inputstate |=
415 INS_command | INS_DLE_command; 402 INS_command | INS_DLE_command;
@@ -417,7 +404,8 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
417 case '.': /*end of command*/ 404 case '.': /*end of command*/
418#ifdef CONFIG_GIGASET_DEBUG 405#ifdef CONFIG_GIGASET_DEBUG
419 if (!(inbuf->inputstate & INS_command)) 406 if (!(inbuf->inputstate & INS_command))
420 err("received <DLE> '.' in hdlc mode"); 407 dev_err(cs->dev,
408 "received <DLE> '.' in hdlc mode\n");
421#endif 409#endif
422 inbuf->inputstate &= cs->dle ? 410 inbuf->inputstate &= cs->dle ?
423 ~(INS_DLE_command|INS_command) 411 ~(INS_DLE_command|INS_command)
@@ -425,7 +413,9 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
425 break; 413 break;
426 //case DLE_FLAG: /*DLE_FLAG in data stream*/ /* schon oben behandelt! */ 414 //case DLE_FLAG: /*DLE_FLAG in data stream*/ /* schon oben behandelt! */
427 default: 415 default:
428 err("received 0x10 0x%02x!", (int) c); 416 dev_err(cs->dev,
417 "received 0x10 0x%02x!\n",
418 (int) c);
429 /* FIXME: reset driver?? */ 419 /* FIXME: reset driver?? */
430 } 420 }
431 } 421 }
@@ -444,7 +434,7 @@ nextbyte:
444 } 434 }
445 } 435 }
446 436
447 dbg(DEBUG_INTR, "setting head to %u", head); 437 gig_dbg(DEBUG_INTR, "setting head to %u", head);
448 atomic_set(&inbuf->head, head); 438 atomic_set(&inbuf->head, head);
449 } 439 }
450} 440}
@@ -479,14 +469,13 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
479 stuf_cnt++; 469 stuf_cnt++;
480 fcs = crc_ccitt_byte(fcs, *cp++); 470 fcs = crc_ccitt_byte(fcs, *cp++);
481 } 471 }
482 fcs ^= 0xffff; /* complement */ 472 fcs ^= 0xffff; /* complement */
483 473
484 /* size of new buffer: original size + number of stuffing bytes 474 /* size of new buffer: original size + number of stuffing bytes
485 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes 475 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes
486 */ 476 */
487 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head); 477 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head);
488 if (!hdlc_skb) { 478 if (!hdlc_skb) {
489 err("unable to allocate memory for HDLC encoding!");
490 dev_kfree_skb(skb); 479 dev_kfree_skb(skb);
491 return NULL; 480 return NULL;
492 } 481 }
@@ -508,7 +497,7 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
508 } 497 }
509 498
510 /* Finally add FCS (byte stuffed) and flag sequence */ 499 /* Finally add FCS (byte stuffed) and flag sequence */
511 c = (fcs & 0x00ff); /* least significant byte first */ 500 c = (fcs & 0x00ff); /* least significant byte first */
512 if (muststuff(c)) { 501 if (muststuff(c)) {
513 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE; 502 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE;
514 c ^= PPP_TRANS; 503 c ^= PPP_TRANS;
@@ -546,7 +535,6 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
546 /* worst case: every byte must be stuffed */ 535 /* worst case: every byte must be stuffed */
547 iraw_skb = dev_alloc_skb(2*skb->len + tail + head); 536 iraw_skb = dev_alloc_skb(2*skb->len + tail + head);
548 if (!iraw_skb) { 537 if (!iraw_skb) {
549 err("unable to allocate memory for HDLC encoding!");
550 dev_kfree_skb(skb); 538 dev_kfree_skb(skb);
551 return NULL; 539 return NULL;
552 } 540 }
@@ -577,21 +565,23 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
577 */ 565 */
578int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb) 566int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb)
579{ 567{
580 unsigned len; 568 unsigned len = skb->len;
581 569 unsigned long flags;
582 IFNULLRETVAL(bcs, -EFAULT);
583 IFNULLRETVAL(skb, -EFAULT);
584 len = skb->len;
585 570
586 if (bcs->proto2 == ISDN_PROTO_L2_HDLC) 571 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
587 skb = HDLC_Encode(skb, HW_HDR_LEN, 0); 572 skb = HDLC_Encode(skb, HW_HDR_LEN, 0);
588 else 573 else
589 skb = iraw_encode(skb, HW_HDR_LEN, 0); 574 skb = iraw_encode(skb, HW_HDR_LEN, 0);
590 if (!skb) 575 if (!skb) {
576 err("unable to allocate memory for encoding!\n");
591 return -ENOMEM; 577 return -ENOMEM;
578 }
592 579
593 skb_queue_tail(&bcs->squeue, skb); 580 skb_queue_tail(&bcs->squeue, skb);
594 tasklet_schedule(&bcs->cs->write_tasklet); 581 spin_lock_irqsave(&bcs->cs->lock, flags);
582 if (bcs->cs->connected)
583 tasklet_schedule(&bcs->cs->write_tasklet);
584 spin_unlock_irqrestore(&bcs->cs->lock, flags);
595 585
596 return len; /* ok so far */ 586 return len; /* ok so far */
597} 587}
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 31f0f07832bc..eb41aba3ddef 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -3,9 +3,7 @@
3 * 3 *
4 * Copyright (c) 2001 by Hansjoerg Lipp <hjlipp@web.de>, 4 * Copyright (c) 2001 by Hansjoerg Lipp <hjlipp@web.de>,
5 * Tilman Schmidt <tilman@imap.cc>, 5 * Tilman Schmidt <tilman@imap.cc>,
6 * Stefan Eilers <Eilers.Stefan@epost.de>. 6 * Stefan Eilers.
7 *
8 * Based on usb-gigaset.c.
9 * 7 *
10 * ===================================================================== 8 * =====================================================================
11 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
@@ -13,10 +11,6 @@
13 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
15 * ===================================================================== 13 * =====================================================================
16 * ToDo: ...
17 * =====================================================================
18 * Version: $Id: bas-gigaset.c,v 1.52.4.19 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
20 */ 14 */
21 15
22#include "gigaset.h" 16#include "gigaset.h"
@@ -30,7 +24,7 @@
30#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
31 25
32/* Version Information */ 26/* Version Information */
33#define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>" 27#define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
34#define DRIVER_DESC "USB Driver for Gigaset 307x" 28#define DRIVER_DESC "USB Driver for Gigaset 307x"
35 29
36 30
@@ -50,19 +44,20 @@ MODULE_PARM_DESC(cidmode, "Call-ID mode");
50#define GIGASET_DEVFSNAME "gig/bas/" 44#define GIGASET_DEVFSNAME "gig/bas/"
51#define GIGASET_DEVNAME "ttyGB" 45#define GIGASET_DEVNAME "ttyGB"
52 46
53#define IF_WRITEBUF 256 //FIXME 47/* length limit according to Siemens 3070usb-protokoll.doc ch. 2.1 */
48#define IF_WRITEBUF 264
54 49
55/* Values for the Gigaset 307x */ 50/* Values for the Gigaset 307x */
56#define USB_GIGA_VENDOR_ID 0x0681 51#define USB_GIGA_VENDOR_ID 0x0681
57#define USB_GIGA_PRODUCT_ID 0x0001 52#define USB_3070_PRODUCT_ID 0x0001
58#define USB_4175_PRODUCT_ID 0x0002 53#define USB_3075_PRODUCT_ID 0x0002
59#define USB_SX303_PRODUCT_ID 0x0021 54#define USB_SX303_PRODUCT_ID 0x0021
60#define USB_SX353_PRODUCT_ID 0x0022 55#define USB_SX353_PRODUCT_ID 0x0022
61 56
62/* table of devices that work with this driver */ 57/* table of devices that work with this driver */
63static struct usb_device_id gigaset_table [] = { 58static struct usb_device_id gigaset_table [] = {
64 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_GIGA_PRODUCT_ID) }, 59 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_3070_PRODUCT_ID) },
65 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_4175_PRODUCT_ID) }, 60 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_3075_PRODUCT_ID) },
66 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX303_PRODUCT_ID) }, 61 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX303_PRODUCT_ID) },
67 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX353_PRODUCT_ID) }, 62 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX353_PRODUCT_ID) },
68 { } /* Terminating entry */ 63 { } /* Terminating entry */
@@ -70,9 +65,6 @@ static struct usb_device_id gigaset_table [] = {
70 65
71MODULE_DEVICE_TABLE(usb, gigaset_table); 66MODULE_DEVICE_TABLE(usb, gigaset_table);
72 67
73/* Get a minor range for your devices from the usb maintainer */
74#define USB_SKEL_MINOR_BASE 200
75
76/*======================= local function prototypes =============================*/ 68/*======================= local function prototypes =============================*/
77 69
78/* This function is called if a new device is connected to the USB port. It 70/* This function is called if a new device is connected to the USB port. It
@@ -84,29 +76,33 @@ static int gigaset_probe(struct usb_interface *interface,
84/* Function will be called if the device is unplugged */ 76/* Function will be called if the device is unplugged */
85static void gigaset_disconnect(struct usb_interface *interface); 77static void gigaset_disconnect(struct usb_interface *interface);
86 78
79static void read_ctrl_callback(struct urb *, struct pt_regs *);
80static void stopurbs(struct bas_bc_state *);
81static int atwrite_submit(struct cardstate *, unsigned char *, int);
82static int start_cbsend(struct cardstate *);
87 83
88/*==============================================================================*/ 84/*==============================================================================*/
89 85
90struct bas_cardstate { 86struct bas_cardstate {
91 struct usb_device *udev; /* USB device pointer */ 87 struct usb_device *udev; /* USB device pointer */
92 struct usb_interface *interface; /* interface for this device */ 88 struct usb_interface *interface; /* interface for this device */
93 unsigned char minor; /* starting minor number */ 89 unsigned char minor; /* starting minor number */
94 90
95 struct urb *urb_ctrl; /* control pipe default URB */ 91 struct urb *urb_ctrl; /* control pipe default URB */
96 struct usb_ctrlrequest dr_ctrl; 92 struct usb_ctrlrequest dr_ctrl;
97 struct timer_list timer_ctrl; /* control request timeout */ 93 struct timer_list timer_ctrl; /* control request timeout */
98 94
99 struct timer_list timer_atrdy; /* AT command ready timeout */ 95 struct timer_list timer_atrdy; /* AT command ready timeout */
100 struct urb *urb_cmd_out; /* for sending AT commands */ 96 struct urb *urb_cmd_out; /* for sending AT commands */
101 struct usb_ctrlrequest dr_cmd_out; 97 struct usb_ctrlrequest dr_cmd_out;
102 int retry_cmd_out; 98 int retry_cmd_out;
103 99
104 struct urb *urb_cmd_in; /* for receiving AT replies */ 100 struct urb *urb_cmd_in; /* for receiving AT replies */
105 struct usb_ctrlrequest dr_cmd_in; 101 struct usb_ctrlrequest dr_cmd_in;
106 struct timer_list timer_cmd_in; /* receive request timeout */ 102 struct timer_list timer_cmd_in; /* receive request timeout */
107 unsigned char *rcvbuf; /* AT reply receive buffer */ 103 unsigned char *rcvbuf; /* AT reply receive buffer */
108 104
109 struct urb *urb_int_in; /* URB for interrupt pipe */ 105 struct urb *urb_int_in; /* URB for interrupt pipe */
110 unsigned char int_in_buf[3]; 106 unsigned char int_in_buf[3];
111 107
112 spinlock_t lock; /* locks all following */ 108 spinlock_t lock; /* locks all following */
@@ -118,12 +114,14 @@ struct bas_cardstate {
118}; 114};
119 115
120/* status of direct USB connection to 307x base (bits in basstate) */ 116/* status of direct USB connection to 307x base (bits in basstate) */
121#define BS_ATOPEN 0x001 117#define BS_ATOPEN 0x001 /* AT channel open */
122#define BS_B1OPEN 0x002 118#define BS_B1OPEN 0x002 /* B channel 1 open */
123#define BS_B2OPEN 0x004 119#define BS_B2OPEN 0x004 /* B channel 2 open */
124#define BS_ATREADY 0x008 120#define BS_ATREADY 0x008 /* base ready for AT command */
125#define BS_INIT 0x010 121#define BS_INIT 0x010 /* base has signalled INIT_OK */
126#define BS_ATTIMER 0x020 122#define BS_ATTIMER 0x020 /* waiting for HD_READY_SEND_ATDATA */
123#define BS_ATRDPEND 0x040 /* urb_cmd_in in use */
124#define BS_ATWRPEND 0x080 /* urb_cmd_out in use */
127 125
128 126
129static struct gigaset_driver *driver = NULL; 127static struct gigaset_driver *driver = NULL;
@@ -137,6 +135,47 @@ static struct usb_driver gigaset_usb_driver = {
137 .id_table = gigaset_table, 135 .id_table = gigaset_table,
138}; 136};
139 137
138/* get message text for usb_submit_urb return code
139 */
140static char *get_usb_rcmsg(int rc)
141{
142 static char unkmsg[28];
143
144 switch (rc) {
145 case 0:
146 return "success";
147 case -ENOMEM:
148 return "out of memory";
149 case -ENODEV:
150 return "device not present";
151 case -ENOENT:
152 return "endpoint not present";
153 case -ENXIO:
154 return "URB type not supported";
155 case -EINVAL:
156 return "invalid argument";
157 case -EAGAIN:
158 return "start frame too early or too much scheduled";
159 case -EFBIG:
160 return "too many isochronous frames requested";
161 case -EPIPE:
162 return "endpoint stalled";
163 case -EMSGSIZE:
164 return "invalid packet size";
165 case -ENOSPC:
166 return "would overcommit USB bandwidth";
167 case -ESHUTDOWN:
168 return "device shut down";
169 case -EPERM:
170 return "reject flag set";
171 case -EHOSTUNREACH:
172 return "device suspended";
173 default:
174 snprintf(unkmsg, sizeof(unkmsg), "unknown error %d", rc);
175 return unkmsg;
176 }
177}
178
140/* get message text for USB status code 179/* get message text for USB status code
141 */ 180 */
142static char *get_usb_statmsg(int status) 181static char *get_usb_statmsg(int status)
@@ -147,43 +186,37 @@ static char *get_usb_statmsg(int status)
147 case 0: 186 case 0:
148 return "success"; 187 return "success";
149 case -ENOENT: 188 case -ENOENT:
150 return "canceled"; 189 return "unlinked (sync)";
151 case -ECONNRESET:
152 return "canceled (async)";
153 case -EINPROGRESS: 190 case -EINPROGRESS:
154 return "pending"; 191 return "pending";
155 case -EPROTO: 192 case -EPROTO:
156 return "bit stuffing or unknown USB error"; 193 return "bit stuffing error, timeout, or unknown USB error";
157 case -EILSEQ: 194 case -EILSEQ:
158 return "Illegal byte sequence (CRC mismatch)"; 195 return "CRC mismatch, timeout, or unknown USB error";
159 case -EPIPE:
160 return "babble detect or endpoint stalled";
161 case -ENOSR:
162 return "buffer error";
163 case -ETIMEDOUT: 196 case -ETIMEDOUT:
164 return "timed out"; 197 return "timed out";
165 case -ENODEV: 198 case -EPIPE:
166 return "device not present"; 199 return "endpoint stalled";
200 case -ECOMM:
201 return "IN buffer overrun";
202 case -ENOSR:
203 return "OUT buffer underrun";
204 case -EOVERFLOW:
205 return "too much data";
167 case -EREMOTEIO: 206 case -EREMOTEIO:
168 return "short packet detected"; 207 return "short packet detected";
208 case -ENODEV:
209 return "device removed";
169 case -EXDEV: 210 case -EXDEV:
170 return "partial isochronous transfer"; 211 return "partial isochronous transfer";
171 case -EINVAL: 212 case -EINVAL:
172 return "invalid argument"; 213 return "invalid argument";
173 case -ENXIO: 214 case -ECONNRESET:
174 return "URB already queued"; 215 return "unlinked (async)";
175 case -EAGAIN:
176 return "isochronous start frame too early or too much scheduled";
177 case -EFBIG:
178 return "too many isochronous frames requested";
179 case -EMSGSIZE:
180 return "endpoint message size zero";
181 case -ESHUTDOWN: 216 case -ESHUTDOWN:
182 return "endpoint shutdown"; 217 return "device shut down";
183 case -EBUSY:
184 return "another request pending";
185 default: 218 default:
186 snprintf(unkmsg, sizeof(unkmsg), "unknown error %d", status); 219 snprintf(unkmsg, sizeof(unkmsg), "unknown status %d", status);
187 return unkmsg; 220 return unkmsg;
188 } 221 }
189} 222}
@@ -208,53 +241,54 @@ static inline char *usb_pipetype_str(int pipe)
208 * write content of URB to syslog for debugging 241 * write content of URB to syslog for debugging
209 */ 242 */
210static inline void dump_urb(enum debuglevel level, const char *tag, 243static inline void dump_urb(enum debuglevel level, const char *tag,
211 struct urb *urb) 244 struct urb *urb)
212{ 245{
213#ifdef CONFIG_GIGASET_DEBUG 246#ifdef CONFIG_GIGASET_DEBUG
214 int i; 247 int i;
215 IFNULLRET(tag); 248 gig_dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
216 dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
217 if (urb) { 249 if (urb) {
218 dbg(level, 250 gig_dbg(level,
219 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, " 251 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, "
220 "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,", 252 "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,",
221 (unsigned long) urb->dev, 253 (unsigned long) urb->dev,
222 usb_pipetype_str(urb->pipe), 254 usb_pipetype_str(urb->pipe),
223 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe), 255 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe),
224 usb_pipein(urb->pipe) ? "in" : "out", 256 usb_pipein(urb->pipe) ? "in" : "out",
225 urb->status, (unsigned long) urb->hcpriv, 257 urb->status, (unsigned long) urb->hcpriv,
226 urb->transfer_flags); 258 urb->transfer_flags);
227 dbg(level, 259 gig_dbg(level,
228 " transfer_buffer=0x%08lx[%d], actual_length=%d, " 260 " transfer_buffer=0x%08lx[%d], actual_length=%d, "
229 "bandwidth=%d, setup_packet=0x%08lx,", 261 "bandwidth=%d, setup_packet=0x%08lx,",
230 (unsigned long) urb->transfer_buffer, 262 (unsigned long) urb->transfer_buffer,
231 urb->transfer_buffer_length, urb->actual_length, 263 urb->transfer_buffer_length, urb->actual_length,
232 urb->bandwidth, (unsigned long) urb->setup_packet); 264 urb->bandwidth, (unsigned long) urb->setup_packet);
233 dbg(level, 265 gig_dbg(level,
234 " start_frame=%d, number_of_packets=%d, interval=%d, " 266 " start_frame=%d, number_of_packets=%d, interval=%d, "
235 "error_count=%d,", 267 "error_count=%d,",
236 urb->start_frame, urb->number_of_packets, urb->interval, 268 urb->start_frame, urb->number_of_packets, urb->interval,
237 urb->error_count); 269 urb->error_count);
238 dbg(level, 270 gig_dbg(level,
239 " context=0x%08lx, complete=0x%08lx, iso_frame_desc[]={", 271 " context=0x%08lx, complete=0x%08lx, "
240 (unsigned long) urb->context, 272 "iso_frame_desc[]={",
241 (unsigned long) urb->complete); 273 (unsigned long) urb->context,
274 (unsigned long) urb->complete);
242 for (i = 0; i < urb->number_of_packets; i++) { 275 for (i = 0; i < urb->number_of_packets; i++) {
243 struct usb_iso_packet_descriptor *pifd = &urb->iso_frame_desc[i]; 276 struct usb_iso_packet_descriptor *pifd
244 dbg(level, 277 = &urb->iso_frame_desc[i];
245 " {offset=%u, length=%u, actual_length=%u, " 278 gig_dbg(level,
246 "status=%u}", 279 " {offset=%u, length=%u, actual_length=%u, "
247 pifd->offset, pifd->length, pifd->actual_length, 280 "status=%u}",
248 pifd->status); 281 pifd->offset, pifd->length, pifd->actual_length,
282 pifd->status);
249 } 283 }
250 } 284 }
251 dbg(level, "}}"); 285 gig_dbg(level, "}}");
252#endif 286#endif
253} 287}
254 288
255/* read/set modem control bits etc. (m10x only) */ 289/* read/set modem control bits etc. (m10x only) */
256static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, 290static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
257 unsigned new_state) 291 unsigned new_state)
258{ 292{
259 return -EINVAL; 293 return -EINVAL;
260} 294}
@@ -280,43 +314,39 @@ static inline void error_hangup(struct bc_state *bcs)
280{ 314{
281 struct cardstate *cs = bcs->cs; 315 struct cardstate *cs = bcs->cs;
282 316
283 dbg(DEBUG_ANY, 317 gig_dbg(DEBUG_ANY, "%s: scheduling HUP for channel %d",
284 "%s: scheduling HUP for channel %d", __func__, bcs->channel); 318 __func__, bcs->channel);
285 319
286 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) { 320 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL))
287 //FIXME what should we do? 321 dev_err(cs->dev, "event queue full\n");
288 return;
289 }
290 322
291 gigaset_schedule_event(cs); 323 gigaset_schedule_event(cs);
292} 324}
293 325
294/* error_reset 326/* error_reset
295 * reset Gigaset device because of an unrecoverable error 327 * reset Gigaset device because of an unrecoverable error
296 * This function may be called from any context and takes care of scheduling 328 * This function may be called from any context, and should take care of
297 * the necessary actions for execution outside of interrupt context. 329 * scheduling the necessary actions for execution outside of interrupt context.
330 * Right now, it just generates a kernel message calling for help.
298 * argument: 331 * argument:
299 * controller state structure 332 * controller state structure
300 */ 333 */
301static inline void error_reset(struct cardstate *cs) 334static inline void error_reset(struct cardstate *cs)
302{ 335{
303 //FIXME try to recover without bothering the user 336 //FIXME try to recover without bothering the user
304 err("unrecoverable error - please disconnect the Gigaset base to reset"); 337 dev_err(cs->dev,
338 "unrecoverable error - please disconnect Gigaset base to reset\n");
305} 339}
306 340
307/* check_pending 341/* check_pending
308 * check for completion of pending control request 342 * check for completion of pending control request
309 * parameter: 343 * parameter:
310 * urb USB request block of completed request 344 * ucs hardware specific controller state structure
311 * urb->context = hardware specific controller state structure
312 */ 345 */
313static void check_pending(struct bas_cardstate *ucs) 346static void check_pending(struct bas_cardstate *ucs)
314{ 347{
315 unsigned long flags; 348 unsigned long flags;
316 349
317 IFNULLRET(ucs);
318 IFNULLRET(cardstate);
319
320 spin_lock_irqsave(&ucs->lock, flags); 350 spin_lock_irqsave(&ucs->lock, flags);
321 switch (ucs->pending) { 351 switch (ucs->pending) {
322 case 0: 352 case 0:
@@ -336,8 +366,6 @@ static void check_pending(struct bas_cardstate *ucs)
336 case HD_CLOSE_ATCHANNEL: 366 case HD_CLOSE_ATCHANNEL:
337 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) 367 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN))
338 ucs->pending = 0; 368 ucs->pending = 0;
339 //wake_up_interruptible(cs->initwait);
340 //FIXME need own wait queue?
341 break; 369 break;
342 case HD_CLOSE_B1CHANNEL: 370 case HD_CLOSE_B1CHANNEL:
343 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN)) 371 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN))
@@ -354,7 +382,9 @@ static void check_pending(struct bas_cardstate *ucs)
354 * are handled separately and should never end up here 382 * are handled separately and should never end up here
355 */ 383 */
356 default: 384 default:
357 warn("unknown pending request 0x%02x cleared", ucs->pending); 385 dev_warn(&ucs->interface->dev,
386 "unknown pending request 0x%02x cleared\n",
387 ucs->pending);
358 ucs->pending = 0; 388 ucs->pending = 0;
359 } 389 }
360 390
@@ -372,58 +402,53 @@ static void check_pending(struct bas_cardstate *ucs)
372static void cmd_in_timeout(unsigned long data) 402static void cmd_in_timeout(unsigned long data)
373{ 403{
374 struct cardstate *cs = (struct cardstate *) data; 404 struct cardstate *cs = (struct cardstate *) data;
375 struct bas_cardstate *ucs; 405 struct bas_cardstate *ucs = cs->hw.bas;
376 unsigned long flags;
377
378 IFNULLRET(cs);
379 ucs = cs->hw.bas;
380 IFNULLRET(ucs);
381 406
382 spin_lock_irqsave(&cs->lock, flags);
383 if (!atomic_read(&cs->connected)) {
384 dbg(DEBUG_USBREQ, "%s: disconnected", __func__);
385 spin_unlock_irqrestore(&cs->lock, flags);
386 return;
387 }
388 if (!ucs->rcvbuf_size) { 407 if (!ucs->rcvbuf_size) {
389 dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__); 408 gig_dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__);
390 spin_unlock_irqrestore(&cs->lock, flags);
391 return; 409 return;
392 } 410 }
393 spin_unlock_irqrestore(&cs->lock, flags);
394 411
395 err("timeout reading AT response"); 412 dev_err(cs->dev, "timeout reading AT response\n");
396 error_reset(cs); //FIXME retry? 413 error_reset(cs); //FIXME retry?
397} 414}
398 415
416/* set/clear bits in base connection state, return previous state
417 */
418inline static int update_basstate(struct bas_cardstate *ucs,
419 int set, int clear)
420{
421 unsigned long flags;
422 int state;
399 423
400static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs); 424 spin_lock_irqsave(&ucs->lock, flags);
425 state = atomic_read(&ucs->basstate);
426 atomic_set(&ucs->basstate, (state & ~clear) | set);
427 spin_unlock_irqrestore(&ucs->lock, flags);
428 return state;
429}
401 430
402/* atread_submit 431/* atread_submit
403 * submit an HD_READ_ATMESSAGE command URB 432 * submit an HD_READ_ATMESSAGE command URB and optionally start a timeout
404 * parameters: 433 * parameters:
405 * cs controller state structure 434 * cs controller state structure
406 * timeout timeout in 1/10 sec., 0: none 435 * timeout timeout in 1/10 sec., 0: none
407 * return value: 436 * return value:
408 * 0 on success 437 * 0 on success
409 * -EINVAL if a NULL pointer is encountered somewhere
410 * -EBUSY if another request is pending 438 * -EBUSY if another request is pending
411 * any URB submission error code 439 * any URB submission error code
412 */ 440 */
413static int atread_submit(struct cardstate *cs, int timeout) 441static int atread_submit(struct cardstate *cs, int timeout)
414{ 442{
415 struct bas_cardstate *ucs; 443 struct bas_cardstate *ucs = cs->hw.bas;
416 int ret; 444 int ret;
417 445
418 IFNULLRETVAL(cs, -EINVAL); 446 gig_dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)",
419 ucs = cs->hw.bas; 447 ucs->rcvbuf_size);
420 IFNULLRETVAL(ucs, -EINVAL);
421 IFNULLRETVAL(ucs->urb_cmd_in, -EINVAL);
422 448
423 dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)", ucs->rcvbuf_size); 449 if (update_basstate(ucs, BS_ATRDPEND, 0) & BS_ATRDPEND) {
424 450 dev_err(cs->dev,
425 if (ucs->urb_cmd_in->status == -EINPROGRESS) { 451 "could not submit HD_READ_ATMESSAGE: URB busy\n");
426 err("could not submit HD_READ_ATMESSAGE: URB busy");
427 return -EBUSY; 452 return -EBUSY;
428 } 453 }
429 454
@@ -433,19 +458,20 @@ static int atread_submit(struct cardstate *cs, int timeout)
433 ucs->dr_cmd_in.wIndex = 0; 458 ucs->dr_cmd_in.wIndex = 0;
434 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size); 459 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size);
435 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev, 460 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev,
436 usb_rcvctrlpipe(ucs->udev, 0), 461 usb_rcvctrlpipe(ucs->udev, 0),
437 (unsigned char*) & ucs->dr_cmd_in, 462 (unsigned char*) & ucs->dr_cmd_in,
438 ucs->rcvbuf, ucs->rcvbuf_size, 463 ucs->rcvbuf, ucs->rcvbuf_size,
439 read_ctrl_callback, cs->inbuf); 464 read_ctrl_callback, cs->inbuf);
440 465
441 if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) { 466 if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) {
442 err("could not submit HD_READ_ATMESSAGE: %s", 467 update_basstate(ucs, 0, BS_ATRDPEND);
443 get_usb_statmsg(ret)); 468 dev_err(cs->dev, "could not submit HD_READ_ATMESSAGE: %s\n",
469 get_usb_statmsg(ret));
444 return ret; 470 return ret;
445 } 471 }
446 472
447 if (timeout > 0) { 473 if (timeout > 0) {
448 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 474 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
449 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10; 475 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10;
450 ucs->timer_cmd_in.data = (unsigned long) cs; 476 ucs->timer_cmd_in.data = (unsigned long) cs;
451 ucs->timer_cmd_in.function = cmd_in_timeout; 477 ucs->timer_cmd_in.function = cmd_in_timeout;
@@ -454,26 +480,6 @@ static int atread_submit(struct cardstate *cs, int timeout)
454 return 0; 480 return 0;
455} 481}
456 482
457static void stopurbs(struct bas_bc_state *);
458static int start_cbsend(struct cardstate *);
459
460/* set/clear bits in base connection state
461 */
462inline static void update_basstate(struct bas_cardstate *ucs,
463 int set, int clear)
464{
465 unsigned long flags;
466 int state;
467
468 spin_lock_irqsave(&ucs->lock, flags);
469 state = atomic_read(&ucs->basstate);
470 state &= ~clear;
471 state |= set;
472 atomic_set(&ucs->basstate, state);
473 spin_unlock_irqrestore(&ucs->lock, flags);
474}
475
476
477/* read_int_callback 483/* read_int_callback
478 * USB completion handler for interrupt pipe input 484 * USB completion handler for interrupt pipe input
479 * called by the USB subsystem in interrupt context 485 * called by the USB subsystem in interrupt context
@@ -483,48 +489,49 @@ inline static void update_basstate(struct bas_cardstate *ucs,
483 */ 489 */
484static void read_int_callback(struct urb *urb, struct pt_regs *regs) 490static void read_int_callback(struct urb *urb, struct pt_regs *regs)
485{ 491{
486 struct cardstate *cs; 492 struct cardstate *cs = urb->context;
487 struct bas_cardstate *ucs; 493 struct bas_cardstate *ucs = cs->hw.bas;
488 struct bc_state *bcs; 494 struct bc_state *bcs;
489 unsigned long flags; 495 unsigned long flags;
490 int status; 496 int rc;
491 unsigned l; 497 unsigned l;
492 int channel; 498 int channel;
493 499
494 IFNULLRET(urb);
495 cs = (struct cardstate *) urb->context;
496 IFNULLRET(cs);
497 ucs = cs->hw.bas;
498 IFNULLRET(ucs);
499
500 if (unlikely(!atomic_read(&cs->connected))) {
501 warn("%s: disconnected", __func__);
502 return;
503 }
504
505 switch (urb->status) { 500 switch (urb->status) {
506 case 0: /* success */ 501 case 0: /* success */
507 break; 502 break;
508 case -ENOENT: /* canceled */ 503 case -ENOENT: /* cancelled */
509 case -ECONNRESET: /* canceled (async) */ 504 case -ECONNRESET: /* cancelled (async) */
510 case -EINPROGRESS: /* pending */ 505 case -EINPROGRESS: /* pending */
511 /* ignore silently */ 506 /* ignore silently */
512 dbg(DEBUG_USBREQ, 507 gig_dbg(DEBUG_USBREQ, "%s: %s",
513 "%s: %s", __func__, get_usb_statmsg(urb->status)); 508 __func__, get_usb_statmsg(urb->status));
509 return;
510 case -ENODEV: /* device removed */
511 case -ESHUTDOWN: /* device shut down */
512 //FIXME use this as disconnect indicator?
513 gig_dbg(DEBUG_USBREQ, "%s: device disconnected", __func__);
514 return; 514 return;
515 default: /* severe trouble */ 515 default: /* severe trouble */
516 warn("interrupt read: %s", get_usb_statmsg(urb->status)); 516 dev_warn(cs->dev, "interrupt read: %s\n",
517 get_usb_statmsg(urb->status));
517 //FIXME corrective action? resubmission always ok? 518 //FIXME corrective action? resubmission always ok?
518 goto resubmit; 519 goto resubmit;
519 } 520 }
520 521
522 /* drop incomplete packets even if the missing bytes wouldn't matter */
523 if (unlikely(urb->actual_length < 3)) {
524 dev_warn(cs->dev, "incomplete interrupt packet (%d bytes)\n",
525 urb->actual_length);
526 goto resubmit;
527 }
528
521 l = (unsigned) ucs->int_in_buf[1] + 529 l = (unsigned) ucs->int_in_buf[1] +
522 (((unsigned) ucs->int_in_buf[2]) << 8); 530 (((unsigned) ucs->int_in_buf[2]) << 8);
523 531
524 dbg(DEBUG_USBREQ, 532 gig_dbg(DEBUG_USBREQ, "<-------%d: 0x%02x (%u [0x%02x 0x%02x])",
525 "<-------%d: 0x%02x (%u [0x%02x 0x%02x])", urb->actual_length, 533 urb->actual_length, (int)ucs->int_in_buf[0], l,
526 (int)ucs->int_in_buf[0], l, 534 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
527 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
528 535
529 channel = 0; 536 channel = 0;
530 537
@@ -570,62 +577,68 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
570 case HD_B1_FLOW_CONTROL: 577 case HD_B1_FLOW_CONTROL:
571 bcs = cs->bcs + channel; 578 bcs = cs->bcs + channel;
572 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES, 579 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES,
573 &bcs->hw.bas->corrbytes); 580 &bcs->hw.bas->corrbytes);
574 dbg(DEBUG_ISO, 581 gig_dbg(DEBUG_ISO,
575 "Flow control (channel %d, sub %d): 0x%02x => %d", 582 "Flow control (channel %d, sub %d): 0x%02x => %d",
576 channel, bcs->hw.bas->numsub, l, 583 channel, bcs->hw.bas->numsub, l,
577 atomic_read(&bcs->hw.bas->corrbytes)); 584 atomic_read(&bcs->hw.bas->corrbytes));
578 break; 585 break;
579 586
580 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */ 587 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */
581 if (!l) { 588 if (!l) {
582 warn("HD_RECEIVEATDATA_ACK with length 0 ignored"); 589 dev_warn(cs->dev,
590 "HD_RECEIVEATDATA_ACK with length 0 ignored\n");
583 break; 591 break;
584 } 592 }
585 spin_lock_irqsave(&cs->lock, flags); 593 spin_lock_irqsave(&cs->lock, flags);
586 if (ucs->rcvbuf_size) { 594 if (ucs->rcvbuf_size) {
587 spin_unlock_irqrestore(&cs->lock, flags); 595 /* throw away previous buffer - we have no queue */
588 err("receive AT data overrun, %d bytes lost", l); 596 dev_err(cs->dev,
589 error_reset(cs); //FIXME reschedule 597 "receive AT data overrun, %d bytes lost\n",
590 break; 598 ucs->rcvbuf_size);
599 kfree(ucs->rcvbuf);
600 ucs->rcvbuf_size = 0;
591 } 601 }
592 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) { 602 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) {
593 spin_unlock_irqrestore(&cs->lock, flags); 603 spin_unlock_irqrestore(&cs->lock, flags);
594 err("%s: out of memory, %d bytes lost", __func__, l); 604 dev_err(cs->dev, "out of memory receiving AT data\n");
595 error_reset(cs); //FIXME reschedule 605 error_reset(cs);
596 break; 606 break;
597 } 607 }
598 ucs->rcvbuf_size = l; 608 ucs->rcvbuf_size = l;
599 ucs->retry_cmd_in = 0; 609 ucs->retry_cmd_in = 0;
600 if ((status = atread_submit(cs, BAS_TIMEOUT)) < 0) { 610 if ((rc = atread_submit(cs, BAS_TIMEOUT)) < 0) {
601 kfree(ucs->rcvbuf); 611 kfree(ucs->rcvbuf);
602 ucs->rcvbuf = NULL; 612 ucs->rcvbuf = NULL;
603 ucs->rcvbuf_size = 0; 613 ucs->rcvbuf_size = 0;
604 error_reset(cs); //FIXME reschedule 614 if (rc != -ENODEV)
615 //FIXME corrective action?
616 error_reset(cs);
605 } 617 }
606 spin_unlock_irqrestore(&cs->lock, flags); 618 spin_unlock_irqrestore(&cs->lock, flags);
607 break; 619 break;
608 620
609 case HD_RESET_INTERRUPT_PIPE_ACK: 621 case HD_RESET_INTERRUPT_PIPE_ACK:
610 dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK"); 622 gig_dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK");
611 break; 623 break;
612 624
613 case HD_SUSPEND_END: 625 case HD_SUSPEND_END:
614 dbg(DEBUG_USBREQ, "HD_SUSPEND_END"); 626 gig_dbg(DEBUG_USBREQ, "HD_SUSPEND_END");
615 break; 627 break;
616 628
617 default: 629 default:
618 warn("unknown Gigaset signal 0x%02x (%u) ignored", 630 dev_warn(cs->dev,
619 (int) ucs->int_in_buf[0], l); 631 "unknown Gigaset signal 0x%02x (%u) ignored\n",
632 (int) ucs->int_in_buf[0], l);
620 } 633 }
621 634
622 check_pending(ucs); 635 check_pending(ucs);
623 636
624resubmit: 637resubmit:
625 status = usb_submit_urb(urb, SLAB_ATOMIC); 638 rc = usb_submit_urb(urb, SLAB_ATOMIC);
626 if (unlikely(status)) { 639 if (unlikely(rc != 0 && rc != -ENODEV)) {
627 err("could not resubmit interrupt URB: %s", 640 dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
628 get_usb_statmsg(status)); 641 get_usb_rcmsg(rc));
629 error_reset(cs); 642 error_reset(cs);
630 } 643 }
631} 644}
@@ -639,31 +652,17 @@ resubmit:
639 */ 652 */
640static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs) 653static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
641{ 654{
642 struct cardstate *cs; 655 struct inbuf_t *inbuf = urb->context;
643 struct bas_cardstate *ucs; 656 struct cardstate *cs = inbuf->cs;
644 unsigned numbytes; 657 struct bas_cardstate *ucs = cs->hw.bas;
645 unsigned long flags;
646 struct inbuf_t *inbuf;
647 int have_data = 0; 658 int have_data = 0;
659 unsigned numbytes;
660 int rc;
648 661
649 IFNULLRET(urb); 662 update_basstate(ucs, 0, BS_ATRDPEND);
650 inbuf = (struct inbuf_t *) urb->context;
651 IFNULLRET(inbuf);
652 cs = inbuf->cs;
653 IFNULLRET(cs);
654 ucs = cs->hw.bas;
655 IFNULLRET(ucs);
656
657 spin_lock_irqsave(&cs->lock, flags);
658 if (!atomic_read(&cs->connected)) {
659 warn("%s: disconnected", __func__);
660 spin_unlock_irqrestore(&cs->lock, flags);
661 return;
662 }
663 663
664 if (!ucs->rcvbuf_size) { 664 if (!ucs->rcvbuf_size) {
665 warn("%s: no receive in progress", __func__); 665 dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
666 spin_unlock_irqrestore(&cs->lock, flags);
667 return; 666 return;
668 } 667 }
669 668
@@ -673,12 +672,14 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
673 case 0: /* normal completion */ 672 case 0: /* normal completion */
674 numbytes = urb->actual_length; 673 numbytes = urb->actual_length;
675 if (unlikely(numbytes == 0)) { 674 if (unlikely(numbytes == 0)) {
676 warn("control read: empty block received"); 675 dev_warn(cs->dev,
676 "control read: empty block received\n");
677 goto retry; 677 goto retry;
678 } 678 }
679 if (unlikely(numbytes != ucs->rcvbuf_size)) { 679 if (unlikely(numbytes != ucs->rcvbuf_size)) {
680 warn("control read: received %d chars, expected %d", 680 dev_warn(cs->dev,
681 numbytes, ucs->rcvbuf_size); 681 "control read: received %d chars, expected %d\n",
682 numbytes, ucs->rcvbuf_size);
682 if (numbytes > ucs->rcvbuf_size) 683 if (numbytes > ucs->rcvbuf_size)
683 numbytes = ucs->rcvbuf_size; 684 numbytes = ucs->rcvbuf_size;
684 } 685 }
@@ -694,27 +695,32 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
694 } 695 }
695 break; 696 break;
696 697
697 case -ENOENT: /* canceled */ 698 case -ENOENT: /* cancelled */
698 case -ECONNRESET: /* canceled (async) */ 699 case -ECONNRESET: /* cancelled (async) */
699 case -EINPROGRESS: /* pending */ 700 case -EINPROGRESS: /* pending */
701 case -ENODEV: /* device removed */
702 case -ESHUTDOWN: /* device shut down */
700 /* no action necessary */ 703 /* no action necessary */
701 dbg(DEBUG_USBREQ, 704 gig_dbg(DEBUG_USBREQ, "%s: %s",
702 "%s: %s", __func__, get_usb_statmsg(urb->status)); 705 __func__, get_usb_statmsg(urb->status));
703 break; 706 break;
704 707
705 default: /* severe trouble */ 708 default: /* severe trouble */
706 warn("control read: %s", get_usb_statmsg(urb->status)); 709 dev_warn(cs->dev, "control read: %s\n",
710 get_usb_statmsg(urb->status));
707 retry: 711 retry:
708 if (ucs->retry_cmd_in++ < BAS_RETRY) { 712 if (ucs->retry_cmd_in++ < BAS_RETRY) {
709 notice("control read: retry %d", ucs->retry_cmd_in); 713 dev_notice(cs->dev, "control read: retry %d\n",
710 if (atread_submit(cs, BAS_TIMEOUT) >= 0) { 714 ucs->retry_cmd_in);
711 /* resubmitted - bypass regular exit block */ 715 rc = atread_submit(cs, BAS_TIMEOUT);
712 spin_unlock_irqrestore(&cs->lock, flags); 716 if (rc >= 0 || rc == -ENODEV)
717 /* resubmitted or disconnected */
718 /* - bypass regular exit block */
713 return; 719 return;
714 }
715 } else { 720 } else {
716 err("control read: giving up after %d tries", 721 dev_err(cs->dev,
717 ucs->retry_cmd_in); 722 "control read: giving up after %d tries\n",
723 ucs->retry_cmd_in);
718 } 724 }
719 error_reset(cs); 725 error_reset(cs);
720 } 726 }
@@ -722,9 +728,8 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
722 kfree(ucs->rcvbuf); 728 kfree(ucs->rcvbuf);
723 ucs->rcvbuf = NULL; 729 ucs->rcvbuf = NULL;
724 ucs->rcvbuf_size = 0; 730 ucs->rcvbuf_size = 0;
725 spin_unlock_irqrestore(&cs->lock, flags);
726 if (have_data) { 731 if (have_data) {
727 dbg(DEBUG_INTR, "%s-->BH", __func__); 732 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
728 gigaset_schedule_event(cs); 733 gigaset_schedule_event(cs);
729 } 734 }
730} 735}
@@ -743,21 +748,19 @@ static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
743 unsigned long flags; 748 unsigned long flags;
744 int i, rc; 749 int i, rc;
745 750
746 IFNULLRET(urb);
747 IFNULLRET(urb->context);
748 IFNULLRET(cardstate);
749
750 /* status codes not worth bothering the tasklet with */ 751 /* status codes not worth bothering the tasklet with */
751 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 752 if (unlikely(urb->status == -ENOENT ||
752 urb->status == -EINPROGRESS)) { 753 urb->status == -ECONNRESET ||
753 dbg(DEBUG_ISO, 754 urb->status == -EINPROGRESS ||
754 "%s: %s", __func__, get_usb_statmsg(urb->status)); 755 urb->status == -ENODEV ||
756 urb->status == -ESHUTDOWN)) {
757 gig_dbg(DEBUG_ISO, "%s: %s",
758 __func__, get_usb_statmsg(urb->status));
755 return; 759 return;
756 } 760 }
757 761
758 bcs = (struct bc_state *) urb->context; 762 bcs = urb->context;
759 ubc = bcs->hw.bas; 763 ubc = bcs->hw.bas;
760 IFNULLRET(ubc);
761 764
762 spin_lock_irqsave(&ubc->isoinlock, flags); 765 spin_lock_irqsave(&ubc->isoinlock, flags);
763 if (likely(ubc->isoindone == NULL)) { 766 if (likely(ubc->isoindone == NULL)) {
@@ -770,21 +773,24 @@ static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
770 for (i = 0; i < BAS_NUMFRAMES; i++) { 773 for (i = 0; i < BAS_NUMFRAMES; i++) {
771 ubc->isoinlost += urb->iso_frame_desc[i].actual_length; 774 ubc->isoinlost += urb->iso_frame_desc[i].actual_length;
772 if (unlikely(urb->iso_frame_desc[i].status != 0 && 775 if (unlikely(urb->iso_frame_desc[i].status != 0 &&
773 urb->iso_frame_desc[i].status != -EINPROGRESS)) { 776 urb->iso_frame_desc[i].status !=
777 -EINPROGRESS))
774 ubc->loststatus = urb->iso_frame_desc[i].status; 778 ubc->loststatus = urb->iso_frame_desc[i].status;
775 }
776 urb->iso_frame_desc[i].status = 0; 779 urb->iso_frame_desc[i].status = 0;
777 urb->iso_frame_desc[i].actual_length = 0; 780 urb->iso_frame_desc[i].actual_length = 0;
778 } 781 }
779 if (likely(atomic_read(&ubc->running))) { 782 if (likely(atomic_read(&ubc->running))) {
780 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */ 783 /* urb->dev is clobbered by USB subsystem */
784 urb->dev = bcs->cs->hw.bas->udev;
781 urb->transfer_flags = URB_ISO_ASAP; 785 urb->transfer_flags = URB_ISO_ASAP;
782 urb->number_of_packets = BAS_NUMFRAMES; 786 urb->number_of_packets = BAS_NUMFRAMES;
783 dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit", __func__); 787 gig_dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit",
788 __func__);
784 rc = usb_submit_urb(urb, SLAB_ATOMIC); 789 rc = usb_submit_urb(urb, SLAB_ATOMIC);
785 if (unlikely(rc != 0)) { 790 if (unlikely(rc != 0 && rc != -ENODEV)) {
786 err("could not resubmit isochronous read URB: %s", 791 dev_err(bcs->cs->dev,
787 get_usb_statmsg(rc)); 792 "could not resubmit isochronous read "
793 "URB: %s\n", get_usb_rcmsg(rc));
788 dump_urb(DEBUG_ISO, "isoc read", urb); 794 dump_urb(DEBUG_ISO, "isoc read", urb);
789 error_hangup(bcs); 795 error_hangup(bcs);
790 } 796 }
@@ -806,23 +812,20 @@ static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
806 struct bas_bc_state *ubc; 812 struct bas_bc_state *ubc;
807 unsigned long flags; 813 unsigned long flags;
808 814
809 IFNULLRET(urb);
810 IFNULLRET(urb->context);
811 IFNULLRET(cardstate);
812
813 /* status codes not worth bothering the tasklet with */ 815 /* status codes not worth bothering the tasklet with */
814 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 816 if (unlikely(urb->status == -ENOENT ||
815 urb->status == -EINPROGRESS)) { 817 urb->status == -ECONNRESET ||
816 dbg(DEBUG_ISO, 818 urb->status == -EINPROGRESS ||
817 "%s: %s", __func__, get_usb_statmsg(urb->status)); 819 urb->status == -ENODEV ||
820 urb->status == -ESHUTDOWN)) {
821 gig_dbg(DEBUG_ISO, "%s: %s",
822 __func__, get_usb_statmsg(urb->status));
818 return; 823 return;
819 } 824 }
820 825
821 /* pass URB context to tasklet */ 826 /* pass URB context to tasklet */
822 ucx = (struct isow_urbctx_t *) urb->context; 827 ucx = urb->context;
823 IFNULLRET(ucx->bcs);
824 ubc = ucx->bcs->hw.bas; 828 ubc = ucx->bcs->hw.bas;
825 IFNULLRET(ubc);
826 829
827 spin_lock_irqsave(&ubc->isooutlock, flags); 830 spin_lock_irqsave(&ubc->isooutlock, flags);
828 ubc->isooutovfl = ubc->isooutdone; 831 ubc->isooutovfl = ubc->isooutdone;
@@ -841,15 +844,11 @@ static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
841 */ 844 */
842static int starturbs(struct bc_state *bcs) 845static int starturbs(struct bc_state *bcs)
843{ 846{
847 struct bas_bc_state *ubc = bcs->hw.bas;
844 struct urb *urb; 848 struct urb *urb;
845 struct bas_bc_state *ubc;
846 int j, k; 849 int j, k;
847 int rc; 850 int rc;
848 851
849 IFNULLRETVAL(bcs, -EFAULT);
850 ubc = bcs->hw.bas;
851 IFNULLRETVAL(ubc, -EFAULT);
852
853 /* initialize L2 reception */ 852 /* initialize L2 reception */
854 if (bcs->proto2 == ISDN_PROTO_L2_HDLC) 853 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
855 bcs->inputstate |= INS_flag_hunt; 854 bcs->inputstate |= INS_flag_hunt;
@@ -859,7 +858,6 @@ static int starturbs(struct bc_state *bcs)
859 for (k = 0; k < BAS_INURBS; k++) { 858 for (k = 0; k < BAS_INURBS; k++) {
860 urb = ubc->isoinurbs[k]; 859 urb = ubc->isoinurbs[k];
861 if (!urb) { 860 if (!urb) {
862 err("isoinurbs[%d]==NULL", k);
863 rc = -EFAULT; 861 rc = -EFAULT;
864 goto error; 862 goto error;
865 } 863 }
@@ -881,11 +879,8 @@ static int starturbs(struct bc_state *bcs)
881 } 879 }
882 880
883 dump_urb(DEBUG_ISO, "Initial isoc read", urb); 881 dump_urb(DEBUG_ISO, "Initial isoc read", urb);
884 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 882 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0)
885 err("could not submit isochronous read URB %d: %s",
886 k, get_usb_statmsg(rc));
887 goto error; 883 goto error;
888 }
889 } 884 }
890 885
891 /* initialize L2 transmission */ 886 /* initialize L2 transmission */
@@ -895,7 +890,6 @@ static int starturbs(struct bc_state *bcs)
895 for (k = 0; k < BAS_OUTURBS; ++k) { 890 for (k = 0; k < BAS_OUTURBS; ++k) {
896 urb = ubc->isoouturbs[k].urb; 891 urb = ubc->isoouturbs[k].urb;
897 if (!urb) { 892 if (!urb) {
898 err("isoouturbs[%d].urb==NULL", k);
899 rc = -EFAULT; 893 rc = -EFAULT;
900 goto error; 894 goto error;
901 } 895 }
@@ -921,11 +915,8 @@ static int starturbs(struct bc_state *bcs)
921 for (k = 0; k < 2; ++k) { 915 for (k = 0; k < 2; ++k) {
922 dump_urb(DEBUG_ISO, "Initial isoc write", urb); 916 dump_urb(DEBUG_ISO, "Initial isoc write", urb);
923 rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC); 917 rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC);
924 if (rc != 0) { 918 if (rc != 0)
925 err("could not submit isochronous write URB %d: %s",
926 k, get_usb_statmsg(rc));
927 goto error; 919 goto error;
928 }
929 } 920 }
930 dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb); 921 dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb);
931 ubc->isooutfree = &ubc->isoouturbs[2]; 922 ubc->isooutfree = &ubc->isoouturbs[2];
@@ -946,20 +937,20 @@ static void stopurbs(struct bas_bc_state *ubc)
946{ 937{
947 int k, rc; 938 int k, rc;
948 939
949 IFNULLRET(ubc);
950
951 atomic_set(&ubc->running, 0); 940 atomic_set(&ubc->running, 0);
952 941
953 for (k = 0; k < BAS_INURBS; ++k) { 942 for (k = 0; k < BAS_INURBS; ++k) {
954 rc = usb_unlink_urb(ubc->isoinurbs[k]); 943 rc = usb_unlink_urb(ubc->isoinurbs[k]);
955 dbg(DEBUG_ISO, "%s: isoc input URB %d unlinked, result = %d", 944 gig_dbg(DEBUG_ISO,
956 __func__, k, rc); 945 "%s: isoc input URB %d unlinked, result = %s",
946 __func__, k, get_usb_rcmsg(rc));
957 } 947 }
958 948
959 for (k = 0; k < BAS_OUTURBS; ++k) { 949 for (k = 0; k < BAS_OUTURBS; ++k) {
960 rc = usb_unlink_urb(ubc->isoouturbs[k].urb); 950 rc = usb_unlink_urb(ubc->isoouturbs[k].urb);
961 dbg(DEBUG_ISO, "%s: isoc output URB %d unlinked, result = %d", 951 gig_dbg(DEBUG_ISO,
962 __func__, k, rc); 952 "%s: isoc output URB %d unlinked, result = %s",
953 __func__, k, get_usb_rcmsg(rc));
963 } 954 }
964} 955}
965 956
@@ -969,7 +960,7 @@ static void stopurbs(struct bas_bc_state *ubc)
969/* submit_iso_write_urb 960/* submit_iso_write_urb
970 * fill and submit the next isochronous write URB 961 * fill and submit the next isochronous write URB
971 * parameters: 962 * parameters:
972 * bcs B channel state structure 963 * ucx context structure containing URB
973 * return value: 964 * return value:
974 * number of frames submitted in URB 965 * number of frames submitted in URB
975 * 0 if URB not submitted because no data available (isooutbuf busy) 966 * 0 if URB not submitted because no data available (isooutbuf busy)
@@ -977,19 +968,13 @@ static void stopurbs(struct bas_bc_state *ubc)
977 */ 968 */
978static int submit_iso_write_urb(struct isow_urbctx_t *ucx) 969static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
979{ 970{
980 struct urb *urb; 971 struct urb *urb = ucx->urb;
981 struct bas_bc_state *ubc; 972 struct bas_bc_state *ubc = ucx->bcs->hw.bas;
982 struct usb_iso_packet_descriptor *ifd; 973 struct usb_iso_packet_descriptor *ifd;
983 int corrbytes, nframe, rc; 974 int corrbytes, nframe, rc;
984 975
985 IFNULLRETVAL(ucx, -EFAULT); 976 /* urb->dev is clobbered by USB subsystem */
986 urb = ucx->urb; 977 urb->dev = ucx->bcs->cs->hw.bas->udev;
987 IFNULLRETVAL(urb, -EFAULT);
988 IFNULLRETVAL(ucx->bcs, -EFAULT);
989 ubc = ucx->bcs->hw.bas;
990 IFNULLRETVAL(ubc, -EFAULT);
991
992 urb->dev = ucx->bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */
993 urb->transfer_flags = URB_ISO_ASAP; 978 urb->transfer_flags = URB_ISO_ASAP;
994 urb->transfer_buffer = ubc->isooutbuf->data; 979 urb->transfer_buffer = ubc->isooutbuf->data;
995 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data); 980 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
@@ -1000,7 +985,8 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1000 /* compute frame length according to flow control */ 985 /* compute frame length according to flow control */
1001 ifd->length = BAS_NORMFRAME; 986 ifd->length = BAS_NORMFRAME;
1002 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) { 987 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) {
1003 dbg(DEBUG_ISO, "%s: corrbytes=%d", __func__, corrbytes); 988 gig_dbg(DEBUG_ISO, "%s: corrbytes=%d",
989 __func__, corrbytes);
1004 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME) 990 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME)
1005 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME; 991 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME;
1006 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME) 992 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME)
@@ -1008,18 +994,21 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1008 ifd->length += corrbytes; 994 ifd->length += corrbytes;
1009 atomic_add(-corrbytes, &ubc->corrbytes); 995 atomic_add(-corrbytes, &ubc->corrbytes);
1010 } 996 }
1011 //dbg(DEBUG_ISO, "%s: frame %d length=%d", __func__, nframe, ifd->length);
1012 997
1013 /* retrieve block of data to send */ 998 /* retrieve block of data to send */
1014 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf, ifd->length); 999 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf,
1000 ifd->length);
1015 if (ifd->offset < 0) { 1001 if (ifd->offset < 0) {
1016 if (ifd->offset == -EBUSY) { 1002 if (ifd->offset == -EBUSY) {
1017 dbg(DEBUG_ISO, "%s: buffer busy at frame %d", 1003 gig_dbg(DEBUG_ISO,
1018 __func__, nframe); 1004 "%s: buffer busy at frame %d",
1019 /* tasklet will be restarted from gigaset_send_skb() */ 1005 __func__, nframe);
1006 /* tasklet will be restarted from
1007 gigaset_send_skb() */
1020 } else { 1008 } else {
1021 err("%s: buffer error %d at frame %d", 1009 dev_err(ucx->bcs->cs->dev,
1022 __func__, ifd->offset, nframe); 1010 "%s: buffer error %d at frame %d\n",
1011 __func__, ifd->offset, nframe);
1023 return ifd->offset; 1012 return ifd->offset;
1024 } 1013 }
1025 break; 1014 break;
@@ -1028,15 +1017,22 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1028 ifd->status = 0; 1017 ifd->status = 0;
1029 ifd->actual_length = 0; 1018 ifd->actual_length = 0;
1030 } 1019 }
1031 if ((urb->number_of_packets = nframe) > 0) { 1020 if (unlikely(nframe == 0))
1032 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 1021 return 0; /* no data to send */
1033 err("could not submit isochronous write URB: %s", 1022 urb->number_of_packets = nframe;
1034 get_usb_statmsg(rc)); 1023
1035 dump_urb(DEBUG_ISO, "isoc write", urb); 1024 rc = usb_submit_urb(urb, SLAB_ATOMIC);
1036 return rc; 1025 if (unlikely(rc)) {
1037 } 1026 if (rc == -ENODEV)
1038 ++ubc->numsub; 1027 /* device removed - give up silently */
1028 gig_dbg(DEBUG_ISO, "%s: disconnected", __func__);
1029 else
1030 dev_err(ucx->bcs->cs->dev,
1031 "could not submit isochronous write URB: %s\n",
1032 get_usb_rcmsg(rc));
1033 return rc;
1039 } 1034 }
1035 ++ubc->numsub;
1040 return nframe; 1036 return nframe;
1041} 1037}
1042 1038
@@ -1048,9 +1044,9 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1048 */ 1044 */
1049static void write_iso_tasklet(unsigned long data) 1045static void write_iso_tasklet(unsigned long data)
1050{ 1046{
1051 struct bc_state *bcs; 1047 struct bc_state *bcs = (struct bc_state *) data;
1052 struct bas_bc_state *ubc; 1048 struct bas_bc_state *ubc = bcs->hw.bas;
1053 struct cardstate *cs; 1049 struct cardstate *cs = bcs->cs;
1054 struct isow_urbctx_t *done, *next, *ovfl; 1050 struct isow_urbctx_t *done, *next, *ovfl;
1055 struct urb *urb; 1051 struct urb *urb;
1056 struct usb_iso_packet_descriptor *ifd; 1052 struct usb_iso_packet_descriptor *ifd;
@@ -1059,23 +1055,12 @@ static void write_iso_tasklet(unsigned long data)
1059 int i; 1055 int i;
1060 struct sk_buff *skb; 1056 struct sk_buff *skb;
1061 int len; 1057 int len;
1062 1058 int rc;
1063 bcs = (struct bc_state *) data;
1064 IFNULLRET(bcs);
1065 ubc = bcs->hw.bas;
1066 IFNULLRET(ubc);
1067 cs = bcs->cs;
1068 IFNULLRET(cs);
1069 1059
1070 /* loop while completed URBs arrive in time */ 1060 /* loop while completed URBs arrive in time */
1071 for (;;) { 1061 for (;;) {
1072 if (unlikely(!atomic_read(&cs->connected))) {
1073 warn("%s: disconnected", __func__);
1074 return;
1075 }
1076
1077 if (unlikely(!(atomic_read(&ubc->running)))) { 1062 if (unlikely(!(atomic_read(&ubc->running)))) {
1078 dbg(DEBUG_ISO, "%s: not running", __func__); 1063 gig_dbg(DEBUG_ISO, "%s: not running", __func__);
1079 return; 1064 return;
1080 } 1065 }
1081 1066
@@ -1087,7 +1072,7 @@ static void write_iso_tasklet(unsigned long data)
1087 ubc->isooutovfl = NULL; 1072 ubc->isooutovfl = NULL;
1088 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1073 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1089 if (ovfl) { 1074 if (ovfl) {
1090 err("isochronous write buffer underrun - buy a faster machine :-)"); 1075 dev_err(cs->dev, "isochronous write buffer underrun\n");
1091 error_hangup(bcs); 1076 error_hangup(bcs);
1092 break; 1077 break;
1093 } 1078 }
@@ -1100,7 +1085,8 @@ static void write_iso_tasklet(unsigned long data)
1100 ubc->isooutfree = NULL; 1085 ubc->isooutfree = NULL;
1101 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1086 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1102 if (next) { 1087 if (next) {
1103 if (submit_iso_write_urb(next) <= 0) { 1088 rc = submit_iso_write_urb(next);
1089 if (unlikely(rc <= 0 && rc != -ENODEV)) {
1104 /* could not submit URB, put it back */ 1090 /* could not submit URB, put it back */
1105 spin_lock_irqsave(&ubc->isooutlock, flags); 1091 spin_lock_irqsave(&ubc->isooutlock, flags);
1106 if (ubc->isooutfree == NULL) { 1092 if (ubc->isooutfree == NULL) {
@@ -1110,7 +1096,8 @@ static void write_iso_tasklet(unsigned long data)
1110 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1096 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1111 if (next) { 1097 if (next) {
1112 /* couldn't put it back */ 1098 /* couldn't put it back */
1113 err("losing isochronous write URB"); 1099 dev_err(cs->dev,
1100 "losing isochronous write URB\n");
1114 error_hangup(bcs); 1101 error_hangup(bcs);
1115 } 1102 }
1116 } 1103 }
@@ -1119,26 +1106,30 @@ static void write_iso_tasklet(unsigned long data)
1119 /* process completed URB */ 1106 /* process completed URB */
1120 urb = done->urb; 1107 urb = done->urb;
1121 switch (urb->status) { 1108 switch (urb->status) {
1109 case -EXDEV: /* partial completion */
1110 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1111 __func__);
1112 /* fall through - what's the difference anyway? */
1122 case 0: /* normal completion */ 1113 case 0: /* normal completion */
1123 break; 1114 /* inspect individual frames
1124 case -EXDEV: /* inspect individual frames */ 1115 * assumptions (for lack of documentation):
1125 /* assumptions (for lack of documentation): 1116 * - actual_length bytes of first frame in error are
1126 * - actual_length bytes of the frame in error are successfully sent 1117 * successfully sent
1127 * - all following frames are not sent at all 1118 * - all following frames are not sent at all
1128 */ 1119 */
1129 dbg(DEBUG_ISO, "%s: URB partially completed", __func__); 1120 offset = done->limit; /* default (no error) */
1130 offset = done->limit; /* just in case */
1131 for (i = 0; i < BAS_NUMFRAMES; i++) { 1121 for (i = 0; i < BAS_NUMFRAMES; i++) {
1132 ifd = &urb->iso_frame_desc[i]; 1122 ifd = &urb->iso_frame_desc[i];
1133 if (ifd->status || 1123 if (ifd->status ||
1134 ifd->actual_length != ifd->length) { 1124 ifd->actual_length != ifd->length) {
1135 warn("isochronous write: frame %d: %s, " 1125 dev_warn(cs->dev,
1136 "only %d of %d bytes sent", 1126 "isochronous write: frame %d: %s, "
1127 "only %d of %d bytes sent\n",
1137 i, get_usb_statmsg(ifd->status), 1128 i, get_usb_statmsg(ifd->status),
1138 ifd->actual_length, ifd->length); 1129 ifd->actual_length, ifd->length);
1139 offset = (ifd->offset + 1130 offset = (ifd->offset +
1140 ifd->actual_length) 1131 ifd->actual_length)
1141 % BAS_OUTBUFSIZE; 1132 % BAS_OUTBUFSIZE;
1142 break; 1133 break;
1143 } 1134 }
1144 } 1135 }
@@ -1148,25 +1139,26 @@ static void write_iso_tasklet(unsigned long data)
1148 ifd = &urb->iso_frame_desc[i]; 1139 ifd = &urb->iso_frame_desc[i];
1149 if (ifd->status != -EINPROGRESS 1140 if (ifd->status != -EINPROGRESS
1150 || ifd->actual_length != 0) { 1141 || ifd->actual_length != 0) {
1151 warn("isochronous write: frame %d: %s, " 1142 dev_warn(cs->dev,
1152 "%d of %d bytes sent", 1143 "isochronous write: frame %d: %s, "
1144 "%d of %d bytes sent\n",
1153 i, get_usb_statmsg(ifd->status), 1145 i, get_usb_statmsg(ifd->status),
1154 ifd->actual_length, ifd->length); 1146 ifd->actual_length, ifd->length);
1155 offset = (ifd->offset + 1147 offset = (ifd->offset +
1156 ifd->actual_length) 1148 ifd->actual_length)
1157 % BAS_OUTBUFSIZE; 1149 % BAS_OUTBUFSIZE;
1158 break; 1150 break;
1159 } 1151 }
1160 } 1152 }
1161#endif 1153#endif
1162 break; 1154 break;
1163 case -EPIPE: //FIXME is this the code for "underrun"? 1155 case -EPIPE: /* stall - probably underrun */
1164 err("isochronous write stalled"); 1156 dev_err(cs->dev, "isochronous write stalled\n");
1165 error_hangup(bcs); 1157 error_hangup(bcs);
1166 break; 1158 break;
1167 default: /* severe trouble */ 1159 default: /* severe trouble */
1168 warn("isochronous write: %s", 1160 dev_warn(cs->dev, "isochronous write: %s\n",
1169 get_usb_statmsg(urb->status)); 1161 get_usb_statmsg(urb->status));
1170 } 1162 }
1171 1163
1172 /* mark the write buffer area covered by this URB as free */ 1164 /* mark the write buffer area covered by this URB as free */
@@ -1180,7 +1172,8 @@ static void write_iso_tasklet(unsigned long data)
1180 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1172 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1181 if (next) { 1173 if (next) {
1182 /* only one URB still active - resubmit one */ 1174 /* only one URB still active - resubmit one */
1183 if (submit_iso_write_urb(next) <= 0) { 1175 rc = submit_iso_write_urb(next);
1176 if (unlikely(rc <= 0 && rc != -ENODEV)) {
1184 /* couldn't submit */ 1177 /* couldn't submit */
1185 error_hangup(bcs); 1178 error_hangup(bcs);
1186 } 1179 }
@@ -1194,8 +1187,8 @@ static void write_iso_tasklet(unsigned long data)
1194 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) { 1187 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) {
1195 /* insufficient buffer space, push back onto queue */ 1188 /* insufficient buffer space, push back onto queue */
1196 skb_queue_head(&bcs->squeue, skb); 1189 skb_queue_head(&bcs->squeue, skb);
1197 dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d", 1190 gig_dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d",
1198 __func__, skb_queue_len(&bcs->squeue)); 1191 __func__, skb_queue_len(&bcs->squeue));
1199 break; 1192 break;
1200 } 1193 }
1201 skb_pull(skb, len); 1194 skb_pull(skb, len);
@@ -1215,28 +1208,16 @@ static void write_iso_tasklet(unsigned long data)
1215 */ 1208 */
1216static void read_iso_tasklet(unsigned long data) 1209static void read_iso_tasklet(unsigned long data)
1217{ 1210{
1218 struct bc_state *bcs; 1211 struct bc_state *bcs = (struct bc_state *) data;
1219 struct bas_bc_state *ubc; 1212 struct bas_bc_state *ubc = bcs->hw.bas;
1220 struct cardstate *cs; 1213 struct cardstate *cs = bcs->cs;
1221 struct urb *urb; 1214 struct urb *urb;
1222 char *rcvbuf; 1215 char *rcvbuf;
1223 unsigned long flags; 1216 unsigned long flags;
1224 int totleft, numbytes, offset, frame, rc; 1217 int totleft, numbytes, offset, frame, rc;
1225 1218
1226 bcs = (struct bc_state *) data;
1227 IFNULLRET(bcs);
1228 ubc = bcs->hw.bas;
1229 IFNULLRET(ubc);
1230 cs = bcs->cs;
1231 IFNULLRET(cs);
1232
1233 /* loop while more completed URBs arrive in the meantime */ 1219 /* loop while more completed URBs arrive in the meantime */
1234 for (;;) { 1220 for (;;) {
1235 if (!atomic_read(&cs->connected)) {
1236 warn("%s: disconnected", __func__);
1237 return;
1238 }
1239
1240 /* retrieve URB */ 1221 /* retrieve URB */
1241 spin_lock_irqsave(&ubc->isoinlock, flags); 1222 spin_lock_irqsave(&ubc->isoinlock, flags);
1242 if (!(urb = ubc->isoindone)) { 1223 if (!(urb = ubc->isoindone)) {
@@ -1245,38 +1226,44 @@ static void read_iso_tasklet(unsigned long data)
1245 } 1226 }
1246 ubc->isoindone = NULL; 1227 ubc->isoindone = NULL;
1247 if (unlikely(ubc->loststatus != -EINPROGRESS)) { 1228 if (unlikely(ubc->loststatus != -EINPROGRESS)) {
1248 warn("isochronous read overrun, dropped URB with status: %s, %d bytes lost", 1229 dev_warn(cs->dev,
1249 get_usb_statmsg(ubc->loststatus), ubc->isoinlost); 1230 "isochronous read overrun, "
1231 "dropped URB with status: %s, %d bytes lost\n",
1232 get_usb_statmsg(ubc->loststatus),
1233 ubc->isoinlost);
1250 ubc->loststatus = -EINPROGRESS; 1234 ubc->loststatus = -EINPROGRESS;
1251 } 1235 }
1252 spin_unlock_irqrestore(&ubc->isoinlock, flags); 1236 spin_unlock_irqrestore(&ubc->isoinlock, flags);
1253 1237
1254 if (unlikely(!(atomic_read(&ubc->running)))) { 1238 if (unlikely(!(atomic_read(&ubc->running)))) {
1255 dbg(DEBUG_ISO, "%s: channel not running, dropped URB with status: %s", 1239 gig_dbg(DEBUG_ISO,
1256 __func__, get_usb_statmsg(urb->status)); 1240 "%s: channel not running, "
1241 "dropped URB with status: %s",
1242 __func__, get_usb_statmsg(urb->status));
1257 return; 1243 return;
1258 } 1244 }
1259 1245
1260 switch (urb->status) { 1246 switch (urb->status) {
1261 case 0: /* normal completion */ 1247 case 0: /* normal completion */
1262 break; 1248 break;
1263 case -EXDEV: /* inspect individual frames (we do that anyway) */ 1249 case -EXDEV: /* inspect individual frames
1264 dbg(DEBUG_ISO, "%s: URB partially completed", __func__); 1250 (we do that anyway) */
1251 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1252 __func__);
1265 break; 1253 break;
1266 case -ENOENT: 1254 case -ENOENT:
1267 case -ECONNRESET: 1255 case -ECONNRESET:
1268 dbg(DEBUG_ISO, "%s: URB canceled", __func__); 1256 case -EINPROGRESS:
1269 continue; /* -> skip */ 1257 gig_dbg(DEBUG_ISO, "%s: %s",
1270 case -EINPROGRESS: /* huh? */ 1258 __func__, get_usb_statmsg(urb->status));
1271 dbg(DEBUG_ISO, "%s: URB still pending", __func__);
1272 continue; /* -> skip */ 1259 continue; /* -> skip */
1273 case -EPIPE: 1260 case -EPIPE:
1274 err("isochronous read stalled"); 1261 dev_err(cs->dev, "isochronous read stalled\n");
1275 error_hangup(bcs); 1262 error_hangup(bcs);
1276 continue; /* -> skip */ 1263 continue; /* -> skip */
1277 default: /* severe trouble */ 1264 default: /* severe trouble */
1278 warn("isochronous read: %s", 1265 dev_warn(cs->dev, "isochronous read: %s\n",
1279 get_usb_statmsg(urb->status)); 1266 get_usb_statmsg(urb->status));
1280 goto error; 1267 goto error;
1281 } 1268 }
1282 1269
@@ -1284,33 +1271,44 @@ static void read_iso_tasklet(unsigned long data)
1284 totleft = urb->actual_length; 1271 totleft = urb->actual_length;
1285 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) { 1272 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
1286 if (unlikely(urb->iso_frame_desc[frame].status)) { 1273 if (unlikely(urb->iso_frame_desc[frame].status)) {
1287 warn("isochronous read: frame %d: %s", 1274 dev_warn(cs->dev,
1288 frame, get_usb_statmsg(urb->iso_frame_desc[frame].status)); 1275 "isochronous read: frame %d: %s\n",
1276 frame,
1277 get_usb_statmsg(
1278 urb->iso_frame_desc[frame].status));
1289 break; 1279 break;
1290 } 1280 }
1291 numbytes = urb->iso_frame_desc[frame].actual_length; 1281 numbytes = urb->iso_frame_desc[frame].actual_length;
1292 if (unlikely(numbytes > BAS_MAXFRAME)) { 1282 if (unlikely(numbytes > BAS_MAXFRAME)) {
1293 warn("isochronous read: frame %d: numbytes (%d) > BAS_MAXFRAME", 1283 dev_warn(cs->dev,
1294 frame, numbytes); 1284 "isochronous read: frame %d: "
1285 "numbytes (%d) > BAS_MAXFRAME\n",
1286 frame, numbytes);
1295 break; 1287 break;
1296 } 1288 }
1297 if (unlikely(numbytes > totleft)) { 1289 if (unlikely(numbytes > totleft)) {
1298 warn("isochronous read: frame %d: numbytes (%d) > totleft (%d)", 1290 dev_warn(cs->dev,
1299 frame, numbytes, totleft); 1291 "isochronous read: frame %d: "
1292 "numbytes (%d) > totleft (%d)\n",
1293 frame, numbytes, totleft);
1300 break; 1294 break;
1301 } 1295 }
1302 offset = urb->iso_frame_desc[frame].offset; 1296 offset = urb->iso_frame_desc[frame].offset;
1303 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) { 1297 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
1304 warn("isochronous read: frame %d: offset (%d) + numbytes (%d) > BAS_INBUFSIZE", 1298 dev_warn(cs->dev,
1305 frame, offset, numbytes); 1299 "isochronous read: frame %d: "
1300 "offset (%d) + numbytes (%d) "
1301 "> BAS_INBUFSIZE\n",
1302 frame, offset, numbytes);
1306 break; 1303 break;
1307 } 1304 }
1308 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs); 1305 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
1309 totleft -= numbytes; 1306 totleft -= numbytes;
1310 } 1307 }
1311 if (unlikely(totleft > 0)) 1308 if (unlikely(totleft > 0))
1312 warn("isochronous read: %d data bytes missing", 1309 dev_warn(cs->dev,
1313 totleft); 1310 "isochronous read: %d data bytes missing\n",
1311 totleft);
1314 1312
1315 error: 1313 error:
1316 /* URB processed, resubmit */ 1314 /* URB processed, resubmit */
@@ -1318,12 +1316,15 @@ static void read_iso_tasklet(unsigned long data)
1318 urb->iso_frame_desc[frame].status = 0; 1316 urb->iso_frame_desc[frame].status = 0;
1319 urb->iso_frame_desc[frame].actual_length = 0; 1317 urb->iso_frame_desc[frame].actual_length = 0;
1320 } 1318 }
1321 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */ 1319 /* urb->dev is clobbered by USB subsystem */
1320 urb->dev = bcs->cs->hw.bas->udev;
1322 urb->transfer_flags = URB_ISO_ASAP; 1321 urb->transfer_flags = URB_ISO_ASAP;
1323 urb->number_of_packets = BAS_NUMFRAMES; 1322 urb->number_of_packets = BAS_NUMFRAMES;
1324 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 1323 rc = usb_submit_urb(urb, SLAB_ATOMIC);
1325 err("could not resubmit isochronous read URB: %s", 1324 if (unlikely(rc != 0 && rc != -ENODEV)) {
1326 get_usb_statmsg(rc)); 1325 dev_err(cs->dev,
1326 "could not resubmit isochronous read URB: %s\n",
1327 get_usb_rcmsg(rc));
1327 dump_urb(DEBUG_ISO, "resubmit iso read", urb); 1328 dump_urb(DEBUG_ISO, "resubmit iso read", urb);
1328 error_hangup(bcs); 1329 error_hangup(bcs);
1329 } 1330 }
@@ -1341,15 +1342,10 @@ static void read_iso_tasklet(unsigned long data)
1341static void req_timeout(unsigned long data) 1342static void req_timeout(unsigned long data)
1342{ 1343{
1343 struct bc_state *bcs = (struct bc_state *) data; 1344 struct bc_state *bcs = (struct bc_state *) data;
1344 struct bas_cardstate *ucs; 1345 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1345 int pending; 1346 int pending;
1346 unsigned long flags; 1347 unsigned long flags;
1347 1348
1348 IFNULLRET(bcs);
1349 IFNULLRET(bcs->cs);
1350 ucs = bcs->cs->hw.bas;
1351 IFNULLRET(ucs);
1352
1353 check_pending(ucs); 1349 check_pending(ucs);
1354 1350
1355 spin_lock_irqsave(&ucs->lock, flags); 1351 spin_lock_irqsave(&ucs->lock, flags);
@@ -1359,33 +1355,34 @@ static void req_timeout(unsigned long data)
1359 1355
1360 switch (pending) { 1356 switch (pending) {
1361 case 0: /* no pending request */ 1357 case 0: /* no pending request */
1362 dbg(DEBUG_USBREQ, "%s: no request pending", __func__); 1358 gig_dbg(DEBUG_USBREQ, "%s: no request pending", __func__);
1363 break; 1359 break;
1364 1360
1365 case HD_OPEN_ATCHANNEL: 1361 case HD_OPEN_ATCHANNEL:
1366 err("timeout opening AT channel"); 1362 dev_err(bcs->cs->dev, "timeout opening AT channel\n");
1367 error_reset(bcs->cs); 1363 error_reset(bcs->cs);
1368 break; 1364 break;
1369 1365
1370 case HD_OPEN_B2CHANNEL: 1366 case HD_OPEN_B2CHANNEL:
1371 case HD_OPEN_B1CHANNEL: 1367 case HD_OPEN_B1CHANNEL:
1372 err("timeout opening channel %d", bcs->channel + 1); 1368 dev_err(bcs->cs->dev, "timeout opening channel %d\n",
1369 bcs->channel + 1);
1373 error_hangup(bcs); 1370 error_hangup(bcs);
1374 break; 1371 break;
1375 1372
1376 case HD_CLOSE_ATCHANNEL: 1373 case HD_CLOSE_ATCHANNEL:
1377 err("timeout closing AT channel"); 1374 dev_err(bcs->cs->dev, "timeout closing AT channel\n");
1378 //wake_up_interruptible(cs->initwait);
1379 //FIXME need own wait queue?
1380 break; 1375 break;
1381 1376
1382 case HD_CLOSE_B2CHANNEL: 1377 case HD_CLOSE_B2CHANNEL:
1383 case HD_CLOSE_B1CHANNEL: 1378 case HD_CLOSE_B1CHANNEL:
1384 err("timeout closing channel %d", bcs->channel + 1); 1379 dev_err(bcs->cs->dev, "timeout closing channel %d\n",
1380 bcs->channel + 1);
1385 break; 1381 break;
1386 1382
1387 default: 1383 default:
1388 warn("request 0x%02x timed out, clearing", pending); 1384 dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
1385 pending);
1389 } 1386 }
1390} 1387}
1391 1388
@@ -1398,18 +1395,14 @@ static void req_timeout(unsigned long data)
1398 */ 1395 */
1399static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs) 1396static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
1400{ 1397{
1401 struct bas_cardstate *ucs; 1398 struct bas_cardstate *ucs = urb->context;
1402 unsigned long flags; 1399 unsigned long flags;
1403 1400
1404 IFNULLRET(urb);
1405 IFNULLRET(urb->context);
1406 IFNULLRET(cardstate);
1407
1408 ucs = (struct bas_cardstate *) urb->context;
1409 spin_lock_irqsave(&ucs->lock, flags); 1401 spin_lock_irqsave(&ucs->lock, flags);
1410 if (urb->status && ucs->pending) { 1402 if (urb->status && ucs->pending) {
1411 err("control request 0x%02x failed: %s", 1403 dev_err(&ucs->interface->dev,
1412 ucs->pending, get_usb_statmsg(urb->status)); 1404 "control request 0x%02x failed: %s\n",
1405 ucs->pending, get_usb_statmsg(urb->status));
1413 del_timer(&ucs->timer_ctrl); 1406 del_timer(&ucs->timer_ctrl);
1414 ucs->pending = 0; 1407 ucs->pending = 0;
1415 } 1408 }
@@ -1432,34 +1425,24 @@ static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
1432 * timeout timeout in seconds (0: no timeout) 1425 * timeout timeout in seconds (0: no timeout)
1433 * return value: 1426 * return value:
1434 * 0 on success 1427 * 0 on success
1435 * -EINVAL if a NULL pointer is encountered somewhere
1436 * -EBUSY if another request is pending 1428 * -EBUSY if another request is pending
1437 * any URB submission error code 1429 * any URB submission error code
1438 */ 1430 */
1439static int req_submit(struct bc_state *bcs, int req, int val, int timeout) 1431static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1440{ 1432{
1441 struct bas_cardstate *ucs; 1433 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1442 int ret; 1434 int ret;
1443 unsigned long flags; 1435 unsigned long flags;
1444 1436
1445 IFNULLRETVAL(bcs, -EINVAL); 1437 gig_dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1446 IFNULLRETVAL(bcs->cs, -EINVAL);
1447 ucs = bcs->cs->hw.bas;
1448 IFNULLRETVAL(ucs, -EINVAL);
1449 IFNULLRETVAL(ucs->urb_ctrl, -EINVAL);
1450
1451 dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1452 1438
1453 spin_lock_irqsave(&ucs->lock, flags); 1439 spin_lock_irqsave(&ucs->lock, flags);
1454 if (ucs->pending) { 1440 if (ucs->pending) {
1455 spin_unlock_irqrestore(&ucs->lock, flags); 1441 spin_unlock_irqrestore(&ucs->lock, flags);
1456 err("submission of request 0x%02x failed: request 0x%02x still pending", 1442 dev_err(bcs->cs->dev,
1457 req, ucs->pending); 1443 "submission of request 0x%02x failed: "
1458 return -EBUSY; 1444 "request 0x%02x still pending\n",
1459 } 1445 req, ucs->pending);
1460 if (ucs->urb_ctrl->status == -EINPROGRESS) {
1461 spin_unlock_irqrestore(&ucs->lock, flags);
1462 err("could not submit request 0x%02x: URB busy", req);
1463 return -EBUSY; 1446 return -EBUSY;
1464 } 1447 }
1465 1448
@@ -1469,19 +1452,19 @@ static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1469 ucs->dr_ctrl.wIndex = 0; 1452 ucs->dr_ctrl.wIndex = 0;
1470 ucs->dr_ctrl.wLength = 0; 1453 ucs->dr_ctrl.wLength = 0;
1471 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev, 1454 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev,
1472 usb_sndctrlpipe(ucs->udev, 0), 1455 usb_sndctrlpipe(ucs->udev, 0),
1473 (unsigned char*) &ucs->dr_ctrl, NULL, 0, 1456 (unsigned char*) &ucs->dr_ctrl, NULL, 0,
1474 write_ctrl_callback, ucs); 1457 write_ctrl_callback, ucs);
1475 if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) { 1458 if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) {
1476 err("could not submit request 0x%02x: %s", 1459 dev_err(bcs->cs->dev, "could not submit request 0x%02x: %s\n",
1477 req, get_usb_statmsg(ret)); 1460 req, get_usb_statmsg(ret));
1478 spin_unlock_irqrestore(&ucs->lock, flags); 1461 spin_unlock_irqrestore(&ucs->lock, flags);
1479 return ret; 1462 return ret;
1480 } 1463 }
1481 ucs->pending = req; 1464 ucs->pending = req;
1482 1465
1483 if (timeout > 0) { 1466 if (timeout > 0) {
1484 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 1467 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
1485 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10; 1468 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10;
1486 ucs->timer_ctrl.data = (unsigned long) bcs; 1469 ucs->timer_ctrl.data = (unsigned long) bcs;
1487 ucs->timer_ctrl.function = req_timeout; 1470 ucs->timer_ctrl.function = req_timeout;
@@ -1503,23 +1486,36 @@ static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1503static int gigaset_init_bchannel(struct bc_state *bcs) 1486static int gigaset_init_bchannel(struct bc_state *bcs)
1504{ 1487{
1505 int req, ret; 1488 int req, ret;
1489 unsigned long flags;
1506 1490
1507 IFNULLRETVAL(bcs, -EINVAL); 1491 spin_lock_irqsave(&bcs->cs->lock, flags);
1492 if (unlikely(!bcs->cs->connected)) {
1493 gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
1494 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1495 return -ENODEV;
1496 }
1508 1497
1509 if ((ret = starturbs(bcs)) < 0) { 1498 if ((ret = starturbs(bcs)) < 0) {
1510 err("could not start isochronous I/O for channel %d", 1499 dev_err(bcs->cs->dev,
1511 bcs->channel + 1); 1500 "could not start isochronous I/O for channel B%d: %s\n",
1512 error_hangup(bcs); 1501 bcs->channel + 1,
1502 ret == -EFAULT ? "null URB" : get_usb_rcmsg(ret));
1503 if (ret != -ENODEV)
1504 error_hangup(bcs);
1505 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1513 return ret; 1506 return ret;
1514 } 1507 }
1515 1508
1516 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL; 1509 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
1517 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) { 1510 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
1518 err("could not open channel %d: %s", 1511 dev_err(bcs->cs->dev, "could not open channel B%d\n",
1519 bcs->channel + 1, get_usb_statmsg(ret)); 1512 bcs->channel + 1);
1520 stopurbs(bcs->hw.bas); 1513 stopurbs(bcs->hw.bas);
1521 error_hangup(bcs); 1514 if (ret != -ENODEV)
1515 error_hangup(bcs);
1522 } 1516 }
1517
1518 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1523 return ret; 1519 return ret;
1524} 1520}
1525 1521
@@ -1536,20 +1532,30 @@ static int gigaset_init_bchannel(struct bc_state *bcs)
1536static int gigaset_close_bchannel(struct bc_state *bcs) 1532static int gigaset_close_bchannel(struct bc_state *bcs)
1537{ 1533{
1538 int req, ret; 1534 int req, ret;
1535 unsigned long flags;
1539 1536
1540 IFNULLRETVAL(bcs, -EINVAL); 1537 spin_lock_irqsave(&bcs->cs->lock, flags);
1538 if (unlikely(!bcs->cs->connected)) {
1539 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1540 gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
1541 return -ENODEV;
1542 }
1541 1543
1542 if (!(atomic_read(&bcs->cs->hw.bas->basstate) & 1544 if (!(atomic_read(&bcs->cs->hw.bas->basstate) &
1543 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) { 1545 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
1544 /* channel not running: just signal common.c */ 1546 /* channel not running: just signal common.c */
1547 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1545 gigaset_bchannel_down(bcs); 1548 gigaset_bchannel_down(bcs);
1546 return 0; 1549 return 0;
1547 } 1550 }
1548 1551
1552 /* channel running: tell device to close it */
1549 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL; 1553 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
1550 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) 1554 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
1551 err("could not submit HD_CLOSE_BxCHANNEL request: %s", 1555 dev_err(bcs->cs->dev, "closing channel B%d failed\n",
1552 get_usb_statmsg(ret)); 1556 bcs->channel + 1);
1557
1558 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1553 return ret; 1559 return ret;
1554} 1560}
1555 1561
@@ -1564,17 +1570,13 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
1564 */ 1570 */
1565static void complete_cb(struct cardstate *cs) 1571static void complete_cb(struct cardstate *cs)
1566{ 1572{
1567 struct cmdbuf_t *cb; 1573 struct cmdbuf_t *cb = cs->cmdbuf;
1568
1569 IFNULLRET(cs);
1570 cb = cs->cmdbuf;
1571 IFNULLRET(cb);
1572 1574
1573 /* unqueue completed buffer */ 1575 /* unqueue completed buffer */
1574 cs->cmdbytes -= cs->curlen; 1576 cs->cmdbytes -= cs->curlen;
1575 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD, 1577 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD,
1576 "write_command: sent %u bytes, %u left", 1578 "write_command: sent %u bytes, %u left",
1577 cs->curlen, cs->cmdbytes); 1579 cs->curlen, cs->cmdbytes);
1578 if ((cs->cmdbuf = cb->next) != NULL) { 1580 if ((cs->cmdbuf = cb->next) != NULL) {
1579 cs->cmdbuf->prev = NULL; 1581 cs->cmdbuf->prev = NULL;
1580 cs->curlen = cs->cmdbuf->len; 1582 cs->curlen = cs->cmdbuf->len;
@@ -1589,8 +1591,6 @@ static void complete_cb(struct cardstate *cs)
1589 kfree(cb); 1591 kfree(cb);
1590} 1592}
1591 1593
1592static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len);
1593
1594/* write_command_callback 1594/* write_command_callback
1595 * USB completion handler for AT command transmission 1595 * USB completion handler for AT command transmission
1596 * called by the USB subsystem in interrupt context 1596 * called by the USB subsystem in interrupt context
@@ -1600,40 +1600,43 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len);
1600 */ 1600 */
1601static void write_command_callback(struct urb *urb, struct pt_regs *regs) 1601static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1602{ 1602{
1603 struct cardstate *cs; 1603 struct cardstate *cs = urb->context;
1604 struct bas_cardstate *ucs = cs->hw.bas;
1604 unsigned long flags; 1605 unsigned long flags;
1605 struct bas_cardstate *ucs;
1606 1606
1607 IFNULLRET(urb); 1607 update_basstate(ucs, 0, BS_ATWRPEND);
1608 cs = (struct cardstate *) urb->context;
1609 IFNULLRET(cs);
1610 ucs = cs->hw.bas;
1611 IFNULLRET(ucs);
1612 1608
1613 /* check status */ 1609 /* check status */
1614 switch (urb->status) { 1610 switch (urb->status) {
1615 case 0: /* normal completion */ 1611 case 0: /* normal completion */
1616 break; 1612 break;
1617 case -ENOENT: /* canceled */ 1613 case -ENOENT: /* cancelled */
1618 case -ECONNRESET: /* canceled (async) */ 1614 case -ECONNRESET: /* cancelled (async) */
1619 case -EINPROGRESS: /* pending */ 1615 case -EINPROGRESS: /* pending */
1616 case -ENODEV: /* device removed */
1617 case -ESHUTDOWN: /* device shut down */
1620 /* ignore silently */ 1618 /* ignore silently */
1621 dbg(DEBUG_USBREQ, 1619 gig_dbg(DEBUG_USBREQ, "%s: %s",
1622 "%s: %s", __func__, get_usb_statmsg(urb->status)); 1620 __func__, get_usb_statmsg(urb->status));
1623 return; 1621 return;
1624 default: /* any failure */ 1622 default: /* any failure */
1625 if (++ucs->retry_cmd_out > BAS_RETRY) { 1623 if (++ucs->retry_cmd_out > BAS_RETRY) {
1626 warn("command write: %s, giving up after %d retries", 1624 dev_warn(cs->dev,
1627 get_usb_statmsg(urb->status), ucs->retry_cmd_out); 1625 "command write: %s, "
1626 "giving up after %d retries\n",
1627 get_usb_statmsg(urb->status),
1628 ucs->retry_cmd_out);
1628 break; 1629 break;
1629 } 1630 }
1630 if (cs->cmdbuf == NULL) { 1631 if (cs->cmdbuf == NULL) {
1631 warn("command write: %s, cannot retry - cmdbuf gone", 1632 dev_warn(cs->dev,
1632 get_usb_statmsg(urb->status)); 1633 "command write: %s, "
1634 "cannot retry - cmdbuf gone\n",
1635 get_usb_statmsg(urb->status));
1633 break; 1636 break;
1634 } 1637 }
1635 notice("command write: %s, retry %d", 1638 dev_notice(cs->dev, "command write: %s, retry %d\n",
1636 get_usb_statmsg(urb->status), ucs->retry_cmd_out); 1639 get_usb_statmsg(urb->status), ucs->retry_cmd_out);
1637 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0) 1640 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
1638 /* resubmitted - bypass regular exit block */ 1641 /* resubmitted - bypass regular exit block */
1639 return; 1642 return;
@@ -1655,13 +1658,9 @@ static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1655static void atrdy_timeout(unsigned long data) 1658static void atrdy_timeout(unsigned long data)
1656{ 1659{
1657 struct cardstate *cs = (struct cardstate *) data; 1660 struct cardstate *cs = (struct cardstate *) data;
1658 struct bas_cardstate *ucs; 1661 struct bas_cardstate *ucs = cs->hw.bas;
1659
1660 IFNULLRET(cs);
1661 ucs = cs->hw.bas;
1662 IFNULLRET(ucs);
1663 1662
1664 warn("timeout waiting for HD_READY_SEND_ATDATA"); 1663 dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n");
1665 1664
1666 /* fake the missing signal - what else can I do? */ 1665 /* fake the missing signal - what else can I do? */
1667 update_basstate(ucs, BS_ATREADY, BS_ATTIMER); 1666 update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
@@ -1676,24 +1675,19 @@ static void atrdy_timeout(unsigned long data)
1676 * len length of command to send 1675 * len length of command to send
1677 * return value: 1676 * return value:
1678 * 0 on success 1677 * 0 on success
1679 * -EFAULT if a NULL pointer is encountered somewhere
1680 * -EBUSY if another request is pending 1678 * -EBUSY if another request is pending
1681 * any URB submission error code 1679 * any URB submission error code
1682 */ 1680 */
1683static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len) 1681static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1684{ 1682{
1685 struct bas_cardstate *ucs; 1683 struct bas_cardstate *ucs = cs->hw.bas;
1686 int ret; 1684 int rc;
1687
1688 IFNULLRETVAL(cs, -EFAULT);
1689 ucs = cs->hw.bas;
1690 IFNULLRETVAL(ucs, -EFAULT);
1691 IFNULLRETVAL(ucs->urb_cmd_out, -EFAULT);
1692 1685
1693 dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len); 1686 gig_dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
1694 1687
1695 if (ucs->urb_cmd_out->status == -EINPROGRESS) { 1688 if (update_basstate(ucs, BS_ATWRPEND, 0) & BS_ATWRPEND) {
1696 err("could not submit HD_WRITE_ATMESSAGE: URB busy"); 1689 dev_err(cs->dev,
1690 "could not submit HD_WRITE_ATMESSAGE: URB busy\n");
1697 return -EBUSY; 1691 return -EBUSY;
1698 } 1692 }
1699 1693
@@ -1706,25 +1700,22 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1706 usb_sndctrlpipe(ucs->udev, 0), 1700 usb_sndctrlpipe(ucs->udev, 0),
1707 (unsigned char*) &ucs->dr_cmd_out, buf, len, 1701 (unsigned char*) &ucs->dr_cmd_out, buf, len,
1708 write_command_callback, cs); 1702 write_command_callback, cs);
1709 1703 rc = usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC);
1710 if ((ret = usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC)) != 0) { 1704 if (unlikely(rc)) {
1711 err("could not submit HD_WRITE_ATMESSAGE: %s", 1705 update_basstate(ucs, 0, BS_ATWRPEND);
1712 get_usb_statmsg(ret)); 1706 dev_err(cs->dev, "could not submit HD_WRITE_ATMESSAGE: %s\n",
1713 return ret; 1707 get_usb_rcmsg(rc));
1708 return rc;
1714 } 1709 }
1715 1710
1716 /* submitted successfully */ 1711 /* submitted successfully, start timeout if necessary */
1717 update_basstate(ucs, 0, BS_ATREADY); 1712 if (!(update_basstate(ucs, BS_ATTIMER, BS_ATREADY) & BS_ATTIMER)) {
1718 1713 gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs",
1719 /* start timeout if necessary */ 1714 ATRDY_TIMEOUT);
1720 if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) {
1721 dbg(DEBUG_OUTPUT,
1722 "setting ATREADY timeout of %d/10 secs", ATRDY_TIMEOUT);
1723 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10; 1715 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10;
1724 ucs->timer_atrdy.data = (unsigned long) cs; 1716 ucs->timer_atrdy.data = (unsigned long) cs;
1725 ucs->timer_atrdy.function = atrdy_timeout; 1717 ucs->timer_atrdy.function = atrdy_timeout;
1726 add_timer(&ucs->timer_atrdy); 1718 add_timer(&ucs->timer_atrdy);
1727 update_basstate(ucs, BS_ATTIMER, 0);
1728 } 1719 }
1729 return 0; 1720 return 0;
1730} 1721}
@@ -1740,21 +1731,16 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1740static int start_cbsend(struct cardstate *cs) 1731static int start_cbsend(struct cardstate *cs)
1741{ 1732{
1742 struct cmdbuf_t *cb; 1733 struct cmdbuf_t *cb;
1743 struct bas_cardstate *ucs; 1734 struct bas_cardstate *ucs = cs->hw.bas;
1744 unsigned long flags; 1735 unsigned long flags;
1745 int rc; 1736 int rc;
1746 int retval = 0; 1737 int retval = 0;
1747 1738
1748 IFNULLRETVAL(cs, -EFAULT);
1749 ucs = cs->hw.bas;
1750 IFNULLRETVAL(ucs, -EFAULT);
1751
1752 /* check if AT channel is open */ 1739 /* check if AT channel is open */
1753 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) { 1740 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
1754 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD, "AT channel not open"); 1741 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open");
1755 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT); 1742 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
1756 if (rc < 0) { 1743 if (rc < 0) {
1757 err("could not open AT channel");
1758 /* flush command queue */ 1744 /* flush command queue */
1759 spin_lock_irqsave(&cs->cmdlock, flags); 1745 spin_lock_irqsave(&cs->cmdlock, flags);
1760 while (cs->cmdbuf != NULL) 1746 while (cs->cmdbuf != NULL)
@@ -1792,27 +1778,23 @@ static int start_cbsend(struct cardstate *cs)
1792 * cs controller state structure 1778 * cs controller state structure
1793 * buf command string to send 1779 * buf command string to send
1794 * len number of bytes to send (max. IF_WRITEBUF) 1780 * len number of bytes to send (max. IF_WRITEBUF)
1795 * wake_tasklet tasklet to run when transmission is completed (NULL if none) 1781 * wake_tasklet tasklet to run when transmission is completed
1782 * (NULL if none)
1796 * return value: 1783 * return value:
1797 * number of bytes queued on success 1784 * number of bytes queued on success
1798 * error code < 0 on error 1785 * error code < 0 on error
1799 */ 1786 */
1800static int gigaset_write_cmd(struct cardstate *cs, 1787static int gigaset_write_cmd(struct cardstate *cs,
1801 const unsigned char *buf, int len, 1788 const unsigned char *buf, int len,
1802 struct tasklet_struct *wake_tasklet) 1789 struct tasklet_struct *wake_tasklet)
1803{ 1790{
1804 struct cmdbuf_t *cb; 1791 struct cmdbuf_t *cb;
1805 unsigned long flags; 1792 unsigned long flags;
1806 int status; 1793 int status;
1807 1794
1808 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ? 1795 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
1809 DEBUG_TRANSCMD : DEBUG_LOCKCMD, 1796 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
1810 "CMD Transmit", len, buf, 0); 1797 "CMD Transmit", len, buf);
1811
1812 if (!atomic_read(&cs->connected)) {
1813 err("%s: not connected", __func__);
1814 return -ENODEV;
1815 }
1816 1798
1817 if (len <= 0) 1799 if (len <= 0)
1818 return 0; /* nothing to do */ 1800 return 0; /* nothing to do */
@@ -1820,7 +1802,7 @@ static int gigaset_write_cmd(struct cardstate *cs,
1820 if (len > IF_WRITEBUF) 1802 if (len > IF_WRITEBUF)
1821 len = IF_WRITEBUF; 1803 len = IF_WRITEBUF;
1822 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { 1804 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
1823 err("%s: out of memory", __func__); 1805 dev_err(cs->dev, "%s: out of memory\n", __func__);
1824 return -ENOMEM; 1806 return -ENOMEM;
1825 } 1807 }
1826 1808
@@ -1842,14 +1824,21 @@ static int gigaset_write_cmd(struct cardstate *cs,
1842 cs->lastcmdbuf = cb; 1824 cs->lastcmdbuf = cb;
1843 spin_unlock_irqrestore(&cs->cmdlock, flags); 1825 spin_unlock_irqrestore(&cs->cmdlock, flags);
1844 1826
1827 spin_lock_irqsave(&cs->lock, flags);
1828 if (unlikely(!cs->connected)) {
1829 spin_unlock_irqrestore(&cs->lock, flags);
1830 gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
1831 return -ENODEV;
1832 }
1845 status = start_cbsend(cs); 1833 status = start_cbsend(cs);
1846 1834 spin_unlock_irqrestore(&cs->lock, flags);
1847 return status < 0 ? status : len; 1835 return status < 0 ? status : len;
1848} 1836}
1849 1837
1850/* gigaset_write_room 1838/* gigaset_write_room
1851 * tty_driver.write_room interface routine 1839 * tty_driver.write_room interface routine
1852 * return number of characters the driver will accept to be written via gigaset_write_cmd 1840 * return number of characters the driver will accept to be written via
1841 * gigaset_write_cmd
1853 * parameter: 1842 * parameter:
1854 * controller state structure 1843 * controller state structure
1855 * return value: 1844 * return value:
@@ -1904,12 +1893,32 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
1904 */ 1893 */
1905static int gigaset_freebcshw(struct bc_state *bcs) 1894static int gigaset_freebcshw(struct bc_state *bcs)
1906{ 1895{
1907 if (!bcs->hw.bas) 1896 struct bas_bc_state *ubc = bcs->hw.bas;
1897 int i;
1898
1899 if (!ubc)
1908 return 0; 1900 return 0;
1909 1901
1910 if (bcs->hw.bas->isooutbuf) 1902 /* kill URBs and tasklets before freeing - better safe than sorry */
1911 kfree(bcs->hw.bas->isooutbuf); 1903 atomic_set(&ubc->running, 0);
1912 kfree(bcs->hw.bas); 1904 for (i = 0; i < BAS_OUTURBS; ++i)
1905 if (ubc->isoouturbs[i].urb) {
1906 gig_dbg(DEBUG_INIT, "%s: killing iso out URB %d",
1907 __func__, i);
1908 usb_kill_urb(ubc->isoouturbs[i].urb);
1909 usb_free_urb(ubc->isoouturbs[i].urb);
1910 }
1911 for (i = 0; i < BAS_INURBS; ++i)
1912 if (ubc->isoinurbs[i]) {
1913 gig_dbg(DEBUG_INIT, "%s: killing iso in URB %d",
1914 __func__, i);
1915 usb_kill_urb(ubc->isoinurbs[i]);
1916 usb_free_urb(ubc->isoinurbs[i]);
1917 }
1918 tasklet_kill(&ubc->sent_tasklet);
1919 tasklet_kill(&ubc->rcvd_tasklet);
1920 kfree(ubc->isooutbuf);
1921 kfree(ubc);
1913 bcs->hw.bas = NULL; 1922 bcs->hw.bas = NULL;
1914 return 1; 1923 return 1;
1915} 1924}
@@ -1947,7 +1956,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
1947 return 0; 1956 return 0;
1948 } 1957 }
1949 tasklet_init(&ubc->sent_tasklet, 1958 tasklet_init(&ubc->sent_tasklet,
1950 &write_iso_tasklet, (unsigned long) bcs); 1959 &write_iso_tasklet, (unsigned long) bcs);
1951 1960
1952 spin_lock_init(&ubc->isoinlock); 1961 spin_lock_init(&ubc->isoinlock);
1953 for (i = 0; i < BAS_INURBS; ++i) 1962 for (i = 0; i < BAS_INURBS; ++i)
@@ -1968,7 +1977,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
1968 ubc->shared0s = 0; 1977 ubc->shared0s = 0;
1969 ubc->stolen0s = 0; 1978 ubc->stolen0s = 0;
1970 tasklet_init(&ubc->rcvd_tasklet, 1979 tasklet_init(&ubc->rcvd_tasklet,
1971 &read_iso_tasklet, (unsigned long) bcs); 1980 &read_iso_tasklet, (unsigned long) bcs);
1972 return 1; 1981 return 1;
1973} 1982}
1974 1983
@@ -1986,13 +1995,9 @@ static void gigaset_reinitbcshw(struct bc_state *bcs)
1986 1995
1987static void gigaset_freecshw(struct cardstate *cs) 1996static void gigaset_freecshw(struct cardstate *cs)
1988{ 1997{
1989 struct bas_cardstate *ucs = cs->hw.bas; 1998 /* timers, URBs and rcvbuf are disposed of in disconnect */
1990
1991 del_timer(&ucs->timer_ctrl);
1992 del_timer(&ucs->timer_atrdy);
1993 del_timer(&ucs->timer_cmd_in);
1994
1995 kfree(cs->hw.bas); 1999 kfree(cs->hw.bas);
2000 cs->hw.bas = NULL;
1996} 2001}
1997 2002
1998static int gigaset_initcshw(struct cardstate *cs) 2003static int gigaset_initcshw(struct cardstate *cs)
@@ -2027,57 +2032,56 @@ static int gigaset_initcshw(struct cardstate *cs)
2027 */ 2032 */
2028static void freeurbs(struct cardstate *cs) 2033static void freeurbs(struct cardstate *cs)
2029{ 2034{
2030 struct bas_cardstate *ucs; 2035 struct bas_cardstate *ucs = cs->hw.bas;
2031 struct bas_bc_state *ubc; 2036 struct bas_bc_state *ubc;
2032 int i, j; 2037 int i, j;
2033 2038
2034 IFNULLRET(cs);
2035 ucs = cs->hw.bas;
2036 IFNULLRET(ucs);
2037
2038 for (j = 0; j < 2; ++j) { 2039 for (j = 0; j < 2; ++j) {
2039 ubc = cs->bcs[j].hw.bas; 2040 ubc = cs->bcs[j].hw.bas;
2040 IFNULLCONT(ubc);
2041 for (i = 0; i < BAS_OUTURBS; ++i) 2041 for (i = 0; i < BAS_OUTURBS; ++i)
2042 if (ubc->isoouturbs[i].urb) { 2042 if (ubc->isoouturbs[i].urb) {
2043 usb_kill_urb(ubc->isoouturbs[i].urb); 2043 usb_kill_urb(ubc->isoouturbs[i].urb);
2044 dbg(DEBUG_INIT, 2044 gig_dbg(DEBUG_INIT,
2045 "%s: isoc output URB %d/%d unlinked", 2045 "%s: isoc output URB %d/%d unlinked",
2046 __func__, j, i); 2046 __func__, j, i);
2047 usb_free_urb(ubc->isoouturbs[i].urb); 2047 usb_free_urb(ubc->isoouturbs[i].urb);
2048 ubc->isoouturbs[i].urb = NULL; 2048 ubc->isoouturbs[i].urb = NULL;
2049 } 2049 }
2050 for (i = 0; i < BAS_INURBS; ++i) 2050 for (i = 0; i < BAS_INURBS; ++i)
2051 if (ubc->isoinurbs[i]) { 2051 if (ubc->isoinurbs[i]) {
2052 usb_kill_urb(ubc->isoinurbs[i]); 2052 usb_kill_urb(ubc->isoinurbs[i]);
2053 dbg(DEBUG_INIT, 2053 gig_dbg(DEBUG_INIT,
2054 "%s: isoc input URB %d/%d unlinked", 2054 "%s: isoc input URB %d/%d unlinked",
2055 __func__, j, i); 2055 __func__, j, i);
2056 usb_free_urb(ubc->isoinurbs[i]); 2056 usb_free_urb(ubc->isoinurbs[i]);
2057 ubc->isoinurbs[i] = NULL; 2057 ubc->isoinurbs[i] = NULL;
2058 } 2058 }
2059 } 2059 }
2060 if (ucs->urb_int_in) { 2060 if (ucs->urb_int_in) {
2061 usb_kill_urb(ucs->urb_int_in); 2061 usb_kill_urb(ucs->urb_int_in);
2062 dbg(DEBUG_INIT, "%s: interrupt input URB unlinked", __func__); 2062 gig_dbg(DEBUG_INIT, "%s: interrupt input URB unlinked",
2063 __func__);
2063 usb_free_urb(ucs->urb_int_in); 2064 usb_free_urb(ucs->urb_int_in);
2064 ucs->urb_int_in = NULL; 2065 ucs->urb_int_in = NULL;
2065 } 2066 }
2066 if (ucs->urb_cmd_out) { 2067 if (ucs->urb_cmd_out) {
2067 usb_kill_urb(ucs->urb_cmd_out); 2068 usb_kill_urb(ucs->urb_cmd_out);
2068 dbg(DEBUG_INIT, "%s: command output URB unlinked", __func__); 2069 gig_dbg(DEBUG_INIT, "%s: command output URB unlinked",
2070 __func__);
2069 usb_free_urb(ucs->urb_cmd_out); 2071 usb_free_urb(ucs->urb_cmd_out);
2070 ucs->urb_cmd_out = NULL; 2072 ucs->urb_cmd_out = NULL;
2071 } 2073 }
2072 if (ucs->urb_cmd_in) { 2074 if (ucs->urb_cmd_in) {
2073 usb_kill_urb(ucs->urb_cmd_in); 2075 usb_kill_urb(ucs->urb_cmd_in);
2074 dbg(DEBUG_INIT, "%s: command input URB unlinked", __func__); 2076 gig_dbg(DEBUG_INIT, "%s: command input URB unlinked",
2077 __func__);
2075 usb_free_urb(ucs->urb_cmd_in); 2078 usb_free_urb(ucs->urb_cmd_in);
2076 ucs->urb_cmd_in = NULL; 2079 ucs->urb_cmd_in = NULL;
2077 } 2080 }
2078 if (ucs->urb_ctrl) { 2081 if (ucs->urb_ctrl) {
2079 usb_kill_urb(ucs->urb_ctrl); 2082 usb_kill_urb(ucs->urb_ctrl);
2080 dbg(DEBUG_INIT, "%s: control output URB unlinked", __func__); 2083 gig_dbg(DEBUG_INIT, "%s: control output URB unlinked",
2084 __func__);
2081 usb_free_urb(ucs->urb_ctrl); 2085 usb_free_urb(ucs->urb_ctrl);
2082 ucs->urb_ctrl = NULL; 2086 ucs->urb_ctrl = NULL;
2083 } 2087 }
@@ -2097,35 +2101,24 @@ static int gigaset_probe(struct usb_interface *interface,
2097 struct bas_bc_state *ubc; 2101 struct bas_bc_state *ubc;
2098 struct usb_endpoint_descriptor *endpoint; 2102 struct usb_endpoint_descriptor *endpoint;
2099 int i, j; 2103 int i, j;
2100 int ret; 2104 int rc;
2101
2102 IFNULLRETVAL(udev, -ENODEV);
2103
2104 dbg(DEBUG_ANY,
2105 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
2106 __func__, le16_to_cpu(udev->descriptor.idVendor),
2107 le16_to_cpu(udev->descriptor.idProduct));
2108 2105
2109 /* See if the device offered us matches what we can accept */ 2106 gig_dbg(DEBUG_ANY,
2110 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) || 2107 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
2111 (le16_to_cpu(udev->descriptor.idProduct) != USB_GIGA_PRODUCT_ID && 2108 __func__, le16_to_cpu(udev->descriptor.idVendor),
2112 le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID && 2109 le16_to_cpu(udev->descriptor.idProduct));
2113 le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID &&
2114 le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) {
2115 dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__);
2116 return -ENODEV;
2117 }
2118 2110
2119 /* set required alternate setting */ 2111 /* set required alternate setting */
2120 hostif = interface->cur_altsetting; 2112 hostif = interface->cur_altsetting;
2121 if (hostif->desc.bAlternateSetting != 3) { 2113 if (hostif->desc.bAlternateSetting != 3) {
2122 dbg(DEBUG_ANY, 2114 gig_dbg(DEBUG_ANY,
2123 "%s: wrong alternate setting %d - trying to switch", 2115 "%s: wrong alternate setting %d - trying to switch",
2124 __func__, hostif->desc.bAlternateSetting); 2116 __func__, hostif->desc.bAlternateSetting);
2125 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) { 2117 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) {
2126 warn("usb_set_interface failed, device %d interface %d altsetting %d", 2118 dev_warn(&udev->dev, "usb_set_interface failed, "
2127 udev->devnum, hostif->desc.bInterfaceNumber, 2119 "device %d interface %d altsetting %d\n",
2128 hostif->desc.bAlternateSetting); 2120 udev->devnum, hostif->desc.bInterfaceNumber,
2121 hostif->desc.bAlternateSetting);
2129 return -ENODEV; 2122 return -ENODEV;
2130 } 2123 }
2131 hostif = interface->cur_altsetting; 2124 hostif = interface->cur_altsetting;
@@ -2134,68 +2127,50 @@ static int gigaset_probe(struct usb_interface *interface,
2134 /* Reject application specific interfaces 2127 /* Reject application specific interfaces
2135 */ 2128 */
2136 if (hostif->desc.bInterfaceClass != 255) { 2129 if (hostif->desc.bInterfaceClass != 255) {
2137 warn("%s: bInterfaceClass == %d", 2130 dev_warn(&udev->dev, "%s: bInterfaceClass == %d\n",
2138 __func__, hostif->desc.bInterfaceClass); 2131 __func__, hostif->desc.bInterfaceClass);
2139 return -ENODEV; 2132 return -ENODEV;
2140 } 2133 }
2141 2134
2142 info("%s: Device matched (Vendor: 0x%x, Product: 0x%x)", 2135 dev_info(&udev->dev,
2143 __func__, le16_to_cpu(udev->descriptor.idVendor), 2136 "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n",
2144 le16_to_cpu(udev->descriptor.idProduct)); 2137 __func__, le16_to_cpu(udev->descriptor.idVendor),
2138 le16_to_cpu(udev->descriptor.idProduct));
2145 2139
2146 cs = gigaset_getunassignedcs(driver); 2140 cs = gigaset_getunassignedcs(driver);
2147 if (!cs) { 2141 if (!cs) {
2148 err("%s: no free cardstate", __func__); 2142 dev_err(&udev->dev, "no free cardstate\n");
2149 return -ENODEV; 2143 return -ENODEV;
2150 } 2144 }
2151 ucs = cs->hw.bas; 2145 ucs = cs->hw.bas;
2146
2147 /* save off device structure ptrs for later use */
2148 usb_get_dev(udev);
2152 ucs->udev = udev; 2149 ucs->udev = udev;
2153 ucs->interface = interface; 2150 ucs->interface = interface;
2151 cs->dev = &interface->dev;
2154 2152
2155 /* allocate URBs: 2153 /* allocate URBs:
2156 * - one for the interrupt pipe 2154 * - one for the interrupt pipe
2157 * - three for the different uses of the default control pipe 2155 * - three for the different uses of the default control pipe
2158 * - three for each isochronous pipe 2156 * - three for each isochronous pipe
2159 */ 2157 */
2160 ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL); 2158 if (!(ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL)) ||
2161 if (!ucs->urb_int_in) { 2159 !(ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL)) ||
2162 err("No free urbs available"); 2160 !(ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL)) ||
2163 goto error; 2161 !(ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL)))
2164 } 2162 goto allocerr;
2165 ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL);
2166 if (!ucs->urb_cmd_in) {
2167 err("No free urbs available");
2168 goto error;
2169 }
2170 ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL);
2171 if (!ucs->urb_cmd_out) {
2172 err("No free urbs available");
2173 goto error;
2174 }
2175 ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL);
2176 if (!ucs->urb_ctrl) {
2177 err("No free urbs available");
2178 goto error;
2179 }
2180 2163
2181 for (j = 0; j < 2; ++j) { 2164 for (j = 0; j < 2; ++j) {
2182 ubc = cs->bcs[j].hw.bas; 2165 ubc = cs->bcs[j].hw.bas;
2183 for (i = 0; i < BAS_OUTURBS; ++i) { 2166 for (i = 0; i < BAS_OUTURBS; ++i)
2184 ubc->isoouturbs[i].urb = 2167 if (!(ubc->isoouturbs[i].urb =
2185 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL); 2168 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL)))
2186 if (!ubc->isoouturbs[i].urb) { 2169 goto allocerr;
2187 err("No free urbs available"); 2170 for (i = 0; i < BAS_INURBS; ++i)
2188 goto error; 2171 if (!(ubc->isoinurbs[i] =
2189 } 2172 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL)))
2190 } 2173 goto allocerr;
2191 for (i = 0; i < BAS_INURBS; ++i) {
2192 ubc->isoinurbs[i] =
2193 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
2194 if (!ubc->isoinurbs[i]) {
2195 err("No free urbs available");
2196 goto error;
2197 }
2198 }
2199 } 2174 }
2200 2175
2201 ucs->rcvbuf = NULL; 2176 ucs->rcvbuf = NULL;
@@ -2204,35 +2179,37 @@ static int gigaset_probe(struct usb_interface *interface,
2204 /* Fill the interrupt urb and send it to the core */ 2179 /* Fill the interrupt urb and send it to the core */
2205 endpoint = &hostif->endpoint[0].desc; 2180 endpoint = &hostif->endpoint[0].desc;
2206 usb_fill_int_urb(ucs->urb_int_in, udev, 2181 usb_fill_int_urb(ucs->urb_int_in, udev,
2207 usb_rcvintpipe(udev, 2182 usb_rcvintpipe(udev,
2208 (endpoint->bEndpointAddress) & 0x0f), 2183 (endpoint->bEndpointAddress) & 0x0f),
2209 ucs->int_in_buf, 3, read_int_callback, cs, 2184 ucs->int_in_buf, 3, read_int_callback, cs,
2210 endpoint->bInterval); 2185 endpoint->bInterval);
2211 ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL); 2186 if ((rc = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL)) != 0) {
2212 if (ret) { 2187 dev_err(cs->dev, "could not submit interrupt URB: %s\n",
2213 err("could not submit interrupt URB: %s", get_usb_statmsg(ret)); 2188 get_usb_rcmsg(rc));
2214 goto error; 2189 goto error;
2215 } 2190 }
2216 2191
2217 /* tell the device that the driver is ready */ 2192 /* tell the device that the driver is ready */
2218 if ((ret = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0)) != 0) 2193 if ((rc = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0)) != 0)
2219 goto error; 2194 goto error;
2220 2195
2221 /* tell common part that the device is ready */ 2196 /* tell common part that the device is ready */
2222 if (startmode == SM_LOCKED) 2197 if (startmode == SM_LOCKED)
2223 atomic_set(&cs->mstate, MS_LOCKED); 2198 atomic_set(&cs->mstate, MS_LOCKED);
2224 if (!gigaset_start(cs))
2225 goto error;
2226 2199
2227 /* save address of controller structure */ 2200 /* save address of controller structure */
2228 usb_set_intfdata(interface, cs); 2201 usb_set_intfdata(interface, cs);
2229 2202
2230 /* set up device sysfs */ 2203 if (!gigaset_start(cs))
2231 gigaset_init_dev_sysfs(interface); 2204 goto error;
2205
2232 return 0; 2206 return 0;
2233 2207
2208allocerr:
2209 dev_err(cs->dev, "could not allocate URBs\n");
2234error: 2210error:
2235 freeurbs(cs); 2211 freeurbs(cs);
2212 usb_set_intfdata(interface, NULL);
2236 gigaset_unassign(cs); 2213 gigaset_unassign(cs);
2237 return -ENODEV; 2214 return -ENODEV;
2238} 2215}
@@ -2244,24 +2221,38 @@ static void gigaset_disconnect(struct usb_interface *interface)
2244{ 2221{
2245 struct cardstate *cs; 2222 struct cardstate *cs;
2246 struct bas_cardstate *ucs; 2223 struct bas_cardstate *ucs;
2247 2224 int j;
2248 /* clear device sysfs */
2249 gigaset_free_dev_sysfs(interface);
2250 2225
2251 cs = usb_get_intfdata(interface); 2226 cs = usb_get_intfdata(interface);
2252 usb_set_intfdata(interface, NULL);
2253 2227
2254 IFNULLRET(cs);
2255 ucs = cs->hw.bas; 2228 ucs = cs->hw.bas;
2256 IFNULLRET(ucs);
2257 2229
2258 info("disconnecting GigaSet base"); 2230 dev_info(cs->dev, "disconnecting Gigaset base\n");
2231
2232 /* mark base as not ready, all channels disconnected */
2233 atomic_set(&ucs->basstate, 0);
2234
2235 /* tell LL all channels are down */
2236 //FIXME shouldn't gigaset_stop() do this?
2237 for (j = 0; j < 2; ++j)
2238 gigaset_bchannel_down(cs->bcs + j);
2239
2240 /* stop driver (common part) */
2259 gigaset_stop(cs); 2241 gigaset_stop(cs);
2242
2243 /* stop timers and URBs, free ressources */
2244 del_timer_sync(&ucs->timer_ctrl);
2245 del_timer_sync(&ucs->timer_atrdy);
2246 del_timer_sync(&ucs->timer_cmd_in);
2260 freeurbs(cs); 2247 freeurbs(cs);
2248 usb_set_intfdata(interface, NULL);
2261 kfree(ucs->rcvbuf); 2249 kfree(ucs->rcvbuf);
2262 ucs->rcvbuf = NULL; 2250 ucs->rcvbuf = NULL;
2263 ucs->rcvbuf_size = 0; 2251 ucs->rcvbuf_size = 0;
2264 atomic_set(&ucs->basstate, 0); 2252 usb_put_dev(ucs->udev);
2253 ucs->interface = NULL;
2254 ucs->udev = NULL;
2255 cs->dev = NULL;
2265 gigaset_unassign(cs); 2256 gigaset_unassign(cs);
2266} 2257}
2267 2258
@@ -2293,13 +2284,14 @@ static int __init bas_gigaset_init(void)
2293 2284
2294 /* allocate memory for our driver state and intialize it */ 2285 /* allocate memory for our driver state and intialize it */
2295 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 2286 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
2296 GIGASET_MODULENAME, GIGASET_DEVNAME, 2287 GIGASET_MODULENAME, GIGASET_DEVNAME,
2297 GIGASET_DEVFSNAME, &gigops, 2288 GIGASET_DEVFSNAME, &gigops,
2298 THIS_MODULE)) == NULL) 2289 THIS_MODULE)) == NULL)
2299 goto error; 2290 goto error;
2300 2291
2301 /* allocate memory for our device state and intialize it */ 2292 /* allocate memory for our device state and intialize it */
2302 cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode, GIGASET_MODULENAME); 2293 cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode,
2294 GIGASET_MODULENAME);
2303 if (!cardstate) 2295 if (!cardstate)
2304 goto error; 2296 goto error;
2305 2297
@@ -2328,22 +2320,35 @@ error: if (cardstate)
2328 */ 2320 */
2329static void __exit bas_gigaset_exit(void) 2321static void __exit bas_gigaset_exit(void)
2330{ 2322{
2323 struct bas_cardstate *ucs = cardstate->hw.bas;
2324
2331 gigaset_blockdriver(driver); /* => probe will fail 2325 gigaset_blockdriver(driver); /* => probe will fail
2332 * => no gigaset_start any more 2326 * => no gigaset_start any more
2333 */ 2327 */
2334 2328
2335 gigaset_shutdown(cardstate); 2329 gigaset_shutdown(cardstate);
2336 /* from now on, no isdn callback should be possible */ 2330 /* from now on, no isdn callback should be possible */
2337 2331
2338 if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) { 2332 /* close all still open channels */
2339 dbg(DEBUG_ANY, "closing AT channel"); 2333 if (atomic_read(&ucs->basstate) & BS_B1OPEN) {
2340 if (req_submit(cardstate->bcs, 2334 gig_dbg(DEBUG_INIT, "closing B1 channel");
2341 HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) { 2335 usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
2342 /* successfully submitted - wait for completion */ 2336 HD_CLOSE_B1CHANNEL, OUT_VENDOR_REQ, 0, 0,
2343 //wait_event_interruptible(cs->initwait, !cs->hw.bas->pending); 2337 NULL, 0, BAS_TIMEOUT);
2344 //FIXME need own wait queue? wakeup? 2338 }
2345 } 2339 if (atomic_read(&ucs->basstate) & BS_B2OPEN) {
2340 gig_dbg(DEBUG_INIT, "closing B2 channel");
2341 usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
2342 HD_CLOSE_B2CHANNEL, OUT_VENDOR_REQ, 0, 0,
2343 NULL, 0, BAS_TIMEOUT);
2344 }
2345 if (atomic_read(&ucs->basstate) & BS_ATOPEN) {
2346 gig_dbg(DEBUG_INIT, "closing AT channel");
2347 usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
2348 HD_CLOSE_ATCHANNEL, OUT_VENDOR_REQ, 0, 0,
2349 NULL, 0, BAS_TIMEOUT);
2346 } 2350 }
2351 atomic_set(&ucs->basstate, 0);
2347 2352
2348 /* deregister this driver with the USB subsystem */ 2353 /* deregister this driver with the USB subsystem */
2349 usb_deregister(&gigaset_usb_driver); 2354 usb_deregister(&gigaset_usb_driver);
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 64371995c1a9..e55767b2ccd3 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>. 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
@@ -11,10 +11,6 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: common.c,v 1.104.4.22 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
@@ -23,7 +19,7 @@
23#include <linux/moduleparam.h> 19#include <linux/moduleparam.h>
24 20
25/* Version Information */ 21/* Version Information */
26#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers <Eilers.Stefan@epost.de>" 22#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers"
27#define DRIVER_DESC "Driver for Gigaset 307x" 23#define DRIVER_DESC "Driver for Gigaset 307x"
28 24
29/* Module parameters */ 25/* Module parameters */
@@ -32,21 +28,10 @@ EXPORT_SYMBOL_GPL(gigaset_debuglevel);
32module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR); 28module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR);
33MODULE_PARM_DESC(debug, "debug level"); 29MODULE_PARM_DESC(debug, "debug level");
34 30
35/*====================================================================== 31/* driver state flags */
36 Prototypes of internal functions 32#define VALID_MINOR 0x01
37 */ 33#define VALID_ID 0x02
38 34#define ASSIGNED 0x04
39//static void gigaset_process_response(int resp_code, int parameter,
40// struct at_state_t *at_state,
41// unsigned char ** pstring);
42static struct cardstate *alloc_cs(struct gigaset_driver *drv);
43static void free_cs(struct cardstate *cs);
44static void make_valid(struct cardstate *cs, unsigned mask);
45static void make_invalid(struct cardstate *cs, unsigned mask);
46
47#define VALID_MINOR 0x01
48#define VALID_ID 0x02
49#define ASSIGNED 0x04
50 35
51/* bitwise byte inversion table */ 36/* bitwise byte inversion table */
52__u8 gigaset_invtab[256] = { 37__u8 gigaset_invtab[256] = {
@@ -86,42 +71,40 @@ __u8 gigaset_invtab[256] = {
86EXPORT_SYMBOL_GPL(gigaset_invtab); 71EXPORT_SYMBOL_GPL(gigaset_invtab);
87 72
88void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, 73void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
89 size_t len, const unsigned char *buf, int from_user) 74 size_t len, const unsigned char *buf)
90{ 75{
91 unsigned char outbuf[80]; 76 unsigned char outbuf[80];
92 unsigned char inbuf[80 - 1]; 77 unsigned char c;
93 size_t numin;
94 const unsigned char *in;
95 size_t space = sizeof outbuf - 1; 78 size_t space = sizeof outbuf - 1;
96 unsigned char *out = outbuf; 79 unsigned char *out = outbuf;
80 size_t numin = len;
97 81
98 if (!from_user) { 82 while (numin--) {
99 in = buf; 83 c = *buf++;
100 numin = len; 84 if (c == '~' || c == '^' || c == '\\') {
101 } else { 85 if (!space--)
102 numin = len < sizeof inbuf ? len : sizeof inbuf; 86 break;
103 in = inbuf; 87 *out++ = '\\';
104 if (copy_from_user(inbuf, (const unsigned char __user *) buf, numin)) {
105 strncpy(inbuf, "<FAULT>", sizeof inbuf);
106 numin = sizeof "<FAULT>" - 1;
107 } 88 }
108 } 89 if (c & 0x80) {
109 90 if (!space--)
110 for (; numin && space; --numin, ++in) { 91 break;
111 --space; 92 *out++ = '~';
112 if (*in >= 32) 93 c ^= 0x80;
113 *out++ = *in; 94 }
114 else { 95 if (c < 0x20 || c == 0x7f) {
96 if (!space--)
97 break;
115 *out++ = '^'; 98 *out++ = '^';
116 if (space) { 99 c ^= 0x40;
117 *out++ = '@' + *in;
118 --space;
119 }
120 } 100 }
101 if (!space--)
102 break;
103 *out++ = c;
121 } 104 }
122 *out = 0; 105 *out = 0;
123 106
124 dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf); 107 gig_dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf);
125} 108}
126EXPORT_SYMBOL_GPL(gigaset_dbg_buffer); 109EXPORT_SYMBOL_GPL(gigaset_dbg_buffer);
127 110
@@ -146,11 +129,6 @@ int gigaset_enterconfigmode(struct cardstate *cs)
146{ 129{
147 int i, r; 130 int i, r;
148 131
149 if (!atomic_read(&cs->connected)) {
150 err("not connected!");
151 return -1;
152 }
153
154 cs->control_state = TIOCM_RTS; //FIXME 132 cs->control_state = TIOCM_RTS; //FIXME
155 133
156 r = setflags(cs, TIOCM_DTR, 200); 134 r = setflags(cs, TIOCM_DTR, 200);
@@ -174,7 +152,7 @@ int gigaset_enterconfigmode(struct cardstate *cs)
174 return 0; 152 return 0;
175 153
176error: 154error:
177 err("error %d on setuartbits!\n", -r); 155 dev_err(cs->dev, "error %d on setuartbits\n", -r);
178 cs->control_state = TIOCM_RTS|TIOCM_DTR; // FIXME is this a good value? 156 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); 157 cs->ops->set_modem_ctrl(cs, 0, TIOCM_RTS|TIOCM_DTR);
180 158
@@ -187,13 +165,13 @@ static int test_timeout(struct at_state_t *at_state)
187 return 0; 165 return 0;
188 166
189 if (--at_state->timer_expires) { 167 if (--at_state->timer_expires) {
190 dbg(DEBUG_MCMD, "decreased timer of %p to %lu", 168 gig_dbg(DEBUG_MCMD, "decreased timer of %p to %lu",
191 at_state, at_state->timer_expires); 169 at_state, at_state->timer_expires);
192 return 0; 170 return 0;
193 } 171 }
194 172
195 if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL, 173 if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL,
196 atomic_read(&at_state->timer_index), NULL)) { 174 at_state->timer_index, NULL)) {
197 //FIXME what should we do? 175 //FIXME what should we do?
198 } 176 }
199 177
@@ -221,10 +199,10 @@ static void timer_tick(unsigned long data)
221 if (test_timeout(at_state)) 199 if (test_timeout(at_state))
222 timeout = 1; 200 timeout = 1;
223 201
224 if (atomic_read(&cs->running)) { 202 if (cs->running) {
225 mod_timer(&cs->timer, jiffies + GIG_TICK); 203 mod_timer(&cs->timer, jiffies + msecs_to_jiffies(GIG_TICK));
226 if (timeout) { 204 if (timeout) {
227 dbg(DEBUG_CMD, "scheduling timeout"); 205 gig_dbg(DEBUG_CMD, "scheduling timeout");
228 tasklet_schedule(&cs->event_tasklet); 206 tasklet_schedule(&cs->event_tasklet);
229 } 207 }
230 } 208 }
@@ -238,13 +216,14 @@ int gigaset_get_channel(struct bc_state *bcs)
238 216
239 spin_lock_irqsave(&bcs->cs->lock, flags); 217 spin_lock_irqsave(&bcs->cs->lock, flags);
240 if (bcs->use_count) { 218 if (bcs->use_count) {
241 dbg(DEBUG_ANY, "could not allocate channel %d", bcs->channel); 219 gig_dbg(DEBUG_ANY, "could not allocate channel %d",
220 bcs->channel);
242 spin_unlock_irqrestore(&bcs->cs->lock, flags); 221 spin_unlock_irqrestore(&bcs->cs->lock, flags);
243 return 0; 222 return 0;
244 } 223 }
245 ++bcs->use_count; 224 ++bcs->use_count;
246 bcs->busy = 1; 225 bcs->busy = 1;
247 dbg(DEBUG_ANY, "allocated channel %d", bcs->channel); 226 gig_dbg(DEBUG_ANY, "allocated channel %d", bcs->channel);
248 spin_unlock_irqrestore(&bcs->cs->lock, flags); 227 spin_unlock_irqrestore(&bcs->cs->lock, flags);
249 return 1; 228 return 1;
250} 229}
@@ -255,13 +234,13 @@ void gigaset_free_channel(struct bc_state *bcs)
255 234
256 spin_lock_irqsave(&bcs->cs->lock, flags); 235 spin_lock_irqsave(&bcs->cs->lock, flags);
257 if (!bcs->busy) { 236 if (!bcs->busy) {
258 dbg(DEBUG_ANY, "could not free channel %d", bcs->channel); 237 gig_dbg(DEBUG_ANY, "could not free channel %d", bcs->channel);
259 spin_unlock_irqrestore(&bcs->cs->lock, flags); 238 spin_unlock_irqrestore(&bcs->cs->lock, flags);
260 return; 239 return;
261 } 240 }
262 --bcs->use_count; 241 --bcs->use_count;
263 bcs->busy = 0; 242 bcs->busy = 0;
264 dbg(DEBUG_ANY, "freed channel %d", bcs->channel); 243 gig_dbg(DEBUG_ANY, "freed channel %d", bcs->channel);
265 spin_unlock_irqrestore(&bcs->cs->lock, flags); 244 spin_unlock_irqrestore(&bcs->cs->lock, flags);
266} 245}
267 246
@@ -274,14 +253,14 @@ int gigaset_get_channels(struct cardstate *cs)
274 for (i = 0; i < cs->channels; ++i) 253 for (i = 0; i < cs->channels; ++i)
275 if (cs->bcs[i].use_count) { 254 if (cs->bcs[i].use_count) {
276 spin_unlock_irqrestore(&cs->lock, flags); 255 spin_unlock_irqrestore(&cs->lock, flags);
277 dbg(DEBUG_ANY, "could not allocated all channels"); 256 gig_dbg(DEBUG_ANY, "could not allocate all channels");
278 return 0; 257 return 0;
279 } 258 }
280 for (i = 0; i < cs->channels; ++i) 259 for (i = 0; i < cs->channels; ++i)
281 ++cs->bcs[i].use_count; 260 ++cs->bcs[i].use_count;
282 spin_unlock_irqrestore(&cs->lock, flags); 261 spin_unlock_irqrestore(&cs->lock, flags);
283 262
284 dbg(DEBUG_ANY, "allocated all channels"); 263 gig_dbg(DEBUG_ANY, "allocated all channels");
285 264
286 return 1; 265 return 1;
287} 266}
@@ -291,7 +270,7 @@ void gigaset_free_channels(struct cardstate *cs)
291 unsigned long flags; 270 unsigned long flags;
292 int i; 271 int i;
293 272
294 dbg(DEBUG_ANY, "unblocking all channels"); 273 gig_dbg(DEBUG_ANY, "unblocking all channels");
295 spin_lock_irqsave(&cs->lock, flags); 274 spin_lock_irqsave(&cs->lock, flags);
296 for (i = 0; i < cs->channels; ++i) 275 for (i = 0; i < cs->channels; ++i)
297 --cs->bcs[i].use_count; 276 --cs->bcs[i].use_count;
@@ -303,7 +282,7 @@ void gigaset_block_channels(struct cardstate *cs)
303 unsigned long flags; 282 unsigned long flags;
304 int i; 283 int i;
305 284
306 dbg(DEBUG_ANY, "blocking all channels"); 285 gig_dbg(DEBUG_ANY, "blocking all channels");
307 spin_lock_irqsave(&cs->lock, flags); 286 spin_lock_irqsave(&cs->lock, flags);
308 for (i = 0; i < cs->channels; ++i) 287 for (i = 0; i < cs->channels; ++i)
309 ++cs->bcs[i].use_count; 288 ++cs->bcs[i].use_count;
@@ -314,25 +293,27 @@ static void clear_events(struct cardstate *cs)
314{ 293{
315 struct event_t *ev; 294 struct event_t *ev;
316 unsigned head, tail; 295 unsigned head, tail;
296 unsigned long flags;
317 297
318 /* no locking needed (no reader/writer allowed) */ 298 spin_lock_irqsave(&cs->ev_lock, flags);
319 299
320 head = atomic_read(&cs->ev_head); 300 head = cs->ev_head;
321 tail = atomic_read(&cs->ev_tail); 301 tail = cs->ev_tail;
322 302
323 while (tail != head) { 303 while (tail != head) {
324 ev = cs->events + head; 304 ev = cs->events + head;
325 kfree(ev->ptr); 305 kfree(ev->ptr);
326
327 head = (head + 1) % MAX_EVENTS; 306 head = (head + 1) % MAX_EVENTS;
328 } 307 }
329 308
330 atomic_set(&cs->ev_head, tail); 309 cs->ev_head = tail;
310
311 spin_unlock_irqrestore(&cs->ev_lock, flags);
331} 312}
332 313
333struct event_t *gigaset_add_event(struct cardstate *cs, 314struct event_t *gigaset_add_event(struct cardstate *cs,
334 struct at_state_t *at_state, int type, 315 struct at_state_t *at_state, int type,
335 void *ptr, int parameter, void *arg) 316 void *ptr, int parameter, void *arg)
336{ 317{
337 unsigned long flags; 318 unsigned long flags;
338 unsigned next, tail; 319 unsigned next, tail;
@@ -340,9 +321,9 @@ struct event_t *gigaset_add_event(struct cardstate *cs,
340 321
341 spin_lock_irqsave(&cs->ev_lock, flags); 322 spin_lock_irqsave(&cs->ev_lock, flags);
342 323
343 tail = atomic_read(&cs->ev_tail); 324 tail = cs->ev_tail;
344 next = (tail + 1) % MAX_EVENTS; 325 next = (tail + 1) % MAX_EVENTS;
345 if (unlikely(next == atomic_read(&cs->ev_head))) 326 if (unlikely(next == cs->ev_head))
346 err("event queue full"); 327 err("event queue full");
347 else { 328 else {
348 event = cs->events + tail; 329 event = cs->events + tail;
@@ -352,7 +333,7 @@ struct event_t *gigaset_add_event(struct cardstate *cs,
352 event->ptr = ptr; 333 event->ptr = ptr;
353 event->arg = arg; 334 event->arg = arg;
354 event->parameter = parameter; 335 event->parameter = parameter;
355 atomic_set(&cs->ev_tail, next); 336 cs->ev_tail = next;
356 } 337 }
357 338
358 spin_unlock_irqrestore(&cs->ev_lock, flags); 339 spin_unlock_irqrestore(&cs->ev_lock, flags);
@@ -391,14 +372,14 @@ static void gigaset_freebcs(struct bc_state *bcs)
391{ 372{
392 int i; 373 int i;
393 374
394 dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel); 375 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel);
395 if (!bcs->cs->ops->freebcshw(bcs)) { 376 if (!bcs->cs->ops->freebcshw(bcs)) {
396 dbg(DEBUG_INIT, "failed"); 377 gig_dbg(DEBUG_INIT, "failed");
397 } 378 }
398 379
399 dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel); 380 gig_dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel);
400 clear_at_state(&bcs->at_state); 381 clear_at_state(&bcs->at_state);
401 dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel); 382 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel);
402 383
403 if (bcs->skb) 384 if (bcs->skb)
404 dev_kfree_skb(bcs->skb); 385 dev_kfree_skb(bcs->skb);
@@ -408,6 +389,52 @@ static void gigaset_freebcs(struct bc_state *bcs)
408 } 389 }
409} 390}
410 391
392static struct cardstate *alloc_cs(struct gigaset_driver *drv)
393{
394 unsigned long flags;
395 unsigned i;
396 static struct cardstate *ret = NULL;
397
398 spin_lock_irqsave(&drv->lock, flags);
399 for (i = 0; i < drv->minors; ++i) {
400 if (!(drv->flags[i] & VALID_MINOR)) {
401 drv->flags[i] = VALID_MINOR;
402 ret = drv->cs + i;
403 }
404 if (ret)
405 break;
406 }
407 spin_unlock_irqrestore(&drv->lock, flags);
408 return ret;
409}
410
411static void free_cs(struct cardstate *cs)
412{
413 unsigned long flags;
414 struct gigaset_driver *drv = cs->driver;
415 spin_lock_irqsave(&drv->lock, flags);
416 drv->flags[cs->minor_index] = 0;
417 spin_unlock_irqrestore(&drv->lock, flags);
418}
419
420static void make_valid(struct cardstate *cs, unsigned mask)
421{
422 unsigned long flags;
423 struct gigaset_driver *drv = cs->driver;
424 spin_lock_irqsave(&drv->lock, flags);
425 drv->flags[cs->minor_index] |= mask;
426 spin_unlock_irqrestore(&drv->lock, flags);
427}
428
429static void make_invalid(struct cardstate *cs, unsigned mask)
430{
431 unsigned long flags;
432 struct gigaset_driver *drv = cs->driver;
433 spin_lock_irqsave(&drv->lock, flags);
434 drv->flags[cs->minor_index] &= ~mask;
435 spin_unlock_irqrestore(&drv->lock, flags);
436}
437
411void gigaset_freecs(struct cardstate *cs) 438void gigaset_freecs(struct cardstate *cs)
412{ 439{
413 int i; 440 int i;
@@ -416,7 +443,7 @@ void gigaset_freecs(struct cardstate *cs)
416 if (!cs) 443 if (!cs)
417 return; 444 return;
418 445
419 down(&cs->sem); 446 mutex_lock(&cs->mutex);
420 447
421 if (!cs->bcs) 448 if (!cs->bcs)
422 goto f_cs; 449 goto f_cs;
@@ -424,8 +451,9 @@ void gigaset_freecs(struct cardstate *cs)
424 goto f_bcs; 451 goto f_bcs;
425 452
426 spin_lock_irqsave(&cs->lock, flags); 453 spin_lock_irqsave(&cs->lock, flags);
427 atomic_set(&cs->running, 0); 454 cs->running = 0;
428 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are not rescheduled below */ 455 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are
456 not rescheduled below */
429 457
430 tasklet_kill(&cs->event_tasklet); 458 tasklet_kill(&cs->event_tasklet);
431 del_timer_sync(&cs->timer); 459 del_timer_sync(&cs->timer);
@@ -434,7 +462,7 @@ void gigaset_freecs(struct cardstate *cs)
434 default: 462 default:
435 gigaset_if_free(cs); 463 gigaset_if_free(cs);
436 464
437 dbg(DEBUG_INIT, "clearing hw"); 465 gig_dbg(DEBUG_INIT, "clearing hw");
438 cs->ops->freecshw(cs); 466 cs->ops->freecshw(cs);
439 467
440 //FIXME cmdbuf 468 //FIXME cmdbuf
@@ -443,36 +471,36 @@ void gigaset_freecs(struct cardstate *cs)
443 case 2: /* error in initcshw */ 471 case 2: /* error in initcshw */
444 /* Deregister from LL */ 472 /* Deregister from LL */
445 make_invalid(cs, VALID_ID); 473 make_invalid(cs, VALID_ID);
446 dbg(DEBUG_INIT, "clearing iif"); 474 gig_dbg(DEBUG_INIT, "clearing iif");
447 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD); 475 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
448 476
449 /* fall through */ 477 /* fall through */
450 case 1: /* error when regestering to LL */ 478 case 1: /* error when regestering to LL */
451 dbg(DEBUG_INIT, "clearing at_state"); 479 gig_dbg(DEBUG_INIT, "clearing at_state");
452 clear_at_state(&cs->at_state); 480 clear_at_state(&cs->at_state);
453 dealloc_at_states(cs); 481 dealloc_at_states(cs);
454 482
455 /* fall through */ 483 /* fall through */
456 case 0: /* error in one call to initbcs */ 484 case 0: /* error in one call to initbcs */
457 for (i = 0; i < cs->channels; ++i) { 485 for (i = 0; i < cs->channels; ++i) {
458 dbg(DEBUG_INIT, "clearing bcs[%d]", i); 486 gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i);
459 gigaset_freebcs(cs->bcs + i); 487 gigaset_freebcs(cs->bcs + i);
460 } 488 }
461 489
462 clear_events(cs); 490 clear_events(cs);
463 dbg(DEBUG_INIT, "freeing inbuf"); 491 gig_dbg(DEBUG_INIT, "freeing inbuf");
464 kfree(cs->inbuf); 492 kfree(cs->inbuf);
465 } 493 }
466f_bcs: dbg(DEBUG_INIT, "freeing bcs[]"); 494f_bcs: gig_dbg(DEBUG_INIT, "freeing bcs[]");
467 kfree(cs->bcs); 495 kfree(cs->bcs);
468f_cs: dbg(DEBUG_INIT, "freeing cs"); 496f_cs: gig_dbg(DEBUG_INIT, "freeing cs");
469 up(&cs->sem); 497 mutex_unlock(&cs->mutex);
470 free_cs(cs); 498 free_cs(cs);
471} 499}
472EXPORT_SYMBOL_GPL(gigaset_freecs); 500EXPORT_SYMBOL_GPL(gigaset_freecs);
473 501
474void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, 502void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
475 struct cardstate *cs, int cid) 503 struct cardstate *cs, int cid)
476{ 504{
477 int i; 505 int i;
478 506
@@ -482,8 +510,8 @@ void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
482 at_state->pending_commands = 0; 510 at_state->pending_commands = 0;
483 at_state->timer_expires = 0; 511 at_state->timer_expires = 0;
484 at_state->timer_active = 0; 512 at_state->timer_active = 0;
485 atomic_set(&at_state->timer_index, 0); 513 at_state->timer_index = 0;
486 atomic_set(&at_state->seq_index, 0); 514 at_state->seq_index = 0;
487 at_state->ConState = 0; 515 at_state->ConState = 0;
488 for (i = 0; i < STR_NUM; ++i) 516 for (i = 0; i < STR_NUM; ++i)
489 at_state->str_var[i] = NULL; 517 at_state->str_var[i] = NULL;
@@ -501,7 +529,7 @@ void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
501 529
502 530
503static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs, 531static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
504 struct cardstate *cs, int inputstate) 532 struct cardstate *cs, int inputstate)
505/* inbuf->read must be allocated before! */ 533/* inbuf->read must be allocated before! */
506{ 534{
507 atomic_set(&inbuf->head, 0); 535 atomic_set(&inbuf->head, 0);
@@ -512,9 +540,50 @@ static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
512 inbuf->inputstate = inputstate; 540 inbuf->inputstate = inputstate;
513} 541}
514 542
543/* append received bytes to inbuf */
544int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
545 unsigned numbytes)
546{
547 unsigned n, head, tail, bytesleft;
548
549 gig_dbg(DEBUG_INTR, "received %u bytes", numbytes);
550
551 if (!numbytes)
552 return 0;
553
554 bytesleft = numbytes;
555 tail = atomic_read(&inbuf->tail);
556 head = atomic_read(&inbuf->head);
557 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
558
559 while (bytesleft) {
560 if (head > tail)
561 n = head - 1 - tail;
562 else if (head == 0)
563 n = (RBUFSIZE-1) - tail;
564 else
565 n = RBUFSIZE - tail;
566 if (!n) {
567 dev_err(inbuf->cs->dev,
568 "buffer overflow (%u bytes lost)", bytesleft);
569 break;
570 }
571 if (n > bytesleft)
572 n = bytesleft;
573 memcpy(inbuf->data + tail, src, n);
574 bytesleft -= n;
575 tail = (tail + n) % RBUFSIZE;
576 src += n;
577 }
578 gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
579 atomic_set(&inbuf->tail, tail);
580 return numbytes != bytesleft;
581}
582EXPORT_SYMBOL_GPL(gigaset_fill_inbuf);
583
515/* Initialize the b-channel structure */ 584/* Initialize the b-channel structure */
516static struct bc_state *gigaset_initbcs(struct bc_state *bcs, 585static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
517 struct cardstate *cs, int channel) 586 struct cardstate *cs, int channel)
518{ 587{
519 int i; 588 int i;
520 589
@@ -526,7 +595,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
526 bcs->trans_down = 0; 595 bcs->trans_down = 0;
527 bcs->trans_up = 0; 596 bcs->trans_up = 0;
528 597
529 dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel); 598 gig_dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel);
530 gigaset_at_init(&bcs->at_state, bcs, cs, -1); 599 gigaset_at_init(&bcs->at_state, bcs, cs, -1);
531 600
532 bcs->rcvbytes = 0; 601 bcs->rcvbytes = 0;
@@ -535,7 +604,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
535 bcs->emptycount = 0; 604 bcs->emptycount = 0;
536#endif 605#endif
537 606
538 dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel); 607 gig_dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel);
539 bcs->fcs = PPP_INITFCS; 608 bcs->fcs = PPP_INITFCS;
540 bcs->inputstate = 0; 609 bcs->inputstate = 0;
541 if (cs->ignoreframes) { 610 if (cs->ignoreframes) {
@@ -544,7 +613,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
544 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 613 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
545 skb_reserve(bcs->skb, HW_HDR_LEN); 614 skb_reserve(bcs->skb, HW_HDR_LEN);
546 else { 615 else {
547 warn("could not allocate skb"); 616 dev_warn(cs->dev, "could not allocate skb\n");
548 bcs->inputstate |= INS_skip_frame; 617 bcs->inputstate |= INS_skip_frame;
549 } 618 }
550 619
@@ -559,14 +628,13 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
559 for (i = 0; i < AT_NUM; ++i) 628 for (i = 0; i < AT_NUM; ++i)
560 bcs->commands[i] = NULL; 629 bcs->commands[i] = NULL;
561 630
562 dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel); 631 gig_dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel);
563 if (cs->ops->initbcshw(bcs)) 632 if (cs->ops->initbcshw(bcs))
564 return bcs; 633 return bcs;
565 634
566//error: 635 gig_dbg(DEBUG_INIT, " failed");
567 dbg(DEBUG_INIT, " failed");
568 636
569 dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel); 637 gig_dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel);
570 if (bcs->skb) 638 if (bcs->skb)
571 dev_kfree_skb(bcs->skb); 639 dev_kfree_skb(bcs->skb);
572 640
@@ -578,9 +646,10 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
578 * Calls hardware dependent gigaset_initcshw() function 646 * Calls hardware dependent gigaset_initcshw() function
579 * Calls B channel initialization function gigaset_initbcs() for each B channel 647 * Calls B channel initialization function gigaset_initbcs() for each B channel
580 * parameters: 648 * parameters:
581 * drv hardware driver the device belongs to 649 * drv hardware driver the device belongs to
582 * channels number of B channels supported by device 650 * channels number of B channels supported by device
583 * onechannel !=0: B channel data and AT commands share one communication channel 651 * onechannel !=0: B channel data and AT commands share one
652 * communication channel
584 * ==0: B channels have separate communication channels 653 * ==0: B channels have separate communication channels
585 * ignoreframes number of frames to ignore after setting up B channel 654 * ignoreframes number of frames to ignore after setting up B channel
586 * cidmode !=0: start in CallID mode 655 * cidmode !=0: start in CallID mode
@@ -593,17 +662,18 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
593 int cidmode, const char *modulename) 662 int cidmode, const char *modulename)
594{ 663{
595 struct cardstate *cs = NULL; 664 struct cardstate *cs = NULL;
665 unsigned long flags;
596 int i; 666 int i;
597 667
598 dbg(DEBUG_INIT, "allocating cs"); 668 gig_dbg(DEBUG_INIT, "allocating cs");
599 cs = alloc_cs(drv); 669 cs = alloc_cs(drv);
600 if (!cs) 670 if (!cs)
601 goto error; 671 goto error;
602 dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1); 672 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
603 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL); 673 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
604 if (!cs->bcs) 674 if (!cs->bcs)
605 goto error; 675 goto error;
606 dbg(DEBUG_INIT, "allocating inbuf"); 676 gig_dbg(DEBUG_INIT, "allocating inbuf");
607 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL); 677 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
608 if (!cs->inbuf) 678 if (!cs->inbuf)
609 goto error; 679 goto error;
@@ -613,19 +683,23 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
613 cs->onechannel = onechannel; 683 cs->onechannel = onechannel;
614 cs->ignoreframes = ignoreframes; 684 cs->ignoreframes = ignoreframes;
615 INIT_LIST_HEAD(&cs->temp_at_states); 685 INIT_LIST_HEAD(&cs->temp_at_states);
616 atomic_set(&cs->running, 0); 686 cs->running = 0;
617 init_timer(&cs->timer); /* clear next & prev */ 687 init_timer(&cs->timer); /* clear next & prev */
618 spin_lock_init(&cs->ev_lock); 688 spin_lock_init(&cs->ev_lock);
619 atomic_set(&cs->ev_tail, 0); 689 cs->ev_tail = 0;
620 atomic_set(&cs->ev_head, 0); 690 cs->ev_head = 0;
621 init_MUTEX_LOCKED(&cs->sem); 691 mutex_init(&cs->mutex);
622 tasklet_init(&cs->event_tasklet, &gigaset_handle_event, (unsigned long) cs); 692 mutex_lock(&cs->mutex);
693
694 tasklet_init(&cs->event_tasklet, &gigaset_handle_event,
695 (unsigned long) cs);
623 atomic_set(&cs->commands_pending, 0); 696 atomic_set(&cs->commands_pending, 0);
624 cs->cur_at_seq = 0; 697 cs->cur_at_seq = 0;
625 cs->gotfwver = -1; 698 cs->gotfwver = -1;
626 cs->open_count = 0; 699 cs->open_count = 0;
700 cs->dev = NULL;
627 cs->tty = NULL; 701 cs->tty = NULL;
628 atomic_set(&cs->cidmode, cidmode != 0); 702 cs->cidmode = cidmode != 0;
629 703
630 //if(onechannel) { //FIXME 704 //if(onechannel) { //FIXME
631 cs->tabnocid = gigaset_tab_nocid_m10x; 705 cs->tabnocid = gigaset_tab_nocid_m10x;
@@ -642,50 +716,43 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
642 atomic_set(&cs->mstate, MS_UNINITIALIZED); 716 atomic_set(&cs->mstate, MS_UNINITIALIZED);
643 717
644 for (i = 0; i < channels; ++i) { 718 for (i = 0; i < channels; ++i) {
645 dbg(DEBUG_INIT, "setting up bcs[%d].read", i); 719 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
646 if (!gigaset_initbcs(cs->bcs + i, cs, i)) 720 if (!gigaset_initbcs(cs->bcs + i, cs, i))
647 goto error; 721 goto error;
648 } 722 }
649 723
650 ++cs->cs_init; 724 ++cs->cs_init;
651 725
652 dbg(DEBUG_INIT, "setting up at_state"); 726 gig_dbg(DEBUG_INIT, "setting up at_state");
653 spin_lock_init(&cs->lock); 727 spin_lock_init(&cs->lock);
654 gigaset_at_init(&cs->at_state, NULL, cs, 0); 728 gigaset_at_init(&cs->at_state, NULL, cs, 0);
655 cs->dle = 0; 729 cs->dle = 0;
656 cs->cbytes = 0; 730 cs->cbytes = 0;
657 731
658 dbg(DEBUG_INIT, "setting up inbuf"); 732 gig_dbg(DEBUG_INIT, "setting up inbuf");
659 if (onechannel) { //FIXME distinction necessary? 733 if (onechannel) { //FIXME distinction necessary?
660 gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command); 734 gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command);
661 } else 735 } else
662 gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command); 736 gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command);
663 737
664 atomic_set(&cs->connected, 0); 738 cs->connected = 0;
739 cs->isdn_up = 0;
665 740
666 dbg(DEBUG_INIT, "setting up cmdbuf"); 741 gig_dbg(DEBUG_INIT, "setting up cmdbuf");
667 cs->cmdbuf = cs->lastcmdbuf = NULL; 742 cs->cmdbuf = cs->lastcmdbuf = NULL;
668 spin_lock_init(&cs->cmdlock); 743 spin_lock_init(&cs->cmdlock);
669 cs->curlen = 0; 744 cs->curlen = 0;
670 cs->cmdbytes = 0; 745 cs->cmdbytes = 0;
671 746
672 /* 747 gig_dbg(DEBUG_INIT, "setting up iif");
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)) { 748 if (!gigaset_register_to_LL(cs, modulename)) {
682 err("register_isdn=>error"); 749 err("register_isdn failed");
683 goto error; 750 goto error;
684 } 751 }
685 752
686 make_valid(cs, VALID_ID); 753 make_valid(cs, VALID_ID);
687 ++cs->cs_init; 754 ++cs->cs_init;
688 dbg(DEBUG_INIT, "setting up hw"); 755 gig_dbg(DEBUG_INIT, "setting up hw");
689 if (!cs->ops->initcshw(cs)) 756 if (!cs->ops->initcshw(cs))
690 goto error; 757 goto error;
691 758
@@ -693,27 +760,28 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
693 760
694 gigaset_if_init(cs); 761 gigaset_if_init(cs);
695 762
696 atomic_set(&cs->running, 1); 763 spin_lock_irqsave(&cs->lock, flags);
697 cs->timer.data = (unsigned long) cs; 764 cs->running = 1;
698 cs->timer.function = timer_tick; 765 spin_unlock_irqrestore(&cs->lock, flags);
699 cs->timer.expires = jiffies + GIG_TICK; 766 setup_timer(&cs->timer, timer_tick, (unsigned long) cs);
767 cs->timer.expires = jiffies + msecs_to_jiffies(GIG_TICK);
700 /* FIXME: can jiffies increase too much until the timer is added? 768 /* FIXME: can jiffies increase too much until the timer is added?
701 * Same problem(?) with mod_timer() in timer_tick(). */ 769 * Same problem(?) with mod_timer() in timer_tick(). */
702 add_timer(&cs->timer); 770 add_timer(&cs->timer);
703 771
704 dbg(DEBUG_INIT, "cs initialized!"); 772 gig_dbg(DEBUG_INIT, "cs initialized");
705 up(&cs->sem); 773 mutex_unlock(&cs->mutex);
706 return cs; 774 return cs;
707 775
708error: if (cs) 776error: if (cs)
709 up(&cs->sem); 777 mutex_unlock(&cs->mutex);
710 dbg(DEBUG_INIT, "failed"); 778 gig_dbg(DEBUG_INIT, "failed");
711 gigaset_freecs(cs); 779 gigaset_freecs(cs);
712 return NULL; 780 return NULL;
713} 781}
714EXPORT_SYMBOL_GPL(gigaset_initcs); 782EXPORT_SYMBOL_GPL(gigaset_initcs);
715 783
716/* ReInitialize the b-channel structure */ /* e.g. called on hangup, disconnect */ 784/* ReInitialize the b-channel structure on hangup */
717void gigaset_bcs_reinit(struct bc_state *bcs) 785void gigaset_bcs_reinit(struct bc_state *bcs)
718{ 786{
719 struct sk_buff *skb; 787 struct sk_buff *skb;
@@ -723,12 +791,12 @@ void gigaset_bcs_reinit(struct bc_state *bcs)
723 while ((skb = skb_dequeue(&bcs->squeue)) != NULL) 791 while ((skb = skb_dequeue(&bcs->squeue)) != NULL)
724 dev_kfree_skb(skb); 792 dev_kfree_skb(skb);
725 793
726 spin_lock_irqsave(&cs->lock, flags); //FIXME 794 spin_lock_irqsave(&cs->lock, flags);
727 clear_at_state(&bcs->at_state); 795 clear_at_state(&bcs->at_state);
728 bcs->at_state.ConState = 0; 796 bcs->at_state.ConState = 0;
729 bcs->at_state.timer_active = 0; 797 bcs->at_state.timer_active = 0;
730 bcs->at_state.timer_expires = 0; 798 bcs->at_state.timer_expires = 0;
731 bcs->at_state.cid = -1; /* No CID defined */ 799 bcs->at_state.cid = -1; /* No CID defined */
732 spin_unlock_irqrestore(&cs->lock, flags); 800 spin_unlock_irqrestore(&cs->lock, flags);
733 801
734 bcs->inputstate = 0; 802 bcs->inputstate = 0;
@@ -803,11 +871,14 @@ static void cleanup_cs(struct cardstate *cs)
803 871
804int gigaset_start(struct cardstate *cs) 872int gigaset_start(struct cardstate *cs)
805{ 873{
806 if (down_interruptible(&cs->sem)) 874 unsigned long flags;
875
876 if (mutex_lock_interruptible(&cs->mutex))
807 return 0; 877 return 0;
808 //info("USB device for Gigaset 307x now attached to Dev %d", ucs->minor);
809 878
810 atomic_set(&cs->connected, 1); 879 spin_lock_irqsave(&cs->lock, flags);
880 cs->connected = 1;
881 spin_unlock_irqrestore(&cs->lock, flags);
811 882
812 if (atomic_read(&cs->mstate) != MS_LOCKED) { 883 if (atomic_read(&cs->mstate) != MS_LOCKED) {
813 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS); 884 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
@@ -826,23 +897,26 @@ int gigaset_start(struct cardstate *cs)
826 goto error; 897 goto error;
827 } 898 }
828 899
829 dbg(DEBUG_CMD, "scheduling START"); 900 gig_dbg(DEBUG_CMD, "scheduling START");
830 gigaset_schedule_event(cs); 901 gigaset_schedule_event(cs);
831 902
832 wait_event(cs->waitqueue, !cs->waiting); 903 wait_event(cs->waitqueue, !cs->waiting);
833 904
834 up(&cs->sem); 905 /* set up device sysfs */
906 gigaset_init_dev_sysfs(cs);
907
908 mutex_unlock(&cs->mutex);
835 return 1; 909 return 1;
836 910
837error: 911error:
838 up(&cs->sem); 912 mutex_unlock(&cs->mutex);
839 return 0; 913 return 0;
840} 914}
841EXPORT_SYMBOL_GPL(gigaset_start); 915EXPORT_SYMBOL_GPL(gigaset_start);
842 916
843void gigaset_shutdown(struct cardstate *cs) 917void gigaset_shutdown(struct cardstate *cs)
844{ 918{
845 down(&cs->sem); 919 mutex_lock(&cs->mutex);
846 920
847 cs->waiting = 1; 921 cs->waiting = 1;
848 922
@@ -851,11 +925,11 @@ void gigaset_shutdown(struct cardstate *cs)
851 goto exit; 925 goto exit;
852 } 926 }
853 927
854 dbg(DEBUG_CMD, "scheduling SHUTDOWN"); 928 gig_dbg(DEBUG_CMD, "scheduling SHUTDOWN");
855 gigaset_schedule_event(cs); 929 gigaset_schedule_event(cs);
856 930
857 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { 931 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) {
858 warn("aborted"); 932 warn("%s: aborted", __func__);
859 //FIXME 933 //FIXME
860 } 934 }
861 935
@@ -872,15 +946,13 @@ void gigaset_shutdown(struct cardstate *cs)
872 cleanup_cs(cs); 946 cleanup_cs(cs);
873 947
874exit: 948exit:
875 up(&cs->sem); 949 mutex_unlock(&cs->mutex);
876} 950}
877EXPORT_SYMBOL_GPL(gigaset_shutdown); 951EXPORT_SYMBOL_GPL(gigaset_shutdown);
878 952
879void gigaset_stop(struct cardstate *cs) 953void gigaset_stop(struct cardstate *cs)
880{ 954{
881 down(&cs->sem); 955 mutex_lock(&cs->mutex);
882
883 atomic_set(&cs->connected, 0);
884 956
885 cs->waiting = 1; 957 cs->waiting = 1;
886 958
@@ -889,21 +961,21 @@ void gigaset_stop(struct cardstate *cs)
889 goto exit; 961 goto exit;
890 } 962 }
891 963
892 dbg(DEBUG_CMD, "scheduling STOP"); 964 gig_dbg(DEBUG_CMD, "scheduling STOP");
893 gigaset_schedule_event(cs); 965 gigaset_schedule_event(cs);
894 966
895 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { 967 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) {
896 warn("aborted"); 968 warn("%s: aborted", __func__);
897 //FIXME 969 //FIXME
898 } 970 }
899 971
900 /* Tell the LL that the device is not available .. */ 972 /* clear device sysfs */
901 gigaset_i4l_cmd(cs, ISDN_STAT_STOP); // FIXME move to event layer? 973 gigaset_free_dev_sysfs(cs);
902 974
903 cleanup_cs(cs); 975 cleanup_cs(cs);
904 976
905exit: 977exit:
906 up(&cs->sem); 978 mutex_unlock(&cs->mutex);
907} 979}
908EXPORT_SYMBOL_GPL(gigaset_stop); 980EXPORT_SYMBOL_GPL(gigaset_stop);
909 981
@@ -947,31 +1019,25 @@ void gigaset_debugdrivers(void)
947 1019
948 spin_lock_irqsave(&driver_lock, flags); 1020 spin_lock_irqsave(&driver_lock, flags);
949 list_for_each_entry(drv, &drivers, list) { 1021 list_for_each_entry(drv, &drivers, list) {
950 dbg(DEBUG_DRIVER, "driver %p", drv); 1022 gig_dbg(DEBUG_DRIVER, "driver %p", drv);
951 spin_lock(&drv->lock); 1023 spin_lock(&drv->lock);
952 for (i = 0; i < drv->minors; ++i) { 1024 for (i = 0; i < drv->minors; ++i) {
953 dbg(DEBUG_DRIVER, " index %u", i); 1025 gig_dbg(DEBUG_DRIVER, " index %u", i);
954 dbg(DEBUG_DRIVER, " flags 0x%02x", drv->flags[i]); 1026 gig_dbg(DEBUG_DRIVER, " flags 0x%02x",
1027 drv->flags[i]);
955 cs = drv->cs + i; 1028 cs = drv->cs + i;
956 dbg(DEBUG_DRIVER, " cardstate %p", cs); 1029 gig_dbg(DEBUG_DRIVER, " cardstate %p", cs);
957 dbg(DEBUG_DRIVER, " minor_index %u", cs->minor_index); 1030 gig_dbg(DEBUG_DRIVER, " minor_index %u",
958 dbg(DEBUG_DRIVER, " driver %p", cs->driver); 1031 cs->minor_index);
959 dbg(DEBUG_DRIVER, " i4l id %d", cs->myid); 1032 gig_dbg(DEBUG_DRIVER, " driver %p", cs->driver);
1033 gig_dbg(DEBUG_DRIVER, " i4l id %d", cs->myid);
960 } 1034 }
961 spin_unlock(&drv->lock); 1035 spin_unlock(&drv->lock);
962 } 1036 }
963 spin_unlock_irqrestore(&driver_lock, flags); 1037 spin_unlock_irqrestore(&driver_lock, flags);
964} 1038}
965EXPORT_SYMBOL_GPL(gigaset_debugdrivers);
966
967struct 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 1039
974struct cardstate *gigaset_get_cs_by_minor(unsigned minor) 1040static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
975{ 1041{
976 unsigned long flags; 1042 unsigned long flags;
977 static struct cardstate *ret = NULL; 1043 static struct cardstate *ret = NULL;
@@ -994,6 +1060,13 @@ struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
994 return ret; 1060 return ret;
995} 1061}
996 1062
1063struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
1064{
1065 if (tty->index < 0 || tty->index >= tty->driver->num)
1066 return NULL;
1067 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
1068}
1069
997void gigaset_freedriver(struct gigaset_driver *drv) 1070void gigaset_freedriver(struct gigaset_driver *drv)
998{ 1071{
999 unsigned long flags; 1072 unsigned long flags;
@@ -1014,20 +1087,20 @@ EXPORT_SYMBOL_GPL(gigaset_freedriver);
1014/* gigaset_initdriver 1087/* gigaset_initdriver
1015 * Allocate and initialize gigaset_driver structure. Initialize interface. 1088 * Allocate and initialize gigaset_driver structure. Initialize interface.
1016 * parameters: 1089 * parameters:
1017 * minor First minor number 1090 * minor First minor number
1018 * minors Number of minors this driver can handle 1091 * minors Number of minors this driver can handle
1019 * procname Name of the driver (e.g. for /proc/tty/drivers, path in /proc/driver) 1092 * procname Name of the driver
1020 * devname Name of the device files (prefix without minor number) 1093 * devname Name of the device files (prefix without minor number)
1021 * devfsname Devfs name of the device files without %d 1094 * devfsname Devfs name of the device files without %d
1022 * return value: 1095 * return value:
1023 * Pointer to the gigaset_driver structure on success, NULL on failure. 1096 * Pointer to the gigaset_driver structure on success, NULL on failure.
1024 */ 1097 */
1025struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, 1098struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1026 const char *procname, 1099 const char *procname,
1027 const char *devname, 1100 const char *devname,
1028 const char *devfsname, 1101 const char *devfsname,
1029 const struct gigaset_ops *ops, 1102 const struct gigaset_ops *ops,
1030 struct module *owner) 1103 struct module *owner)
1031{ 1104{
1032 struct gigaset_driver *drv; 1105 struct gigaset_driver *drv;
1033 unsigned long flags; 1106 unsigned long flags;
@@ -1036,8 +1109,9 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1036 drv = kmalloc(sizeof *drv, GFP_KERNEL); 1109 drv = kmalloc(sizeof *drv, GFP_KERNEL);
1037 if (!drv) 1110 if (!drv)
1038 return NULL; 1111 return NULL;
1112
1039 if (!try_module_get(owner)) 1113 if (!try_module_get(owner))
1040 return NULL; 1114 goto out1;
1041 1115
1042 drv->cs = NULL; 1116 drv->cs = NULL;
1043 drv->have_tty = 0; 1117 drv->have_tty = 0;
@@ -1051,10 +1125,11 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1051 1125
1052 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL); 1126 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1053 if (!drv->cs) 1127 if (!drv->cs)
1054 goto out1; 1128 goto out2;
1129
1055 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL); 1130 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
1056 if (!drv->flags) 1131 if (!drv->flags)
1057 goto out2; 1132 goto out3;
1058 1133
1059 for (i = 0; i < minors; ++i) { 1134 for (i = 0; i < minors; ++i) {
1060 drv->flags[i] = 0; 1135 drv->flags[i] = 0;
@@ -1071,61 +1146,16 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1071 1146
1072 return drv; 1147 return drv;
1073 1148
1074out2: 1149out3:
1075 kfree(drv->cs); 1150 kfree(drv->cs);
1151out2:
1152 module_put(owner);
1076out1: 1153out1:
1077 kfree(drv); 1154 kfree(drv);
1078 module_put(owner);
1079 return NULL; 1155 return NULL;
1080} 1156}
1081EXPORT_SYMBOL_GPL(gigaset_initdriver); 1157EXPORT_SYMBOL_GPL(gigaset_initdriver);
1082 1158
1083static 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
1102static 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
1111static 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
1120static 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) */ 1159/* For drivers without fixed assignment device<->cardstate (usb) */
1130struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv) 1160struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv)
1131{ 1161{
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index fdcb80bb21c7..18e05c09b71c 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>. 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
@@ -11,82 +11,78 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: ev-layer.c,v 1.4.2.18 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
21 17
22/* ========================================================== */ 18/* ========================================================== */
23/* bit masks for pending commands */ 19/* bit masks for pending commands */
24#define PC_INIT 0x004 20#define PC_DIAL 0x001
25#define PC_DLE0 0x008 21#define PC_HUP 0x002
26#define PC_DLE1 0x010 22#define PC_INIT 0x004
27#define PC_CID 0x080 23#define PC_DLE0 0x008
28#define PC_NOCID 0x100 24#define PC_DLE1 0x010
29#define PC_HUP 0x002 25#define PC_SHUTDOWN 0x020
30#define PC_DIAL 0x001 26#define PC_ACCEPT 0x040
31#define PC_ACCEPT 0x040 27#define PC_CID 0x080
32#define PC_SHUTDOWN 0x020 28#define PC_NOCID 0x100
33#define PC_CIDMODE 0x200 29#define PC_CIDMODE 0x200
34#define PC_UMMODE 0x400 30#define PC_UMMODE 0x400
35 31
36/* types of modem responses */ 32/* types of modem responses */
37#define RT_NOTHING 0 33#define RT_NOTHING 0
38#define RT_ZSAU 1 34#define RT_ZSAU 1
39#define RT_RING 2 35#define RT_RING 2
40#define RT_NUMBER 3 36#define RT_NUMBER 3
41#define RT_STRING 4 37#define RT_STRING 4
42#define RT_HEX 5 38#define RT_HEX 5
43#define RT_ZCAU 6 39#define RT_ZCAU 6
44 40
45/* Possible ASCII responses */ 41/* Possible ASCII responses */
46#define RSP_OK 0 42#define RSP_OK 0
47//#define RSP_BUSY 1 43//#define RSP_BUSY 1
48//#define RSP_CONNECT 2 44//#define RSP_CONNECT 2
49#define RSP_ZGCI 3 45#define RSP_ZGCI 3
50#define RSP_RING 4 46#define RSP_RING 4
51#define RSP_ZAOC 5 47#define RSP_ZAOC 5
52#define RSP_ZCSTR 6 48#define RSP_ZCSTR 6
53#define RSP_ZCFGT 7 49#define RSP_ZCFGT 7
54#define RSP_ZCFG 8 50#define RSP_ZCFG 8
55#define RSP_ZCCR 9 51#define RSP_ZCCR 9
56#define RSP_EMPTY 10 52#define RSP_EMPTY 10
57#define RSP_ZLOG 11 53#define RSP_ZLOG 11
58#define RSP_ZCAU 12 54#define RSP_ZCAU 12
59#define RSP_ZMWI 13 55#define RSP_ZMWI 13
60#define RSP_ZABINFO 14 56#define RSP_ZABINFO 14
61#define RSP_ZSMLSTCHG 15 57#define RSP_ZSMLSTCHG 15
62#define RSP_VAR 100 58#define RSP_VAR 100
63#define RSP_ZSAU (RSP_VAR + VAR_ZSAU) 59#define RSP_ZSAU (RSP_VAR + VAR_ZSAU)
64#define RSP_ZDLE (RSP_VAR + VAR_ZDLE) 60#define RSP_ZDLE (RSP_VAR + VAR_ZDLE)
65#define RSP_ZVLS (RSP_VAR + VAR_ZVLS) 61#define RSP_ZVLS (RSP_VAR + VAR_ZVLS)
66#define RSP_ZCTP (RSP_VAR + VAR_ZCTP) 62#define RSP_ZCTP (RSP_VAR + VAR_ZCTP)
67#define RSP_STR (RSP_VAR + VAR_NUM) 63#define RSP_STR (RSP_VAR + VAR_NUM)
68#define RSP_NMBR (RSP_STR + STR_NMBR) 64#define RSP_NMBR (RSP_STR + STR_NMBR)
69#define RSP_ZCPN (RSP_STR + STR_ZCPN) 65#define RSP_ZCPN (RSP_STR + STR_ZCPN)
70#define RSP_ZCON (RSP_STR + STR_ZCON) 66#define RSP_ZCON (RSP_STR + STR_ZCON)
71#define RSP_ZBC (RSP_STR + STR_ZBC) 67#define RSP_ZBC (RSP_STR + STR_ZBC)
72#define RSP_ZHLC (RSP_STR + STR_ZHLC) 68#define RSP_ZHLC (RSP_STR + STR_ZHLC)
73#define RSP_ERROR -1 /* ERROR */ 69#define RSP_ERROR -1 /* ERROR */
74#define RSP_WRONG_CID -2 /* unknown cid in cmd */ 70#define RSP_WRONG_CID -2 /* unknown cid in cmd */
75//#define RSP_EMPTY -3 71//#define RSP_EMPTY -3
76#define RSP_UNKNOWN -4 /* unknown response */ 72#define RSP_UNKNOWN -4 /* unknown response */
77#define RSP_FAIL -5 /* internal error */ 73#define RSP_FAIL -5 /* internal error */
78#define RSP_INVAL -6 /* invalid response */ 74#define RSP_INVAL -6 /* invalid response */
79 75
80#define RSP_NONE -19 76#define RSP_NONE -19
81#define RSP_STRING -20 77#define RSP_STRING -20
82#define RSP_NULL -21 78#define RSP_NULL -21
83//#define RSP_RETRYFAIL -22 79//#define RSP_RETRYFAIL -22
84//#define RSP_RETRY -23 80//#define RSP_RETRY -23
85//#define RSP_SKIP -24 81//#define RSP_SKIP -24
86#define RSP_INIT -27 82#define RSP_INIT -27
87#define RSP_ANY -26 83#define RSP_ANY -26
88#define RSP_LAST -28 84#define RSP_LAST -28
89#define RSP_NODEV -9 85#define RSP_NODEV -9
90 86
91/* actions for process_response */ 87/* actions for process_response */
92#define ACT_NOTHING 0 88#define ACT_NOTHING 0
@@ -112,7 +108,7 @@
112#define ACT_DISCONNECT 20 108#define ACT_DISCONNECT 20
113#define ACT_CONNECT 21 109#define ACT_CONNECT 21
114#define ACT_REMOTEREJECT 22 110#define ACT_REMOTEREJECT 22
115#define ACT_CONNTIMEOUT 23 111#define ACT_CONNTIMEOUT 23
116#define ACT_REMOTEHUP 24 112#define ACT_REMOTEHUP 24
117#define ACT_ABORTHUP 25 113#define ACT_ABORTHUP 25
118#define ACT_ICALL 26 114#define ACT_ICALL 26
@@ -127,40 +123,40 @@
127#define ACT_ERROR 35 123#define ACT_ERROR 35
128#define ACT_ABORTCID 36 124#define ACT_ABORTCID 36
129#define ACT_ZCAU 37 125#define ACT_ZCAU 37
130#define ACT_NOTIFY_BC_DOWN 38 126#define ACT_NOTIFY_BC_DOWN 38
131#define ACT_NOTIFY_BC_UP 39 127#define ACT_NOTIFY_BC_UP 39
132#define ACT_DIAL 40 128#define ACT_DIAL 40
133#define ACT_ACCEPT 41 129#define ACT_ACCEPT 41
134#define ACT_PROTO_L2 42 130#define ACT_PROTO_L2 42
135#define ACT_HUP 43 131#define ACT_HUP 43
136#define ACT_IF_LOCK 44 132#define ACT_IF_LOCK 44
137#define ACT_START 45 133#define ACT_START 45
138#define ACT_STOP 46 134#define ACT_STOP 46
139#define ACT_FAKEDLE0 47 135#define ACT_FAKEDLE0 47
140#define ACT_FAKEHUP 48 136#define ACT_FAKEHUP 48
141#define ACT_FAKESDOWN 49 137#define ACT_FAKESDOWN 49
142#define ACT_SHUTDOWN 50 138#define ACT_SHUTDOWN 50
143#define ACT_PROC_CIDMODE 51 139#define ACT_PROC_CIDMODE 51
144#define ACT_UMODESET 52 140#define ACT_UMODESET 52
145#define ACT_FAILUMODE 53 141#define ACT_FAILUMODE 53
146#define ACT_CMODESET 54 142#define ACT_CMODESET 54
147#define ACT_FAILCMODE 55 143#define ACT_FAILCMODE 55
148#define ACT_IF_VER 56 144#define ACT_IF_VER 56
149#define ACT_CMD 100 145#define ACT_CMD 100
150 146
151/* at command sequences */ 147/* at command sequences */
152#define SEQ_NONE 0 148#define SEQ_NONE 0
153#define SEQ_INIT 100 149#define SEQ_INIT 100
154#define SEQ_DLE0 200 150#define SEQ_DLE0 200
155#define SEQ_DLE1 250 151#define SEQ_DLE1 250
156#define SEQ_CID 300 152#define SEQ_CID 300
157#define SEQ_NOCID 350 153#define SEQ_NOCID 350
158#define SEQ_HUP 400 154#define SEQ_HUP 400
159#define SEQ_DIAL 600 155#define SEQ_DIAL 600
160#define SEQ_ACCEPT 720 156#define SEQ_ACCEPT 720
161#define SEQ_SHUTDOWN 500 157#define SEQ_SHUTDOWN 500
162#define SEQ_CIDMODE 10 158#define SEQ_CIDMODE 10
163#define SEQ_UMMODE 11 159#define SEQ_UMMODE 11
164 160
165 161
166// 100: init, 200: dle0, 250:dle1, 300: get cid (dial), 350: "hup" (no cid), 400: hup, 500: reset, 600: dial, 700: ring 162// 100: init, 200: dle0, 250:dle1, 300: get cid (dial), 350: "hup" (no cid), 400: hup, 500: reset, 600: dial, 700: ring
@@ -175,7 +171,7 @@ struct reply_t gigaset_tab_nocid_m10x[]= /* with dle mode */
175 // {ACT_TIMEOUT}}, 171 // {ACT_TIMEOUT}},
176 172
177 {RSP_INIT, -1, -1,SEQ_INIT, 100, INIT_TIMEOUT, 173 {RSP_INIT, -1, -1,SEQ_INIT, 100, INIT_TIMEOUT,
178 {ACT_TIMEOUT}}, /* wait until device is ready */ 174 {ACT_TIMEOUT}}, /* wait until device is ready */
179 175
180 {EV_TIMEOUT, 100,100, -1, 101, 3, {0}, "Z\r"}, /* device in transparent mode? try to initialize it. */ 176 {EV_TIMEOUT, 100,100, -1, 101, 3, {0}, "Z\r"}, /* device in transparent mode? try to initialize it. */
181 {RSP_OK, 101,103, -1, 120, 5, {ACT_GETSTRING}, "+GMR\r"}, /* get version */ 177 {RSP_OK, 101,103, -1, 120, 5, {ACT_GETSTRING}, "+GMR\r"}, /* get version */
@@ -190,8 +186,8 @@ struct reply_t gigaset_tab_nocid_m10x[]= /* with dle mode */
190 {RSP_ERROR, 108,108, -1, 0, 0, {ACT_FAILINIT}}, 186 {RSP_ERROR, 108,108, -1, 0, 0, {ACT_FAILINIT}},
191 187
192 {EV_TIMEOUT, 108,108, -1, 105, 2, {ACT_SETDLE0, 188 {EV_TIMEOUT, 108,108, -1, 105, 2, {ACT_SETDLE0,
193 ACT_HUPMODEM, 189 ACT_HUPMODEM,
194 ACT_TIMEOUT}}, /* still timeout => connection in unimodem mode? */ 190 ACT_TIMEOUT}}, /* still timeout => connection in unimodem mode? */
195 {EV_TIMEOUT, 105,105, -1, 103, 5, {0}, "Z\r"}, 191 {EV_TIMEOUT, 105,105, -1, 103, 5, {0}, "Z\r"},
196 192
197 {RSP_ERROR, 102,102, -1, 107, 5, {0}, "^GETPRE\r"}, /* ERROR on ATZ => maybe in config mode? */ 193 {RSP_ERROR, 102,102, -1, 107, 5, {0}, "^GETPRE\r"}, /* ERROR on ATZ => maybe in config mode? */
@@ -377,6 +373,9 @@ struct reply_t gigaset_tab_cid_m10x[] = /* for M10x */
377 373
378 {EV_TIMEOUT, 750,750, -1, 0, 0, {ACT_CONNTIMEOUT}}, 374 {EV_TIMEOUT, 750,750, -1, 0, 0, {ACT_CONNTIMEOUT}},
379 375
376 /* B channel closed (general case) */
377 {EV_BC_CLOSED, -1, -1, -1, -1,-1, {ACT_NOTIFY_BC_DOWN}}, //FIXME
378
380 /* misc. */ 379 /* misc. */
381 {EV_PROTO_L2, -1, -1, -1, -1,-1, {ACT_PROTO_L2}}, //FIXME 380 {EV_PROTO_L2, -1, -1, -1, -1,-1, {ACT_PROTO_L2}}, //FIXME
382 381
@@ -393,7 +392,7 @@ struct reply_t gigaset_tab_cid_m10x[] = /* for M10x */
393 392
394 393
395#if 0 394#if 0
396static struct reply_t tab_nocid[]= /* no dle mode */ //FIXME aenderungen uebernehmen 395static struct reply_t tab_nocid[]= /* no dle mode */ //FIXME
397{ 396{
398 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */ 397 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
399 398
@@ -401,7 +400,7 @@ static struct reply_t tab_nocid[]= /* no dle mode */ //FIXME aenderungen ueberne
401 {RSP_LAST,0,0,0,0,0,0} 400 {RSP_LAST,0,0,0,0,0,0}
402}; 401};
403 402
404static struct reply_t tab_cid[] = /* no dle mode */ //FIXME aenderungen uebernehmen 403static struct reply_t tab_cid[] = /* no dle mode */ //FIXME
405{ 404{
406 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */ 405 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
407 406
@@ -412,30 +411,30 @@ static struct reply_t tab_cid[] = /* no dle mode */ //FIXME aenderungen ueberneh
412 411
413static struct resp_type_t resp_type[]= 412static struct resp_type_t resp_type[]=
414{ 413{
415 /*{"", RSP_EMPTY, RT_NOTHING},*/ 414 /*{"", RSP_EMPTY, RT_NOTHING},*/
416 {"OK", RSP_OK, RT_NOTHING}, 415 {"OK", RSP_OK, RT_NOTHING},
417 {"ERROR", RSP_ERROR, RT_NOTHING}, 416 {"ERROR", RSP_ERROR, RT_NOTHING},
418 {"ZSAU", RSP_ZSAU, RT_ZSAU}, 417 {"ZSAU", RSP_ZSAU, RT_ZSAU},
419 {"ZCAU", RSP_ZCAU, RT_ZCAU}, 418 {"ZCAU", RSP_ZCAU, RT_ZCAU},
420 {"RING", RSP_RING, RT_RING}, 419 {"RING", RSP_RING, RT_RING},
421 {"ZGCI", RSP_ZGCI, RT_NUMBER}, 420 {"ZGCI", RSP_ZGCI, RT_NUMBER},
422 {"ZVLS", RSP_ZVLS, RT_NUMBER}, 421 {"ZVLS", RSP_ZVLS, RT_NUMBER},
423 {"ZCTP", RSP_ZCTP, RT_NUMBER}, 422 {"ZCTP", RSP_ZCTP, RT_NUMBER},
424 {"ZDLE", RSP_ZDLE, RT_NUMBER}, 423 {"ZDLE", RSP_ZDLE, RT_NUMBER},
425 {"ZCFGT", RSP_ZCFGT, RT_NUMBER}, 424 {"ZCFGT", RSP_ZCFGT, RT_NUMBER},
426 {"ZCCR", RSP_ZCCR, RT_NUMBER}, 425 {"ZCCR", RSP_ZCCR, RT_NUMBER},
427 {"ZMWI", RSP_ZMWI, RT_NUMBER}, 426 {"ZMWI", RSP_ZMWI, RT_NUMBER},
428 {"ZHLC", RSP_ZHLC, RT_STRING}, 427 {"ZHLC", RSP_ZHLC, RT_STRING},
429 {"ZBC", RSP_ZBC, RT_STRING}, 428 {"ZBC", RSP_ZBC, RT_STRING},
430 {"NMBR", RSP_NMBR, RT_STRING}, 429 {"NMBR", RSP_NMBR, RT_STRING},
431 {"ZCPN", RSP_ZCPN, RT_STRING}, 430 {"ZCPN", RSP_ZCPN, RT_STRING},
432 {"ZCON", RSP_ZCON, RT_STRING}, 431 {"ZCON", RSP_ZCON, RT_STRING},
433 {"ZAOC", RSP_ZAOC, RT_STRING}, 432 {"ZAOC", RSP_ZAOC, RT_STRING},
434 {"ZCSTR", RSP_ZCSTR, RT_STRING}, 433 {"ZCSTR", RSP_ZCSTR, RT_STRING},
435 {"ZCFG", RSP_ZCFG, RT_HEX}, 434 {"ZCFG", RSP_ZCFG, RT_HEX},
436 {"ZLOG", RSP_ZLOG, RT_NOTHING}, 435 {"ZLOG", RSP_ZLOG, RT_NOTHING},
437 {"ZABINFO", RSP_ZABINFO, RT_NOTHING}, 436 {"ZABINFO", RSP_ZABINFO, RT_NOTHING},
438 {"ZSMLSTCHG", RSP_ZSMLSTCHG, RT_NOTHING}, 437 {"ZSMLSTCHG", RSP_ZSMLSTCHG, RT_NOTHING},
439 {NULL,0,0} 438 {NULL,0,0}
440}; 439};
441 440
@@ -446,9 +445,7 @@ static int isdn_getnum(char *p)
446{ 445{
447 int v = -1; 446 int v = -1;
448 447
449 IFNULLRETVAL(p, -1); 448 gig_dbg(DEBUG_TRANSCMD, "string: %s", p);
450
451 dbg(DEBUG_TRANSCMD, "string: %s", p);
452 449
453 while (*p >= '0' && *p <= '9') 450 while (*p >= '0' && *p <= '9')
454 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0'); 451 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0');
@@ -465,9 +462,7 @@ static int isdn_gethex(char *p)
465 int v = 0; 462 int v = 0;
466 int c; 463 int c;
467 464
468 IFNULLRETVAL(p, -1); 465 gig_dbg(DEBUG_TRANSCMD, "string: %s", p);
469
470 dbg(DEBUG_TRANSCMD, "string: %s", p);
471 466
472 if (!*p) 467 if (!*p)
473 return -1; 468 return -1;
@@ -490,14 +485,6 @@ static int isdn_gethex(char *p)
490 return v; 485 return v;
491} 486}
492 487
493static inline void new_index(atomic_t *index, int max)
494{
495 if (atomic_read(index) == max) //FIXME race?
496 atomic_set(index, 0);
497 else
498 atomic_inc(index);
499}
500
501/* retrieve CID from parsed response 488/* retrieve CID from parsed response
502 * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535 489 * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535
503 */ 490 */
@@ -536,16 +523,14 @@ void gigaset_handle_modem_response(struct cardstate *cs)
536 int cid; 523 int cid;
537 int rawstring; 524 int rawstring;
538 525
539 IFNULLRET(cs);
540
541 len = cs->cbytes; 526 len = cs->cbytes;
542 if (!len) { 527 if (!len) {
543 /* ignore additional LFs/CRs (M10x config mode or cx100) */ 528 /* ignore additional LFs/CRs (M10x config mode or cx100) */
544 dbg(DEBUG_MCMD, "skipped EOL [%02X]", cs->respdata[len]); 529 gig_dbg(DEBUG_MCMD, "skipped EOL [%02X]", cs->respdata[len]);
545 return; 530 return;
546 } 531 }
547 cs->respdata[len] = 0; 532 cs->respdata[len] = 0;
548 dbg(DEBUG_TRANSCMD, "raw string: '%s'", cs->respdata); 533 gig_dbg(DEBUG_TRANSCMD, "raw string: '%s'", cs->respdata);
549 argv[0] = cs->respdata; 534 argv[0] = cs->respdata;
550 params = 1; 535 params = 1;
551 if (cs->at_state.getstring) { 536 if (cs->at_state.getstring) {
@@ -561,7 +546,8 @@ void gigaset_handle_modem_response(struct cardstate *cs)
561 case ',': 546 case ',':
562 case '=': 547 case '=':
563 if (params > MAX_REC_PARAMS) { 548 if (params > MAX_REC_PARAMS) {
564 warn("too many parameters in response"); 549 dev_warn(cs->dev,
550 "too many parameters in response\n");
565 /* need last parameter (might be CID) */ 551 /* need last parameter (might be CID) */
566 params--; 552 params--;
567 } 553 }
@@ -572,33 +558,33 @@ void gigaset_handle_modem_response(struct cardstate *cs)
572 cid = params > 1 ? cid_of_response(argv[params-1]) : 0; 558 cid = params > 1 ? cid_of_response(argv[params-1]) : 0;
573 if (cid < 0) { 559 if (cid < 0) {
574 gigaset_add_event(cs, &cs->at_state, RSP_INVAL, 560 gigaset_add_event(cs, &cs->at_state, RSP_INVAL,
575 NULL, 0, NULL); 561 NULL, 0, NULL);
576 return; 562 return;
577 } 563 }
578 564
579 for (j = 1; j < params; ++j) 565 for (j = 1; j < params; ++j)
580 argv[j][-1] = 0; 566 argv[j][-1] = 0;
581 567
582 dbg(DEBUG_TRANSCMD, "CMD received: %s", argv[0]); 568 gig_dbg(DEBUG_TRANSCMD, "CMD received: %s", argv[0]);
583 if (cid) { 569 if (cid) {
584 --params; 570 --params;
585 dbg(DEBUG_TRANSCMD, "CID: %s", argv[params]); 571 gig_dbg(DEBUG_TRANSCMD, "CID: %s", argv[params]);
586 } 572 }
587 dbg(DEBUG_TRANSCMD, "available params: %d", params - 1); 573 gig_dbg(DEBUG_TRANSCMD, "available params: %d", params - 1);
588 for (j = 1; j < params; j++) 574 for (j = 1; j < params; j++)
589 dbg(DEBUG_TRANSCMD, "param %d: %s", j, argv[j]); 575 gig_dbg(DEBUG_TRANSCMD, "param %d: %s", j, argv[j]);
590 } 576 }
591 577
592 spin_lock_irqsave(&cs->ev_lock, flags); 578 spin_lock_irqsave(&cs->ev_lock, flags);
593 head = atomic_read(&cs->ev_head); 579 head = cs->ev_head;
594 tail = atomic_read(&cs->ev_tail); 580 tail = cs->ev_tail;
595 581
596 abort = 1; 582 abort = 1;
597 curarg = 0; 583 curarg = 0;
598 while (curarg < params) { 584 while (curarg < params) {
599 next = (tail + 1) % MAX_EVENTS; 585 next = (tail + 1) % MAX_EVENTS;
600 if (unlikely(next == head)) { 586 if (unlikely(next == head)) {
601 err("event queue full"); 587 dev_err(cs->dev, "event queue full\n");
602 break; 588 break;
603 } 589 }
604 590
@@ -619,8 +605,9 @@ void gigaset_handle_modem_response(struct cardstate *cs)
619 605
620 if (!rt->response) { 606 if (!rt->response) {
621 event->type = RSP_UNKNOWN; 607 event->type = RSP_UNKNOWN;
622 warn("unknown modem response: %s", 608 dev_warn(cs->dev,
623 argv[curarg]); 609 "unknown modem response: %s\n",
610 argv[curarg]);
624 break; 611 break;
625 } 612 }
626 613
@@ -636,7 +623,8 @@ void gigaset_handle_modem_response(struct cardstate *cs)
636 break; 623 break;
637 case RT_RING: 624 case RT_RING:
638 if (!cid) { 625 if (!cid) {
639 err("received RING without CID!"); 626 dev_err(cs->dev,
627 "received RING without CID!\n");
640 event->type = RSP_INVAL; 628 event->type = RSP_INVAL;
641 abort = 1; 629 abort = 1;
642 } else { 630 } else {
@@ -664,27 +652,25 @@ void gigaset_handle_modem_response(struct cardstate *cs)
664 event->parameter = ZSAU_DISCONNECT_REQ; 652 event->parameter = ZSAU_DISCONNECT_REQ;
665 else { 653 else {
666 event->parameter = ZSAU_UNKNOWN; 654 event->parameter = ZSAU_UNKNOWN;
667 warn("%s: unknown parameter %s after ZSAU", 655 dev_warn(cs->dev,
668 __func__, argv[curarg]); 656 "%s: unknown parameter %s after ZSAU\n",
657 __func__, argv[curarg]);
669 } 658 }
670 ++curarg; 659 ++curarg;
671 break; 660 break;
672 case RT_STRING: 661 case RT_STRING:
673 if (curarg < params) { 662 if (curarg < params) {
674 len = strlen(argv[curarg]) + 1; 663 event->ptr = kstrdup(argv[curarg], GFP_ATOMIC);
675 event->ptr = kmalloc(len, GFP_ATOMIC); 664 if (!event->ptr)
676 if (event->ptr) 665 dev_err(cs->dev, "out of memory\n");
677 memcpy(event->ptr, argv[curarg], len);
678 else
679 err("no memory for string!");
680 ++curarg; 666 ++curarg;
681 } 667 }
682#ifdef CONFIG_GIGASET_DEBUG 668#ifdef CONFIG_GIGASET_DEBUG
683 if (!event->ptr) 669 if (!event->ptr)
684 dbg(DEBUG_CMD, "string==NULL"); 670 gig_dbg(DEBUG_CMD, "string==NULL");
685 else 671 else
686 dbg(DEBUG_CMD, 672 gig_dbg(DEBUG_CMD, "string==%s",
687 "string==%s", (char *) event->ptr); 673 (char *) event->ptr);
688#endif 674#endif
689 break; 675 break;
690 case RT_ZCAU: 676 case RT_ZCAU:
@@ -694,7 +680,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
694 j = isdn_gethex(argv[curarg + 1]); 680 j = isdn_gethex(argv[curarg + 1]);
695 if (i >= 0 && i < 256 && j >= 0 && j < 256) 681 if (i >= 0 && i < 256 && j >= 0 && j < 256)
696 event->parameter = (unsigned) i << 8 682 event->parameter = (unsigned) i << 8
697 | j; 683 | j;
698 curarg += 2; 684 curarg += 2;
699 } else 685 } else
700 curarg = params - 1; 686 curarg = params - 1;
@@ -712,7 +698,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
712 } else 698 } else
713 event->parameter = -1; 699 event->parameter = -1;
714#ifdef CONFIG_GIGASET_DEBUG 700#ifdef CONFIG_GIGASET_DEBUG
715 dbg(DEBUG_CMD, "parameter==%d", event->parameter); 701 gig_dbg(DEBUG_CMD, "parameter==%d", event->parameter);
716#endif 702#endif
717 break; 703 break;
718 } 704 }
@@ -724,12 +710,13 @@ void gigaset_handle_modem_response(struct cardstate *cs)
724 break; 710 break;
725 } 711 }
726 712
727 atomic_set(&cs->ev_tail, tail); 713 cs->ev_tail = tail;
728 spin_unlock_irqrestore(&cs->ev_lock, flags); 714 spin_unlock_irqrestore(&cs->ev_lock, flags);
729 715
730 if (curarg != params) 716 if (curarg != params)
731 dbg(DEBUG_ANY, "invalid number of processed parameters: %d/%d", 717 gig_dbg(DEBUG_ANY,
732 curarg, params); 718 "invalid number of processed parameters: %d/%d",
719 curarg, params);
733} 720}
734EXPORT_SYMBOL_GPL(gigaset_handle_modem_response); 721EXPORT_SYMBOL_GPL(gigaset_handle_modem_response);
735 722
@@ -739,23 +726,19 @@ EXPORT_SYMBOL_GPL(gigaset_handle_modem_response);
739static void disconnect(struct at_state_t **at_state_p) 726static void disconnect(struct at_state_t **at_state_p)
740{ 727{
741 unsigned long flags; 728 unsigned long flags;
742 struct bc_state *bcs; 729 struct bc_state *bcs = (*at_state_p)->bcs;
743 struct cardstate *cs; 730 struct cardstate *cs = (*at_state_p)->cs;
744
745 IFNULLRET(at_state_p);
746 IFNULLRET(*at_state_p);
747 bcs = (*at_state_p)->bcs;
748 cs = (*at_state_p)->cs;
749 IFNULLRET(cs);
750 731
751 new_index(&(*at_state_p)->seq_index, MAX_SEQ_INDEX); 732 spin_lock_irqsave(&cs->lock, flags);
733 ++(*at_state_p)->seq_index;
752 734
753 /* revert to selected idle mode */ 735 /* revert to selected idle mode */
754 if (!atomic_read(&cs->cidmode)) { 736 if (!cs->cidmode) {
755 cs->at_state.pending_commands |= PC_UMMODE; 737 cs->at_state.pending_commands |= PC_UMMODE;
756 atomic_set(&cs->commands_pending, 1); //FIXME 738 atomic_set(&cs->commands_pending, 1); //FIXME
757 dbg(DEBUG_CMD, "Scheduling PC_UMMODE"); 739 gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
758 } 740 }
741 spin_unlock_irqrestore(&cs->lock, flags);
759 742
760 if (bcs) { 743 if (bcs) {
761 /* B channel assigned: invoke hardware specific handler */ 744 /* B channel assigned: invoke hardware specific handler */
@@ -777,7 +760,7 @@ static void disconnect(struct at_state_t **at_state_p)
777 * The structure should be freed by calling disconnect() after use. 760 * The structure should be freed by calling disconnect() after use.
778 */ 761 */
779static inline struct at_state_t *get_free_channel(struct cardstate *cs, 762static inline struct at_state_t *get_free_channel(struct cardstate *cs,
780 int cid) 763 int cid)
781/* cids: >0: siemens-cid 764/* cids: >0: siemens-cid
782 0: without cid 765 0: without cid
783 -1: no cid assigned yet 766 -1: no cid assigned yet
@@ -826,7 +809,7 @@ static void init_failed(struct cardstate *cs, int mode)
826static void schedule_init(struct cardstate *cs, int state) 809static void schedule_init(struct cardstate *cs, int state)
827{ 810{
828 if (cs->at_state.pending_commands & PC_INIT) { 811 if (cs->at_state.pending_commands & PC_INIT) {
829 dbg(DEBUG_CMD, "not scheduling PC_INIT again"); 812 gig_dbg(DEBUG_CMD, "not scheduling PC_INIT again");
830 return; 813 return;
831 } 814 }
832 atomic_set(&cs->mstate, state); 815 atomic_set(&cs->mstate, state);
@@ -834,52 +817,56 @@ static void schedule_init(struct cardstate *cs, int state)
834 gigaset_block_channels(cs); 817 gigaset_block_channels(cs);
835 cs->at_state.pending_commands |= PC_INIT; 818 cs->at_state.pending_commands |= PC_INIT;
836 atomic_set(&cs->commands_pending, 1); 819 atomic_set(&cs->commands_pending, 1);
837 dbg(DEBUG_CMD, "Scheduling PC_INIT"); 820 gig_dbg(DEBUG_CMD, "Scheduling PC_INIT");
838} 821}
839 822
840/* Add "AT" to a command, add the cid, dle encode it, send the result to the hardware. */ 823/* Add "AT" to a command, add the cid, dle encode it, send the result to the
824 hardware. */
841static void send_command(struct cardstate *cs, const char *cmd, int cid, 825static void send_command(struct cardstate *cs, const char *cmd, int cid,
842 int dle, gfp_t kmallocflags) 826 int dle, gfp_t kmallocflags)
843{ 827{
844 size_t cmdlen, buflen; 828 size_t cmdlen, buflen;
845 char *cmdpos, *cmdbuf, *cmdtail; 829 char *cmdpos, *cmdbuf, *cmdtail;
846 830
847 cmdlen = strlen(cmd); 831 cmdlen = strlen(cmd);
848 buflen = 11 + cmdlen; 832 buflen = 11 + cmdlen;
833 if (unlikely(buflen <= cmdlen)) {
834 dev_err(cs->dev, "integer overflow in buflen\n");
835 return;
836 }
849 837
850 if (likely(buflen > cmdlen)) { 838 cmdbuf = kmalloc(buflen, kmallocflags);
851 cmdbuf = kmalloc(buflen, kmallocflags); 839 if (unlikely(!cmdbuf)) {
852 if (likely(cmdbuf != NULL)) { 840 dev_err(cs->dev, "out of memory\n");
853 cmdpos = cmdbuf + 9; 841 return;
854 cmdtail = cmdpos + cmdlen; 842 }
855 memcpy(cmdpos, cmd, cmdlen);
856
857 if (cid > 0 && cid <= 65535) {
858 do {
859 *--cmdpos = '0' + cid % 10;
860 cid /= 10;
861 ++cmdlen;
862 } while (cid);
863 }
864 843
865 cmdlen += 2; 844 cmdpos = cmdbuf + 9;
866 *--cmdpos = 'T'; 845 cmdtail = cmdpos + cmdlen;
867 *--cmdpos = 'A'; 846 memcpy(cmdpos, cmd, cmdlen);
868 847
869 if (dle) { 848 if (cid > 0 && cid <= 65535) {
870 cmdlen += 4; 849 do {
871 *--cmdpos = '('; 850 *--cmdpos = '0' + cid % 10;
872 *--cmdpos = 0x10; 851 cid /= 10;
873 *cmdtail++ = 0x10; 852 ++cmdlen;
874 *cmdtail++ = ')'; 853 } while (cid);
875 } 854 }
876 855
877 cs->ops->write_cmd(cs, cmdpos, cmdlen, NULL); 856 cmdlen += 2;
878 kfree(cmdbuf); 857 *--cmdpos = 'T';
879 } else 858 *--cmdpos = 'A';
880 err("no memory for command buffer"); 859
881 } else 860 if (dle) {
882 err("overflow in buflen"); 861 cmdlen += 4;
862 *--cmdpos = '(';
863 *--cmdpos = 0x10;
864 *cmdtail++ = 0x10;
865 *cmdtail++ = ')';
866 }
867
868 cs->ops->write_cmd(cs, cmdpos, cmdlen, NULL);
869 kfree(cmdbuf);
883} 870}
884 871
885static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid) 872static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid)
@@ -910,9 +897,6 @@ static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid)
910 897
911static void bchannel_down(struct bc_state *bcs) 898static void bchannel_down(struct bc_state *bcs)
912{ 899{
913 IFNULLRET(bcs);
914 IFNULLRET(bcs->cs);
915
916 if (bcs->chstate & CHS_B_UP) { 900 if (bcs->chstate & CHS_B_UP) {
917 bcs->chstate &= ~CHS_B_UP; 901 bcs->chstate &= ~CHS_B_UP;
918 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP); 902 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP);
@@ -930,16 +914,15 @@ static void bchannel_down(struct bc_state *bcs)
930 914
931static void bchannel_up(struct bc_state *bcs) 915static void bchannel_up(struct bc_state *bcs)
932{ 916{
933 IFNULLRET(bcs);
934
935 if (!(bcs->chstate & CHS_D_UP)) { 917 if (!(bcs->chstate & CHS_D_UP)) {
936 notice("%s: D channel not up", __func__); 918 dev_notice(bcs->cs->dev, "%s: D channel not up\n", __func__);
937 bcs->chstate |= CHS_D_UP; 919 bcs->chstate |= CHS_D_UP;
938 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN); 920 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
939 } 921 }
940 922
941 if (bcs->chstate & CHS_B_UP) { 923 if (bcs->chstate & CHS_B_UP) {
942 notice("%s: B channel already up", __func__); 924 dev_notice(bcs->cs->dev, "%s: B channel already up\n",
925 __func__);
943 return; 926 return;
944 } 927 }
945 928
@@ -947,17 +930,21 @@ static void bchannel_up(struct bc_state *bcs)
947 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN); 930 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN);
948} 931}
949 932
950static void start_dial(struct at_state_t *at_state, void *data, int seq_index) 933static void start_dial(struct at_state_t *at_state, void *data, unsigned seq_index)
951{ 934{
952 struct bc_state *bcs = at_state->bcs; 935 struct bc_state *bcs = at_state->bcs;
953 struct cardstate *cs = at_state->cs; 936 struct cardstate *cs = at_state->cs;
954 int retval; 937 int retval;
938 unsigned long flags;
955 939
956 bcs->chstate |= CHS_NOTIFY_LL; 940 bcs->chstate |= CHS_NOTIFY_LL;
957 //atomic_set(&bcs->status, BCS_INIT);
958 941
959 if (atomic_read(&at_state->seq_index) != seq_index) 942 spin_lock_irqsave(&cs->lock, flags);
943 if (at_state->seq_index != seq_index) {
944 spin_unlock_irqrestore(&cs->lock, flags);
960 goto error; 945 goto error;
946 }
947 spin_unlock_irqrestore(&cs->lock, flags);
961 948
962 retval = gigaset_isdn_setup_dial(at_state, data); 949 retval = gigaset_isdn_setup_dial(at_state, data);
963 if (retval != 0) 950 if (retval != 0)
@@ -965,20 +952,14 @@ static void start_dial(struct at_state_t *at_state, void *data, int seq_index)
965 952
966 953
967 at_state->pending_commands |= PC_CID; 954 at_state->pending_commands |= PC_CID;
968 dbg(DEBUG_CMD, "Scheduling PC_CID"); 955 gig_dbg(DEBUG_CMD, "Scheduling PC_CID");
969//#ifdef GIG_MAYINITONDIAL 956 atomic_set(&cs->commands_pending, 1);
970// if (atomic_read(&cs->MState) == MS_UNKNOWN) {
971// cs->at_state.pending_commands |= PC_INIT;
972// dbg(DEBUG_CMD, "Scheduling PC_INIT");
973// }
974//#endif
975 atomic_set(&cs->commands_pending, 1); //FIXME
976 return; 957 return;
977 958
978error: 959error:
979 at_state->pending_commands |= PC_NOCID; 960 at_state->pending_commands |= PC_NOCID;
980 dbg(DEBUG_CMD, "Scheduling PC_NOCID"); 961 gig_dbg(DEBUG_CMD, "Scheduling PC_NOCID");
981 atomic_set(&cs->commands_pending, 1); //FIXME 962 atomic_set(&cs->commands_pending, 1);
982 return; 963 return;
983} 964}
984 965
@@ -991,13 +972,13 @@ static void start_accept(struct at_state_t *at_state)
991 972
992 if (retval == 0) { 973 if (retval == 0) {
993 at_state->pending_commands |= PC_ACCEPT; 974 at_state->pending_commands |= PC_ACCEPT;
994 dbg(DEBUG_CMD, "Scheduling PC_ACCEPT"); 975 gig_dbg(DEBUG_CMD, "Scheduling PC_ACCEPT");
995 atomic_set(&cs->commands_pending, 1); //FIXME 976 atomic_set(&cs->commands_pending, 1);
996 } else { 977 } else {
997 //FIXME 978 //FIXME
998 at_state->pending_commands |= PC_HUP; 979 at_state->pending_commands |= PC_HUP;
999 dbg(DEBUG_CMD, "Scheduling PC_HUP"); 980 gig_dbg(DEBUG_CMD, "Scheduling PC_HUP");
1000 atomic_set(&cs->commands_pending, 1); //FIXME 981 atomic_set(&cs->commands_pending, 1);
1001 } 982 }
1002} 983}
1003 984
@@ -1008,9 +989,10 @@ static void do_start(struct cardstate *cs)
1008 if (atomic_read(&cs->mstate) != MS_LOCKED) 989 if (atomic_read(&cs->mstate) != MS_LOCKED)
1009 schedule_init(cs, MS_INIT); 990 schedule_init(cs, MS_INIT);
1010 991
992 cs->isdn_up = 1;
1011 gigaset_i4l_cmd(cs, ISDN_STAT_RUN); 993 gigaset_i4l_cmd(cs, ISDN_STAT_RUN);
1012 // FIXME: not in locked mode 994 // FIXME: not in locked mode
1013 // FIXME 2: only after init sequence 995 // FIXME 2: only after init sequence
1014 996
1015 cs->waiting = 0; 997 cs->waiting = 0;
1016 wake_up(&cs->waitqueue); 998 wake_up(&cs->waitqueue);
@@ -1023,6 +1005,12 @@ static void finish_shutdown(struct cardstate *cs)
1023 atomic_set(&cs->mode, M_UNKNOWN); 1005 atomic_set(&cs->mode, M_UNKNOWN);
1024 } 1006 }
1025 1007
1008 /* Tell the LL that the device is not available .. */
1009 if (cs->isdn_up) {
1010 cs->isdn_up = 0;
1011 gigaset_i4l_cmd(cs, ISDN_STAT_STOP);
1012 }
1013
1026 /* The rest is done by cleanup_cs () in user mode. */ 1014 /* The rest is done by cleanup_cs () in user mode. */
1027 1015
1028 cs->cmd_result = -ENODEV; 1016 cs->cmd_result = -ENODEV;
@@ -1037,15 +1025,20 @@ static void do_shutdown(struct cardstate *cs)
1037 if (atomic_read(&cs->mstate) == MS_READY) { 1025 if (atomic_read(&cs->mstate) == MS_READY) {
1038 atomic_set(&cs->mstate, MS_SHUTDOWN); 1026 atomic_set(&cs->mstate, MS_SHUTDOWN);
1039 cs->at_state.pending_commands |= PC_SHUTDOWN; 1027 cs->at_state.pending_commands |= PC_SHUTDOWN;
1040 atomic_set(&cs->commands_pending, 1); //FIXME 1028 atomic_set(&cs->commands_pending, 1);
1041 dbg(DEBUG_CMD, "Scheduling PC_SHUTDOWN"); //FIXME 1029 gig_dbg(DEBUG_CMD, "Scheduling PC_SHUTDOWN");
1042 //gigaset_schedule_event(cs); //FIXME
1043 } else 1030 } else
1044 finish_shutdown(cs); 1031 finish_shutdown(cs);
1045} 1032}
1046 1033
1047static void do_stop(struct cardstate *cs) 1034static void do_stop(struct cardstate *cs)
1048{ 1035{
1036 unsigned long flags;
1037
1038 spin_lock_irqsave(&cs->lock, flags);
1039 cs->connected = 0;
1040 spin_unlock_irqrestore(&cs->lock, flags);
1041
1049 do_shutdown(cs); 1042 do_shutdown(cs);
1050} 1043}
1051 1044
@@ -1069,9 +1062,11 @@ static int reinit_and_retry(struct cardstate *cs, int channel)
1069 return 0; 1062 return 0;
1070 1063
1071 if (channel < 0) 1064 if (channel < 0)
1072 warn("Could not enter cid mode. Reinit device and try again."); 1065 dev_warn(cs->dev,
1066 "Could not enter cid mode. Reinit device and try again.\n");
1073 else { 1067 else {
1074 warn("Could not get a call id. Reinit device and try again."); 1068 dev_warn(cs->dev,
1069 "Could not get a call id. Reinit device and try again.\n");
1075 cs->bcs[channel].at_state.pending_commands |= PC_CID; 1070 cs->bcs[channel].at_state.pending_commands |= PC_CID;
1076 } 1071 }
1077 schedule_init(cs, MS_INIT); 1072 schedule_init(cs, MS_INIT);
@@ -1079,7 +1074,7 @@ static int reinit_and_retry(struct cardstate *cs, int channel)
1079} 1074}
1080 1075
1081static int at_state_invalid(struct cardstate *cs, 1076static int at_state_invalid(struct cardstate *cs,
1082 struct at_state_t *test_ptr) 1077 struct at_state_t *test_ptr)
1083{ 1078{
1084 unsigned long flags; 1079 unsigned long flags;
1085 unsigned channel; 1080 unsigned channel;
@@ -1116,7 +1111,7 @@ static void handle_icall(struct cardstate *cs, struct bc_state *bcs,
1116 case ICALL_ACCEPT: 1111 case ICALL_ACCEPT:
1117 break; 1112 break;
1118 default: 1113 default:
1119 err("internal error: disposition=%d", retval); 1114 dev_err(cs->dev, "internal error: disposition=%d\n", retval);
1120 /* --v-- fall through --v-- */ 1115 /* --v-- fall through --v-- */
1121 case ICALL_IGNORE: 1116 case ICALL_IGNORE:
1122 case ICALL_REJECT: 1117 case ICALL_REJECT:
@@ -1160,7 +1155,6 @@ static int do_lock(struct cardstate *cs)
1160 mode = atomic_read(&cs->mode); 1155 mode = atomic_read(&cs->mode);
1161 atomic_set(&cs->mstate, MS_LOCKED); 1156 atomic_set(&cs->mstate, MS_LOCKED);
1162 atomic_set(&cs->mode, M_UNKNOWN); 1157 atomic_set(&cs->mode, M_UNKNOWN);
1163 //FIXME reset card state / at states / bcs states
1164 1158
1165 return mode; 1159 return mode;
1166} 1160}
@@ -1173,8 +1167,7 @@ static int do_unlock(struct cardstate *cs)
1173 atomic_set(&cs->mstate, MS_UNINITIALIZED); 1167 atomic_set(&cs->mstate, MS_UNINITIALIZED);
1174 atomic_set(&cs->mode, M_UNKNOWN); 1168 atomic_set(&cs->mode, M_UNKNOWN);
1175 gigaset_free_channels(cs); 1169 gigaset_free_channels(cs);
1176 //FIXME reset card state / at states / bcs states 1170 if (cs->connected)
1177 if (atomic_read(&cs->connected))
1178 schedule_init(cs, MS_INIT); 1171 schedule_init(cs, MS_INIT);
1179 1172
1180 return 0; 1173 return 0;
@@ -1203,21 +1196,23 @@ static void do_action(int action, struct cardstate *cs,
1203 at_state->waiting = 1; 1196 at_state->waiting = 1;
1204 break; 1197 break;
1205 case ACT_INIT: 1198 case ACT_INIT:
1206 //FIXME setup everything
1207 cs->at_state.pending_commands &= ~PC_INIT; 1199 cs->at_state.pending_commands &= ~PC_INIT;
1208 cs->cur_at_seq = SEQ_NONE; 1200 cs->cur_at_seq = SEQ_NONE;
1209 atomic_set(&cs->mode, M_UNIMODEM); 1201 atomic_set(&cs->mode, M_UNIMODEM);
1210 if (!atomic_read(&cs->cidmode)) { 1202 spin_lock_irqsave(&cs->lock, flags);
1203 if (!cs->cidmode) {
1204 spin_unlock_irqrestore(&cs->lock, flags);
1211 gigaset_free_channels(cs); 1205 gigaset_free_channels(cs);
1212 atomic_set(&cs->mstate, MS_READY); 1206 atomic_set(&cs->mstate, MS_READY);
1213 break; 1207 break;
1214 } 1208 }
1209 spin_unlock_irqrestore(&cs->lock, flags);
1215 cs->at_state.pending_commands |= PC_CIDMODE; 1210 cs->at_state.pending_commands |= PC_CIDMODE;
1216 atomic_set(&cs->commands_pending, 1); //FIXME 1211 atomic_set(&cs->commands_pending, 1);
1217 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); 1212 gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1218 break; 1213 break;
1219 case ACT_FAILINIT: 1214 case ACT_FAILINIT:
1220 warn("Could not initialize the device."); 1215 dev_warn(cs->dev, "Could not initialize the device.\n");
1221 cs->dle = 0; 1216 cs->dle = 0;
1222 init_failed(cs, M_UNKNOWN); 1217 init_failed(cs, M_UNKNOWN);
1223 cs->cur_at_seq = SEQ_NONE; 1218 cs->cur_at_seq = SEQ_NONE;
@@ -1273,8 +1268,8 @@ static void do_action(int action, struct cardstate *cs,
1273 /* get fresh AT state structure for new CID */ 1268 /* get fresh AT state structure for new CID */
1274 at_state2 = get_free_channel(cs, ev->parameter); 1269 at_state2 = get_free_channel(cs, ev->parameter);
1275 if (!at_state2) { 1270 if (!at_state2) {
1276 warn("RING ignored: " 1271 dev_warn(cs->dev,
1277 "could not allocate channel structure"); 1272 "RING ignored: could not allocate channel structure\n");
1278 break; 1273 break;
1279 } 1274 }
1280 1275
@@ -1302,7 +1297,7 @@ static void do_action(int action, struct cardstate *cs,
1302 at_state = *p_at_state; 1297 at_state = *p_at_state;
1303 break; 1298 break;
1304 case ACT_FAILSDOWN: 1299 case ACT_FAILSDOWN:
1305 warn("Could not shut down the device."); 1300 dev_warn(cs->dev, "Could not shut down the device.\n");
1306 /* fall through */ 1301 /* fall through */
1307 case ACT_FAKESDOWN: 1302 case ACT_FAKESDOWN:
1308 case ACT_SDOWN: 1303 case ACT_SDOWN:
@@ -1355,7 +1350,7 @@ static void do_action(int action, struct cardstate *cs,
1355 break; 1350 break;
1356 case ACT_ABORTHUP: 1351 case ACT_ABORTHUP:
1357 cs->cur_at_seq = SEQ_NONE; 1352 cs->cur_at_seq = SEQ_NONE;
1358 warn("Could not hang up."); 1353 dev_warn(cs->dev, "Could not hang up.\n");
1359 at_state->cid = -1; 1354 at_state->cid = -1;
1360 if (bcs && cs->onechannel) 1355 if (bcs && cs->onechannel)
1361 at_state->pending_commands |= PC_DLE0; 1356 at_state->pending_commands |= PC_DLE0;
@@ -1367,14 +1362,15 @@ static void do_action(int action, struct cardstate *cs,
1367 break; 1362 break;
1368 case ACT_FAILDLE0: 1363 case ACT_FAILDLE0:
1369 cs->cur_at_seq = SEQ_NONE; 1364 cs->cur_at_seq = SEQ_NONE;
1370 warn("Could not leave DLE mode."); 1365 dev_warn(cs->dev, "Could not leave DLE mode.\n");
1371 at_state2 = &cs->bcs[cs->curchannel].at_state; 1366 at_state2 = &cs->bcs[cs->curchannel].at_state;
1372 disconnect(&at_state2); 1367 disconnect(&at_state2);
1373 schedule_init(cs, MS_RECOVER); 1368 schedule_init(cs, MS_RECOVER);
1374 break; 1369 break;
1375 case ACT_FAILDLE1: 1370 case ACT_FAILDLE1:
1376 cs->cur_at_seq = SEQ_NONE; 1371 cs->cur_at_seq = SEQ_NONE;
1377 warn("Could not enter DLE mode. Try to hang up."); 1372 dev_warn(cs->dev,
1373 "Could not enter DLE mode. Trying to hang up.\n");
1378 channel = cs->curchannel; 1374 channel = cs->curchannel;
1379 cs->bcs[channel].at_state.pending_commands |= PC_HUP; 1375 cs->bcs[channel].at_state.pending_commands |= PC_HUP;
1380 atomic_set(&cs->commands_pending, 1); 1376 atomic_set(&cs->commands_pending, 1);
@@ -1395,7 +1391,8 @@ static void do_action(int action, struct cardstate *cs,
1395 cs->cur_at_seq = SEQ_NONE; 1391 cs->cur_at_seq = SEQ_NONE;
1396 channel = cs->curchannel; 1392 channel = cs->curchannel;
1397 if (!reinit_and_retry(cs, channel)) { 1393 if (!reinit_and_retry(cs, channel)) {
1398 warn("Could not get a call id. Dialing not possible"); 1394 dev_warn(cs->dev,
1395 "Could not get a call ID. Cannot dial.\n");
1399 at_state2 = &cs->bcs[channel].at_state; 1396 at_state2 = &cs->bcs[channel].at_state;
1400 disconnect(&at_state2); 1397 disconnect(&at_state2);
1401 } 1398 }
@@ -1428,7 +1425,8 @@ static void do_action(int action, struct cardstate *cs,
1428 at_state->pending_commands |= PC_HUP; 1425 at_state->pending_commands |= PC_HUP;
1429 atomic_set(&cs->commands_pending, 1); 1426 atomic_set(&cs->commands_pending, 1);
1430 break; 1427 break;
1431 case ACT_GETSTRING: /* warning: RING, ZDLE, ... are not handled properly any more */ 1428 case ACT_GETSTRING: /* warning: RING, ZDLE, ...
1429 are not handled properly anymore */
1432 at_state->getstring = 1; 1430 at_state->getstring = 1;
1433 break; 1431 break;
1434 case ACT_SETVER: 1432 case ACT_SETVER:
@@ -1469,16 +1467,16 @@ static void do_action(int action, struct cardstate *cs,
1469 case ACT_GOTVER: 1467 case ACT_GOTVER:
1470 if (cs->gotfwver == 0) { 1468 if (cs->gotfwver == 0) {
1471 cs->gotfwver = 1; 1469 cs->gotfwver = 1;
1472 dbg(DEBUG_ANY, 1470 gig_dbg(DEBUG_ANY,
1473 "firmware version %02d.%03d.%02d.%02d", 1471 "firmware version %02d.%03d.%02d.%02d",
1474 cs->fwver[0], cs->fwver[1], 1472 cs->fwver[0], cs->fwver[1],
1475 cs->fwver[2], cs->fwver[3]); 1473 cs->fwver[2], cs->fwver[3]);
1476 break; 1474 break;
1477 } 1475 }
1478 /* fall through */ 1476 /* fall through */
1479 case ACT_FAILVER: 1477 case ACT_FAILVER:
1480 cs->gotfwver = -1; 1478 cs->gotfwver = -1;
1481 err("could not read firmware version."); 1479 dev_err(cs->dev, "could not read firmware version.\n");
1482 break; 1480 break;
1483#ifdef CONFIG_GIGASET_DEBUG 1481#ifdef CONFIG_GIGASET_DEBUG
1484 case ACT_ERROR: 1482 case ACT_ERROR:
@@ -1496,16 +1494,16 @@ static void do_action(int action, struct cardstate *cs,
1496 break; 1494 break;
1497#endif 1495#endif
1498 case ACT_DEBUG: 1496 case ACT_DEBUG:
1499 dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d", 1497 gig_dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d",
1500 __func__, ev->type, at_state->ConState); 1498 __func__, ev->type, at_state->ConState);
1501 break; 1499 break;
1502 case ACT_WARN: 1500 case ACT_WARN:
1503 warn("%s: resp_code %d in ConState %d!", 1501 dev_warn(cs->dev, "%s: resp_code %d in ConState %d!\n",
1504 __func__, ev->type, at_state->ConState); 1502 __func__, ev->type, at_state->ConState);
1505 break; 1503 break;
1506 case ACT_ZCAU: 1504 case ACT_ZCAU:
1507 warn("cause code %04x in connection state %d.", 1505 dev_warn(cs->dev, "cause code %04x in connection state %d.\n",
1508 ev->parameter, at_state->ConState); 1506 ev->parameter, at_state->ConState);
1509 break; 1507 break;
1510 1508
1511 /* events from the LL */ 1509 /* events from the LL */
@@ -1516,14 +1514,14 @@ static void do_action(int action, struct cardstate *cs,
1516 start_accept(at_state); 1514 start_accept(at_state);
1517 break; 1515 break;
1518 case ACT_PROTO_L2: 1516 case ACT_PROTO_L2:
1519 dbg(DEBUG_CMD, 1517 gig_dbg(DEBUG_CMD, "set protocol to %u",
1520 "set protocol to %u", (unsigned) ev->parameter); 1518 (unsigned) ev->parameter);
1521 at_state->bcs->proto2 = ev->parameter; 1519 at_state->bcs->proto2 = ev->parameter;
1522 break; 1520 break;
1523 case ACT_HUP: 1521 case ACT_HUP:
1524 at_state->pending_commands |= PC_HUP; 1522 at_state->pending_commands |= PC_HUP;
1525 atomic_set(&cs->commands_pending, 1); //FIXME 1523 atomic_set(&cs->commands_pending, 1);
1526 dbg(DEBUG_CMD, "Scheduling PC_HUP"); 1524 gig_dbg(DEBUG_CMD, "Scheduling PC_HUP");
1527 break; 1525 break;
1528 1526
1529 /* hotplug events */ 1527 /* hotplug events */
@@ -1555,17 +1553,19 @@ static void do_action(int action, struct cardstate *cs,
1555 1553
1556 /* events from the proc file system */ // FIXME without ACT_xxxx? 1554 /* events from the proc file system */ // FIXME without ACT_xxxx?
1557 case ACT_PROC_CIDMODE: 1555 case ACT_PROC_CIDMODE:
1558 if (ev->parameter != atomic_read(&cs->cidmode)) { 1556 spin_lock_irqsave(&cs->lock, flags);
1559 atomic_set(&cs->cidmode, ev->parameter); 1557 if (ev->parameter != cs->cidmode) {
1558 cs->cidmode = ev->parameter;
1560 if (ev->parameter) { 1559 if (ev->parameter) {
1561 cs->at_state.pending_commands |= PC_CIDMODE; 1560 cs->at_state.pending_commands |= PC_CIDMODE;
1562 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); 1561 gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1563 } else { 1562 } else {
1564 cs->at_state.pending_commands |= PC_UMMODE; 1563 cs->at_state.pending_commands |= PC_UMMODE;
1565 dbg(DEBUG_CMD, "Scheduling PC_UMMODE"); 1564 gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
1566 } 1565 }
1567 atomic_set(&cs->commands_pending, 1); 1566 atomic_set(&cs->commands_pending, 1);
1568 } 1567 }
1568 spin_unlock_irqrestore(&cs->lock, flags);
1569 cs->waiting = 0; 1569 cs->waiting = 0;
1570 wake_up(&cs->waitqueue); 1570 wake_up(&cs->waitqueue);
1571 break; 1571 break;
@@ -1590,7 +1590,7 @@ static void do_action(int action, struct cardstate *cs,
1590 *p_resp_code = RSP_NULL; 1590 *p_resp_code = RSP_NULL;
1591 } 1591 }
1592 } else 1592 } else
1593 err("%s: action==%d!", __func__, action); 1593 dev_err(cs->dev, "%s: action==%d!\n", __func__, action);
1594 } 1594 }
1595} 1595}
1596 1596
@@ -1609,47 +1609,46 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1609 int curact; 1609 int curact;
1610 unsigned long flags; 1610 unsigned long flags;
1611 1611
1612 IFNULLRET(cs);
1613 IFNULLRET(ev);
1614
1615 if (ev->cid >= 0) { 1612 if (ev->cid >= 0) {
1616 at_state = at_state_from_cid(cs, ev->cid); 1613 at_state = at_state_from_cid(cs, ev->cid);
1617 if (!at_state) { 1614 if (!at_state) {
1618 gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID, 1615 gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID,
1619 NULL, 0, NULL); 1616 NULL, 0, NULL);
1620 return; 1617 return;
1621 } 1618 }
1622 } else { 1619 } else {
1623 at_state = ev->at_state; 1620 at_state = ev->at_state;
1624 if (at_state_invalid(cs, at_state)) { 1621 if (at_state_invalid(cs, at_state)) {
1625 dbg(DEBUG_ANY, 1622 gig_dbg(DEBUG_ANY, "event for invalid at_state %p",
1626 "event for invalid at_state %p", at_state); 1623 at_state);
1627 return; 1624 return;
1628 } 1625 }
1629 } 1626 }
1630 1627
1631 dbg(DEBUG_CMD, 1628 gig_dbg(DEBUG_CMD, "connection state %d, event %d",
1632 "connection state %d, event %d", at_state->ConState, ev->type); 1629 at_state->ConState, ev->type);
1633 1630
1634 bcs = at_state->bcs; 1631 bcs = at_state->bcs;
1635 sendcid = at_state->cid; 1632 sendcid = at_state->cid;
1636 1633
1637 /* Setting the pointer to the dial array */ 1634 /* Setting the pointer to the dial array */
1638 rep = at_state->replystruct; 1635 rep = at_state->replystruct;
1639 IFNULLRET(rep);
1640 1636
1637 spin_lock_irqsave(&cs->lock, flags);
1641 if (ev->type == EV_TIMEOUT) { 1638 if (ev->type == EV_TIMEOUT) {
1642 if (ev->parameter != atomic_read(&at_state->timer_index) 1639 if (ev->parameter != at_state->timer_index
1643 || !at_state->timer_active) { 1640 || !at_state->timer_active) {
1644 ev->type = RSP_NONE; /* old timeout */ 1641 ev->type = RSP_NONE; /* old timeout */
1645 dbg(DEBUG_ANY, "old timeout"); 1642 gig_dbg(DEBUG_ANY, "old timeout");
1646 } else if (!at_state->waiting) 1643 } else if (!at_state->waiting)
1647 dbg(DEBUG_ANY, "timeout occured"); 1644 gig_dbg(DEBUG_ANY, "timeout occurred");
1648 else 1645 else
1649 dbg(DEBUG_ANY, "stopped waiting"); 1646 gig_dbg(DEBUG_ANY, "stopped waiting");
1650 } 1647 }
1648 spin_unlock_irqrestore(&cs->lock, flags);
1651 1649
1652 /* if the response belongs to a variable in at_state->int_var[VAR_XXXX] or at_state->str_var[STR_XXXX], set it */ 1650 /* if the response belongs to a variable in at_state->int_var[VAR_XXXX]
1651 or at_state->str_var[STR_XXXX], set it */
1653 if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) { 1652 if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) {
1654 index = ev->type - RSP_VAR; 1653 index = ev->type - RSP_VAR;
1655 at_state->int_var[index] = ev->parameter; 1654 at_state->int_var[index] = ev->parameter;
@@ -1657,20 +1656,22 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1657 index = ev->type - RSP_STR; 1656 index = ev->type - RSP_STR;
1658 kfree(at_state->str_var[index]); 1657 kfree(at_state->str_var[index]);
1659 at_state->str_var[index] = ev->ptr; 1658 at_state->str_var[index] = ev->ptr;
1660 ev->ptr = NULL; /* prevent process_events() from deallocating ptr */ 1659 ev->ptr = NULL; /* prevent process_events() from
1660 deallocating ptr */
1661 } 1661 }
1662 1662
1663 if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING) 1663 if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING)
1664 at_state->getstring = 0; 1664 at_state->getstring = 0;
1665 1665
1666 /* Search row in dial array which matches modem response and current constate */ 1666 /* Search row in dial array which matches modem response and current
1667 constate */
1667 for (;; rep++) { 1668 for (;; rep++) {
1668 rcode = rep->resp_code; 1669 rcode = rep->resp_code;
1669 /* dbg (DEBUG_ANY, "rcode %d", rcode); */
1670 if (rcode == RSP_LAST) { 1670 if (rcode == RSP_LAST) {
1671 /* found nothing...*/ 1671 /* found nothing...*/
1672 warn("%s: rcode=RSP_LAST: resp_code %d in ConState %d!", 1672 dev_warn(cs->dev, "%s: rcode=RSP_LAST: "
1673 __func__, ev->type, at_state->ConState); 1673 "resp_code %d in ConState %d!\n",
1674 __func__, ev->type, at_state->ConState);
1674 return; 1675 return;
1675 } 1676 }
1676 if ((rcode == RSP_ANY || rcode == ev->type) 1677 if ((rcode == RSP_ANY || rcode == ev->type)
@@ -1706,14 +1707,14 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1706 } else { 1707 } else {
1707 /* Send command to modem if not NULL... */ 1708 /* Send command to modem if not NULL... */
1708 if (p_command/*rep->command*/) { 1709 if (p_command/*rep->command*/) {
1709 if (atomic_read(&cs->connected)) 1710 if (cs->connected)
1710 send_command(cs, p_command, 1711 send_command(cs, p_command,
1711 sendcid, cs->dle, 1712 sendcid, cs->dle,
1712 GFP_ATOMIC); 1713 GFP_ATOMIC);
1713 else 1714 else
1714 gigaset_add_event(cs, at_state, 1715 gigaset_add_event(cs, at_state,
1715 RSP_NODEV, 1716 RSP_NODEV,
1716 NULL, 0, NULL); 1717 NULL, 0, NULL);
1717 } 1718 }
1718 1719
1719 spin_lock_irqsave(&cs->lock, flags); 1720 spin_lock_irqsave(&cs->lock, flags);
@@ -1723,8 +1724,7 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1723 } else if (rep->timeout > 0) { /* new timeout */ 1724 } else if (rep->timeout > 0) { /* new timeout */
1724 at_state->timer_expires = rep->timeout * 10; 1725 at_state->timer_expires = rep->timeout * 10;
1725 at_state->timer_active = 1; 1726 at_state->timer_active = 1;
1726 new_index(&at_state->timer_index, 1727 ++at_state->timer_index;
1727 MAX_TIMER_INDEX);
1728 } 1728 }
1729 spin_unlock_irqrestore(&cs->lock, flags); 1729 spin_unlock_irqrestore(&cs->lock, flags);
1730 } 1730 }
@@ -1744,17 +1744,16 @@ static void process_command_flags(struct cardstate *cs)
1744 struct bc_state *bcs; 1744 struct bc_state *bcs;
1745 int i; 1745 int i;
1746 int sequence; 1746 int sequence;
1747 1747 unsigned long flags;
1748 IFNULLRET(cs);
1749 1748
1750 atomic_set(&cs->commands_pending, 0); 1749 atomic_set(&cs->commands_pending, 0);
1751 1750
1752 if (cs->cur_at_seq) { 1751 if (cs->cur_at_seq) {
1753 dbg(DEBUG_CMD, "not searching scheduled commands: busy"); 1752 gig_dbg(DEBUG_CMD, "not searching scheduled commands: busy");
1754 return; 1753 return;
1755 } 1754 }
1756 1755
1757 dbg(DEBUG_CMD, "searching scheduled commands"); 1756 gig_dbg(DEBUG_CMD, "searching scheduled commands");
1758 1757
1759 sequence = SEQ_NONE; 1758 sequence = SEQ_NONE;
1760 1759
@@ -1795,8 +1794,9 @@ static void process_command_flags(struct cardstate *cs)
1795 } 1794 }
1796 1795
1797 /* only switch back to unimodem mode, if no commands are pending and no channels are up */ 1796 /* only switch back to unimodem mode, if no commands are pending and no channels are up */
1797 spin_lock_irqsave(&cs->lock, flags);
1798 if (cs->at_state.pending_commands == PC_UMMODE 1798 if (cs->at_state.pending_commands == PC_UMMODE
1799 && !atomic_read(&cs->cidmode) 1799 && !cs->cidmode
1800 && list_empty(&cs->temp_at_states) 1800 && list_empty(&cs->temp_at_states)
1801 && atomic_read(&cs->mode) == M_CID) { 1801 && atomic_read(&cs->mode) == M_CID) {
1802 sequence = SEQ_UMMODE; 1802 sequence = SEQ_UMMODE;
@@ -1810,6 +1810,7 @@ static void process_command_flags(struct cardstate *cs)
1810 } 1810 }
1811 } 1811 }
1812 } 1812 }
1813 spin_unlock_irqrestore(&cs->lock, flags);
1813 cs->at_state.pending_commands &= ~PC_UMMODE; 1814 cs->at_state.pending_commands &= ~PC_UMMODE;
1814 if (sequence != SEQ_NONE) { 1815 if (sequence != SEQ_NONE) {
1815 schedule_sequence(cs, at_state, sequence); 1816 schedule_sequence(cs, at_state, sequence);
@@ -1865,11 +1866,7 @@ static void process_command_flags(struct cardstate *cs)
1865 if (cs->at_state.pending_commands & PC_CIDMODE) { 1866 if (cs->at_state.pending_commands & PC_CIDMODE) {
1866 cs->at_state.pending_commands &= ~PC_CIDMODE; 1867 cs->at_state.pending_commands &= ~PC_CIDMODE;
1867 if (atomic_read(&cs->mode) == M_UNIMODEM) { 1868 if (atomic_read(&cs->mode) == M_UNIMODEM) {
1868#if 0
1869 cs->retry_count = 2;
1870#else
1871 cs->retry_count = 1; 1869 cs->retry_count = 1;
1872#endif
1873 schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE); 1870 schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE);
1874 return; 1871 return;
1875 } 1872 }
@@ -1897,7 +1894,7 @@ static void process_command_flags(struct cardstate *cs)
1897 switch (atomic_read(&cs->mode)) { 1894 switch (atomic_read(&cs->mode)) {
1898 case M_UNIMODEM: 1895 case M_UNIMODEM:
1899 cs->at_state.pending_commands |= PC_CIDMODE; 1896 cs->at_state.pending_commands |= PC_CIDMODE;
1900 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); 1897 gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1901 atomic_set(&cs->commands_pending, 1); 1898 atomic_set(&cs->commands_pending, 1);
1902 return; 1899 return;
1903#ifdef GIG_MAYINITONDIAL 1900#ifdef GIG_MAYINITONDIAL
@@ -1926,18 +1923,21 @@ static void process_events(struct cardstate *cs)
1926 int i; 1923 int i;
1927 int check_flags = 0; 1924 int check_flags = 0;
1928 int was_busy; 1925 int was_busy;
1926 unsigned long flags;
1929 1927
1930 /* no locking needed (only one reader) */ 1928 spin_lock_irqsave(&cs->ev_lock, flags);
1931 head = atomic_read(&cs->ev_head); 1929 head = cs->ev_head;
1932 1930
1933 for (i = 0; i < 2 * MAX_EVENTS; ++i) { 1931 for (i = 0; i < 2 * MAX_EVENTS; ++i) {
1934 tail = atomic_read(&cs->ev_tail); 1932 tail = cs->ev_tail;
1935 if (tail == head) { 1933 if (tail == head) {
1936 if (!check_flags && !atomic_read(&cs->commands_pending)) 1934 if (!check_flags && !atomic_read(&cs->commands_pending))
1937 break; 1935 break;
1938 check_flags = 0; 1936 check_flags = 0;
1937 spin_unlock_irqrestore(&cs->ev_lock, flags);
1939 process_command_flags(cs); 1938 process_command_flags(cs);
1940 tail = atomic_read(&cs->ev_tail); 1939 spin_lock_irqsave(&cs->ev_lock, flags);
1940 tail = cs->ev_tail;
1941 if (tail == head) { 1941 if (tail == head) {
1942 if (!atomic_read(&cs->commands_pending)) 1942 if (!atomic_read(&cs->commands_pending))
1943 break; 1943 break;
@@ -1947,18 +1947,23 @@ static void process_events(struct cardstate *cs)
1947 1947
1948 ev = cs->events + head; 1948 ev = cs->events + head;
1949 was_busy = cs->cur_at_seq != SEQ_NONE; 1949 was_busy = cs->cur_at_seq != SEQ_NONE;
1950 spin_unlock_irqrestore(&cs->ev_lock, flags);
1950 process_event(cs, ev); 1951 process_event(cs, ev);
1952 spin_lock_irqsave(&cs->ev_lock, flags);
1951 kfree(ev->ptr); 1953 kfree(ev->ptr);
1952 ev->ptr = NULL; 1954 ev->ptr = NULL;
1953 if (was_busy && cs->cur_at_seq == SEQ_NONE) 1955 if (was_busy && cs->cur_at_seq == SEQ_NONE)
1954 check_flags = 1; 1956 check_flags = 1;
1955 1957
1956 head = (head + 1) % MAX_EVENTS; 1958 head = (head + 1) % MAX_EVENTS;
1957 atomic_set(&cs->ev_head, head); 1959 cs->ev_head = head;
1958 } 1960 }
1959 1961
1962 spin_unlock_irqrestore(&cs->ev_lock, flags);
1963
1960 if (i == 2 * MAX_EVENTS) { 1964 if (i == 2 * MAX_EVENTS) {
1961 err("infinite loop in process_events; aborting."); 1965 dev_err(cs->dev,
1966 "infinite loop in process_events; aborting.\n");
1962 } 1967 }
1963} 1968}
1964 1969
@@ -1970,12 +1975,9 @@ void gigaset_handle_event(unsigned long data)
1970{ 1975{
1971 struct cardstate *cs = (struct cardstate *) data; 1976 struct cardstate *cs = (struct cardstate *) data;
1972 1977
1973 IFNULLRET(cs);
1974 IFNULLRET(cs->inbuf);
1975
1976 /* handle incoming data on control/common channel */ 1978 /* handle incoming data on control/common channel */
1977 if (atomic_read(&cs->inbuf->head) != atomic_read(&cs->inbuf->tail)) { 1979 if (atomic_read(&cs->inbuf->head) != atomic_read(&cs->inbuf->tail)) {
1978 dbg(DEBUG_INTR, "processing new data"); 1980 gig_dbg(DEBUG_INTR, "processing new data");
1979 cs->ops->handle_input(cs->inbuf); 1981 cs->ops->handle_input(cs->inbuf);
1980 } 1982 }
1981 1983
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index 729edcdb6dac..22b9693f7c0a 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -1,11 +1,16 @@
1/* Siemens Gigaset 307x driver 1/*
2 * Siemens Gigaset 307x driver
2 * Common header file for all connection variants 3 * Common header file for all connection variants
3 * 4 *
4 * Written by Stefan Eilers <Eilers.Stefan@epost.de> 5 * Written by Stefan Eilers
5 * and Hansjoerg Lipp <hjlipp@web.de> 6 * and Hansjoerg Lipp <hjlipp@web.de>
6 * 7 *
7 * Version: $Id: gigaset.h,v 1.97.4.26 2006/02/04 18:28:16 hjlipp Exp $ 8 * =====================================================================
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 * =====================================================================
9 */ 14 */
10 15
11#ifndef GIGASET_H 16#ifndef GIGASET_H
@@ -15,7 +20,6 @@
15#include <linux/kernel.h> 20#include <linux/kernel.h>
16#include <linux/compiler.h> 21#include <linux/compiler.h>
17#include <linux/types.h> 22#include <linux/types.h>
18#include <asm/atomic.h>
19#include <linux/spinlock.h> 23#include <linux/spinlock.h>
20#include <linux/isdnif.h> 24#include <linux/isdnif.h>
21#include <linux/usb.h> 25#include <linux/usb.h>
@@ -27,21 +31,22 @@
27#include <linux/tty.h> 31#include <linux/tty.h>
28#include <linux/tty_driver.h> 32#include <linux/tty_driver.h>
29#include <linux/list.h> 33#include <linux/list.h>
34#include <asm/atomic.h>
30 35
31#define GIG_VERSION {0,5,0,0} 36#define GIG_VERSION {0,5,0,0}
32#define GIG_COMPAT {0,4,0,0} 37#define GIG_COMPAT {0,4,0,0}
33 38
34#define MAX_REC_PARAMS 10 /* Max. number of params in response string */ 39#define MAX_REC_PARAMS 10 /* Max. number of params in response string */
35#define MAX_RESP_SIZE 512 /* Max. size of a response string */ 40#define MAX_RESP_SIZE 512 /* Max. size of a response string */
36#define HW_HDR_LEN 2 /* Header size used to store ack info */ 41#define HW_HDR_LEN 2 /* Header size used to store ack info */
37 42
38#define MAX_EVENTS 64 /* size of event queue */ 43#define MAX_EVENTS 64 /* size of event queue */
39 44
40#define RBUFSIZE 8192 45#define RBUFSIZE 8192
41#define SBUFSIZE 4096 /* sk_buff payload size */ 46#define SBUFSIZE 4096 /* sk_buff payload size */
42 47
43#define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */ 48#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */
44#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */ 49#define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */
45 50
46/* compile time options */ 51/* compile time options */
47#define GIG_MAJOR 0 52#define GIG_MAJOR 0
@@ -50,10 +55,7 @@
50#define GIG_RETRYCID 55#define GIG_RETRYCID
51#define GIG_X75 56#define GIG_X75
52 57
53#define MAX_TIMER_INDEX 1000 58#define GIG_TICK 100 /* in milliseconds */
54#define MAX_SEQ_INDEX 1000
55
56#define GIG_TICK (HZ / 10)
57 59
58/* timeout values (unit: 1 sec) */ 60/* timeout values (unit: 1 sec) */
59#define INIT_TIMEOUT 1 61#define INIT_TIMEOUT 1
@@ -67,74 +69,89 @@
67 69
68#define MAXACT 3 70#define MAXACT 3
69 71
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
76extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */ 72extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
77 73
78/* any combination of these can be given with the 'debug=' parameter to insmod, e.g. 74/* any combination of these can be given with the 'debug=' parameter to insmod,
79 * 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and DEBUG_INTR. */ 75 * e.g. 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and
80enum debuglevel { /* up to 24 bits (atomic_t) */ 76 * DEBUG_INTR.
77 */
78enum debuglevel {
81 DEBUG_REG = 0x0002, /* serial port I/O register operations */ 79 DEBUG_REG = 0x0002, /* serial port I/O register operations */
82 DEBUG_OPEN = 0x0004, /* open/close serial port */ 80 DEBUG_OPEN = 0x0004, /* open/close serial port */
83 DEBUG_INTR = 0x0008, /* interrupt processing */ 81 DEBUG_INTR = 0x0008, /* interrupt processing */
84 DEBUG_INTR_DUMP = 0x0010, /* Activating hexdump debug output on interrupt 82 DEBUG_INTR_DUMP = 0x0010, /* Activating hexdump debug output on
85 requests, not available as run-time option */ 83 interrupt requests, not available as
84 run-time option */
86 DEBUG_CMD = 0x00020, /* sent/received LL commands */ 85 DEBUG_CMD = 0x00020, /* sent/received LL commands */
87 DEBUG_STREAM = 0x00040, /* application data stream I/O events */ 86 DEBUG_STREAM = 0x00040, /* application data stream I/O events */
88 DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */ 87 DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */
89 DEBUG_LLDATA = 0x00100, /* sent/received LL data */ 88 DEBUG_LLDATA = 0x00100, /* sent/received LL data */
90 DEBUG_INTR_0 = 0x00200, /* serial port output interrupt processing */ 89 DEBUG_INTR_0 = 0x00200, /* serial port interrupt processing */
91 DEBUG_DRIVER = 0x00400, /* driver structure */ 90 DEBUG_DRIVER = 0x00400, /* driver structure */
92 DEBUG_HDLC = 0x00800, /* M10x HDLC processing */ 91 DEBUG_HDLC = 0x00800, /* M10x HDLC processing */
93 DEBUG_WRITE = 0x01000, /* M105 data write */ 92 DEBUG_WRITE = 0x01000, /* M105 data write */
94 DEBUG_TRANSCMD = 0x02000, /*AT-COMMANDS+RESPONSES*/ 93 DEBUG_TRANSCMD = 0x02000, /* AT-COMMANDS+RESPONSES */
95 DEBUG_MCMD = 0x04000, /*COMMANDS THAT ARE SENT VERY OFTEN*/ 94 DEBUG_MCMD = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */
96 DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data structures */ 95 DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data
96 structures */
97 DEBUG_LOCK = 0x10000, /* semaphore operations */ 97 DEBUG_LOCK = 0x10000, /* semaphore operations */
98 DEBUG_OUTPUT = 0x20000, /* output to device */ 98 DEBUG_OUTPUT = 0x20000, /* output to device */
99 DEBUG_ISO = 0x40000, /* isochronous transfers */ 99 DEBUG_ISO = 0x40000, /* isochronous transfers */
100 DEBUG_IF = 0x80000, /* character device operations */ 100 DEBUG_IF = 0x80000, /* character device operations */
101 DEBUG_USBREQ = 0x100000, /* USB communication (except payload data) */ 101 DEBUG_USBREQ = 0x100000, /* USB communication (except payload
102 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when MS_LOCKED */ 102 data) */
103 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when
104 MS_LOCKED */
103 105
104 DEBUG_ANY = 0x3fffff, /* print message if any of the others is activated */ 106 DEBUG_ANY = 0x3fffff, /* print message if any of the others is
107 activated */
105}; 108};
106 109
107#ifdef CONFIG_GIGASET_DEBUG 110/* missing from linux/device.h ... */
108#define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ) 111#ifndef dev_notice
109//#define DEBUG_DEFAULT (DEBUG_LOCK | DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUF_IF | DEBUG_DRIVER | DEBUG_OUTPUT | DEBUG_INTR) 112#define dev_notice(dev, format, arg...) \
110#else 113 dev_printk(KERN_NOTICE , dev , format , ## arg)
111#define DEBUG_DEFAULT 0
112#endif 114#endif
113 115
114/* redefine syslog macros to prepend module name instead of entire source path */ 116/* Kernel message macros for situations where dev_printk and friends cannot be
115/* The space before the comma in ", ##" is needed by gcc 2.95 */ 117 * used for lack of reliable access to a device structure.
118 * linux/usb.h already contains these but in an obsolete form which clutters
119 * the log needlessly, and according to the USB maintainer those should be
120 * removed rather than fixed anyway.
121 */
122#undef err
116#undef info 123#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 124#undef warn
123#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) 125#undef notice
124 126
125#undef err 127#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
126#define err(format, arg...) printk(KERN_ERR "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) 128 format "\n" , ## arg)
129#define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
130 format "\n" , ## arg)
131#define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \
132 format "\n" , ## arg)
133#define notice(format, arg...) printk(KERN_NOTICE KBUILD_MODNAME ": " \
134 format "\n" , ## arg)
127 135
128#undef dbg
129#ifdef CONFIG_GIGASET_DEBUG 136#ifdef CONFIG_GIGASET_DEBUG
130#define dbg(level, format, arg...) do { if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \ 137
131 printk(KERN_DEBUG "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg); } while (0) 138#define gig_dbg(level, format, arg...) \
139 do { \
140 if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
141 printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
142 ## arg); \
143 } while (0)
144#define DEBUG_DEFAULT (DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
145
132#else 146#else
133#define dbg(level, format, arg...) do {} while (0) 147
148#define gig_dbg(level, format, arg...) do {} while (0)
149#define DEBUG_DEFAULT 0
150
134#endif 151#endif
135 152
136void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, 153void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
137 size_t len, const unsigned char *buf, int from_user); 154 size_t len, const unsigned char *buf);
138 155
139/* connection state */ 156/* connection state */
140#define ZSAU_NONE 0 157#define ZSAU_NONE 0
@@ -148,13 +165,14 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
148#define ZSAU_UNKNOWN -1 165#define ZSAU_UNKNOWN -1
149 166
150/* USB control transfer requests */ 167/* USB control transfer requests */
151#define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT) 168#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) 169#define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
153 170
154/* int-in-events 3070 */ 171/* int-in-events 3070 */
155#define HD_B1_FLOW_CONTROL 0x80 172#define HD_B1_FLOW_CONTROL 0x80
156#define HD_B2_FLOW_CONTROL 0x81 173#define HD_B2_FLOW_CONTROL 0x81
157#define HD_RECEIVEATDATA_ACK (0x35) // 3070 // att: HD_RECEIVE>>AT<<DATA_ACK 174#define HD_RECEIVEATDATA_ACK (0x35) // 3070
175 // att: HD_RECEIVE>>AT<<DATA_ACK
158#define HD_READY_SEND_ATDATA (0x36) // 3070 176#define HD_READY_SEND_ATDATA (0x36) // 3070
159#define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070 177#define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070
160#define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070 178#define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070
@@ -181,17 +199,18 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
181#define HD_CLOSE_ATCHANNEL (0x29) // 3070 199#define HD_CLOSE_ATCHANNEL (0x29) // 3070
182 200
183/* USB frames for isochronous transfer */ 201/* USB frames for isochronous transfer */
184#define BAS_FRAMETIME 1 /* number of milliseconds between frames */ 202#define BAS_FRAMETIME 1 /* number of milliseconds between frames */
185#define BAS_NUMFRAMES 8 /* number of frames per URB */ 203#define BAS_NUMFRAMES 8 /* number of frames per URB */
186#define BAS_MAXFRAME 16 /* allocated bytes per frame */ 204#define BAS_MAXFRAME 16 /* allocated bytes per frame */
187#define BAS_NORMFRAME 8 /* send size without flow control */ 205#define BAS_NORMFRAME 8 /* send size without flow control */
188#define BAS_HIGHFRAME 10 /* " " with positive flow control */ 206#define BAS_HIGHFRAME 10 /* " " with positive flow control */
189#define BAS_LOWFRAME 5 /* " " with negative flow control */ 207#define BAS_LOWFRAME 5 /* " " with negative flow control */
190#define BAS_CORRFRAMES 4 /* flow control multiplicator */ 208#define BAS_CORRFRAMES 4 /* flow control multiplicator */
191 209
192#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES) /* size of isochronous input buffer per URB */ 210#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES)
193#define BAS_OUTBUFSIZE 4096 /* size of common isochronous output buffer */ 211 /* size of isoc in buf per URB */
194#define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isochronous output buffer */ 212#define BAS_OUTBUFSIZE 4096 /* size of common isoc out buffer */
213#define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isoc out buf */
195 214
196#define BAS_INURBS 3 215#define BAS_INURBS 3
197#define BAS_OUTURBS 3 216#define BAS_OUTURBS 3
@@ -207,40 +226,40 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
207#define AT_NUM 7 226#define AT_NUM 7
208 227
209/* variables in struct at_state_t */ 228/* variables in struct at_state_t */
210#define VAR_ZSAU 0 229#define VAR_ZSAU 0
211#define VAR_ZDLE 1 230#define VAR_ZDLE 1
212#define VAR_ZVLS 2 231#define VAR_ZVLS 2
213#define VAR_ZCTP 3 232#define VAR_ZCTP 3
214#define VAR_NUM 4 233#define VAR_NUM 4
215 234
216#define STR_NMBR 0 235#define STR_NMBR 0
217#define STR_ZCPN 1 236#define STR_ZCPN 1
218#define STR_ZCON 2 237#define STR_ZCON 2
219#define STR_ZBC 3 238#define STR_ZBC 3
220#define STR_ZHLC 4 239#define STR_ZHLC 4
221#define STR_NUM 5 240#define STR_NUM 5
222 241
223#define EV_TIMEOUT -105 242#define EV_TIMEOUT -105
224#define EV_IF_VER -106 243#define EV_IF_VER -106
225#define EV_PROC_CIDMODE -107 244#define EV_PROC_CIDMODE -107
226#define EV_SHUTDOWN -108 245#define EV_SHUTDOWN -108
227#define EV_START -110 246#define EV_START -110
228#define EV_STOP -111 247#define EV_STOP -111
229#define EV_IF_LOCK -112 248#define EV_IF_LOCK -112
230#define EV_PROTO_L2 -113 249#define EV_PROTO_L2 -113
231#define EV_ACCEPT -114 250#define EV_ACCEPT -114
232#define EV_DIAL -115 251#define EV_DIAL -115
233#define EV_HUP -116 252#define EV_HUP -116
234#define EV_BC_OPEN -117 253#define EV_BC_OPEN -117
235#define EV_BC_CLOSED -118 254#define EV_BC_CLOSED -118
236 255
237/* input state */ 256/* input state */
238#define INS_command 0x0001 257#define INS_command 0x0001
239#define INS_DLE_char 0x0002 258#define INS_DLE_char 0x0002
240#define INS_byte_stuff 0x0004 259#define INS_byte_stuff 0x0004
241#define INS_have_data 0x0008 260#define INS_have_data 0x0008
242#define INS_skip_frame 0x0010 261#define INS_skip_frame 0x0010
243#define INS_DLE_command 0x0020 262#define INS_DLE_command 0x0020
244#define INS_flag_hunt 0x0040 263#define INS_flag_hunt 0x0040
245 264
246/* channel state */ 265/* channel state */
@@ -248,27 +267,27 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
248#define CHS_B_UP 0x02 267#define CHS_B_UP 0x02
249#define CHS_NOTIFY_LL 0x04 268#define CHS_NOTIFY_LL 0x04
250 269
251#define ICALL_REJECT 0 270#define ICALL_REJECT 0
252#define ICALL_ACCEPT 1 271#define ICALL_ACCEPT 1
253#define ICALL_IGNORE 2 272#define ICALL_IGNORE 2
254 273
255/* device state */ 274/* device state */
256#define MS_UNINITIALIZED 0 275#define MS_UNINITIALIZED 0
257#define MS_INIT 1 276#define MS_INIT 1
258#define MS_LOCKED 2 277#define MS_LOCKED 2
259#define MS_SHUTDOWN 3 278#define MS_SHUTDOWN 3
260#define MS_RECOVER 4 279#define MS_RECOVER 4
261#define MS_READY 5 280#define MS_READY 5
262 281
263/* mode */ 282/* mode */
264#define M_UNKNOWN 0 283#define M_UNKNOWN 0
265#define M_CONFIG 1 284#define M_CONFIG 1
266#define M_UNIMODEM 2 285#define M_UNIMODEM 2
267#define M_CID 3 286#define M_CID 3
268 287
269/* start mode */ 288/* start mode */
270#define SM_LOCKED 0 289#define SM_LOCKED 0
271#define SM_ISDN 1 /* default */ 290#define SM_ISDN 1 /* default */
272 291
273struct gigaset_ops; 292struct gigaset_ops;
274struct gigaset_driver; 293struct gigaset_driver;
@@ -283,27 +302,26 @@ struct ser_bc_state;
283struct bas_bc_state; 302struct bas_bc_state;
284 303
285struct reply_t { 304struct reply_t {
286 int resp_code; /* RSP_XXXX */ 305 int resp_code; /* RSP_XXXX */
287 int min_ConState; /* <0 => ignore */ 306 int min_ConState; /* <0 => ignore */
288 int max_ConState; /* <0 => ignore */ 307 int max_ConState; /* <0 => ignore */
289 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/ 308 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/
290 int new_ConState; /* <0 => ignore */ 309 int new_ConState; /* <0 => ignore */
291 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/ 310 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/
292 int action[MAXACT]; /* ACT_XXXX */ 311 int action[MAXACT]; /* ACT_XXXX */
293 char *command; /* NULL==none */ 312 char *command; /* NULL==none */
294}; 313};
295 314
296extern struct reply_t gigaset_tab_cid_m10x[]; 315extern struct reply_t gigaset_tab_cid_m10x[];
297extern struct reply_t gigaset_tab_nocid_m10x[]; 316extern struct reply_t gigaset_tab_nocid_m10x[];
298 317
299struct inbuf_t { 318struct inbuf_t {
300 unsigned char *rcvbuf; /* usb-gigaset receive buffer */ 319 unsigned char *rcvbuf; /* usb-gigaset receive buffer */
301 struct bc_state *bcs; 320 struct bc_state *bcs;
302 struct cardstate *cs; 321 struct cardstate *cs;
303 int inputstate; 322 int inputstate;
304 323 atomic_t head, tail;
305 atomic_t head, tail; 324 unsigned char data[RBUFSIZE];
306 unsigned char data[RBUFSIZE];
307}; 325};
308 326
309/* isochronous write buffer structure 327/* isochronous write buffer structure
@@ -319,16 +337,9 @@ struct inbuf_t {
319 * if writesem <= 0, data[write..read-1] is currently being written to 337 * 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 338 * - 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 339 * reached; if nextread==write (buffer contains no data to send), either the
322 * BAS_OUTBUFPAD bytes immediately before data[write] (if write>=BAS_OUTBUFPAD) 340 * BAS_OUTBUFPAD bytes immediately before data[write] (if
323 * or those of the pad area (if write<BAS_OUTBUFPAD) are also filled with that 341 * write>=BAS_OUTBUFPAD) or those of the pad area (if write<BAS_OUTBUFPAD)
324 * value 342 * are also filled with that 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 */ 343 */
333struct isowbuf_t { 344struct isowbuf_t {
334 atomic_t read; 345 atomic_t read;
@@ -358,34 +369,28 @@ struct isow_urbctx_t {
358 * it is currently assigned a B channel 369 * it is currently assigned a B channel
359 */ 370 */
360struct at_state_t { 371struct at_state_t {
361 struct list_head list; 372 struct list_head list;
362 int waiting; 373 int waiting;
363 int getstring; 374 int getstring;
364 atomic_t timer_index; 375 unsigned timer_index;
365 unsigned long timer_expires; 376 unsigned long timer_expires;
366 int timer_active; 377 int timer_active;
367 unsigned int ConState; /* State of connection */ 378 unsigned int ConState; /* State of connection */
368 struct reply_t *replystruct; 379 struct reply_t *replystruct;
369 int cid; 380 int cid;
370 int int_var[VAR_NUM]; /* see VAR_XXXX */ 381 int int_var[VAR_NUM]; /* see VAR_XXXX */
371 char *str_var[STR_NUM]; /* see STR_XXXX */ 382 char *str_var[STR_NUM]; /* see STR_XXXX */
372 unsigned pending_commands; /* see PC_XXXX */ 383 unsigned pending_commands; /* see PC_XXXX */
373 atomic_t seq_index; 384 unsigned seq_index;
374 385
375 struct cardstate *cs; 386 struct cardstate *cs;
376 struct bc_state *bcs; 387 struct bc_state *bcs;
377}; 388};
378 389
379struct resp_type_t { 390struct resp_type_t {
380 unsigned char *response; 391 unsigned char *response;
381 int resp_code; /* RSP_XXXX */ 392 int resp_code; /* RSP_XXXX */
382 int type; /* RT_XXXX */ 393 int type; /* RT_XXXX */
383};
384
385struct prot_skb {
386 atomic_t empty;
387 struct semaphore *sem;
388 struct sk_buff *skb;
389}; 394};
390 395
391struct event_t { 396struct event_t {
@@ -398,29 +403,29 @@ struct event_t {
398 403
399/* This buffer holds all information about the used B-Channel */ 404/* This buffer holds all information about the used B-Channel */
400struct bc_state { 405struct bc_state {
401 struct sk_buff *tx_skb; /* Current transfer buffer to modem */ 406 struct sk_buff *tx_skb; /* Current transfer buffer to modem */
402 struct sk_buff_head squeue; /* B-Channel send Queue */ 407 struct sk_buff_head squeue; /* B-Channel send Queue */
403 408
404 /* Variables for debugging .. */ 409 /* Variables for debugging .. */
405 int corrupted; /* Counter for corrupted packages */ 410 int corrupted; /* Counter for corrupted packages */
406 int trans_down; /* Counter of packages (downstream) */ 411 int trans_down; /* Counter of packages (downstream) */
407 int trans_up; /* Counter of packages (upstream) */ 412 int trans_up; /* Counter of packages (upstream) */
408 413
409 struct at_state_t at_state; 414 struct at_state_t at_state;
410 unsigned long rcvbytes; 415 unsigned long rcvbytes;
411 416
412 __u16 fcs; 417 __u16 fcs;
413 struct sk_buff *skb; 418 struct sk_buff *skb;
414 int inputstate; /* see INS_XXXX */ 419 int inputstate; /* see INS_XXXX */
415 420
416 int channel; 421 int channel;
417 422
418 struct cardstate *cs; 423 struct cardstate *cs;
419 424
420 unsigned chstate; /* bitmap (CHS_*) */ 425 unsigned chstate; /* bitmap (CHS_*) */
421 int ignore; 426 int ignore;
422 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */ 427 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
423 char *commands[AT_NUM]; /* see AT_XXXX */ 428 char *commands[AT_NUM]; /* see AT_XXXX */
424 429
425#ifdef CONFIG_GIGASET_DEBUG 430#ifdef CONFIG_GIGASET_DEBUG
426 int emptycount; 431 int emptycount;
@@ -428,37 +433,39 @@ struct bc_state {
428 int busy; 433 int busy;
429 int use_count; 434 int use_count;
430 435
431 /* hardware drivers */ 436 /* private data of hardware drivers */
432 union { 437 union {
433 struct ser_bc_state *ser; /* private data of serial hardware driver */ 438 struct ser_bc_state *ser; /* serial hardware driver */
434 struct usb_bc_state *usb; /* private data of usb hardware driver */ 439 struct usb_bc_state *usb; /* usb hardware driver (m105) */
435 struct bas_bc_state *bas; 440 struct bas_bc_state *bas; /* usb hardware driver (base) */
436 } hw; 441 } hw;
437}; 442};
438 443
439struct cardstate { 444struct cardstate {
440 struct gigaset_driver *driver; 445 struct gigaset_driver *driver;
441 unsigned minor_index; 446 unsigned minor_index;
447 struct device *dev;
442 448
443 const struct gigaset_ops *ops; 449 const struct gigaset_ops *ops;
444 450
445 /* Stuff to handle communication */ 451 /* Stuff to handle communication */
446 //wait_queue_head_t initwait;
447 wait_queue_head_t waitqueue; 452 wait_queue_head_t waitqueue;
448 int waiting; 453 int waiting;
449 atomic_t mode; /* see M_XXXX */ 454 atomic_t mode; /* see M_XXXX */
450 atomic_t mstate; /* Modem state: see MS_XXXX */ 455 atomic_t mstate; /* Modem state: see MS_XXXX */
451 /* only changed by the event layer */ 456 /* only changed by the event layer */
452 int cmd_result; 457 int cmd_result;
453 458
454 int channels; 459 int channels;
455 struct bc_state *bcs; /* Array of struct bc_state */ 460 struct bc_state *bcs; /* Array of struct bc_state */
456 461
457 int onechannel; /* data and commands transmitted in one stream (M10x) */ 462 int onechannel; /* data and commands transmitted in one
463 stream (M10x) */
458 464
459 spinlock_t lock; 465 spinlock_t lock;
460 struct at_state_t at_state; /* at_state_t for cid == 0 */ 466 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 */ 467 struct list_head temp_at_states;/* list of temporary "struct
468 at_state_t"s without B channel */
462 469
463 struct inbuf_t *inbuf; 470 struct inbuf_t *inbuf;
464 471
@@ -474,58 +481,69 @@ struct cardstate {
474 unsigned fwver[4]; 481 unsigned fwver[4];
475 int gotfwver; 482 int gotfwver;
476 483
477 atomic_t running; /* !=0 if events are handled */ 484 unsigned running; /* !=0 if events are handled */
478 atomic_t connected; /* !=0 if hardware is connected */ 485 unsigned connected; /* !=0 if hardware is connected */
486 unsigned isdn_up; /* !=0 after ISDN_STAT_RUN */
479 487
480 atomic_t cidmode; 488 unsigned cidmode;
481 489
482 int myid; /* id for communication with LL */ 490 int myid; /* id for communication with LL */
483 isdn_if iif; 491 isdn_if iif;
484 492
485 struct reply_t *tabnocid; 493 struct reply_t *tabnocid;
486 struct reply_t *tabcid; 494 struct reply_t *tabcid;
487 int cs_init; 495 int cs_init;
488 int ignoreframes; /* frames to ignore after setting up the B channel */ 496 int ignoreframes; /* frames to ignore after setting up the
489 struct semaphore sem; /* locks this structure: */ 497 B channel */
490 /* connected is not changed, */ 498 struct mutex mutex; /* locks this structure:
491 /* hardware_up is not changed, */ 499 * connected is not changed,
492 /* MState is not changed to or from MS_LOCKED */ 500 * hardware_up is not changed,
501 * MState is not changed to or from
502 * MS_LOCKED */
493 503
494 struct timer_list timer; 504 struct timer_list timer;
495 int retry_count; 505 int retry_count;
496 int dle; /* !=0 if modem commands/responses are dle encoded */ 506 int dle; /* !=0 if modem commands/responses are
497 int cur_at_seq; /* sequence of AT commands being processed */ 507 dle encoded */
498 int curchannel; /* channel, those commands are meant for */ 508 int cur_at_seq; /* sequence of AT commands being
499 atomic_t commands_pending; /* flag(s) in xxx.commands_pending have been set */ 509 processed */
500 struct tasklet_struct event_tasklet; /* tasklet for serializing AT commands. Scheduled 510 int curchannel; /* channel those commands are meant
501 * -> for modem reponses (and incomming data for M10x) 511 for */
502 * -> on timeout 512 atomic_t commands_pending; /* flag(s) in xxx.commands_pending have
503 * -> after setting bits in xxx.at_state.pending_command 513 been set */
504 * (e.g. command from LL) */ 514 struct tasklet_struct event_tasklet;
505 struct tasklet_struct write_tasklet; /* tasklet for serial output 515 /* tasklet for serializing AT commands.
506 * (not used in base driver) */ 516 * Scheduled
517 * -> for modem reponses (and
518 * incoming data for M10x)
519 * -> on timeout
520 * -> after setting bits in
521 * xxx.at_state.pending_command
522 * (e.g. command from LL) */
523 struct tasklet_struct write_tasklet;
524 /* tasklet for serial output
525 * (not used in base driver) */
507 526
508 /* event queue */ 527 /* event queue */
509 struct event_t events[MAX_EVENTS]; 528 struct event_t events[MAX_EVENTS];
510 atomic_t ev_tail, ev_head; 529 unsigned ev_tail, ev_head;
511 spinlock_t ev_lock; 530 spinlock_t ev_lock;
512 531
513 /* current modem response */ 532 /* current modem response */
514 unsigned char respdata[MAX_RESP_SIZE]; 533 unsigned char respdata[MAX_RESP_SIZE];
515 unsigned cbytes; 534 unsigned cbytes;
516 535
517 /* hardware drivers */ 536 /* private data of hardware drivers */
518 union { 537 union {
519 struct usb_cardstate *usb; /* private data of USB hardware driver */ 538 struct usb_cardstate *usb; /* USB hardware driver (m105) */
520 struct ser_cardstate *ser; /* private data of serial hardware driver */ 539 struct ser_cardstate *ser; /* serial hardware driver */
521 struct bas_cardstate *bas; /* private data of base hardware driver */ 540 struct bas_cardstate *bas; /* USB hardware driver (base) */
522 } hw; 541 } hw;
523}; 542};
524 543
525struct gigaset_driver { 544struct gigaset_driver {
526 struct list_head list; 545 struct list_head list;
527 spinlock_t lock; /* locks minor tables and blocked */ 546 spinlock_t lock; /* locks minor tables and blocked */
528 //struct semaphore sem; /* locks this structure */
529 struct tty_driver *tty; 547 struct tty_driver *tty;
530 unsigned have_tty; 548 unsigned have_tty;
531 unsigned minor; 549 unsigned minor;
@@ -553,37 +571,42 @@ struct bas_bc_state {
553 struct isow_urbctx_t isoouturbs[BAS_OUTURBS]; 571 struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
554 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl; 572 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
555 struct isowbuf_t *isooutbuf; 573 struct isowbuf_t *isooutbuf;
556 unsigned numsub; /* submitted URB counter (for diagnostic messages only) */ 574 unsigned numsub; /* submitted URB counter
575 (for diagnostic messages only) */
557 struct tasklet_struct sent_tasklet; 576 struct tasklet_struct sent_tasklet;
558 577
559 /* isochronous input state */ 578 /* isochronous input state */
560 spinlock_t isoinlock; 579 spinlock_t isoinlock;
561 struct urb *isoinurbs[BAS_INURBS]; 580 struct urb *isoinurbs[BAS_INURBS];
562 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS]; 581 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
563 struct urb *isoindone; /* completed isoc read URB */ 582 struct urb *isoindone; /* completed isoc read URB */
564 int loststatus; /* status of dropped URB */ 583 int loststatus; /* status of dropped URB */
565 unsigned isoinlost; /* number of bytes lost */ 584 unsigned isoinlost; /* number of bytes lost */
566 /* state of bit unstuffing algorithm (in addition to BC_state.inputstate) */ 585 /* state of bit unstuffing algorithm
567 unsigned seqlen; /* number of '1' bits not yet unstuffed */ 586 (in addition to BC_state.inputstate) */
568 unsigned inbyte, inbits; /* collected bits for next byte */ 587 unsigned seqlen; /* number of '1' bits not yet
588 unstuffed */
589 unsigned inbyte, inbits; /* collected bits for next byte */
569 /* statistics */ 590 /* statistics */
570 unsigned goodbytes; /* bytes correctly received */ 591 unsigned goodbytes; /* bytes correctly received */
571 unsigned alignerrs; /* frames with incomplete byte at end */ 592 unsigned alignerrs; /* frames with incomplete byte at end */
572 unsigned fcserrs; /* FCS errors */ 593 unsigned fcserrs; /* FCS errors */
573 unsigned frameerrs; /* framing errors */ 594 unsigned frameerrs; /* framing errors */
574 unsigned giants; /* long frames */ 595 unsigned giants; /* long frames */
575 unsigned runts; /* short frames */ 596 unsigned runts; /* short frames */
576 unsigned aborts; /* HDLC aborts */ 597 unsigned aborts; /* HDLC aborts */
577 unsigned shared0s; /* '0' bits shared between flags */ 598 unsigned shared0s; /* '0' bits shared between flags */
578 unsigned stolen0s; /* '0' stuff bits also serving as leading flag bits */ 599 unsigned stolen0s; /* '0' stuff bits also serving as
600 leading flag bits */
579 struct tasklet_struct rcvd_tasklet; 601 struct tasklet_struct rcvd_tasklet;
580}; 602};
581 603
582struct gigaset_ops { 604struct gigaset_ops {
583 /* Called from ev-layer.c/interface.c for sending AT commands to the device */ 605 /* Called from ev-layer.c/interface.c for sending AT commands to the
606 device */
584 int (*write_cmd)(struct cardstate *cs, 607 int (*write_cmd)(struct cardstate *cs,
585 const unsigned char *buf, int len, 608 const unsigned char *buf, int len,
586 struct tasklet_struct *wake_tasklet); 609 struct tasklet_struct *wake_tasklet);
587 610
588 /* Called from interface.c for additional device control */ 611 /* Called from interface.c for additional device control */
589 int (*write_room)(struct cardstate *cs); 612 int (*write_room)(struct cardstate *cs);
@@ -604,7 +627,7 @@ struct gigaset_ops {
604 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */ 627 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
605 int (*freebcshw)(struct bc_state *bcs); 628 int (*freebcshw)(struct bc_state *bcs);
606 629
607 /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting bcs->hw.xxx */ 630 /* Called by gigaset_bchannel_down() for resetting bcs->hw.xxx */
608 void (*reinitbcshw)(struct bc_state *bcs); 631 void (*reinitbcshw)(struct bc_state *bcs);
609 632
610 /* Called by gigaset_initcs() for setting up cs->hw.xxx */ 633 /* Called by gigaset_initcs() for setting up cs->hw.xxx */
@@ -613,13 +636,10 @@ struct gigaset_ops {
613 /* Called by gigaset_freecs() for freeing cs->hw.xxx */ 636 /* Called by gigaset_freecs() for freeing cs->hw.xxx */
614 void (*freecshw)(struct cardstate *cs); 637 void (*freecshw)(struct cardstate *cs);
615 638
616 ///* Called by gigaset_stop() for killing URBs, shutting down the device, ... 639 /* Called from common.c/interface.c for additional serial port
617 // hardwareup: ==0: don't try to shut down the device, hardware is really not accessible 640 control */
618 // !=0: hardware still up */ 641 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state,
619 //void (*stophw)(struct cardstate *cs, int hardwareup); 642 unsigned new_state);
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); 643 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
624 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag); 644 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
625 645
@@ -639,7 +659,7 @@ struct gigaset_ops {
639 * <DLE_FLAG>: 0x10 659 * <DLE_FLAG>: 0x10
640 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+ 660 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
641 */ 661 */
642#define DLE_FLAG 0x10 662#define DLE_FLAG 0x10
643 663
644/* =========================================================================== 664/* ===========================================================================
645 * Functions implemented in asyncdata.c 665 * Functions implemented in asyncdata.c
@@ -667,7 +687,8 @@ void gigaset_isoc_input(struct inbuf_t *inbuf);
667 687
668/* Called from bas-gigaset.c to process a block of data 688/* Called from bas-gigaset.c to process a block of data
669 * received through the isochronous channel */ 689 * received through the isochronous channel */
670void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs); 690void gigaset_isoc_receive(unsigned char *src, unsigned count,
691 struct bc_state *bcs);
671 692
672/* Called from bas-gigaset.c to put a block of data 693/* Called from bas-gigaset.c to put a block of data
673 * into the isochronous output buffer */ 694 * into the isochronous output buffer */
@@ -703,7 +724,7 @@ static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
703 isdn_ctrl response; 724 isdn_ctrl response;
704 725
705 /* error -> LL */ 726 /* error -> LL */
706 dbg(DEBUG_CMD, "sending L1ERR"); 727 gig_dbg(DEBUG_CMD, "sending L1ERR");
707 response.driver = bcs->cs->myid; 728 response.driver = bcs->cs->myid;
708 response.command = ISDN_STAT_L1ERR; 729 response.command = ISDN_STAT_L1ERR;
709 response.arg = bcs->channel; 730 response.arg = bcs->channel;
@@ -727,8 +748,8 @@ void gigaset_handle_modem_response(struct cardstate *cs);
727 */ 748 */
728 749
729/* initialize sysfs for device */ 750/* initialize sysfs for device */
730void gigaset_init_dev_sysfs(struct usb_interface *interface); 751void gigaset_init_dev_sysfs(struct cardstate *cs);
731void gigaset_free_dev_sysfs(struct usb_interface *interface); 752void gigaset_free_dev_sysfs(struct cardstate *cs);
732 753
733/* =========================================================================== 754/* ===========================================================================
734 * Functions implemented in common.c/gigaset.h 755 * Functions implemented in common.c/gigaset.h
@@ -736,7 +757,7 @@ void gigaset_free_dev_sysfs(struct usb_interface *interface);
736 757
737void gigaset_bcs_reinit(struct bc_state *bcs); 758void gigaset_bcs_reinit(struct bc_state *bcs);
738void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, 759void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
739 struct cardstate *cs, int cid); 760 struct cardstate *cs, int cid);
740int gigaset_get_channel(struct bc_state *bcs); 761int gigaset_get_channel(struct bc_state *bcs);
741void gigaset_free_channel(struct bc_state *bcs); 762void gigaset_free_channel(struct bc_state *bcs);
742int gigaset_get_channels(struct cardstate *cs); 763int gigaset_get_channels(struct cardstate *cs);
@@ -745,16 +766,15 @@ void gigaset_block_channels(struct cardstate *cs);
745 766
746/* Allocate and initialize driver structure. */ 767/* Allocate and initialize driver structure. */
747struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, 768struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
748 const char *procname, 769 const char *procname,
749 const char *devname, 770 const char *devname,
750 const char *devfsname, 771 const char *devfsname,
751 const struct gigaset_ops *ops, 772 const struct gigaset_ops *ops,
752 struct module *owner); 773 struct module *owner);
753 774
754/* Deallocate driver structure. */ 775/* Deallocate driver structure. */
755void gigaset_freedriver(struct gigaset_driver *drv); 776void gigaset_freedriver(struct gigaset_driver *drv);
756void gigaset_debugdrivers(void); 777void gigaset_debugdrivers(void);
757struct cardstate *gigaset_get_cs_by_minor(unsigned minor);
758struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty); 778struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
759struct cardstate *gigaset_get_cs_by_id(int id); 779struct cardstate *gigaset_get_cs_by_id(int id);
760 780
@@ -763,7 +783,8 @@ struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv);
763void gigaset_unassign(struct cardstate *cs); 783void gigaset_unassign(struct cardstate *cs);
764void gigaset_blockdriver(struct gigaset_driver *drv); 784void gigaset_blockdriver(struct gigaset_driver *drv);
765 785
766/* Allocate and initialize card state. Calls hardware dependent gigaset_init[b]cs(). */ 786/* Allocate and initialize card state. Calls hardware dependent
787 gigaset_init[b]cs(). */
767struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, 788struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
768 int onechannel, int ignoreframes, 789 int onechannel, int ignoreframes,
769 int cidmode, const char *modulename); 790 int cidmode, const char *modulename);
@@ -788,8 +809,8 @@ void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
788 * ptr must be kmalloc()ed (and not be freed by the caller). 809 * ptr must be kmalloc()ed (and not be freed by the caller).
789 */ 810 */
790struct event_t *gigaset_add_event(struct cardstate *cs, 811struct event_t *gigaset_add_event(struct cardstate *cs,
791 struct at_state_t *at_state, int type, 812 struct at_state_t *at_state, int type,
792 void *ptr, int parameter, void *arg); 813 void *ptr, int parameter, void *arg);
793 814
794/* Called on CONFIG1 command from frontend. */ 815/* Called on CONFIG1 command from frontend. */
795int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode 816int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
@@ -799,7 +820,7 @@ static inline void gigaset_schedule_event(struct cardstate *cs)
799{ 820{
800 unsigned long flags; 821 unsigned long flags;
801 spin_lock_irqsave(&cs->lock, flags); 822 spin_lock_irqsave(&cs->lock, flags);
802 if (atomic_read(&cs->running)) 823 if (cs->running)
803 tasklet_schedule(&cs->event_tasklet); 824 tasklet_schedule(&cs->event_tasklet);
804 spin_unlock_irqrestore(&cs->lock, flags); 825 spin_unlock_irqrestore(&cs->lock, flags);
805} 826}
@@ -810,7 +831,7 @@ static inline void gigaset_bchannel_down(struct bc_state *bcs)
810{ 831{
811 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL); 832 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
812 833
813 dbg(DEBUG_CMD, "scheduling BC_CLOSED"); 834 gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED");
814 gigaset_schedule_event(bcs->cs); 835 gigaset_schedule_event(bcs->cs);
815} 836}
816 837
@@ -820,36 +841,19 @@ static inline void gigaset_bchannel_up(struct bc_state *bcs)
820{ 841{
821 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL); 842 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
822 843
823 dbg(DEBUG_CMD, "scheduling BC_OPEN"); 844 gig_dbg(DEBUG_CMD, "scheduling BC_OPEN");
824 gigaset_schedule_event(bcs->cs); 845 gigaset_schedule_event(bcs->cs);
825} 846}
826 847
827/* handling routines for sk_buff */ 848/* handling routines for sk_buff */
828/* ============================= */ 849/* ============================= */
829 850
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 */
837static 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 851/* pass received skb to LL
848 * Warning: skb must not be accessed anymore! 852 * Warning: skb must not be accessed anymore!
849 */ 853 */
850static inline void gigaset_rcv_skb(struct sk_buff *skb, 854static inline void gigaset_rcv_skb(struct sk_buff *skb,
851 struct cardstate *cs, 855 struct cardstate *cs,
852 struct bc_state *bcs) 856 struct bc_state *bcs)
853{ 857{
854 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb); 858 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
855 bcs->trans_down++; 859 bcs->trans_down++;
@@ -859,8 +863,8 @@ static inline void gigaset_rcv_skb(struct sk_buff *skb,
859 * Warning: skb must not be accessed anymore! 863 * Warning: skb must not be accessed anymore!
860 */ 864 */
861static inline void gigaset_rcv_error(struct sk_buff *procskb, 865static inline void gigaset_rcv_error(struct sk_buff *procskb,
862 struct cardstate *cs, 866 struct cardstate *cs,
863 struct bc_state *bcs) 867 struct bc_state *bcs)
864{ 868{
865 if (procskb) 869 if (procskb)
866 dev_kfree_skb(procskb); 870 dev_kfree_skb(procskb);
@@ -877,46 +881,9 @@ static inline void gigaset_rcv_error(struct sk_buff *procskb,
877/* bitwise byte inversion table */ 881/* bitwise byte inversion table */
878extern __u8 gigaset_invtab[]; /* in common.c */ 882extern __u8 gigaset_invtab[]; /* in common.c */
879 883
880
881/* append received bytes to inbuf */ 884/* append received bytes to inbuf */
882static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf, 885int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
883 const unsigned char *src, 886 unsigned numbytes);
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 887
921/* =========================================================================== 888/* ===========================================================================
922 * Functions implemented in interface.c 889 * Functions implemented in interface.c
@@ -924,7 +891,7 @@ static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf,
924 891
925/* initialize interface */ 892/* initialize interface */
926void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, 893void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
927 const char *devname, const char *devfsname); 894 const char *devname, const char *devfsname);
928/* release interface */ 895/* release interface */
929void gigaset_if_freedriver(struct gigaset_driver *drv); 896void gigaset_if_freedriver(struct gigaset_driver *drv);
930/* add minor */ 897/* add minor */
@@ -933,6 +900,6 @@ void gigaset_if_init(struct cardstate *cs);
933void gigaset_if_free(struct cardstate *cs); 900void gigaset_if_free(struct cardstate *cs);
934/* device received data */ 901/* device received data */
935void gigaset_if_receive(struct cardstate *cs, 902void gigaset_if_receive(struct cardstate *cs,
936 unsigned char *buffer, size_t len); 903 unsigned char *buffer, size_t len);
937 904
938#endif 905#endif
diff --git a/drivers/isdn/gigaset/i4l.c b/drivers/isdn/gigaset/i4l.c
index 731a675f21b0..1654fa413575 100644
--- a/drivers/isdn/gigaset/i4l.c
+++ b/drivers/isdn/gigaset/i4l.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers (Eilers.Stefan@epost.de), 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp (hjlipp@web.de), 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt (tilman@imap.cc). 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
8 * ===================================================================== 8 * =====================================================================
9 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
@@ -11,15 +11,11 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: i4l.c,v 1.3.2.9 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
21 17
22/* == Handling of I4L IO ============================================================================*/ 18/* == Handling of I4L IO =====================================================*/
23 19
24/* writebuf_from_LL 20/* writebuf_from_LL
25 * called by LL to transmit data on an open channel 21 * called by LL to transmit data on an open channel
@@ -29,14 +25,16 @@
29 * parameters: 25 * parameters:
30 * driverID driver ID as assigned by LL 26 * driverID driver ID as assigned by LL
31 * channel channel number 27 * channel channel number
32 * ack if != 0 LL wants to be notified on completion via statcallb(ISDN_STAT_BSENT) 28 * ack if != 0 LL wants to be notified on completion via
29 * statcallb(ISDN_STAT_BSENT)
33 * skb skb containing data to send 30 * skb skb containing data to send
34 * return value: 31 * return value:
35 * number of accepted bytes 32 * number of accepted bytes
36 * 0 if temporarily unable to accept data (out of buffer space) 33 * 0 if temporarily unable to accept data (out of buffer space)
37 * <0 on error (eg. -EINVAL) 34 * <0 on error (eg. -EINVAL)
38 */ 35 */
39static int writebuf_from_LL(int driverID, int channel, int ack, struct sk_buff *skb) 36static int writebuf_from_LL(int driverID, int channel, int ack,
37 struct sk_buff *skb)
40{ 38{
41 struct cardstate *cs; 39 struct cardstate *cs;
42 struct bc_state *bcs; 40 struct bc_state *bcs;
@@ -54,28 +52,25 @@ static int writebuf_from_LL(int driverID, int channel, int ack, struct sk_buff *
54 bcs = &cs->bcs[channel]; 52 bcs = &cs->bcs[channel];
55 len = skb->len; 53 len = skb->len;
56 54
57 dbg(DEBUG_LLDATA, 55 gig_dbg(DEBUG_LLDATA,
58 "Receiving data from LL (id: %d, channel: %d, ack: %d, size: %d)", 56 "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
59 driverID, channel, ack, len); 57 driverID, channel, ack, len);
60 58
61 if (!len) { 59 if (!len) {
62 if (ack) 60 if (ack)
63 warn("not ACKing empty packet from LL"); 61 notice("%s: not ACKing empty packet", __func__);
64 return 0; 62 return 0;
65 } 63 }
66 if (len > MAX_BUF_SIZE) { 64 if (len > MAX_BUF_SIZE) {
67 err("%s: packet too large (%d bytes)", __func__, channel); 65 err("%s: packet too large (%d bytes)", __func__, len);
68 return -EINVAL; 66 return -EINVAL;
69 } 67 }
70 68
71 if (!atomic_read(&cs->connected))
72 return -ENODEV;
73
74 skblen = ack ? len : 0; 69 skblen = ack ? len : 0;
75 skb->head[0] = skblen & 0xff; 70 skb->head[0] = skblen & 0xff;
76 skb->head[1] = skblen >> 8; 71 skb->head[1] = skblen >> 8;
77 dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x", len, skblen, 72 gig_dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x",
78 (unsigned) skb->head[0], (unsigned) skb->head[1]); 73 len, skblen, (unsigned) skb->head[0], (unsigned) skb->head[1]);
79 74
80 /* pass to device-specific module */ 75 /* pass to device-specific module */
81 return cs->ops->send_skb(bcs, skb); 76 return cs->ops->send_skb(bcs, skb);
@@ -89,14 +84,14 @@ void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
89 ++bcs->trans_up; 84 ++bcs->trans_up;
90 85
91 if (skb->len) 86 if (skb->len)
92 warn("%s: skb->len==%d", __func__, skb->len); 87 dev_warn(bcs->cs->dev, "%s: skb->len==%d\n",
88 __func__, skb->len);
93 89
94 len = (unsigned char) skb->head[0] | 90 len = (unsigned char) skb->head[0] |
95 (unsigned) (unsigned char) skb->head[1] << 8; 91 (unsigned) (unsigned char) skb->head[1] << 8;
96 if (len) { 92 if (len) {
97 dbg(DEBUG_MCMD, 93 gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)",
98 "Acknowledge sending to LL (id: %d, channel: %d size: %u)", 94 bcs->cs->myid, bcs->channel, len);
99 bcs->cs->myid, bcs->channel, len);
100 95
101 response.driver = bcs->cs->myid; 96 response.driver = bcs->cs->myid;
102 response.command = ISDN_STAT_BSENT; 97 response.command = ISDN_STAT_BSENT;
@@ -119,15 +114,12 @@ static int command_from_LL(isdn_ctrl *cntrl)
119 struct bc_state *bcs; 114 struct bc_state *bcs;
120 int retval = 0; 115 int retval = 0;
121 struct setup_parm *sp; 116 struct setup_parm *sp;
117 unsigned param;
118 unsigned long flags;
122 119
123 //dbg(DEBUG_ANY, "Gigaset_HW: Receiving command");
124 gigaset_debugdrivers(); 120 gigaset_debugdrivers();
125 121
126 /* Terminate this call if no device is present. Bt if the command is "ISDN_CMD_LOCK" or 122 if (!cs) {
127 * "ISDN_CMD_UNLOCK" then execute it due to the fact that they are device independent !
128 */
129 //FIXME "remove test for &connected"
130 if ((!cs || !atomic_read(&cs->connected))) {
131 warn("LL tried to access unknown device with nr. %d", 123 warn("LL tried to access unknown device with nr. %d",
132 cntrl->driver); 124 cntrl->driver);
133 return -ENODEV; 125 return -ENODEV;
@@ -135,29 +127,30 @@ static int command_from_LL(isdn_ctrl *cntrl)
135 127
136 switch (cntrl->command) { 128 switch (cntrl->command) {
137 case ISDN_CMD_IOCTL: 129 case ISDN_CMD_IOCTL:
138 130 gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)",
139 dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver:%d,arg: %ld)", 131 cntrl->driver, cntrl->arg);
140 cntrl->driver, cntrl->arg);
141 132
142 warn("ISDN_CMD_IOCTL is not supported."); 133 warn("ISDN_CMD_IOCTL is not supported.");
143 return -EINVAL; 134 return -EINVAL;
144 135
145 case ISDN_CMD_DIAL: 136 case ISDN_CMD_DIAL:
146 dbg(DEBUG_ANY, "ISDN_CMD_DIAL (driver: %d, channel: %ld, " 137 gig_dbg(DEBUG_ANY,
147 "phone: %s,ownmsn: %s, si1: %d, si2: %d)", 138 "ISDN_CMD_DIAL (driver: %d, ch: %ld, "
148 cntrl->driver, cntrl->arg, 139 "phone: %s, ownmsn: %s, si1: %d, si2: %d)",
149 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, 140 cntrl->driver, cntrl->arg,
150 cntrl->parm.setup.si1, cntrl->parm.setup.si2); 141 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
142 cntrl->parm.setup.si1, cntrl->parm.setup.si2);
151 143
152 if (cntrl->arg >= cs->channels) { 144 if (cntrl->arg >= cs->channels) {
153 err("invalid channel (%d)", (int) cntrl->arg); 145 err("ISDN_CMD_DIAL: invalid channel (%d)",
146 (int) cntrl->arg);
154 return -EINVAL; 147 return -EINVAL;
155 } 148 }
156 149
157 bcs = cs->bcs + cntrl->arg; 150 bcs = cs->bcs + cntrl->arg;
158 151
159 if (!gigaset_get_channel(bcs)) { 152 if (!gigaset_get_channel(bcs)) {
160 err("channel not free"); 153 err("ISDN_CMD_DIAL: channel not free");
161 return -EBUSY; 154 return -EBUSY;
162 } 155 }
163 156
@@ -169,42 +162,46 @@ static int command_from_LL(isdn_ctrl *cntrl)
169 } 162 }
170 *sp = cntrl->parm.setup; 163 *sp = cntrl->parm.setup;
171 164
172 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp, 165 spin_lock_irqsave(&cs->lock, flags);
173 atomic_read(&bcs->at_state.seq_index), 166 param = bcs->at_state.seq_index;
174 NULL)) { 167 spin_unlock_irqrestore(&cs->lock, flags);
168
169 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp, param,
170 NULL)) {
175 //FIXME what should we do? 171 //FIXME what should we do?
176 kfree(sp); 172 kfree(sp);
177 gigaset_free_channel(bcs); 173 gigaset_free_channel(bcs);
178 return -ENOMEM; 174 return -ENOMEM;
179 } 175 }
180 176
181 dbg(DEBUG_CMD, "scheduling DIAL"); 177 gig_dbg(DEBUG_CMD, "scheduling DIAL");
182 gigaset_schedule_event(cs); 178 gigaset_schedule_event(cs);
183 break; 179 break;
184 case ISDN_CMD_ACCEPTD: //FIXME 180 case ISDN_CMD_ACCEPTD: //FIXME
185 dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD"); 181 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD");
186 182
187 if (cntrl->arg >= cs->channels) { 183 if (cntrl->arg >= cs->channels) {
188 err("invalid channel (%d)", (int) cntrl->arg); 184 err("ISDN_CMD_ACCEPTD: invalid channel (%d)",
185 (int) cntrl->arg);
189 return -EINVAL; 186 return -EINVAL;
190 } 187 }
191 188
192 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, 189 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
193 EV_ACCEPT, NULL, 0, NULL)) { 190 EV_ACCEPT, NULL, 0, NULL)) {
194 //FIXME what should we do? 191 //FIXME what should we do?
195 return -ENOMEM; 192 return -ENOMEM;
196 } 193 }
197 194
198 dbg(DEBUG_CMD, "scheduling ACCEPT"); 195 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
199 gigaset_schedule_event(cs); 196 gigaset_schedule_event(cs);
200 197
201 break; 198 break;
202 case ISDN_CMD_ACCEPTB: 199 case ISDN_CMD_ACCEPTB:
203 dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB"); 200 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB");
204 break; 201 break;
205 case ISDN_CMD_HANGUP: 202 case ISDN_CMD_HANGUP:
206 dbg(DEBUG_ANY, 203 gig_dbg(DEBUG_ANY, "ISDN_CMD_HANGUP (ch: %d)",
207 "ISDN_CMD_HANGUP (channel: %d)", (int) cntrl->arg); 204 (int) cntrl->arg);
208 205
209 if (cntrl->arg >= cs->channels) { 206 if (cntrl->arg >= cs->channels) {
210 err("ISDN_CMD_HANGUP: invalid channel (%u)", 207 err("ISDN_CMD_HANGUP: invalid channel (%u)",
@@ -213,66 +210,68 @@ static int command_from_LL(isdn_ctrl *cntrl)
213 } 210 }
214 211
215 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, 212 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
216 EV_HUP, NULL, 0, NULL)) { 213 EV_HUP, NULL, 0, NULL)) {
217 //FIXME what should we do? 214 //FIXME what should we do?
218 return -ENOMEM; 215 return -ENOMEM;
219 } 216 }
220 217
221 dbg(DEBUG_CMD, "scheduling HUP"); 218 gig_dbg(DEBUG_CMD, "scheduling HUP");
222 gigaset_schedule_event(cs); 219 gigaset_schedule_event(cs);
223 220
224 break; 221 break;
225 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME 222 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME
226 dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ"); 223 gig_dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ");
227 break; 224 break;
228 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME 225 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME
229 dbg(DEBUG_ANY, 226 gig_dbg(DEBUG_ANY,
230 "ISDN_CMD_SETEAZ (id:%d, channel: %ld, number: %s)", 227 "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)",
231 cntrl->driver, cntrl->arg, cntrl->parm.num); 228 cntrl->driver, cntrl->arg, cntrl->parm.num);
232 break; 229 break;
233 case ISDN_CMD_SETL2: /* Set L2 to given protocol */ 230 case ISDN_CMD_SETL2: /* Set L2 to given protocol */
234 dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (Channel: %ld, Proto: %lx)", 231 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)",
235 cntrl->arg & 0xff, (cntrl->arg >> 8)); 232 cntrl->arg & 0xff, (cntrl->arg >> 8));
236 233
237 if ((cntrl->arg & 0xff) >= cs->channels) { 234 if ((cntrl->arg & 0xff) >= cs->channels) {
238 err("invalid channel (%u)", 235 err("ISDN_CMD_SETL2: invalid channel (%u)",
239 (unsigned) cntrl->arg & 0xff); 236 (unsigned) cntrl->arg & 0xff);
240 return -EINVAL; 237 return -EINVAL;
241 } 238 }
242 239
243 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state, 240 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state,
244 EV_PROTO_L2, NULL, cntrl->arg >> 8, 241 EV_PROTO_L2, NULL, cntrl->arg >> 8,
245 NULL)) { 242 NULL)) {
246 //FIXME what should we do? 243 //FIXME what should we do?
247 return -ENOMEM; 244 return -ENOMEM;
248 } 245 }
249 246
250 dbg(DEBUG_CMD, "scheduling PROTO_L2"); 247 gig_dbg(DEBUG_CMD, "scheduling PROTO_L2");
251 gigaset_schedule_event(cs); 248 gigaset_schedule_event(cs);
252 break; 249 break;
253 case ISDN_CMD_SETL3: /* Set L3 to given protocol */ 250 case ISDN_CMD_SETL3: /* Set L3 to given protocol */
254 dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (Channel: %ld, Proto: %lx)", 251 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)",
255 cntrl->arg & 0xff, (cntrl->arg >> 8)); 252 cntrl->arg & 0xff, (cntrl->arg >> 8));
256 253
257 if ((cntrl->arg & 0xff) >= cs->channels) { 254 if ((cntrl->arg & 0xff) >= cs->channels) {
258 err("invalid channel (%u)", 255 err("ISDN_CMD_SETL3: invalid channel (%u)",
259 (unsigned) cntrl->arg & 0xff); 256 (unsigned) cntrl->arg & 0xff);
260 return -EINVAL; 257 return -EINVAL;
261 } 258 }
262 259
263 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { 260 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
264 err("invalid protocol %lu", cntrl->arg >> 8); 261 err("ISDN_CMD_SETL3: invalid protocol %lu",
262 cntrl->arg >> 8);
265 return -EINVAL; 263 return -EINVAL;
266 } 264 }
267 265
268 break; 266 break;
269 case ISDN_CMD_PROCEED: 267 case ISDN_CMD_PROCEED:
270 dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME 268 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME
271 break; 269 break;
272 case ISDN_CMD_ALERT: 270 case ISDN_CMD_ALERT:
273 dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME 271 gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME
274 if (cntrl->arg >= cs->channels) { 272 if (cntrl->arg >= cs->channels) {
275 err("invalid channel (%d)", (int) cntrl->arg); 273 err("ISDN_CMD_ALERT: invalid channel (%d)",
274 (int) cntrl->arg);
276 return -EINVAL; 275 return -EINVAL;
277 } 276 }
278 //bcs = cs->bcs + cntrl->arg; 277 //bcs = cs->bcs + cntrl->arg;
@@ -280,32 +279,31 @@ static int command_from_LL(isdn_ctrl *cntrl)
280 // FIXME 279 // FIXME
281 break; 280 break;
282 case ISDN_CMD_REDIR: 281 case ISDN_CMD_REDIR:
283 dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME 282 gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME
284 break; 283 break;
285 case ISDN_CMD_PROT_IO: 284 case ISDN_CMD_PROT_IO:
286 dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO"); 285 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO");
287 break; 286 break;
288 case ISDN_CMD_FAXCMD: 287 case ISDN_CMD_FAXCMD:
289 dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD"); 288 gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
290 break; 289 break;
291 case ISDN_CMD_GETL2: 290 case ISDN_CMD_GETL2:
292 dbg(DEBUG_ANY, "ISDN_CMD_GETL2"); 291 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
293 break; 292 break;
294 case ISDN_CMD_GETL3: 293 case ISDN_CMD_GETL3:
295 dbg(DEBUG_ANY, "ISDN_CMD_GETL3"); 294 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
296 break; 295 break;
297 case ISDN_CMD_GETEAZ: 296 case ISDN_CMD_GETEAZ:
298 dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ"); 297 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
299 break; 298 break;
300 case ISDN_CMD_SETSIL: 299 case ISDN_CMD_SETSIL:
301 dbg(DEBUG_ANY, "ISDN_CMD_SETSIL"); 300 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
302 break; 301 break;
303 case ISDN_CMD_GETSIL: 302 case ISDN_CMD_GETSIL:
304 dbg(DEBUG_ANY, "ISDN_CMD_GETSIL"); 303 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
305 break; 304 break;
306 default: 305 default:
307 err("unknown command %d from LL", 306 err("unknown command %d from LL", cntrl->command);
308 cntrl->command);
309 return -EINVAL; 307 return -EINVAL;
310 } 308 }
311 309
@@ -350,7 +348,8 @@ int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
350 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */ 348 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
351 break; 349 break;
352 default: 350 default:
353 err("invalid protocol: %u", bcs->proto2); 351 dev_err(bcs->cs->dev, "%s: invalid L2 protocol: %u\n",
352 __func__, bcs->proto2);
354 return -EINVAL; 353 return -EINVAL;
355 } 354 }
356 355
@@ -378,7 +377,7 @@ int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
378 bcs->commands[i] = NULL; 377 bcs->commands[i] = NULL;
379 if (length[i] && 378 if (length[i] &&
380 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) { 379 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
381 err("out of memory"); 380 dev_err(bcs->cs->dev, "out of memory\n");
382 return -ENOMEM; 381 return -ENOMEM;
383 } 382 }
384 } 383 }
@@ -396,10 +395,14 @@ int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
396 } 395 }
397 396
398 if (bcs->commands[AT_MSN]) 397 if (bcs->commands[AT_MSN])
399 snprintf(bcs->commands[AT_MSN], length[AT_MSN], "^SMSN=%s\r", sp->eazmsn); 398 snprintf(bcs->commands[AT_MSN], length[AT_MSN],
400 snprintf(bcs->commands[AT_BC ], length[AT_BC ], "^SBC=%s\r", bc); 399 "^SMSN=%s\r", sp->eazmsn);
401 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], "^SBPR=%u\r", proto); 400 snprintf(bcs->commands[AT_BC ], length[AT_BC ],
402 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], "^SISO=%u\r", (unsigned)bcs->channel + 1); 401 "^SBC=%s\r", bc);
402 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
403 "^SBPR=%u\r", proto);
404 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
405 "^SISO=%u\r", (unsigned)bcs->channel + 1);
403 406
404 return 0; 407 return 0;
405} 408}
@@ -419,7 +422,8 @@ int gigaset_isdn_setup_accept(struct at_state_t *at_state)
419 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */ 422 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
420 break; 423 break;
421 default: 424 default:
422 err("invalid protocol: %u", bcs->proto2); 425 dev_err(at_state->cs->dev, "%s: invalid protocol: %u\n",
426 __func__, bcs->proto2);
423 return -EINVAL; 427 return -EINVAL;
424 } 428 }
425 429
@@ -436,13 +440,15 @@ int gigaset_isdn_setup_accept(struct at_state_t *at_state)
436 bcs->commands[i] = NULL; 440 bcs->commands[i] = NULL;
437 if (length[i] && 441 if (length[i] &&
438 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) { 442 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
439 err("out of memory"); 443 dev_err(at_state->cs->dev, "out of memory\n");
440 return -ENOMEM; 444 return -ENOMEM;
441 } 445 }
442 } 446 }
443 447
444 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], "^SBPR=%u\r", proto); 448 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
445 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], "^SISO=%u\r", (unsigned) bcs->channel + 1); 449 "^SBPR=%u\r", proto);
450 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
451 "^SISO=%u\r", (unsigned) bcs->channel + 1);
446 452
447 return 0; 453 return 0;
448} 454}
@@ -473,7 +479,7 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
473 response.parm.setup.si1 = 1; 479 response.parm.setup.si1 = 1;
474 response.parm.setup.si2 = 2; 480 response.parm.setup.si2 = 2;
475 } else { 481 } else {
476 warn("RING ignored - unsupported BC %s", 482 dev_warn(cs->dev, "RING ignored - unsupported BC %s\n",
477 at_state->str_var[STR_ZBC]); 483 at_state->str_var[STR_ZBC]);
478 return ICALL_IGNORE; 484 return ICALL_IGNORE;
479 } 485 }
@@ -491,18 +497,17 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
491 response.parm.setup.eazmsn[0] = 0; 497 response.parm.setup.eazmsn[0] = 0;
492 498
493 if (!bcs) { 499 if (!bcs) {
494 notice("no channel for incoming call"); 500 dev_notice(cs->dev, "no channel for incoming call\n");
495 dbg(DEBUG_CMD, "Sending ICALLW");
496 response.command = ISDN_STAT_ICALLW; 501 response.command = ISDN_STAT_ICALLW;
497 response.arg = 0; //FIXME 502 response.arg = 0; //FIXME
498 } else { 503 } else {
499 dbg(DEBUG_CMD, "Sending ICALL"); 504 gig_dbg(DEBUG_CMD, "Sending ICALL");
500 response.command = ISDN_STAT_ICALL; 505 response.command = ISDN_STAT_ICALL;
501 response.arg = bcs->channel; //FIXME 506 response.arg = bcs->channel; //FIXME
502 } 507 }
503 response.driver = cs->myid; 508 response.driver = cs->myid;
504 retval = cs->iif.statcallb(&response); 509 retval = cs->iif.statcallb(&response);
505 dbg(DEBUG_CMD, "Response: %d", retval); 510 gig_dbg(DEBUG_CMD, "Response: %d", retval);
506 switch (retval) { 511 switch (retval) {
507 case 0: /* no takers */ 512 case 0: /* no takers */
508 return ICALL_IGNORE; 513 return ICALL_IGNORE;
@@ -512,7 +517,8 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
512 case 2: /* reject */ 517 case 2: /* reject */
513 return ICALL_REJECT; 518 return ICALL_REJECT;
514 case 3: /* incomplete */ 519 case 3: /* incomplete */
515 warn("LL requested unsupported feature: Incomplete Number"); 520 dev_warn(cs->dev,
521 "LL requested unsupported feature: Incomplete Number\n");
516 return ICALL_IGNORE; 522 return ICALL_IGNORE;
517 case 4: /* proceeding */ 523 case 4: /* proceeding */
518 /* Gigaset will send ALERTING anyway. 524 /* Gigaset will send ALERTING anyway.
@@ -520,10 +526,11 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
520 */ 526 */
521 return ICALL_ACCEPT; 527 return ICALL_ACCEPT;
522 case 5: /* deflect */ 528 case 5: /* deflect */
523 warn("LL requested unsupported feature: Call Deflection"); 529 dev_warn(cs->dev,
530 "LL requested unsupported feature: Call Deflection\n");
524 return ICALL_IGNORE; 531 return ICALL_IGNORE;
525 default: 532 default:
526 err("LL error %d on ICALL", retval); 533 dev_err(cs->dev, "LL error %d on ICALL\n", retval);
527 return ICALL_IGNORE; 534 return ICALL_IGNORE;
528 } 535 }
529} 536}
@@ -533,7 +540,7 @@ int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid)
533{ 540{
534 isdn_if *iif = &cs->iif; 541 isdn_if *iif = &cs->iif;
535 542
536 dbg(DEBUG_ANY, "Register driver capabilities to LL"); 543 gig_dbg(DEBUG_ANY, "Register driver capabilities to LL");
537 544
538 //iif->id[sizeof(iif->id) - 1]=0; 545 //iif->id[sizeof(iif->id) - 1]=0;
539 //strncpy(iif->id, isdnid, sizeof(iif->id) - 1); 546 //strncpy(iif->id, isdnid, sizeof(iif->id) - 1);
@@ -542,26 +549,26 @@ int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid)
542 return -ENOMEM; //FIXME EINVAL/...?? 549 return -ENOMEM; //FIXME EINVAL/...??
543 550
544 iif->owner = THIS_MODULE; 551 iif->owner = THIS_MODULE;
545 iif->channels = cs->channels; /* I am supporting just one channel *//* I was supporting...*/ 552 iif->channels = cs->channels;
546 iif->maxbufsize = MAX_BUF_SIZE; 553 iif->maxbufsize = MAX_BUF_SIZE;
547 iif->features = ISDN_FEATURE_L2_TRANS | /* Our device is very advanced, therefore */ 554 iif->features = ISDN_FEATURE_L2_TRANS |
548 ISDN_FEATURE_L2_HDLC | 555 ISDN_FEATURE_L2_HDLC |
549#ifdef GIG_X75 556#ifdef GIG_X75
550 ISDN_FEATURE_L2_X75I | 557 ISDN_FEATURE_L2_X75I |
551#endif 558#endif
552 ISDN_FEATURE_L3_TRANS | 559 ISDN_FEATURE_L3_TRANS |
553 ISDN_FEATURE_P_EURO; 560 ISDN_FEATURE_P_EURO;
554 iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */ 561 iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */
555 iif->command = command_from_LL; 562 iif->command = command_from_LL;
556 iif->writebuf_skb = writebuf_from_LL; 563 iif->writebuf_skb = writebuf_from_LL;
557 iif->writecmd = NULL; /* Don't support isdnctrl */ 564 iif->writecmd = NULL; /* Don't support isdnctrl */
558 iif->readstat = NULL; /* Don't support isdnctrl */ 565 iif->readstat = NULL; /* Don't support isdnctrl */
559 iif->rcvcallb_skb = NULL; /* Will be set by LL */ 566 iif->rcvcallb_skb = NULL; /* Will be set by LL */
560 iif->statcallb = NULL; /* Will be set by LL */ 567 iif->statcallb = NULL; /* Will be set by LL */
561 568
562 if (!register_isdn(iif)) 569 if (!register_isdn(iif))
563 return 0; 570 return 0;
564 571
565 cs->myid = iif->channels; /* Set my device id */ 572 cs->myid = iif->channels; /* Set my device id */
566 return 1; 573 return 1;
567} 574}
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index 3a81d9c65141..08e4c4eea14d 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -9,8 +9,6 @@
9 * published by the Free Software Foundation; either version 2 of 9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version. 10 * the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * Version: $Id: interface.c,v 1.14.4.15 2006/02/04 18:28:16 hjlipp Exp $
13 * =====================================================================
14 */ 12 */
15 13
16#include "gigaset.h" 14#include "gigaset.h"
@@ -24,7 +22,7 @@ static int if_lock(struct cardstate *cs, int *arg)
24{ 22{
25 int cmd = *arg; 23 int cmd = *arg;
26 24
27 dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd); 25 gig_dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd);
28 26
29 if (cmd > 1) 27 if (cmd > 1)
30 return -EINVAL; 28 return -EINVAL;
@@ -35,7 +33,7 @@ static int if_lock(struct cardstate *cs, int *arg)
35 } 33 }
36 34
37 if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED 35 if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
38 && atomic_read(&cs->connected)) { 36 && cs->connected) {
39 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS); 37 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
40 cs->ops->baud_rate(cs, B115200); 38 cs->ops->baud_rate(cs, B115200);
41 cs->ops->set_line_ctrl(cs, CS8); 39 cs->ops->set_line_ctrl(cs, CS8);
@@ -44,12 +42,12 @@ static int if_lock(struct cardstate *cs, int *arg)
44 42
45 cs->waiting = 1; 43 cs->waiting = 1;
46 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK, 44 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK,
47 NULL, cmd, NULL)) { 45 NULL, cmd, NULL)) {
48 cs->waiting = 0; 46 cs->waiting = 0;
49 return -ENOMEM; 47 return -ENOMEM;
50 } 48 }
51 49
52 dbg(DEBUG_CMD, "scheduling IF_LOCK"); 50 gig_dbg(DEBUG_CMD, "scheduling IF_LOCK");
53 gigaset_schedule_event(cs); 51 gigaset_schedule_event(cs);
54 52
55 wait_event(cs->waitqueue, !cs->waiting); 53 wait_event(cs->waitqueue, !cs->waiting);
@@ -68,7 +66,7 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
68 static const unsigned compat[4] = GIG_COMPAT; 66 static const unsigned compat[4] = GIG_COMPAT;
69 unsigned cmd = arg[0]; 67 unsigned cmd = arg[0];
70 68
71 dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd); 69 gig_dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd);
72 70
73 switch (cmd) { 71 switch (cmd) {
74 case GIGVER_DRIVER: 72 case GIGVER_DRIVER:
@@ -80,12 +78,12 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
80 case GIGVER_FWBASE: 78 case GIGVER_FWBASE:
81 cs->waiting = 1; 79 cs->waiting = 1;
82 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER, 80 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER,
83 NULL, 0, arg)) { 81 NULL, 0, arg)) {
84 cs->waiting = 0; 82 cs->waiting = 0;
85 return -ENOMEM; 83 return -ENOMEM;
86 } 84 }
87 85
88 dbg(DEBUG_CMD, "scheduling IF_VER"); 86 gig_dbg(DEBUG_CMD, "scheduling IF_VER");
89 gigaset_schedule_event(cs); 87 gigaset_schedule_event(cs);
90 88
91 wait_event(cs->waitqueue, !cs->waiting); 89 wait_event(cs->waitqueue, !cs->waiting);
@@ -101,7 +99,7 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
101 99
102static int if_config(struct cardstate *cs, int *arg) 100static int if_config(struct cardstate *cs, int *arg)
103{ 101{
104 dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg); 102 gig_dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg);
105 103
106 if (*arg != 1) 104 if (*arg != 1)
107 return -EINVAL; 105 return -EINVAL;
@@ -109,6 +107,11 @@ static int if_config(struct cardstate *cs, int *arg)
109 if (atomic_read(&cs->mstate) != MS_LOCKED) 107 if (atomic_read(&cs->mstate) != MS_LOCKED)
110 return -EBUSY; 108 return -EBUSY;
111 109
110 if (!cs->connected) {
111 err("not connected!");
112 return -ENODEV;
113 }
114
112 *arg = 0; 115 *arg = 0;
113 return gigaset_enterconfigmode(cs); 116 return gigaset_enterconfigmode(cs);
114} 117}
@@ -119,7 +122,7 @@ static int if_config(struct cardstate *cs, int *arg)
119static int if_open(struct tty_struct *tty, struct file *filp); 122static int if_open(struct tty_struct *tty, struct file *filp);
120static void if_close(struct tty_struct *tty, struct file *filp); 123static void if_close(struct tty_struct *tty, struct file *filp);
121static int if_ioctl(struct tty_struct *tty, struct file *file, 124static int if_ioctl(struct tty_struct *tty, struct file *file,
122 unsigned int cmd, unsigned long arg); 125 unsigned int cmd, unsigned long arg);
123static int if_write_room(struct tty_struct *tty); 126static int if_write_room(struct tty_struct *tty);
124static int if_chars_in_buffer(struct tty_struct *tty); 127static int if_chars_in_buffer(struct tty_struct *tty);
125static void if_throttle(struct tty_struct *tty); 128static void if_throttle(struct tty_struct *tty);
@@ -127,9 +130,9 @@ static void if_unthrottle(struct tty_struct *tty);
127static void if_set_termios(struct tty_struct *tty, struct termios *old); 130static void if_set_termios(struct tty_struct *tty, struct termios *old);
128static int if_tiocmget(struct tty_struct *tty, struct file *file); 131static int if_tiocmget(struct tty_struct *tty, struct file *file);
129static int if_tiocmset(struct tty_struct *tty, struct file *file, 132static int if_tiocmset(struct tty_struct *tty, struct file *file,
130 unsigned int set, unsigned int clear); 133 unsigned int set, unsigned int clear);
131static int if_write(struct tty_struct *tty, 134static int if_write(struct tty_struct *tty,
132 const unsigned char *buf, int count); 135 const unsigned char *buf, int count);
133 136
134static struct tty_operations if_ops = { 137static struct tty_operations if_ops = {
135 .open = if_open, 138 .open = if_open,
@@ -153,8 +156,8 @@ static int if_open(struct tty_struct *tty, struct file *filp)
153 struct cardstate *cs; 156 struct cardstate *cs;
154 unsigned long flags; 157 unsigned long flags;
155 158
156 dbg(DEBUG_IF, "%d+%d: %s()", tty->driver->minor_start, tty->index, 159 gig_dbg(DEBUG_IF, "%d+%d: %s()",
157 __FUNCTION__); 160 tty->driver->minor_start, tty->index, __func__);
158 161
159 tty->driver_data = NULL; 162 tty->driver_data = NULL;
160 163
@@ -162,7 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
162 if (!cs) 165 if (!cs)
163 return -ENODEV; 166 return -ENODEV;
164 167
165 if (down_interruptible(&cs->sem)) 168 if (mutex_lock_interruptible(&cs->mutex))
166 return -ERESTARTSYS; // FIXME -EINTR? 169 return -ERESTARTSYS; // FIXME -EINTR?
167 tty->driver_data = cs; 170 tty->driver_data = cs;
168 171
@@ -173,10 +176,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
173 cs->tty = tty; 176 cs->tty = tty;
174 spin_unlock_irqrestore(&cs->lock, flags); 177 spin_unlock_irqrestore(&cs->lock, flags);
175 tty->low_latency = 1; //FIXME test 178 tty->low_latency = 1; //FIXME test
176 //FIXME
177 } 179 }
178 180
179 up(&cs->sem); 181 mutex_unlock(&cs->mutex);
180 return 0; 182 return 0;
181} 183}
182 184
@@ -187,30 +189,29 @@ static void if_close(struct tty_struct *tty, struct file *filp)
187 189
188 cs = (struct cardstate *) tty->driver_data; 190 cs = (struct cardstate *) tty->driver_data;
189 if (!cs) { 191 if (!cs) {
190 err("cs==NULL in %s", __FUNCTION__); 192 err("cs==NULL in %s", __func__);
191 return; 193 return;
192 } 194 }
193 195
194 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 196 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
195 197
196 down(&cs->sem); 198 mutex_lock(&cs->mutex);
197 199
198 if (!cs->open_count) 200 if (!cs->open_count)
199 warn("%s: device not opened", __FUNCTION__); 201 warn("%s: device not opened", __func__);
200 else { 202 else {
201 if (!--cs->open_count) { 203 if (!--cs->open_count) {
202 spin_lock_irqsave(&cs->lock, flags); 204 spin_lock_irqsave(&cs->lock, flags);
203 cs->tty = NULL; 205 cs->tty = NULL;
204 spin_unlock_irqrestore(&cs->lock, flags); 206 spin_unlock_irqrestore(&cs->lock, flags);
205 //FIXME
206 } 207 }
207 } 208 }
208 209
209 up(&cs->sem); 210 mutex_unlock(&cs->mutex);
210} 211}
211 212
212static int if_ioctl(struct tty_struct *tty, struct file *file, 213static int if_ioctl(struct tty_struct *tty, struct file *file,
213 unsigned int cmd, unsigned long arg) 214 unsigned int cmd, unsigned long arg)
214{ 215{
215 struct cardstate *cs; 216 struct cardstate *cs;
216 int retval = -ENODEV; 217 int retval = -ENODEV;
@@ -220,17 +221,17 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
220 221
221 cs = (struct cardstate *) tty->driver_data; 222 cs = (struct cardstate *) tty->driver_data;
222 if (!cs) { 223 if (!cs) {
223 err("cs==NULL in %s", __FUNCTION__); 224 err("cs==NULL in %s", __func__);
224 return -ENODEV; 225 return -ENODEV;
225 } 226 }
226 227
227 dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __FUNCTION__, cmd); 228 gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
228 229
229 if (down_interruptible(&cs->sem)) 230 if (mutex_lock_interruptible(&cs->mutex))
230 return -ERESTARTSYS; // FIXME -EINTR? 231 return -ERESTARTSYS; // FIXME -EINTR?
231 232
232 if (!cs->open_count) 233 if (!cs->open_count)
233 warn("%s: device not opened", __FUNCTION__); 234 warn("%s: device not opened", __func__);
234 else { 235 else {
235 retval = 0; 236 retval = 0;
236 switch (cmd) { 237 switch (cmd) {
@@ -250,37 +251,40 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
250 break; 251 break;
251 case GIGASET_BRKCHARS: 252 case GIGASET_BRKCHARS:
252 //FIXME test if MS_LOCKED 253 //FIXME test if MS_LOCKED
253 gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS", 254 if (!cs->connected) {
254 6, (const unsigned char *) arg, 1); 255 gig_dbg(DEBUG_ANY,
255 if (!atomic_read(&cs->connected)) { 256 "can't communicate with unplugged device");
256 dbg(DEBUG_ANY, "can't communicate with unplugged device");
257 retval = -ENODEV; 257 retval = -ENODEV;
258 break; 258 break;
259 } 259 }
260 retval = copy_from_user(&buf, 260 retval = copy_from_user(&buf,
261 (const unsigned char __user *) arg, 6) 261 (const unsigned char __user *) arg, 6)
262 ? -EFAULT : 0; 262 ? -EFAULT : 0;
263 if (retval >= 0) 263 if (retval >= 0) {
264 gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
265 6, (const unsigned char *) arg);
264 retval = cs->ops->brkchars(cs, buf); 266 retval = cs->ops->brkchars(cs, buf);
267 }
265 break; 268 break;
266 case GIGASET_VERSION: 269 case GIGASET_VERSION:
267 retval = copy_from_user(version, (unsigned __user *) arg, 270 retval = copy_from_user(version,
268 sizeof version) ? -EFAULT : 0; 271 (unsigned __user *) arg, sizeof version)
272 ? -EFAULT : 0;
269 if (retval >= 0) 273 if (retval >= 0)
270 retval = if_version(cs, version); 274 retval = if_version(cs, version);
271 if (retval >= 0) 275 if (retval >= 0)
272 retval = copy_to_user((unsigned __user *) arg, version, 276 retval = copy_to_user((unsigned __user *) arg,
273 sizeof version) 277 version, sizeof version)
274 ? -EFAULT : 0; 278 ? -EFAULT : 0;
275 break; 279 break;
276 default: 280 default:
277 dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x", 281 gig_dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x",
278 __FUNCTION__, cmd); 282 __func__, cmd);
279 retval = -ENOIOCTLCMD; 283 retval = -ENOIOCTLCMD;
280 } 284 }
281 } 285 }
282 286
283 up(&cs->sem); 287 mutex_unlock(&cs->mutex);
284 288
285 return retval; 289 return retval;
286} 290}
@@ -292,25 +296,25 @@ static int if_tiocmget(struct tty_struct *tty, struct file *file)
292 296
293 cs = (struct cardstate *) tty->driver_data; 297 cs = (struct cardstate *) tty->driver_data;
294 if (!cs) { 298 if (!cs) {
295 err("cs==NULL in %s", __FUNCTION__); 299 err("cs==NULL in %s", __func__);
296 return -ENODEV; 300 return -ENODEV;
297 } 301 }
298 302
299 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 303 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
300 304
301 if (down_interruptible(&cs->sem)) 305 if (mutex_lock_interruptible(&cs->mutex))
302 return -ERESTARTSYS; // FIXME -EINTR? 306 return -ERESTARTSYS; // FIXME -EINTR?
303 307
304 // FIXME read from device? 308 // FIXME read from device?
305 retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR); 309 retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
306 310
307 up(&cs->sem); 311 mutex_unlock(&cs->mutex);
308 312
309 return retval; 313 return retval;
310} 314}
311 315
312static int if_tiocmset(struct tty_struct *tty, struct file *file, 316static int if_tiocmset(struct tty_struct *tty, struct file *file,
313 unsigned int set, unsigned int clear) 317 unsigned int set, unsigned int clear)
314{ 318{
315 struct cardstate *cs; 319 struct cardstate *cs;
316 int retval; 320 int retval;
@@ -318,18 +322,18 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
318 322
319 cs = (struct cardstate *) tty->driver_data; 323 cs = (struct cardstate *) tty->driver_data;
320 if (!cs) { 324 if (!cs) {
321 err("cs==NULL in %s", __FUNCTION__); 325 err("cs==NULL in %s", __func__);
322 return -ENODEV; 326 return -ENODEV;
323 } 327 }
324 328
325 dbg(DEBUG_IF, 329 gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
326 "%u: %s(0x%x, 0x%x)", cs->minor_index, __FUNCTION__, set, clear); 330 cs->minor_index, __func__, set, clear);
327 331
328 if (down_interruptible(&cs->sem)) 332 if (mutex_lock_interruptible(&cs->mutex))
329 return -ERESTARTSYS; // FIXME -EINTR? 333 return -ERESTARTSYS; // FIXME -EINTR?
330 334
331 if (!atomic_read(&cs->connected)) { 335 if (!cs->connected) {
332 dbg(DEBUG_ANY, "can't communicate with unplugged device"); 336 gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
333 retval = -ENODEV; 337 retval = -ENODEV;
334 } else { 338 } else {
335 mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR); 339 mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
@@ -337,7 +341,7 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
337 cs->control_state = mc; 341 cs->control_state = mc;
338 } 342 }
339 343
340 up(&cs->sem); 344 mutex_unlock(&cs->mutex);
341 345
342 return retval; 346 return retval;
343} 347}
@@ -349,29 +353,29 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
349 353
350 cs = (struct cardstate *) tty->driver_data; 354 cs = (struct cardstate *) tty->driver_data;
351 if (!cs) { 355 if (!cs) {
352 err("cs==NULL in %s", __FUNCTION__); 356 err("cs==NULL in %s", __func__);
353 return -ENODEV; 357 return -ENODEV;
354 } 358 }
355 359
356 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 360 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
357 361
358 if (down_interruptible(&cs->sem)) 362 if (mutex_lock_interruptible(&cs->mutex))
359 return -ERESTARTSYS; // FIXME -EINTR? 363 return -ERESTARTSYS; // FIXME -EINTR?
360 364
361 if (!cs->open_count) 365 if (!cs->open_count)
362 warn("%s: device not opened", __FUNCTION__); 366 warn("%s: device not opened", __func__);
363 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 367 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
364 warn("can't write to unlocked device"); 368 warn("can't write to unlocked device");
365 retval = -EBUSY; 369 retval = -EBUSY;
366 } else if (!atomic_read(&cs->connected)) { 370 } else if (!cs->connected) {
367 dbg(DEBUG_ANY, "can't write to unplugged device"); 371 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
368 retval = -EBUSY; //FIXME 372 retval = -EBUSY; //FIXME
369 } else { 373 } else {
370 retval = cs->ops->write_cmd(cs, buf, count, 374 retval = cs->ops->write_cmd(cs, buf, count,
371 &cs->if_wake_tasklet); 375 &cs->if_wake_tasklet);
372 } 376 }
373 377
374 up(&cs->sem); 378 mutex_unlock(&cs->mutex);
375 379
376 return retval; 380 return retval;
377} 381}
@@ -383,27 +387,27 @@ static int if_write_room(struct tty_struct *tty)
383 387
384 cs = (struct cardstate *) tty->driver_data; 388 cs = (struct cardstate *) tty->driver_data;
385 if (!cs) { 389 if (!cs) {
386 err("cs==NULL in %s", __FUNCTION__); 390 err("cs==NULL in %s", __func__);
387 return -ENODEV; 391 return -ENODEV;
388 } 392 }
389 393
390 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 394 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
391 395
392 if (down_interruptible(&cs->sem)) 396 if (mutex_lock_interruptible(&cs->mutex))
393 return -ERESTARTSYS; // FIXME -EINTR? 397 return -ERESTARTSYS; // FIXME -EINTR?
394 398
395 if (!cs->open_count) 399 if (!cs->open_count)
396 warn("%s: device not opened", __FUNCTION__); 400 warn("%s: device not opened", __func__);
397 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 401 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
398 warn("can't write to unlocked device"); 402 warn("can't write to unlocked device");
399 retval = -EBUSY; //FIXME 403 retval = -EBUSY; //FIXME
400 } else if (!atomic_read(&cs->connected)) { 404 } else if (!cs->connected) {
401 dbg(DEBUG_ANY, "can't write to unplugged device"); 405 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
402 retval = -EBUSY; //FIXME 406 retval = -EBUSY; //FIXME
403 } else 407 } else
404 retval = cs->ops->write_room(cs); 408 retval = cs->ops->write_room(cs);
405 409
406 up(&cs->sem); 410 mutex_unlock(&cs->mutex);
407 411
408 return retval; 412 return retval;
409} 413}
@@ -415,27 +419,27 @@ static int if_chars_in_buffer(struct tty_struct *tty)
415 419
416 cs = (struct cardstate *) tty->driver_data; 420 cs = (struct cardstate *) tty->driver_data;
417 if (!cs) { 421 if (!cs) {
418 err("cs==NULL in %s", __FUNCTION__); 422 err("cs==NULL in %s", __func__);
419 return -ENODEV; 423 return -ENODEV;
420 } 424 }
421 425
422 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 426 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
423 427
424 if (down_interruptible(&cs->sem)) 428 if (mutex_lock_interruptible(&cs->mutex))
425 return -ERESTARTSYS; // FIXME -EINTR? 429 return -ERESTARTSYS; // FIXME -EINTR?
426 430
427 if (!cs->open_count) 431 if (!cs->open_count)
428 warn("%s: device not opened", __FUNCTION__); 432 warn("%s: device not opened", __func__);
429 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 433 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
430 warn("can't write to unlocked device"); 434 warn("can't write to unlocked device");
431 retval = -EBUSY; 435 retval = -EBUSY;
432 } else if (!atomic_read(&cs->connected)) { 436 } else if (!cs->connected) {
433 dbg(DEBUG_ANY, "can't write to unplugged device"); 437 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
434 retval = -EBUSY; //FIXME 438 retval = -EBUSY; //FIXME
435 } else 439 } else
436 retval = cs->ops->chars_in_buffer(cs); 440 retval = cs->ops->chars_in_buffer(cs);
437 441
438 up(&cs->sem); 442 mutex_unlock(&cs->mutex);
439 443
440 return retval; 444 return retval;
441} 445}
@@ -446,21 +450,21 @@ static void if_throttle(struct tty_struct *tty)
446 450
447 cs = (struct cardstate *) tty->driver_data; 451 cs = (struct cardstate *) tty->driver_data;
448 if (!cs) { 452 if (!cs) {
449 err("cs==NULL in %s", __FUNCTION__); 453 err("cs==NULL in %s", __func__);
450 return; 454 return;
451 } 455 }
452 456
453 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 457 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
454 458
455 down(&cs->sem); 459 mutex_lock(&cs->mutex);
456 460
457 if (!cs->open_count) 461 if (!cs->open_count)
458 warn("%s: device not opened", __FUNCTION__); 462 warn("%s: device not opened", __func__);
459 else { 463 else {
460 //FIXME 464 //FIXME
461 } 465 }
462 466
463 up(&cs->sem); 467 mutex_unlock(&cs->mutex);
464} 468}
465 469
466static void if_unthrottle(struct tty_struct *tty) 470static void if_unthrottle(struct tty_struct *tty)
@@ -469,21 +473,21 @@ static void if_unthrottle(struct tty_struct *tty)
469 473
470 cs = (struct cardstate *) tty->driver_data; 474 cs = (struct cardstate *) tty->driver_data;
471 if (!cs) { 475 if (!cs) {
472 err("cs==NULL in %s", __FUNCTION__); 476 err("cs==NULL in %s", __func__);
473 return; 477 return;
474 } 478 }
475 479
476 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 480 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
477 481
478 down(&cs->sem); 482 mutex_lock(&cs->mutex);
479 483
480 if (!cs->open_count) 484 if (!cs->open_count)
481 warn("%s: device not opened", __FUNCTION__); 485 warn("%s: device not opened", __func__);
482 else { 486 else {
483 //FIXME 487 //FIXME
484 } 488 }
485 489
486 up(&cs->sem); 490 mutex_unlock(&cs->mutex);
487} 491}
488 492
489static void if_set_termios(struct tty_struct *tty, struct termios *old) 493static void if_set_termios(struct tty_struct *tty, struct termios *old)
@@ -496,21 +500,21 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
496 500
497 cs = (struct cardstate *) tty->driver_data; 501 cs = (struct cardstate *) tty->driver_data;
498 if (!cs) { 502 if (!cs) {
499 err("cs==NULL in %s", __FUNCTION__); 503 err("cs==NULL in %s", __func__);
500 return; 504 return;
501 } 505 }
502 506
503 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 507 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
504 508
505 down(&cs->sem); 509 mutex_lock(&cs->mutex);
506 510
507 if (!cs->open_count) { 511 if (!cs->open_count) {
508 warn("%s: device not opened", __FUNCTION__); 512 warn("%s: device not opened", __func__);
509 goto out; 513 goto out;
510 } 514 }
511 515
512 if (!atomic_read(&cs->connected)) { 516 if (!cs->connected) {
513 dbg(DEBUG_ANY, "can't communicate with unplugged device"); 517 gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
514 goto out; 518 goto out;
515 } 519 }
516 520
@@ -518,8 +522,8 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
518 iflag = tty->termios->c_iflag; 522 iflag = tty->termios->c_iflag;
519 cflag = tty->termios->c_cflag; 523 cflag = tty->termios->c_cflag;
520 old_cflag = old ? old->c_cflag : cflag; //FIXME? 524 old_cflag = old ? old->c_cflag : cflag; //FIXME?
521 dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x", cs->minor_index, 525 gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
522 iflag, cflag, old_cflag); 526 cs->minor_index, iflag, cflag, old_cflag);
523 527
524 /* get a local copy of the current port settings */ 528 /* get a local copy of the current port settings */
525 control_state = cs->control_state; 529 control_state = cs->control_state;
@@ -531,14 +535,15 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
531 * Premature optimization is the root of all evil. 535 * Premature optimization is the root of all evil.
532 */ 536 */
533 537
534 /* reassert DTR and (maybe) RTS on transition from B0 */ 538 /* reassert DTR and (maybe) RTS on transition from B0 */
535 if ((old_cflag & CBAUD) == B0) { 539 if ((old_cflag & CBAUD) == B0) {
536 new_state = control_state | TIOCM_DTR; 540 new_state = control_state | TIOCM_DTR;
537 /* don't set RTS if using hardware flow control */ 541 /* don't set RTS if using hardware flow control */
538 if (!(old_cflag & CRTSCTS)) 542 if (!(old_cflag & CRTSCTS))
539 new_state |= TIOCM_RTS; 543 new_state |= TIOCM_RTS;
540 dbg(DEBUG_IF, "%u: from B0 - set DTR%s", cs->minor_index, 544 gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s",
541 (new_state & TIOCM_RTS) ? " only" : "/RTS"); 545 cs->minor_index,
546 (new_state & TIOCM_RTS) ? " only" : "/RTS");
542 cs->ops->set_modem_ctrl(cs, control_state, new_state); 547 cs->ops->set_modem_ctrl(cs, control_state, new_state);
543 control_state = new_state; 548 control_state = new_state;
544 } 549 }
@@ -547,7 +552,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
547 552
548 if ((cflag & CBAUD) == B0) { 553 if ((cflag & CBAUD) == B0) {
549 /* Drop RTS and DTR */ 554 /* Drop RTS and DTR */
550 dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index); 555 gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
551 new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS); 556 new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
552 cs->ops->set_modem_ctrl(cs, control_state, new_state); 557 cs->ops->set_modem_ctrl(cs, control_state, new_state);
553 control_state = new_state; 558 control_state = new_state;
@@ -567,15 +572,17 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
567 * Just do what we have seen with SniffUSB on Win98. 572 * Just do what we have seen with SniffUSB on Win98.
568 */ 573 */
569 /* Drop DTR/RTS if no flow control otherwise assert */ 574 /* Drop DTR/RTS if no flow control otherwise assert */
570 dbg(DEBUG_IF, "%u: control_state %x", cs->minor_index, control_state); 575 gig_dbg(DEBUG_IF, "%u: control_state %x",
576 cs->minor_index, control_state);
571 new_state = control_state; 577 new_state = control_state;
572 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS)) 578 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
573 new_state |= TIOCM_DTR | TIOCM_RTS; 579 new_state |= TIOCM_DTR | TIOCM_RTS;
574 else 580 else
575 new_state &= ~(TIOCM_DTR | TIOCM_RTS); 581 new_state &= ~(TIOCM_DTR | TIOCM_RTS);
576 if (new_state != control_state) { 582 if (new_state != control_state) {
577 dbg(DEBUG_IF, "%u: new_state %x", cs->minor_index, new_state); 583 gig_dbg(DEBUG_IF, "%u: new_state %x",
578 gigaset_set_modem_ctrl(cs, control_state, new_state); // FIXME: mct_u232.c sets the old state here. is this a bug? 584 cs->minor_index, new_state);
585 gigaset_set_modem_ctrl(cs, control_state, new_state);
579 control_state = new_state; 586 control_state = new_state;
580 } 587 }
581#endif 588#endif
@@ -584,7 +591,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
584 cs->control_state = control_state; 591 cs->control_state = control_state;
585 592
586out: 593out:
587 up(&cs->sem); 594 mutex_unlock(&cs->mutex);
588} 595}
589 596
590 597
@@ -600,7 +607,7 @@ static void if_wake(unsigned long data)
600 607
601 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && 608 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
602 tty->ldisc.write_wakeup) { 609 tty->ldisc.write_wakeup) {
603 dbg(DEBUG_IF, "write wakeup call"); 610 gig_dbg(DEBUG_IF, "write wakeup call");
604 tty->ldisc.write_wakeup(tty); 611 tty->ldisc.write_wakeup(tty);
605 } 612 }
606 613
@@ -635,14 +642,14 @@ void gigaset_if_free(struct cardstate *cs)
635} 642}
636 643
637void gigaset_if_receive(struct cardstate *cs, 644void gigaset_if_receive(struct cardstate *cs,
638 unsigned char *buffer, size_t len) 645 unsigned char *buffer, size_t len)
639{ 646{
640 unsigned long flags; 647 unsigned long flags;
641 struct tty_struct *tty; 648 struct tty_struct *tty;
642 649
643 spin_lock_irqsave(&cs->lock, flags); 650 spin_lock_irqsave(&cs->lock, flags);
644 if ((tty = cs->tty) == NULL) 651 if ((tty = cs->tty) == NULL)
645 dbg(DEBUG_ANY, "receive on closed device"); 652 gig_dbg(DEBUG_ANY, "receive on closed device");
646 else { 653 else {
647 tty_buffer_request_room(tty, len); 654 tty_buffer_request_room(tty, len);
648 tty_insert_flip_string(tty, buffer, len); 655 tty_insert_flip_string(tty, buffer, len);
@@ -655,13 +662,13 @@ EXPORT_SYMBOL_GPL(gigaset_if_receive);
655/* gigaset_if_initdriver 662/* gigaset_if_initdriver
656 * Initialize tty interface. 663 * Initialize tty interface.
657 * parameters: 664 * parameters:
658 * drv Driver 665 * drv Driver
659 * procname Name of the driver (e.g. for /proc/tty/drivers) 666 * procname Name of the driver (e.g. for /proc/tty/drivers)
660 * devname Name of the device files (prefix without minor number) 667 * devname Name of the device files (prefix without minor number)
661 * devfsname Devfs name of the device files without %d 668 * devfsname Devfs name of the device files without %d
662 */ 669 */
663void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, 670void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
664 const char *devname, const char *devfsname) 671 const char *devname, const char *devfsname)
665{ 672{
666 unsigned minors = drv->minors; 673 unsigned minors = drv->minors;
667 int ret; 674 int ret;
@@ -696,7 +703,7 @@ void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
696 warn("failed to register tty driver (error %d)", ret); 703 warn("failed to register tty driver (error %d)", ret);
697 goto error; 704 goto error;
698 } 705 }
699 dbg(DEBUG_IF, "tty driver initialized"); 706 gig_dbg(DEBUG_IF, "tty driver initialized");
700 drv->have_tty = 1; 707 drv->have_tty = 1;
701 return; 708 return;
702 709
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
index 5744eb91b315..8667daaa1a82 100644
--- a/drivers/isdn/gigaset/isocdata.c
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -10,10 +10,6 @@
10 * published by the Free Software Foundation; either version 2 of 10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version. 11 * the License, or (at your option) any later version.
12 * ===================================================================== 12 * =====================================================================
13 * ToDo: ...
14 * =====================================================================
15 * Version: $Id: isocdata.c,v 1.2.2.5 2005/11/13 23:05:19 hjlipp Exp $
16 * =====================================================================
17 */ 13 */
18 14
19#include "gigaset.h" 15#include "gigaset.h"
@@ -87,14 +83,14 @@ static inline int isowbuf_startwrite(struct isowbuf_t *iwb)
87{ 83{
88 if (!atomic_dec_and_test(&iwb->writesem)) { 84 if (!atomic_dec_and_test(&iwb->writesem)) {
89 atomic_inc(&iwb->writesem); 85 atomic_inc(&iwb->writesem);
90 dbg(DEBUG_ISO, 86 gig_dbg(DEBUG_ISO, "%s: couldn't acquire iso write semaphore",
91 "%s: couldn't acquire iso write semaphore", __func__); 87 __func__);
92 return 0; 88 return 0;
93 } 89 }
94#ifdef CONFIG_GIGASET_DEBUG 90#ifdef CONFIG_GIGASET_DEBUG
95 dbg(DEBUG_ISO, 91 gig_dbg(DEBUG_ISO,
96 "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d", 92 "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d",
97 __func__, iwb->data[atomic_read(&iwb->write)], iwb->wbits); 93 __func__, iwb->data[atomic_read(&iwb->write)], iwb->wbits);
98#endif 94#endif
99 return 1; 95 return 1;
100} 96}
@@ -147,7 +143,7 @@ static inline void isowbuf_putflag(struct isowbuf_t *iwb)
147 /* recover the idle flag byte */ 143 /* recover the idle flag byte */
148 write = atomic_read(&iwb->write); 144 write = atomic_read(&iwb->write);
149 iwb->idle = iwb->data[write]; 145 iwb->idle = iwb->data[write];
150 dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle); 146 gig_dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle);
151 /* mask extraneous bits in buffer */ 147 /* mask extraneous bits in buffer */
152 iwb->data[write] &= (1 << iwb->wbits) - 1; 148 iwb->data[write] &= (1 << iwb->wbits) - 1;
153} 149}
@@ -166,15 +162,14 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
166 read = atomic_read(&iwb->nextread); 162 read = atomic_read(&iwb->nextread);
167 write = atomic_read(&iwb->write); 163 write = atomic_read(&iwb->write);
168 if (likely(read == write)) { 164 if (likely(read == write)) {
169 //dbg(DEBUG_STREAM, "%s: send buffer empty", __func__);
170 /* return idle frame */ 165 /* return idle frame */
171 return read < BAS_OUTBUFPAD ? 166 return read < BAS_OUTBUFPAD ?
172 BAS_OUTBUFSIZE : read - BAS_OUTBUFPAD; 167 BAS_OUTBUFSIZE : read - BAS_OUTBUFPAD;
173 } 168 }
174 169
175 limit = read + size; 170 limit = read + size;
176 dbg(DEBUG_STREAM, 171 gig_dbg(DEBUG_STREAM, "%s: read=%d write=%d limit=%d",
177 "%s: read=%d write=%d limit=%d", __func__, read, write, limit); 172 __func__, read, write, limit);
178#ifdef CONFIG_GIGASET_DEBUG 173#ifdef CONFIG_GIGASET_DEBUG
179 if (unlikely(size < 0 || size > BAS_OUTBUFPAD)) { 174 if (unlikely(size < 0 || size > BAS_OUTBUFPAD)) {
180 err("invalid size %d", size); 175 err("invalid size %d", size);
@@ -196,11 +191,12 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
196 return -EBUSY; 191 return -EBUSY;
197 /* write position could have changed */ 192 /* write position could have changed */
198 if (limit >= (write = atomic_read(&iwb->write))) { 193 if (limit >= (write = atomic_read(&iwb->write))) {
199 pbyte = iwb->data[write]; /* save partial byte */ 194 pbyte = iwb->data[write]; /* save
195 partial byte */
200 limit = write + BAS_OUTBUFPAD; 196 limit = write + BAS_OUTBUFPAD;
201 dbg(DEBUG_STREAM, 197 gig_dbg(DEBUG_STREAM,
202 "%s: filling %d->%d with %02x", 198 "%s: filling %d->%d with %02x",
203 __func__, write, limit, iwb->idle); 199 __func__, write, limit, iwb->idle);
204 if (write + BAS_OUTBUFPAD < BAS_OUTBUFSIZE) 200 if (write + BAS_OUTBUFPAD < BAS_OUTBUFSIZE)
205 memset(iwb->data + write, iwb->idle, 201 memset(iwb->data + write, iwb->idle,
206 BAS_OUTBUFPAD); 202 BAS_OUTBUFPAD);
@@ -211,9 +207,11 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
211 - write); 207 - write);
212 limit = 0; 208 limit = 0;
213 } 209 }
214 dbg(DEBUG_STREAM, "%s: restoring %02x at %d", 210 gig_dbg(DEBUG_STREAM,
215 __func__, pbyte, limit); 211 "%s: restoring %02x at %d",
216 iwb->data[limit] = pbyte; /* restore partial byte */ 212 __func__, pbyte, limit);
213 iwb->data[limit] = pbyte; /* restore
214 partial byte */
217 atomic_set(&iwb->write, limit); 215 atomic_set(&iwb->write, limit);
218 } 216 }
219 isowbuf_donewrite(iwb); 217 isowbuf_donewrite(iwb);
@@ -242,19 +240,17 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
242 * write hex bytes to syslog for debugging 240 * write hex bytes to syslog for debugging
243 */ 241 */
244static inline void dump_bytes(enum debuglevel level, const char *tag, 242static inline void dump_bytes(enum debuglevel level, const char *tag,
245 unsigned char *bytes, int count) 243 unsigned char *bytes, int count)
246{ 244{
247#ifdef CONFIG_GIGASET_DEBUG 245#ifdef CONFIG_GIGASET_DEBUG
248 unsigned char c; 246 unsigned char c;
249 static char dbgline[3 * 32 + 1]; 247 static char dbgline[3 * 32 + 1];
250 static const char hexdigit[] = "0123456789abcdef"; 248 static const char hexdigit[] = "0123456789abcdef";
251 int i = 0; 249 int i = 0;
252 IFNULLRET(tag);
253 IFNULLRET(bytes);
254 while (count-- > 0) { 250 while (count-- > 0) {
255 if (i > sizeof(dbgline) - 4) { 251 if (i > sizeof(dbgline) - 4) {
256 dbgline[i] = '\0'; 252 dbgline[i] = '\0';
257 dbg(level, "%s:%s", tag, dbgline); 253 gig_dbg(level, "%s:%s", tag, dbgline);
258 i = 0; 254 i = 0;
259 } 255 }
260 c = *bytes++; 256 c = *bytes++;
@@ -264,7 +260,7 @@ static inline void dump_bytes(enum debuglevel level, const char *tag,
264 dbgline[i++] = hexdigit[c & 0x0f]; 260 dbgline[i++] = hexdigit[c & 0x0f];
265 } 261 }
266 dbgline[i] = '\0'; 262 dbgline[i] = '\0';
267 dbg(level, "%s:%s", tag, dbgline); 263 gig_dbg(level, "%s:%s", tag, dbgline);
268#endif 264#endif
269} 265}
270 266
@@ -380,7 +376,7 @@ static u16 stufftab[5 * 256] = {
380 */ 376 */
381 377
382static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin, 378static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin,
383 int ones) 379 int ones)
384{ 380{
385 u16 stuff; 381 u16 stuff;
386 int shiftinc, newones; 382 int shiftinc, newones;
@@ -422,7 +418,7 @@ static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin,
422 */ 418 */
423 419
424static inline int hdlc_buildframe(struct isowbuf_t *iwb, 420static inline int hdlc_buildframe(struct isowbuf_t *iwb,
425 unsigned char *in, int count) 421 unsigned char *in, int count)
426{ 422{
427 int ones; 423 int ones;
428 u16 fcs; 424 u16 fcs;
@@ -431,8 +427,8 @@ static inline int hdlc_buildframe(struct isowbuf_t *iwb,
431 427
432 if (isowbuf_freebytes(iwb) < count + count / 5 + 6 || 428 if (isowbuf_freebytes(iwb) < count + count / 5 + 6 ||
433 !isowbuf_startwrite(iwb)) { 429 !isowbuf_startwrite(iwb)) {
434 dbg(DEBUG_ISO, "%s: %d bytes free -> -EAGAIN", 430 gig_dbg(DEBUG_ISO, "%s: %d bytes free -> -EAGAIN",
435 __func__, isowbuf_freebytes(iwb)); 431 __func__, isowbuf_freebytes(iwb));
436 return -EAGAIN; 432 return -EAGAIN;
437 } 433 }
438 434
@@ -484,11 +480,11 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
484 480
485 if (isowbuf_freebytes(iwb) < count || 481 if (isowbuf_freebytes(iwb) < count ||
486 !isowbuf_startwrite(iwb)) { 482 !isowbuf_startwrite(iwb)) {
487 dbg(DEBUG_ISO, "can't put %d bytes", count); 483 gig_dbg(DEBUG_ISO, "can't put %d bytes", count);
488 return -EAGAIN; 484 return -EAGAIN;
489 } 485 }
490 486
491 dbg(DEBUG_STREAM, "put %d bytes", count); 487 gig_dbg(DEBUG_STREAM, "put %d bytes", count);
492 write = atomic_read(&iwb->write); 488 write = atomic_read(&iwb->write);
493 do { 489 do {
494 c = gigaset_invtab[*in++]; 490 c = gigaset_invtab[*in++];
@@ -508,11 +504,13 @@ int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len)
508 switch (bcs->proto2) { 504 switch (bcs->proto2) {
509 case ISDN_PROTO_L2_HDLC: 505 case ISDN_PROTO_L2_HDLC:
510 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len); 506 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len);
511 dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d", __func__, len, result); 507 gig_dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d",
508 __func__, len, result);
512 break; 509 break;
513 default: /* assume transparent */ 510 default: /* assume transparent */
514 result = trans_buildframe(bcs->hw.bas->isooutbuf, in, len); 511 result = trans_buildframe(bcs->hw.bas->isooutbuf, in, len);
515 dbg(DEBUG_ISO, "%s: %d bytes trans -> %d", __func__, len, result); 512 gig_dbg(DEBUG_ISO, "%s: %d bytes trans -> %d",
513 __func__, len, result);
516 } 514 }
517 return result; 515 return result;
518} 516}
@@ -528,13 +526,13 @@ static inline void hdlc_putbyte(unsigned char c, struct bc_state *bcs)
528 return; 526 return;
529 } 527 }
530 if (unlikely(bcs->skb->len == SBUFSIZE)) { 528 if (unlikely(bcs->skb->len == SBUFSIZE)) {
531 warn("received oversized packet discarded"); 529 dev_warn(bcs->cs->dev, "received oversized packet discarded\n");
532 bcs->hw.bas->giants++; 530 bcs->hw.bas->giants++;
533 dev_kfree_skb_any(bcs->skb); 531 dev_kfree_skb_any(bcs->skb);
534 bcs->skb = NULL; 532 bcs->skb = NULL;
535 return; 533 return;
536 } 534 }
537 *gigaset_skb_put_quick(bcs->skb, 1) = c; 535 *__skb_put(bcs->skb, 1) = c;
538} 536}
539 537
540/* hdlc_flush 538/* hdlc_flush
@@ -549,7 +547,7 @@ static inline void hdlc_flush(struct bc_state *bcs)
549 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 547 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
550 skb_reserve(bcs->skb, HW_HDR_LEN); 548 skb_reserve(bcs->skb, HW_HDR_LEN);
551 else 549 else
552 err("could not allocate skb"); 550 dev_err(bcs->cs->dev, "could not allocate skb\n");
553 } 551 }
554 552
555 /* reset packet state */ 553 /* reset packet state */
@@ -571,23 +569,25 @@ static inline void hdlc_done(struct bc_state *bcs)
571 569
572 if ((procskb = bcs->skb) == NULL) { 570 if ((procskb = bcs->skb) == NULL) {
573 /* previous error */ 571 /* previous error */
574 dbg(DEBUG_ISO, "%s: skb=NULL", __func__); 572 gig_dbg(DEBUG_ISO, "%s: skb=NULL", __func__);
575 gigaset_rcv_error(NULL, bcs->cs, bcs); 573 gigaset_rcv_error(NULL, bcs->cs, bcs);
576 } else if (procskb->len < 2) { 574 } else if (procskb->len < 2) {
577 notice("received short frame (%d octets)", procskb->len); 575 dev_notice(bcs->cs->dev, "received short frame (%d octets)\n",
576 procskb->len);
578 bcs->hw.bas->runts++; 577 bcs->hw.bas->runts++;
579 gigaset_rcv_error(procskb, bcs->cs, bcs); 578 gigaset_rcv_error(procskb, bcs->cs, bcs);
580 } else if (bcs->fcs != PPP_GOODFCS) { 579 } else if (bcs->fcs != PPP_GOODFCS) {
581 notice("frame check error (0x%04x)", bcs->fcs); 580 dev_notice(bcs->cs->dev, "frame check error (0x%04x)\n",
581 bcs->fcs);
582 bcs->hw.bas->fcserrs++; 582 bcs->hw.bas->fcserrs++;
583 gigaset_rcv_error(procskb, bcs->cs, bcs); 583 gigaset_rcv_error(procskb, bcs->cs, bcs);
584 } else { 584 } else {
585 procskb->len -= 2; /* subtract FCS */ 585 procskb->len -= 2; /* subtract FCS */
586 procskb->tail -= 2; 586 procskb->tail -= 2;
587 dbg(DEBUG_ISO, 587 gig_dbg(DEBUG_ISO, "%s: good frame (%d octets)",
588 "%s: good frame (%d octets)", __func__, procskb->len); 588 __func__, procskb->len);
589 dump_bytes(DEBUG_STREAM, 589 dump_bytes(DEBUG_STREAM,
590 "rcv data", procskb->data, procskb->len); 590 "rcv data", procskb->data, procskb->len);
591 bcs->hw.bas->goodbytes += procskb->len; 591 bcs->hw.bas->goodbytes += procskb->len;
592 gigaset_rcv_skb(procskb, bcs->cs, bcs); 592 gigaset_rcv_skb(procskb, bcs->cs, bcs);
593 } 593 }
@@ -595,7 +595,7 @@ static inline void hdlc_done(struct bc_state *bcs)
595 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 595 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
596 skb_reserve(bcs->skb, HW_HDR_LEN); 596 skb_reserve(bcs->skb, HW_HDR_LEN);
597 else 597 else
598 err("could not allocate skb"); 598 dev_err(bcs->cs->dev, "could not allocate skb\n");
599 bcs->fcs = PPP_INITFCS; 599 bcs->fcs = PPP_INITFCS;
600} 600}
601 601
@@ -610,14 +610,14 @@ static inline void hdlc_frag(struct bc_state *bcs, unsigned inbits)
610 return; 610 return;
611 } 611 }
612 612
613 notice("received partial byte (%d bits)", inbits); 613 dev_notice(bcs->cs->dev, "received partial byte (%d bits)\n", inbits);
614 bcs->hw.bas->alignerrs++; 614 bcs->hw.bas->alignerrs++;
615 gigaset_rcv_error(bcs->skb, bcs->cs, bcs); 615 gigaset_rcv_error(bcs->skb, bcs->cs, bcs);
616 616
617 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 617 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
618 skb_reserve(bcs->skb, HW_HDR_LEN); 618 skb_reserve(bcs->skb, HW_HDR_LEN);
619 else 619 else
620 err("could not allocate skb"); 620 dev_err(bcs->cs->dev, "could not allocate skb\n");
621 bcs->fcs = PPP_INITFCS; 621 bcs->fcs = PPP_INITFCS;
622} 622}
623 623
@@ -659,16 +659,12 @@ static unsigned char bitcounts[256] = {
659 * bcs receiving B channel structure 659 * bcs receiving B channel structure
660 */ 660 */
661static inline void hdlc_unpack(unsigned char *src, unsigned count, 661static inline void hdlc_unpack(unsigned char *src, unsigned count,
662 struct bc_state *bcs) 662 struct bc_state *bcs)
663{ 663{
664 struct bas_bc_state *ubc; 664 struct bas_bc_state *ubc = bcs->hw.bas;
665 int inputstate; 665 int inputstate;
666 unsigned seqlen, inbyte, inbits; 666 unsigned seqlen, inbyte, inbits;
667 667
668 IFNULLRET(bcs);
669 ubc = bcs->hw.bas;
670 IFNULLRET(ubc);
671
672 /* load previous state: 668 /* load previous state:
673 * inputstate = set of flag bits: 669 * inputstate = set of flag bits:
674 * - INS_flag_hunt: no complete opening flag received since connection setup or last abort 670 * - INS_flag_hunt: no complete opening flag received since connection setup or last abort
@@ -856,7 +852,7 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
856 * bcs receiving B channel structure 852 * bcs receiving B channel structure
857 */ 853 */
858static inline void trans_receive(unsigned char *src, unsigned count, 854static inline void trans_receive(unsigned char *src, unsigned count,
859 struct bc_state *bcs) 855 struct bc_state *bcs)
860{ 856{
861 struct sk_buff *skb; 857 struct sk_buff *skb;
862 int dobytes; 858 int dobytes;
@@ -870,7 +866,7 @@ static inline void trans_receive(unsigned char *src, unsigned count,
870 if (unlikely((skb = bcs->skb) == NULL)) { 866 if (unlikely((skb = bcs->skb) == NULL)) {
871 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 867 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN);
872 if (!skb) { 868 if (!skb) {
873 err("could not allocate skb"); 869 dev_err(bcs->cs->dev, "could not allocate skb\n");
874 return; 870 return;
875 } 871 }
876 skb_reserve(skb, HW_HDR_LEN); 872 skb_reserve(skb, HW_HDR_LEN);
@@ -888,7 +884,8 @@ static inline void trans_receive(unsigned char *src, unsigned count,
888 gigaset_rcv_skb(skb, bcs->cs, bcs); 884 gigaset_rcv_skb(skb, bcs->cs, bcs);
889 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 885 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN);
890 if (!skb) { 886 if (!skb) {
891 err("could not allocate skb"); 887 dev_err(bcs->cs->dev,
888 "could not allocate skb\n");
892 return; 889 return;
893 } 890 }
894 skb_reserve(bcs->skb, HW_HDR_LEN); 891 skb_reserve(bcs->skb, HW_HDR_LEN);
@@ -921,8 +918,8 @@ static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf)
921 case '\r': 918 case '\r':
922 case '\n': 919 case '\n':
923 /* end of line */ 920 /* end of line */
924 dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", 921 gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
925 __func__, cbytes); 922 __func__, cbytes);
926 cs->cbytes = cbytes; 923 cs->cbytes = cbytes;
927 gigaset_handle_modem_response(cs); 924 gigaset_handle_modem_response(cs);
928 cbytes = 0; 925 cbytes = 0;
@@ -932,7 +929,7 @@ static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf)
932 if (cbytes < MAX_RESP_SIZE - 1) 929 if (cbytes < MAX_RESP_SIZE - 1)
933 cbytes++; 930 cbytes++;
934 else 931 else
935 warn("response too large"); 932 dev_warn(cs->dev, "response too large\n");
936 } 933 }
937 } 934 }
938 935
@@ -951,27 +948,27 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
951 948
952 head = atomic_read(&inbuf->head); 949 head = atomic_read(&inbuf->head);
953 while (head != (tail = atomic_read(&inbuf->tail))) { 950 while (head != (tail = atomic_read(&inbuf->tail))) {
954 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); 951 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
955 if (head > tail) 952 if (head > tail)
956 tail = RBUFSIZE; 953 tail = RBUFSIZE;
957 src = inbuf->data + head; 954 src = inbuf->data + head;
958 numbytes = tail - head; 955 numbytes = tail - head;
959 dbg(DEBUG_INTR, "processing %u bytes", numbytes); 956 gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
960 957
961 if (atomic_read(&cs->mstate) == MS_LOCKED) { 958 if (atomic_read(&cs->mstate) == MS_LOCKED) {
962 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response", 959 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response",
963 numbytes, src, 0); 960 numbytes, src);
964 gigaset_if_receive(inbuf->cs, src, numbytes); 961 gigaset_if_receive(inbuf->cs, src, numbytes);
965 } else { 962 } else {
966 gigaset_dbg_buffer(DEBUG_CMD, "received response", 963 gigaset_dbg_buffer(DEBUG_CMD, "received response",
967 numbytes, src, 0); 964 numbytes, src);
968 cmd_loop(src, numbytes, inbuf); 965 cmd_loop(src, numbytes, inbuf);
969 } 966 }
970 967
971 head += numbytes; 968 head += numbytes;
972 if (head == RBUFSIZE) 969 if (head == RBUFSIZE)
973 head = 0; 970 head = 0;
974 dbg(DEBUG_INTR, "setting head to %u", head); 971 gig_dbg(DEBUG_INTR, "setting head to %u", head);
975 atomic_set(&inbuf->head, head); 972 atomic_set(&inbuf->head, head);
976 } 973 }
977} 974}
@@ -992,18 +989,22 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
992 */ 989 */
993int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb) 990int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb)
994{ 991{
995 int len; 992 int len = skb->len;
993 unsigned long flags;
996 994
997 IFNULLRETVAL(bcs, -EFAULT); 995 spin_lock_irqsave(&bcs->cs->lock, flags);
998 IFNULLRETVAL(skb, -EFAULT); 996 if (!bcs->cs->connected) {
999 len = skb->len; 997 spin_unlock_irqrestore(&bcs->cs->lock, flags);
998 return -ENODEV;
999 }
1000 1000
1001 skb_queue_tail(&bcs->squeue, skb); 1001 skb_queue_tail(&bcs->squeue, skb);
1002 dbg(DEBUG_ISO, 1002 gig_dbg(DEBUG_ISO, "%s: skb queued, qlen=%d",
1003 "%s: skb queued, qlen=%d", __func__, skb_queue_len(&bcs->squeue)); 1003 __func__, skb_queue_len(&bcs->squeue));
1004 1004
1005 /* tasklet submits URB if necessary */ 1005 /* tasklet submits URB if necessary */
1006 tasklet_schedule(&bcs->hw.bas->sent_tasklet); 1006 tasklet_schedule(&bcs->hw.bas->sent_tasklet);
1007 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1007 1008
1008 return len; /* ok so far */ 1009 return len; /* ok so far */
1009} 1010}
diff --git a/drivers/isdn/gigaset/proc.c b/drivers/isdn/gigaset/proc.c
index c6915fa2be6c..d267a636b53c 100644
--- a/drivers/isdn/gigaset/proc.c
+++ b/drivers/isdn/gigaset/proc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>. 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
@@ -11,26 +11,29 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: proc.c,v 1.5.2.13 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
21#include <linux/ctype.h> 17#include <linux/ctype.h>
22 18
23static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr, char *buf) 19static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr,
20 char *buf)
24{ 21{
25 struct usb_interface *intf = to_usb_interface(dev); 22 int ret;
26 struct cardstate *cs = usb_get_intfdata(intf); 23 unsigned long flags;
27 return sprintf(buf, "%d\n", atomic_read(&cs->cidmode)); // FIXME use scnprintf for 13607 bit architectures (if PAGE_SIZE==4096) 24 struct cardstate *cs = dev_get_drvdata(dev);
25
26 spin_lock_irqsave(&cs->lock, flags);
27 ret = sprintf(buf, "%u\n", cs->cidmode);
28 spin_unlock_irqrestore(&cs->lock, flags);
29
30 return ret;
28} 31}
29 32
30static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 33static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
34 const char *buf, size_t count)
31{ 35{
32 struct usb_interface *intf = to_usb_interface(dev); 36 struct cardstate *cs = dev_get_drvdata(dev);
33 struct cardstate *cs = usb_get_intfdata(intf);
34 long int value; 37 long int value;
35 char *end; 38 char *end;
36 39
@@ -41,23 +44,23 @@ static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, co
41 if (value < 0 || value > 1) 44 if (value < 0 || value > 1)
42 return -EINVAL; 45 return -EINVAL;
43 46
44 if (down_interruptible(&cs->sem)) 47 if (mutex_lock_interruptible(&cs->mutex))
45 return -ERESTARTSYS; // FIXME -EINTR? 48 return -ERESTARTSYS; // FIXME -EINTR?
46 49
47 cs->waiting = 1; 50 cs->waiting = 1;
48 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE, 51 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
49 NULL, value, NULL)) { 52 NULL, value, NULL)) {
50 cs->waiting = 0; 53 cs->waiting = 0;
51 up(&cs->sem); 54 mutex_unlock(&cs->mutex);
52 return -ENOMEM; 55 return -ENOMEM;
53 } 56 }
54 57
55 dbg(DEBUG_CMD, "scheduling PROC_CIDMODE"); 58 gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
56 gigaset_schedule_event(cs); 59 gigaset_schedule_event(cs);
57 60
58 wait_event(cs->waitqueue, !cs->waiting); 61 wait_event(cs->waitqueue, !cs->waiting);
59 62
60 up(&cs->sem); 63 mutex_unlock(&cs->mutex);
61 64
62 return count; 65 return count;
63} 66}
@@ -65,17 +68,15 @@ static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, co
65static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode); 68static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
66 69
67/* free sysfs for device */ 70/* free sysfs for device */
68void gigaset_free_dev_sysfs(struct usb_interface *interface) 71void gigaset_free_dev_sysfs(struct cardstate *cs)
69{ 72{
70 dbg(DEBUG_INIT, "removing sysfs entries"); 73 gig_dbg(DEBUG_INIT, "removing sysfs entries");
71 device_remove_file(&interface->dev, &dev_attr_cidmode); 74 device_remove_file(cs->dev, &dev_attr_cidmode);
72} 75}
73EXPORT_SYMBOL_GPL(gigaset_free_dev_sysfs);
74 76
75/* initialize sysfs for device */ 77/* initialize sysfs for device */
76void gigaset_init_dev_sysfs(struct usb_interface *interface) 78void gigaset_init_dev_sysfs(struct cardstate *cs)
77{ 79{
78 dbg(DEBUG_INIT, "setting up sysfs"); 80 gig_dbg(DEBUG_INIT, "setting up sysfs");
79 device_create_file(&interface->dev, &dev_attr_cidmode); 81 device_create_file(cs->dev, &dev_attr_cidmode);
80} 82}
81EXPORT_SYMBOL_GPL(gigaset_init_dev_sysfs);
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
index 323fc7349dec..bfb73fd5077e 100644
--- a/drivers/isdn/gigaset/usb-gigaset.c
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB driver for Gigaset 307x directly or using M105 Data. 2 * USB driver for Gigaset 307x directly or using M105 Data.
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de> 4 * Copyright (c) 2001 by Stefan Eilers
5 * and Hansjoerg Lipp <hjlipp@web.de>. 5 * and Hansjoerg Lipp <hjlipp@web.de>.
6 * 6 *
7 * This driver was derived from the USB skeleton driver by 7 * This driver was derived from the USB skeleton driver by
@@ -13,10 +13,6 @@
13 * published by the Free Software Foundation; either version 2 of 13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version. 14 * the License, or (at your option) any later version.
15 * ===================================================================== 15 * =====================================================================
16 * ToDo: ...
17 * =====================================================================
18 * Version: $Id: usb-gigaset.c,v 1.85.4.18 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
20 */ 16 */
21 17
22#include "gigaset.h" 18#include "gigaset.h"
@@ -29,7 +25,7 @@
29#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
30 26
31/* Version Information */ 27/* Version Information */
32#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>" 28#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
33#define DRIVER_DESC "USB Driver for Gigaset 307x using M105" 29#define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
34 30
35/* Module parameters */ 31/* Module parameters */
@@ -62,10 +58,6 @@ static struct usb_device_id gigaset_table [] = {
62 58
63MODULE_DEVICE_TABLE(usb, gigaset_table); 59MODULE_DEVICE_TABLE(usb, gigaset_table);
64 60
65/* Get a minor range for your devices from the usb maintainer */
66#define USB_SKEL_MINOR_BASE 200
67
68
69/* 61/*
70 * Control requests (empty fields: 00) 62 * Control requests (empty fields: 00)
71 * 63 *
@@ -114,7 +106,7 @@ MODULE_DEVICE_TABLE(usb, gigaset_table);
114 */ 106 */
115 107
116static int gigaset_probe(struct usb_interface *interface, 108static int gigaset_probe(struct usb_interface *interface,
117 const struct usb_device_id *id); 109 const struct usb_device_id *id);
118static void gigaset_disconnect(struct usb_interface *interface); 110static void gigaset_disconnect(struct usb_interface *interface);
119 111
120static struct gigaset_driver *driver = NULL; 112static struct gigaset_driver *driver = NULL;
@@ -122,29 +114,29 @@ static struct cardstate *cardstate = NULL;
122 114
123/* usb specific object needed to register this driver with the usb subsystem */ 115/* usb specific object needed to register this driver with the usb subsystem */
124static struct usb_driver gigaset_usb_driver = { 116static struct usb_driver gigaset_usb_driver = {
125 .name = GIGASET_MODULENAME, 117 .name = GIGASET_MODULENAME,
126 .probe = gigaset_probe, 118 .probe = gigaset_probe,
127 .disconnect = gigaset_disconnect, 119 .disconnect = gigaset_disconnect,
128 .id_table = gigaset_table, 120 .id_table = gigaset_table,
129}; 121};
130 122
131struct usb_cardstate { 123struct usb_cardstate {
132 struct usb_device *udev; /* save off the usb device pointer */ 124 struct usb_device *udev; /* usb device pointer */
133 struct usb_interface *interface; /* the interface for this device */ 125 struct usb_interface *interface; /* interface for this device */
134 atomic_t busy; /* bulk output in progress */ 126 atomic_t busy; /* bulk output in progress */
135 127
136 /* Output buffer for commands (M105: and data)*/ 128 /* Output buffer */
137 unsigned char *bulk_out_buffer; /* the buffer to send data */ 129 unsigned char *bulk_out_buffer;
138 int bulk_out_size; /* the size of the send buffer */ 130 int bulk_out_size;
139 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 131 __u8 bulk_out_endpointAddr;
140 struct urb *bulk_out_urb; /* the urb used to transmit data */ 132 struct urb *bulk_out_urb;
141 133
142 /* Input buffer for command responses (M105: and data)*/ 134 /* Input buffer */
143 int rcvbuf_size; /* the size of the receive buffer */ 135 int rcvbuf_size;
144 struct urb *read_urb; /* the urb used to receive data */ 136 struct urb *read_urb;
145 __u8 int_in_endpointAddr; /* the address of the bulk in endpoint */ 137 __u8 int_in_endpointAddr;
146 138
147 char bchars[6]; /* req. 0x19 */ 139 char bchars[6]; /* for request 0x19 */
148}; 140};
149 141
150struct usb_bc_state {}; 142struct usb_bc_state {};
@@ -157,19 +149,20 @@ static inline unsigned tiocm_to_gigaset(unsigned state)
157#ifdef CONFIG_GIGASET_UNDOCREQ 149#ifdef CONFIG_GIGASET_UNDOCREQ
158/* WARNING: EXPERIMENTAL! */ 150/* WARNING: EXPERIMENTAL! */
159static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, 151static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
160 unsigned new_state) 152 unsigned new_state)
161{ 153{
154 struct usb_device *udev = cs->hw.usb->udev;
162 unsigned mask, val; 155 unsigned mask, val;
163 int r; 156 int r;
164 157
165 mask = tiocm_to_gigaset(old_state ^ new_state); 158 mask = tiocm_to_gigaset(old_state ^ new_state);
166 val = tiocm_to_gigaset(new_state); 159 val = tiocm_to_gigaset(new_state);
167 160
168 dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask); 161 gig_dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask);
169 r = usb_control_msg(cs->hw.usb->udev, 162 // don't use this in an interrupt/BH
170 usb_sndctrlpipe(cs->hw.usb->udev, 0), 7, 0x41, 163 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 7, 0x41,
171 (val & 0xff) | ((mask & 0xff) << 8), 0, 164 (val & 0xff) | ((mask & 0xff) << 8), 0,
172 NULL, 0, 2000 /*timeout??*/); // don't use this in an interrupt/BH 165 NULL, 0, 2000 /* timeout? */);
173 if (r < 0) 166 if (r < 0)
174 return r; 167 return r;
175 //.. 168 //..
@@ -178,30 +171,29 @@ static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
178 171
179static int set_value(struct cardstate *cs, u8 req, u16 val) 172static int set_value(struct cardstate *cs, u8 req, u16 val)
180{ 173{
174 struct usb_device *udev = cs->hw.usb->udev;
181 int r, r2; 175 int r, r2;
182 176
183 dbg(DEBUG_USBREQ, "request %02x (%04x)", (unsigned)req, (unsigned)val); 177 gig_dbg(DEBUG_USBREQ, "request %02x (%04x)",
184 r = usb_control_msg(cs->hw.usb->udev, 178 (unsigned)req, (unsigned)val);
185 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x12, 0x41, 179 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x12, 0x41,
186 0xf /*?*/, 0, 180 0xf /*?*/, 0, NULL, 0, 2000 /*?*/);
187 NULL, 0, 2000 /*?*/); /* no idea, what this does */ 181 /* no idea what this does */
188 if (r < 0) { 182 if (r < 0) {
189 err("error %d on request 0x12", -r); 183 dev_err(&udev->dev, "error %d on request 0x12\n", -r);
190 return r; 184 return r;
191 } 185 }
192 186
193 r = usb_control_msg(cs->hw.usb->udev, 187 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), req, 0x41,
194 usb_sndctrlpipe(cs->hw.usb->udev, 0), req, 0x41, 188 val, 0, NULL, 0, 2000 /*?*/);
195 val, 0,
196 NULL, 0, 2000 /*?*/);
197 if (r < 0) 189 if (r < 0)
198 err("error %d on request 0x%02x", -r, (unsigned)req); 190 dev_err(&udev->dev, "error %d on request 0x%02x\n",
191 -r, (unsigned)req);
199 192
200 r2 = usb_control_msg(cs->hw.usb->udev, 193 r2 = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
201 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41, 194 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/);
202 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/);
203 if (r2 < 0) 195 if (r2 < 0)
204 err("error %d on request 0x19", -r2); 196 dev_err(&udev->dev, "error %d on request 0x19\n", -r2);
205 197
206 return r < 0 ? r : (r2 < 0 ? r2 : 0); 198 return r < 0 ? r : (r2 < 0 ? r2 : 0);
207} 199}
@@ -229,8 +221,8 @@ static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
229 case B115200: rate = 115200; break; 221 case B115200: rate = 115200; break;
230 default: 222 default:
231 rate = 9600; 223 rate = 9600;
232 err("unsupported baudrate request 0x%x," 224 dev_err(cs->dev, "unsupported baudrate request 0x%x,"
233 " using default of B9600", cflag); 225 " using default of B9600\n", cflag);
234 } 226 }
235 227
236 val = 0x383fff / rate + 1; 228 val = 0x383fff / rate + 1;
@@ -259,7 +251,7 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
259 case CS8: 251 case CS8:
260 val |= 8 << 8; break; 252 val |= 8 << 8; break;
261 default: 253 default:
262 err("CSIZE was not CS5-CS8, using default of 8"); 254 dev_err(cs->dev, "CSIZE was not CS5-CS8, using default of 8\n");
263 val |= 8 << 8; 255 val |= 8 << 8;
264 break; 256 break;
265 } 257 }
@@ -277,7 +269,7 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
277 269
278#else 270#else
279static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, 271static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
280 unsigned new_state) 272 unsigned new_state)
281{ 273{
282 return -EINVAL; 274 return -EINVAL;
283} 275}
@@ -309,15 +301,12 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
309 return 0; 301 return 0;
310} 302}
311 303
312//void send_ack_to_LL(void *data);
313static int write_modem(struct cardstate *cs); 304static int write_modem(struct cardstate *cs);
314static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb); 305static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb);
315 306
316 307
317/* Handling of send queue. If there is already a skb opened, put data to 308/* Write tasklet handler: Continue sending current skb, or send command, or
318 * the transfer buffer by calling "write_modem". Otherwise take a new skb out of the queue. 309 * start sending an skb from the send queue.
319 * This function will be called by the ISR via "transmit_chars" (USB: B-Channel Bulk callback handler
320 * via immediate task queue) or by writebuf_from_LL if the LL wants to transmit data.
321 */ 310 */
322static void gigaset_modem_fill(unsigned long data) 311static void gigaset_modem_fill(unsigned long data)
323{ 312{
@@ -327,10 +316,10 @@ static void gigaset_modem_fill(unsigned long data)
327 unsigned long flags; 316 unsigned long flags;
328 int again; 317 int again;
329 318
330 dbg(DEBUG_OUTPUT, "modem_fill"); 319 gig_dbg(DEBUG_OUTPUT, "modem_fill");
331 320
332 if (atomic_read(&cs->hw.usb->busy)) { 321 if (atomic_read(&cs->hw.usb->busy)) {
333 dbg(DEBUG_OUTPUT, "modem_fill: busy"); 322 gig_dbg(DEBUG_OUTPUT, "modem_fill: busy");
334 return; 323 return;
335 } 324 }
336 325
@@ -341,26 +330,27 @@ static void gigaset_modem_fill(unsigned long data)
341 cb = cs->cmdbuf; 330 cb = cs->cmdbuf;
342 spin_unlock_irqrestore(&cs->cmdlock, flags); 331 spin_unlock_irqrestore(&cs->cmdlock, flags);
343 if (cb) { /* commands to send? */ 332 if (cb) { /* commands to send? */
344 dbg(DEBUG_OUTPUT, "modem_fill: cb"); 333 gig_dbg(DEBUG_OUTPUT, "modem_fill: cb");
345 if (send_cb(cs, cb) < 0) { 334 if (send_cb(cs, cb) < 0) {
346 dbg(DEBUG_OUTPUT, 335 gig_dbg(DEBUG_OUTPUT,
347 "modem_fill: send_cb failed"); 336 "modem_fill: send_cb failed");
348 again = 1; /* no callback will be called! */ 337 again = 1; /* no callback will be
338 called! */
349 } 339 }
350 } else { /* skbs to send? */ 340 } else { /* skbs to send? */
351 bcs->tx_skb = skb_dequeue(&bcs->squeue); 341 bcs->tx_skb = skb_dequeue(&bcs->squeue);
352 if (bcs->tx_skb) 342 if (bcs->tx_skb)
353 dbg(DEBUG_INTR, 343 gig_dbg(DEBUG_INTR,
354 "Dequeued skb (Adr: %lx)!", 344 "Dequeued skb (Adr: %lx)!",
355 (unsigned long) bcs->tx_skb); 345 (unsigned long) bcs->tx_skb);
356 } 346 }
357 } 347 }
358 348
359 if (bcs->tx_skb) { 349 if (bcs->tx_skb) {
360 dbg(DEBUG_OUTPUT, "modem_fill: tx_skb"); 350 gig_dbg(DEBUG_OUTPUT, "modem_fill: tx_skb");
361 if (write_modem(cs) < 0) { 351 if (write_modem(cs) < 0) {
362 dbg(DEBUG_OUTPUT, 352 gig_dbg(DEBUG_OUTPUT,
363 "modem_fill: write_modem failed"); 353 "modem_fill: write_modem failed");
364 // FIXME should we tell the LL? 354 // FIXME should we tell the LL?
365 again = 1; /* no callback will be called! */ 355 again = 1; /* no callback will be called! */
366 } 356 }
@@ -371,88 +361,85 @@ static void gigaset_modem_fill(unsigned long data)
371/** 361/**
372 * gigaset_read_int_callback 362 * gigaset_read_int_callback
373 * 363 *
374 * It is called if the data was received from the device. This is almost similiar to 364 * It is called if the data was received from the device.
375 * the interrupt service routine in the serial device.
376 */ 365 */
377static void gigaset_read_int_callback(struct urb *urb, struct pt_regs *regs) 366static void gigaset_read_int_callback(struct urb *urb, struct pt_regs *regs)
378{ 367{
368 struct inbuf_t *inbuf = urb->context;
369 struct cardstate *cs = inbuf->cs;
379 int resubmit = 0; 370 int resubmit = 0;
380 int r; 371 int r;
381 struct cardstate *cs;
382 unsigned numbytes; 372 unsigned numbytes;
383 unsigned char *src; 373 unsigned char *src;
384 //unsigned long flags; 374 unsigned long flags;
385 struct inbuf_t *inbuf;
386
387 IFNULLRET(urb);
388 inbuf = (struct inbuf_t *) urb->context;
389 IFNULLRET(inbuf);
390 //spin_lock_irqsave(&inbuf->lock, flags);
391 cs = inbuf->cs;
392 IFNULLGOTO(cs, exit);
393 IFNULLGOTO(cardstate, exit);
394
395 if (!atomic_read(&cs->connected)) {
396 err("%s: disconnected", __func__);
397 goto exit;
398 }
399 375
400 if (!urb->status) { 376 if (!urb->status) {
377 if (!cs->connected) {
378 err("%s: disconnected", __func__); /* should never happen */
379 return;
380 }
381
401 numbytes = urb->actual_length; 382 numbytes = urb->actual_length;
402 383
403 if (numbytes) { 384 if (numbytes) {
404 src = inbuf->rcvbuf; 385 src = inbuf->rcvbuf;
405 if (unlikely(*src)) 386 if (unlikely(*src))
406 warn("%s: There was no leading 0, but 0x%02x!", 387 dev_warn(cs->dev,
407 __func__, (unsigned) *src); 388 "%s: There was no leading 0, but 0x%02x!\n",
389 __func__, (unsigned) *src);
408 ++src; /* skip leading 0x00 */ 390 ++src; /* skip leading 0x00 */
409 --numbytes; 391 --numbytes;
410 if (gigaset_fill_inbuf(inbuf, src, numbytes)) { 392 if (gigaset_fill_inbuf(inbuf, src, numbytes)) {
411 dbg(DEBUG_INTR, "%s-->BH", __func__); 393 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
412 gigaset_schedule_event(inbuf->cs); 394 gigaset_schedule_event(inbuf->cs);
413 } 395 }
414 } else 396 } else
415 dbg(DEBUG_INTR, "Received zero block length"); 397 gig_dbg(DEBUG_INTR, "Received zero block length");
416 resubmit = 1; 398 resubmit = 1;
417 } else { 399 } else {
418 /* The urb might have been killed. */ 400 /* The urb might have been killed. */
419 dbg(DEBUG_ANY, "%s - nonzero read bulk status received: %d", 401 gig_dbg(DEBUG_ANY, "%s - nonzero read bulk status received: %d",
420 __func__, urb->status); 402 __func__, urb->status);
421 if (urb->status != -ENOENT) /* not killed */ 403 if (urb->status != -ENOENT) { /* not killed */
404 if (!cs->connected) {
405 err("%s: disconnected", __func__); /* should never happen */
406 return;
407 }
422 resubmit = 1; 408 resubmit = 1;
409 }
423 } 410 }
424exit: 411
425 //spin_unlock_irqrestore(&inbuf->lock, flags);
426 if (resubmit) { 412 if (resubmit) {
427 r = usb_submit_urb(urb, SLAB_ATOMIC); 413 spin_lock_irqsave(&cs->lock, flags);
414 r = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
415 spin_unlock_irqrestore(&cs->lock, flags);
428 if (r) 416 if (r)
429 err("error %d when resubmitting urb.", -r); 417 dev_err(cs->dev, "error %d when resubmitting urb.\n",
418 -r);
430 } 419 }
431} 420}
432 421
433 422
434/* This callback routine is called when data was transmitted to a B-Channel. 423/* This callback routine is called when data was transmitted to the device. */
435 * Therefore it has to check if there is still data to transmit. This
436 * happens by calling modem_fill via task queue.
437 *
438 */
439static void gigaset_write_bulk_callback(struct urb *urb, struct pt_regs *regs) 424static void gigaset_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
440{ 425{
441 struct cardstate *cs = (struct cardstate *) urb->context; 426 struct cardstate *cs = urb->context;
427 unsigned long flags;
442 428
443 IFNULLRET(cs);
444#ifdef CONFIG_GIGASET_DEBUG
445 if (!atomic_read(&cs->connected)) {
446 err("%s:not connected", __func__);
447 return;
448 }
449#endif
450 if (urb->status) 429 if (urb->status)
451 err("bulk transfer failed (status %d)", -urb->status); /* That's all we can do. Communication problems 430 dev_err(cs->dev, "bulk transfer failed (status %d)\n",
452 are handeled by timeouts or network protocols */ 431 -urb->status);
432 /* That's all we can do. Communication problems
433 are handled by timeouts or network protocols. */
453 434
454 atomic_set(&cs->hw.usb->busy, 0); 435 spin_lock_irqsave(&cs->lock, flags);
455 tasklet_schedule(&cs->write_tasklet); 436 if (!cs->connected) {
437 err("%s: not connected", __func__);
438 } else {
439 atomic_set(&cs->hw.usb->busy, 0);
440 tasklet_schedule(&cs->write_tasklet);
441 }
442 spin_unlock_irqrestore(&cs->lock, flags);
456} 443}
457 444
458static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb) 445static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
@@ -469,8 +456,8 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
469 456
470 spin_lock_irqsave(&cs->cmdlock, flags); 457 spin_lock_irqsave(&cs->cmdlock, flags);
471 cs->cmdbytes -= cs->curlen; 458 cs->cmdbytes -= cs->curlen;
472 dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left", 459 gig_dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left",
473 cs->curlen, cs->cmdbytes); 460 cs->curlen, cs->cmdbytes);
474 cs->cmdbuf = cb = cb->next; 461 cs->cmdbuf = cb = cb->next;
475 if (cb) { 462 if (cb) {
476 cb->prev = NULL; 463 cb->prev = NULL;
@@ -487,52 +474,51 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
487 } 474 }
488 if (cb) { 475 if (cb) {
489 count = min(cb->len, ucs->bulk_out_size); 476 count = min(cb->len, ucs->bulk_out_size);
477 gig_dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
478
490 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev, 479 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
491 usb_sndbulkpipe(ucs->udev, 480 usb_sndbulkpipe(ucs->udev,
492 ucs->bulk_out_endpointAddr & 0x0f), 481 ucs->bulk_out_endpointAddr & 0x0f),
493 cb->buf + cb->offset, count, 482 cb->buf + cb->offset, count,
494 gigaset_write_bulk_callback, cs); 483 gigaset_write_bulk_callback, cs);
495 484
496 cb->offset += count; 485 cb->offset += count;
497 cb->len -= count; 486 cb->len -= count;
498 atomic_set(&ucs->busy, 1); 487 atomic_set(&ucs->busy, 1);
499 dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
500 488
501 status = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC); 489 spin_lock_irqsave(&cs->lock, flags);
490 status = cs->connected ? usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC) : -ENODEV;
491 spin_unlock_irqrestore(&cs->lock, flags);
492
502 if (status) { 493 if (status) {
503 atomic_set(&ucs->busy, 0); 494 atomic_set(&ucs->busy, 0);
504 err("could not submit urb (error %d).", 495 err("could not submit urb (error %d)\n",
505 -status); 496 -status);
506 cb->len = 0; /* skip urb => remove cb+wakeup in next loop cycle */ 497 cb->len = 0; /* skip urb => remove cb+wakeup
498 in next loop cycle */
507 } 499 }
508 } 500 }
509 } while (cb && status); /* bei Fehler naechster Befehl //FIXME: ist das OK? */ 501 } while (cb && status); /* next command on error */
510 502
511 return status; 503 return status;
512} 504}
513 505
514/* Write string into transbuf and send it to modem. 506/* Send command to device. */
515 */
516static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf, 507static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
517 int len, struct tasklet_struct *wake_tasklet) 508 int len, struct tasklet_struct *wake_tasklet)
518{ 509{
519 struct cmdbuf_t *cb; 510 struct cmdbuf_t *cb;
520 unsigned long flags; 511 unsigned long flags;
521 512
522 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ? 513 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
523 DEBUG_TRANSCMD : DEBUG_LOCKCMD, 514 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
524 "CMD Transmit", len, buf, 0); 515 "CMD Transmit", len, buf);
525
526 if (!atomic_read(&cs->connected)) {
527 err("%s: not connected", __func__);
528 return -ENODEV;
529 }
530 516
531 if (len <= 0) 517 if (len <= 0)
532 return 0; 518 return 0;
533 519
534 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { 520 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
535 err("%s: out of memory", __func__); 521 dev_err(cs->dev, "%s: out of memory\n", __func__);
536 return -ENOMEM; 522 return -ENOMEM;
537 } 523 }
538 524
@@ -554,7 +540,10 @@ static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
554 cs->lastcmdbuf = cb; 540 cs->lastcmdbuf = cb;
555 spin_unlock_irqrestore(&cs->cmdlock, flags); 541 spin_unlock_irqrestore(&cs->cmdlock, flags);
556 542
557 tasklet_schedule(&cs->write_tasklet); 543 spin_lock_irqsave(&cs->lock, flags);
544 if (cs->connected)
545 tasklet_schedule(&cs->write_tasklet);
546 spin_unlock_irqrestore(&cs->lock, flags);
558 return len; 547 return len;
559} 548}
560 549
@@ -578,11 +567,12 @@ static int gigaset_chars_in_buffer(struct cardstate *cs)
578static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6]) 567static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
579{ 568{
580#ifdef CONFIG_GIGASET_UNDOCREQ 569#ifdef CONFIG_GIGASET_UNDOCREQ
581 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf, 0); 570 struct usb_device *udev = cs->hw.usb->udev;
571
572 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
582 memcpy(cs->hw.usb->bchars, buf, 6); 573 memcpy(cs->hw.usb->bchars, buf, 6);
583 return usb_control_msg(cs->hw.usb->udev, 574 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
584 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41, 575 0, 0, &buf, 6, 2000);
585 0, 0, &buf, 6, 2000);
586#else 576#else
587 return -EINVAL; 577 return -EINVAL;
588#endif 578#endif
@@ -604,7 +594,6 @@ static int gigaset_initbcshw(struct bc_state *bcs)
604 if (!bcs->hw.usb) 594 if (!bcs->hw.usb)
605 return 0; 595 return 0;
606 596
607 //bcs->hw.usb->trans_flg = READY_TO_TRNSMIT; /* B-Channel ready to transmit */
608 return 1; 597 return 1;
609} 598}
610 599
@@ -614,7 +603,6 @@ static void gigaset_reinitbcshw(struct bc_state *bcs)
614 603
615static void gigaset_freecshw(struct cardstate *cs) 604static void gigaset_freecshw(struct cardstate *cs)
616{ 605{
617 //FIXME
618 tasklet_kill(&cs->write_tasklet); 606 tasklet_kill(&cs->write_tasklet);
619 kfree(cs->hw.usb); 607 kfree(cs->hw.usb);
620} 608}
@@ -639,33 +627,21 @@ static int gigaset_initcshw(struct cardstate *cs)
639 //ucs->urb_cmd_out = NULL; 627 //ucs->urb_cmd_out = NULL;
640 ucs->read_urb = NULL; 628 ucs->read_urb = NULL;
641 tasklet_init(&cs->write_tasklet, 629 tasklet_init(&cs->write_tasklet,
642 &gigaset_modem_fill, (unsigned long) cs); 630 &gigaset_modem_fill, (unsigned long) cs);
643 631
644 return 1; 632 return 1;
645} 633}
646 634
647/* Writes the data of the current open skb into the modem. 635/* Send data from current skb to the device. */
648 * We have to protect against multiple calls until the
649 * callback handler () is called , due to the fact that we
650 * are just allowed to send data once to an endpoint. Therefore
651 * we using "trans_flg" to synchonize ...
652 */
653static int write_modem(struct cardstate *cs) 636static int write_modem(struct cardstate *cs)
654{ 637{
655 int ret; 638 int ret = 0;
656 int count; 639 int count;
657 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */ 640 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
658 struct usb_cardstate *ucs = cs->hw.usb; 641 struct usb_cardstate *ucs = cs->hw.usb;
659 //unsigned long flags; 642 unsigned long flags;
660
661 IFNULLRETVAL(bcs->tx_skb, -EINVAL);
662
663 dbg(DEBUG_WRITE, "len: %d...", bcs->tx_skb->len);
664 643
665 ret = -ENODEV; 644 gig_dbg(DEBUG_WRITE, "len: %d...", bcs->tx_skb->len);
666 IFNULLGOTO(ucs->bulk_out_buffer, error);
667 IFNULLGOTO(ucs->bulk_out_urb, error);
668 ret = 0;
669 645
670 if (!bcs->tx_skb->len) { 646 if (!bcs->tx_skb->len) {
671 dev_kfree_skb_any(bcs->tx_skb); 647 dev_kfree_skb_any(bcs->tx_skb);
@@ -679,40 +655,42 @@ static int write_modem(struct cardstate *cs)
679 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size); 655 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
680 memcpy(ucs->bulk_out_buffer, bcs->tx_skb->data, count); 656 memcpy(ucs->bulk_out_buffer, bcs->tx_skb->data, count);
681 skb_pull(bcs->tx_skb, count); 657 skb_pull(bcs->tx_skb, count);
682
683 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
684 usb_sndbulkpipe(ucs->udev,
685 ucs->bulk_out_endpointAddr & 0x0f),
686 ucs->bulk_out_buffer, count,
687 gigaset_write_bulk_callback, cs);
688 atomic_set(&ucs->busy, 1); 658 atomic_set(&ucs->busy, 1);
689 dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count); 659 gig_dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count);
660
661 spin_lock_irqsave(&cs->lock, flags);
662 if (cs->connected) {
663 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
664 usb_sndbulkpipe(ucs->udev,
665 ucs->bulk_out_endpointAddr & 0x0f),
666 ucs->bulk_out_buffer, count,
667 gigaset_write_bulk_callback, cs);
668 ret = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
669 } else {
670 ret = -ENODEV;
671 }
672 spin_unlock_irqrestore(&cs->lock, flags);
690 673
691 ret = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
692 if (ret) { 674 if (ret) {
693 err("could not submit urb (error %d).", -ret); 675 err("could not submit urb (error %d)\n", -ret);
694 atomic_set(&ucs->busy, 0); 676 atomic_set(&ucs->busy, 0);
695 } 677 }
678
696 if (!bcs->tx_skb->len) { 679 if (!bcs->tx_skb->len) {
697 /* skb sent completely */ 680 /* skb sent completely */
698 gigaset_skb_sent(bcs, bcs->tx_skb); //FIXME also, when ret<0? 681 gigaset_skb_sent(bcs, bcs->tx_skb); //FIXME also, when ret<0?
699 682
700 dbg(DEBUG_INTR, 683 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
701 "kfree skb (Adr: %lx)!", (unsigned long) bcs->tx_skb); 684 (unsigned long) bcs->tx_skb);
702 dev_kfree_skb_any(bcs->tx_skb); 685 dev_kfree_skb_any(bcs->tx_skb);
703 bcs->tx_skb = NULL; 686 bcs->tx_skb = NULL;
704 } 687 }
705 688
706 return ret; 689 return ret;
707error:
708 dev_kfree_skb_any(bcs->tx_skb);
709 bcs->tx_skb = NULL;
710 return ret;
711
712} 690}
713 691
714static int gigaset_probe(struct usb_interface *interface, 692static int gigaset_probe(struct usb_interface *interface,
715 const struct usb_device_id *id) 693 const struct usb_device_id *id)
716{ 694{
717 int retval; 695 int retval;
718 struct usb_device *udev = interface_to_usbdev(interface); 696 struct usb_device *udev = interface_to_usbdev(interface);
@@ -720,16 +698,14 @@ static int gigaset_probe(struct usb_interface *interface,
720 struct usb_host_interface *hostif; 698 struct usb_host_interface *hostif;
721 struct cardstate *cs = NULL; 699 struct cardstate *cs = NULL;
722 struct usb_cardstate *ucs = NULL; 700 struct usb_cardstate *ucs = NULL;
723 //struct usb_interface_descriptor *iface_desc;
724 struct usb_endpoint_descriptor *endpoint; 701 struct usb_endpoint_descriptor *endpoint;
725 //isdn_ctrl command;
726 int buffer_size; 702 int buffer_size;
727 int alt; 703 int alt;
728 //unsigned long flags;
729 704
730 info("%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)", 705 gig_dbg(DEBUG_ANY,
731 __func__, le16_to_cpu(udev->descriptor.idVendor), 706 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
732 le16_to_cpu(udev->descriptor.idProduct)); 707 __func__, le16_to_cpu(udev->descriptor.idVendor),
708 le16_to_cpu(udev->descriptor.idProduct));
733 709
734 retval = -ENODEV; //FIXME 710 retval = -ENODEV; //FIXME
735 711
@@ -744,7 +720,7 @@ static int gigaset_probe(struct usb_interface *interface,
744 ifnum = hostif->desc.bInterfaceNumber; // FIXME ? 720 ifnum = hostif->desc.bInterfaceNumber; // FIXME ?
745 721
746 if (alt != 0 || ifnum != 0) { 722 if (alt != 0 || ifnum != 0) {
747 warn("ifnum %d, alt %d", ifnum, alt); 723 dev_warn(&udev->dev, "ifnum %d, alt %d\n", ifnum, alt);
748 return -ENODEV; 724 return -ENODEV;
749 } 725 }
750 726
@@ -752,42 +728,29 @@ static int gigaset_probe(struct usb_interface *interface,
752 * 728 *
753 */ 729 */
754 if (hostif->desc.bInterfaceClass != 255) { 730 if (hostif->desc.bInterfaceClass != 255) {
755 info("%s: Device matched, but iface_desc[%d]->bInterfaceClass==%d !", 731 dev_info(&udev->dev,
756 __func__, ifnum, hostif->desc.bInterfaceClass); 732 "%s: Device matched but iface_desc[%d]->bInterfaceClass==%d!\n",
733 __func__, ifnum, hostif->desc.bInterfaceClass);
757 return -ENODEV; 734 return -ENODEV;
758 } 735 }
759 736
760 info("%s: Device matched ... !", __func__); 737 dev_info(&udev->dev, "%s: Device matched ... !\n", __func__);
761 738
762 cs = gigaset_getunassignedcs(driver); 739 cs = gigaset_getunassignedcs(driver);
763 if (!cs) { 740 if (!cs) {
764 warn("No free cardstate!"); 741 dev_warn(&udev->dev, "no free cardstate\n");
765 return -ENODEV; 742 return -ENODEV;
766 } 743 }
767 ucs = cs->hw.usb; 744 ucs = cs->hw.usb;
768 745
769#if 0 746 /* save off device structure ptrs for later use */
770 if (usb_set_configuration(udev, udev->config[0].desc.bConfigurationValue) < 0) { 747 usb_get_dev(udev);
771 warn("set_configuration failed"); 748 ucs->udev = udev;
772 goto error; 749 ucs->interface = interface;
773 } 750 cs->dev = &interface->dev;
774
775
776 if (usb_set_interface(udev, ifnum/*==0*/, alt/*==0*/) < 0) {
777 warn("usb_set_interface failed, device %d interface %d altsetting %d",
778 udev->devnum, ifnum, alt);
779 goto error;
780 }
781#endif
782 751
783 /* set up the endpoint information */ 752 /* save address of controller structure */
784 /* check out the endpoints */ 753 usb_set_intfdata(interface, cs); // dev_set_drvdata(&interface->dev, cs);
785 /* We will get 2 endpoints: One for sending commands to the device (bulk out) and one to
786 * poll messages from the device(int in).
787 * Therefore we will have an almost similiar situation as with our serial port handler.
788 * If an connection will be established, we will have to create data in/out pipes
789 * dynamically...
790 */
791 754
792 endpoint = &hostif->endpoint[0].desc; 755 endpoint = &hostif->endpoint[0].desc;
793 756
@@ -796,14 +759,14 @@ static int gigaset_probe(struct usb_interface *interface,
796 ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress; 759 ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress;
797 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); 760 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
798 if (!ucs->bulk_out_buffer) { 761 if (!ucs->bulk_out_buffer) {
799 err("Couldn't allocate bulk_out_buffer"); 762 dev_err(cs->dev, "Couldn't allocate bulk_out_buffer\n");
800 retval = -ENOMEM; 763 retval = -ENOMEM;
801 goto error; 764 goto error;
802 } 765 }
803 766
804 ucs->bulk_out_urb = usb_alloc_urb(0, SLAB_KERNEL); 767 ucs->bulk_out_urb = usb_alloc_urb(0, SLAB_KERNEL);
805 if (!ucs->bulk_out_urb) { 768 if (!ucs->bulk_out_urb) {
806 err("Couldn't allocate bulk_out_buffer"); 769 dev_err(cs->dev, "Couldn't allocate bulk_out_urb\n");
807 retval = -ENOMEM; 770 retval = -ENOMEM;
808 goto error; 771 goto error;
809 } 772 }
@@ -811,12 +774,10 @@ static int gigaset_probe(struct usb_interface *interface,
811 endpoint = &hostif->endpoint[1].desc; 774 endpoint = &hostif->endpoint[1].desc;
812 775
813 atomic_set(&ucs->busy, 0); 776 atomic_set(&ucs->busy, 0);
814 ucs->udev = udev;
815 ucs->interface = interface;
816 777
817 ucs->read_urb = usb_alloc_urb(0, SLAB_KERNEL); 778 ucs->read_urb = usb_alloc_urb(0, SLAB_KERNEL);
818 if (!ucs->read_urb) { 779 if (!ucs->read_urb) {
819 err("No free urbs available"); 780 dev_err(cs->dev, "No free urbs available\n");
820 retval = -ENOMEM; 781 retval = -ENOMEM;
821 goto error; 782 goto error;
822 } 783 }
@@ -825,38 +786,33 @@ static int gigaset_probe(struct usb_interface *interface,
825 ucs->int_in_endpointAddr = endpoint->bEndpointAddress; 786 ucs->int_in_endpointAddr = endpoint->bEndpointAddress;
826 cs->inbuf[0].rcvbuf = kmalloc(buffer_size, GFP_KERNEL); 787 cs->inbuf[0].rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
827 if (!cs->inbuf[0].rcvbuf) { 788 if (!cs->inbuf[0].rcvbuf) {
828 err("Couldn't allocate rcvbuf"); 789 dev_err(cs->dev, "Couldn't allocate rcvbuf\n");
829 retval = -ENOMEM; 790 retval = -ENOMEM;
830 goto error; 791 goto error;
831 } 792 }
832 /* Fill the interrupt urb and send it to the core */ 793 /* Fill the interrupt urb and send it to the core */
833 usb_fill_int_urb(ucs->read_urb, udev, 794 usb_fill_int_urb(ucs->read_urb, udev,
834 usb_rcvintpipe(udev, 795 usb_rcvintpipe(udev,
835 endpoint->bEndpointAddress & 0x0f), 796 endpoint->bEndpointAddress & 0x0f),
836 cs->inbuf[0].rcvbuf, buffer_size, 797 cs->inbuf[0].rcvbuf, buffer_size,
837 gigaset_read_int_callback, 798 gigaset_read_int_callback,
838 cs->inbuf + 0, endpoint->bInterval); 799 cs->inbuf + 0, endpoint->bInterval);
839 800
840 retval = usb_submit_urb(ucs->read_urb, SLAB_KERNEL); 801 retval = usb_submit_urb(ucs->read_urb, SLAB_KERNEL);
841 if (retval) { 802 if (retval) {
842 err("Could not submit URB!"); 803 dev_err(cs->dev, "Could not submit URB (error %d)\n", -retval);
843 goto error; 804 goto error;
844 } 805 }
845 806
846 /* tell common part that the device is ready */ 807 /* tell common part that the device is ready */
847 if (startmode == SM_LOCKED) 808 if (startmode == SM_LOCKED)
848 atomic_set(&cs->mstate, MS_LOCKED); 809 atomic_set(&cs->mstate, MS_LOCKED);
810
849 if (!gigaset_start(cs)) { 811 if (!gigaset_start(cs)) {
850 tasklet_kill(&cs->write_tasklet); 812 tasklet_kill(&cs->write_tasklet);
851 retval = -ENODEV; //FIXME 813 retval = -ENODEV; //FIXME
852 goto error; 814 goto error;
853 } 815 }
854
855 /* save address of controller structure */
856 usb_set_intfdata(interface, cs);
857
858 /* set up device sysfs */
859 gigaset_init_dev_sysfs(interface);
860 return 0; 816 return 0;
861 817
862error: 818error:
@@ -868,48 +824,45 @@ error:
868 kfree(cs->inbuf[0].rcvbuf); 824 kfree(cs->inbuf[0].rcvbuf);
869 if (ucs->read_urb != NULL) 825 if (ucs->read_urb != NULL)
870 usb_free_urb(ucs->read_urb); 826 usb_free_urb(ucs->read_urb);
827 usb_set_intfdata(interface, NULL);
871 ucs->read_urb = ucs->bulk_out_urb = NULL; 828 ucs->read_urb = ucs->bulk_out_urb = NULL;
872 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL; 829 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
830 usb_put_dev(ucs->udev);
831 ucs->udev = NULL;
832 ucs->interface = NULL;
873 gigaset_unassign(cs); 833 gigaset_unassign(cs);
874 return retval; 834 return retval;
875} 835}
876 836
877/**
878 * skel_disconnect
879 */
880static void gigaset_disconnect(struct usb_interface *interface) 837static void gigaset_disconnect(struct usb_interface *interface)
881{ 838{
882 struct cardstate *cs; 839 struct cardstate *cs;
883 struct usb_cardstate *ucs; 840 struct usb_cardstate *ucs;
884 841
885 cs = usb_get_intfdata(interface); 842 cs = usb_get_intfdata(interface);
886
887 /* clear device sysfs */
888 gigaset_free_dev_sysfs(interface);
889
890 usb_set_intfdata(interface, NULL);
891 ucs = cs->hw.usb; 843 ucs = cs->hw.usb;
892 usb_kill_urb(ucs->read_urb); 844 usb_kill_urb(ucs->read_urb);
893 //info("GigaSet USB device #%d will be disconnected", minor);
894 845
895 gigaset_stop(cs); 846 gigaset_stop(cs);
896 847
848 usb_set_intfdata(interface, NULL);
897 tasklet_kill(&cs->write_tasklet); 849 tasklet_kill(&cs->write_tasklet);
898 850
899 usb_kill_urb(ucs->bulk_out_urb); /* FIXME: nur, wenn noetig */ 851 usb_kill_urb(ucs->bulk_out_urb); /* FIXME: only if active? */
900 //usb_kill_urb(ucs->urb_cmd_out); /* FIXME: nur, wenn noetig */
901 852
902 kfree(ucs->bulk_out_buffer); 853 kfree(ucs->bulk_out_buffer);
903 if (ucs->bulk_out_urb != NULL) 854 if (ucs->bulk_out_urb != NULL)
904 usb_free_urb(ucs->bulk_out_urb); 855 usb_free_urb(ucs->bulk_out_urb);
905 //if(ucs->urb_cmd_out != NULL)
906 // usb_free_urb(ucs->urb_cmd_out);
907 kfree(cs->inbuf[0].rcvbuf); 856 kfree(cs->inbuf[0].rcvbuf);
908 if (ucs->read_urb != NULL) 857 if (ucs->read_urb != NULL)
909 usb_free_urb(ucs->read_urb); 858 usb_free_urb(ucs->read_urb);
910 ucs->read_urb = ucs->bulk_out_urb/*=ucs->urb_cmd_out*/=NULL; 859 ucs->read_urb = ucs->bulk_out_urb = NULL;
911 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL; 860 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
912 861
862 usb_put_dev(ucs->udev);
863 ucs->interface = NULL;
864 ucs->udev = NULL;
865 cs->dev = NULL;
913 gigaset_unassign(cs); 866 gigaset_unassign(cs);
914} 867}
915 868
@@ -942,9 +895,9 @@ static int __init usb_gigaset_init(void)
942 895
943 /* allocate memory for our driver state and intialize it */ 896 /* allocate memory for our driver state and intialize it */
944 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 897 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
945 GIGASET_MODULENAME, GIGASET_DEVNAME, 898 GIGASET_MODULENAME, GIGASET_DEVNAME,
946 GIGASET_DEVFSNAME, &ops, 899 GIGASET_DEVFSNAME, &ops,
947 THIS_MODULE)) == NULL) 900 THIS_MODULE)) == NULL)
948 goto error; 901 goto error;
949 902
950 /* allocate memory for our device state and intialize it */ 903 /* allocate memory for our device state and intialize it */
@@ -981,8 +934,8 @@ error: if (cardstate)
981static void __exit usb_gigaset_exit(void) 934static void __exit usb_gigaset_exit(void)
982{ 935{
983 gigaset_blockdriver(driver); /* => probe will fail 936 gigaset_blockdriver(driver); /* => probe will fail
984 * => no gigaset_start any more 937 * => no gigaset_start any more
985 */ 938 */
986 939
987 gigaset_shutdown(cardstate); 940 gigaset_shutdown(cardstate);
988 /* from now on, no isdn callback should be possible */ 941 /* from now on, no isdn callback should be possible */
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index 2a2b03ff096b..7bbfd85ab793 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -51,8 +51,8 @@ MODULE_LICENSE("GPL");
51 handler. 51 handler.
52*/ 52*/
53 53
54static void avmcs_config(dev_link_t *link); 54static int avmcs_config(struct pcmcia_device *link);
55static void avmcs_release(dev_link_t *link); 55static void avmcs_release(struct pcmcia_device *link);
56 56
57/* 57/*
58 The attach() and detach() entry points are used to create and destroy 58 The attach() and detach() entry points are used to create and destroy
@@ -65,10 +65,10 @@ static void avmcs_detach(struct pcmcia_device *p_dev);
65/* 65/*
66 A linked list of "instances" of the skeleton device. Each actual 66 A linked list of "instances" of the skeleton device. Each actual
67 PCMCIA card corresponds to one device instance, and is described 67 PCMCIA card corresponds to one device instance, and is described
68 by one dev_link_t structure (defined in ds.h). 68 by one struct pcmcia_device structure (defined in ds.h).
69 69
70 You may not want to use a linked list for this -- for example, the 70 You may not want to use a linked list for this -- for example, the
71 memory card driver uses an array of dev_link_t pointers, where minor 71 memory card driver uses an array of struct pcmcia_device pointers, where minor
72 device numbers are used to derive the corresponding array index. 72 device numbers are used to derive the corresponding array index.
73*/ 73*/
74 74
@@ -78,7 +78,7 @@ static void avmcs_detach(struct pcmcia_device *p_dev);
78 example, ethernet cards, modems). In other cases, there may be 78 example, ethernet cards, modems). In other cases, there may be
79 many actual or logical devices (SCSI adapters, memory cards with 79 many actual or logical devices (SCSI adapters, memory cards with
80 multiple partitions). The dev_node_t structures need to be kept 80 multiple partitions). The dev_node_t structures need to be kept
81 in a linked list starting at the 'dev' field of a dev_link_t 81 in a linked list starting at the 'dev' field of a struct pcmcia_device
82 structure. We allocate them in the card's private data structure, 82 structure. We allocate them in the card's private data structure,
83 because they generally can't be allocated dynamically. 83 because they generally can't be allocated dynamically.
84*/ 84*/
@@ -99,54 +99,38 @@ typedef struct local_info_t {
99 99
100======================================================================*/ 100======================================================================*/
101 101
102static int avmcs_attach(struct pcmcia_device *p_dev) 102static int avmcs_probe(struct pcmcia_device *p_dev)
103{ 103{
104 dev_link_t *link;
105 local_info_t *local; 104 local_info_t *local;
106 105
107 /* Initialize the dev_link_t structure */
108 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
109 if (!link)
110 goto err;
111 memset(link, 0, sizeof(struct dev_link_t));
112
113 /* The io structure describes IO port mapping */ 106 /* The io structure describes IO port mapping */
114 link->io.NumPorts1 = 16; 107 p_dev->io.NumPorts1 = 16;
115 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 108 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
116 link->io.NumPorts2 = 0; 109 p_dev->io.NumPorts2 = 0;
117 110
118 /* Interrupt setup */ 111 /* Interrupt setup */
119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 112 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
120 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 113 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
114
115 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
121 116
122 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
123
124 /* General socket configuration */ 117 /* General socket configuration */
125 link->conf.Attributes = CONF_ENABLE_IRQ; 118 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
126 link->conf.Vcc = 50; 119 p_dev->conf.IntType = INT_MEMORY_AND_IO;
127 link->conf.IntType = INT_MEMORY_AND_IO; 120 p_dev->conf.ConfigIndex = 1;
128 link->conf.ConfigIndex = 1; 121 p_dev->conf.Present = PRESENT_OPTION;
129 link->conf.Present = PRESENT_OPTION;
130 122
131 /* Allocate space for private device-specific data */ 123 /* Allocate space for private device-specific data */
132 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 124 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
133 if (!local) 125 if (!local)
134 goto err_kfree; 126 goto err;
135 memset(local, 0, sizeof(local_info_t)); 127 memset(local, 0, sizeof(local_info_t));
136 link->priv = local; 128 p_dev->priv = local;
137 129
138 link->handle = p_dev; 130 return avmcs_config(p_dev);
139 p_dev->instance = link;
140 131
141 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
142 avmcs_config(link);
143
144 return 0;
145
146 err_kfree:
147 kfree(link);
148 err: 132 err:
149 return -EINVAL; 133 return -ENOMEM;
150} /* avmcs_attach */ 134} /* avmcs_attach */
151 135
152/*====================================================================== 136/*======================================================================
@@ -158,15 +142,10 @@ static int avmcs_attach(struct pcmcia_device *p_dev)
158 142
159======================================================================*/ 143======================================================================*/
160 144
161static void avmcs_detach(struct pcmcia_device *p_dev) 145static void avmcs_detach(struct pcmcia_device *link)
162{ 146{
163 dev_link_t *link = dev_to_instance(p_dev);
164
165 if (link->state & DEV_CONFIG)
166 avmcs_release(link); 147 avmcs_release(link);
167 148 kfree(link->priv);
168 kfree(link->priv);
169 kfree(link);
170} /* avmcs_detach */ 149} /* avmcs_detach */
171 150
172/*====================================================================== 151/*======================================================================
@@ -177,7 +156,7 @@ static void avmcs_detach(struct pcmcia_device *p_dev)
177 156
178======================================================================*/ 157======================================================================*/
179 158
180static int get_tuple(client_handle_t handle, tuple_t *tuple, 159static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
181 cisparse_t *parse) 160 cisparse_t *parse)
182{ 161{
183 int i = pcmcia_get_tuple_data(handle, tuple); 162 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -185,7 +164,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
185 return pcmcia_parse_tuple(handle, tuple, parse); 164 return pcmcia_parse_tuple(handle, tuple, parse);
186} 165}
187 166
188static int first_tuple(client_handle_t handle, tuple_t *tuple, 167static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
189 cisparse_t *parse) 168 cisparse_t *parse)
190{ 169{
191 int i = pcmcia_get_first_tuple(handle, tuple); 170 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -193,7 +172,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
193 return get_tuple(handle, tuple, parse); 172 return get_tuple(handle, tuple, parse);
194} 173}
195 174
196static int next_tuple(client_handle_t handle, tuple_t *tuple, 175static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
197 cisparse_t *parse) 176 cisparse_t *parse)
198{ 177{
199 int i = pcmcia_get_next_tuple(handle, tuple); 178 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -201,9 +180,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
201 return get_tuple(handle, tuple, parse); 180 return get_tuple(handle, tuple, parse);
202} 181}
203 182
204static void avmcs_config(dev_link_t *link) 183static int avmcs_config(struct pcmcia_device *link)
205{ 184{
206 client_handle_t handle;
207 tuple_t tuple; 185 tuple_t tuple;
208 cisparse_t parse; 186 cisparse_t parse;
209 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 187 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
@@ -213,8 +191,7 @@ static void avmcs_config(dev_link_t *link)
213 char devname[128]; 191 char devname[128];
214 int cardtype; 192 int cardtype;
215 int (*addcard)(unsigned int port, unsigned irq); 193 int (*addcard)(unsigned int port, unsigned irq);
216 194
217 handle = link->handle;
218 dev = link->priv; 195 dev = link->priv;
219 196
220 /* 197 /*
@@ -223,25 +200,21 @@ static void avmcs_config(dev_link_t *link)
223 */ 200 */
224 do { 201 do {
225 tuple.DesiredTuple = CISTPL_CONFIG; 202 tuple.DesiredTuple = CISTPL_CONFIG;
226 i = pcmcia_get_first_tuple(handle, &tuple); 203 i = pcmcia_get_first_tuple(link, &tuple);
227 if (i != CS_SUCCESS) break; 204 if (i != CS_SUCCESS) break;
228 tuple.TupleData = buf; 205 tuple.TupleData = buf;
229 tuple.TupleDataMax = 64; 206 tuple.TupleDataMax = 64;
230 tuple.TupleOffset = 0; 207 tuple.TupleOffset = 0;
231 i = pcmcia_get_tuple_data(handle, &tuple); 208 i = pcmcia_get_tuple_data(link, &tuple);
232 if (i != CS_SUCCESS) break; 209 if (i != CS_SUCCESS) break;
233 i = pcmcia_parse_tuple(handle, &tuple, &parse); 210 i = pcmcia_parse_tuple(link, &tuple, &parse);
234 if (i != CS_SUCCESS) break; 211 if (i != CS_SUCCESS) break;
235 link->conf.ConfigBase = parse.config.base; 212 link->conf.ConfigBase = parse.config.base;
236 } while (0); 213 } while (0);
237 if (i != CS_SUCCESS) { 214 if (i != CS_SUCCESS) {
238 cs_error(link->handle, ParseTuple, i); 215 cs_error(link, ParseTuple, i);
239 link->state &= ~DEV_CONFIG_PENDING; 216 return -ENODEV;
240 return;
241 } 217 }
242
243 /* Configure card */
244 link->state |= DEV_CONFIG;
245 218
246 do { 219 do {
247 220
@@ -252,7 +225,7 @@ static void avmcs_config(dev_link_t *link)
252 tuple.DesiredTuple = CISTPL_VERS_1; 225 tuple.DesiredTuple = CISTPL_VERS_1;
253 226
254 devname[0] = 0; 227 devname[0] = 0;
255 if( !first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 1 ) { 228 if( !first_tuple(link, &tuple, &parse) && parse.version_1.ns > 1 ) {
256 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1], 229 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1],
257 sizeof(devname)); 230 sizeof(devname));
258 } 231 }
@@ -263,7 +236,7 @@ static void avmcs_config(dev_link_t *link)
263 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 236 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
264 tuple.Attributes = 0; 237 tuple.Attributes = 0;
265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 238 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
266 i = first_tuple(handle, &tuple, &parse); 239 i = first_tuple(link, &tuple, &parse);
267 while (i == CS_SUCCESS) { 240 while (i == CS_SUCCESS) {
268 if (cf->io.nwin > 0) { 241 if (cf->io.nwin > 0) {
269 link->conf.ConfigIndex = cf->index; 242 link->conf.ConfigIndex = cf->index;
@@ -273,36 +246,36 @@ static void avmcs_config(dev_link_t *link)
273 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n", 246 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n",
274 link->io.BasePort1, 247 link->io.BasePort1,
275 link->io.BasePort1+link->io.NumPorts1-1); 248 link->io.BasePort1+link->io.NumPorts1-1);
276 i = pcmcia_request_io(link->handle, &link->io); 249 i = pcmcia_request_io(link, &link->io);
277 if (i == CS_SUCCESS) goto found_port; 250 if (i == CS_SUCCESS) goto found_port;
278 } 251 }
279 i = next_tuple(handle, &tuple, &parse); 252 i = next_tuple(link, &tuple, &parse);
280 } 253 }
281 254
282found_port: 255found_port:
283 if (i != CS_SUCCESS) { 256 if (i != CS_SUCCESS) {
284 cs_error(link->handle, RequestIO, i); 257 cs_error(link, RequestIO, i);
285 break; 258 break;
286 } 259 }
287 260
288 /* 261 /*
289 * allocate an interrupt line 262 * allocate an interrupt line
290 */ 263 */
291 i = pcmcia_request_irq(link->handle, &link->irq); 264 i = pcmcia_request_irq(link, &link->irq);
292 if (i != CS_SUCCESS) { 265 if (i != CS_SUCCESS) {
293 cs_error(link->handle, RequestIRQ, i); 266 cs_error(link, RequestIRQ, i);
294 pcmcia_release_io(link->handle, &link->io); 267 /* undo */
268 pcmcia_disable_device(link);
295 break; 269 break;
296 } 270 }
297 271
298 /* 272 /*
299 * configure the PCMCIA socket 273 * configure the PCMCIA socket
300 */ 274 */
301 i = pcmcia_request_configuration(link->handle, &link->conf); 275 i = pcmcia_request_configuration(link, &link->conf);
302 if (i != CS_SUCCESS) { 276 if (i != CS_SUCCESS) {
303 cs_error(link->handle, RequestConfiguration, i); 277 cs_error(link, RequestConfiguration, i);
304 pcmcia_release_io(link->handle, &link->io); 278 pcmcia_disable_device(link);
305 pcmcia_release_irq(link->handle, &link->irq);
306 break; 279 break;
307 } 280 }
308 281
@@ -331,13 +304,12 @@ found_port:
331 304
332 dev->node.major = 64; 305 dev->node.major = 64;
333 dev->node.minor = 0; 306 dev->node.minor = 0;
334 link->dev = &dev->node; 307 link->dev_node = &dev->node;
335 308
336 link->state &= ~DEV_CONFIG_PENDING;
337 /* If any step failed, release any partially configured state */ 309 /* If any step failed, release any partially configured state */
338 if (i != 0) { 310 if (i != 0) {
339 avmcs_release(link); 311 avmcs_release(link);
340 return; 312 return -ENODEV;
341 } 313 }
342 314
343 315
@@ -351,9 +323,10 @@ found_port:
351 printk(KERN_ERR "avm_cs: failed to add AVM-%s-Controller at i/o %#x, irq %d\n", 323 printk(KERN_ERR "avm_cs: failed to add AVM-%s-Controller at i/o %#x, irq %d\n",
352 dev->node.dev_name, link->io.BasePort1, link->irq.AssignedIRQ); 324 dev->node.dev_name, link->io.BasePort1, link->irq.AssignedIRQ);
353 avmcs_release(link); 325 avmcs_release(link);
354 return; 326 return -ENODEV;
355 } 327 }
356 dev->node.minor = i; 328 dev->node.minor = i;
329 return 0;
357 330
358} /* avmcs_config */ 331} /* avmcs_config */
359 332
@@ -365,56 +338,12 @@ found_port:
365 338
366======================================================================*/ 339======================================================================*/
367 340
368static void avmcs_release(dev_link_t *link) 341static void avmcs_release(struct pcmcia_device *link)
369{ 342{
370 b1pcmcia_delcard(link->io.BasePort1, link->irq.AssignedIRQ); 343 b1pcmcia_delcard(link->io.BasePort1, link->irq.AssignedIRQ);
371 344 pcmcia_disable_device(link);
372 /* Unlink the device chain */
373 link->dev = NULL;
374
375 /* Don't bother checking to see if these succeed or not */
376 pcmcia_release_configuration(link->handle);
377 pcmcia_release_io(link->handle, &link->io);
378 pcmcia_release_irq(link->handle, &link->irq);
379 link->state &= ~DEV_CONFIG;
380} /* avmcs_release */ 345} /* avmcs_release */
381 346
382static int avmcs_suspend(struct pcmcia_device *dev)
383{
384 dev_link_t *link = dev_to_instance(dev);
385
386 link->state |= DEV_SUSPEND;
387 if (link->state & DEV_CONFIG)
388 pcmcia_release_configuration(link->handle);
389
390 return 0;
391}
392
393static int avmcs_resume(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state &= ~DEV_SUSPEND;
398 if (link->state & DEV_CONFIG)
399 pcmcia_request_configuration(link->handle, &link->conf);
400
401 return 0;
402}
403
404/*======================================================================
405
406 The card status event handler. Mostly, this schedules other
407 stuff to run after an event is received. A CARD_REMOVAL event
408 also sets some flags to discourage the net drivers from trying
409 to talk to the card any more.
410
411 When a CARD_REMOVAL event is received, we immediately set a flag
412 to block future accesses to this device. All the functions that
413 actually access the device should check this flag to make sure
414 the card is still present.
415
416======================================================================*/
417
418 347
419static struct pcmcia_device_id avmcs_ids[] = { 348static struct pcmcia_device_id avmcs_ids[] = {
420 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335), 349 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
@@ -429,11 +358,9 @@ static struct pcmcia_driver avmcs_driver = {
429 .drv = { 358 .drv = {
430 .name = "avm_cs", 359 .name = "avm_cs",
431 }, 360 },
432 .probe = avmcs_attach, 361 .probe = avmcs_probe,
433 .remove = avmcs_detach, 362 .remove = avmcs_detach,
434 .id_table = avmcs_ids, 363 .id_table = avmcs_ids,
435 .suspend= avmcs_suspend,
436 .resume = avmcs_resume,
437}; 364};
438 365
439static int __init avmcs_init(void) 366static int __init avmcs_init(void)
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 969da40c4248..ac28e3278ad9 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -67,8 +67,8 @@ module_param(isdnprot, int, 0);
67 handler. 67 handler.
68*/ 68*/
69 69
70static void avma1cs_config(dev_link_t *link); 70static int avma1cs_config(struct pcmcia_device *link);
71static void avma1cs_release(dev_link_t *link); 71static void avma1cs_release(struct pcmcia_device *link);
72 72
73/* 73/*
74 The attach() and detach() entry points are used to create and destroy 74 The attach() and detach() entry points are used to create and destroy
@@ -82,10 +82,10 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
82/* 82/*
83 A linked list of "instances" of the skeleton device. Each actual 83 A linked list of "instances" of the skeleton device. Each actual
84 PCMCIA card corresponds to one device instance, and is described 84 PCMCIA card corresponds to one device instance, and is described
85 by one dev_link_t structure (defined in ds.h). 85 by one struct pcmcia_device structure (defined in ds.h).
86 86
87 You may not want to use a linked list for this -- for example, the 87 You may not want to use a linked list for this -- for example, the
88 memory card driver uses an array of dev_link_t pointers, where minor 88 memory card driver uses an array of struct pcmcia_device pointers, where minor
89 device numbers are used to derive the corresponding array index. 89 device numbers are used to derive the corresponding array index.
90*/ 90*/
91 91
@@ -95,7 +95,7 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
95 example, ethernet cards, modems). In other cases, there may be 95 example, ethernet cards, modems). In other cases, there may be
96 many actual or logical devices (SCSI adapters, memory cards with 96 many actual or logical devices (SCSI adapters, memory cards with
97 multiple partitions). The dev_node_t structures need to be kept 97 multiple partitions). The dev_node_t structures need to be kept
98 in a linked list starting at the 'dev' field of a dev_link_t 98 in a linked list starting at the 'dev' field of a struct pcmcia_device
99 structure. We allocate them in the card's private data structure, 99 structure. We allocate them in the card's private data structure,
100 because they generally can't be allocated dynamically. 100 because they generally can't be allocated dynamically.
101*/ 101*/
@@ -116,55 +116,40 @@ typedef struct local_info_t {
116 116
117======================================================================*/ 117======================================================================*/
118 118
119static int avma1cs_attach(struct pcmcia_device *p_dev) 119static int avma1cs_probe(struct pcmcia_device *p_dev)
120{ 120{
121 dev_link_t *link;
122 local_info_t *local; 121 local_info_t *local;
123 122
124 DEBUG(0, "avma1cs_attach()\n"); 123 DEBUG(0, "avma1cs_attach()\n");
125 124
126 /* Initialize the dev_link_t structure */
127 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
128 if (!link)
129 return -ENOMEM;
130 memset(link, 0, sizeof(struct dev_link_t));
131
132 /* Allocate space for private device-specific data */ 125 /* Allocate space for private device-specific data */
133 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 126 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
134 if (!local) { 127 if (!local)
135 kfree(link);
136 return -ENOMEM; 128 return -ENOMEM;
137 } 129
138 memset(local, 0, sizeof(local_info_t)); 130 memset(local, 0, sizeof(local_info_t));
139 link->priv = local; 131 p_dev->priv = local;
140 132
141 /* The io structure describes IO port mapping */ 133 /* The io structure describes IO port mapping */
142 link->io.NumPorts1 = 16; 134 p_dev->io.NumPorts1 = 16;
143 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 135 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
144 link->io.NumPorts2 = 16; 136 p_dev->io.NumPorts2 = 16;
145 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; 137 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
146 link->io.IOAddrLines = 5; 138 p_dev->io.IOAddrLines = 5;
147 139
148 /* Interrupt setup */ 140 /* Interrupt setup */
149 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 141 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
150 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 142 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
151 143
152 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 144 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
153 145
154 /* General socket configuration */ 146 /* General socket configuration */
155 link->conf.Attributes = CONF_ENABLE_IRQ; 147 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
156 link->conf.Vcc = 50; 148 p_dev->conf.IntType = INT_MEMORY_AND_IO;
157 link->conf.IntType = INT_MEMORY_AND_IO; 149 p_dev->conf.ConfigIndex = 1;
158 link->conf.ConfigIndex = 1; 150 p_dev->conf.Present = PRESENT_OPTION;
159 link->conf.Present = PRESENT_OPTION;
160 151
161 link->handle = p_dev; 152 return avma1cs_config(p_dev);
162 p_dev->instance = link;
163
164 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
165 avma1cs_config(link);
166
167 return 0;
168} /* avma1cs_attach */ 153} /* avma1cs_attach */
169 154
170/*====================================================================== 155/*======================================================================
@@ -176,17 +161,11 @@ static int avma1cs_attach(struct pcmcia_device *p_dev)
176 161
177======================================================================*/ 162======================================================================*/
178 163
179static void avma1cs_detach(struct pcmcia_device *p_dev) 164static void avma1cs_detach(struct pcmcia_device *link)
180{ 165{
181 dev_link_t *link = dev_to_instance(p_dev); 166 DEBUG(0, "avma1cs_detach(0x%p)\n", link);
182 167 avma1cs_release(link);
183 DEBUG(0, "avma1cs_detach(0x%p)\n", link); 168 kfree(link->priv);
184
185 if (link->state & DEV_CONFIG)
186 avma1cs_release(link);
187
188 kfree(link->priv);
189 kfree(link);
190} /* avma1cs_detach */ 169} /* avma1cs_detach */
191 170
192/*====================================================================== 171/*======================================================================
@@ -197,7 +176,7 @@ static void avma1cs_detach(struct pcmcia_device *p_dev)
197 176
198======================================================================*/ 177======================================================================*/
199 178
200static int get_tuple(client_handle_t handle, tuple_t *tuple, 179static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
201 cisparse_t *parse) 180 cisparse_t *parse)
202{ 181{
203 int i = pcmcia_get_tuple_data(handle, tuple); 182 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -205,7 +184,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
205 return pcmcia_parse_tuple(handle, tuple, parse); 184 return pcmcia_parse_tuple(handle, tuple, parse);
206} 185}
207 186
208static int first_tuple(client_handle_t handle, tuple_t *tuple, 187static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
209 cisparse_t *parse) 188 cisparse_t *parse)
210{ 189{
211 int i = pcmcia_get_first_tuple(handle, tuple); 190 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -213,7 +192,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
213 return get_tuple(handle, tuple, parse); 192 return get_tuple(handle, tuple, parse);
214} 193}
215 194
216static int next_tuple(client_handle_t handle, tuple_t *tuple, 195static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
217 cisparse_t *parse) 196 cisparse_t *parse)
218{ 197{
219 int i = pcmcia_get_next_tuple(handle, tuple); 198 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -221,9 +200,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
221 return get_tuple(handle, tuple, parse); 200 return get_tuple(handle, tuple, parse);
222} 201}
223 202
224static void avma1cs_config(dev_link_t *link) 203static int avma1cs_config(struct pcmcia_device *link)
225{ 204{
226 client_handle_t handle;
227 tuple_t tuple; 205 tuple_t tuple;
228 cisparse_t parse; 206 cisparse_t parse;
229 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 207 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
@@ -233,8 +211,7 @@ static void avma1cs_config(dev_link_t *link)
233 char devname[128]; 211 char devname[128];
234 IsdnCard_t icard; 212 IsdnCard_t icard;
235 int busy = 0; 213 int busy = 0;
236 214
237 handle = link->handle;
238 dev = link->priv; 215 dev = link->priv;
239 216
240 DEBUG(0, "avma1cs_config(0x%p)\n", link); 217 DEBUG(0, "avma1cs_config(0x%p)\n", link);
@@ -245,25 +222,21 @@ static void avma1cs_config(dev_link_t *link)
245 */ 222 */
246 do { 223 do {
247 tuple.DesiredTuple = CISTPL_CONFIG; 224 tuple.DesiredTuple = CISTPL_CONFIG;
248 i = pcmcia_get_first_tuple(handle, &tuple); 225 i = pcmcia_get_first_tuple(link, &tuple);
249 if (i != CS_SUCCESS) break; 226 if (i != CS_SUCCESS) break;
250 tuple.TupleData = buf; 227 tuple.TupleData = buf;
251 tuple.TupleDataMax = 64; 228 tuple.TupleDataMax = 64;
252 tuple.TupleOffset = 0; 229 tuple.TupleOffset = 0;
253 i = pcmcia_get_tuple_data(handle, &tuple); 230 i = pcmcia_get_tuple_data(link, &tuple);
254 if (i != CS_SUCCESS) break; 231 if (i != CS_SUCCESS) break;
255 i = pcmcia_parse_tuple(handle, &tuple, &parse); 232 i = pcmcia_parse_tuple(link, &tuple, &parse);
256 if (i != CS_SUCCESS) break; 233 if (i != CS_SUCCESS) break;
257 link->conf.ConfigBase = parse.config.base; 234 link->conf.ConfigBase = parse.config.base;
258 } while (0); 235 } while (0);
259 if (i != CS_SUCCESS) { 236 if (i != CS_SUCCESS) {
260 cs_error(link->handle, ParseTuple, i); 237 cs_error(link, ParseTuple, i);
261 link->state &= ~DEV_CONFIG_PENDING; 238 return -ENODEV;
262 return;
263 } 239 }
264
265 /* Configure card */
266 link->state |= DEV_CONFIG;
267 240
268 do { 241 do {
269 242
@@ -274,7 +247,7 @@ static void avma1cs_config(dev_link_t *link)
274 tuple.DesiredTuple = CISTPL_VERS_1; 247 tuple.DesiredTuple = CISTPL_VERS_1;
275 248
276 devname[0] = 0; 249 devname[0] = 0;
277 if( !first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 1 ) { 250 if( !first_tuple(link, &tuple, &parse) && parse.version_1.ns > 1 ) {
278 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1], 251 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1],
279 sizeof(devname)); 252 sizeof(devname));
280 } 253 }
@@ -285,7 +258,7 @@ static void avma1cs_config(dev_link_t *link)
285 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 258 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
286 tuple.Attributes = 0; 259 tuple.Attributes = 0;
287 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 260 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
288 i = first_tuple(handle, &tuple, &parse); 261 i = first_tuple(link, &tuple, &parse);
289 while (i == CS_SUCCESS) { 262 while (i == CS_SUCCESS) {
290 if (cf->io.nwin > 0) { 263 if (cf->io.nwin > 0) {
291 link->conf.ConfigIndex = cf->index; 264 link->conf.ConfigIndex = cf->index;
@@ -295,36 +268,36 @@ static void avma1cs_config(dev_link_t *link)
295 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n", 268 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
296 link->io.BasePort1, 269 link->io.BasePort1,
297 link->io.BasePort1+link->io.NumPorts1 - 1); 270 link->io.BasePort1+link->io.NumPorts1 - 1);
298 i = pcmcia_request_io(link->handle, &link->io); 271 i = pcmcia_request_io(link, &link->io);
299 if (i == CS_SUCCESS) goto found_port; 272 if (i == CS_SUCCESS) goto found_port;
300 } 273 }
301 i = next_tuple(handle, &tuple, &parse); 274 i = next_tuple(link, &tuple, &parse);
302 } 275 }
303 276
304found_port: 277found_port:
305 if (i != CS_SUCCESS) { 278 if (i != CS_SUCCESS) {
306 cs_error(link->handle, RequestIO, i); 279 cs_error(link, RequestIO, i);
307 break; 280 break;
308 } 281 }
309 282
310 /* 283 /*
311 * allocate an interrupt line 284 * allocate an interrupt line
312 */ 285 */
313 i = pcmcia_request_irq(link->handle, &link->irq); 286 i = pcmcia_request_irq(link, &link->irq);
314 if (i != CS_SUCCESS) { 287 if (i != CS_SUCCESS) {
315 cs_error(link->handle, RequestIRQ, i); 288 cs_error(link, RequestIRQ, i);
316 pcmcia_release_io(link->handle, &link->io); 289 /* undo */
290 pcmcia_disable_device(link);
317 break; 291 break;
318 } 292 }
319 293
320 /* 294 /*
321 * configure the PCMCIA socket 295 * configure the PCMCIA socket
322 */ 296 */
323 i = pcmcia_request_configuration(link->handle, &link->conf); 297 i = pcmcia_request_configuration(link, &link->conf);
324 if (i != CS_SUCCESS) { 298 if (i != CS_SUCCESS) {
325 cs_error(link->handle, RequestConfiguration, i); 299 cs_error(link, RequestConfiguration, i);
326 pcmcia_release_io(link->handle, &link->io); 300 pcmcia_disable_device(link);
327 pcmcia_release_irq(link->handle, &link->irq);
328 break; 301 break;
329 } 302 }
330 303
@@ -336,13 +309,12 @@ found_port:
336 strcpy(dev->node.dev_name, "A1"); 309 strcpy(dev->node.dev_name, "A1");
337 dev->node.major = 45; 310 dev->node.major = 45;
338 dev->node.minor = 0; 311 dev->node.minor = 0;
339 link->dev = &dev->node; 312 link->dev_node = &dev->node;
340 313
341 link->state &= ~DEV_CONFIG_PENDING;
342 /* If any step failed, release any partially configured state */ 314 /* If any step failed, release any partially configured state */
343 if (i != 0) { 315 if (i != 0) {
344 avma1cs_release(link); 316 avma1cs_release(link);
345 return; 317 return -ENODEV;
346 } 318 }
347 319
348 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n", 320 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
@@ -357,10 +329,11 @@ found_port:
357 if (i < 0) { 329 if (i < 0) {
358 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1); 330 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1);
359 avma1cs_release(link); 331 avma1cs_release(link);
360 return; 332 return -ENODEV;
361 } 333 }
362 dev->node.minor = i; 334 dev->node.minor = i;
363 335
336 return 0;
364} /* avma1cs_config */ 337} /* avma1cs_config */
365 338
366/*====================================================================== 339/*======================================================================
@@ -371,47 +344,18 @@ found_port:
371 344
372======================================================================*/ 345======================================================================*/
373 346
374static void avma1cs_release(dev_link_t *link) 347static void avma1cs_release(struct pcmcia_device *link)
375{ 348{
376 local_info_t *local = link->priv; 349 local_info_t *local = link->priv;
377 350
378 DEBUG(0, "avma1cs_release(0x%p)\n", link); 351 DEBUG(0, "avma1cs_release(0x%p)\n", link);
379 352
380 /* no unregister function with hisax */ 353 /* now unregister function with hisax */
381 HiSax_closecard(local->node.minor); 354 HiSax_closecard(local->node.minor);
382 355
383 /* Unlink the device chain */ 356 pcmcia_disable_device(link);
384 link->dev = NULL;
385
386 /* Don't bother checking to see if these succeed or not */
387 pcmcia_release_configuration(link->handle);
388 pcmcia_release_io(link->handle, &link->io);
389 pcmcia_release_irq(link->handle, &link->irq);
390 link->state &= ~DEV_CONFIG;
391} /* avma1cs_release */ 357} /* avma1cs_release */
392 358
393static int avma1cs_suspend(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state |= DEV_SUSPEND;
398 if (link->state & DEV_CONFIG)
399 pcmcia_release_configuration(link->handle);
400
401 return 0;
402}
403
404static int avma1cs_resume(struct pcmcia_device *dev)
405{
406 dev_link_t *link = dev_to_instance(dev);
407
408 link->state &= ~DEV_SUSPEND;
409 if (link->state & DEV_CONFIG)
410 pcmcia_request_configuration(link->handle, &link->conf);
411
412 return 0;
413}
414
415 359
416static struct pcmcia_device_id avma1cs_ids[] = { 360static struct pcmcia_device_id avma1cs_ids[] = {
417 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), 361 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
@@ -425,13 +369,11 @@ static struct pcmcia_driver avma1cs_driver = {
425 .drv = { 369 .drv = {
426 .name = "avma1_cs", 370 .name = "avma1_cs",
427 }, 371 },
428 .probe = avma1cs_attach, 372 .probe = avma1cs_probe,
429 .remove = avma1cs_detach, 373 .remove = avma1cs_detach,
430 .id_table = avma1cs_ids, 374 .id_table = avma1cs_ids,
431 .suspend = avma1cs_suspend,
432 .resume = avma1cs_resume,
433}; 375};
434 376
435/*====================================================================*/ 377/*====================================================================*/
436 378
437static int __init init_avma1_cs(void) 379static int __init init_avma1_cs(void)
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index 062fb8f0739f..e18e75be8ed3 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -94,8 +94,8 @@ module_param(protocol, int, 0);
94 handler. 94 handler.
95*/ 95*/
96 96
97static void elsa_cs_config(dev_link_t *link); 97static int elsa_cs_config(struct pcmcia_device *link);
98static void elsa_cs_release(dev_link_t *link); 98static void elsa_cs_release(struct pcmcia_device *link);
99 99
100/* 100/*
101 The attach() and detach() entry points are used to create and destroy 101 The attach() and detach() entry points are used to create and destroy
@@ -111,7 +111,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev);
111 example, ethernet cards, modems). In other cases, there may be 111 example, ethernet cards, modems). In other cases, there may be
112 many actual or logical devices (SCSI adapters, memory cards with 112 many actual or logical devices (SCSI adapters, memory cards with
113 multiple partitions). The dev_node_t structures need to be kept 113 multiple partitions). The dev_node_t structures need to be kept
114 in a linked list starting at the 'dev' field of a dev_link_t 114 in a linked list starting at the 'dev' field of a struct pcmcia_device
115 structure. We allocate them in the card's private data structure, 115 structure. We allocate them in the card's private data structure,
116 because they generally shouldn't be allocated dynamically. 116 because they generally shouldn't be allocated dynamically.
117 In this case, we also provide a flag to indicate if a device is 117 In this case, we also provide a flag to indicate if a device is
@@ -121,7 +121,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev);
121*/ 121*/
122 122
123typedef struct local_info_t { 123typedef struct local_info_t {
124 dev_link_t link; 124 struct pcmcia_device *p_dev;
125 dev_node_t node; 125 dev_node_t node;
126 int busy; 126 int busy;
127 int cardnr; 127 int cardnr;
@@ -139,9 +139,8 @@ typedef struct local_info_t {
139 139
140======================================================================*/ 140======================================================================*/
141 141
142static int elsa_cs_attach(struct pcmcia_device *p_dev) 142static int elsa_cs_probe(struct pcmcia_device *link)
143{ 143{
144 dev_link_t *link;
145 local_info_t *local; 144 local_info_t *local;
146 145
147 DEBUG(0, "elsa_cs_attach()\n"); 146 DEBUG(0, "elsa_cs_attach()\n");
@@ -150,8 +149,11 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
150 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 149 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
151 if (!local) return -ENOMEM; 150 if (!local) return -ENOMEM;
152 memset(local, 0, sizeof(local_info_t)); 151 memset(local, 0, sizeof(local_info_t));
152
153 local->p_dev = link;
154 link->priv = local;
155
153 local->cardnr = -1; 156 local->cardnr = -1;
154 link = &local->link; link->priv = local;
155 157
156 /* Interrupt setup */ 158 /* Interrupt setup */
157 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 159 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
@@ -170,16 +172,9 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
170 link->io.IOAddrLines = 3; 172 link->io.IOAddrLines = 3;
171 173
172 link->conf.Attributes = CONF_ENABLE_IRQ; 174 link->conf.Attributes = CONF_ENABLE_IRQ;
173 link->conf.Vcc = 50;
174 link->conf.IntType = INT_MEMORY_AND_IO; 175 link->conf.IntType = INT_MEMORY_AND_IO;
175 176
176 link->handle = p_dev; 177 return elsa_cs_config(link);
177 p_dev->instance = link;
178
179 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
180 elsa_cs_config(link);
181
182 return 0;
183} /* elsa_cs_attach */ 178} /* elsa_cs_attach */
184 179
185/*====================================================================== 180/*======================================================================
@@ -191,20 +186,16 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
191 186
192======================================================================*/ 187======================================================================*/
193 188
194static void elsa_cs_detach(struct pcmcia_device *p_dev) 189static void elsa_cs_detach(struct pcmcia_device *link)
195{ 190{
196 dev_link_t *link = dev_to_instance(p_dev); 191 local_info_t *info = link->priv;
197 local_info_t *info = link->priv;
198 192
199 DEBUG(0, "elsa_cs_detach(0x%p)\n", link); 193 DEBUG(0, "elsa_cs_detach(0x%p)\n", link);
200 194
201 if (link->state & DEV_CONFIG) { 195 info->busy = 1;
202 info->busy = 1; 196 elsa_cs_release(link);
203 elsa_cs_release(link);
204 }
205
206 kfree(info);
207 197
198 kfree(info);
208} /* elsa_cs_detach */ 199} /* elsa_cs_detach */
209 200
210/*====================================================================== 201/*======================================================================
@@ -214,7 +205,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev)
214 device available to the system. 205 device available to the system.
215 206
216======================================================================*/ 207======================================================================*/
217static int get_tuple(client_handle_t handle, tuple_t *tuple, 208static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
218 cisparse_t *parse) 209 cisparse_t *parse)
219{ 210{
220 int i = pcmcia_get_tuple_data(handle, tuple); 211 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -222,7 +213,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
222 return pcmcia_parse_tuple(handle, tuple, parse); 213 return pcmcia_parse_tuple(handle, tuple, parse);
223} 214}
224 215
225static int first_tuple(client_handle_t handle, tuple_t *tuple, 216static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
226 cisparse_t *parse) 217 cisparse_t *parse)
227{ 218{
228 int i = pcmcia_get_first_tuple(handle, tuple); 219 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -230,7 +221,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
230 return get_tuple(handle, tuple, parse); 221 return get_tuple(handle, tuple, parse);
231} 222}
232 223
233static int next_tuple(client_handle_t handle, tuple_t *tuple, 224static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
234 cisparse_t *parse) 225 cisparse_t *parse)
235{ 226{
236 int i = pcmcia_get_next_tuple(handle, tuple); 227 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -238,9 +229,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
238 return get_tuple(handle, tuple, parse); 229 return get_tuple(handle, tuple, parse);
239} 230}
240 231
241static void elsa_cs_config(dev_link_t *link) 232static int elsa_cs_config(struct pcmcia_device *link)
242{ 233{
243 client_handle_t handle;
244 tuple_t tuple; 234 tuple_t tuple;
245 cisparse_t parse; 235 cisparse_t parse;
246 local_info_t *dev; 236 local_info_t *dev;
@@ -250,7 +240,6 @@ static void elsa_cs_config(dev_link_t *link)
250 IsdnCard_t icard; 240 IsdnCard_t icard;
251 241
252 DEBUG(0, "elsa_config(0x%p)\n", link); 242 DEBUG(0, "elsa_config(0x%p)\n", link);
253 handle = link->handle;
254 dev = link->priv; 243 dev = link->priv;
255 244
256 /* 245 /*
@@ -262,7 +251,7 @@ static void elsa_cs_config(dev_link_t *link)
262 tuple.TupleDataMax = 255; 251 tuple.TupleDataMax = 255;
263 tuple.TupleOffset = 0; 252 tuple.TupleOffset = 0;
264 tuple.Attributes = 0; 253 tuple.Attributes = 0;
265 i = first_tuple(handle, &tuple, &parse); 254 i = first_tuple(link, &tuple, &parse);
266 if (i != CS_SUCCESS) { 255 if (i != CS_SUCCESS) {
267 last_fn = ParseTuple; 256 last_fn = ParseTuple;
268 goto cs_failed; 257 goto cs_failed;
@@ -270,32 +259,29 @@ static void elsa_cs_config(dev_link_t *link)
270 link->conf.ConfigBase = parse.config.base; 259 link->conf.ConfigBase = parse.config.base;
271 link->conf.Present = parse.config.rmask[0]; 260 link->conf.Present = parse.config.rmask[0];
272 261
273 /* Configure card */
274 link->state |= DEV_CONFIG;
275
276 tuple.TupleData = (cisdata_t *)buf; 262 tuple.TupleData = (cisdata_t *)buf;
277 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 263 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
278 tuple.Attributes = 0; 264 tuple.Attributes = 0;
279 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
280 i = first_tuple(handle, &tuple, &parse); 266 i = first_tuple(link, &tuple, &parse);
281 while (i == CS_SUCCESS) { 267 while (i == CS_SUCCESS) {
282 if ( (cf->io.nwin > 0) && cf->io.win[0].base) { 268 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
283 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n"); 269 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
284 link->conf.ConfigIndex = cf->index; 270 link->conf.ConfigIndex = cf->index;
285 link->io.BasePort1 = cf->io.win[0].base; 271 link->io.BasePort1 = cf->io.win[0].base;
286 i = pcmcia_request_io(link->handle, &link->io); 272 i = pcmcia_request_io(link, &link->io);
287 if (i == CS_SUCCESS) break; 273 if (i == CS_SUCCESS) break;
288 } else { 274 } else {
289 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n"); 275 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
290 link->conf.ConfigIndex = cf->index; 276 link->conf.ConfigIndex = cf->index;
291 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) { 277 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
292 link->io.BasePort1 = j; 278 link->io.BasePort1 = j;
293 i = pcmcia_request_io(link->handle, &link->io); 279 i = pcmcia_request_io(link, &link->io);
294 if (i == CS_SUCCESS) break; 280 if (i == CS_SUCCESS) break;
295 } 281 }
296 break; 282 break;
297 } 283 }
298 i = next_tuple(handle, &tuple, &parse); 284 i = next_tuple(link, &tuple, &parse);
299 } 285 }
300 286
301 if (i != CS_SUCCESS) { 287 if (i != CS_SUCCESS) {
@@ -303,14 +289,14 @@ static void elsa_cs_config(dev_link_t *link)
303 goto cs_failed; 289 goto cs_failed;
304 } 290 }
305 291
306 i = pcmcia_request_irq(link->handle, &link->irq); 292 i = pcmcia_request_irq(link, &link->irq);
307 if (i != CS_SUCCESS) { 293 if (i != CS_SUCCESS) {
308 link->irq.AssignedIRQ = 0; 294 link->irq.AssignedIRQ = 0;
309 last_fn = RequestIRQ; 295 last_fn = RequestIRQ;
310 goto cs_failed; 296 goto cs_failed;
311 } 297 }
312 298
313 i = pcmcia_request_configuration(link->handle, &link->conf); 299 i = pcmcia_request_configuration(link, &link->conf);
314 if (i != CS_SUCCESS) { 300 if (i != CS_SUCCESS) {
315 last_fn = RequestConfiguration; 301 last_fn = RequestConfiguration;
316 goto cs_failed; 302 goto cs_failed;
@@ -321,14 +307,11 @@ static void elsa_cs_config(dev_link_t *link)
321 sprintf(dev->node.dev_name, "elsa"); 307 sprintf(dev->node.dev_name, "elsa");
322 dev->node.major = dev->node.minor = 0x0; 308 dev->node.major = dev->node.minor = 0x0;
323 309
324 link->dev = &dev->node; 310 link->dev_node = &dev->node;
325 311
326 /* Finally, report what we've done */ 312 /* Finally, report what we've done */
327 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 313 printk(KERN_INFO "%s: index 0x%02x: ",
328 dev->node.dev_name, link->conf.ConfigIndex, 314 dev->node.dev_name, link->conf.ConfigIndex);
329 link->conf.Vcc/10, link->conf.Vcc%10);
330 if (link->conf.Vpp1)
331 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
332 if (link->conf.Attributes & CONF_ENABLE_IRQ) 315 if (link->conf.Attributes & CONF_ENABLE_IRQ)
333 printk(", irq %d", link->irq.AssignedIRQ); 316 printk(", irq %d", link->irq.AssignedIRQ);
334 if (link->io.NumPorts1) 317 if (link->io.NumPorts1)
@@ -339,8 +322,6 @@ static void elsa_cs_config(dev_link_t *link)
339 link->io.BasePort2+link->io.NumPorts2-1); 322 link->io.BasePort2+link->io.NumPorts2-1);
340 printk("\n"); 323 printk("\n");
341 324
342 link->state &= ~DEV_CONFIG_PENDING;
343
344 icard.para[0] = link->irq.AssignedIRQ; 325 icard.para[0] = link->irq.AssignedIRQ;
345 icard.para[1] = link->io.BasePort1; 326 icard.para[1] = link->io.BasePort1;
346 icard.protocol = protocol; 327 icard.protocol = protocol;
@@ -354,10 +335,11 @@ static void elsa_cs_config(dev_link_t *link)
354 } else 335 } else
355 ((local_info_t*)link->priv)->cardnr = i; 336 ((local_info_t*)link->priv)->cardnr = i;
356 337
357 return; 338 return 0;
358cs_failed: 339cs_failed:
359 cs_error(link->handle, last_fn, i); 340 cs_error(link, last_fn, i);
360 elsa_cs_release(link); 341 elsa_cs_release(link);
342 return -ENODEV;
361} /* elsa_cs_config */ 343} /* elsa_cs_config */
362 344
363/*====================================================================== 345/*======================================================================
@@ -368,7 +350,7 @@ cs_failed:
368 350
369======================================================================*/ 351======================================================================*/
370 352
371static void elsa_cs_release(dev_link_t *link) 353static void elsa_cs_release(struct pcmcia_device *link)
372{ 354{
373 local_info_t *local = link->priv; 355 local_info_t *local = link->priv;
374 356
@@ -380,39 +362,23 @@ static void elsa_cs_release(dev_link_t *link)
380 HiSax_closecard(local->cardnr); 362 HiSax_closecard(local->cardnr);
381 } 363 }
382 } 364 }
383 /* Unlink the device chain */ 365
384 link->dev = NULL; 366 pcmcia_disable_device(link);
385
386 /* Don't bother checking to see if these succeed or not */
387 if (link->win)
388 pcmcia_release_window(link->win);
389 pcmcia_release_configuration(link->handle);
390 pcmcia_release_io(link->handle, &link->io);
391 pcmcia_release_irq(link->handle, &link->irq);
392 link->state &= ~DEV_CONFIG;
393} /* elsa_cs_release */ 367} /* elsa_cs_release */
394 368
395static int elsa_suspend(struct pcmcia_device *p_dev) 369static int elsa_suspend(struct pcmcia_device *link)
396{ 370{
397 dev_link_t *link = dev_to_instance(p_dev);
398 local_info_t *dev = link->priv; 371 local_info_t *dev = link->priv;
399 372
400 link->state |= DEV_SUSPEND;
401 dev->busy = 1; 373 dev->busy = 1;
402 if (link->state & DEV_CONFIG)
403 pcmcia_release_configuration(link->handle);
404 374
405 return 0; 375 return 0;
406} 376}
407 377
408static int elsa_resume(struct pcmcia_device *p_dev) 378static int elsa_resume(struct pcmcia_device *link)
409{ 379{
410 dev_link_t *link = dev_to_instance(p_dev);
411 local_info_t *dev = link->priv; 380 local_info_t *dev = link->priv;
412 381
413 link->state &= ~DEV_SUSPEND;
414 if (link->state & DEV_CONFIG)
415 pcmcia_request_configuration(link->handle, &link->conf);
416 dev->busy = 0; 382 dev->busy = 0;
417 383
418 return 0; 384 return 0;
@@ -430,7 +396,7 @@ static struct pcmcia_driver elsa_cs_driver = {
430 .drv = { 396 .drv = {
431 .name = "elsa_cs", 397 .name = "elsa_cs",
432 }, 398 },
433 .probe = elsa_cs_attach, 399 .probe = elsa_cs_probe,
434 .remove = elsa_cs_detach, 400 .remove = elsa_cs_detach,
435 .id_table = elsa_ids, 401 .id_table = elsa_ids,
436 .suspend = elsa_suspend, 402 .suspend = elsa_suspend,
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 6f5213a18a8d..9bb18f3f7829 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -95,8 +95,8 @@ module_param(protocol, int, 0);
95 event handler. 95 event handler.
96*/ 96*/
97 97
98static void sedlbauer_config(dev_link_t *link); 98static int sedlbauer_config(struct pcmcia_device *link);
99static void sedlbauer_release(dev_link_t *link); 99static void sedlbauer_release(struct pcmcia_device *link);
100 100
101/* 101/*
102 The attach() and detach() entry points are used to create and destroy 102 The attach() and detach() entry points are used to create and destroy
@@ -119,7 +119,7 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev);
119 example, ethernet cards, modems). In other cases, there may be 119 example, ethernet cards, modems). In other cases, there may be
120 many actual or logical devices (SCSI adapters, memory cards with 120 many actual or logical devices (SCSI adapters, memory cards with
121 multiple partitions). The dev_node_t structures need to be kept 121 multiple partitions). The dev_node_t structures need to be kept
122 in a linked list starting at the 'dev' field of a dev_link_t 122 in a linked list starting at the 'dev' field of a struct pcmcia_device
123 structure. We allocate them in the card's private data structure, 123 structure. We allocate them in the card's private data structure,
124 because they generally shouldn't be allocated dynamically. 124 because they generally shouldn't be allocated dynamically.
125 125
@@ -130,7 +130,7 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev);
130*/ 130*/
131 131
132typedef struct local_info_t { 132typedef struct local_info_t {
133 dev_link_t link; 133 struct pcmcia_device *p_dev;
134 dev_node_t node; 134 dev_node_t node;
135 int stop; 135 int stop;
136 int cardnr; 136 int cardnr;
@@ -148,11 +148,10 @@ typedef struct local_info_t {
148 148
149======================================================================*/ 149======================================================================*/
150 150
151static int sedlbauer_attach(struct pcmcia_device *p_dev) 151static int sedlbauer_probe(struct pcmcia_device *link)
152{ 152{
153 local_info_t *local; 153 local_info_t *local;
154 dev_link_t *link; 154
155
156 DEBUG(0, "sedlbauer_attach()\n"); 155 DEBUG(0, "sedlbauer_attach()\n");
157 156
158 /* Allocate space for private device-specific data */ 157 /* Allocate space for private device-specific data */
@@ -160,8 +159,10 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
160 if (!local) return -ENOMEM; 159 if (!local) return -ENOMEM;
161 memset(local, 0, sizeof(local_info_t)); 160 memset(local, 0, sizeof(local_info_t));
162 local->cardnr = -1; 161 local->cardnr = -1;
163 link = &local->link; link->priv = local; 162
164 163 local->p_dev = link;
164 link->priv = local;
165
165 /* Interrupt setup */ 166 /* Interrupt setup */
166 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 167 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
167 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 168 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
@@ -182,18 +183,10 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
182 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 183 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
183 link->io.IOAddrLines = 3; 184 link->io.IOAddrLines = 3;
184 185
185
186 link->conf.Attributes = 0; 186 link->conf.Attributes = 0;
187 link->conf.Vcc = 50;
188 link->conf.IntType = INT_MEMORY_AND_IO; 187 link->conf.IntType = INT_MEMORY_AND_IO;
189 188
190 link->handle = p_dev; 189 return sedlbauer_config(link);
191 p_dev->instance = link;
192
193 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
194 sedlbauer_config(link);
195
196 return 0;
197} /* sedlbauer_attach */ 190} /* sedlbauer_attach */
198 191
199/*====================================================================== 192/*======================================================================
@@ -205,19 +198,15 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
205 198
206======================================================================*/ 199======================================================================*/
207 200
208static void sedlbauer_detach(struct pcmcia_device *p_dev) 201static void sedlbauer_detach(struct pcmcia_device *link)
209{ 202{
210 dev_link_t *link = dev_to_instance(p_dev); 203 DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
211
212 DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
213 204
214 if (link->state & DEV_CONFIG) { 205 ((local_info_t *)link->priv)->stop = 1;
215 ((local_info_t *)link->priv)->stop = 1; 206 sedlbauer_release(link);
216 sedlbauer_release(link);
217 }
218 207
219 /* This points to the parent local_info_t struct */ 208 /* This points to the parent local_info_t struct */
220 kfree(link->priv); 209 kfree(link->priv);
221} /* sedlbauer_detach */ 210} /* sedlbauer_detach */
222 211
223/*====================================================================== 212/*======================================================================
@@ -230,9 +219,8 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev)
230#define CS_CHECK(fn, ret) \ 219#define CS_CHECK(fn, ret) \
231do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 220do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
232 221
233static void sedlbauer_config(dev_link_t *link) 222static int sedlbauer_config(struct pcmcia_device *link)
234{ 223{
235 client_handle_t handle = link->handle;
236 local_info_t *dev = link->priv; 224 local_info_t *dev = link->priv;
237 tuple_t tuple; 225 tuple_t tuple;
238 cisparse_t parse; 226 cisparse_t parse;
@@ -254,18 +242,13 @@ static void sedlbauer_config(dev_link_t *link)
254 tuple.TupleData = buf; 242 tuple.TupleData = buf;
255 tuple.TupleDataMax = sizeof(buf); 243 tuple.TupleDataMax = sizeof(buf);
256 tuple.TupleOffset = 0; 244 tuple.TupleOffset = 0;
257 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 245 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
258 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 246 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
259 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 247 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
260 link->conf.ConfigBase = parse.config.base; 248 link->conf.ConfigBase = parse.config.base;
261 link->conf.Present = parse.config.rmask[0]; 249 link->conf.Present = parse.config.rmask[0];
262
263 /* Configure card */
264 link->state |= DEV_CONFIG;
265 250
266 /* Look up the current Vcc */ 251 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
267 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
268 link->conf.Vcc = conf.Vcc;
269 252
270 /* 253 /*
271 In this loop, we scan the CIS for configuration table entries, 254 In this loop, we scan the CIS for configuration table entries,
@@ -280,12 +263,12 @@ static void sedlbauer_config(dev_link_t *link)
280 will only use the CIS to fill in implementation-defined details. 263 will only use the CIS to fill in implementation-defined details.
281 */ 264 */
282 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
283 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 266 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
284 while (1) { 267 while (1) {
285 cistpl_cftable_entry_t dflt = { 0 }; 268 cistpl_cftable_entry_t dflt = { 0 };
286 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 269 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
287 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 270 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
288 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 271 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
289 goto next_entry; 272 goto next_entry;
290 273
291 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 274 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
@@ -309,10 +292,10 @@ static void sedlbauer_config(dev_link_t *link)
309 } 292 }
310 293
311 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 294 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
312 link->conf.Vpp1 = link->conf.Vpp2 = 295 link->conf.Vpp =
313 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 296 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
314 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 297 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
315 link->conf.Vpp1 = link->conf.Vpp2 = 298 link->conf.Vpp =
316 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 299 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
317 300
318 /* Do we need to allocate an interrupt? */ 301 /* Do we need to allocate an interrupt? */
@@ -339,13 +322,13 @@ static void sedlbauer_config(dev_link_t *link)
339 link->io.NumPorts2 = io->win[1].len; 322 link->io.NumPorts2 = io->win[1].len;
340 } 323 }
341 /* This reserves IO space but doesn't actually enable it */ 324 /* This reserves IO space but doesn't actually enable it */
342 if (pcmcia_request_io(link->handle, &link->io) != 0) 325 if (pcmcia_request_io(link, &link->io) != 0)
343 goto next_entry; 326 goto next_entry;
344 } 327 }
345 328
346 /* 329 /*
347 Now set up a common memory window, if needed. There is room 330 Now set up a common memory window, if needed. There is room
348 in the dev_link_t structure for one memory window handle, 331 in the struct pcmcia_device structure for one memory window handle,
349 but if the base addresses need to be saved, or if multiple 332 but if the base addresses need to be saved, or if multiple
350 windows are needed, the info should go in the private data 333 windows are needed, the info should go in the private data
351 structure for this device. 334 structure for this device.
@@ -366,7 +349,7 @@ static void sedlbauer_config(dev_link_t *link)
366 req.Size = 0x1000; 349 req.Size = 0x1000;
367*/ 350*/
368 req.AccessSpeed = 0; 351 req.AccessSpeed = 0;
369 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 352 if (pcmcia_request_window(&link, &req, &link->win) != 0)
370 goto next_entry; 353 goto next_entry;
371 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 354 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
372 if (pcmcia_map_mem_page(link->win, &map) != 0) 355 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -374,29 +357,25 @@ static void sedlbauer_config(dev_link_t *link)
374 } 357 }
375 /* If we got this far, we're cool! */ 358 /* If we got this far, we're cool! */
376 break; 359 break;
377 360
378 next_entry: 361 next_entry:
379/* new in dummy.cs 2001/01/28 MN 362 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
380 if (link->io.NumPorts1)
381 pcmcia_release_io(link->handle, &link->io);
382*/
383 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
384 } 363 }
385 364
386 /* 365 /*
387 Allocate an interrupt line. Note that this does not assign a 366 Allocate an interrupt line. Note that this does not assign a
388 handler to the interrupt, unless the 'Handler' member of the 367 handler to the interrupt, unless the 'Handler' member of the
389 irq structure is initialized. 368 irq structure is initialized.
390 */ 369 */
391 if (link->conf.Attributes & CONF_ENABLE_IRQ) 370 if (link->conf.Attributes & CONF_ENABLE_IRQ)
392 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 371 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
393 372
394 /* 373 /*
395 This actually configures the PCMCIA socket -- setting up 374 This actually configures the PCMCIA socket -- setting up
396 the I/O windows and the interrupt mapping, and putting the 375 the I/O windows and the interrupt mapping, and putting the
397 card and host interface into "Memory and IO" mode. 376 card and host interface into "Memory and IO" mode.
398 */ 377 */
399 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 378 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
400 379
401 /* 380 /*
402 At this point, the dev_node_t structure(s) need to be 381 At this point, the dev_node_t structure(s) need to be
@@ -404,14 +383,13 @@ static void sedlbauer_config(dev_link_t *link)
404 */ 383 */
405 sprintf(dev->node.dev_name, "sedlbauer"); 384 sprintf(dev->node.dev_name, "sedlbauer");
406 dev->node.major = dev->node.minor = 0; 385 dev->node.major = dev->node.minor = 0;
407 link->dev = &dev->node; 386 link->dev_node = &dev->node;
408 387
409 /* Finally, report what we've done */ 388 /* Finally, report what we've done */
410 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 389 printk(KERN_INFO "%s: index 0x%02x:",
411 dev->node.dev_name, link->conf.ConfigIndex, 390 dev->node.dev_name, link->conf.ConfigIndex);
412 link->conf.Vcc/10, link->conf.Vcc%10); 391 if (link->conf.Vpp)
413 if (link->conf.Vpp1) 392 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
414 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
415 if (link->conf.Attributes & CONF_ENABLE_IRQ) 393 if (link->conf.Attributes & CONF_ENABLE_IRQ)
416 printk(", irq %d", link->irq.AssignedIRQ); 394 printk(", irq %d", link->irq.AssignedIRQ);
417 if (link->io.NumPorts1) 395 if (link->io.NumPorts1)
@@ -424,8 +402,6 @@ static void sedlbauer_config(dev_link_t *link)
424 printk(", mem 0x%06lx-0x%06lx", req.Base, 402 printk(", mem 0x%06lx-0x%06lx", req.Base,
425 req.Base+req.Size-1); 403 req.Base+req.Size-1);
426 printk("\n"); 404 printk("\n");
427
428 link->state &= ~DEV_CONFIG_PENDING;
429 405
430 icard.para[0] = link->irq.AssignedIRQ; 406 icard.para[0] = link->irq.AssignedIRQ;
431 icard.para[1] = link->io.BasePort1; 407 icard.para[1] = link->io.BasePort1;
@@ -437,14 +413,16 @@ static void sedlbauer_config(dev_link_t *link)
437 printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n", 413 printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n",
438 last_ret, link->io.BasePort1); 414 last_ret, link->io.BasePort1);
439 sedlbauer_release(link); 415 sedlbauer_release(link);
416 return -ENODEV;
440 } else 417 } else
441 ((local_info_t*)link->priv)->cardnr = last_ret; 418 ((local_info_t*)link->priv)->cardnr = last_ret;
442 419
443 return; 420 return 0;
444 421
445cs_failed: 422cs_failed:
446 cs_error(link->handle, last_fn, last_ret); 423 cs_error(link, last_fn, last_ret);
447 sedlbauer_release(link); 424 sedlbauer_release(link);
425 return -ENODEV;
448 426
449} /* sedlbauer_config */ 427} /* sedlbauer_config */
450 428
@@ -456,7 +434,7 @@ cs_failed:
456 434
457======================================================================*/ 435======================================================================*/
458 436
459static void sedlbauer_release(dev_link_t *link) 437static void sedlbauer_release(struct pcmcia_device *link)
460{ 438{
461 local_info_t *local = link->priv; 439 local_info_t *local = link->priv;
462 DEBUG(0, "sedlbauer_release(0x%p)\n", link); 440 DEBUG(0, "sedlbauer_release(0x%p)\n", link);
@@ -467,46 +445,23 @@ static void sedlbauer_release(dev_link_t *link)
467 HiSax_closecard(local->cardnr); 445 HiSax_closecard(local->cardnr);
468 } 446 }
469 } 447 }
470 /* Unlink the device chain */
471 link->dev = NULL;
472 448
473 /* 449 pcmcia_disable_device(link);
474 In a normal driver, additional code may be needed to release
475 other kernel data structures associated with this device.
476 */
477
478 /* Don't bother checking to see if these succeed or not */
479 if (link->win)
480 pcmcia_release_window(link->win);
481 pcmcia_release_configuration(link->handle);
482 if (link->io.NumPorts1)
483 pcmcia_release_io(link->handle, &link->io);
484 if (link->irq.AssignedIRQ)
485 pcmcia_release_irq(link->handle, &link->irq);
486 link->state &= ~DEV_CONFIG;
487} /* sedlbauer_release */ 450} /* sedlbauer_release */
488 451
489static int sedlbauer_suspend(struct pcmcia_device *p_dev) 452static int sedlbauer_suspend(struct pcmcia_device *link)
490{ 453{
491 dev_link_t *link = dev_to_instance(p_dev);
492 local_info_t *dev = link->priv; 454 local_info_t *dev = link->priv;
493 455
494 link->state |= DEV_SUSPEND;
495 dev->stop = 1; 456 dev->stop = 1;
496 if (link->state & DEV_CONFIG)
497 pcmcia_release_configuration(link->handle);
498 457
499 return 0; 458 return 0;
500} 459}
501 460
502static int sedlbauer_resume(struct pcmcia_device *p_dev) 461static int sedlbauer_resume(struct pcmcia_device *link)
503{ 462{
504 dev_link_t *link = dev_to_instance(p_dev);
505 local_info_t *dev = link->priv; 463 local_info_t *dev = link->priv;
506 464
507 link->state &= ~DEV_SUSPEND;
508 if (link->state & DEV_CONFIG)
509 pcmcia_request_configuration(link->handle, &link->conf);
510 dev->stop = 0; 465 dev->stop = 0;
511 466
512 return 0; 467 return 0;
@@ -530,7 +485,7 @@ static struct pcmcia_driver sedlbauer_driver = {
530 .drv = { 485 .drv = {
531 .name = "sedlbauer_cs", 486 .name = "sedlbauer_cs",
532 }, 487 },
533 .probe = sedlbauer_attach, 488 .probe = sedlbauer_probe,
534 .remove = sedlbauer_detach, 489 .remove = sedlbauer_detach,
535 .id_table = sedlbauer_ids, 490 .id_table = sedlbauer_ids,
536 .suspend = sedlbauer_suspend, 491 .suspend = sedlbauer_suspend,
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index 4e5c14c7240e..afcc2aeadb34 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -75,8 +75,8 @@ module_param(protocol, int, 0);
75 handler. 75 handler.
76*/ 76*/
77 77
78static void teles_cs_config(dev_link_t *link); 78static int teles_cs_config(struct pcmcia_device *link);
79static void teles_cs_release(dev_link_t *link); 79static void teles_cs_release(struct pcmcia_device *link);
80 80
81/* 81/*
82 The attach() and detach() entry points are used to create and destroy 82 The attach() and detach() entry points are used to create and destroy
@@ -89,10 +89,10 @@ static void teles_detach(struct pcmcia_device *p_dev);
89/* 89/*
90 A linked list of "instances" of the teles_cs device. Each actual 90 A linked list of "instances" of the teles_cs device. Each actual
91 PCMCIA card corresponds to one device instance, and is described 91 PCMCIA card corresponds to one device instance, and is described
92 by one dev_link_t structure (defined in ds.h). 92 by one struct pcmcia_device structure (defined in ds.h).
93 93
94 You may not want to use a linked list for this -- for example, the 94 You may not want to use a linked list for this -- for example, the
95 memory card driver uses an array of dev_link_t pointers, where minor 95 memory card driver uses an array of struct pcmcia_device pointers, where minor
96 device numbers are used to derive the corresponding array index. 96 device numbers are used to derive the corresponding array index.
97*/ 97*/
98 98
@@ -102,7 +102,7 @@ static void teles_detach(struct pcmcia_device *p_dev);
102 example, ethernet cards, modems). In other cases, there may be 102 example, ethernet cards, modems). In other cases, there may be
103 many actual or logical devices (SCSI adapters, memory cards with 103 many actual or logical devices (SCSI adapters, memory cards with
104 multiple partitions). The dev_node_t structures need to be kept 104 multiple partitions). The dev_node_t structures need to be kept
105 in a linked list starting at the 'dev' field of a dev_link_t 105 in a linked list starting at the 'dev' field of a struct pcmcia_device
106 structure. We allocate them in the card's private data structure, 106 structure. We allocate them in the card's private data structure,
107 because they generally shouldn't be allocated dynamically. 107 because they generally shouldn't be allocated dynamically.
108 In this case, we also provide a flag to indicate if a device is 108 In this case, we also provide a flag to indicate if a device is
@@ -112,7 +112,7 @@ static void teles_detach(struct pcmcia_device *p_dev);
112*/ 112*/
113 113
114typedef struct local_info_t { 114typedef struct local_info_t {
115 dev_link_t link; 115 struct pcmcia_device *p_dev;
116 dev_node_t node; 116 dev_node_t node;
117 int busy; 117 int busy;
118 int cardnr; 118 int cardnr;
@@ -130,9 +130,8 @@ typedef struct local_info_t {
130 130
131======================================================================*/ 131======================================================================*/
132 132
133static int teles_attach(struct pcmcia_device *p_dev) 133static int teles_probe(struct pcmcia_device *link)
134{ 134{
135 dev_link_t *link;
136 local_info_t *local; 135 local_info_t *local;
137 136
138 DEBUG(0, "teles_attach()\n"); 137 DEBUG(0, "teles_attach()\n");
@@ -142,7 +141,9 @@ static int teles_attach(struct pcmcia_device *p_dev)
142 if (!local) return -ENOMEM; 141 if (!local) return -ENOMEM;
143 memset(local, 0, sizeof(local_info_t)); 142 memset(local, 0, sizeof(local_info_t));
144 local->cardnr = -1; 143 local->cardnr = -1;
145 link = &local->link; link->priv = local; 144
145 local->p_dev = link;
146 link->priv = local;
146 147
147 /* Interrupt setup */ 148 /* Interrupt setup */
148 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 149 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
@@ -161,16 +162,9 @@ static int teles_attach(struct pcmcia_device *p_dev)
161 link->io.IOAddrLines = 5; 162 link->io.IOAddrLines = 5;
162 163
163 link->conf.Attributes = CONF_ENABLE_IRQ; 164 link->conf.Attributes = CONF_ENABLE_IRQ;
164 link->conf.Vcc = 50;
165 link->conf.IntType = INT_MEMORY_AND_IO; 165 link->conf.IntType = INT_MEMORY_AND_IO;
166 166
167 link->handle = p_dev; 167 return teles_cs_config(link);
168 p_dev->instance = link;
169
170 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
171 teles_cs_config(link);
172
173 return 0;
174} /* teles_attach */ 168} /* teles_attach */
175 169
176/*====================================================================== 170/*======================================================================
@@ -182,20 +176,16 @@ static int teles_attach(struct pcmcia_device *p_dev)
182 176
183======================================================================*/ 177======================================================================*/
184 178
185static void teles_detach(struct pcmcia_device *p_dev) 179static void teles_detach(struct pcmcia_device *link)
186{ 180{
187 dev_link_t *link = dev_to_instance(p_dev); 181 local_info_t *info = link->priv;
188 local_info_t *info = link->priv;
189
190 DEBUG(0, "teles_detach(0x%p)\n", link);
191 182
192 if (link->state & DEV_CONFIG) { 183 DEBUG(0, "teles_detach(0x%p)\n", link);
193 info->busy = 1;
194 teles_cs_release(link);
195 }
196 184
197 kfree(info); 185 info->busy = 1;
186 teles_cs_release(link);
198 187
188 kfree(info);
199} /* teles_detach */ 189} /* teles_detach */
200 190
201/*====================================================================== 191/*======================================================================
@@ -205,7 +195,7 @@ static void teles_detach(struct pcmcia_device *p_dev)
205 device available to the system. 195 device available to the system.
206 196
207======================================================================*/ 197======================================================================*/
208static int get_tuple(client_handle_t handle, tuple_t *tuple, 198static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
209 cisparse_t *parse) 199 cisparse_t *parse)
210{ 200{
211 int i = pcmcia_get_tuple_data(handle, tuple); 201 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -213,7 +203,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
213 return pcmcia_parse_tuple(handle, tuple, parse); 203 return pcmcia_parse_tuple(handle, tuple, parse);
214} 204}
215 205
216static int first_tuple(client_handle_t handle, tuple_t *tuple, 206static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
217 cisparse_t *parse) 207 cisparse_t *parse)
218{ 208{
219 int i = pcmcia_get_first_tuple(handle, tuple); 209 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -221,7 +211,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
221 return get_tuple(handle, tuple, parse); 211 return get_tuple(handle, tuple, parse);
222} 212}
223 213
224static int next_tuple(client_handle_t handle, tuple_t *tuple, 214static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
225 cisparse_t *parse) 215 cisparse_t *parse)
226{ 216{
227 int i = pcmcia_get_next_tuple(handle, tuple); 217 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -229,9 +219,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
229 return get_tuple(handle, tuple, parse); 219 return get_tuple(handle, tuple, parse);
230} 220}
231 221
232static void teles_cs_config(dev_link_t *link) 222static int teles_cs_config(struct pcmcia_device *link)
233{ 223{
234 client_handle_t handle;
235 tuple_t tuple; 224 tuple_t tuple;
236 cisparse_t parse; 225 cisparse_t parse;
237 local_info_t *dev; 226 local_info_t *dev;
@@ -241,7 +230,6 @@ static void teles_cs_config(dev_link_t *link)
241 IsdnCard_t icard; 230 IsdnCard_t icard;
242 231
243 DEBUG(0, "teles_config(0x%p)\n", link); 232 DEBUG(0, "teles_config(0x%p)\n", link);
244 handle = link->handle;
245 dev = link->priv; 233 dev = link->priv;
246 234
247 /* 235 /*
@@ -253,7 +241,7 @@ static void teles_cs_config(dev_link_t *link)
253 tuple.TupleDataMax = 255; 241 tuple.TupleDataMax = 255;
254 tuple.TupleOffset = 0; 242 tuple.TupleOffset = 0;
255 tuple.Attributes = 0; 243 tuple.Attributes = 0;
256 i = first_tuple(handle, &tuple, &parse); 244 i = first_tuple(link, &tuple, &parse);
257 if (i != CS_SUCCESS) { 245 if (i != CS_SUCCESS) {
258 last_fn = ParseTuple; 246 last_fn = ParseTuple;
259 goto cs_failed; 247 goto cs_failed;
@@ -261,32 +249,29 @@ static void teles_cs_config(dev_link_t *link)
261 link->conf.ConfigBase = parse.config.base; 249 link->conf.ConfigBase = parse.config.base;
262 link->conf.Present = parse.config.rmask[0]; 250 link->conf.Present = parse.config.rmask[0];
263 251
264 /* Configure card */
265 link->state |= DEV_CONFIG;
266
267 tuple.TupleData = (cisdata_t *)buf; 252 tuple.TupleData = (cisdata_t *)buf;
268 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 253 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
269 tuple.Attributes = 0; 254 tuple.Attributes = 0;
270 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 255 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
271 i = first_tuple(handle, &tuple, &parse); 256 i = first_tuple(link, &tuple, &parse);
272 while (i == CS_SUCCESS) { 257 while (i == CS_SUCCESS) {
273 if ( (cf->io.nwin > 0) && cf->io.win[0].base) { 258 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
274 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n"); 259 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
275 link->conf.ConfigIndex = cf->index; 260 link->conf.ConfigIndex = cf->index;
276 link->io.BasePort1 = cf->io.win[0].base; 261 link->io.BasePort1 = cf->io.win[0].base;
277 i = pcmcia_request_io(link->handle, &link->io); 262 i = pcmcia_request_io(link, &link->io);
278 if (i == CS_SUCCESS) break; 263 if (i == CS_SUCCESS) break;
279 } else { 264 } else {
280 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n"); 265 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
281 link->conf.ConfigIndex = cf->index; 266 link->conf.ConfigIndex = cf->index;
282 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) { 267 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
283 link->io.BasePort1 = j; 268 link->io.BasePort1 = j;
284 i = pcmcia_request_io(link->handle, &link->io); 269 i = pcmcia_request_io(link, &link->io);
285 if (i == CS_SUCCESS) break; 270 if (i == CS_SUCCESS) break;
286 } 271 }
287 break; 272 break;
288 } 273 }
289 i = next_tuple(handle, &tuple, &parse); 274 i = next_tuple(link, &tuple, &parse);
290 } 275 }
291 276
292 if (i != CS_SUCCESS) { 277 if (i != CS_SUCCESS) {
@@ -294,14 +279,14 @@ static void teles_cs_config(dev_link_t *link)
294 goto cs_failed; 279 goto cs_failed;
295 } 280 }
296 281
297 i = pcmcia_request_irq(link->handle, &link->irq); 282 i = pcmcia_request_irq(link, &link->irq);
298 if (i != CS_SUCCESS) { 283 if (i != CS_SUCCESS) {
299 link->irq.AssignedIRQ = 0; 284 link->irq.AssignedIRQ = 0;
300 last_fn = RequestIRQ; 285 last_fn = RequestIRQ;
301 goto cs_failed; 286 goto cs_failed;
302 } 287 }
303 288
304 i = pcmcia_request_configuration(link->handle, &link->conf); 289 i = pcmcia_request_configuration(link, &link->conf);
305 if (i != CS_SUCCESS) { 290 if (i != CS_SUCCESS) {
306 last_fn = RequestConfiguration; 291 last_fn = RequestConfiguration;
307 goto cs_failed; 292 goto cs_failed;
@@ -312,14 +297,11 @@ static void teles_cs_config(dev_link_t *link)
312 sprintf(dev->node.dev_name, "teles"); 297 sprintf(dev->node.dev_name, "teles");
313 dev->node.major = dev->node.minor = 0x0; 298 dev->node.major = dev->node.minor = 0x0;
314 299
315 link->dev = &dev->node; 300 link->dev_node = &dev->node;
316 301
317 /* Finally, report what we've done */ 302 /* Finally, report what we've done */
318 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 303 printk(KERN_INFO "%s: index 0x%02x:",
319 dev->node.dev_name, link->conf.ConfigIndex, 304 dev->node.dev_name, link->conf.ConfigIndex);
320 link->conf.Vcc/10, link->conf.Vcc%10);
321 if (link->conf.Vpp1)
322 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
323 if (link->conf.Attributes & CONF_ENABLE_IRQ) 305 if (link->conf.Attributes & CONF_ENABLE_IRQ)
324 printk(", irq %d", link->irq.AssignedIRQ); 306 printk(", irq %d", link->irq.AssignedIRQ);
325 if (link->io.NumPorts1) 307 if (link->io.NumPorts1)
@@ -330,8 +312,6 @@ static void teles_cs_config(dev_link_t *link)
330 link->io.BasePort2+link->io.NumPorts2-1); 312 link->io.BasePort2+link->io.NumPorts2-1);
331 printk("\n"); 313 printk("\n");
332 314
333 link->state &= ~DEV_CONFIG_PENDING;
334
335 icard.para[0] = link->irq.AssignedIRQ; 315 icard.para[0] = link->irq.AssignedIRQ;
336 icard.para[1] = link->io.BasePort1; 316 icard.para[1] = link->io.BasePort1;
337 icard.protocol = protocol; 317 icard.protocol = protocol;
@@ -342,13 +322,16 @@ static void teles_cs_config(dev_link_t *link)
342 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n", 322 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
343 i, link->io.BasePort1); 323 i, link->io.BasePort1);
344 teles_cs_release(link); 324 teles_cs_release(link);
345 } else 325 return -ENODEV;
346 ((local_info_t*)link->priv)->cardnr = i; 326 }
327
328 ((local_info_t*)link->priv)->cardnr = i;
329 return 0;
347 330
348 return;
349cs_failed: 331cs_failed:
350 cs_error(link->handle, last_fn, i); 332 cs_error(link, last_fn, i);
351 teles_cs_release(link); 333 teles_cs_release(link);
334 return -ENODEV;
352} /* teles_cs_config */ 335} /* teles_cs_config */
353 336
354/*====================================================================== 337/*======================================================================
@@ -359,7 +342,7 @@ cs_failed:
359 342
360======================================================================*/ 343======================================================================*/
361 344
362static void teles_cs_release(dev_link_t *link) 345static void teles_cs_release(struct pcmcia_device *link)
363{ 346{
364 local_info_t *local = link->priv; 347 local_info_t *local = link->priv;
365 348
@@ -371,39 +354,23 @@ static void teles_cs_release(dev_link_t *link)
371 HiSax_closecard(local->cardnr); 354 HiSax_closecard(local->cardnr);
372 } 355 }
373 } 356 }
374 /* Unlink the device chain */ 357
375 link->dev = NULL; 358 pcmcia_disable_device(link);
376
377 /* Don't bother checking to see if these succeed or not */
378 if (link->win)
379 pcmcia_release_window(link->win);
380 pcmcia_release_configuration(link->handle);
381 pcmcia_release_io(link->handle, &link->io);
382 pcmcia_release_irq(link->handle, &link->irq);
383 link->state &= ~DEV_CONFIG;
384} /* teles_cs_release */ 359} /* teles_cs_release */
385 360
386static int teles_suspend(struct pcmcia_device *p_dev) 361static int teles_suspend(struct pcmcia_device *link)
387{ 362{
388 dev_link_t *link = dev_to_instance(p_dev);
389 local_info_t *dev = link->priv; 363 local_info_t *dev = link->priv;
390 364
391 link->state |= DEV_SUSPEND;
392 dev->busy = 1; 365 dev->busy = 1;
393 if (link->state & DEV_CONFIG)
394 pcmcia_release_configuration(link->handle);
395 366
396 return 0; 367 return 0;
397} 368}
398 369
399static int teles_resume(struct pcmcia_device *p_dev) 370static int teles_resume(struct pcmcia_device *link)
400{ 371{
401 dev_link_t *link = dev_to_instance(p_dev);
402 local_info_t *dev = link->priv; 372 local_info_t *dev = link->priv;
403 373
404 link->state &= ~DEV_SUSPEND;
405 if (link->state & DEV_CONFIG)
406 pcmcia_request_configuration(link->handle, &link->conf);
407 dev->busy = 0; 374 dev->busy = 0;
408 375
409 return 0; 376 return 0;
@@ -421,7 +388,7 @@ static struct pcmcia_driver teles_cs_driver = {
421 .drv = { 388 .drv = {
422 .name = "teles_cs", 389 .name = "teles_cs",
423 }, 390 },
424 .probe = teles_attach, 391 .probe = teles_probe,
425 .remove = teles_detach, 392 .remove = teles_detach,
426 .id_table = teles_ids, 393 .id_table = teles_ids,
427 .suspend = teles_suspend, 394 .suspend = teles_suspend,
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index a0927d1b7a0c..918742271c79 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -109,7 +109,7 @@ isdn_ppp_free(isdn_net_local * lp)
109{ 109{
110 struct ippp_struct *is; 110 struct ippp_struct *is;
111 111
112 if (lp->ppp_slot < 0 || lp->ppp_slot > ISDN_MAX_CHANNELS) { 112 if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
113 printk(KERN_ERR "%s: ppp_slot(%d) out of range\n", 113 printk(KERN_ERR "%s: ppp_slot(%d) out of range\n",
114 __FUNCTION__, lp->ppp_slot); 114 __FUNCTION__, lp->ppp_slot);
115 return 0; 115 return 0;
@@ -126,7 +126,7 @@ isdn_ppp_free(isdn_net_local * lp)
126 lp->netdev->pb->ref_ct--; 126 lp->netdev->pb->ref_ct--;
127 spin_unlock(&lp->netdev->pb->lock); 127 spin_unlock(&lp->netdev->pb->lock);
128#endif /* CONFIG_ISDN_MPP */ 128#endif /* CONFIG_ISDN_MPP */
129 if (lp->ppp_slot < 0 || lp->ppp_slot > ISDN_MAX_CHANNELS) { 129 if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
130 printk(KERN_ERR "%s: ppp_slot(%d) now invalid\n", 130 printk(KERN_ERR "%s: ppp_slot(%d) now invalid\n",
131 __FUNCTION__, lp->ppp_slot); 131 __FUNCTION__, lp->ppp_slot);
132 return 0; 132 return 0;
@@ -279,7 +279,7 @@ isdn_ppp_open(int min, struct file *file)
279 int slot; 279 int slot;
280 struct ippp_struct *is; 280 struct ippp_struct *is;
281 281
282 if (min < 0 || min > ISDN_MAX_CHANNELS) 282 if (min < 0 || min >= ISDN_MAX_CHANNELS)
283 return -ENODEV; 283 return -ENODEV;
284 284
285 slot = isdn_ppp_get_slot(); 285 slot = isdn_ppp_get_slot();
@@ -1042,7 +1042,7 @@ isdn_ppp_push_higher(isdn_net_dev * net_dev, isdn_net_local * lp, struct sk_buff
1042 if (lp->master) { // FIXME? 1042 if (lp->master) { // FIXME?
1043 mlp = (isdn_net_local *) lp->master->priv; 1043 mlp = (isdn_net_local *) lp->master->priv;
1044 slot = mlp->ppp_slot; 1044 slot = mlp->ppp_slot;
1045 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1045 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1046 printk(KERN_ERR "isdn_ppp_push_higher: master->ppp_slot(%d)\n", 1046 printk(KERN_ERR "isdn_ppp_push_higher: master->ppp_slot(%d)\n",
1047 lp->ppp_slot); 1047 lp->ppp_slot);
1048 goto drop_packet; 1048 goto drop_packet;
@@ -1264,7 +1264,7 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
1264 /* we have our lp locked from now on */ 1264 /* we have our lp locked from now on */
1265 1265
1266 slot = lp->ppp_slot; 1266 slot = lp->ppp_slot;
1267 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1267 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1268 printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n", 1268 printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n",
1269 lp->ppp_slot); 1269 lp->ppp_slot);
1270 kfree_skb(skb); 1270 kfree_skb(skb);
@@ -1603,7 +1603,7 @@ static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
1603 mp = net_dev->pb; 1603 mp = net_dev->pb;
1604 stats = &mp->stats; 1604 stats = &mp->stats;
1605 slot = lp->ppp_slot; 1605 slot = lp->ppp_slot;
1606 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1606 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1607 printk(KERN_ERR "%s: lp->ppp_slot(%d)\n", 1607 printk(KERN_ERR "%s: lp->ppp_slot(%d)\n",
1608 __FUNCTION__, lp->ppp_slot); 1608 __FUNCTION__, lp->ppp_slot);
1609 stats->frame_drops++; 1609 stats->frame_drops++;
@@ -1640,7 +1640,7 @@ static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
1640 is->last_link_seqno = minseq = newseq; 1640 is->last_link_seqno = minseq = newseq;
1641 for (lpq = net_dev->queue;;) { 1641 for (lpq = net_dev->queue;;) {
1642 slot = lpq->ppp_slot; 1642 slot = lpq->ppp_slot;
1643 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1643 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1644 printk(KERN_ERR "%s: lpq->ppp_slot(%d)\n", 1644 printk(KERN_ERR "%s: lpq->ppp_slot(%d)\n",
1645 __FUNCTION__, lpq->ppp_slot); 1645 __FUNCTION__, lpq->ppp_slot);
1646 } else { 1646 } else {
@@ -2648,7 +2648,7 @@ static void isdn_ppp_receive_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
2648 2648
2649 printk(KERN_DEBUG "Received CCP frame from peer slot(%d)\n", 2649 printk(KERN_DEBUG "Received CCP frame from peer slot(%d)\n",
2650 lp->ppp_slot); 2650 lp->ppp_slot);
2651 if (lp->ppp_slot < 0 || lp->ppp_slot > ISDN_MAX_CHANNELS) { 2651 if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
2652 printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n", 2652 printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
2653 __FUNCTION__, lp->ppp_slot); 2653 __FUNCTION__, lp->ppp_slot);
2654 return; 2654 return;
@@ -2658,7 +2658,7 @@ static void isdn_ppp_receive_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
2658 2658
2659 if(lp->master) { 2659 if(lp->master) {
2660 int slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot; 2660 int slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot;
2661 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 2661 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
2662 printk(KERN_ERR "%s: slot(%d) out of range\n", 2662 printk(KERN_ERR "%s: slot(%d) out of range\n",
2663 __FUNCTION__, slot); 2663 __FUNCTION__, slot);
2664 return; 2664 return;
@@ -2845,7 +2845,7 @@ static void isdn_ppp_send_ccp(isdn_net_dev *net_dev, isdn_net_local *lp, struct
2845 2845
2846 if (lp->master) { 2846 if (lp->master) {
2847 slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot; 2847 slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot;
2848 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 2848 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
2849 printk(KERN_ERR "%s: slot(%d) out of range\n", 2849 printk(KERN_ERR "%s: slot(%d) out of range\n",
2850 __FUNCTION__, slot); 2850 __FUNCTION__, slot);
2851 return; 2851 return;