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 skb_put_data(skb, 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 netif_trans_update(sl->dev);
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
564 return sl_realloc_bufs(sl, new_mtu);
574 struct slip *sl = netdev_priv(dev); local
575 struct slcompress *comp = sl->slcomp;
606 struct slip *sl = netdev_priv(dev); local
612 dev->mtu = sl->mtu;
613 dev->type = ARPHRD_SLIP + sl->mode;
623 struct slip *sl = netdev_priv(dev); local
625 sl_free_bufs(sl);
686 struct slip *sl = tty->disc_data; local
688 if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev))
694 if (!test_and_set_bit(SLF_ERROR, &sl->flags))
695 sl->dev->stats.rx_errors++;
700 if (sl->mode & SL_MODE_SLIP6)
701 slip_unesc6(sl, *cp++);
704 slip_unesc(sl, *cp++);
717 struct slip *sl; local
724 sl = netdev_priv(dev);
725 if (sl->tty || sl->leased)
739 struct slip *sl; local
751 dev = alloc_netdev(sizeof(*sl), name, NET_NAME_UNKNOWN, sl_setup);
756 sl = netdev_priv(dev);
759 sl->magic = SLIP_MAGIC;
760 sl->dev = dev;
761 spin_lock_init(&sl->lock);
762 INIT_WORK(&sl->tx_work, slip_transmit);
763 sl->mode = SL_MODE_DEFAULT;
766 timer_setup(&sl->keepalive_timer, sl_keepalive, 0);
767 timer_setup(&sl->outfill_timer, sl_outfill, 0);
770 return sl;
785 struct slip *sl; local
803 sl = tty->disc_data;
807 if (sl && sl->magic == SLIP_MAGIC)
812 sl = sl_alloc();
813 if (sl == NULL)
816 sl->tty = tty;
817 tty->disc_data = sl;
818 sl->pid = current->pid;
820 if (!test_bit(SLF_INUSE, &sl->flags)) {
822 err = sl_alloc_bufs(sl, SL_MTU);
826 set_bit(SLF_INUSE, &sl->flags);
828 err = register_netdevice(sl->dev);
834 if (sl->keepalive) {
835 sl->keepalive_timer.expires = jiffies + sl->keepalive * HZ;
836 add_timer(&sl->keepalive_timer);
838 if (sl->outfill) {
839 sl->outfill_timer.expires = jiffies + sl->outfill * HZ;
840 add_timer(&sl->outfill_timer);
852 sl_free_bufs(sl);
855 sl->tty = NULL;
857 clear_bit(SLF_INUSE, &sl->flags);
858 free_netdev(sl->dev);
877 struct slip *sl = tty->disc_data; local
880 if (!sl || sl->magic != SLIP_MAGIC || sl->tty != tty)
883 spin_lock_bh(&sl->lock);
885 sl->tty = NULL;
886 spin_unlock_bh(&sl->lock);
888 flush_work(&sl->tx_work);
892 del_timer_sync(&sl->keepalive_timer);
893 del_timer_sync(&sl->outfill_timer);
896 unregister_netdev(sl->dev);
946 static void slip_unesc(struct slip *sl, unsigned char s) argument
953 if (test_bit(SLF_KEEPTEST, &sl->flags))
954 clear_bit(SLF_KEEPTEST, &sl->flags);
957 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
958 (sl->rcount > 2))
959 sl_bump(sl);
960 clear_bit(SLF_ESCAPE, &sl->flags);
961 sl->rcount = 0;
965 set_bit(SLF_ESCAPE, &sl->flags);
968 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
972 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
976 if (!test_bit(SLF_ERROR, &sl->flags)) {
977 if (sl->rcount < sl->buffsize) {
978 sl->rbuff[sl->rcount++] = s;
981 sl->dev->stats.rx_over_errors++;
982 set_bit(SLF_ERROR, &sl->flags);
1029 static void slip_unesc6(struct slip *sl, unsigned char s) argument
1036 if (test_bit(SLF_KEEPTEST, &sl->flags))
1037 clear_bit(SLF_KEEPTEST, &sl->flags);
1040 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
1041 (sl->rcount > 2))
1042 sl_bump(sl);
1043 sl->rcount = 0;
1044 sl->xbits = 0;
1045 sl->xdata = 0;
1047 sl->xdata = (sl->xdata << 6) | ((s - 0x30) & 0x3F);
1048 sl->xbits += 6;
1049 if (sl->xbits >= 8) {
1050 sl->xbits -= 8;
1051 c = (unsigned char)(sl->xdata >> sl->xbits);
1052 if (!test_bit(SLF_ERROR, &sl->flags)) {
1053 if (sl->rcount < sl->buffsize) {
1054 sl->rbuff[sl->rcount++] = c;
1057 sl->dev->stats.rx_over_errors++;
1058 set_bit(SLF_ERROR, &sl->flags);
1069 struct slip *sl = tty->disc_data; local
1074 if (!sl || sl->magic != SLIP_MAGIC)
1079 tmp = strlen(sl->dev->name) + 1;
1080 if (copy_to_user((void __user *)arg, sl->dev->name, tmp))
1085 if (put_user(sl->mode, p))
1105 sl->mode = tmp;
1106 sl->dev->type = ARPHRD_SLIP + sl->mode;
1120 spin_lock_bh(&sl->lock);
1121 if (!sl->tty) {
1122 spin_unlock_bh(&sl->lock);
1125 sl->keepalive = (u8)tmp;
1126 if (sl->keepalive != 0) {
1127 mod_timer(&sl->keepalive_timer,
1128 jiffies + sl->keepalive * HZ);
1129 set_bit(SLF_KEEPTEST, &sl->flags);
1131 del_timer(&sl->keepalive_timer);
1132 spin_unlock_bh(&sl->lock);
1136 if (put_user(sl->keepalive, p))
1145 spin_lock_bh(&sl->lock);
1146 if (!sl->tty) {
1147 spin_unlock_bh(&sl->lock);
1150 sl->outfill = (u8)tmp;
1151 if (sl->outfill != 0) {
1152 mod_timer(&sl->outfill_timer,
1153 jiffies + sl->outfill * HZ);
1154 set_bit(SLF_OUTWAIT, &sl->flags);
1156 del_timer(&sl->outfill_timer);
1157 spin_unlock_bh(&sl->lock);
1161 if (put_user(sl->outfill, p))
1179 struct slip *sl = netdev_priv(dev); local
1182 if (sl == NULL) /* Allocation failed ?? */
1185 spin_lock_bh(&sl->lock);
1187 if (!sl->tty) {
1188 spin_unlock_bh(&sl->lock);
1196 spin_unlock_bh(&sl->lock);
1199 sl->keepalive = (u8)*p;
1200 if (sl->keepalive != 0) {
1201 sl->keepalive_timer.expires =
1202 jiffies + sl->keepalive * HZ;
1203 mod_timer(&sl->keepalive_timer,
1204 jiffies + sl->keepalive * HZ);
1205 set_bit(SLF_KEEPTEST, &sl->flags);
1207 del_timer(&sl->keepalive_timer);
1211 *p = sl->keepalive;
1216 spin_unlock_bh(&sl->lock);
1219 sl->outfill = (u8)*p;
1220 if (sl->outfill != 0) {
1221 mod_timer(&sl->outfill_timer,
1222 jiffies + sl->outfill * HZ);
1223 set_bit(SLF_OUTWAIT, &sl->flags);
1225 del_timer(&sl->outfill_timer);
1229 *p = sl->outfill;
1236 if (sl->tty != current->signal->tty &&
1237 sl->pid != current->pid) {
1238 spin_unlock_bh(&sl->lock);
1241 sl->leased = 0;
1243 sl->leased = 1;
1247 *p = sl->leased;
1249 spin_unlock_bh(&sl->lock);
1305 struct slip *sl; local
1323 sl = netdev_priv(dev);
1324 spin_lock_bh(&sl->lock);
1325 if (sl->tty) {
1327 tty_hangup(sl->tty);
1329 spin_unlock_bh(&sl->lock);
1342 sl = netdev_priv(dev);
1343 if (sl->tty) {
1370 struct slip *sl = from_timer(sl, t, outfill_timer); local
1372 spin_lock(&sl->lock);
1374 if (sl->tty == NULL)
1377 if (sl->outfill) {
1378 if (test_bit(SLF_OUTWAIT, &sl->flags)) {
1381 unsigned char s = (sl->mode & SL_MODE_SLIP6)?0x70:END;
1386 if (!netif_queue_stopped(sl->dev)) {
1388 sl->tty->ops->write(sl->tty, &s, 1);
1391 set_bit(SLF_OUTWAIT, &sl->flags);
1393 mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ);
1396 spin_unlock(&sl->lock);
1401 struct slip *sl = from_timer(sl, t, keepalive_timer); local
1403 spin_lock(&sl->lock);
1405 if (sl->tty == NULL)
1408 if (sl->keepalive) {
1409 if (test_bit(SLF_KEEPTEST, &sl->flags)) {
1411 if (sl->outfill)
1413 (void)del_timer(&sl->outfill_timer);
1414 printk(KERN_DEBUG "%s: no packets received during keepalive timeout, hangup.\n", sl->dev->name);
1416 tty_hangup(sl->tty);
1420 set_bit(SLF_KEEPTEST, &sl->flags);
1422 mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ);
1425 spin_unlock(&sl->lock);