Lines Matching refs:mc

404 static int pcan_usb_update_ts(struct pcan_usb_msg_context *mc)  in pcan_usb_update_ts()  argument
406 if ((mc->ptr + 2) > mc->end) in pcan_usb_update_ts()
409 mc->ts16 = get_unaligned_le16(mc->ptr); in pcan_usb_update_ts()
411 if (mc->rec_idx > 0) in pcan_usb_update_ts()
412 peak_usb_update_ts_now(&mc->pdev->time_ref, mc->ts16); in pcan_usb_update_ts()
414 peak_usb_set_ts_now(&mc->pdev->time_ref, mc->ts16); in pcan_usb_update_ts()
422 static int pcan_usb_decode_ts(struct pcan_usb_msg_context *mc, u8 first_packet) in pcan_usb_decode_ts() argument
426 if ((mc->ptr + 2) > mc->end) in pcan_usb_decode_ts()
429 mc->ts16 = get_unaligned_le16(mc->ptr); in pcan_usb_decode_ts()
430 mc->prev_ts8 = mc->ts16 & 0x00ff; in pcan_usb_decode_ts()
432 mc->ptr += 2; in pcan_usb_decode_ts()
436 if ((mc->ptr + 1) > mc->end) in pcan_usb_decode_ts()
439 ts8 = *mc->ptr++; in pcan_usb_decode_ts()
441 if (ts8 < mc->prev_ts8) in pcan_usb_decode_ts()
442 mc->ts16 += 0x100; in pcan_usb_decode_ts()
444 mc->ts16 &= 0xff00; in pcan_usb_decode_ts()
445 mc->ts16 |= ts8; in pcan_usb_decode_ts()
446 mc->prev_ts8 = ts8; in pcan_usb_decode_ts()
452 static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n, in pcan_usb_decode_error() argument
461 if (!mc->pdev->time_ref.tick_count) in pcan_usb_decode_error()
465 skb = alloc_can_err_skb(mc->netdev, &cf); in pcan_usb_decode_error()
469 netdev_dbg(mc->netdev, "data overrun interrupt\n"); in pcan_usb_decode_error()
470 mc->netdev->stats.rx_over_errors++; in pcan_usb_decode_error()
471 mc->netdev->stats.rx_errors++; in pcan_usb_decode_error()
479 netdev_dbg(mc->netdev, "device Tx queue full)\n"); in pcan_usb_decode_error()
484 new_state = ((mc->pdev->bec.txerr >= 128) || in pcan_usb_decode_error()
485 (mc->pdev->bec.rxerr >= 128)) ? in pcan_usb_decode_error()
493 if (new_state != mc->pdev->dev.can.state) { in pcan_usb_decode_error()
495 (mc->pdev->bec.txerr >= mc->pdev->bec.rxerr) ? in pcan_usb_decode_error()
498 (mc->pdev->bec.txerr <= mc->pdev->bec.rxerr) ? in pcan_usb_decode_error()
501 can_change_state(mc->netdev, cf, tx_state, rx_state); in pcan_usb_decode_error()
504 can_bus_off(mc->netdev); in pcan_usb_decode_error()
510 cf->data[6] = mc->pdev->bec.txerr; in pcan_usb_decode_error()
511 cf->data[7] = mc->pdev->bec.rxerr; in pcan_usb_decode_error()
521 peak_usb_get_ts_time(&mc->pdev->time_ref, mc->ts16, in pcan_usb_decode_error()
533 static int pcan_usb_handle_bus_evt(struct pcan_usb_msg_context *mc, u8 ir) in pcan_usb_handle_bus_evt() argument
535 struct pcan_usb *pdev = mc->pdev; in pcan_usb_handle_bus_evt()
543 pdev->bec.rxerr = mc->ptr[1]; in pcan_usb_handle_bus_evt()
544 pdev->bec.txerr = mc->ptr[2]; in pcan_usb_handle_bus_evt()
558 static int pcan_usb_decode_status(struct pcan_usb_msg_context *mc, in pcan_usb_decode_status() argument
566 if ((mc->ptr + 2) > mc->end) in pcan_usb_decode_status()
569 f = mc->ptr[PCAN_USB_CMD_FUNC]; in pcan_usb_decode_status()
570 n = mc->ptr[PCAN_USB_CMD_NUM]; in pcan_usb_decode_status()
571 mc->ptr += PCAN_USB_CMD_ARGS; in pcan_usb_decode_status()
574 int err = pcan_usb_decode_ts(mc, !mc->rec_ts_idx); in pcan_usb_decode_status()
582 mc->rec_ts_idx++; in pcan_usb_decode_status()
587 err = pcan_usb_decode_error(mc, n, status_len); in pcan_usb_decode_status()
604 if (pcan_usb_update_ts(mc)) in pcan_usb_decode_status()
610 err = pcan_usb_handle_bus_evt(mc, n); in pcan_usb_decode_status()
615 netdev_err(mc->netdev, "unexpected function %u\n", f); in pcan_usb_decode_status()
619 if ((mc->ptr + rec_len) > mc->end) in pcan_usb_decode_status()
622 mc->ptr += rec_len; in pcan_usb_decode_status()
630 static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) in pcan_usb_decode_data() argument
638 skb = alloc_can_skb(mc->netdev, &cf); in pcan_usb_decode_data()
643 if ((mc->ptr + 4) > mc->end) in pcan_usb_decode_data()
646 can_id_flags = get_unaligned_le32(mc->ptr); in pcan_usb_decode_data()
648 mc->ptr += 4; in pcan_usb_decode_data()
650 if ((mc->ptr + 2) > mc->end) in pcan_usb_decode_data()
653 can_id_flags = get_unaligned_le16(mc->ptr); in pcan_usb_decode_data()
655 mc->ptr += 2; in pcan_usb_decode_data()
658 can_frame_set_cc_len(cf, rec_len, mc->pdev->dev.can.ctrlmode); in pcan_usb_decode_data()
661 if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) in pcan_usb_decode_data()
665 mc->rec_ts_idx++; in pcan_usb_decode_data()
672 if ((mc->ptr + rec_len) > mc->end) in pcan_usb_decode_data()
675 memcpy(cf->data, mc->ptr, cf->len); in pcan_usb_decode_data()
676 mc->ptr += rec_len; in pcan_usb_decode_data()
680 mc->ptr++; in pcan_usb_decode_data()
683 mc->netdev->stats.rx_bytes += cf->len; in pcan_usb_decode_data()
685 mc->netdev->stats.rx_packets++; in pcan_usb_decode_data()
689 peak_usb_get_ts_time(&mc->pdev->time_ref, mc->ts16, &hwts->hwtstamp); in pcan_usb_decode_data()
706 struct pcan_usb_msg_context mc = { in pcan_usb_decode_msg() local
715 for (err = 0; mc.rec_idx < mc.rec_cnt && !err; mc.rec_idx++) { in pcan_usb_decode_msg()
716 u8 sl = *mc.ptr++; in pcan_usb_decode_msg()
720 err = pcan_usb_decode_status(&mc, sl); in pcan_usb_decode_msg()
723 err = pcan_usb_decode_data(&mc, sl); in pcan_usb_decode_msg()