aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/gigaset/common.c')
-rw-r--r--drivers/isdn/gigaset/common.c41
1 files changed, 41 insertions, 0 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 */
525int 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}
563EXPORT_SYMBOL_GPL(gigaset_fill_inbuf);
564
524/* Initialize the b-channel structure */ 565/* Initialize the b-channel structure */
525static struct bc_state *gigaset_initbcs(struct bc_state *bcs, 566static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
526 struct cardstate *cs, int channel) 567 struct cardstate *cs, int channel)