- 0x80, 0xc0, 0x40, 0x00, 0xc0, 0x80, 0x00, 0x40,
- 0x00, 0x40, 0xc0, 0x80, 0x40, 0x00, 0x80, 0xc0,
- 0x40, 0x00, 0x80, 0xc0, 0x00, 0x40, 0xc0, 0x80,
- 0xc0, 0x80, 0x00, 0x40, 0x80, 0xc0, 0x40, 0x00,
- 0x00, 0x40, 0xc0, 0x80, 0x40, 0x00, 0x80, 0xc0,
- 0x80, 0xc0, 0x40, 0x00, 0xc0, 0x80, 0x00, 0x40,
- 0xc0, 0x80, 0x00, 0x40, 0x80, 0xc0, 0x40, 0x00,
- 0x40, 0x00, 0x80, 0xc0, 0x00, 0x40, 0xc0, 0x80
+ 0x80, 0xc0, 0x40, 0x00, 0xc0, 0x80, 0x00, 0x40,
+ 0x00, 0x40, 0xc0, 0x80, 0x40, 0x00, 0x80, 0xc0,
+ 0x40, 0x00, 0x80, 0xc0, 0x00, 0x40, 0xc0, 0x80,
+ 0xc0, 0x80, 0x00, 0x40, 0x80, 0xc0, 0x40, 0x00,
+ 0x00, 0x40, 0xc0, 0x80, 0x40, 0x00, 0x80, 0xc0,
+ 0x80, 0xc0, 0x40, 0x00, 0xc0, 0x80, 0x00, 0x40,
+ 0xc0, 0x80, 0x00, 0x40, 0x80, 0xc0, 0x40, 0x00,
+ 0x40, 0x00, 0x80, 0xc0, 0x00, 0x40, 0xc0, 0x80
- if (sl->lin_master == true) {
- if (sl->rx_cnt >= sl->rx_expect) { /* Probably whole frame was received */
- set_bit(SLF_RXEVENT, &sl->flags);
- wake_up(&sl->kwt_wq);
- pr_debug("sllin: sllin_receive_buf count %d, wakeup\n", sl->rx_cnt);
- } else {
- pr_debug("sllin: sllin_receive_buf count %d, waiting\n", sl->rx_cnt);
- }
- } else { /* LIN slave */
- int lin_id;
- struct sllin_conf_entry *sce;
-
- pr_debug("sllin: rx_cnt = %u; header_received = %u\n",
- sl->rx_cnt, sl->header_received);
-
- /* Whole header was received */
- if ((sl->rx_cnt >= (SLLIN_BUFF_ID + 1)) &&
- (sl->header_received == false))
- {
- lin_id = sl->rx_buff[SLLIN_BUFF_ID] & LIN_ID_MASK;
- sce = &sl->linfr_cache[lin_id];
-
- /* Is the length of data set in frame cache? */
- if (sce->frame_fl & LIN_LOC_SLAVE_CACHE)
- sl->rx_expect += sce->dlc;
- else
- sl->rx_expect += 2; /* 1 data byte + checksum */
-
- sl->header_received = true;
- sll_send_rtr(sl);
- }
+ if (sl->lin_master == true) {
+ if (SLL_RESPONSE_RECEIVED) {
+ set_bit(SLF_RXEVENT, &sl->flags);
+ wake_up(&sl->kwt_wq);
+ pr_debug("sllin: sllin_receive_buf count %d, wakeup\n", sl->rx_cnt);
+ } else {
+ pr_debug("sllin: sllin_receive_buf count %d, waiting\n", sl->rx_cnt);
+ }
+ } else { /* LIN slave */
+ int lin_id;
+ struct sllin_conf_entry *sce;
+
+ pr_debug("sllin: rx_cnt = %u; header_received = %u\n",
+ sl->rx_cnt, sl->header_received);
+
+ if (SLL_HEADER_RECEIVED) {
+ lin_id = sl->rx_buff[SLLIN_BUFF_ID] & LIN_ID_MASK;
+ sce = &sl->linfr_cache[lin_id];
+
+ spin_lock(&sl->lock);
+ /* Is the length of data set in frame cache? */
+ if (sce->frame_fl & LIN_LOC_SLAVE_CACHE) {
+ sl->rx_expect += sce->dlc;
+ sl->rx_len_unknown = false;
+ } else {
+ sl->rx_expect += SLLIN_DATA_MAX + 1; /* + checksum */
+ sl->rx_len_unknown = true;
+ }
+ spin_unlock(&sl->lock);
- /* Probably whole frame was received */
- if ((sl->rx_cnt >= sl->rx_expect) && (sl->rx_cnt > SLLIN_BUFF_DATA)) {
- sll_bump(sl);
- pr_debug("sllin: Received LIN header & LIN response. "
- "rx_cnt = %u, rx_expect = %u\n", sl->rx_cnt,
- sl->rx_expect);
-
- /* Prepare for reception of new header */
- sl->rx_cnt = 0;
- sl->rx_expect = SLLIN_BUFF_ID + 1;
- sl->header_received = false;
+ sl->header_received = true;
+ sll_send_rtr(sl);
+ continue;
+ }
+
+ if (SLL_RESPONSE_RECEIVED) {
+ sll_bump(sl);
+ pr_debug("sllin: Received LIN header & LIN response. "
+ "rx_cnt = %u, rx_expect = %u\n", sl->rx_cnt,
+ sl->rx_expect);
+
+ /* Prepare for reception of new header */
+ sl->rx_cnt = 0;
+ sl->rx_expect = SLLIN_BUFF_ID + 1;
+ sl->rx_len_unknown = false; /* We do know exact length of the header */
+ sl->header_received = false;
+ }
- /* SFF RTR CAN frame -> LIN header */
- if (cf->can_id & CAN_RTR_FLAG) {
- spin_lock(&sl->lock);
- pr_debug("sllin: %s: RTR SFF CAN frame, ID = %x\n",
- __FUNCTION__, cf->can_id & LIN_ID_MASK);
-
- /* Is there Slave response in linfr_cache to be sent? */
- if ((sl->linfr_cache[cf->can_id & LIN_ID_MASK].frame_fl &
- LIN_LOC_SLAVE_CACHE)
- && (sl->linfr_cache[cf->can_id & LIN_ID_MASK].dlc > 0)) {
-
- pr_debug("sllin: Sending LIN response from linfr_cache\n");
- lin_data = sl->linfr_cache[cf->can_id & LIN_ID_MASK].data;
- lin_dlc = sl->linfr_cache[cf->can_id & LIN_ID_MASK].dlc;
- if (lin_dlc > SLLIN_DATA_MAX)
- lin_dlc = SLLIN_DATA_MAX;
- memcpy(lin_data_buff, lin_data, lin_dlc);
- lin_data = lin_data_buff;
- } else {
- lin_data = NULL;
- lin_dlc = sl->linfr_cache[cf->can_id & LIN_ID_MASK].dlc;
- }
- spin_unlock(&sl->lock);
- } else { /* SFF NON-RTR CAN frame -> LIN header + LIN response */
- pr_debug("sllin: %s: NON-RTR SFF CAN frame, ID = %x\n",
- __FUNCTION__, (int)cf->can_id & LIN_ID_MASK);
+ /* SFF RTR CAN frame -> LIN header */
+ if (cf->can_id & CAN_RTR_FLAG) {
+ spin_lock(&sl->lock);
+ pr_debug("sllin: %s: RTR SFF CAN frame, ID = %x\n",
+ __FUNCTION__, cf->can_id & LIN_ID_MASK);
+
+ /* Is there Slave response in linfr_cache to be sent? */
+ if ((sl->linfr_cache[cf->can_id & LIN_ID_MASK].frame_fl &
+ LIN_LOC_SLAVE_CACHE)
+ && (sl->linfr_cache[cf->can_id & LIN_ID_MASK].dlc > 0)) {
- 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;
+ 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_ID_SENT:
- hrtimer_cancel(&sl->rx_timer);
- sl->id_to_send = false;
- if (sl->data_to_send) {
- sllin_send_tx_buff(sl);
- sl->lin_state = SLSTATE_RESPONSE_SENT;
- sl->rx_expect = sl->tx_lim;
- goto slstate_response_sent;
+ case SLSTATE_ID_SENT:
+ hrtimer_cancel(&sl->rx_timer);
+ sl->id_to_send = false;
+ if (sl->data_to_send) {
+ sllin_send_tx_buff(sl);
+ sl->lin_state = SLSTATE_RESPONSE_SENT;
+ sl->rx_expect = sl->tx_lim;
+ goto slstate_response_sent;
+ } else {
+ if (sl->resp_len_known) {
+ sl->rx_expect = sl->rx_lim;
- if (sl->resp_len_known) {
- sl->rx_expect = sl->rx_lim;
- } else {
- sl->rx_expect = SLLIN_BUFF_DATA + 2;
- }
- sl->lin_state = SLSTATE_RESPONSE_WAIT;
- /* If we don't receive anything, timer will "unblock" us */
- hrtimer_start(&sl->rx_timer,
- ktime_add(ktime_get(), sl->rx_timer_timeout),
- HRTIMER_MODE_ABS);
- goto slstate_response_wait;
+ sl->rx_expect = SLLIN_BUFF_DATA + 2;
- case SLSTATE_RESPONSE_WAIT:
- slstate_response_wait:
- if (test_bit(SLF_MSGEVENT, &sl->flags)) {
- unsigned char *lin_buff;
- cf = (struct can_frame *)sl->tx_req_skb->data;
-
- 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) {
-
- sl->rx_expect = sl->tx_lim;
- sl->data_to_send = true;
- sl->dev->stats.tx_packets++;
- sl->dev->stats.tx_bytes += tx_bytes;
-
- if (!sl->lin_master) {
- sl->tx_cnt = SLLIN_BUFF_DATA;
- }
-
- sllin_send_tx_buff(sl);
- clear_bit(SLF_MSGEVENT, &sl->flags);
- kfree_skb(sl->tx_req_skb);
- netif_wake_queue(sl->dev);
-
- sl->lin_state = SLSTATE_RESPONSE_SENT;
- goto slstate_response_sent;
- }
- } else {
- sl->lin_state = SLSTATE_RESPONSE_WAIT_BUS;
- }
- }
+ case SLSTATE_RESPONSE_WAIT:
+slstate_response_wait:
+ if (test_bit(SLF_MSGEVENT, &sl->flags)) {
+ unsigned char *lin_buff;
+ cf = (struct can_frame *)sl->tx_req_skb->data;
- /* Be aware, no BREAK here */
- case SLSTATE_RESPONSE_WAIT_BUS:
- if (sl->rx_cnt < sl->rx_expect)
- continue;
+ 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) {
+
+ sl->rx_expect = sl->tx_lim;
+ sl->data_to_send = true;
+ sl->dev->stats.tx_packets++;
+ sl->dev->stats.tx_bytes += tx_bytes;
+
+ if (!sl->lin_master) {
+ sl->tx_cnt = SLLIN_BUFF_DATA;
+ }
- hrtimer_cancel(&sl->rx_timer);
+ hrtimer_cancel(&sl->rx_timer);
+ pr_debug("sllin: response received ID %d len %d\n",
+ sl->rx_buff[SLLIN_BUFF_ID], sl->rx_cnt - SLLIN_BUFF_DATA - 1);
+
+ if (sllin_rx_validate(sl) == -1) {
+ pr_debug("sllin: RX validation failed.\n");
+ sllin_report_error(sl, LIN_ERR_CHECKSUM);
+ } else {
+ /* Send CAN non-RTR frame with data */
+ pr_debug("sllin: sending NON-RTR CAN"
+ "frame with LIN payload.");
- sl->id_to_send = false;
- sl->lin_state = SLSTATE_IDLE;
- break;
+ sl->id_to_send = false;
+ sl->lin_state = SLSTATE_IDLE;
+ break;
+
+ case SLSTATE_RESPONSE_SENT:
+slstate_response_sent:
+ if (sl->rx_cnt < sl->tx_lim)
+ continue;
+
+ hrtimer_cancel(&sl->rx_timer);
+ sll_bump(sl); /* send packet to the network layer */
+ pr_debug("sllin: response sent ID %d len %d\n",
+ sl->rx_buff[SLLIN_BUFF_ID], sl->rx_cnt - SLLIN_BUFF_DATA - 1);
+
+ sl->id_to_send = false;
+ sl->lin_state = SLSTATE_IDLE;
+ break;