aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/asyncdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/gigaset/asyncdata.c')
-rw-r--r--drivers/isdn/gigaset/asyncdata.c80
1 files changed, 43 insertions, 37 deletions
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index 778d864ab612..a375d0a411b5 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -41,7 +41,7 @@ static inline int muststuff(unsigned char c)
41 * number of processed bytes 41 * number of processed bytes
42 */ 42 */
43static 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,
44 struct inbuf_t *inbuf) 44 struct inbuf_t *inbuf)
45{ 45{
46 struct cardstate *cs = inbuf->cs; 46 struct cardstate *cs = inbuf->cs;
47 unsigned cbytes = cs->cbytes; 47 unsigned cbytes = cs->cbytes;
@@ -51,8 +51,8 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
51 for (;;) { 51 for (;;) {
52 cs->respdata[cbytes] = c; 52 cs->respdata[cbytes] = c;
53 if (c == 10 || c == 13) { 53 if (c == 10 || c == 13) {
54 dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", 54 gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
55 __func__, cbytes); 55 __func__, cbytes);
56 cs->cbytes = cbytes; 56 cs->cbytes = cbytes;
57 gigaset_handle_modem_response(cs); /* can change 57 gigaset_handle_modem_response(cs); /* can change
58 cs->dle */ 58 cs->dle */
@@ -68,7 +68,7 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
68 if (cbytes < MAX_RESP_SIZE - 1) 68 if (cbytes < MAX_RESP_SIZE - 1)
69 cbytes++; 69 cbytes++;
70 else 70 else
71 warn("response too large"); 71 dev_warn(cs->dev, "response too large\n");
72 } 72 }
73 73
74 if (!numbytes) 74 if (!numbytes)
@@ -93,7 +93,7 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
93 * number of processed bytes 93 * number of processed bytes
94 */ 94 */
95static inline int lock_loop(unsigned char *src, int numbytes, 95static inline int lock_loop(unsigned char *src, int numbytes,
96 struct inbuf_t *inbuf) 96 struct inbuf_t *inbuf)
97{ 97{
98 struct cardstate *cs = inbuf->cs; 98 struct cardstate *cs = inbuf->cs;
99 99
@@ -113,7 +113,7 @@ static inline int lock_loop(unsigned char *src, int numbytes,
113 * numbytes (all bytes processed) on error --FIXME 113 * numbytes (all bytes processed) on error --FIXME
114 */ 114 */
115static 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,
116 struct inbuf_t *inbuf) 116 struct inbuf_t *inbuf)
117{ 117{
118 struct cardstate *cs = inbuf->cs; 118 struct cardstate *cs = inbuf->cs;
119 struct bc_state *bcs = inbuf->bcs; 119 struct bc_state *bcs = inbuf->bcs;
@@ -154,39 +154,37 @@ byte_stuff:
154 c ^= PPP_TRANS; 154 c ^= PPP_TRANS;
155#ifdef CONFIG_GIGASET_DEBUG 155#ifdef CONFIG_GIGASET_DEBUG
156 if (unlikely(!muststuff(c))) 156 if (unlikely(!muststuff(c)))
157 dbg(DEBUG_HDLC, 157 gig_dbg(DEBUG_HDLC, "byte stuffed: 0x%02x", c);
158 "byte stuffed: 0x%02x", c);
159#endif 158#endif
160 } else if (unlikely(c == PPP_FLAG)) { 159 } else if (unlikely(c == PPP_FLAG)) {
161 if (unlikely(inputstate & INS_skip_frame)) { 160 if (unlikely(inputstate & INS_skip_frame)) {
162 if (!(inputstate & INS_have_data)) { /* 7E 7E */ 161 if (!(inputstate & INS_have_data)) { /* 7E 7E */
163 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
164#ifdef CONFIG_GIGASET_DEBUG 162#ifdef CONFIG_GIGASET_DEBUG
165 ++bcs->emptycount; 163 ++bcs->emptycount;
166#endif 164#endif
167 } else 165 } else
168 dbg(DEBUG_HDLC, 166 gig_dbg(DEBUG_HDLC,
169 "7e----------------------------"); 167 "7e----------------------------");
170 168
171 /* end of frame */ 169 /* end of frame */
172 error = 1; 170 error = 1;
173 gigaset_rcv_error(NULL, cs, bcs); 171 gigaset_rcv_error(NULL, cs, bcs);
174 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */ 172 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */
175 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
176#ifdef CONFIG_GIGASET_DEBUG 173#ifdef CONFIG_GIGASET_DEBUG
177 ++bcs->emptycount; 174 ++bcs->emptycount;
178#endif 175#endif
179 break; 176 break;
180 } else { 177 } else {
181 dbg(DEBUG_HDLC, 178 gig_dbg(DEBUG_HDLC,
182 "7e----------------------------"); 179 "7e----------------------------");
183 180
184 /* end of frame */ 181 /* end of frame */
185 error = 0; 182 error = 0;
186 183
187 if (unlikely(fcs != PPP_GOODFCS)) { 184 if (unlikely(fcs != PPP_GOODFCS)) {
188 err("Packet checksum at %lu failed, " 185 dev_err(cs->dev,
189 "packet is corrupted (%u bytes)!", 186 "Packet checksum at %lu failed, "
187 "packet is corrupted (%u bytes)!\n",
190 bcs->rcvbytes, skb->len); 188 bcs->rcvbytes, skb->len);
191 compskb = NULL; 189 compskb = NULL;
192 gigaset_rcv_error(compskb, cs, bcs); 190 gigaset_rcv_error(compskb, cs, bcs);
@@ -200,9 +198,11 @@ byte_stuff:
200 skb = NULL; 198 skb = NULL;
201 inputstate |= INS_skip_frame; 199 inputstate |= INS_skip_frame;
202 if (l == 1) { 200 if (l == 1) {
203 err("invalid packet size (1)!"); 201 dev_err(cs->dev,
202 "invalid packet size (1)!\n");
204 error = 1; 203 error = 1;
205 gigaset_rcv_error(NULL, cs, bcs); 204 gigaset_rcv_error(NULL,
205 cs, bcs);
206 } 206 }
207 } 207 }
208 if (likely(!(error || 208 if (likely(!(error ||
@@ -225,7 +225,8 @@ byte_stuff:
225 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) { 225 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) {
226 skb_reserve(skb, HW_HDR_LEN); 226 skb_reserve(skb, HW_HDR_LEN);
227 } else { 227 } else {
228 warn("could not allocate new skb"); 228 dev_warn(cs->dev,
229 "could not allocate new skb\n");
229 inputstate |= INS_skip_frame; 230 inputstate |= INS_skip_frame;
230 } 231 }
231 232
@@ -233,7 +234,7 @@ byte_stuff:
233#ifdef CONFIG_GIGASET_DEBUG 234#ifdef CONFIG_GIGASET_DEBUG
234 } else if (unlikely(muststuff(c))) { 235 } else if (unlikely(muststuff(c))) {
235 /* Should not happen. Possible after ZDLE=1<CR><LF>. */ 236 /* Should not happen. Possible after ZDLE=1<CR><LF>. */
236 dbg(DEBUG_HDLC, "not byte stuffed: 0x%02x", c); 237 gig_dbg(DEBUG_HDLC, "not byte stuffed: 0x%02x", c);
237#endif 238#endif
238 } 239 }
239 240
@@ -241,8 +242,8 @@ byte_stuff:
241 242
242#ifdef CONFIG_GIGASET_DEBUG 243#ifdef CONFIG_GIGASET_DEBUG
243 if (unlikely(!(inputstate & INS_have_data))) { 244 if (unlikely(!(inputstate & INS_have_data))) {
244 dbg(DEBUG_HDLC, 245 gig_dbg(DEBUG_HDLC, "7e (%d x) ================",
245 "7e (%d x) ================", bcs->emptycount); 246 bcs->emptycount);
246 bcs->emptycount = 0; 247 bcs->emptycount = 0;
247 } 248 }
248#endif 249#endif
@@ -251,7 +252,7 @@ byte_stuff:
251 252
252 if (likely(!(inputstate & INS_skip_frame))) { 253 if (likely(!(inputstate & INS_skip_frame))) {
253 if (unlikely(skb->len == SBUFSIZE)) { 254 if (unlikely(skb->len == SBUFSIZE)) {
254 warn("received packet too long"); 255 dev_warn(cs->dev, "received packet too long\n");
255 dev_kfree_skb_any(skb); 256 dev_kfree_skb_any(skb);
256 skb = NULL; 257 skb = NULL;
257 inputstate |= INS_skip_frame; 258 inputstate |= INS_skip_frame;
@@ -287,7 +288,7 @@ byte_stuff:
287 * numbytes (all bytes processed) on error --FIXME 288 * numbytes (all bytes processed) on error --FIXME
288 */ 289 */
289static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes, 290static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
290 struct inbuf_t *inbuf) 291 struct inbuf_t *inbuf)
291{ 292{
292 struct cardstate *cs = inbuf->cs; 293 struct cardstate *cs = inbuf->cs;
293 struct bc_state *bcs = inbuf->bcs; 294 struct bc_state *bcs = inbuf->bcs;
@@ -307,7 +308,7 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
307 if (likely(!(inputstate & INS_skip_frame))) { 308 if (likely(!(inputstate & INS_skip_frame))) {
308 if (unlikely(skb->len == SBUFSIZE)) { 309 if (unlikely(skb->len == SBUFSIZE)) {
309 //FIXME just pass skb up and allocate a new one 310 //FIXME just pass skb up and allocate a new one
310 warn("received packet too long"); 311 dev_warn(cs->dev, "received packet too long\n");
311 dev_kfree_skb_any(skb); 312 dev_kfree_skb_any(skb);
312 skb = NULL; 313 skb = NULL;
313 inputstate |= INS_skip_frame; 314 inputstate |= INS_skip_frame;
@@ -341,7 +342,7 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
341 != NULL)) { 342 != NULL)) {
342 skb_reserve(skb, HW_HDR_LEN); 343 skb_reserve(skb, HW_HDR_LEN);
343 } else { 344 } else {
344 warn("could not allocate new skb"); 345 dev_warn(cs->dev, "could not allocate new skb\n");
345 inputstate |= INS_skip_frame; 346 inputstate |= INS_skip_frame;
346 } 347 }
347 } 348 }
@@ -362,13 +363,13 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
362 363
363 head = atomic_read(&inbuf->head); 364 head = atomic_read(&inbuf->head);
364 tail = atomic_read(&inbuf->tail); 365 tail = atomic_read(&inbuf->tail);
365 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); 366 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
366 367
367 if (head != tail) { 368 if (head != tail) {
368 cs = inbuf->cs; 369 cs = inbuf->cs;
369 src = inbuf->data + head; 370 src = inbuf->data + head;
370 numbytes = (head > tail ? RBUFSIZE : tail) - head; 371 numbytes = (head > tail ? RBUFSIZE : tail) - head;
371 dbg(DEBUG_INTR, "processing %u bytes", numbytes); 372 gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
372 373
373 while (numbytes) { 374 while (numbytes) {
374 if (atomic_read(&cs->mstate) == MS_LOCKED) { 375 if (atomic_read(&cs->mstate) == MS_LOCKED) {
@@ -400,13 +401,14 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
400 401
401 src += procbytes; 402 src += procbytes;
402 numbytes -= procbytes; 403 numbytes -= procbytes;
403 } else { /* DLE-char */ 404 } else { /* DLE char */
404 inbuf->inputstate &= ~INS_DLE_char; 405 inbuf->inputstate &= ~INS_DLE_char;
405 switch (c) { 406 switch (c) {
406 case 'X': /*begin of command*/ 407 case 'X': /*begin of command*/
407#ifdef CONFIG_GIGASET_DEBUG 408#ifdef CONFIG_GIGASET_DEBUG
408 if (inbuf->inputstate & INS_command) 409 if (inbuf->inputstate & INS_command)
409 err("received <DLE> 'X' in command mode"); 410 dev_err(cs->dev,
411 "received <DLE> 'X' in command mode\n");
410#endif 412#endif
411 inbuf->inputstate |= 413 inbuf->inputstate |=
412 INS_command | INS_DLE_command; 414 INS_command | INS_DLE_command;
@@ -414,7 +416,8 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
414 case '.': /*end of command*/ 416 case '.': /*end of command*/
415#ifdef CONFIG_GIGASET_DEBUG 417#ifdef CONFIG_GIGASET_DEBUG
416 if (!(inbuf->inputstate & INS_command)) 418 if (!(inbuf->inputstate & INS_command))
417 err("received <DLE> '.' in hdlc mode"); 419 dev_err(cs->dev,
420 "received <DLE> '.' in hdlc mode\n");
418#endif 421#endif
419 inbuf->inputstate &= cs->dle ? 422 inbuf->inputstate &= cs->dle ?
420 ~(INS_DLE_command|INS_command) 423 ~(INS_DLE_command|INS_command)
@@ -422,7 +425,9 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
422 break; 425 break;
423 //case DLE_FLAG: /*DLE_FLAG in data stream*/ /* schon oben behandelt! */ 426 //case DLE_FLAG: /*DLE_FLAG in data stream*/ /* schon oben behandelt! */
424 default: 427 default:
425 err("received 0x10 0x%02x!", (int) c); 428 dev_err(cs->dev,
429 "received 0x10 0x%02x!\n",
430 (int) c);
426 /* FIXME: reset driver?? */ 431 /* FIXME: reset driver?? */
427 } 432 }
428 } 433 }
@@ -441,7 +446,7 @@ nextbyte:
441 } 446 }
442 } 447 }
443 448
444 dbg(DEBUG_INTR, "setting head to %u", head); 449 gig_dbg(DEBUG_INTR, "setting head to %u", head);
445 atomic_set(&inbuf->head, head); 450 atomic_set(&inbuf->head, head);
446 } 451 }
447} 452}
@@ -476,14 +481,13 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
476 stuf_cnt++; 481 stuf_cnt++;
477 fcs = crc_ccitt_byte(fcs, *cp++); 482 fcs = crc_ccitt_byte(fcs, *cp++);
478 } 483 }
479 fcs ^= 0xffff; /* complement */ 484 fcs ^= 0xffff; /* complement */
480 485
481 /* size of new buffer: original size + number of stuffing bytes 486 /* size of new buffer: original size + number of stuffing bytes
482 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes 487 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes
483 */ 488 */
484 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head); 489 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head);
485 if (!hdlc_skb) { 490 if (!hdlc_skb) {
486 err("unable to allocate memory for HDLC encoding!");
487 dev_kfree_skb(skb); 491 dev_kfree_skb(skb);
488 return NULL; 492 return NULL;
489 } 493 }
@@ -505,7 +509,7 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
505 } 509 }
506 510
507 /* Finally add FCS (byte stuffed) and flag sequence */ 511 /* Finally add FCS (byte stuffed) and flag sequence */
508 c = (fcs & 0x00ff); /* least significant byte first */ 512 c = (fcs & 0x00ff); /* least significant byte first */
509 if (muststuff(c)) { 513 if (muststuff(c)) {
510 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE; 514 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE;
511 c ^= PPP_TRANS; 515 c ^= PPP_TRANS;
@@ -543,7 +547,6 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
543 /* worst case: every byte must be stuffed */ 547 /* worst case: every byte must be stuffed */
544 iraw_skb = dev_alloc_skb(2*skb->len + tail + head); 548 iraw_skb = dev_alloc_skb(2*skb->len + tail + head);
545 if (!iraw_skb) { 549 if (!iraw_skb) {
546 err("unable to allocate memory for HDLC encoding!");
547 dev_kfree_skb(skb); 550 dev_kfree_skb(skb);
548 return NULL; 551 return NULL;
549 } 552 }
@@ -584,8 +587,11 @@ int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb)
584 skb = HDLC_Encode(skb, HW_HDR_LEN, 0); 587 skb = HDLC_Encode(skb, HW_HDR_LEN, 0);
585 else 588 else
586 skb = iraw_encode(skb, HW_HDR_LEN, 0); 589 skb = iraw_encode(skb, HW_HDR_LEN, 0);
587 if (!skb) 590 if (!skb) {
591 dev_err(bcs->cs->dev,
592 "unable to allocate memory for encoding!\n");
588 return -ENOMEM; 593 return -ENOMEM;
594 }
589 595
590 skb_queue_tail(&bcs->squeue, skb); 596 skb_queue_tail(&bcs->squeue, skb);
591 tasklet_schedule(&bcs->cs->write_tasklet); 597 tasklet_schedule(&bcs->cs->write_tasklet);