aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/isocdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/gigaset/isocdata.c')
-rw-r--r--drivers/isdn/gigaset/isocdata.c186
1 files changed, 93 insertions, 93 deletions
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
index 9f3ef7b4248c..85394a6ebae8 100644
--- a/drivers/isdn/gigaset/isocdata.c
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -41,7 +41,8 @@ static inline int isowbuf_freebytes(struct isowbuf_t *iwb)
41 41
42 read = iwb->read; 42 read = iwb->read;
43 write = iwb->write; 43 write = iwb->write;
44 if ((freebytes = read - write) > 0) { 44 freebytes = read - write;
45 if (freebytes > 0) {
45 /* no wraparound: need padding space within regular area */ 46 /* no wraparound: need padding space within regular area */
46 return freebytes - BAS_OUTBUFPAD; 47 return freebytes - BAS_OUTBUFPAD;
47 } else if (read < BAS_OUTBUFPAD) { 48 } else if (read < BAS_OUTBUFPAD) {
@@ -53,29 +54,6 @@ static inline int isowbuf_freebytes(struct isowbuf_t *iwb)
53 } 54 }
54} 55}
55 56
56/* compare two offsets within the buffer
57 * The buffer is seen as circular, with the read position as start
58 * returns -1/0/1 if position a </=/> position b without crossing 'read'
59 */
60static inline int isowbuf_poscmp(struct isowbuf_t *iwb, int a, int b)
61{
62 int read;
63 if (a == b)
64 return 0;
65 read = iwb->read;
66 if (a < b) {
67 if (a < read && read <= b)
68 return +1;
69 else
70 return -1;
71 } else {
72 if (b < read && read <= a)
73 return -1;
74 else
75 return +1;
76 }
77}
78
79/* start writing 57/* start writing
80 * acquire the write semaphore 58 * acquire the write semaphore
81 * return true if acquired, false if busy 59 * return true if acquired, false if busy
@@ -271,7 +249,7 @@ static inline void dump_bytes(enum debuglevel level, const char *tag,
271 * bit 14..13 = number of bits added by stuffing 249 * bit 14..13 = number of bits added by stuffing
272 */ 250 */
273static const u16 stufftab[5 * 256] = { 251static const u16 stufftab[5 * 256] = {
274// previous 1s = 0: 252/* previous 1s = 0: */
275 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 253 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
276 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x201f, 254 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x201f,
277 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 255 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
@@ -289,7 +267,7 @@ static const u16 stufftab[5 * 256] = {
289 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x0cef, 267 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x0cef,
290 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x10f7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x2ddf, 268 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x10f7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x2ddf,
291 269
292// previous 1s = 1: 270/* previous 1s = 1: */
293 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x200f, 271 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x200f,
294 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x202f, 272 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x202f,
295 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x204f, 273 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x204f,
@@ -307,7 +285,7 @@ static const u16 stufftab[5 * 256] = {
307 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x2dcf, 285 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x2dcf,
308 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x10f7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x31ef, 286 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x10f7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x31ef,
309 287
310// previous 1s = 2: 288/* previous 1s = 2: */
311 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x2007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x2017, 289 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x2007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x2017,
312 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x2027, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x2037, 290 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x2027, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x2037,
313 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x2047, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x2057, 291 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x2047, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x2057,
@@ -325,7 +303,7 @@ static const u16 stufftab[5 * 256] = {
325 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x2dc7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x2dd7, 303 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x2dc7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x2dd7,
326 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x31e7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x41f7, 304 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x31e7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x41f7,
327 305
328// previous 1s = 3: 306/* previous 1s = 3: */
329 0x0000, 0x0001, 0x0002, 0x2003, 0x0004, 0x0005, 0x0006, 0x200b, 0x0008, 0x0009, 0x000a, 0x2013, 0x000c, 0x000d, 0x000e, 0x201b, 307 0x0000, 0x0001, 0x0002, 0x2003, 0x0004, 0x0005, 0x0006, 0x200b, 0x0008, 0x0009, 0x000a, 0x2013, 0x000c, 0x000d, 0x000e, 0x201b,
330 0x0010, 0x0011, 0x0012, 0x2023, 0x0014, 0x0015, 0x0016, 0x202b, 0x0018, 0x0019, 0x001a, 0x2033, 0x001c, 0x001d, 0x001e, 0x203b, 308 0x0010, 0x0011, 0x0012, 0x2023, 0x0014, 0x0015, 0x0016, 0x202b, 0x0018, 0x0019, 0x001a, 0x2033, 0x001c, 0x001d, 0x001e, 0x203b,
331 0x0020, 0x0021, 0x0022, 0x2043, 0x0024, 0x0025, 0x0026, 0x204b, 0x0028, 0x0029, 0x002a, 0x2053, 0x002c, 0x002d, 0x002e, 0x205b, 309 0x0020, 0x0021, 0x0022, 0x2043, 0x0024, 0x0025, 0x0026, 0x204b, 0x0028, 0x0029, 0x002a, 0x2053, 0x002c, 0x002d, 0x002e, 0x205b,
@@ -343,7 +321,7 @@ static const u16 stufftab[5 * 256] = {
343 0x0ce0, 0x0ce1, 0x0ce2, 0x2dc3, 0x0ce4, 0x0ce5, 0x0ce6, 0x2dcb, 0x0ce8, 0x0ce9, 0x0cea, 0x2dd3, 0x0cec, 0x0ced, 0x0cee, 0x2ddb, 321 0x0ce0, 0x0ce1, 0x0ce2, 0x2dc3, 0x0ce4, 0x0ce5, 0x0ce6, 0x2dcb, 0x0ce8, 0x0ce9, 0x0cea, 0x2dd3, 0x0cec, 0x0ced, 0x0cee, 0x2ddb,
344 0x10f0, 0x10f1, 0x10f2, 0x31e3, 0x10f4, 0x10f5, 0x10f6, 0x31eb, 0x20f8, 0x20f9, 0x20fa, 0x41f3, 0x257c, 0x257d, 0x29be, 0x46fb, 322 0x10f0, 0x10f1, 0x10f2, 0x31e3, 0x10f4, 0x10f5, 0x10f6, 0x31eb, 0x20f8, 0x20f9, 0x20fa, 0x41f3, 0x257c, 0x257d, 0x29be, 0x46fb,
345 323
346// previous 1s = 4: 324/* previous 1s = 4: */
347 0x0000, 0x2001, 0x0002, 0x2005, 0x0004, 0x2009, 0x0006, 0x200d, 0x0008, 0x2011, 0x000a, 0x2015, 0x000c, 0x2019, 0x000e, 0x201d, 325 0x0000, 0x2001, 0x0002, 0x2005, 0x0004, 0x2009, 0x0006, 0x200d, 0x0008, 0x2011, 0x000a, 0x2015, 0x000c, 0x2019, 0x000e, 0x201d,
348 0x0010, 0x2021, 0x0012, 0x2025, 0x0014, 0x2029, 0x0016, 0x202d, 0x0018, 0x2031, 0x001a, 0x2035, 0x001c, 0x2039, 0x001e, 0x203d, 326 0x0010, 0x2021, 0x0012, 0x2025, 0x0014, 0x2029, 0x0016, 0x202d, 0x0018, 0x2031, 0x001a, 0x2035, 0x001c, 0x2039, 0x001e, 0x203d,
349 0x0020, 0x2041, 0x0022, 0x2045, 0x0024, 0x2049, 0x0026, 0x204d, 0x0028, 0x2051, 0x002a, 0x2055, 0x002c, 0x2059, 0x002e, 0x205d, 327 0x0020, 0x2041, 0x0022, 0x2045, 0x0024, 0x2049, 0x0026, 0x204d, 0x0028, 0x2051, 0x002a, 0x2055, 0x002c, 0x2059, 0x002e, 0x205d,
@@ -367,7 +345,8 @@ static const u16 stufftab[5 * 256] = {
367 * parameters: 345 * parameters:
368 * cin input byte 346 * cin input byte
369 * ones number of trailing '1' bits in result before this step 347 * ones number of trailing '1' bits in result before this step
370 * iwb pointer to output buffer structure (write semaphore must be held) 348 * iwb pointer to output buffer structure
349 * (write semaphore must be held)
371 * return value: 350 * return value:
372 * number of trailing '1' bits in result after this step 351 * number of trailing '1' bits in result after this step
373 */ 352 */
@@ -408,7 +387,8 @@ static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin,
408 * parameters: 387 * parameters:
409 * in input buffer 388 * in input buffer
410 * count number of bytes in input buffer 389 * count number of bytes in input buffer
411 * iwb pointer to output buffer structure (write semaphore must be held) 390 * iwb pointer to output buffer structure
391 * (write semaphore must be held)
412 * return value: 392 * return value:
413 * position of end of packet in output buffer on success, 393 * position of end of packet in output buffer on success,
414 * -EAGAIN if write semaphore busy or buffer full 394 * -EAGAIN if write semaphore busy or buffer full
@@ -440,7 +420,8 @@ static inline int hdlc_buildframe(struct isowbuf_t *iwb,
440 fcs = crc_ccitt_byte(fcs, c); 420 fcs = crc_ccitt_byte(fcs, c);
441 } 421 }
442 422
443 /* bitstuff and append FCS (complemented, least significant byte first) */ 423 /* bitstuff and append FCS
424 * (complemented, least significant byte first) */
444 fcs ^= 0xffff; 425 fcs ^= 0xffff;
445 ones = hdlc_bitstuff_byte(iwb, fcs & 0x00ff, ones); 426 ones = hdlc_bitstuff_byte(iwb, fcs & 0x00ff, ones);
446 ones = hdlc_bitstuff_byte(iwb, (fcs >> 8) & 0x00ff, ones); 427 ones = hdlc_bitstuff_byte(iwb, (fcs >> 8) & 0x00ff, ones);
@@ -459,7 +440,8 @@ static inline int hdlc_buildframe(struct isowbuf_t *iwb,
459 * parameters: 440 * parameters:
460 * in input buffer 441 * in input buffer
461 * count number of bytes in input buffer 442 * count number of bytes in input buffer
462 * iwb pointer to output buffer structure (write semaphore must be held) 443 * iwb pointer to output buffer structure
444 * (write semaphore must be held)
463 * return value: 445 * return value:
464 * position of end of packet in output buffer on success, 446 * position of end of packet in output buffer on success,
465 * -EAGAIN if write semaphore busy or buffer full 447 * -EAGAIN if write semaphore busy or buffer full
@@ -500,7 +482,7 @@ int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len)
500 int result; 482 int result;
501 483
502 switch (bcs->proto2) { 484 switch (bcs->proto2) {
503 case ISDN_PROTO_L2_HDLC: 485 case L2_HDLC:
504 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len); 486 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len);
505 gig_dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d", 487 gig_dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d",
506 __func__, len, result); 488 __func__, len, result);
@@ -542,8 +524,9 @@ static inline void hdlc_flush(struct bc_state *bcs)
542 if (likely(bcs->skb != NULL)) 524 if (likely(bcs->skb != NULL))
543 skb_trim(bcs->skb, 0); 525 skb_trim(bcs->skb, 0);
544 else if (!bcs->ignore) { 526 else if (!bcs->ignore) {
545 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 527 bcs->skb = dev_alloc_skb(SBUFSIZE + bcs->cs->hw_hdr_len);
546 skb_reserve(bcs->skb, HW_HDR_LEN); 528 if (bcs->skb)
529 skb_reserve(bcs->skb, bcs->cs->hw_hdr_len);
547 else 530 else
548 dev_err(bcs->cs->dev, "could not allocate skb\n"); 531 dev_err(bcs->cs->dev, "could not allocate skb\n");
549 } 532 }
@@ -557,43 +540,46 @@ static inline void hdlc_flush(struct bc_state *bcs)
557 */ 540 */
558static inline void hdlc_done(struct bc_state *bcs) 541static inline void hdlc_done(struct bc_state *bcs)
559{ 542{
543 struct cardstate *cs = bcs->cs;
560 struct sk_buff *procskb; 544 struct sk_buff *procskb;
545 unsigned int len;
561 546
562 if (unlikely(bcs->ignore)) { 547 if (unlikely(bcs->ignore)) {
563 bcs->ignore--; 548 bcs->ignore--;
564 hdlc_flush(bcs); 549 hdlc_flush(bcs);
565 return; 550 return;
566 } 551 }
567 552 procskb = bcs->skb;
568 if ((procskb = bcs->skb) == NULL) { 553 if (procskb == NULL) {
569 /* previous error */ 554 /* previous error */
570 gig_dbg(DEBUG_ISO, "%s: skb=NULL", __func__); 555 gig_dbg(DEBUG_ISO, "%s: skb=NULL", __func__);
571 gigaset_rcv_error(NULL, bcs->cs, bcs); 556 gigaset_isdn_rcv_err(bcs);
572 } else if (procskb->len < 2) { 557 } else if (procskb->len < 2) {
573 dev_notice(bcs->cs->dev, "received short frame (%d octets)\n", 558 dev_notice(cs->dev, "received short frame (%d octets)\n",
574 procskb->len); 559 procskb->len);
575 bcs->hw.bas->runts++; 560 bcs->hw.bas->runts++;
576 gigaset_rcv_error(procskb, bcs->cs, bcs); 561 dev_kfree_skb_any(procskb);
562 gigaset_isdn_rcv_err(bcs);
577 } else if (bcs->fcs != PPP_GOODFCS) { 563 } else if (bcs->fcs != PPP_GOODFCS) {
578 dev_notice(bcs->cs->dev, "frame check error (0x%04x)\n", 564 dev_notice(cs->dev, "frame check error (0x%04x)\n", bcs->fcs);
579 bcs->fcs);
580 bcs->hw.bas->fcserrs++; 565 bcs->hw.bas->fcserrs++;
581 gigaset_rcv_error(procskb, bcs->cs, bcs); 566 dev_kfree_skb_any(procskb);
567 gigaset_isdn_rcv_err(bcs);
582 } else { 568 } else {
583 procskb->len -= 2; /* subtract FCS */ 569 len = procskb->len;
584 procskb->tail -= 2; 570 __skb_trim(procskb, len -= 2); /* subtract FCS */
585 gig_dbg(DEBUG_ISO, "%s: good frame (%d octets)", 571 gig_dbg(DEBUG_ISO, "%s: good frame (%d octets)", __func__, len);
586 __func__, procskb->len);
587 dump_bytes(DEBUG_STREAM_DUMP, 572 dump_bytes(DEBUG_STREAM_DUMP,
588 "rcv data", procskb->data, procskb->len); 573 "rcv data", procskb->data, len);
589 bcs->hw.bas->goodbytes += procskb->len; 574 bcs->hw.bas->goodbytes += len;
590 gigaset_rcv_skb(procskb, bcs->cs, bcs); 575 gigaset_skb_rcvd(bcs, procskb);
591 } 576 }
592 577
593 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 578 bcs->skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
594 skb_reserve(bcs->skb, HW_HDR_LEN); 579 if (bcs->skb)
580 skb_reserve(bcs->skb, cs->hw_hdr_len);
595 else 581 else
596 dev_err(bcs->cs->dev, "could not allocate skb\n"); 582 dev_err(cs->dev, "could not allocate skb\n");
597 bcs->fcs = PPP_INITFCS; 583 bcs->fcs = PPP_INITFCS;
598} 584}
599 585
@@ -610,12 +596,8 @@ static inline void hdlc_frag(struct bc_state *bcs, unsigned inbits)
610 596
611 dev_notice(bcs->cs->dev, "received partial byte (%d bits)\n", inbits); 597 dev_notice(bcs->cs->dev, "received partial byte (%d bits)\n", inbits);
612 bcs->hw.bas->alignerrs++; 598 bcs->hw.bas->alignerrs++;
613 gigaset_rcv_error(bcs->skb, bcs->cs, bcs); 599 gigaset_isdn_rcv_err(bcs);
614 600 __skb_trim(bcs->skb, 0);
615 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
616 skb_reserve(bcs->skb, HW_HDR_LEN);
617 else
618 dev_err(bcs->cs->dev, "could not allocate skb\n");
619 bcs->fcs = PPP_INITFCS; 601 bcs->fcs = PPP_INITFCS;
620} 602}
621 603
@@ -646,10 +628,10 @@ static const unsigned char bitcounts[256] = {
646}; 628};
647 629
648/* hdlc_unpack 630/* hdlc_unpack
649 * perform HDLC frame processing (bit unstuffing, flag detection, FCS calculation) 631 * perform HDLC frame processing (bit unstuffing, flag detection, FCS
650 * on a sequence of received data bytes (8 bits each, LSB first) 632 * calculation) on a sequence of received data bytes (8 bits each, LSB first)
651 * pass on successfully received, complete frames as SKBs via gigaset_rcv_skb 633 * pass on successfully received, complete frames as SKBs via gigaset_skb_rcvd
652 * notify of errors via gigaset_rcv_error 634 * notify of errors via gigaset_isdn_rcv_err
653 * tally frames, errors etc. in BC structure counters 635 * tally frames, errors etc. in BC structure counters
654 * parameters: 636 * parameters:
655 * src received data 637 * src received data
@@ -665,9 +647,12 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
665 647
666 /* load previous state: 648 /* load previous state:
667 * inputstate = set of flag bits: 649 * inputstate = set of flag bits:
668 * - INS_flag_hunt: no complete opening flag received since connection setup or last abort 650 * - INS_flag_hunt: no complete opening flag received since connection
669 * - INS_have_data: at least one complete data byte received since last flag 651 * setup or last abort
670 * seqlen = number of consecutive '1' bits in last 7 input stream bits (0..7) 652 * - INS_have_data: at least one complete data byte received since last
653 * flag
654 * seqlen = number of consecutive '1' bits in last 7 input stream bits
655 * (0..7)
671 * inbyte = accumulated partial data byte (if !INS_flag_hunt) 656 * inbyte = accumulated partial data byte (if !INS_flag_hunt)
672 * inbits = number of valid bits in inbyte, starting at LSB (0..6) 657 * inbits = number of valid bits in inbyte, starting at LSB (0..6)
673 */ 658 */
@@ -701,9 +686,11 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
701 inbyte = c >> (lead1 + 1); 686 inbyte = c >> (lead1 + 1);
702 inbits = 7 - lead1; 687 inbits = 7 - lead1;
703 if (trail1 >= 8) { 688 if (trail1 >= 8) {
704 /* interior stuffing: omitting the MSB handles most cases */ 689 /* interior stuffing:
690 * omitting the MSB handles most cases,
691 * correct the incorrectly handled
692 * cases individually */
705 inbits--; 693 inbits--;
706 /* correct the incorrectly handled cases individually */
707 switch (c) { 694 switch (c) {
708 case 0xbe: 695 case 0xbe:
709 inbyte = 0x3f; 696 inbyte = 0x3f;
@@ -729,13 +716,14 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
729 hdlc_flush(bcs); 716 hdlc_flush(bcs);
730 inputstate |= INS_flag_hunt; 717 inputstate |= INS_flag_hunt;
731 } else if (seqlen == 6) { 718 } else if (seqlen == 6) {
732 /* closing flag, including (6 - lead1) '1's and one '0' from inbits */ 719 /* closing flag, including (6 - lead1) '1's
720 * and one '0' from inbits */
733 if (inbits > 7 - lead1) { 721 if (inbits > 7 - lead1) {
734 hdlc_frag(bcs, inbits + lead1 - 7); 722 hdlc_frag(bcs, inbits + lead1 - 7);
735 inputstate &= ~INS_have_data; 723 inputstate &= ~INS_have_data;
736 } else { 724 } else {
737 if (inbits < 7 - lead1) 725 if (inbits < 7 - lead1)
738 ubc->stolen0s ++; 726 ubc->stolen0s++;
739 if (inputstate & INS_have_data) { 727 if (inputstate & INS_have_data) {
740 hdlc_done(bcs); 728 hdlc_done(bcs);
741 inputstate &= ~INS_have_data; 729 inputstate &= ~INS_have_data;
@@ -744,7 +732,7 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
744 732
745 if (c == PPP_FLAG) { 733 if (c == PPP_FLAG) {
746 /* complete flag, LSB overlaps preceding flag */ 734 /* complete flag, LSB overlaps preceding flag */
747 ubc->shared0s ++; 735 ubc->shared0s++;
748 inbits = 0; 736 inbits = 0;
749 inbyte = 0; 737 inbyte = 0;
750 } else if (trail1 != 7) { 738 } else if (trail1 != 7) {
@@ -752,9 +740,11 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
752 inbyte = c >> (lead1 + 1); 740 inbyte = c >> (lead1 + 1);
753 inbits = 7 - lead1; 741 inbits = 7 - lead1;
754 if (trail1 >= 8) { 742 if (trail1 >= 8) {
755 /* interior stuffing: omitting the MSB handles most cases */ 743 /* interior stuffing:
744 * omitting the MSB handles most cases,
745 * correct the incorrectly handled
746 * cases individually */
756 inbits--; 747 inbits--;
757 /* correct the incorrectly handled cases individually */
758 switch (c) { 748 switch (c) {
759 case 0xbe: 749 case 0xbe:
760 inbyte = 0x3f; 750 inbyte = 0x3f;
@@ -762,7 +752,8 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
762 } 752 }
763 } 753 }
764 } else { 754 } else {
765 /* abort sequence follows, skb already empty anyway */ 755 /* abort sequence follows,
756 * skb already empty anyway */
766 ubc->aborts++; 757 ubc->aborts++;
767 inputstate |= INS_flag_hunt; 758 inputstate |= INS_flag_hunt;
768 } 759 }
@@ -787,14 +778,17 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
787 } else { 778 } else {
788 /* stuffed data */ 779 /* stuffed data */
789 if (trail1 < 7) { /* => seqlen == 5 */ 780 if (trail1 < 7) { /* => seqlen == 5 */
790 /* stuff bit at position lead1, no interior stuffing */ 781 /* stuff bit at position lead1,
782 * no interior stuffing */
791 unsigned char mask = (1 << lead1) - 1; 783 unsigned char mask = (1 << lead1) - 1;
792 c = (c & mask) | ((c & ~mask) >> 1); 784 c = (c & mask) | ((c & ~mask) >> 1);
793 inbyte |= c << inbits; 785 inbyte |= c << inbits;
794 inbits += 7; 786 inbits += 7;
795 } else if (seqlen < 5) { /* trail1 >= 8 */ 787 } else if (seqlen < 5) { /* trail1 >= 8 */
796 /* interior stuffing: omitting the MSB handles most cases */ 788 /* interior stuffing:
797 /* correct the incorrectly handled cases individually */ 789 * omitting the MSB handles most cases,
790 * correct the incorrectly handled
791 * cases individually */
798 switch (c) { 792 switch (c) {
799 case 0xbe: 793 case 0xbe:
800 c = 0x7e; 794 c = 0x7e;
@@ -804,8 +798,9 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
804 inbits += 7; 798 inbits += 7;
805 } else { /* seqlen == 5 && trail1 >= 8 */ 799 } else { /* seqlen == 5 && trail1 >= 8 */
806 800
807 /* stuff bit at lead1 *and* interior stuffing */ 801 /* stuff bit at lead1 *and* interior
808 switch (c) { /* unstuff individually */ 802 * stuffing -- unstuff individually */
803 switch (c) {
809 case 0x7d: 804 case 0x7d:
810 c = 0x3f; 805 c = 0x3f;
811 break; 806 break;
@@ -841,7 +836,7 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
841} 836}
842 837
843/* trans_receive 838/* trans_receive
844 * pass on received USB frame transparently as SKB via gigaset_rcv_skb 839 * pass on received USB frame transparently as SKB via gigaset_skb_rcvd
845 * invert bytes 840 * invert bytes
846 * tally frames, errors etc. in BC structure counters 841 * tally frames, errors etc. in BC structure counters
847 * parameters: 842 * parameters:
@@ -852,6 +847,7 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
852static inline void trans_receive(unsigned char *src, unsigned count, 847static inline void trans_receive(unsigned char *src, unsigned count,
853 struct bc_state *bcs) 848 struct bc_state *bcs)
854{ 849{
850 struct cardstate *cs = bcs->cs;
855 struct sk_buff *skb; 851 struct sk_buff *skb;
856 int dobytes; 852 int dobytes;
857 unsigned char *dst; 853 unsigned char *dst;
@@ -861,13 +857,14 @@ static inline void trans_receive(unsigned char *src, unsigned count,
861 hdlc_flush(bcs); 857 hdlc_flush(bcs);
862 return; 858 return;
863 } 859 }
864 if (unlikely((skb = bcs->skb) == NULL)) { 860 skb = bcs->skb;
865 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 861 if (unlikely(skb == NULL)) {
862 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
866 if (!skb) { 863 if (!skb) {
867 dev_err(bcs->cs->dev, "could not allocate skb\n"); 864 dev_err(cs->dev, "could not allocate skb\n");
868 return; 865 return;
869 } 866 }
870 skb_reserve(skb, HW_HDR_LEN); 867 skb_reserve(skb, cs->hw_hdr_len);
871 } 868 }
872 bcs->hw.bas->goodbytes += skb->len; 869 bcs->hw.bas->goodbytes += skb->len;
873 dobytes = TRANSBUFSIZE - skb->len; 870 dobytes = TRANSBUFSIZE - skb->len;
@@ -881,23 +878,24 @@ static inline void trans_receive(unsigned char *src, unsigned count,
881 if (dobytes == 0) { 878 if (dobytes == 0) {
882 dump_bytes(DEBUG_STREAM_DUMP, 879 dump_bytes(DEBUG_STREAM_DUMP,
883 "rcv data", skb->data, skb->len); 880 "rcv data", skb->data, skb->len);
884 gigaset_rcv_skb(skb, bcs->cs, bcs); 881 gigaset_skb_rcvd(bcs, skb);
885 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 882 bcs->skb = skb =
883 dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
886 if (!skb) { 884 if (!skb) {
887 dev_err(bcs->cs->dev, 885 dev_err(cs->dev, "could not allocate skb\n");
888 "could not allocate skb\n");
889 return; 886 return;
890 } 887 }
891 skb_reserve(bcs->skb, HW_HDR_LEN); 888 skb_reserve(skb, cs->hw_hdr_len);
892 dobytes = TRANSBUFSIZE; 889 dobytes = TRANSBUFSIZE;
893 } 890 }
894 } 891 }
895} 892}
896 893
897void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs) 894void gigaset_isoc_receive(unsigned char *src, unsigned count,
895 struct bc_state *bcs)
898{ 896{
899 switch (bcs->proto2) { 897 switch (bcs->proto2) {
900 case ISDN_PROTO_L2_HDLC: 898 case L2_HDLC:
901 hdlc_unpack(src, count, bcs); 899 hdlc_unpack(src, count, bcs);
902 break; 900 break;
903 default: /* assume transparent */ 901 default: /* assume transparent */
@@ -981,8 +979,10 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
981 * @bcs: B channel descriptor structure. 979 * @bcs: B channel descriptor structure.
982 * @skb: data to send. 980 * @skb: data to send.
983 * 981 *
984 * Called by i4l.c to queue an skb for sending, and start transmission if 982 * Called by LL to queue an skb for sending, and start transmission if
985 * necessary. 983 * necessary.
984 * Once the payload data has been transmitted completely, gigaset_skb_sent()
985 * will be called with the skb's link layer header preserved.
986 * 986 *
987 * Return value: 987 * Return value:
988 * number of bytes accepted for sending (skb->len) if ok, 988 * number of bytes accepted for sending (skb->len) if ok,