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

Commit 67fb3b92 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'rpmsg-v4.16' of git://github.com/andersson/remoteproc

Pull rpmsg updates from Bjorn Andersson:
 "This fixes a few issues found in the SMD and GLINK drivers and
  corrects the handling of SMD channels that are found in an
  (previously) unexpected state"

* tag 'rpmsg-v4.16' of git://github.com/andersson/remoteproc:
  rpmsg: smd: Fix double unlock in __qcom_smd_send()
  rpmsg: glink: Fix missing mutex_init() in qcom_glink_alloc_channel()
  rpmsg: smd: Don't hold the tx lock during wait
  rpmsg: smd: Fail send on a closed channel
  rpmsg: smd: Wake up all waiters
  rpmsg: smd: Create device for all channels
  rpmsg: smd: Perform handshake during open
  rpmsg: glink: smem: Ensure ordering during tx
  drivers: rpmsg: remove duplicate includes
  remoteproc: qcom: Use PTR_ERR_OR_ZERO() in glink prob
parents ae77c958 c3388a07
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -57,7 +57,7 @@ static int glink_subdev_probe(struct rproc_subdev *subdev)


	glink->edge = qcom_glink_smem_register(glink->dev, glink->node);
	glink->edge = qcom_glink_smem_register(glink->dev, glink->node);


	return IS_ERR(glink->edge) ? PTR_ERR(glink->edge) : 0;
	return PTR_ERR_OR_ZERO(glink->edge);
}
}


static void glink_subdev_remove(struct rproc_subdev *subdev)
static void glink_subdev_remove(struct rproc_subdev *subdev)
+1 −0
Original line number Original line Diff line number Diff line
@@ -221,6 +221,7 @@ static struct glink_channel *qcom_glink_alloc_channel(struct qcom_glink *glink,
	/* Setup glink internal glink_channel data */
	/* Setup glink internal glink_channel data */
	spin_lock_init(&channel->recv_lock);
	spin_lock_init(&channel->recv_lock);
	spin_lock_init(&channel->intent_lock);
	spin_lock_init(&channel->intent_lock);
	mutex_init(&channel->intent_req_lock);


	channel->glink = glink;
	channel->glink = glink;
	channel->name = kstrdup(name, GFP_KERNEL);
	channel->name = kstrdup(name, GFP_KERNEL);
+3 −2
Original line number Original line Diff line number Diff line
@@ -29,8 +29,6 @@
#include <linux/workqueue.h>
#include <linux/workqueue.h>
#include <linux/list.h>
#include <linux/list.h>


#include <linux/delay.h>
#include <linux/rpmsg.h>
#include <linux/rpmsg/qcom_glink.h>
#include <linux/rpmsg/qcom_glink.h>


#include "qcom_glink_native.h"
#include "qcom_glink_native.h"
@@ -185,6 +183,9 @@ static void glink_smem_tx_write(struct qcom_glink_pipe *glink_pipe,
	if (head >= pipe->native.length)
	if (head >= pipe->native.length)
		head -= pipe->native.length;
		head -= pipe->native.length;


	/* Ensure ordering of fifo and head update */
	wmb();

	*pipe->head = cpu_to_le32(head);
	*pipe->head = cpu_to_le32(head);
}
}


+50 −16
Original line number Original line Diff line number Diff line
@@ -200,6 +200,7 @@ struct qcom_smd_channel {
	char *name;
	char *name;
	enum smd_channel_state state;
	enum smd_channel_state state;
	enum smd_channel_state remote_state;
	enum smd_channel_state remote_state;
	wait_queue_head_t state_change_event;


	struct smd_channel_info_pair *info;
	struct smd_channel_info_pair *info;
	struct smd_channel_info_word_pair *info_word;
	struct smd_channel_info_word_pair *info_word;
@@ -570,13 +571,15 @@ static bool qcom_smd_channel_intr(struct qcom_smd_channel *channel)
	if (remote_state != channel->remote_state) {
	if (remote_state != channel->remote_state) {
		channel->remote_state = remote_state;
		channel->remote_state = remote_state;
		need_state_scan = true;
		need_state_scan = true;

		wake_up_interruptible_all(&channel->state_change_event);
	}
	}
	/* Indicate that we have seen any state change */
	/* Indicate that we have seen any state change */
	SET_RX_CHANNEL_FLAG(channel, fSTATE, 0);
	SET_RX_CHANNEL_FLAG(channel, fSTATE, 0);


	/* Signal waiting qcom_smd_send() about the interrupt */
	/* Signal waiting qcom_smd_send() about the interrupt */
	if (!GET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR))
	if (!GET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR))
		wake_up_interruptible(&channel->fblockread_event);
		wake_up_interruptible_all(&channel->fblockread_event);


	/* Don't consume any data until we've opened the channel */
	/* Don't consume any data until we've opened the channel */
	if (channel->state != SMD_CHANNEL_OPENED)
	if (channel->state != SMD_CHANNEL_OPENED)
