Lines Matching defs:sp

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