Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4590814 authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "drivers: net: can: Add timestamp adjustment for can frames in qti-can"

parents cd27b401 891a9305
Loading
Loading
Loading
Loading
+32 −5
Original line number Diff line number Diff line
/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -45,6 +45,7 @@
#define DRIVER_MODE_PROPERTIES		1
#define DRIVER_MODE_AMB			2
#define QUERY_FIRMWARE_TIMEOUT_MS	100
#define EUPGRADE			140

struct qti_can {
	struct net_device	**netdev;
@@ -70,6 +71,7 @@ struct qti_can {
	bool can_fw_cmd_timeout_req;
	u32 rem_all_buffering_timeout_ms;
	u32 can_fw_cmd_timeout_ms;
	s64 time_diff;
};

struct qti_can_netdev_privdata {
@@ -119,6 +121,7 @@ struct spi_miso { /* TLV for MISO line */
#define CMD_BOOT_ROM_UPGRADE_DATA	0x9A
#define CMD_END_BOOT_ROM_UPGRADE	0x9B
#define CMD_END_FW_UPDATE_FILE		0x9C
#define CMD_UPDATE_TIME_INFO		0x9D

#define IOCTL_RELEASE_CAN_BUFFER	(SIOCDEVPRIVATE + 0)
#define IOCTL_ENABLE_BUFFERING		(SIOCDEVPRIVATE + 1)
@@ -165,7 +168,7 @@ struct can_add_filter_resp {

struct can_receive_frame {
	u8 can_if;
	u32 ts;
	u64 ts;
	u32 mid;
	u8 dlc;
	u8 data[8];
@@ -180,6 +183,10 @@ struct can_config_bit_timing {
	u32 brp;
} __packed;

struct can_time_info {
	u64 time;
} __packed;

static struct can_bittiming_const rh850_bittiming_const = {
	.name = "qti_can",
	.tseg1_min = 1,
@@ -293,7 +300,7 @@ static void qti_can_receive_frame(struct qti_can *priv_data,
		return;
	}

	LOGDI("rcv frame %d %d %x %d %x %x %x %x %x %x %x %x\n",
	LOGDI("rcv frame %d %llu %x %d %x %x %x %x %x %x %x %x\n",
	      frame->can_if, frame->ts, frame->mid, frame->dlc,
	      frame->data[0], frame->data[1], frame->data[2], frame->data[3],
	      frame->data[4], frame->data[5], frame->data[6], frame->data[7]);
@@ -303,12 +310,12 @@ static void qti_can_receive_frame(struct qti_can *priv_data,
	for (i = 0; i < cf->can_dlc; i++)
		cf->data[i] = frame->data[i];

	nsec = ms_to_ktime(le32_to_cpu(frame->ts));
	nsec = ms_to_ktime(le64_to_cpu(frame->ts) + priv_data->time_diff);
	skt = skb_hwtstamps(skb);
	skt->hwtstamp = nsec;
	LOGDI("  hwtstamp %lld\n", ktime_to_ms(skt->hwtstamp));
	skb->tstamp = nsec;
	netif_rx(skb);
	LOGDI("hwtstamp: %lld\n", ktime_to_ms(skt->hwtstamp));
	netdev->stats.rx_packets++;
}

@@ -356,11 +363,21 @@ static int qti_can_process_response(struct qti_can *priv_data,
				    struct spi_miso *resp, int length)
{
	int ret = 0;
	u64 mstime;
	ktime_t ktime_now;

	LOGDI("<%x %2d [%d]\n", resp->cmd, resp->len, resp->seq);
	if (resp->cmd == CMD_CAN_RECEIVE_FRAME) {
		struct can_receive_frame *frame =
				(struct can_receive_frame *)&resp->data;
		if ((resp->len - (frame->dlc + sizeof(frame->dlc))) <
			(sizeof(*frame) - (sizeof(frame->dlc)
			+ sizeof(frame->data)))) {
			LOGDE("len:%d, size:%d\n", resp->len, sizeof(*frame));
			LOGDE("Check the f/w version & upgrade to latest!!\n");
			ret = -EUPGRADE;
			goto exit;
		}
		if (resp->len > length) {
			/* Error. This should never happen */
			LOGDE("%s error: Saving %d bytes\n", __func__, length);
@@ -373,6 +390,7 @@ static int qti_can_process_response(struct qti_can *priv_data,
	} else if (resp->cmd == CMD_PROPERTY_READ) {
		struct vehicle_property *property =
				(struct vehicle_property *)&resp->data;

		if (resp->len > length) {
			/* Error. This should never happen */
			LOGDE("%s error: Saving %d bytes\n", __func__, length);
@@ -392,6 +410,7 @@ static int qti_can_process_response(struct qti_can *priv_data,
	} else if (resp->cmd  == CMD_GET_FW_BR_VERSION) {
		struct can_fw_br_resp *fw_resp =
				(struct can_fw_br_resp *)resp->data;

		dev_info(&priv_data->spidev->dev, "fw_can %d.%d",
			 fw_resp->maj, fw_resp->min);
		dev_info(&priv_data->spidev->dev, "fw string %s",
@@ -404,8 +423,16 @@ static int qti_can_process_response(struct qti_can *priv_data,
		ret |= (fw_resp->br_min & 0xFF) << 16;
		ret |= (fw_resp->maj & 0xF) << 8;
		ret |= (fw_resp->min & 0xFF);
	} else if (resp->cmd == CMD_UPDATE_TIME_INFO) {
		struct can_time_info *time_data =
			(struct can_time_info *)resp->data;

		ktime_now = ktime_get_boottime();
		mstime = ktime_to_ms(ktime_now);
		priv_data->time_diff = mstime - (le64_to_cpu(time_data->time));
	}

exit:
	if (resp->cmd == priv_data->wait_cmd) {
		priv_data->cmd_result = ret;
		complete(&priv_data->response_completion);