@@ -740,28 +743,37 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
	if (ret)
	if (ret)
		return ret;
		return ret;


	while (qcom_smd_get_tx_avail(channel) < tlen) {
	while (qcom_smd_get_tx_avail(channel) < tlen &&
	       channel->state == SMD_CHANNEL_OPENED) {
		if (!wait) {
		if (!wait) {
			ret = -EAGAIN;
			ret = -EAGAIN;
			goto out;
			goto out_unlock;
		}

		if (channel->state != SMD_CHANNEL_OPENED) {
			ret = -EPIPE;
			goto out;
		}
		}


		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 0);
		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 0);


		/* Wait without holding the tx_lock */
		mutex_unlock(&channel->tx_lock);

		ret = wait_event_interruptible(channel->fblockread_event,
		ret = wait_event_interruptible(channel->fblockread_event,
				       qcom_smd_get_tx_avail(channel) >= tlen ||
				       qcom_smd_get_tx_avail(channel) >= tlen ||
				       channel->state != SMD_CHANNEL_OPENED);
				       channel->state != SMD_CHANNEL_OPENED);
		if (ret)
		if (ret)
			goto out;
			return ret;

		ret = mutex_lock_interruptible(&channel->tx_lock);
		if (ret)
			return ret;


		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 1);
		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 1);
	}
	}


	/* Fail if the channel was closed */
	if (channel->state != SMD_CHANNEL_OPENED) {
		ret = -EPIPE;
		goto out_unlock;
	}

	SET_TX_CHANNEL_FLAG(channel, fTAIL, 0);
	SET_TX_CHANNEL_FLAG(channel, fTAIL, 0);


	qcom_smd_write_fifo(channel, hdr, sizeof(hdr));
	qcom_smd_write_fifo(channel, hdr, sizeof(hdr));
@@ -774,7 +786,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,


	qcom_smd_signal_channel(channel);
	qcom_smd_signal_channel(channel);


out:
out_unlock:
	mutex_unlock(&channel->tx_lock);
	mutex_unlock(&channel->tx_lock);


	return ret;
	return ret;
@@ -786,7 +798,9 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
static int qcom_smd_channel_open(struct qcom_smd_channel *channel,
static int qcom_smd_channel_open(struct qcom_smd_channel *channel,
				 rpmsg_rx_cb_t cb)
				 rpmsg_rx_cb_t cb)
{
{
	struct qcom_smd_edge *edge = channel->edge;
	size_t bb_size;
	size_t bb_size;
	int ret;


	/*
	/*
	 * Packets are maximum 4k, but reduce if the fifo is smaller
	 * Packets are maximum 4k, but reduce if the fifo is smaller
@@ -798,9 +812,33 @@ static int qcom_smd_channel_open(struct qcom_smd_channel *channel,


	qcom_smd_channel_set_callback(channel, cb);
	qcom_smd_channel_set_callback(channel, cb);
	qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING);
	qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING);

	/* Wait for remote to enter opening or opened */
	ret = wait_event_interruptible_timeout(channel->state_change_event,
			channel->remote_state == SMD_CHANNEL_OPENING ||
			channel->remote_state == SMD_CHANNEL_OPENED,
			HZ);
	if (!ret) {
		dev_err(&edge->dev, "remote side did not enter opening state\n");
		goto out_close_timeout;
	}

	qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED);
	qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED);


	/* Wait for remote to enter opened */
	ret = wait_event_interruptible_timeout(channel->state_change_event,
			channel->remote_state == SMD_CHANNEL_OPENED,
			HZ);
	if (!ret) {
		dev_err(&edge->dev, "remote side did not enter open state\n");
		goto out_close_timeout;
	}

	return 0;
	return 0;

out_close_timeout:
	qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED);
	return -ETIMEDOUT;
}
}


/*
/*
@@ -1055,6 +1093,7 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
	mutex_init(&channel->tx_lock);
	mutex_init(&channel->tx_lock);
	spin_lock_init(&channel->recv_lock);
	spin_lock_init(&channel->recv_lock);
	init_waitqueue_head(&channel->fblockread_event);
	init_waitqueue_head(&channel->fblockread_event);
	init_waitqueue_head(&channel->state_change_event);


	info = qcom_smem_get(edge->remote_pid, smem_info_item, &info_size);
	info = qcom_smem_get(edge->remote_pid, smem_info_item, &info_size);
	if (IS_ERR(info)) {
	if (IS_ERR(info)) {
@@ -1161,7 +1200,7 @@ static void qcom_channel_scan_worker(struct work_struct *work)
			dev_dbg(&edge->dev, "new channel found: '%s'\n", channel->name);
			dev_dbg(&edge->dev, "new channel found: '%s'\n", channel->name);
			set_bit(i, edge->allocated[tbl]);
			set_bit(i, edge->allocated[tbl]);


			wake_up_interruptible(&edge->new_channel_event);
			wake_up_interruptible_all(&edge->new_channel_event);
		}
		}
	}
	}


@@ -1195,11 +1234,6 @@ static void qcom_channel_state_worker(struct work_struct *work)
		if (channel->state != SMD_CHANNEL_CLOSED)
		if (channel->state != SMD_CHANNEL_CLOSED)
			continue;
			continue;


		remote_state = GET_RX_CHANNEL_INFO(channel, state);
		if (remote_state != SMD_CHANNEL_OPENING &&
		    remote_state != SMD_CHANNEL_OPENED)
			continue;

		if (channel->registered)
		if (channel->registered)
			continue;
			continue;