Lines Matching refs:sl
104 static void slip_unesc(struct slip *sl, unsigned char c);
107 static void slip_unesc6(struct slip *sl, unsigned char c);
130 static int sl_alloc_bufs(struct slip *sl, int mtu) in sl_alloc_bufs() argument
171 spin_lock_bh(&sl->lock); in sl_alloc_bufs()
172 if (sl->tty == NULL) { in sl_alloc_bufs()
173 spin_unlock_bh(&sl->lock); in sl_alloc_bufs()
177 sl->mtu = mtu; in sl_alloc_bufs()
178 sl->buffsize = len; in sl_alloc_bufs()
179 sl->rcount = 0; in sl_alloc_bufs()
180 sl->xleft = 0; in sl_alloc_bufs()
181 rbuff = xchg(&sl->rbuff, rbuff); in sl_alloc_bufs()
182 xbuff = xchg(&sl->xbuff, xbuff); in sl_alloc_bufs()
184 cbuff = xchg(&sl->cbuff, cbuff); in sl_alloc_bufs()
185 slcomp = xchg(&sl->slcomp, slcomp); in sl_alloc_bufs()
188 sl->xdata = 0; in sl_alloc_bufs()
189 sl->xbits = 0; in sl_alloc_bufs()
191 spin_unlock_bh(&sl->lock); in sl_alloc_bufs()
206 static void sl_free_bufs(struct slip *sl) in sl_free_bufs() argument
209 kfree(xchg(&sl->rbuff, NULL)); in sl_free_bufs()
210 kfree(xchg(&sl->xbuff, NULL)); in sl_free_bufs()
212 kfree(xchg(&sl->cbuff, NULL)); in sl_free_bufs()
213 slhc_free(xchg(&sl->slcomp, NULL)); in sl_free_bufs()
221 static int sl_realloc_bufs(struct slip *sl, int mtu) argument
224 struct net_device *dev = sl->dev;
251 if (mtu > sl->mtu) {
258 spin_lock_bh(&sl->lock);
261 if (sl->tty == NULL)
264 xbuff = xchg(&sl->xbuff, xbuff);
265 rbuff = xchg(&sl->rbuff, rbuff);
267 cbuff = xchg(&sl->cbuff, cbuff);
269 if (sl->xleft) {
270 if (sl->xleft <= len) {
271 memcpy(sl->xbuff, sl->xhead, sl->xleft);
273 sl->xleft = 0;
277 sl->xhead = sl->xbuff;
279 if (sl->rcount) {
280 if (sl->rcount <= len) {
281 memcpy(sl->rbuff, rbuff, sl->rcount);
283 sl->rcount = 0;
285 set_bit(SLF_ERROR, &sl->flags);
288 sl->mtu = mtu;
290 sl->buffsize = len;
294 spin_unlock_bh(&sl->lock);
307 static inline void sl_lock(struct slip *sl) argument
309 netif_stop_queue(sl->dev);
314 static inline void sl_unlock(struct slip *sl) argument
316 netif_wake_queue(sl->dev);
320 static void sl_bump(struct slip *sl) argument
322 struct net_device *dev = sl->dev;
326 count = sl->rcount;
328 if (sl->mode & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) {
329 unsigned char c = sl->rbuff[0];
332 if (!(sl->mode & SL_MODE_CSLIP)) {
338 if (count + 80 > sl->buffsize) {
342 count = slhc_uncompress(sl->slcomp, sl->rbuff, count);
346 if (!(sl->mode & SL_MODE_CSLIP)) {
348 sl->mode |= SL_MODE_CSLIP;
349 sl->mode &= ~SL_MODE_ADAPTIVE;
352 sl->rbuff[0] &= 0x4f;
353 if (slhc_remember(sl->slcomp, sl->rbuff, count) <= 0)
368 skb_put_data(skb, sl->rbuff, count);
376 static void sl_encaps(struct slip *sl, unsigned char *icp, int len) argument
381 if (len > sl->mtu) { /* Sigh, shouldn't occur BUT ... */
382 printk(KERN_WARNING "%s: truncating oversized transmit packet!\n", sl->dev->name);
383 sl->dev->stats.tx_dropped++;
384 sl_unlock(sl);
390 if (sl->mode & SL_MODE_CSLIP)
391 len = slhc_compress(sl->slcomp, p, len, sl->cbuff, &p, 1);
394 if (sl->mode & SL_MODE_SLIP6)
395 count = slip_esc6(p, sl->xbuff, len);
398 count = slip_esc(p, sl->xbuff, len);
408 set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
409 actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
411 netif_trans_update(sl->dev);
413 sl->xleft = count - actual;
414 sl->xhead = sl->xbuff + actual;
417 clear_bit(SLF_OUTWAIT, &sl->flags); /* reset outfill flag */
424 struct slip *sl = container_of(work, struct slip, tx_work); local
427 spin_lock_bh(&sl->lock);
429 if (!sl->tty || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) {
430 spin_unlock_bh(&sl->lock);
434 if (sl->xleft <= 0) {
437 sl->dev->stats.tx_packets++;
438 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
439 spin_unlock_bh(&sl->lock);
440 sl_unlock(sl);
444 actual = sl->tty->ops->write(sl->tty, sl->xhead, sl->xleft);
445 sl->xleft -= actual;
446 sl->xhead += actual;
447 spin_unlock_bh(&sl->lock);
456 struct slip *sl; local
459 sl = rcu_dereference(tty->disc_data);
460 if (sl)
461 schedule_work(&sl->tx_work);
467 struct slip *sl = netdev_priv(dev); local
469 spin_lock(&sl->lock);
472 if (!netif_running(dev) || !sl->tty)
485 (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
487 sl->xleft = 0;
488 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
489 sl_unlock(sl);
493 spin_unlock(&sl->lock);
501 struct slip *sl = netdev_priv(dev); local
503 spin_lock(&sl->lock);
505 spin_unlock(&sl->lock);
510 if (sl->tty == NULL) {
511 spin_unlock(&sl->lock);
516 sl_lock(sl);
518 sl_encaps(sl, skb->data, skb->len);
519 spin_unlock(&sl->lock);
535 struct slip *sl = netdev_priv(dev); local
537 spin_lock_bh(&sl->lock);
538 if (sl->tty)
540 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
542 sl->rcount = 0;
543 sl->xleft = 0;
544 spin_unlock_bh(&sl->lock);
553 struct slip *sl = netdev_priv(dev); local
555 if (sl->tty == NULL)
558 sl->flags &= (1 << SLF_INUSE);
567 struct slip *sl = netdev_priv(dev); local
569 return sl_realloc_bufs(sl, new_mtu);
579 struct slip *sl = netdev_priv(dev); local
580 struct slcompress *comp = sl->slcomp;
611 struct slip *sl = netdev_priv(dev); local
617 dev->mtu = sl->mtu;
618 dev->type = ARPHRD_SLIP + sl->mode;
628 struct slip *sl = netdev_priv(dev); local
630 sl_free_bufs(sl);
691 struct slip *sl = tty->disc_data; local
693 if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev))
699 if (!test_and_set_bit(SLF_ERROR, &sl->flags))
700 sl->dev->stats.rx_errors++;
705 if (sl->mode & SL_MODE_SLIP6)
706 slip_unesc6(sl, *cp++);
709 slip_unesc(sl, *cp++);
722 struct slip *sl; local
729 sl = netdev_priv(dev);
730 if (sl->tty || sl->leased)
744 struct slip *sl; local
756 dev = alloc_netdev(sizeof(*sl), name, NET_NAME_UNKNOWN, sl_setup);
761 sl = netdev_priv(dev);
764 sl->magic = SLIP_MAGIC;
765 sl->dev = dev;
766 spin_lock_init(&sl->lock);
767 INIT_WORK(&sl->tx_work, slip_transmit);
768 sl->mode = SL_MODE_DEFAULT;
771 timer_setup(&sl->keepalive_timer, sl_keepalive, 0);
772 timer_setup(&sl->outfill_timer, sl_outfill, 0);
775 return sl;
790 struct slip *sl; local
808 sl = tty->disc_data;
812 if (sl && sl->magic == SLIP_MAGIC)
817 sl = sl_alloc();
818 if (sl == NULL)
821 sl->tty = tty;
822 tty->disc_data = sl;
823 sl->pid = current->pid;
825 if (!test_bit(SLF_INUSE, &sl->flags)) {
827 err = sl_alloc_bufs(sl, SL_MTU);
831 set_bit(SLF_INUSE, &sl->flags);
833 err = register_netdevice(sl->dev);
839 if (sl->keepalive) {
840 sl->keepalive_timer.expires = jiffies + sl->keepalive * HZ;
841 add_timer(&sl->keepalive_timer);
843 if (sl->outfill) {
844 sl->outfill_timer.expires = jiffies + sl->outfill * HZ;
845 add_timer(&sl->outfill_timer);
857 sl_free_bufs(sl);
860 sl->tty = NULL;
862 clear_bit(SLF_INUSE, &sl->flags);
863 sl_free_netdev(sl->dev);
866 free_netdev(sl->dev);
886 struct slip *sl = tty->disc_data; local
889 if (!sl || sl->magic != SLIP_MAGIC || sl->tty != tty)
892 spin_lock_bh(&sl->lock);
894 sl->tty = NULL;
895 spin_unlock_bh(&sl->lock);
898 flush_work(&sl->tx_work);
902 del_timer_sync(&sl->keepalive_timer);
903 del_timer_sync(&sl->outfill_timer);
906 unregister_netdev(sl->dev);
955 static void slip_unesc(struct slip *sl, unsigned char s) argument
962 if (test_bit(SLF_KEEPTEST, &sl->flags))
963 clear_bit(SLF_KEEPTEST, &sl->flags);
966 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
967 (sl->rcount > 2))
968 sl_bump(sl);
969 clear_bit(SLF_ESCAPE, &sl->flags);
970 sl->rcount = 0;
974 set_bit(SLF_ESCAPE, &sl->flags);
977 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
981 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
985 if (!test_bit(SLF_ERROR, &sl->flags)) {
986 if (sl->rcount < sl->buffsize) {
987 sl->rbuff[sl->rcount++] = s;
990 sl->dev->stats.rx_over_errors++;
991 set_bit(SLF_ERROR, &sl->flags);
1038 static void slip_unesc6(struct slip *sl, unsigned char s) argument
1045 if (test_bit(SLF_KEEPTEST, &sl->flags))
1046 clear_bit(SLF_KEEPTEST, &sl->flags);
1049 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
1050 (sl->rcount > 2))
1051 sl_bump(sl);
1052 sl->rcount = 0;
1053 sl->xbits = 0;
1054 sl->xdata = 0;
1056 sl->xdata = (sl->xdata << 6) | ((s - 0x30) & 0x3F);
1057 sl->xbits += 6;
1058 if (sl->xbits >= 8) {
1059 sl->xbits -= 8;
1060 c = (unsigned char)(sl->xdata >> sl->xbits);
1061 if (!test_bit(SLF_ERROR, &sl->flags)) {
1062 if (sl->rcount < sl->buffsize) {
1063 sl->rbuff[sl->rcount++] = c;
1066 sl->dev->stats.rx_over_errors++;
1067 set_bit(SLF_ERROR, &sl->flags);
1078 struct slip *sl = tty->disc_data; local
1083 if (!sl || sl->magic != SLIP_MAGIC)
1088 tmp = strlen(sl->dev->name) + 1;
1089 if (copy_to_user((void __user *)arg, sl->dev->name, tmp))
1094 if (put_user(sl->mode, p))
1114 sl->mode = tmp;
1115 sl->dev->type = ARPHRD_SLIP + sl->mode;
1129 spin_lock_bh(&sl->lock);
1130 if (!sl->tty) {
1131 spin_unlock_bh(&sl->lock);
1134 sl->keepalive = (u8)tmp;
1135 if (sl->keepalive != 0) {
1136 mod_timer(&sl->keepalive_timer,
1137 jiffies + sl->keepalive * HZ);
1138 set_bit(SLF_KEEPTEST, &sl->flags);
1140 del_timer(&sl->keepalive_timer);
1141 spin_unlock_bh(&sl->lock);
1145 if (put_user(sl->keepalive, p))
1154 spin_lock_bh(&sl->lock);
1155 if (!sl->tty) {
1156 spin_unlock_bh(&sl->lock);
1159 sl->outfill = (u8)tmp;
1160 if (sl->outfill != 0) {
1161 mod_timer(&sl->outfill_timer,
1162 jiffies + sl->outfill * HZ);
1163 set_bit(SLF_OUTWAIT, &sl->flags);
1165 del_timer(&sl->outfill_timer);
1166 spin_unlock_bh(&sl->lock);
1170 if (put_user(sl->outfill, p))
1189 struct slip *sl = netdev_priv(dev); local
1192 if (sl == NULL) /* Allocation failed ?? */
1198 spin_lock_bh(&sl->lock);
1200 if (!sl->tty) {
1201 spin_unlock_bh(&sl->lock);
1209 spin_unlock_bh(&sl->lock);
1212 sl->keepalive = (u8)*p;
1213 if (sl->keepalive != 0) {
1214 sl->keepalive_timer.expires =
1215 jiffies + sl->keepalive * HZ;
1216 mod_timer(&sl->keepalive_timer,
1217 jiffies + sl->keepalive * HZ);
1218 set_bit(SLF_KEEPTEST, &sl->flags);
1220 del_timer(&sl->keepalive_timer);
1224 *p = sl->keepalive;
1229 spin_unlock_bh(&sl->lock);
1232 sl->outfill = (u8)*p;
1233 if (sl->outfill != 0) {
1234 mod_timer(&sl->outfill_timer,
1235 jiffies + sl->outfill * HZ);
1236 set_bit(SLF_OUTWAIT, &sl->flags);
1238 del_timer(&sl->outfill_timer);
1242 *p = sl->outfill;
1249 if (sl->tty != current->signal->tty &&
1250 sl->pid != current->pid) {
1251 spin_unlock_bh(&sl->lock);
1254 sl->leased = 0;
1256 sl->leased = 1;
1260 *p = sl->leased;
1262 spin_unlock_bh(&sl->lock);
1318 struct slip *sl; local
1336 sl = netdev_priv(dev);
1337 spin_lock_bh(&sl->lock);
1338 if (sl->tty) {
1340 tty_hangup(sl->tty);
1342 spin_unlock_bh(&sl->lock);
1355 sl = netdev_priv(dev);
1356 if (sl->tty) {
1381 struct slip *sl = from_timer(sl, t, outfill_timer); local
1383 spin_lock(&sl->lock);
1385 if (sl->tty == NULL)
1388 if (sl->outfill) {
1389 if (test_bit(SLF_OUTWAIT, &sl->flags)) {
1392 unsigned char s = (sl->mode & SL_MODE_SLIP6)?0x70:END;
1397 if (!netif_queue_stopped(sl->dev)) {
1399 sl->tty->ops->write(sl->tty, &s, 1);
1402 set_bit(SLF_OUTWAIT, &sl->flags);
1404 mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ);
1407 spin_unlock(&sl->lock);
1412 struct slip *sl = from_timer(sl, t, keepalive_timer); local
1414 spin_lock(&sl->lock);
1416 if (sl->tty == NULL)
1419 if (sl->keepalive) {
1420 if (test_bit(SLF_KEEPTEST, &sl->flags)) {
1422 if (sl->outfill)
1424 (void)del_timer(&sl->outfill_timer);
1425 printk(KERN_DEBUG "%s: no packets received during keepalive timeout, hangup.\n", sl->dev->name);
1427 tty_hangup(sl->tty);
1431 set_bit(SLF_KEEPTEST, &sl->flags);
1433 mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ);
1436 spin_unlock(&sl->lock);