• Home
  • Raw
  • Download

Lines Matching refs:sl

112 	struct slcan *sl = netdev_priv(ndev);  in slcan_err_rst_on_open()  local
114 return !!test_bit(CF_ERR_RST, &sl->cmd_flags); in slcan_err_rst_on_open()
119 struct slcan *sl = netdev_priv(ndev); in slcan_enable_err_rst_on_open() local
125 set_bit(CF_ERR_RST, &sl->cmd_flags); in slcan_enable_err_rst_on_open()
127 clear_bit(CF_ERR_RST, &sl->cmd_flags); in slcan_enable_err_rst_on_open()
171 static void slcan_bump_frame(struct slcan *sl) in slcan_bump_frame() argument
177 char *cmd = sl->rbuff; in slcan_bump_frame()
179 skb = alloc_can_skb(sl->dev, &cf); in slcan_bump_frame()
181 sl->dev->stats.rx_dropped++; in slcan_bump_frame()
191 cf->len = sl->rbuff[SLCAN_CMD_LEN + SLCAN_SFF_ID_LEN]; in slcan_bump_frame()
192 sl->rbuff[SLCAN_CMD_LEN + SLCAN_SFF_ID_LEN] = 0; in slcan_bump_frame()
202 cf->len = sl->rbuff[SLCAN_CMD_LEN + SLCAN_EFF_ID_LEN]; in slcan_bump_frame()
203 sl->rbuff[SLCAN_CMD_LEN + SLCAN_EFF_ID_LEN] = 0; in slcan_bump_frame()
211 if (kstrtou32(sl->rbuff + SLCAN_CMD_LEN, 16, &tmpid)) in slcan_bump_frame()
238 sl->dev->stats.rx_packets++; in slcan_bump_frame()
240 sl->dev->stats.rx_bytes += cf->len; in slcan_bump_frame()
246 sl->dev->stats.rx_errors++; in slcan_bump_frame()
258 static void slcan_bump_state(struct slcan *sl) in slcan_bump_state() argument
260 struct net_device *dev = sl->dev; in slcan_bump_state()
263 char *cmd = sl->rbuff; in slcan_bump_state()
284 if (state == sl->can.state || sl->rcount < SLCAN_STATE_FRAME_LEN) in slcan_bump_state()
322 static void slcan_bump_err(struct slcan *sl) in slcan_bump_err() argument
324 struct net_device *dev = sl->dev; in slcan_bump_err()
327 char *cmd = sl->rbuff; in slcan_bump_err()
338 if ((len + SLCAN_CMD_LEN + 1) > sl->rcount) in slcan_bump_err()
435 static void slcan_bump(struct slcan *sl) in slcan_bump() argument
437 switch (sl->rbuff[0]) { in slcan_bump()
445 return slcan_bump_frame(sl); in slcan_bump()
447 return slcan_bump_err(sl); in slcan_bump()
449 return slcan_bump_state(sl); in slcan_bump()
456 static void slcan_unesc(struct slcan *sl, unsigned char s) in slcan_unesc() argument
459 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) && in slcan_unesc()
460 sl->rcount > 4) in slcan_unesc()
461 slcan_bump(sl); in slcan_unesc()
463 sl->rcount = 0; in slcan_unesc()
465 if (!test_bit(SLF_ERROR, &sl->flags)) { in slcan_unesc()
466 if (sl->rcount < SLCAN_MTU) { in slcan_unesc()
467 sl->rbuff[sl->rcount++] = s; in slcan_unesc()
471 sl->dev->stats.rx_over_errors++; in slcan_unesc()
472 set_bit(SLF_ERROR, &sl->flags); in slcan_unesc()
482 static void slcan_encaps(struct slcan *sl, struct can_frame *cf) in slcan_encaps() argument
489 pos = sl->xbuff; in slcan_encaps()
523 sl->dev->stats.tx_bytes += cf->len; in slcan_encaps()
536 set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); in slcan_encaps()
537 actual = sl->tty->ops->write(sl->tty, sl->xbuff, pos - sl->xbuff); in slcan_encaps()
538 sl->xleft = (pos - sl->xbuff) - actual; in slcan_encaps()
539 sl->xhead = sl->xbuff + actual; in slcan_encaps()
545 struct slcan *sl = container_of(work, struct slcan, tx_work); in slcan_transmit() local
548 spin_lock_bh(&sl->lock); in slcan_transmit()
550 if (unlikely(!netif_running(sl->dev)) && in slcan_transmit()
551 likely(!test_bit(SLF_XCMD, &sl->flags))) { in slcan_transmit()
552 spin_unlock_bh(&sl->lock); in slcan_transmit()
556 if (sl->xleft <= 0) { in slcan_transmit()
557 if (unlikely(test_bit(SLF_XCMD, &sl->flags))) { in slcan_transmit()
558 clear_bit(SLF_XCMD, &sl->flags); in slcan_transmit()
559 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); in slcan_transmit()
560 spin_unlock_bh(&sl->lock); in slcan_transmit()
561 wake_up(&sl->xcmd_wait); in slcan_transmit()
568 sl->dev->stats.tx_packets++; in slcan_transmit()
569 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); in slcan_transmit()
570 spin_unlock_bh(&sl->lock); in slcan_transmit()
571 netif_wake_queue(sl->dev); in slcan_transmit()
575 actual = sl->tty->ops->write(sl->tty, sl->xhead, sl->xleft); in slcan_transmit()
576 sl->xleft -= actual; in slcan_transmit()
577 sl->xhead += actual; in slcan_transmit()
578 spin_unlock_bh(&sl->lock); in slcan_transmit()
586 struct slcan *sl = tty->disc_data; in slcan_write_wakeup() local
588 schedule_work(&sl->tx_work); in slcan_write_wakeup()
595 struct slcan *sl = netdev_priv(dev); in slcan_netdev_xmit() local
600 spin_lock(&sl->lock); in slcan_netdev_xmit()
602 spin_unlock(&sl->lock); in slcan_netdev_xmit()
606 if (!sl->tty) { in slcan_netdev_xmit()
607 spin_unlock(&sl->lock); in slcan_netdev_xmit()
611 netif_stop_queue(sl->dev); in slcan_netdev_xmit()
612 slcan_encaps(sl, (struct can_frame *)skb->data); /* encaps & send */ in slcan_netdev_xmit()
613 spin_unlock(&sl->lock); in slcan_netdev_xmit()
626 static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) in slcan_transmit_cmd() argument
630 spin_lock(&sl->lock); in slcan_transmit_cmd()
631 if (!sl->tty) { in slcan_transmit_cmd()
632 spin_unlock(&sl->lock); in slcan_transmit_cmd()
636 n = scnprintf(sl->xbuff, sizeof(sl->xbuff), "%s", cmd); in slcan_transmit_cmd()
637 set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); in slcan_transmit_cmd()
638 actual = sl->tty->ops->write(sl->tty, sl->xbuff, n); in slcan_transmit_cmd()
639 sl->xleft = n - actual; in slcan_transmit_cmd()
640 sl->xhead = sl->xbuff + actual; in slcan_transmit_cmd()
641 set_bit(SLF_XCMD, &sl->flags); in slcan_transmit_cmd()
642 spin_unlock(&sl->lock); in slcan_transmit_cmd()
643 ret = wait_event_interruptible_timeout(sl->xcmd_wait, in slcan_transmit_cmd()
644 !test_bit(SLF_XCMD, &sl->flags), in slcan_transmit_cmd()
646 clear_bit(SLF_XCMD, &sl->flags); in slcan_transmit_cmd()
659 struct slcan *sl = netdev_priv(dev); in slcan_netdev_close() local
662 if (sl->can.bittiming.bitrate && in slcan_netdev_close()
663 sl->can.bittiming.bitrate != CAN_BITRATE_UNKNOWN) { in slcan_netdev_close()
664 err = slcan_transmit_cmd(sl, "C\r"); in slcan_netdev_close()
671 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); in slcan_netdev_close()
672 flush_work(&sl->tx_work); in slcan_netdev_close()
675 sl->rcount = 0; in slcan_netdev_close()
676 sl->xleft = 0; in slcan_netdev_close()
678 sl->can.state = CAN_STATE_STOPPED; in slcan_netdev_close()
679 if (sl->can.bittiming.bitrate == CAN_BITRATE_UNKNOWN) in slcan_netdev_close()
680 sl->can.bittiming.bitrate = CAN_BITRATE_UNSET; in slcan_netdev_close()
688 struct slcan *sl = netdev_priv(dev); in slcan_netdev_open() local
697 if (sl->can.bittiming.bitrate == CAN_BITRATE_UNSET) in slcan_netdev_open()
698 sl->can.bittiming.bitrate = CAN_BITRATE_UNKNOWN; in slcan_netdev_open()
706 if (sl->can.bittiming.bitrate != CAN_BITRATE_UNKNOWN) { in slcan_netdev_open()
708 if (sl->can.bittiming.bitrate == slcan_bitrate_const[s]) in slcan_netdev_open()
716 err = slcan_transmit_cmd(sl, cmd); in slcan_netdev_open()
724 if (test_bit(CF_ERR_RST, &sl->cmd_flags)) { in slcan_netdev_open()
725 err = slcan_transmit_cmd(sl, "F\r"); in slcan_netdev_open()
733 if (sl->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) { in slcan_netdev_open()
734 err = slcan_transmit_cmd(sl, "L\r"); in slcan_netdev_open()
741 err = slcan_transmit_cmd(sl, "O\r"); in slcan_netdev_open()
750 sl->can.state = CAN_STATE_ERROR_ACTIVE; in slcan_netdev_open()
780 struct slcan *sl = tty->disc_data; in slcan_receive_buf() local
782 if (!netif_running(sl->dev)) in slcan_receive_buf()
788 if (!test_and_set_bit(SLF_ERROR, &sl->flags)) in slcan_receive_buf()
789 sl->dev->stats.rx_errors++; in slcan_receive_buf()
793 slcan_unesc(sl, *cp++); in slcan_receive_buf()
806 struct slcan *sl; in slcan_open() local
815 dev = alloc_candev(sizeof(*sl), 1); in slcan_open()
819 sl = netdev_priv(dev); in slcan_open()
823 sl->rcount = 0; in slcan_open()
824 sl->xleft = 0; in slcan_open()
825 spin_lock_init(&sl->lock); in slcan_open()
826 INIT_WORK(&sl->tx_work, slcan_transmit); in slcan_open()
827 init_waitqueue_head(&sl->xcmd_wait); in slcan_open()
830 sl->can.bitrate_const = slcan_bitrate_const; in slcan_open()
831 sl->can.bitrate_const_cnt = ARRAY_SIZE(slcan_bitrate_const); in slcan_open()
832 sl->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY; in slcan_open()
835 sl->dev = dev; in slcan_open()
840 sl->tty = tty; in slcan_open()
841 tty->disc_data = sl; in slcan_open()
864 struct slcan *sl = tty->disc_data; in slcan_close() local
866 unregister_candev(sl->dev); in slcan_close()
872 flush_work(&sl->tx_work); in slcan_close()
875 spin_lock_bh(&sl->lock); in slcan_close()
877 sl->tty = NULL; in slcan_close()
878 spin_unlock_bh(&sl->lock); in slcan_close()
880 netdev_info(sl->dev, "slcan off %s.\n", tty->name); in slcan_close()
881 free_candev(sl->dev); in slcan_close()
888 struct slcan *sl = tty->disc_data; in slcan_ioctl() local
893 tmp = strlen(sl->dev->name) + 1; in slcan_ioctl()
894 if (copy_to_user((void __user *)arg, sl->dev->name, tmp)) in slcan_ioctl()