Lines Matching full:sp

136 	struct sixpack *sp = timer_container_of(sp, t, tx_t);  in sp_xmit_on_air()  local
137 int actual, when = sp->slottime; in sp_xmit_on_air()
142 if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) { in sp_xmit_on_air()
143 sp->led_state = 0x70; in sp_xmit_on_air()
144 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in sp_xmit_on_air()
145 sp->tx_enable = 1; in sp_xmit_on_air()
146 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2); in sp_xmit_on_air()
147 sp->xleft -= actual; in sp_xmit_on_air()
148 sp->xhead += actual; in sp_xmit_on_air()
149 sp->led_state = 0x60; in sp_xmit_on_air()
150 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in sp_xmit_on_air()
151 sp->status2 = 0; in sp_xmit_on_air()
153 mod_timer(&sp->tx_t, jiffies + ((when + 1) * HZ) / 100); in sp_xmit_on_air()
159 static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len) in sp_encaps() argument
184 count = encode_sixpack(p, sp->xbuff, len, sp->tx_delay); in sp_encaps()
185 set_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags); in sp_encaps()
188 case 1: sp->tx_delay = p[1]; in sp_encaps()
190 case 2: sp->persistence = p[1]; in sp_encaps()
192 case 3: sp->slottime = p[1]; in sp_encaps()
196 case 5: sp->duplex = p[1]; in sp_encaps()
209 if (sp->duplex == 1) { in sp_encaps()
210 sp->led_state = 0x70; in sp_encaps()
211 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in sp_encaps()
212 sp->tx_enable = 1; in sp_encaps()
213 actual = sp->tty->ops->write(sp->tty, sp->xbuff, count); in sp_encaps()
214 sp->xleft = count - actual; in sp_encaps()
215 sp->xhead = sp->xbuff + actual; in sp_encaps()
216 sp->led_state = 0x60; in sp_encaps()
217 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in sp_encaps()
219 sp->xleft = count; in sp_encaps()
220 sp->xhead = sp->xbuff; in sp_encaps()
221 sp->status2 = count; in sp_encaps()
222 sp_xmit_on_air(&sp->tx_t); in sp_encaps()
228 sp->dev->stats.tx_dropped++; in sp_encaps()
229 netif_start_queue(sp->dev); in sp_encaps()
231 printk(KERN_DEBUG "%s: %s - dropped.\n", sp->dev->name, msg); in sp_encaps()
238 struct sixpack *sp = netdev_priv(dev); in sp_xmit() local
243 spin_lock_bh(&sp->lock); in sp_xmit()
247 sp_encaps(sp, skb->data, skb->len); in sp_xmit()
248 spin_unlock_bh(&sp->lock); in sp_xmit()
257 struct sixpack *sp = netdev_priv(dev); in sp_open_dev() local
259 if (sp->tty == NULL) in sp_open_dev()
267 struct sixpack *sp = netdev_priv(dev); in sp_close() local
269 spin_lock_bh(&sp->lock); in sp_close()
270 if (sp->tty) { in sp_close()
272 clear_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags); in sp_close()
275 spin_unlock_bh(&sp->lock); in sp_close()
326 static void sp_bump(struct sixpack *sp, char cmd) in sp_bump() argument
332 count = sp->rcount + 1; in sp_bump()
334 sp->dev->stats.rx_bytes += count; in sp_bump()
342 memcpy(ptr, sp->cooked_buf + 1, count); in sp_bump()
343 skb->protocol = ax25_type_trans(skb, sp->dev); in sp_bump()
345 sp->dev->stats.rx_packets++; in sp_bump()
350 sp->dev->stats.rx_dropped++; in sp_bump()
368 struct sixpack *sp; in sp_get() local
371 sp = tty->disc_data; in sp_get()
372 if (sp) in sp_get()
373 refcount_inc(&sp->refcnt); in sp_get()
376 return sp; in sp_get()
379 static void sp_put(struct sixpack *sp) in sp_put() argument
381 if (refcount_dec_and_test(&sp->refcnt)) in sp_put()
382 complete(&sp->dead); in sp_put()
391 struct sixpack *sp = sp_get(tty); in sixpack_write_wakeup() local
394 if (!sp) in sixpack_write_wakeup()
396 if (sp->xleft <= 0) { in sixpack_write_wakeup()
399 sp->dev->stats.tx_packets++; in sixpack_write_wakeup()
401 sp->tx_enable = 0; in sixpack_write_wakeup()
402 netif_wake_queue(sp->dev); in sixpack_write_wakeup()
406 if (sp->tx_enable) { in sixpack_write_wakeup()
407 actual = tty->ops->write(tty, sp->xhead, sp->xleft); in sixpack_write_wakeup()
408 sp->xleft -= actual; in sixpack_write_wakeup()
409 sp->xhead += actual; in sixpack_write_wakeup()
413 sp_put(sp); in sixpack_write_wakeup()
427 struct sixpack *sp; in sixpack_receive_buf() local
433 sp = sp_get(tty); in sixpack_receive_buf()
434 if (!sp) in sixpack_receive_buf()
442 if (!test_and_set_bit(SIXPF_ERROR, &sp->flags)) in sixpack_receive_buf()
443 sp->dev->stats.rx_errors++; in sixpack_receive_buf()
447 sixpack_decode(sp, cp, count1); in sixpack_receive_buf()
449 sp_put(sp); in sixpack_receive_buf()
463 static void __tnc_set_sync_state(struct sixpack *sp, int new_tnc_state) in __tnc_set_sync_state() argument
480 sp->tnc_state = new_tnc_state; in __tnc_set_sync_state()
481 printk(KERN_INFO "%s: %s\n", sp->dev->name, msg); in __tnc_set_sync_state()
484 static inline void tnc_set_sync_state(struct sixpack *sp, int new_tnc_state) in tnc_set_sync_state() argument
486 int old_tnc_state = sp->tnc_state; in tnc_set_sync_state()
489 __tnc_set_sync_state(sp, new_tnc_state); in tnc_set_sync_state()
494 struct sixpack *sp = timer_container_of(sp, t, resync_t); in resync_tnc() local
499 sp->rx_count = 0; in resync_tnc()
500 sp->rx_count_cooked = 0; in resync_tnc()
504 sp->status = 1; in resync_tnc()
505 sp->status1 = 1; in resync_tnc()
506 sp->status2 = 0; in resync_tnc()
510 sp->led_state = 0x60; in resync_tnc()
511 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in resync_tnc()
512 sp->tty->ops->write(sp->tty, &resync_cmd, 1); in resync_tnc()
516 mod_timer(&sp->resync_t, jiffies + SIXP_RESYNC_TIMEOUT); in resync_tnc()
519 static inline int tnc_init(struct sixpack *sp) in tnc_init() argument
523 tnc_set_sync_state(sp, TNC_UNSYNC_STARTUP); in tnc_init()
525 sp->tty->ops->write(sp->tty, &inbyte, 1); in tnc_init()
527 mod_timer(&sp->resync_t, jiffies + SIXP_RESYNC_TIMEOUT); in tnc_init()
543 struct sixpack *sp; in sixpack_open() local
552 dev = alloc_netdev(sizeof(struct sixpack), "sp%d", NET_NAME_UNKNOWN, in sixpack_open()
559 sp = netdev_priv(dev); in sixpack_open()
560 sp->dev = dev; in sixpack_open()
562 spin_lock_init(&sp->lock); in sixpack_open()
563 spin_lock_init(&sp->rxlock); in sixpack_open()
564 refcount_set(&sp->refcnt, 1); in sixpack_open()
565 init_completion(&sp->dead); in sixpack_open()
577 spin_lock_bh(&sp->lock); in sixpack_open()
579 sp->tty = tty; in sixpack_open()
581 sp->xbuff = xbuff; in sixpack_open()
583 sp->rcount = 0; in sixpack_open()
584 sp->rx_count = 0; in sixpack_open()
585 sp->rx_count_cooked = 0; in sixpack_open()
586 sp->xleft = 0; in sixpack_open()
588 sp->flags = 0; /* Clear ESCAPE & ERROR flags */ in sixpack_open()
590 sp->duplex = 0; in sixpack_open()
591 sp->tx_delay = SIXP_TXDELAY; in sixpack_open()
592 sp->persistence = SIXP_PERSIST; in sixpack_open()
593 sp->slottime = SIXP_SLOTTIME; in sixpack_open()
594 sp->led_state = 0x60; in sixpack_open()
595 sp->status = 1; in sixpack_open()
596 sp->status1 = 1; in sixpack_open()
597 sp->status2 = 0; in sixpack_open()
598 sp->tx_enable = 0; in sixpack_open()
602 timer_setup(&sp->tx_t, sp_xmit_on_air, 0); in sixpack_open()
604 timer_setup(&sp->resync_t, resync_tnc, 0); in sixpack_open()
606 spin_unlock_bh(&sp->lock); in sixpack_open()
609 tty->disc_data = sp; in sixpack_open()
617 tnc_init(sp); in sixpack_open()
639 struct sixpack *sp; in sixpack_close() local
642 sp = tty->disc_data; in sixpack_close()
645 if (!sp) in sixpack_close()
652 if (!refcount_dec_and_test(&sp->refcnt)) in sixpack_close()
653 wait_for_completion(&sp->dead); in sixpack_close()
656 * on the free buffers. The sp->dead completion is not sufficient in sixpack_close()
657 * to protect us from sp->xbuff access. in sixpack_close()
659 netif_stop_queue(sp->dev); in sixpack_close()
661 unregister_netdev(sp->dev); in sixpack_close()
663 timer_delete_sync(&sp->tx_t); in sixpack_close()
664 timer_delete_sync(&sp->resync_t); in sixpack_close()
667 kfree(sp->xbuff); in sixpack_close()
669 free_netdev(sp->dev); in sixpack_close()
676 struct sixpack *sp = sp_get(tty); in sixpack_ioctl() local
680 if (!sp) in sixpack_ioctl()
682 dev = sp->dev; in sixpack_ioctl()
700 sp->mode = tmp; in sixpack_ioctl()
728 sp_put(sp); in sixpack_ioctl()
803 static void decode_data(struct sixpack *sp, u8 inbyte) in decode_data() argument
807 if (sp->rx_count != 3) { in decode_data()
808 sp->raw_buf[sp->rx_count++] = inbyte; in decode_data()
813 if (sp->rx_count_cooked + 2 >= sizeof(sp->cooked_buf)) { in decode_data()
815 sp->rx_count = 0; in decode_data()
819 buf = sp->raw_buf; in decode_data()
820 sp->cooked_buf[sp->rx_count_cooked++] = in decode_data()
822 sp->cooked_buf[sp->rx_count_cooked++] = in decode_data()
824 sp->cooked_buf[sp->rx_count_cooked++] = in decode_data()
826 sp->rx_count = 0; in decode_data()
831 static void decode_prio_command(struct sixpack *sp, u8 cmd) in decode_prio_command() argument
844 if (((sp->status & SIXP_DCD_MASK) == 0) && in decode_prio_command()
846 if (sp->status != 1) in decode_prio_command()
849 sp->status = 0; in decode_prio_command()
852 sp->status = cmd & SIXP_PRIO_DATA_MASK; in decode_prio_command()
854 if ((sp->status2 != 0) && (sp->duplex == 1)) { in decode_prio_command()
855 sp->led_state = 0x70; in decode_prio_command()
856 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in decode_prio_command()
857 sp->tx_enable = 1; in decode_prio_command()
858 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2); in decode_prio_command()
859 sp->xleft -= actual; in decode_prio_command()
860 sp->xhead += actual; in decode_prio_command()
861 sp->led_state = 0x60; in decode_prio_command()
862 sp->status2 = 0; in decode_prio_command()
868 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in decode_prio_command()
873 if (sp->tnc_state == TNC_IN_SYNC) in decode_prio_command()
874 mod_timer(&sp->resync_t, jiffies + SIXP_INIT_RESYNC_TIMEOUT); in decode_prio_command()
876 sp->status1 = cmd & SIXP_PRIO_DATA_MASK; in decode_prio_command()
881 static void decode_std_command(struct sixpack *sp, u8 cmd) in decode_std_command() argument
888 if ((sp->rx_count == 0) && (sp->rx_count_cooked == 0)) { in decode_std_command()
889 if ((sp->status & SIXP_RX_DCD_MASK) == in decode_std_command()
891 sp->led_state = 0x68; in decode_std_command()
892 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in decode_std_command()
895 sp->led_state = 0x60; in decode_std_command()
897 sp->tty->ops->write(sp->tty, &sp->led_state, 1); in decode_std_command()
898 spin_lock_bh(&sp->rxlock); in decode_std_command()
899 rest = sp->rx_count; in decode_std_command()
902 decode_data(sp, 0); in decode_std_command()
904 sp->rx_count_cooked -= 2; in decode_std_command()
906 sp->rx_count_cooked -= 1; in decode_std_command()
907 for (i = 0; i < sp->rx_count_cooked; i++) in decode_std_command()
908 checksum += sp->cooked_buf[i]; in decode_std_command()
912 sp->rcount = sp->rx_count_cooked-2; in decode_std_command()
913 sp_bump(sp, 0); in decode_std_command()
915 sp->rx_count_cooked = 0; in decode_std_command()
916 spin_unlock_bh(&sp->rxlock); in decode_std_command()
931 sixpack_decode(struct sixpack *sp, const u8 *pre_rbuff, size_t count) in sixpack_decode() argument
939 tnc_set_sync_state(sp, TNC_IN_SYNC); in sixpack_decode()
940 timer_delete(&sp->resync_t); in sixpack_decode()
943 decode_prio_command(sp, inbyte); in sixpack_decode()
945 decode_std_command(sp, inbyte); in sixpack_decode()
946 else if ((sp->status & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK) { in sixpack_decode()
947 spin_lock_bh(&sp->rxlock); in sixpack_decode()
948 decode_data(sp, inbyte); in sixpack_decode()
949 spin_unlock_bh(&sp->rxlock); in sixpack_decode()