From a138c883193a66c3aaee554c8f976f62469c66a7 Mon Sep 17 00:00:00 2001 From: "Anna, Suman" Date: Fri, 12 Aug 2016 18:42:28 -0500 Subject: samples/rpmsg: add support for multiple instances The current rpmsg_client_sample is a very simple example and is not designed to handle multiple instances. Add support for multiple instances, so that the same number of pings are sent to each instance. The instances can be on one or multiple remote processors. Signed-off-by: Suman Anna Signed-off-by: Bjorn Andersson --- samples/rpmsg/rpmsg_client_sample.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'samples') diff --git a/samples/rpmsg/rpmsg_client_sample.c b/samples/rpmsg/rpmsg_client_sample.c index d0e249c9..7e17d1c 100644 --- a/samples/rpmsg/rpmsg_client_sample.c +++ b/samples/rpmsg/rpmsg_client_sample.c @@ -24,19 +24,24 @@ #define MSG "hello world!" #define MSG_LIMIT 100 +struct instance_data { + int rx_count; +}; + static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len, void *priv, u32 src) { int ret; - static int rx_count; + struct instance_data *idata = dev_get_drvdata(&rpdev->dev); - dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", ++rx_count, src); + dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", + ++idata->rx_count, src); print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1, data, len, true); /* samples should not live forever */ - if (rx_count >= MSG_LIMIT) { + if (idata->rx_count >= MSG_LIMIT) { dev_info(&rpdev->dev, "goodbye!\n"); return; } @@ -50,10 +55,17 @@ static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len, static int rpmsg_sample_probe(struct rpmsg_channel *rpdev) { int ret; + struct instance_data *idata; dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n", rpdev->src, rpdev->dst); + idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL); + if (!idata) + return -ENOMEM; + + dev_set_drvdata(&rpdev->dev, idata); + /* send a message to our remote processor */ ret = rpmsg_send(rpdev, MSG, strlen(MSG)); if (ret) { -- cgit v1.1 From 2a48d7322dc88f1bc6c8bd9e087fc6341ba659fd Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Thu, 1 Sep 2016 15:27:55 -0700 Subject: rpmsg: rpmsg_send() operations takes rpmsg_endpoint The rpmsg_send() operations has been taking a rpmsg_device, but this forces users of secondary rpmsg_endpoints to use the rpmsg_sendto() interface - by extracting source and destination from the given data structures. If we instead pass the rpmsg_endpoint to these functions a service can use rpmsg_sendto() to respond to messages, even on secondary endpoints. In addition this would allow us to support operations on multiple channels in future backends that does not support off-channel operations. Signed-off-by: Bjorn Andersson --- samples/rpmsg/rpmsg_client_sample.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'samples') diff --git a/samples/rpmsg/rpmsg_client_sample.c b/samples/rpmsg/rpmsg_client_sample.c index 7e17d1c..37975ed 100644 --- a/samples/rpmsg/rpmsg_client_sample.c +++ b/samples/rpmsg/rpmsg_client_sample.c @@ -47,7 +47,7 @@ static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len, } /* send a new message now */ - ret = rpmsg_send(rpdev, MSG, strlen(MSG)); + ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG)); if (ret) dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); } @@ -67,7 +67,7 @@ static int rpmsg_sample_probe(struct rpmsg_channel *rpdev) dev_set_drvdata(&rpdev->dev, idata); /* send a message to our remote processor */ - ret = rpmsg_send(rpdev, MSG, strlen(MSG)); + ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG)); if (ret) { dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); return ret; -- cgit v1.1 From 92e1de51bf2cb8d49adc8925abe56ce84911a232 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Thu, 1 Sep 2016 15:27:57 -0700 Subject: rpmsg: Clean up rpmsg device vs channel naming The rpmsg device representing struct is called rpmsg_channel and the variable name used throughout is rpdev, with the communication happening on endpoints it's clearer to just call this a "device" in a public API. Signed-off-by: Bjorn Andersson --- samples/rpmsg/rpmsg_client_sample.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'samples') diff --git a/samples/rpmsg/rpmsg_client_sample.c b/samples/rpmsg/rpmsg_client_sample.c index 37975ed..4fcd7ee 100644 --- a/samples/rpmsg/rpmsg_client_sample.c +++ b/samples/rpmsg/rpmsg_client_sample.c @@ -28,7 +28,7 @@ struct instance_data { int rx_count; }; -static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len, +static void rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src) { int ret; @@ -52,7 +52,7 @@ static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len, dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); } -static int rpmsg_sample_probe(struct rpmsg_channel *rpdev) +static int rpmsg_sample_probe(struct rpmsg_device *rpdev) { int ret; struct instance_data *idata; @@ -76,7 +76,7 @@ static int rpmsg_sample_probe(struct rpmsg_channel *rpdev) return 0; } -static void rpmsg_sample_remove(struct rpmsg_channel *rpdev) +static void rpmsg_sample_remove(struct rpmsg_device *rpdev) { dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n"); } -- cgit v1.1 From 4b83c52a21cf5a7421b7c28bebf8ff28ba96ceb9 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Thu, 1 Sep 2016 15:28:08 -0700 Subject: rpmsg: Allow callback to return errors Some rpmsg backends support holding on to and redelivering messages upon failed handling of them, so provide a way for the callback to report and error and allow the backends to handle this. Signed-off-by: Bjorn Andersson --- samples/rpmsg/rpmsg_client_sample.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'samples') diff --git a/samples/rpmsg/rpmsg_client_sample.c b/samples/rpmsg/rpmsg_client_sample.c index 4fcd7ee..f161dfd 100644 --- a/samples/rpmsg/rpmsg_client_sample.c +++ b/samples/rpmsg/rpmsg_client_sample.c @@ -28,7 +28,7 @@ struct instance_data { int rx_count; }; -static void rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len, +static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src) { int ret; @@ -43,13 +43,15 @@ static void rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len, /* samples should not live forever */ if (idata->rx_count >= MSG_LIMIT) { dev_info(&rpdev->dev, "goodbye!\n"); - return; + return 0; } /* send a new message now */ ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG)); if (ret) dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); + + return 0; } static int rpmsg_sample_probe(struct rpmsg_device *rpdev) -- cgit v1.1