Lines Matching refs:sp

141 	struct sixpack *sp = from_timer(sp, t, tx_t);
142 int actual, when = sp->slottime;
147 if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) {
148 sp->led_state = 0x70;
149 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
150 sp->tx_enable = 1;
151 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2);
152 sp->xleft -= actual;
153 sp->xhead += actual;
154 sp->led_state = 0x60;
155 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
156 sp->status2 = 0;
158 mod_timer(&sp->tx_t, jiffies + ((when + 1) * HZ) / 100);
164 static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len)
169 if (len > sp->mtu) { /* sp->mtu = AX25_MTU = max. PACLEN = 256 */
174 if (len > sp->mtu) { /* sp->mtu = AX25_MTU = max. PACLEN = 256 */
194 count = encode_sixpack(p, sp->xbuff, len, sp->tx_delay);
195 set_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags);
198 case 1: sp->tx_delay = p[1];
200 case 2: sp->persistence = p[1];
202 case 3: sp->slottime = p[1];
206 case 5: sp->duplex = p[1];
219 if (sp->duplex == 1) {
220 sp->led_state = 0x70;
221 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
222 sp->tx_enable = 1;
223 actual = sp->tty->ops->write(sp->tty, sp->xbuff, count);
224 sp->xleft = count - actual;
225 sp->xhead = sp->xbuff + actual;
226 sp->led_state = 0x60;
227 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
229 sp->xleft = count;
230 sp->xhead = sp->xbuff;
231 sp->status2 = count;
232 sp_xmit_on_air(&sp->tx_t);
238 sp->dev->stats.tx_dropped++;
239 netif_start_queue(sp->dev);
241 printk(KERN_DEBUG "%s: %s - dropped.\n", sp->dev->name, msg);
248 struct sixpack *sp = netdev_priv(dev);
253 spin_lock_bh(&sp->lock);
257 sp_encaps(sp, skb->data, skb->len);
258 spin_unlock_bh(&sp->lock);
267 struct sixpack *sp = netdev_priv(dev);
269 if (sp->tty == NULL)
277 struct sixpack *sp = netdev_priv(dev);
279 spin_lock_bh(&sp->lock);
280 if (sp->tty) {
282 clear_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags);
285 spin_unlock_bh(&sp->lock);
336 static void sp_bump(struct sixpack *sp, char cmd)
342 count = sp->rcount + 1;
344 sp->dev->stats.rx_bytes += count;
352 memcpy(ptr, sp->cooked_buf + 1, count);
353 skb->protocol = ax25_type_trans(skb, sp->dev);
355 sp->dev->stats.rx_packets++;
360 sp->dev->stats.rx_dropped++;
378 struct sixpack *sp;
381 sp = tty->disc_data;
382 if (sp)
383 refcount_inc(&sp->refcnt);
386 return sp;
389 static void sp_put(struct sixpack *sp)
391 if (refcount_dec_and_test(&sp->refcnt))
392 complete(&sp->dead);
401 struct sixpack *sp = sp_get(tty);
404 if (!sp)
406 if (sp->xleft <= 0) {
409 sp->dev->stats.tx_packets++;
411 sp->tx_enable = 0;
412 netif_wake_queue(sp->dev);
416 if (sp->tx_enable) {
417 actual = tty->ops->write(tty, sp->xhead, sp->xleft);
418 sp->xleft -= actual;
419 sp->xhead += actual;
423 sp_put(sp);
437 struct sixpack *sp;
443 sp = sp_get(tty);
444 if (!sp)
452 if (!test_and_set_bit(SIXPF_ERROR, &sp->flags))
453 sp->dev->stats.rx_errors++;
457 sixpack_decode(sp, cp, count1);
459 sp_put(sp);
473 static void __tnc_set_sync_state(struct sixpack *sp, int new_tnc_state)
490 sp->tnc_state = new_tnc_state;
491 printk(KERN_INFO "%s: %s\n", sp->dev->name, msg);
494 static inline void tnc_set_sync_state(struct sixpack *sp, int new_tnc_state)
496 int old_tnc_state = sp->tnc_state;
499 __tnc_set_sync_state(sp, new_tnc_state);
504 struct sixpack *sp = from_timer(sp, t, resync_t);
509 sp->rx_count = 0;
510 sp->rx_count_cooked = 0;
514 sp->status = 1;
515 sp->status1 = 1;
516 sp->status2 = 0;
520 sp->led_state = 0x60;
521 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
522 sp->tty->ops->write(sp->tty, &resync_cmd, 1);
526 mod_timer(&sp->resync_t, jiffies + SIXP_RESYNC_TIMEOUT);
529 static inline int tnc_init(struct sixpack *sp)
533 tnc_set_sync_state(sp, TNC_UNSYNC_STARTUP);
535 sp->tty->ops->write(sp->tty, &inbyte, 1);
537 mod_timer(&sp->resync_t, jiffies + SIXP_RESYNC_TIMEOUT);
553 struct sixpack *sp;
562 dev = alloc_netdev(sizeof(struct sixpack), "sp%d", NET_NAME_UNKNOWN,
569 sp = netdev_priv(dev);
570 sp->dev = dev;
572 spin_lock_init(&sp->lock);
573 refcount_set(&sp->refcnt, 1);
574 init_completion(&sp->dead);
588 spin_lock_bh(&sp->lock);
590 sp->tty = tty;
592 sp->rbuff = rbuff;
593 sp->xbuff = xbuff;
595 sp->mtu = AX25_MTU + 73;
596 sp->buffsize = len;
597 sp->rcount = 0;
598 sp->rx_count = 0;
599 sp->rx_count_cooked = 0;
600 sp->xleft = 0;
602 sp->flags = 0; /* Clear ESCAPE & ERROR flags */
604 sp->duplex = 0;
605 sp->tx_delay = SIXP_TXDELAY;
606 sp->persistence = SIXP_PERSIST;
607 sp->slottime = SIXP_SLOTTIME;
608 sp->led_state = 0x60;
609 sp->status = 1;
610 sp->status1 = 1;
611 sp->status2 = 0;
612 sp->tx_enable = 0;
616 timer_setup(&sp->tx_t, sp_xmit_on_air, 0);
618 timer_setup(&sp->resync_t, resync_tnc, 0);
620 spin_unlock_bh(&sp->lock);
623 tty->disc_data = sp;
631 tnc_init(sp);
654 struct sixpack *sp;
657 sp = tty->disc_data;
660 if (!sp)
667 if (!refcount_dec_and_test(&sp->refcnt))
668 wait_for_completion(&sp->dead);
671 * on the free buffers. The sp->dead completion is not sufficient
672 * to protect us from sp->xbuff access.
674 netif_stop_queue(sp->dev);
676 unregister_netdev(sp->dev);
678 del_timer_sync(&sp->tx_t);
679 del_timer_sync(&sp->resync_t);
682 kfree(sp->rbuff);
683 kfree(sp->xbuff);
685 free_netdev(sp->dev);
692 struct sixpack *sp = sp_get(tty);
696 if (!sp)
698 dev = sp->dev;
716 sp->mode = tmp;
746 sp_put(sp);
833 static void decode_data(struct sixpack *sp, unsigned char inbyte)
837 if (sp->rx_count != 3) {
838 sp->raw_buf[sp->rx_count++] = inbyte;
843 if (sp->rx_count_cooked + 2 >= sizeof(sp->cooked_buf)) {
845 sp->rx_count = 0;
849 buf = sp->raw_buf;
850 sp->cooked_buf[sp->rx_count_cooked++] =
852 sp->cooked_buf[sp->rx_count_cooked++] =
854 sp->cooked_buf[sp->rx_count_cooked++] =
856 sp->rx_count = 0;
861 static void decode_prio_command(struct sixpack *sp, unsigned char cmd)
874 if (((sp->status & SIXP_DCD_MASK) == 0) &&
876 if (sp->status != 1)
879 sp->status = 0;
882 sp->status = cmd & SIXP_PRIO_DATA_MASK;
884 if ((sp->status2 != 0) && (sp->duplex == 1)) {
885 sp->led_state = 0x70;
886 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
887 sp->tx_enable = 1;
888 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2);
889 sp->xleft -= actual;
890 sp->xhead += actual;
891 sp->led_state = 0x60;
892 sp->status2 = 0;
898 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
903 if (sp->tnc_state == TNC_IN_SYNC)
904 mod_timer(&sp->resync_t, jiffies + SIXP_INIT_RESYNC_TIMEOUT);
906 sp->status1 = cmd & SIXP_PRIO_DATA_MASK;
911 static void decode_std_command(struct sixpack *sp, unsigned char cmd)
918 if ((sp->rx_count == 0) && (sp->rx_count_cooked == 0)) {
919 if ((sp->status & SIXP_RX_DCD_MASK) ==
921 sp->led_state = 0x68;
922 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
925 sp->led_state = 0x60;
927 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
928 rest = sp->rx_count;
931 decode_data(sp, 0);
933 sp->rx_count_cooked -= 2;
935 sp->rx_count_cooked -= 1;
936 for (i = 0; i < sp->rx_count_cooked; i++)
937 checksum += sp->cooked_buf[i];
941 sp->rcount = sp->rx_count_cooked-2;
942 sp_bump(sp, 0);
944 sp->rx_count_cooked = 0;
959 sixpack_decode(struct sixpack *sp, const unsigned char *pre_rbuff, int count)
967 tnc_set_sync_state(sp, TNC_IN_SYNC);
968 del_timer(&sp->resync_t);
971 decode_prio_command(sp, inbyte);
973 decode_std_command(sp, inbyte);
974 else if ((sp->status & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK)
975 decode_data(sp, inbyte);