Lines Matching refs:sl
14 * Has a new sl->mtu field.
35 * ifconfig sl? up & down now works
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)
170 spin_lock_bh(&sl->lock);
171 if (sl->tty == NULL) {
172 spin_unlock_bh(&sl->lock);
176 sl->mtu = mtu;
177 sl->buffsize = len;
178 sl->rcount = 0;
179 sl->xleft = 0;
180 rbuff = xchg(&sl->rbuff, rbuff);
181 xbuff = xchg(&sl->xbuff, xbuff);
183 cbuff = xchg(&sl->cbuff, cbuff);
184 slcomp = xchg(&sl->slcomp, slcomp);
187 sl->xdata = 0;
188 sl->xbits = 0;
190 spin_unlock_bh(&sl->lock);
205 static void sl_free_bufs(struct slip *sl)
208 kfree(xchg(&sl->rbuff, NULL));
209 kfree(xchg(&sl->xbuff, NULL));
211 kfree(xchg(&sl->cbuff, NULL));
212 slhc_free(xchg(&sl->slcomp, NULL));
220 static int sl_realloc_bufs(struct slip *sl, int mtu)
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)
308 netif_stop_queue(sl->dev);
313 static inline void sl_unlock(struct slip *sl)
315 netif_wake_queue(sl->dev);
319 static void sl_bump(struct slip *sl)
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)
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);
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;
458 sl = rcu_dereference(tty->disc_data);
459 if (sl)
460 schedule_work(&sl->tx_work);
466 struct slip *sl = netdev_priv(dev);
468 spin_lock(&sl->lock);
471 if (!netif_running(dev) || !sl->tty)
484 (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
486 sl->xleft = 0;
487 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
488 sl_unlock(sl);
492 spin_unlock(&sl->lock);
500 struct slip *sl = netdev_priv(dev);
502 spin_lock(&sl->lock);
504 spin_unlock(&sl->lock);
509 if (sl->tty == NULL) {
510 spin_unlock(&sl->lock);
515 sl_lock(sl);
517 sl_encaps(sl, skb->data, skb->len);
518 spin_unlock(&sl->lock);
534 struct slip *sl = netdev_priv(dev);
536 spin_lock_bh(&sl->lock);
537 if (sl->tty)
539 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
541 sl->rcount = 0;
542 sl->xleft = 0;
543 spin_unlock_bh(&sl->lock);
552 struct slip *sl = netdev_priv(dev);
554 if (sl->tty == NULL)
557 sl->flags &= (1 << SLF_INUSE);
566 struct slip *sl = netdev_priv(dev);
568 return sl_realloc_bufs(sl, new_mtu);
578 struct slip *sl = netdev_priv(dev);
579 struct slcompress *comp = sl->slcomp;
610 struct slip *sl = netdev_priv(dev);
616 dev->mtu = sl->mtu;
617 dev->type = ARPHRD_SLIP + sl->mode;
627 struct slip *sl = netdev_priv(dev);
629 sl_free_bufs(sl);
690 struct slip *sl = tty->disc_data;
692 if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev))
698 if (!test_and_set_bit(SLF_ERROR, &sl->flags))
699 sl->dev->stats.rx_errors++;
704 if (sl->mode & SL_MODE_SLIP6)
705 slip_unesc6(sl, *cp++);
708 slip_unesc(sl, *cp++);
721 struct slip *sl;
728 sl = netdev_priv(dev);
729 if (sl->tty || sl->leased)
743 struct slip *sl;
754 sprintf(name, "sl%d", i);
755 dev = alloc_netdev(sizeof(*sl), name, NET_NAME_UNKNOWN, sl_setup);
760 sl = netdev_priv(dev);
763 sl->magic = SLIP_MAGIC;
764 sl->dev = dev;
765 spin_lock_init(&sl->lock);
766 INIT_WORK(&sl->tx_work, slip_transmit);
767 sl->mode = SL_MODE_DEFAULT;
770 timer_setup(&sl->keepalive_timer, sl_keepalive, 0);
771 timer_setup(&sl->outfill_timer, sl_outfill, 0);
774 return sl;
789 struct slip *sl;
807 sl = tty->disc_data;
811 if (sl && sl->magic == SLIP_MAGIC)
816 sl = sl_alloc();
817 if (sl == NULL)
820 sl->tty = tty;
821 tty->disc_data = sl;
822 sl->pid = current->pid;
824 if (!test_bit(SLF_INUSE, &sl->flags)) {
826 err = sl_alloc_bufs(sl, SL_MTU);
830 set_bit(SLF_INUSE, &sl->flags);
832 err = register_netdevice(sl->dev);
838 if (sl->keepalive) {
839 sl->keepalive_timer.expires = jiffies + sl->keepalive * HZ;
840 add_timer(&sl->keepalive_timer);
842 if (sl->outfill) {
843 sl->outfill_timer.expires = jiffies + sl->outfill * HZ;
844 add_timer(&sl->outfill_timer);
856 sl_free_bufs(sl);
859 sl->tty = NULL;
861 clear_bit(SLF_INUSE, &sl->flags);
862 sl_free_netdev(sl->dev);
865 free_netdev(sl->dev);
885 struct slip *sl = tty->disc_data;
888 if (!sl || sl->magic != SLIP_MAGIC || sl->tty != tty)
891 spin_lock_bh(&sl->lock);
893 sl->tty = NULL;
894 spin_unlock_bh(&sl->lock);
897 flush_work(&sl->tx_work);
901 del_timer_sync(&sl->keepalive_timer);
902 del_timer_sync(&sl->outfill_timer);
905 unregister_netdev(sl->dev);
955 static void slip_unesc(struct slip *sl, unsigned char s)
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)
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;
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))
1188 struct slip *sl = netdev_priv(dev);
1191 if (sl == NULL) /* Allocation failed ?? */
1194 spin_lock_bh(&sl->lock);
1196 if (!sl->tty) {
1197 spin_unlock_bh(&sl->lock);
1205 spin_unlock_bh(&sl->lock);
1208 sl->keepalive = (u8)*p;
1209 if (sl->keepalive != 0) {
1210 sl->keepalive_timer.expires =
1211 jiffies + sl->keepalive * HZ;
1212 mod_timer(&sl->keepalive_timer,
1213 jiffies + sl->keepalive * HZ);
1214 set_bit(SLF_KEEPTEST, &sl->flags);
1216 del_timer(&sl->keepalive_timer);
1220 *p = sl->keepalive;
1225 spin_unlock_bh(&sl->lock);
1228 sl->outfill = (u8)*p;
1229 if (sl->outfill != 0) {
1230 mod_timer(&sl->outfill_timer,
1231 jiffies + sl->outfill * HZ);
1232 set_bit(SLF_OUTWAIT, &sl->flags);
1234 del_timer(&sl->outfill_timer);
1238 *p = sl->outfill;
1245 if (sl->tty != current->signal->tty &&
1246 sl->pid != current->pid) {
1247 spin_unlock_bh(&sl->lock);
1250 sl->leased = 0;
1252 sl->leased = 1;
1256 *p = sl->leased;
1258 spin_unlock_bh(&sl->lock);
1314 struct slip *sl;
1332 sl = netdev_priv(dev);
1333 spin_lock_bh(&sl->lock);
1334 if (sl->tty) {
1336 tty_hangup(sl->tty);
1338 spin_unlock_bh(&sl->lock);
1351 sl = netdev_priv(dev);
1352 if (sl->tty) {
1379 struct slip *sl = from_timer(sl, t, outfill_timer);
1381 spin_lock(&sl->lock);
1383 if (sl->tty == NULL)
1386 if (sl->outfill) {
1387 if (test_bit(SLF_OUTWAIT, &sl->flags)) {
1390 unsigned char s = (sl->mode & SL_MODE_SLIP6)?0x70:END;
1395 if (!netif_queue_stopped(sl->dev)) {
1397 sl->tty->ops->write(sl->tty, &s, 1);
1400 set_bit(SLF_OUTWAIT, &sl->flags);
1402 mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ);
1405 spin_unlock(&sl->lock);
1410 struct slip *sl = from_timer(sl, t, keepalive_timer);
1412 spin_lock(&sl->lock);
1414 if (sl->tty == NULL)
1417 if (sl->keepalive) {
1418 if (test_bit(SLF_KEEPTEST, &sl->flags)) {
1420 if (sl->outfill)
1422 (void)del_timer(&sl->outfill_timer);
1423 printk(KERN_DEBUG "%s: no packets received during keepalive timeout, hangup.\n", sl->dev->name);
1425 tty_hangup(sl->tty);
1429 set_bit(SLF_KEEPTEST, &sl->flags);
1431 mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ);
1434 spin_unlock(&sl->lock);