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

Commit 93c42b2c authored by Tarun Gupta's avatar Tarun Gupta Committed by Gerrit - the friendly Code Review server
Browse files

USB: QTI: Add counters for no. of packets sent over qti control xport



Add counters to track the number of packets sent to host, to modem from
qti control driver and also number of packets dropped by modem. Add a new
debugfs entry. The stats can be read from
    /d/usb_qti/status.

Change-Id: I8938d2e44eea0fc9eb8a090acee9ee3b0e10f27a
Signed-off-by: default avatarAzhar Shaikh <azhars@codeaurora.org>
Signed-off-by: default avatarTarun Gupta <tarung@codeaurora.org>
parent 564e6be5
Loading
Loading
Loading
Loading
+104 −0
Original line number Original line Diff line number Diff line
@@ -55,6 +55,11 @@ struct qti_ctrl_port {


	spinlock_t	lock;
	spinlock_t	lock;
	enum gadget_type	gtype;
	enum gadget_type	gtype;
	unsigned	host_to_modem;
	unsigned	copied_to_modem;
	unsigned	copied_from_modem;
	unsigned	modem_to_host;
	unsigned	drp_cpkt_cnt;
};
};
static struct qti_ctrl_port *ctrl_port[NR_QTI_PORTS];
static struct qti_ctrl_port *ctrl_port[NR_QTI_PORTS];


@@ -138,12 +143,14 @@ static int gqti_ctrl_send_cpkt_tomodem(u8 portno, void *buf, size_t len)
	if (!port->is_open) {
	if (!port->is_open) {
		pr_debug("rmnet file handler %p(index=%d) is not open",
		pr_debug("rmnet file handler %p(index=%d) is not open",
		       port, port->index);
		       port, port->index);
		port->drp_cpkt_cnt++;
		spin_unlock_irqrestore(&port->lock, flags);
		spin_unlock_irqrestore(&port->lock, flags);
		free_rmnet_ctrl_pkt(cpkt);
		free_rmnet_ctrl_pkt(cpkt);
		return 0;
		return 0;
	}
	}


	list_add_tail(&cpkt->list, &port->cpkt_req_q);
	list_add_tail(&cpkt->list, &port->cpkt_req_q);
	port->host_to_modem++;
	spin_unlock_irqrestore(&port->lock, flags);
	spin_unlock_irqrestore(&port->lock, flags);


	/* wakeup read thread */
	/* wakeup read thread */
@@ -231,6 +238,12 @@ int gqti_ctrl_connect(void *gr, u8 port_num, unsigned intf,
		return -ENODEV;
		return -ENODEV;
	}
	}


	port->host_to_modem = 0;
	port->copied_to_modem = 0;
	port->copied_from_modem = 0;
	port->modem_to_host = 0;
	port->drp_cpkt_cnt = 0;

	spin_unlock_irqrestore(&port->lock, flags);
	spin_unlock_irqrestore(&port->lock, flags);


	atomic_set(&port->connected, 1);
	atomic_set(&port->connected, 1);
@@ -422,6 +435,7 @@ qti_ctrl_read(struct file *fp, char __user *buf, size_t count, loff_t *pos)
	} else {
	} else {
		pr_debug("%s: copied %d bytes to user\n", __func__, cpkt->len);
		pr_debug("%s: copied %d bytes to user\n", __func__, cpkt->len);
		ret = cpkt->len;
		ret = cpkt->len;
		port->copied_to_modem++;
	}
	}


	free_rmnet_ctrl_pkt(cpkt);
	free_rmnet_ctrl_pkt(cpkt);
@@ -478,6 +492,7 @@ qti_ctrl_write(struct file *fp, const char __user *buf, size_t count,
		qti_ctrl_unlock(&port->write_excl);
		qti_ctrl_unlock(&port->write_excl);
		return -EFAULT;
		return -EFAULT;
	}
	}
	port->copied_from_modem++;


	spin_lock_irqsave(&port->lock, flags);
	spin_lock_irqsave(&port->lock, flags);
	if (port && port->port_usb) {
	if (port && port->port_usb) {
@@ -495,6 +510,7 @@ qti_ctrl_write(struct file *fp, const char __user *buf, size_t count,
							kbuf, count);
							kbuf, count);
			if (ret)
			if (ret)
				pr_err("%d failed to send ctrl packet.\n", ret);
				pr_err("%d failed to send ctrl packet.\n", ret);
			port->modem_to_host++;
		} else {
		} else {
			pr_err("send_cpkt_response callback is NULL\n");
			pr_err("send_cpkt_response callback is NULL\n");
			ret = -EINVAL;
			ret = -EINVAL;
@@ -632,6 +648,92 @@ static unsigned int qti_ctrl_poll(struct file *file, poll_table *wait)
	return mask;
	return mask;
}
}


