Lines Matching refs:sp
142 struct sixpack *sp = from_timer(sp, t, tx_t);
143 int actual, when = sp->slottime;
148 if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) {
149 sp->led_state = 0x70;
150 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
151 sp->tx_enable = 1;
152 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2);
153 sp->xleft -= actual;
154 sp->xhead += actual;
155 sp->led_state = 0x60;
156 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
157 sp->status2 = 0;
159 mod_timer(&sp->tx_t, jiffies + ((when + 1) * HZ) / 100);
165 static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len)
170 if (len > sp->mtu) { /* sp->mtu = AX25_MTU = max. PACLEN = 256 */
190 count = encode_sixpack(p, sp->xbuff, len, sp->tx_delay);
191 set_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags);
194 case 1: sp->tx_delay = p[1];
196 case 2: sp->persistence = p[1];
198 case 3: sp->slottime = p[1];
202 case 5: sp->duplex = p[1];
215 if (sp->duplex == 1) {
216 sp->led_state = 0x70;
217 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
218 sp->tx_enable = 1;
219 actual = sp->tty->ops->write(sp->tty, sp->xbuff, count);
220 sp->xleft = count - actual;
221 sp->xhead = sp->xbuff + actual;
222 sp->led_state = 0x60;
223 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
225 sp->xleft = count;
226 sp->xhead = sp->xbuff;
227 sp->status2 = count;
228 sp_xmit_on_air(&sp->tx_t);
234 sp->dev->stats.tx_dropped++;
235 netif_start_queue(sp->dev);
237 printk(KERN_DEBUG "%s: %s - dropped.\n", sp->dev->name, msg);
244 struct sixpack *sp = netdev_priv(dev);
249 spin_lock_bh(&sp->lock);
253 sp_encaps(sp, skb->data, skb->len);
254 spin_unlock_bh(&sp->lock);
263 struct sixpack *sp = netdev_priv(dev);
265 if (sp->tty == NULL)
273 struct sixpack *sp = netdev_priv(dev);
275 spin_lock_bh(&sp->lock);
276 if (sp->tty) {
278 clear_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags);
281 spin_unlock_bh(&sp->lock);
332 static void sp_bump(struct sixpack *sp, char cmd)
338 count = sp->rcount + 1;
340 sp->dev->stats.rx_bytes += count;
348 memcpy(ptr, sp->cooked_buf + 1, count);
349 skb->protocol = ax25_type_trans(skb, sp->dev);
351 sp->dev->stats.rx_packets++;
356 sp->dev->stats.rx_dropped++;
374 struct sixpack *sp;
377 sp = tty->disc_data;
378 if (sp)
379 refcount_inc(&sp->refcnt);
382 return sp;
385 static void sp_put(struct sixpack *sp)
387 if (refcount_dec_and_test(&sp->refcnt))
388 complete(&sp->dead);
397 struct sixpack *sp = sp_get(tty);
400 if (!sp)
402 if (sp->xleft <= 0) {
405 sp->dev->stats.tx_packets++;
407 sp->tx_enable = 0;
408 netif_wake_queue(sp->dev);
412 if (sp->tx_enable) {
413 actual = tty->ops->write(tty, sp->xhead, sp->xleft);
414 sp->xleft -= actual;
415 sp->xhead += actual;
419 sp_put(sp);
433 struct sixpack *sp;
439 sp = sp_get(tty);
440 if (!sp)
448 if (!test_and_set_bit(SIXPF_ERROR, &sp->flags))
449 sp->dev->stats.rx_errors++;
453 sixpack_decode(sp, cp, count1);
455 sp_put(sp);
469 static void __tnc_set_sync_state(struct sixpack *sp, int new_tnc_state)
486 sp->tnc_state = new_tnc_state;
487 printk(KERN_INFO "%s: %s\n", sp->dev->name, msg);
490 static inline void tnc_set_sync_state(struct sixpack *sp, int new_tnc_state)
492 int old_tnc_state = sp->tnc_state;
495 __tnc_set_sync_state(sp, new_tnc_state);
500 struct sixpack *sp = from_timer(sp, t, resync_t);
505 sp->rx_count = 0;
506 sp->rx_count_cooked = 0;
510 sp->status = 1;
511 sp->status1 = 1;
512 sp->status2 = 0;
516 sp->led_state = 0x60;
517 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
518 sp->tty->ops->write(sp->tty, &resync_cmd, 1);
522 mod_timer(&sp->resync_t, jiffies + SIXP_RESYNC_TIMEOUT);
525 static inline int tnc_init(struct sixpack *sp)
529 tnc_set_sync_state(sp, TNC_UNSYNC_STARTUP);
531 sp->tty->ops->write(sp->tty, &inbyte, 1);
533 mod_timer(&sp->resync_t, jiffies + SIXP_RESYNC_TIMEOUT);
549 struct sixpack *sp;
558 dev = alloc_netdev(sizeof(struct sixpack), "sp%d", NET_NAME_UNKNOWN,
565 sp = netdev_priv(dev);
566 sp->dev = dev;
568 spin_lock_init(&sp->lock);
569 spin_lock_init(&sp->rxlock);
570 refcount_set(&sp->refcnt, 1);
571 init_completion(&sp->dead);
585 spin_lock_bh(&sp->lock);
587 sp->tty = tty;
589 sp->rbuff = rbuff;
590 sp->xbuff = xbuff;
592 sp->mtu = AX25_MTU + 73;
593 sp->buffsize = len;
594 sp->rcount = 0;
595 sp->rx_count = 0;
596 sp->rx_count_cooked = 0;
597 sp->xleft = 0;
599 sp->flags = 0; /* Clear ESCAPE & ERROR flags */
601 sp->duplex = 0;
602 sp->tx_delay = SIXP_TXDELAY;
603 sp->persistence = SIXP_PERSIST;
604 sp->slottime = SIXP_SLOTTIME;
605 sp->led_state = 0x60;
606 sp->status = 1;
607 sp->status1 = 1;
608 sp->status2 = 0;
609 sp->tx_enable = 0;
613 timer_setup(&sp->tx_t, sp_xmit_on_air, 0);
615 timer_setup(&sp->resync_t, resync_tnc, 0);
617 spin_unlock_bh(&sp->lock);
620 tty->disc_data = sp;
628 tnc_init(sp);
651 struct sixpack *sp;
654 sp = tty->disc_data;
657 if (!sp)
664 if (!refcount_dec_and_test(&sp->refcnt))
665 wait_for_completion(&sp->dead);
668 * on the free buffers. The sp->dead completion is not sufficient
669 * to protect us from sp->xbuff access.
671 netif_stop_queue(sp->dev);
673 unregister_netdev(sp->dev);
675 del_timer_sync(&sp->tx_t);
676 del_timer_sync(&sp->resync_t);
679 kfree(sp->rbuff);
680 kfree(sp->xbuff);
682 free_netdev(sp->dev);
689 struct sixpack *sp = sp_get(tty);
693 if (!sp)
695 dev = sp->dev;
713 sp->mode = tmp;
741 sp_put(sp);
823 static void decode_data(struct sixpack *sp, unsigned char inbyte)
827 if (sp->rx_count != 3) {
828 sp->raw_buf[sp->rx_count++] = inbyte;
833 if (sp->rx_count_cooked + 2 >= sizeof(sp->cooked_buf)) {
835 sp->rx_count = 0;
839 buf = sp->raw_buf;
840 sp->cooked_buf[sp->rx_count_cooked++] =
842 sp->cooked_buf[sp->rx_count_cooked++] =
844 sp->cooked_buf[sp->rx_count_cooked++] =
846 sp->rx_count = 0;
851 static void decode_prio_command(struct sixpack *sp, unsigned char cmd)
864 if (((sp->status & SIXP_DCD_MASK) == 0) &&
866 if (sp->status != 1)
869 sp->status = 0;
872 sp->status = cmd & SIXP_PRIO_DATA_MASK;
874 if ((sp->status2 != 0) && (sp->duplex == 1)) {
875 sp->led_state = 0x70;
876 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
877 sp->tx_enable = 1;
878 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2);
879 sp->xleft -= actual;
880 sp->xhead += actual;
881 sp->led_state = 0x60;
882 sp->status2 = 0;
888 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
893 if (sp->tnc_state == TNC_IN_SYNC)
894 mod_timer(&sp->resync_t, jiffies + SIXP_INIT_RESYNC_TIMEOUT);
896 sp->status1 = cmd & SIXP_PRIO_DATA_MASK;
901 static void decode_std_command(struct sixpack *sp, unsigned char cmd)
908 if ((sp->rx_count == 0) && (sp->rx_count_cooked == 0)) {
909 if ((sp->status & SIXP_RX_DCD_MASK) ==
911 sp->led_state = 0x68;
912 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
915 sp->led_state = 0x60;
917 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
918 spin_lock_bh(&sp->rxlock);
919 rest = sp->rx_count;
922 decode_data(sp, 0);
924 sp->rx_count_cooked -= 2;
926 sp->rx_count_cooked -= 1;
927 for (i = 0; i < sp->rx_count_cooked; i++)
928 checksum += sp->cooked_buf[i];
932 sp->rcount = sp->rx_count_cooked-2;
933 sp_bump(sp, 0);
935 sp->rx_count_cooked = 0;
936 spin_unlock_bh(&sp->rxlock);
951 sixpack_decode(struct sixpack *sp, const unsigned char *pre_rbuff, int count)
959 tnc_set_sync_state(sp, TNC_IN_SYNC);
960 del_timer(&sp->resync_t);
963 decode_prio_command(sp, inbyte);
965 decode_std_command(sp, inbyte);
966 else if ((sp->status & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK) {
967 spin_lock_bh(&sp->rxlock);
968 decode_data(sp, inbyte);
969 spin_unlock_bh(&sp->rxlock);