Lines Matching refs:sl
103 static void slip_unesc(struct slip *sl, unsigned char c);
106 static void slip_unesc6(struct slip *sl, unsigned char c);
129 static int sl_alloc_bufs(struct slip *sl, int mtu) in sl_alloc_bufs() argument
170 spin_lock_bh(&sl->lock); in sl_alloc_bufs()
171 if (sl->tty == NULL) { in sl_alloc_bufs()
172 spin_unlock_bh(&sl->lock); in sl_alloc_bufs()
176 sl->mtu = mtu; in sl_alloc_bufs()
177 sl->buffsize = len; in sl_alloc_bufs()
178 sl->rcount = 0; in sl_alloc_bufs()
179 sl->xleft = 0; in sl_alloc_bufs()
180 rbuff = xchg(&sl->rbuff, rbuff); in sl_alloc_bufs()
181 xbuff = xchg(&sl->xbuff, xbuff); in sl_alloc_bufs()
183 cbuff = xchg(&sl->cbuff, cbuff); in sl_alloc_bufs()
184 slcomp = xchg(&sl->slcomp, slcomp); in sl_alloc_bufs()
187 sl->xdata = 0; in sl_alloc_bufs()
188 sl->xbits = 0; in sl_alloc_bufs()
190 spin_unlock_bh(&sl->lock); in sl_alloc_bufs()
205 static void sl_free_bufs(struct slip *sl) in sl_free_bufs() argument
208 kfree(xchg(&sl->rbuff, NULL)); in sl_free_bufs()
209 kfree(xchg(&sl->xbuff, NULL)); in sl_free_bufs()
211 kfree(xchg(&sl->cbuff, NULL)); in sl_free_bufs()
212 slhc_free(xchg(&sl->slcomp, NULL)); in sl_free_bufs()
220 static int sl_realloc_bufs(struct slip *sl, int mtu) argument
223 struct net_device *dev = sl->dev;
250 if (mtu > sl->mtu) {
257 spin_lock_bh(&sl->lock);
260 if (sl->tty == NULL)
263 xbuff = xchg(&sl->xbuff, xbuff);
264 rbuff = xchg(&sl->rbuff, rbuff);
266 cbuff = xchg(&sl->cbuff, cbuff);
268 if (sl->xleft) {
269 if (sl->xleft <= len) {
270 memcpy(sl->xbuff, sl->xhead, sl->xleft);
272 sl->xleft = 0;
276 sl->xhead = sl->xbuff;
278 if (sl->rcount) {
279 if (sl->rcount <= len) {
280 memcpy(sl->rbuff, rbuff, sl->rcount);
282 sl->rcount = 0;
284 set_bit(SLF_ERROR, &sl->flags);
287 sl->mtu = mtu;
289 sl->buffsize = len;
293 spin_unlock_bh(&sl->lock);
306 static inline void sl_lock(struct slip *sl) argument
308 netif_stop_queue(sl->dev);
313 static inline void sl_unlock(struct slip *sl) argument
315 netif_wake_queue(sl->dev);
319 static void sl_bump(struct slip *sl) argument
321 struct net_device *dev = sl->dev;
325 count = sl->rcount;
327 if (sl->mode & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) {
328 unsigned char c = sl->rbuff[0];
331 if (!(sl->mode & SL_MODE_CSLIP)) {
337 if (count + 80 > sl->buffsize) {
341 count = slhc_uncompress(sl->slcomp, sl->rbuff, count);
345 if (!(sl->mode & SL_MODE_CSLIP)) {
347 sl->mode |= SL_MODE_CSLIP;
348 sl->mode &= ~SL_MODE_ADAPTIVE;
351 sl->rbuff[0] &= 0x4f;
352 if (slhc_remember(sl->slcomp, sl->rbuff, count) <= 0)
367 memcpy(skb_put(skb, count), sl->rbuff, count);
375 static void sl_encaps(struct slip *sl, unsigned char *icp, int len) argument
380 if (len > sl->mtu) { /* Sigh, shouldn't occur BUT ... */
381 printk(KERN_WARNING "%s: truncating oversized transmit packet!\n", sl->dev->name);
382 sl->dev->stats.tx_dropped++;
383 sl_unlock(sl);
389 if (sl->mode & SL_MODE_CSLIP)
390 len = slhc_compress(sl->slcomp, p, len, sl->cbuff, &p, 1);
393 if (sl->mode & SL_MODE_SLIP6)
394 count = slip_esc6(p, sl->xbuff, len);
397 count = slip_esc(p, sl->xbuff, len);
407 set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
408 actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
410 sl->dev->trans_start = jiffies;
412 sl->xleft = count - actual;
413 sl->xhead = sl->xbuff + actual;
416 clear_bit(SLF_OUTWAIT, &sl->flags); /* reset outfill flag */
423 struct slip *sl = container_of(work, struct slip, tx_work); local
426 spin_lock_bh(&sl->lock);
428 if (!sl->tty || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) {
429 spin_unlock_bh(&sl->lock);
433 if (sl->xleft <= 0) {
436 sl->dev->stats.tx_packets++;
437 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
438 spin_unlock_bh(&sl->lock);
439 sl_unlock(sl);
443 actual = sl->tty->ops->write(sl->tty, sl->xhead, sl->xleft);
444 sl->xleft -= actual;
445 sl->xhead += actual;
446 spin_unlock_bh(&sl->lock);
455 struct slip *sl = tty->disc_data; local
457 schedule_work(&sl->tx_work);
462 struct slip *sl = netdev_priv(dev); local
464 spin_lock(&sl->lock);
480 (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
482 sl->xleft = 0;
483 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
484 sl_unlock(sl);
488 spin_unlock(&sl->lock);
496 struct slip *sl = netdev_priv(dev); local
498 spin_lock(&sl->lock);
500 spin_unlock(&sl->lock);
505 if (sl->tty == NULL) {
506 spin_unlock(&sl->lock);
511 sl_lock(sl);
513 sl_encaps(sl, skb->data, skb->len);
514 spin_unlock(&sl->lock);
530 struct slip *sl = netdev_priv(dev); local
532 spin_lock_bh(&sl->lock);
533 if (sl->tty)
535 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
537 sl->rcount = 0;
538 sl->xleft = 0;
539 spin_unlock_bh(&sl->lock);
548 struct slip *sl = netdev_priv(dev); local
550 if (sl->tty == NULL)
553 sl->flags &= (1 << SLF_INUSE);
562 struct slip *sl = netdev_priv(dev); local
568 return sl_realloc_bufs(sl, new_mtu);
579 struct slip *sl = netdev_priv(dev); local
580 struct slcompress *comp = sl->slcomp;
612 struct slip *sl = netdev_priv(dev); local
618 dev->mtu = sl->mtu;
619 dev->type = ARPHRD_SLIP + sl->mode;
629 struct slip *sl = netdev_priv(dev); local
631 sl_free_bufs(sl);
687 struct slip *sl = tty->disc_data; local
689 if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev))
695 if (!test_and_set_bit(SLF_ERROR, &sl->flags))
696 sl->dev->stats.rx_errors++;
701 if (sl->mode & SL_MODE_SLIP6)
702 slip_unesc6(sl, *cp++);
705 slip_unesc(sl, *cp++);
718 struct slip *sl; local
725 sl = netdev_priv(dev);
726 if (sl->tty || sl->leased)
740 struct slip *sl; local
752 dev = alloc_netdev(sizeof(*sl), name, NET_NAME_UNKNOWN, sl_setup);
757 sl = netdev_priv(dev);
760 sl->magic = SLIP_MAGIC;
761 sl->dev = dev;
762 spin_lock_init(&sl->lock);
763 INIT_WORK(&sl->tx_work, slip_transmit);
764 sl->mode = SL_MODE_DEFAULT;
767 init_timer(&sl->keepalive_timer);
768 sl->keepalive_timer.data = (unsigned long)sl;
769 sl->keepalive_timer.function = sl_keepalive;
770 init_timer(&sl->outfill_timer);
771 sl->outfill_timer.data = (unsigned long)sl;
772 sl->outfill_timer.function = sl_outfill;
775 return sl;
790 struct slip *sl; local
808 sl = tty->disc_data;
812 if (sl && sl->magic == SLIP_MAGIC)
817 sl = sl_alloc(tty_devnum(tty));
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);
881 struct slip *sl = tty->disc_data; local
884 if (!sl || sl->magic != SLIP_MAGIC || sl->tty != tty)
887 spin_lock_bh(&sl->lock);
889 sl->tty = NULL;
890 spin_unlock_bh(&sl->lock);
892 flush_work(&sl->tx_work);
896 del_timer_sync(&sl->keepalive_timer);
897 del_timer_sync(&sl->outfill_timer);
900 unregister_netdev(sl->dev);
950 static void slip_unesc(struct slip *sl, unsigned char s) argument
957 if (test_bit(SLF_KEEPTEST, &sl->flags))
958 clear_bit(SLF_KEEPTEST, &sl->flags);
961 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
962 (sl->rcount > 2))
963 sl_bump(sl);
964 clear_bit(SLF_ESCAPE, &sl->flags);
965 sl->rcount = 0;
969 set_bit(SLF_ESCAPE, &sl->flags);
972 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
976 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
980 if (!test_bit(SLF_ERROR, &sl->flags)) {
981 if (sl->rcount < sl->buffsize) {
982 sl->rbuff[sl->rcount++] = s;
985 sl->dev->stats.rx_over_errors++;
986 set_bit(SLF_ERROR, &sl->flags);
1033 static void slip_unesc6(struct slip *sl, unsigned char s) argument
1040 if (test_bit(SLF_KEEPTEST, &sl->flags))
1041 clear_bit(SLF_KEEPTEST, &sl->flags);
1044 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
1045 (sl->rcount > 2))
1046 sl_bump(sl);
1047 sl->rcount = 0;
1048 sl->xbits = 0;
1049 sl->xdata = 0;
1051 sl->xdata = (sl->xdata << 6) | ((s - 0x30) & 0x3F);
1052 sl->xbits += 6;
1053 if (sl->xbits >= 8) {
1054 sl->xbits -= 8;
1055 c = (unsigned char)(sl->xdata >> sl->xbits);
1056 if (!test_bit(SLF_ERROR, &sl->flags)) {
1057 if (sl->rcount < sl->buffsize) {
1058 sl->rbuff[sl->rcount++] = c;
1061 sl->dev->stats.rx_over_errors++;
1062 set_bit(SLF_ERROR, &sl->flags);
1073 struct slip *sl = tty->disc_data; local
1078 if (!sl || sl->magic != SLIP_MAGIC)
1083 tmp = strlen(sl->dev->name) + 1;
1084 if (copy_to_user((void __user *)arg, sl->dev->name, tmp))
1089 if (put_user(sl->mode, p))
1109 sl->mode = tmp;
1110 sl->dev->type = ARPHRD_SLIP + sl->mode;
1124 spin_lock_bh(&sl->lock);
1125 if (!sl->tty) {
1126 spin_unlock_bh(&sl->lock);
1129 sl->keepalive = (u8)tmp;
1130 if (sl->keepalive != 0) {
1131 mod_timer(&sl->keepalive_timer,
1132 jiffies + sl->keepalive * HZ);
1133 set_bit(SLF_KEEPTEST, &sl->flags);
1135 del_timer(&sl->keepalive_timer);
1136 spin_unlock_bh(&sl->lock);
1140 if (put_user(sl->keepalive, p))
1149 spin_lock_bh(&sl->lock);
1150 if (!sl->tty) {
1151 spin_unlock_bh(&sl->lock);
1154 sl->outfill = (u8)tmp;
1155 if (sl->outfill != 0) {
1156 mod_timer(&sl->outfill_timer,
1157 jiffies + sl->outfill * HZ);
1158 set_bit(SLF_OUTWAIT, &sl->flags);
1160 del_timer(&sl->outfill_timer);
1161 spin_unlock_bh(&sl->lock);
1165 if (put_user(sl->outfill, p))
1204 struct slip *sl = netdev_priv(dev); local
1207 if (sl == NULL) /* Allocation failed ?? */
1210 spin_lock_bh(&sl->lock);
1212 if (!sl->tty) {
1213 spin_unlock_bh(&sl->lock);
1221 spin_unlock_bh(&sl->lock);
1224 sl->keepalive = (u8)*p;
1225 if (sl->keepalive != 0) {
1226 sl->keepalive_timer.expires =
1227 jiffies + sl->keepalive * HZ;
1228 mod_timer(&sl->keepalive_timer,
1229 jiffies + sl->keepalive * HZ);
1230 set_bit(SLF_KEEPTEST, &sl->flags);
1232 del_timer(&sl->keepalive_timer);
1236 *p = sl->keepalive;
1241 spin_unlock_bh(&sl->lock);
1244 sl->outfill = (u8)*p;
1245 if (sl->outfill != 0) {
1246 mod_timer(&sl->outfill_timer,
1247 jiffies + sl->outfill * HZ);
1248 set_bit(SLF_OUTWAIT, &sl->flags);
1250 del_timer(&sl->outfill_timer);
1254 *p = sl->outfill;
1261 if (sl->tty != current->signal->tty &&
1262 sl->pid != current->pid) {
1263 spin_unlock_bh(&sl->lock);
1266 sl->leased = 0;
1268 sl->leased = 1;
1272 *p = sl->leased;
1274 spin_unlock_bh(&sl->lock);
1333 struct slip *sl; local
1351 sl = netdev_priv(dev);
1352 spin_lock_bh(&sl->lock);
1353 if (sl->tty) {
1355 tty_hangup(sl->tty);
1357 spin_unlock_bh(&sl->lock);
1370 sl = netdev_priv(dev);
1371 if (sl->tty) {
1400 struct slip *sl = (struct slip *)sls; local
1402 spin_lock(&sl->lock);
1404 if (sl->tty == NULL)
1407 if (sl->outfill) {
1408 if (test_bit(SLF_OUTWAIT, &sl->flags)) {
1411 unsigned char s = (sl->mode & SL_MODE_SLIP6)?0x70:END;
1416 if (!netif_queue_stopped(sl->dev)) {
1418 sl->tty->ops->write(sl->tty, &s, 1);
1421 set_bit(SLF_OUTWAIT, &sl->flags);
1423 mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ);
1426 spin_unlock(&sl->lock);
1431 struct slip *sl = (struct slip *)sls; local
1433 spin_lock(&sl->lock);
1435 if (sl->tty == NULL)
1438 if (sl->keepalive) {
1439 if (test_bit(SLF_KEEPTEST, &sl->flags)) {
1441 if (sl->outfill)
1443 (void)del_timer(&sl->outfill_timer);
1444 printk(KERN_DEBUG "%s: no packets received during keepalive timeout, hangup.\n", sl->dev->name);
1446 tty_hangup(sl->tty);
1450 set_bit(SLF_KEEPTEST, &sl->flags);
1452 mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ);
1455 spin_unlock(&sl->lock);