static int qti_ctrl_read_stats(struct seq_file *s, void *unused)
{
	struct qti_ctrl_port	*port = s->private;
	unsigned long		flags;
	int			i;

	for (i = 0; i < NR_QTI_PORTS; i++) {
		port = ctrl_port[i];
		if (!port)
			continue;
		spin_lock_irqsave(&port->lock, flags);

		seq_printf(s, "\n#PORT:%d port: %p\n", i, port);
		seq_printf(s, "name:			%s\n", port->name);
		seq_printf(s, "host_to_modem:		%d\n",
				port->host_to_modem);
		seq_printf(s, "copied_to_modem:	%d\n",
				port->copied_to_modem);
		seq_printf(s, "copied_from_modem:	%d\n",
				port->copied_from_modem);
		seq_printf(s, "modem_to_host:		%d\n",
				port->modem_to_host);
		seq_printf(s, "cpkt_drp_cnt:		%d\n",
				port->drp_cpkt_cnt);
		spin_unlock_irqrestore(&port->lock, flags);
	}

	return 0;
}

static int qti_ctrl_stats_open(struct inode *inode, struct file *file)
{
	return single_open(file, qti_ctrl_read_stats, inode->i_private);
}

static ssize_t qti_ctrl_reset_stats(struct file *file,
	const char __user *buf, size_t count, loff_t *ppos)
{
	struct seq_file *s = file->private_data;
	struct qti_ctrl_port *port = s->private;
	int                     i;
	unsigned long           flags;

	for (i = 0; i < NR_QTI_PORTS; i++) {
		port = ctrl_port[i];
		if (!port)
			continue;

		spin_lock_irqsave(&port->lock, flags);
		port->host_to_modem = 0;
		port->copied_to_modem = 0;
		port->copied_from_modem = 0;
		port->modem_to_host = 0;
		port->drp_cpkt_cnt = 0;
		spin_unlock_irqrestore(&port->lock, flags);
	}
	return count;
}

const struct file_operations qti_ctrl_stats_ops = {
	.open = qti_ctrl_stats_open,
	.read = seq_read,
	.write = qti_ctrl_reset_stats,
};

static struct dentry   *qti_ctrl_dent;
static void qti_ctrl_debugfs_init(void)
{
	struct dentry   *qti_ctrl_dfile;

	qti_ctrl_dent = debugfs_create_dir("usb_qti", 0);
	if (IS_ERR(qti_ctrl_dent))
		return;

	qti_ctrl_dfile =
		debugfs_create_file("status", 0444, qti_ctrl_dent, 0,
				&qti_ctrl_stats_ops);
	if (!qti_ctrl_dfile || IS_ERR(qti_ctrl_dfile))
		debugfs_remove(qti_ctrl_dent);
}

static void qti_ctrl_debugfs_exit(void)
{
	debugfs_remove_recursive(qti_ctrl_dent);
}

/* file operations for rmnet device /dev/rmnet_ctrl */
/* file operations for rmnet device /dev/rmnet_ctrl */
static const struct file_operations qti_ctrl_fops = {
static const struct file_operations qti_ctrl_fops = {
	.owner = THIS_MODULE,
	.owner = THIS_MODULE,
@@ -710,6 +812,7 @@ static int __init gqti_ctrl_init(void)
			goto fail_init;
			goto fail_init;
		}
		}
	}
	}
	qti_ctrl_debugfs_init();


	return ret;
	return ret;


@@ -732,5 +835,6 @@ static void __exit gqti_ctrl_cleanup(void)
		kfree(ctrl_port[i]);
		kfree(ctrl_port[i]);
		ctrl_port[i] = NULL;
		ctrl_port[i] = NULL;
	}
	}
	qti_ctrl_debugfs_exit();
}
}
module_exit(gqti_ctrl_cleanup);
module_exit(gqti_ctrl_cleanup);