Lines Matching refs:sl
48 static void x25_asy_unesc(struct x25_asy *sl, unsigned char c);
55 struct x25_asy *sl;
68 sl = netdev_priv(dev);
70 if (!test_and_set_bit(SLF_INUSE, &sl->flags))
71 return sl;
90 sl = netdev_priv(dev);
96 set_bit(SLF_INUSE, &sl->flags);
98 return sl;
109 static void x25_asy_free(struct x25_asy *sl)
112 kfree(sl->rbuff);
113 sl->rbuff = NULL;
114 kfree(sl->xbuff);
115 sl->xbuff = NULL;
117 if (!test_and_clear_bit(SLF_INUSE, &sl->flags))
118 netdev_err(sl->dev, "x25_asy_free for already free unit\n");
123 struct x25_asy *sl = netdev_priv(dev);
137 spin_lock_bh(&sl->lock);
138 xbuff = xchg(&sl->xbuff, xbuff);
139 if (sl->xleft) {
140 if (sl->xleft <= len) {
141 memcpy(sl->xbuff, sl->xhead, sl->xleft);
143 sl->xleft = 0;
147 sl->xhead = sl->xbuff;
149 rbuff = xchg(&sl->rbuff, rbuff);
150 if (sl->rcount) {
151 if (sl->rcount <= len) {
152 memcpy(sl->rbuff, rbuff, sl->rcount);
154 sl->rcount = 0;
156 set_bit(SLF_ERROR, &sl->flags);
161 sl->buffsize = len;
163 spin_unlock_bh(&sl->lock);
173 static inline void x25_asy_lock(struct x25_asy *sl)
175 netif_stop_queue(sl->dev);
181 static inline void x25_asy_unlock(struct x25_asy *sl)
183 netif_wake_queue(sl->dev);
188 static void x25_asy_bump(struct x25_asy *sl)
190 struct net_device *dev = sl->dev;
195 count = sl->rcount;
200 netdev_warn(sl->dev, "memory squeeze, dropping packet\n");
204 skb_put_data(skb, sl->rbuff, count);
205 err = lapb_data_received(sl->dev, skb);
215 static void x25_asy_encaps(struct x25_asy *sl, unsigned char *icp, int len)
218 int actual, count, mtu = sl->dev->mtu;
224 sl->dev->name);
225 sl->dev->stats.tx_dropped++;
226 x25_asy_unlock(sl);
231 count = x25_asy_esc(p, sl->xbuff, len);
241 set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
242 actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
243 sl->xleft = count - actual;
244 sl->xhead = sl->xbuff + actual;
254 struct x25_asy *sl = tty->disc_data;
257 if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev))
260 if (sl->xleft <= 0) {
263 sl->dev->stats.tx_packets++;
265 x25_asy_unlock(sl);
269 actual = tty->ops->write(tty, sl->xhead, sl->xleft);
270 sl->xleft -= actual;
271 sl->xhead += actual;
276 struct x25_asy *sl = netdev_priv(dev);
278 spin_lock(&sl->lock);
284 (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
286 sl->xleft = 0;
287 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
288 x25_asy_unlock(sl);
290 spin_unlock(&sl->lock);
298 struct x25_asy *sl = netdev_priv(dev);
301 if (!netif_running(sl->dev)) {
388 struct x25_asy *sl = netdev_priv(dev);
390 spin_lock(&sl->lock);
391 if (netif_queue_stopped(sl->dev) || sl->tty == NULL) {
392 spin_unlock(&sl->lock);
399 x25_asy_lock(sl);
401 x25_asy_encaps(sl, skb->data, skb->len);
404 spin_unlock(&sl->lock);
413 struct x25_asy *sl = netdev_priv(dev);
426 skb->protocol = x25_type_trans(skb, sl->dev);
432 struct x25_asy *sl = netdev_priv(dev);
445 skb->protocol = x25_type_trans(skb, sl->dev);
462 struct x25_asy *sl = netdev_priv(dev);
465 if (sl->tty == NULL)
477 sl->rbuff = kmalloc(len + 4, GFP_KERNEL);
478 if (sl->rbuff == NULL)
480 sl->xbuff = kmalloc(len + 4, GFP_KERNEL);
481 if (sl->xbuff == NULL)
484 sl->buffsize = len;
485 sl->rcount = 0;
486 sl->xleft = 0;
487 sl->flags &= (1 << SLF_INUSE); /* Clear ESCAPE & ERROR flags */
492 kfree(sl->xbuff);
493 sl->xbuff = NULL;
495 kfree(sl->rbuff);
496 sl->rbuff = NULL;
505 struct x25_asy *sl = netdev_priv(dev);
507 spin_lock(&sl->lock);
508 if (sl->tty)
509 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
511 sl->rcount = 0;
512 sl->xleft = 0;
513 spin_unlock(&sl->lock);
527 struct x25_asy *sl = tty->disc_data;
529 if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev))
536 if (!test_and_set_bit(SLF_ERROR, &sl->flags))
537 sl->dev->stats.rx_errors++;
541 x25_asy_unesc(sl, *cp++);
555 struct x25_asy *sl;
562 sl = x25_asy_alloc();
563 if (sl == NULL)
566 sl->tty = tty;
567 tty->disc_data = sl;
573 sl->dev->type = ARPHRD_X25;
576 err = x25_asy_open(sl->dev);
578 x25_asy_free(sl);
594 struct x25_asy *sl = tty->disc_data;
597 if (!sl || sl->magic != X25_ASY_MAGIC)
601 if (sl->dev->flags & IFF_UP)
602 dev_close(sl->dev);
606 sl->tty = NULL;
607 x25_asy_free(sl);
651 static void x25_asy_unesc(struct x25_asy *sl, unsigned char s)
656 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
657 sl->rcount >= 2)
658 x25_asy_bump(sl);
659 clear_bit(SLF_ESCAPE, &sl->flags);
660 sl->rcount = 0;
663 set_bit(SLF_ESCAPE, &sl->flags);
667 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
671 if (!test_bit(SLF_ERROR, &sl->flags)) {
672 if (sl->rcount < sl->buffsize) {
673 sl->rbuff[sl->rcount++] = s;
676 sl->dev->stats.rx_over_errors++;
677 set_bit(SLF_ERROR, &sl->flags);
686 struct x25_asy *sl = tty->disc_data;
689 if (!sl || sl->magic != X25_ASY_MAGIC)
694 if (copy_to_user((void __user *)arg, sl->dev->name,
695 strlen(sl->dev->name) + 1))
708 struct x25_asy *sl = netdev_priv(dev);
709 if (sl->tty == NULL)
748 struct x25_asy *sl = netdev_priv(dev);
750 sl->magic = X25_ASY_MAGIC;
751 sl->dev = dev;
752 spin_lock_init(&sl->lock);
753 set_bit(SLF_INUSE, &sl->flags);
815 struct x25_asy *sl = netdev_priv(dev);
817 spin_lock_bh(&sl->lock);
818 if (sl->tty)
819 tty_hangup(sl->tty);
821 spin_unlock_bh(&sl->lock);