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

Commit b3d0c5b7 authored by Ravi Aravamudhan's avatar Ravi Aravamudhan Committed by Gerrit - the friendly Code Review server
Browse files

diag: Separate SMUX structures from diag



Diag driver is deeply coupled with SMUX structures. Make changes
to remove references of SMUX from diag core files.

Change-Id: I2abc6b98659fea5b5b429467af9ccf5ed3d37eaf
Signed-off-by: default avatarRavi Aravamudhan <aravamud@codeaurora.org>
parent 97a56dda
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "diagfwd.h"
#include "diagfwd_bridge.h"
#include "diagfwd_hsic.h"
#include "diagfwd_smux.h"
#include "diagmem.h"
#include "diag_dci.h"

@@ -576,13 +577,17 @@ static ssize_t diag_dbgfs_read_bridge(struct file *file, char __user *ubuf,
	bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
		"Values for SMUX instance: 0\n"
		"smux ch: %d\n"
		"smux read_buf: %p\n"
		"smux read_len: %d\n"
		"smux enabled %d\n"
		"smux in busy %d\n"
		"smux connected %d\n\n",
		driver->lcid,
		driver->diag_smux_enabled,
		driver->in_busy_smux,
		driver->smux_connected);
		diag_smux->lcid,
		diag_smux->read_buf,
		diag_smux->read_len,
		diag_smux->enabled,
		diag_smux->in_busy,
		diag_smux->connected);

	bytes_in_buffer += bytes_written;
	bytes_remaining = buf_size - bytes_in_buffer;
+0 −7
Original line number Diff line number Diff line
@@ -462,13 +462,6 @@ struct diagchar_dev {
	/* common for all bridges */
	struct work_struct diag_connect_work;
	struct work_struct diag_disconnect_work;
	/* SGLTE variables */
	int lcid;
	unsigned char *buf_in_smux;
	int smux_buf_len;
	int in_busy_smux;
	int diag_smux_enabled;
	int smux_connected;
#endif
};

+18 −13
Original line number Diff line number Diff line
@@ -571,7 +571,7 @@ uint16_t diag_get_remote_device_mask(void)
			remote_dev |= 1 << i;

	/* Check for QSC processor */
	if (driver->diag_smux_enabled)
	if (diag_smux->enabled)
		remote_dev |= 1 << SMUX;

	return remote_dev;
@@ -658,7 +658,7 @@ drop_hsic:
		}
		remote_token--;
	}
	if (driver->in_busy_smux == 1) {
	if (diag_smux->in_busy == 1) {
		remote_token = diag_get_remote(QSC);
		num_data++;

@@ -667,13 +667,12 @@ drop_hsic:
			remote_token, 4);
		/* Copy the length of data being passed */
		COPY_USER_SPACE_OR_EXIT(buf+ret,
			(driver->smux_buf_len), 4);
			(diag_smux->read_len), 4);
		/* Copy the actual data being passed */
		COPY_USER_SPACE_OR_EXIT(buf+ret,
			*(driver->buf_in_smux),
			driver->smux_buf_len);
		COPY_USER_SPACE_OR_EXIT(buf+ret, *(diag_smux->read_buf),
					diag_smux->read_len);
		pr_debug("diag: SMUX  data copied\n");
		driver->in_busy_smux = 0;
		diag_smux->in_busy = 0;
	}
	exit_stat = 0;
	if (copy_data)
