Lines Matching refs:ap

97 static int ppp_async_encode(struct asyncppp *ap);
99 static int ppp_async_push(struct asyncppp *ap);
100 static void ppp_async_flush_output(struct asyncppp *ap);
101 static void ppp_async_input(struct asyncppp *ap, const unsigned char *buf,
107 static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,
135 struct asyncppp *ap;
138 ap = tty->disc_data;
139 if (ap != NULL)
140 refcount_inc(&ap->refcnt);
142 return ap;
145 static void ap_put(struct asyncppp *ap)
147 if (refcount_dec_and_test(&ap->refcnt))
148 complete(&ap->dead);
158 struct asyncppp *ap;
166 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
167 if (!ap)
171 ap->tty = tty;
172 ap->mru = PPP_MRU;
173 spin_lock_init(&ap->xmit_lock);
174 spin_lock_init(&ap->recv_lock);
175 ap->xaccm[0] = ~0U;
176 ap->xaccm[3] = 0x60000000U;
177 ap->raccm = ~0U;
178 ap->optr = ap->obuf;
179 ap->olim = ap->obuf;
180 ap->lcp_fcs = -1;
182 skb_queue_head_init(&ap->rqueue);
183 tasklet_setup(&ap->tsk, ppp_async_process);
185 refcount_set(&ap->refcnt, 1);
186 init_completion(&ap->dead);
188 ap->chan.private = ap;
189 ap->chan.ops = &async_ops;
190 ap->chan.mtu = PPP_MRU;
192 ap->chan.speed = speed;
193 err = ppp_register_channel(&ap->chan);
197 tty->disc_data = ap;
202 kfree(ap);
218 struct asyncppp *ap;
221 ap = tty->disc_data;
224 if (!ap)
228 * We have now ensured that nobody can start using ap from now
234 if (!refcount_dec_and_test(&ap->refcnt))
235 wait_for_completion(&ap->dead);
236 tasklet_kill(&ap->tsk);
238 ppp_unregister_channel(&ap->chan);
239 kfree_skb(ap->rpkt);
240 skb_queue_purge(&ap->rqueue);
241 kfree_skb(ap->tpkt);
242 kfree(ap);
286 struct asyncppp *ap = ap_get(tty);
290 if (!ap)
296 if (put_user(ppp_channel_index(&ap->chan), p))
303 if (put_user(ppp_unit_number(&ap->chan), p))
311 ppp_async_flush_output(ap);
327 ap_put(ap);
336 struct asyncppp *ap = ap_get(tty);
339 if (!ap)
341 spin_lock_irqsave(&ap->recv_lock, flags);
342 ppp_async_input(ap, buf, cflags, count);
343 spin_unlock_irqrestore(&ap->recv_lock, flags);
344 if (!skb_queue_empty(&ap->rqueue))
345 tasklet_schedule(&ap->tsk);
346 ap_put(ap);
353 struct asyncppp *ap = ap_get(tty);
356 if (!ap)
358 set_bit(XMIT_WAKEUP, &ap->xmit_flags);
359 tasklet_schedule(&ap->tsk);
360 ap_put(ap);
396 struct asyncppp *ap = chan->private;
405 val = ap->flags | ap->rbits;
413 ap->flags = val & ~SC_RCV_BITS;
414 spin_lock_irq(&ap->recv_lock);
415 ap->rbits = val & SC_RCV_BITS;
416 spin_unlock_irq(&ap->recv_lock);
421 if (put_user(ap->xaccm[0], (u32 __user *)argp))
426 if (get_user(ap->xaccm[0], (u32 __user *)argp))
432 if (put_user(ap->raccm, (u32 __user *)argp))
437 if (get_user(ap->raccm, (u32 __user *)argp))
443 if (copy_to_user(argp, ap->xaccm, sizeof(ap->xaccm)))
452 memcpy(ap->xaccm, accm, sizeof(ap->xaccm));
457 if (put_user(ap->mru, p))
470 ap->mru = val;
488 struct asyncppp *ap = from_tasklet(ap, t, tsk);
492 while ((skb = skb_dequeue(&ap->rqueue)) != NULL) {
494 ppp_input_error(&ap->chan, 0);
495 ppp_input(&ap->chan, skb);
499 if (test_bit(XMIT_WAKEUP, &ap->xmit_flags) && ppp_async_push(ap))
500 ppp_output_wakeup(&ap->chan);
511 * Assumes ap->tpkt != 0 on entry.
515 #define PUT_BYTE(ap, buf, c, islcp) do { \
516 if ((islcp && c < 0x20) || (ap->xaccm[c >> 5] & (1 << (c & 0x1f)))) {\
524 ppp_async_encode(struct asyncppp *ap)
531 buf = ap->obuf;
532 ap->olim = buf;
533 ap->optr = buf;
534 i = ap->tpkt_pos;
535 data = ap->tpkt->data;
536 count = ap->tpkt->len;
537 fcs = ap->tfcs;
549 async_lcp_peek(ap, data, count, 0);
556 time_after_eq(jiffies, ap->last_xmit + flag_time))
558 ap->last_xmit = jiffies;
564 if ((ap->flags & SC_COMP_AC) == 0 || islcp) {
565 PUT_BYTE(ap, buf, 0xff, islcp);
567 PUT_BYTE(ap, buf, 0x03, islcp);
577 buflim = ap->obuf + OBUFSIZE - 6;
580 if (i == 1 && c == 0 && (ap->flags & SC_COMP_PROT))
583 PUT_BYTE(ap, buf, c, islcp);
590 ap->olim = buf;
591 ap->tpkt_pos = i;
592 ap->tfcs = fcs;
601 PUT_BYTE(ap, buf, c, islcp);
603 PUT_BYTE(ap, buf, c, islcp);
605 ap->olim = buf;
607 consume_skb(ap->tpkt);
608 ap->tpkt = NULL;
625 struct asyncppp *ap = chan->private;
627 ppp_async_push(ap);
629 if (test_and_set_bit(XMIT_FULL, &ap->xmit_flags))
631 ap->tpkt = skb;
632 ap->tpkt_pos = 0;
634 ppp_async_push(ap);
642 ppp_async_push(struct asyncppp *ap)
645 struct tty_struct *tty = ap->tty;
657 if (test_and_set_bit(XMIT_BUSY, &ap->xmit_flags))
659 spin_lock_bh(&ap->xmit_lock);
661 if (test_and_clear_bit(XMIT_WAKEUP, &ap->xmit_flags))
663 if (!tty_stuffed && ap->optr < ap->olim) {
664 avail = ap->olim - ap->optr;
666 sent = tty->ops->write(tty, ap->optr, avail);
669 ap->optr += sent;
674 if (ap->optr >= ap->olim && ap->tpkt) {
675 if (ppp_async_encode(ap)) {
676 /* finished processing ap->tpkt */
677 clear_bit(XMIT_FULL, &ap->xmit_flags);
691 clear_bit(XMIT_BUSY, &ap->xmit_flags);
693 if (!(test_bit(XMIT_WAKEUP, &ap->xmit_flags) ||
694 (!tty_stuffed && ap->tpkt)))
697 if (test_and_set_bit(XMIT_BUSY, &ap->xmit_flags))
700 spin_unlock_bh(&ap->xmit_lock);
704 clear_bit(XMIT_BUSY, &ap->xmit_flags);
705 if (ap->tpkt) {
706 kfree_skb(ap->tpkt);
707 ap->tpkt = NULL;
708 clear_bit(XMIT_FULL, &ap->xmit_flags);
711 ap->optr = ap->olim;
712 spin_unlock_bh(&ap->xmit_lock);
722 ppp_async_flush_output(struct asyncppp *ap)
726 spin_lock_bh(&ap->xmit_lock);
727 ap->optr = ap->olim;
728 if (ap->tpkt != NULL) {
729 kfree_skb(ap->tpkt);
730 ap->tpkt = NULL;
731 clear_bit(XMIT_FULL, &ap->xmit_flags);
734 spin_unlock_bh(&ap->xmit_lock);
736 ppp_output_wakeup(&ap->chan);
745 scan_ordinary(struct asyncppp *ap, const unsigned char *buf, int count)
752 (c < 0x20 && (ap->raccm & (1 << c)) != 0))
760 process_input_packet(struct asyncppp *ap)
766 skb = ap->rpkt;
767 if (ap->state & (SC_TOSS | SC_ESCAPE))
802 async_lcp_peek(ap, p, skb->len, 1);
806 skb->cb[0] = ap->state;
807 skb_queue_tail(&ap->rqueue, skb);
808 ap->rpkt = NULL;
809 ap->state = 0;
814 ap->state = SC_PREV_ERROR;
826 ppp_async_input(struct asyncppp *ap, const u8 *buf, const u8 *flags, int count)
833 if (~ap->rbits & SC_RCV_BITS) {
843 ap->rbits |= s;
848 if ((ap->state & SC_ESCAPE) && buf[0] == PPP_ESCAPE)
851 n = scan_ordinary(ap, buf, count);
854 if (flags && (ap->state & SC_TOSS) == 0) {
862 ap->state |= SC_TOSS;
864 } else if (n > 0 && (ap->state & SC_TOSS) == 0) {
866 skb = ap->rpkt;
868 skb = dev_alloc_skb(ap->mru + PPP_HDRLEN + 2);
871 ap->rpkt = skb;
885 ap->state |= SC_TOSS;
888 if (ap->state & SC_ESCAPE) {
890 ap->state &= ~SC_ESCAPE;
900 ap->state |= SC_TOSS;
902 process_input_packet(ap);
904 ap->state |= SC_ESCAPE;
905 } else if (I_IXON(ap->tty)) {
906 if (c == START_CHAR(ap->tty))
907 start_tty(ap->tty);
908 else if (c == STOP_CHAR(ap->tty))
909 stop_tty(ap->tty);
923 ap->state |= SC_TOSS;
944 static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,
972 ap->lcp_fcs = fcs;
977 fcs ^= ap->lcp_fcs;
978 ap->lcp_fcs = -1;
993 ap->mru = val;
995 ap->chan.mtu = val;
1000 ap->raccm = val;
1002 ap->xaccm[0] = val;