Lines Matching refs:ax
245 static void ax_bump(struct mkiss *ax) in ax_bump() argument
250 spin_lock_bh(&ax->buflock); in ax_bump()
251 if (ax->rbuff[0] > 0x0f) { in ax_bump()
252 if (ax->rbuff[0] & 0x80) { in ax_bump()
253 if (check_crc_16(ax->rbuff, ax->rcount) < 0) { in ax_bump()
254 ax->dev->stats.rx_errors++; in ax_bump()
255 spin_unlock_bh(&ax->buflock); in ax_bump()
259 if (ax->crcmode != CRC_MODE_SMACK && ax->crcauto) { in ax_bump()
262 ax->dev->name); in ax_bump()
263 ax->crcmode = CRC_MODE_SMACK; in ax_bump()
265 ax->rcount -= 2; in ax_bump()
266 *ax->rbuff &= ~0x80; in ax_bump()
267 } else if (ax->rbuff[0] & 0x20) { in ax_bump()
268 if (check_crc_flex(ax->rbuff, ax->rcount) < 0) { in ax_bump()
269 ax->dev->stats.rx_errors++; in ax_bump()
270 spin_unlock_bh(&ax->buflock); in ax_bump()
273 if (ax->crcmode != CRC_MODE_FLEX && ax->crcauto) { in ax_bump()
276 ax->dev->name); in ax_bump()
277 ax->crcmode = CRC_MODE_FLEX; in ax_bump()
279 ax->rcount -= 2; in ax_bump()
287 *ax->rbuff &= ~0x20; in ax_bump()
291 count = ax->rcount; in ax_bump()
295 ax->dev->name); in ax_bump()
296 ax->dev->stats.rx_dropped++; in ax_bump()
297 spin_unlock_bh(&ax->buflock); in ax_bump()
301 memcpy(skb_put(skb,count), ax->rbuff, count); in ax_bump()
302 skb->protocol = ax25_type_trans(skb, ax->dev); in ax_bump()
304 ax->dev->stats.rx_packets++; in ax_bump()
305 ax->dev->stats.rx_bytes += count; in ax_bump()
306 spin_unlock_bh(&ax->buflock); in ax_bump()
309 static void kiss_unesc(struct mkiss *ax, unsigned char s) in kiss_unesc() argument
314 if (test_bit(AXF_KEEPTEST, &ax->flags)) in kiss_unesc()
315 clear_bit(AXF_KEEPTEST, &ax->flags); in kiss_unesc()
317 if (!test_and_clear_bit(AXF_ERROR, &ax->flags) && (ax->rcount > 2)) in kiss_unesc()
318 ax_bump(ax); in kiss_unesc()
320 clear_bit(AXF_ESCAPE, &ax->flags); in kiss_unesc()
321 ax->rcount = 0; in kiss_unesc()
325 set_bit(AXF_ESCAPE, &ax->flags); in kiss_unesc()
328 if (test_and_clear_bit(AXF_ESCAPE, &ax->flags)) in kiss_unesc()
332 if (test_and_clear_bit(AXF_ESCAPE, &ax->flags)) in kiss_unesc()
337 spin_lock_bh(&ax->buflock); in kiss_unesc()
338 if (!test_bit(AXF_ERROR, &ax->flags)) { in kiss_unesc()
339 if (ax->rcount < ax->buffsize) { in kiss_unesc()
340 ax->rbuff[ax->rcount++] = s; in kiss_unesc()
341 spin_unlock_bh(&ax->buflock); in kiss_unesc()
345 ax->dev->stats.rx_over_errors++; in kiss_unesc()
346 set_bit(AXF_ERROR, &ax->flags); in kiss_unesc()
348 spin_unlock_bh(&ax->buflock); in kiss_unesc()
366 static void ax_changedmtu(struct mkiss *ax) in ax_changedmtu() argument
368 struct net_device *dev = ax->dev; in ax_changedmtu()
388 ax->dev->name); in ax_changedmtu()
389 dev->mtu = ax->mtu; in ax_changedmtu()
395 spin_lock_bh(&ax->buflock); in ax_changedmtu()
397 oxbuff = ax->xbuff; in ax_changedmtu()
398 ax->xbuff = xbuff; in ax_changedmtu()
399 orbuff = ax->rbuff; in ax_changedmtu()
400 ax->rbuff = rbuff; in ax_changedmtu()
402 if (ax->xleft) { in ax_changedmtu()
403 if (ax->xleft <= len) { in ax_changedmtu()
404 memcpy(ax->xbuff, ax->xhead, ax->xleft); in ax_changedmtu()
406 ax->xleft = 0; in ax_changedmtu()
411 ax->xhead = ax->xbuff; in ax_changedmtu()
413 if (ax->rcount) { in ax_changedmtu()
414 if (ax->rcount <= len) { in ax_changedmtu()
415 memcpy(ax->rbuff, orbuff, ax->rcount); in ax_changedmtu()
417 ax->rcount = 0; in ax_changedmtu()
419 set_bit(AXF_ERROR, &ax->flags); in ax_changedmtu()
423 ax->mtu = dev->mtu + 73; in ax_changedmtu()
424 ax->buffsize = len; in ax_changedmtu()
426 spin_unlock_bh(&ax->buflock); in ax_changedmtu()
435 struct mkiss *ax = netdev_priv(dev); in ax_encaps() local
439 if (ax->mtu != ax->dev->mtu + 73) /* Someone has been ifconfigging */ in ax_encaps()
440 ax_changedmtu(ax); in ax_encaps()
442 if (len > ax->mtu) { /* Sigh, shouldn't occur BUT ... */ in ax_encaps()
443 len = ax->mtu; in ax_encaps()
444 printk(KERN_ERR "mkiss: %s: truncating oversized transmit packet!\n", ax->dev->name); in ax_encaps()
452 spin_lock_bh(&ax->buflock); in ax_encaps()
466 ax->crcmode = CRC_MODE_SMACK; in ax_encaps()
469 ax->crcmode = CRC_MODE_FLEX; in ax_encaps()
472 ax->crcmode = CRC_MODE_NONE; in ax_encaps()
476 ax->crcmode = CRC_MODE_SMACK_TEST; in ax_encaps()
479 ax->crcauto = (cmd ? 0 : 1); in ax_encaps()
480 printk(KERN_INFO "mkiss: %s: crc mode %s %d\n", ax->dev->name, (len) ? "set to" : "is", cmd); in ax_encaps()
482 spin_unlock_bh(&ax->buflock); in ax_encaps()
487 count = kiss_esc(p, ax->xbuff, len); in ax_encaps()
491 switch (ax->crcmode) { in ax_encaps()
493 ax->crcmode = CRC_MODE_FLEX_TEST; in ax_encaps()
494 printk(KERN_INFO "mkiss: %s: Trying crc-smack\n", ax->dev->name); in ax_encaps()
499 count = kiss_esc_crc(p, ax->xbuff, crc, len+2); in ax_encaps()
502 ax->crcmode = CRC_MODE_NONE; in ax_encaps()
503 printk(KERN_INFO "mkiss: %s: Trying crc-flexnet\n", ax->dev->name); in ax_encaps()
508 count = kiss_esc_crc(p, ax->xbuff, crc, len+2); in ax_encaps()
512 count = kiss_esc(p, ax->xbuff, len); in ax_encaps()
515 spin_unlock_bh(&ax->buflock); in ax_encaps()
517 set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); in ax_encaps()
518 actual = ax->tty->ops->write(ax->tty, ax->xbuff, count); in ax_encaps()
522 ax->dev->trans_start = jiffies; in ax_encaps()
523 ax->xleft = count - actual; in ax_encaps()
524 ax->xhead = ax->xbuff + actual; in ax_encaps()
530 struct mkiss *ax = netdev_priv(dev); in ax_xmit() local
551 (tty_chars_in_buffer(ax->tty) || ax->xleft) ? in ax_xmit()
554 ax->xleft = 0; in ax_xmit()
555 clear_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); in ax_xmit()
569 struct mkiss *ax = netdev_priv(dev); in ax_open_dev() local
571 if (ax->tty == NULL) in ax_open_dev()
580 struct mkiss *ax = netdev_priv(dev); in ax_open() local
583 if (ax->tty == NULL) in ax_open()
602 if ((ax->rbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL) in ax_open()
605 if ((ax->xbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL) in ax_open()
608 ax->mtu = dev->mtu + 73; in ax_open()
609 ax->buffsize = len; in ax_open()
610 ax->rcount = 0; in ax_open()
611 ax->xleft = 0; in ax_open()
613 ax->flags &= (1 << AXF_INUSE); /* Clear ESCAPE & ERROR flags */ in ax_open()
615 spin_lock_init(&ax->buflock); in ax_open()
620 kfree(ax->rbuff); in ax_open()
630 struct mkiss *ax = netdev_priv(dev); in ax_close() local
632 if (ax->tty) in ax_close()
633 clear_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); in ax_close()
677 struct mkiss *ax; in mkiss_get() local
680 ax = tty->disc_data; in mkiss_get()
681 if (ax) in mkiss_get()
682 atomic_inc(&ax->refcnt); in mkiss_get()
685 return ax; in mkiss_get()
688 static void mkiss_put(struct mkiss *ax) in mkiss_put() argument
690 if (atomic_dec_and_test(&ax->refcnt)) in mkiss_put()
691 up(&ax->dead_sem); in mkiss_put()
699 struct mkiss *ax; in mkiss_open() local
714 ax = netdev_priv(dev); in mkiss_open()
715 ax->dev = dev; in mkiss_open()
717 spin_lock_init(&ax->buflock); in mkiss_open()
718 atomic_set(&ax->refcnt, 1); in mkiss_open()
719 sema_init(&ax->dead_sem, 0); in mkiss_open()
721 ax->tty = tty; in mkiss_open()
722 tty->disc_data = ax; in mkiss_open()
731 err = ax_open(ax->dev); in mkiss_open()
742 ax->crcmode = CRC_MODE_SMACK; in mkiss_open()
744 ax->dev->name); in mkiss_open()
747 ax->crcmode = CRC_MODE_FLEX; in mkiss_open()
749 ax->dev->name); in mkiss_open()
752 ax->crcmode = CRC_MODE_NONE; in mkiss_open()
754 ax->dev->name); in mkiss_open()
761 ax->dev->name); in mkiss_open()
762 ax->crcmode = CRC_MODE_SMACK_TEST; in mkiss_open()
764 ax->crcauto = (crc_force ? 0 : 1); in mkiss_open()
772 kfree(ax->rbuff); in mkiss_open()
773 kfree(ax->xbuff); in mkiss_open()
784 struct mkiss *ax; in mkiss_close() local
787 ax = tty->disc_data; in mkiss_close()
791 if (!ax) in mkiss_close()
798 if (!atomic_dec_and_test(&ax->refcnt)) in mkiss_close()
799 down(&ax->dead_sem); in mkiss_close()
804 netif_stop_queue(ax->dev); in mkiss_close()
806 unregister_netdev(ax->dev); in mkiss_close()
809 kfree(ax->rbuff); in mkiss_close()
810 kfree(ax->xbuff); in mkiss_close()
812 ax->tty = NULL; in mkiss_close()
814 free_netdev(ax->dev); in mkiss_close()
821 struct mkiss *ax = mkiss_get(tty); in mkiss_ioctl() local
826 if (ax == NULL) in mkiss_ioctl()
828 dev = ax->dev; in mkiss_ioctl()
832 err = copy_to_user((void __user *) arg, ax->dev->name, in mkiss_ioctl()
833 strlen(ax->dev->name) + 1) ? -EFAULT : 0; in mkiss_ioctl()
846 ax->mode = tmp; in mkiss_ioctl()
875 mkiss_put(ax); in mkiss_ioctl()
906 struct mkiss *ax = mkiss_get(tty); in mkiss_receive_buf() local
908 if (!ax) in mkiss_receive_buf()
915 if (ax->mtu != ax->dev->mtu + 73) in mkiss_receive_buf()
916 ax_changedmtu(ax); in mkiss_receive_buf()
921 if (!test_and_set_bit(AXF_ERROR, &ax->flags)) in mkiss_receive_buf()
922 ax->dev->stats.rx_errors++; in mkiss_receive_buf()
927 kiss_unesc(ax, *cp++); in mkiss_receive_buf()
930 mkiss_put(ax); in mkiss_receive_buf()
940 struct mkiss *ax = mkiss_get(tty); in mkiss_write_wakeup() local
943 if (!ax) in mkiss_write_wakeup()
946 if (ax->xleft <= 0) { in mkiss_write_wakeup()
952 netif_wake_queue(ax->dev); in mkiss_write_wakeup()
956 actual = tty->ops->write(tty, ax->xhead, ax->xleft); in mkiss_write_wakeup()
957 ax->xleft -= actual; in mkiss_write_wakeup()
958 ax->xhead += actual; in mkiss_write_wakeup()
961 mkiss_put(ax); in mkiss_write_wakeup()