]> rtime.felk.cvut.cz Git - linux-lin.git/blobdiff - sllin/sllin.c
sllin: Ensure full initialization of all termios flags.
[linux-lin.git] / sllin / sllin.c
index e07558994abde83283d66126ce0dc2902d390c3b..92420f0e3ce0b29a4559ba8fd923cb21edc51ce1 100644 (file)
@@ -188,10 +188,16 @@ static int sltty_change_speed(struct tty_struct *tty, unsigned speed)
        mutex_lock(&tty->termios_mutex);
 
        old_termios = *(tty->termios);
-       cflag = tty->termios->c_cflag;
+
+       cflag = CS8 | CREAD | CLOCAL | HUPCL;
        cflag &= ~(CBAUD | CIBAUD);
        cflag |= BOTHER;
        tty->termios->c_cflag = cflag;
+       tty->termios->c_oflag = 0;
+       tty->termios->c_lflag = 0;
+
+       /* Enable interrupt when UART-Break or Framing error received */
+       tty->termios->c_iflag = BRKINT | INPCK;
 
        tty_encode_baud_rate(tty, speed, speed);
 
@@ -203,7 +209,6 @@ static int sltty_change_speed(struct tty_struct *tty, unsigned speed)
        return 0;
 }
 
-
 /* Send one can_frame to the network layer */
 static void sllin_send_canfr(struct sllin *sl, canid_t id, char *data, int len)
 {
@@ -230,8 +235,6 @@ static void sllin_send_canfr(struct sllin *sl, canid_t id, char *data, int len)
 
        sl->dev->stats.rx_packets++;
        sl->dev->stats.rx_bytes += cf.can_dlc;
-
-
 }
 
 /**
@@ -419,9 +422,11 @@ static void sllin_receive_buf(struct tty_struct *tty,
                if (fp && *fp++) {
                        if (!test_and_set_bit(SLF_ERROR, &sl->flags))
                                sl->dev->stats.rx_errors++;
+
                        pr_debug("sllin: sllin_receive_buf char 0x%02x ignored "
                                "due marker 0x%02x, flags 0x%lx\n",
                                *cp, *(fp-1), sl->flags);
+
                        cp++;
                        continue;
                }
@@ -459,6 +464,16 @@ static void sllin_receive_buf(struct tty_struct *tty,
  */
 void sllin_report_error(struct sllin *sl, int err)
 {
+       switch (err) {
+               case LIN_ERR_CHECKSUM:
+                       sl->dev->stats.rx_crc_errors++;
+                       break;
+
+               case LIN_ERR_RX_TIMEOUT:                
+                       sl->dev->stats.rx_errors++;
+                       break;
+       }
+
        sllin_send_canfr(sl, 0 | CAN_EFF_FLAG |
                (err & ~LIN_ID_MASK), NULL, 0);
 }
@@ -823,6 +838,9 @@ int sllin_kwthread(void *ptr)
                                clear_bit(SLF_MSGEVENT, &sl->flags);
                                kfree_skb(sl->tx_req_skb);
                                netif_wake_queue(sl->dev);
+                               hrtimer_start(&sl->rx_timer,
+                                       ktime_add(ktime_get(), sl->rx_timer_timeout),
+                                       HRTIMER_MODE_ABS);
                                break;
 
                        case SLSTATE_BREAK_SENT:
@@ -838,6 +856,7 @@ int sllin_kwthread(void *ptr)
                                break;
 
                        case SLSTATE_ID_SENT:
+                               hrtimer_cancel(&sl->rx_timer);
                                sl->id_to_send = false;
                                if (sl->data_to_send) {
                                        sllin_send_tx_buff(sl);
@@ -867,6 +886,8 @@ int sllin_kwthread(void *ptr)
 
                                        lin_buff = (sl->lin_master) ? sl->tx_buff : sl->rx_buff;
                                        if (cf->can_id == (lin_buff[SLLIN_BUFF_ID] & LIN_ID_MASK)) {
+                                               hrtimer_cancel(&sl->rx_timer);
+                                               pr_debug("sllin: received LIN response in a CAN frame.\n");
                                                if (sllin_setup_msg(sl, SLLIN_STPMSG_RESPONLY,
                                                        cf->can_id & LIN_ID_MASK,
                                                        cf->data, cf->can_dlc) != -1) {
@@ -905,7 +926,6 @@ int sllin_kwthread(void *ptr)
                                if (sllin_rx_validate(sl) == -1) {
                                        pr_debug("sllin: RX validation failed.\n");
                                        sllin_report_error(sl, LIN_ERR_CHECKSUM);
-                                       /* FIXME tx_stat.err++ */
                                } else {
                                        /* Send CAN non-RTR frame with data */
                                        pr_debug("sllin: sending NON-RTR CAN"
@@ -930,12 +950,6 @@ int sllin_kwthread(void *ptr)
                                sl->lin_state = SLSTATE_IDLE;
                                break;
                }
-
-
-
-
-               /* sl->dev->stats.tx_packets++; send frames statistic */
-               /* netif_wake_queue(sl->dev); allow next Tx packet arrival */
        }
 
        hrtimer_cancel(&sl->rx_timer);