@@ -1923,10 +1922,10 @@ static ssize_t diagchar_write(struct file *file, const char __user *buf,
				 }
			 }
		}
		if (driver->diag_smux_enabled && (remote_proc == QSC)
						&& driver->lcid) {
		if (diag_smux->enabled && (remote_proc == QSC)
						&& diag_smux->lcid) {
			if (payload_size > 0) {
				err = msm_smux_write(driver->lcid, NULL,
				err = msm_smux_write(diag_smux->lcid, NULL,
					(char *)buf_hdlc, payload_size + 3);
				if (err) {
					pr_err("diag:send mask to MDM err %d",
@@ -2021,10 +2020,10 @@ static ssize_t diagchar_write(struct file *file, const char __user *buf,
				 }
			 }
		}
		if (driver->diag_smux_enabled && (remote_proc == QSC)
						&& driver->lcid) {
		if (diag_smux->enabled && (remote_proc == QSC)
						&& diag_smux->lcid) {
			if (payload_size > 0) {
				err = msm_smux_write(driver->lcid, NULL,
				err = msm_smux_write(diag_smux->lcid, NULL,
					driver->user_space_data_buf +
						token_offset,
						payload_size);
@@ -2604,6 +2603,12 @@ static int __init diagchar_init(void)
		pr_warn("diag: could not allocate memory for hsic dci ch\n");
		goto fail;
	}

	diag_smux = kzalloc(sizeof(struct diag_smux_info), GFP_KERNEL);
	if (!diag_smux) {
		pr_warn("diag: could not allocate memory for smux ch\n");
		goto fail;
	}
#endif

	driver->used = 0;
+13 −13
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ void connect_bridge(int process_cable, uint8_t index)
	}

	if (index == SMUX) {
		if (driver->diag_smux_enabled) {
			driver->in_busy_smux = 0;
		if (diag_smux->enabled) {
			diag_smux->in_busy = 0;
			diagfwd_connect_smux();
		}
	} else {
@@ -138,11 +138,11 @@ int diagfwd_disconnect_bridge(int process_cable)
			}

			if (i == SMUX) {
				if (driver->diag_smux_enabled &&
				if (diag_smux->enabled &&
					driver->logging_mode == USB_MODE) {
					driver->in_busy_smux = 1;
					driver->lcid = LCID_INVALID;
					driver->smux_connected = 0;
					diag_smux->in_busy = 1;
					diag_smux->lcid = LCID_INVALID;
					diag_smux->connected = 0;
					/*
					 * Turn off communication over usb
					 * and smux
@@ -176,7 +176,7 @@ int diagfwd_read_complete_bridge(struct diag_request *diag_read_ptr)
	diag_bridge[index].read_len = diag_read_ptr->actual;

	if (index == SMUX) {
		if (driver->diag_smux_enabled) {
		if (diag_smux->enabled) {
			diagfwd_read_complete_smux();
			return 0;
		} else {
@@ -256,7 +256,7 @@ static void diagfwd_bridge_notifier(void *priv, unsigned event,
		break;
	case USB_DIAG_WRITE_DONE:
		index = (int)(uintptr_t)(d_req->context);
		if (index == SMUX && driver->diag_smux_enabled) {
		if (index == SMUX && diag_smux->enabled) {
			diagfwd_write_complete_smux();
			diagmem_free(driver, d_req, POOL_TYPE_QSC_USB);
		} else if (diag_hsic[index].hsic_device_enabled) {
@@ -327,7 +327,7 @@ int diagfwd_bridge_init(int index)
			diag_bridge[index].enabled = 1;
#endif
	} else if (index == SMUX) {
		driver->smux_buf_len = 0;
		diag_smux->read_len = 0;
		INIT_WORK(&(diag_bridge[index].usb_read_complete_work),
					 diag_usb_read_complete_smux_fn);
#ifdef CONFIG_DIAG_OVER_USB
@@ -373,10 +373,10 @@ void diagfwd_bridge_exit(void)
		kfree(diag_hsic[i].hsic_buf_tbl);
	}

	if (driver->diag_smux_enabled) {
		driver->lcid = LCID_INVALID;
		kfree(driver->buf_in_smux);
		driver->diag_smux_enabled = 0;
	if (diag_smux->enabled) {
		diag_smux->lcid = LCID_INVALID;
		kfree(diag_smux->read_buf);
		diag_smux->enabled = 0;
		diag_bridge[SMUX].enabled = 0;
	}
	platform_driver_unregister(&msm_hsic_ch_driver);
+32 −30
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#include "diagfwd_hsic.h"
#include "diagfwd_bridge.h"

struct diag_smux_info *diag_smux;

void diag_smux_event(void *priv, int event_type, const void *metadata)
{
	unsigned char *rx_buf;
@@ -30,15 +32,15 @@ void diag_smux_event(void *priv, int event_type, const void *metadata)
	switch (event_type) {
	case SMUX_CONNECTED:
		pr_info("diag: SMUX_CONNECTED received\n");
		driver->smux_connected = 1;
		driver->in_busy_smux = 0;
		diag_smux->connected = 1;
		diag_smux->in_busy = 0;
		/* read data from USB MDM channel & Initiate first write */
		queue_work(diag_bridge[SMUX].wq,
			   &diag_bridge[SMUX].diag_read_work);
		break;
	case SMUX_DISCONNECTED:
		driver->smux_connected = 0;
		driver->lcid = LCID_INVALID;
		diag_smux->connected = 0;
		diag_smux->lcid = LCID_INVALID;
		msm_smux_close(LCID_VALID);
		pr_info("diag: SMUX_DISCONNECTED received\n");
		break;
@@ -54,8 +56,8 @@ void diag_smux_event(void *priv, int event_type, const void *metadata)
	case SMUX_READ_DONE:
		len = ((struct smux_meta_read *)metadata)->len;
		rx_buf = ((struct smux_meta_read *)metadata)->buffer;
		driver->smux_buf_len = len;
		diag_device_write(driver->buf_in_smux, len, SMUX_DATA, SMUX);
		diag_smux->read_len = len;
		diag_device_write(diag_smux->read_buf, len, SMUX_DATA, SMUX);
		break;
	};
}
@@ -63,7 +65,7 @@ void diag_smux_event(void *priv, int event_type, const void *metadata)
int diagfwd_write_complete_smux(void)
{
	pr_debug("diag: clear in_busy_smux\n");
	driver->in_busy_smux = 0;
	diag_smux->in_busy = 0;
	return 0;
}

@@ -75,11 +77,11 @@ int diagfwd_read_complete_smux(void)

int diag_get_rx_buffer(void *priv, void **pkt_priv, void **buffer, int size)
{
	if (!driver->in_busy_smux) {
	if (!diag_smux->in_busy) {
		*pkt_priv = (void *)0x1234;
		*buffer = driver->buf_in_smux;
		*buffer = diag_smux->read_buf;
		pr_debug("diag: set in_busy_smux as 1\n");
		driver->in_busy_smux = 1;
		diag_smux->in_busy = 1;
	} else {
		pr_debug("diag: read buffer for SMUX is BUSY\n");
		return -EAGAIN;
@@ -96,16 +98,16 @@ void diag_read_usb_smux_work_fn(struct work_struct *work)
{
	int ret;

	if (driver->diag_smux_enabled) {
		if (driver->lcid && diag_bridge[SMUX].usb_buf_out &&
	if (diag_smux->enabled) {
		if (diag_smux->lcid && diag_bridge[SMUX].usb_buf_out &&
			(diag_bridge[SMUX].read_len > 0) &&
				driver->smux_connected) {
			ret = msm_smux_write(driver->lcid, NULL,
				diag_smux->connected) {
			ret = msm_smux_write(diag_smux->lcid, NULL,
			      diag_bridge[SMUX].usb_buf_out,
				 diag_bridge[SMUX].read_len);
			if (ret)
				pr_err("diag: writing to SMUX ch, r = %d, lcid = %d\n",
						 ret, driver->lcid);
						 ret, diag_smux->lcid);
		}
		diag_bridge[SMUX].usb_read_ptr->buf =
					 diag_bridge[SMUX].usb_buf_out;
@@ -139,12 +141,12 @@ int diagfwd_connect_smux(void)
	void *priv = NULL;
	int ret = 0;

	if (driver->lcid == LCID_INVALID) {
	if (diag_smux->lcid == LCID_INVALID) {
		ret = msm_smux_open(LCID_VALID, priv, diag_smux_event,
						 diag_get_rx_buffer);
		if (!ret) {
			driver->lcid = LCID_VALID;
			msm_smux_tiocm_set(driver->lcid, TIOCM_DTR, 0);
			diag_smux->lcid = LCID_VALID;
			msm_smux_tiocm_set(diag_smux->lcid, TIOCM_DTR, 0);
			pr_info("diag: open SMUX ch, r = %d\n", ret);
		} else {
			pr_err("diag: failed to open SMUX ch, r = %d\n", ret);
@@ -161,11 +163,11 @@ static int diagfwd_smux_probe(struct platform_device *pdev)
	int ret = 0;

	pr_info("diag: SMUX probe called\n");
	driver->lcid = LCID_INVALID;
	driver->diag_smux_enabled = 1;
	if (driver->buf_in_smux == NULL) {
		driver->buf_in_smux = kzalloc(IN_BUF_SIZE, GFP_KERNEL);
		if (driver->buf_in_smux == NULL)
	diag_smux->lcid = LCID_INVALID;
	diag_smux->enabled = 1;
	if (diag_smux->read_buf == NULL) {
		diag_smux->read_buf = kzalloc(IN_BUF_SIZE, GFP_KERNEL);
		if (diag_smux->read_buf == NULL)
			goto err;
	}
	/* Only required for Local loopback test
@@ -179,18 +181,18 @@ static int diagfwd_smux_probe(struct platform_device *pdev)

err:
	pr_err("diag: Could not initialize SMUX buffer\n");
	kfree(driver->buf_in_smux);
	kfree(diag_smux->read_buf);
	return ret;
}

static int diagfwd_smux_remove(struct platform_device *pdev)
{
	driver->lcid = LCID_INVALID;
	driver->smux_connected = 0;
	driver->diag_smux_enabled = 0;
	driver->in_busy_smux = 1;
	kfree(driver->buf_in_smux);
	driver->buf_in_smux = NULL;
	diag_smux->lcid = LCID_INVALID;
	diag_smux->connected = 0;
	diag_smux->enabled = 0;
	diag_smux->in_busy = 1;
	kfree(diag_smux->read_buf);
	diag_smux->read_buf = NULL;
	return 0;
}

Loading