diff options
Diffstat (limited to 'drivers/isdn')
-rw-r--r-- | drivers/isdn/gigaset/common.c | 41 | ||||
-rw-r--r-- | drivers/isdn/gigaset/gigaset.h | 42 |
2 files changed, 43 insertions, 40 deletions
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c index 2ea4976aa02a..5155c5b07a06 100644 --- a/drivers/isdn/gigaset/common.c +++ b/drivers/isdn/gigaset/common.c | |||
@@ -521,6 +521,47 @@ static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs, | |||
521 | inbuf->inputstate = inputstate; | 521 | inbuf->inputstate = inputstate; |
522 | } | 522 | } |
523 | 523 | ||
524 | /* append received bytes to inbuf */ | ||
525 | int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, | ||
526 | unsigned numbytes) | ||
527 | { | ||
528 | unsigned n, head, tail, bytesleft; | ||
529 | |||
530 | gig_dbg(DEBUG_INTR, "received %u bytes", numbytes); | ||
531 | |||
532 | if (!numbytes) | ||
533 | return 0; | ||
534 | |||
535 | bytesleft = numbytes; | ||
536 | tail = atomic_read(&inbuf->tail); | ||
537 | head = atomic_read(&inbuf->head); | ||
538 | gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); | ||
539 | |||
540 | while (bytesleft) { | ||
541 | if (head > tail) | ||
542 | n = head - 1 - tail; | ||
543 | else if (head == 0) | ||
544 | n = (RBUFSIZE-1) - tail; | ||
545 | else | ||
546 | n = RBUFSIZE - tail; | ||
547 | if (!n) { | ||
548 | dev_err(inbuf->cs->dev, | ||
549 | "buffer overflow (%u bytes lost)", bytesleft); | ||
550 | break; | ||
551 | } | ||
552 | if (n > bytesleft) | ||
553 | n = bytesleft; | ||
554 | memcpy(inbuf->data + tail, src, n); | ||
555 | bytesleft -= n; | ||
556 | tail = (tail + n) % RBUFSIZE; | ||
557 | src += n; | ||
558 | } | ||
559 | gig_dbg(DEBUG_INTR, "setting tail to %u", tail); | ||
560 | atomic_set(&inbuf->tail, tail); | ||
561 | return numbytes != bytesleft; | ||
562 | } | ||
563 | EXPORT_SYMBOL_GPL(gigaset_fill_inbuf); | ||
564 | |||
524 | /* Initialize the b-channel structure */ | 565 | /* Initialize the b-channel structure */ |
525 | static struct bc_state *gigaset_initbcs(struct bc_state *bcs, | 566 | static struct bc_state *gigaset_initbcs(struct bc_state *bcs, |
526 | struct cardstate *cs, int channel) | 567 | struct cardstate *cs, int channel) |
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h index 7acae34e66e0..446a078224a9 100644 --- a/drivers/isdn/gigaset/gigaset.h +++ b/drivers/isdn/gigaset/gigaset.h | |||
@@ -902,47 +902,9 @@ static inline void gigaset_rcv_error(struct sk_buff *procskb, | |||
902 | /* bitwise byte inversion table */ | 902 | /* bitwise byte inversion table */ |
903 | extern __u8 gigaset_invtab[]; /* in common.c */ | 903 | extern __u8 gigaset_invtab[]; /* in common.c */ |
904 | 904 | ||
905 | |||
906 | /* append received bytes to inbuf */ | 905 | /* append received bytes to inbuf */ |
907 | static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf, | 906 | int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, |
908 | const unsigned char *src, | 907 | unsigned numbytes); |
909 | unsigned numbytes) | ||
910 | { | ||
911 | unsigned n, head, tail, bytesleft; | ||
912 | |||
913 | gig_dbg(DEBUG_INTR, "received %u bytes", numbytes); | ||
914 | |||
915 | if (!numbytes) | ||
916 | return 0; | ||
917 | |||
918 | bytesleft = numbytes; | ||
919 | tail = atomic_read(&inbuf->tail); | ||
920 | head = atomic_read(&inbuf->head); | ||
921 | gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); | ||
922 | |||
923 | while (bytesleft) { | ||
924 | if (head > tail) | ||
925 | n = head - 1 - tail; | ||
926 | else if (head == 0) | ||
927 | n = (RBUFSIZE-1) - tail; | ||
928 | else | ||
929 | n = RBUFSIZE - tail; | ||
930 | if (!n) { | ||
931 | dev_err(inbuf->cs->dev, | ||
932 | "buffer overflow (%u bytes lost)", bytesleft); | ||
933 | break; | ||
934 | } | ||
935 | if (n > bytesleft) | ||
936 | n = bytesleft; | ||
937 | memcpy(inbuf->data + tail, src, n); | ||
938 | bytesleft -= n; | ||
939 | tail = (tail + n) % RBUFSIZE; | ||
940 | src += n; | ||
941 | } | ||
942 | gig_dbg(DEBUG_INTR, "setting tail to %u", tail); | ||
943 | atomic_set(&inbuf->tail, tail); | ||
944 | return numbytes != bytesleft; | ||
945 | } | ||
946 | 908 | ||
947 | /* =========================================================================== | 909 | /* =========================================================================== |
948 | * Functions implemented in interface.c | 910 | * Functions implemented in interface.c |