Merge tag 'rpmsg-v4.16' of git://github.com/andersson/remoteproc
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 5 Feb 2018 18:05:40 +0000 (10:05 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 5 Feb 2018 18:05:40 +0000 (10:05 -0800)
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

drivers/remoteproc/qcom_common.c
drivers/rpmsg/qcom_glink_native.c
drivers/rpmsg/qcom_glink_smem.c
drivers/rpmsg/qcom_smd.c

index d487040b528ba0509e58b4fc694e9da5991a23f7..e9b5f2a98c4dbfea4772085099de3e17c5b6d64e 100644 (file)
@@ -57,7 +57,7 @@ static int glink_subdev_probe(struct rproc_subdev *subdev)
 
        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)
index 40d76d2a5efff58339c0b823be3678591c99482e..e0f31ed096a50223bfa04b960fb0bbdd45e72434 100644 (file)
@@ -221,6 +221,7 @@ static struct glink_channel *qcom_glink_alloc_channel(struct qcom_glink *glink,
        /* Setup glink internal glink_channel data */
        spin_lock_init(&channel->recv_lock);
        spin_lock_init(&channel->intent_lock);
+       mutex_init(&channel->intent_req_lock);
 
        channel->glink = glink;
        channel->name = kstrdup(name, GFP_KERNEL);
index 5cdaa5f8fb61e53392fc1c6ef9f109fffe622131..892f2b92a4d854d5122887f21591184e18973b0f 100644 (file)
@@ -29,8 +29,6 @@
 #include <linux/workqueue.h>
 #include <linux/list.h>
 
-#include <linux/delay.h>
-#include <linux/rpmsg.h>
 #include <linux/rpmsg/qcom_glink.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)
                head -= pipe->native.length;
 
+       /* Ensure ordering of fifo and head update */
+       wmb();
+
        *pipe->head = cpu_to_le32(head);
 }
 
index e540ca362d086aa15a642d9875ee7533a3df7319..8428eba8cb73629b9aa608f7c2300b732218c643 100644 (file)
@@ -200,6 +200,7 @@ struct qcom_smd_channel {
        char *name;
        enum smd_channel_state state;
        enum smd_channel_state remote_state;
+       wait_queue_head_t state_change_event;
 
        struct smd_channel_info_pair *info;
        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) {
                channel->remote_state = remote_state;
                need_state_scan = true;
+
+               wake_up_interruptible_all(&channel->state_change_event);
        }
        /* Indicate that we have seen any state change */
        SET_RX_CHANNEL_FLAG(channel, fSTATE, 0);
 
        /* Signal waiting qcom_smd_send() about the interrupt */
        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 */
        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)
                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) {
                        ret = -EAGAIN;
-                       goto out;
-               }
-
-               if (channel->state != SMD_CHANNEL_OPENED) {
-                       ret = -EPIPE;
-                       goto out;
+                       goto out_unlock;
                }
 
                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,
                                       qcom_smd_get_tx_avail(channel) >= tlen ||
                                       channel->state != SMD_CHANNEL_OPENED);
                if (ret)
-                       goto out;
+                       return ret;
+
+               ret = mutex_lock_interruptible(&channel->tx_lock);
+               if (ret)
+                       return ret;
 
                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);
 
        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);
 
-out:
+out_unlock:
        mutex_unlock(&channel->tx_lock);
 
        return ret;
@@ -786,7 +798,9 @@ out:
 static int qcom_smd_channel_open(struct qcom_smd_channel *channel,
                                 rpmsg_rx_cb_t cb)
 {
+       struct qcom_smd_edge *edge = channel->edge;
        size_t bb_size;
+       int ret;
 
        /*
         * 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_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);
 
+       /* 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;
+
+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);
        spin_lock_init(&channel->recv_lock);
        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);
        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);
                        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)
                        continue;
 
-               remote_state = GET_RX_CHANNEL_INFO(channel, state);
-               if (remote_state != SMD_CHANNEL_OPENING &&
-                   remote_state != SMD_CHANNEL_OPENED)
-                       continue;
-
                if (channel->registered)
                        continue;