512 bytes isn't always suitable for all case, let firmware
maker decide the best value from resource table.
enable by VIRTIO_RPMSG_F_BUFSZ feature bit.
Signed-off-by: Tanmay Shah <[email protected]>
---
Test done:
- Verify this patch works with the existing firmware
- Verify this patch works with the firmware that configures
differt tx & rx buf size
Changes in v2:
- %s/sbuf_size/tx_buf_size/
- %s/rbuf_size/rx_buf_size/
- fix typo
- do not use ALIGN on buf size, rely on allocator
- make err msg more explicit, %s/vdev config:/bad vdev config/
- fix license and add AMD copyrights in the header virtio_rpmsg.h
- Assign bit 1 to VIRTIO_RPMSG_F_BUFSZ feature
- use __virtio32 over __u32
- add version field to virtio rpmsg config structure
- move linux/virtio_rpmsg.h to linux/rpmsg/virtio_rpmsg.h
drivers/rpmsg/virtio_rpmsg_bus.c | 70 ++++++++++++++++++++++--------
include/linux/rpmsg/virtio_rpmsg.h | 27 ++++++++++++
2 files changed, 79 insertions(+), 18 deletions(-)
create mode 100644 include/linux/rpmsg/virtio_rpmsg.h
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/
virtio_rpmsg_bus.c
index e59d8cf9b975..8116d94413cc 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -20,6 +20,7 @@
#include <linux/rpmsg.h>
#include <linux/rpmsg/byteorder.h>
#include <linux/rpmsg/ns.h>
+#include <linux/rpmsg/virtio_rpmsg.h>
#include <linux/scatterlist.h>
#include <linux/slab.h>
#include <linux/sched.h>
@@ -39,7 +40,8 @@
* @tx_bufs: kernel address of tx buffers
* @num_rx_buf: total number of buffers for rx
* @num_tx_buf: total number of buffers for tx
- * @buf_size: size of one rx or tx buffer
+ * @rx_buf_size: size of one rx buffer
+ * @tx_buf_size: size of one tx buffer
* @last_sbuf: index of last tx buffer used
* @bufs_dma: dma base addr of the buffers
* @tx_lock: protects svq and tx_bufs, to allow concurrent senders.
@@ -59,7 +61,8 @@ struct virtproc_info {
void *rx_bufs, *tx_bufs;
unsigned int num_rx_buf;
unsigned int num_tx_buf;
- unsigned int buf_size;
+ unsigned int rx_buf_size;
+ unsigned int tx_buf_size;
int last_sbuf;
dma_addr_t bufs_dma;
struct mutex tx_lock;
@@ -68,9 +71,6 @@ struct virtproc_info {
wait_queue_head_t sendq;
};
-/* The feature bitmap for virtio rpmsg */
-#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service
notifications */
-
/**
* struct rpmsg_hdr - common header for all rpmsg messages
* @src: source address
@@ -128,7 +128,7 @@ struct virtio_rpmsg_channel {
* processor.
*/
#define MAX_RPMSG_NUM_BUFS (256)
-#define MAX_RPMSG_BUF_SIZE (512)
+#define DEFAULT_RPMSG_BUF_SIZE (512)
/*
* Local addresses are dynamically allocated on-demand.
@@ -444,7 +444,7 @@ static void *get_a_tx_buf(struct virtproc_info *vrp)
/* either pick the next unused tx buffer */
if (vrp->last_sbuf < vrp->num_tx_buf)
- ret = vrp->tx_bufs + vrp->buf_size * vrp->last_sbuf++;
+ ret = vrp->tx_bufs + vrp->tx_buf_size * vrp->last_sbuf++;
/* or recycle a used one */
else
ret = virtqueue_get_buf(vrp->svq, &len);
@@ -514,7 +514,7 @@ static int rpmsg_send_offchannel_raw(struct
rpmsg_device *rpdev,
* messaging), or to improve the buffer allocator, to support
* variable-length buffer sizes.
*/
- if (len > vrp->buf_size - sizeof(struct rpmsg_hdr)) {
+ if (len > vrp->tx_buf_size - sizeof(struct rpmsg_hdr)) {
dev_err(dev, "message is too big (%d)\n", len);
return -EMSGSIZE;
}
@@ -647,7 +647,7 @@ static ssize_t virtio_rpmsg_get_mtu(struct
rpmsg_endpoint *ept)
struct rpmsg_device *rpdev = ept->rpdev;
struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev);
- return vch->vrp->buf_size - sizeof(struct rpmsg_hdr);
+ return vch->vrp->tx_buf_size - sizeof(struct rpmsg_hdr);
}
static int rpmsg_recv_single(struct virtproc_info *vrp, struct
device *dev,
@@ -673,7 +673,7 @@ static int rpmsg_recv_single(struct virtproc_info
*vrp, struct device *dev,
* We currently use fixed-sized buffers, so trivially sanitize
* the reported payload length.
*/
- if (len > vrp->buf_size ||
+ if (len > vrp->rx_buf_size ||
msg_len > (len - sizeof(struct rpmsg_hdr))) {
dev_warn(dev, "inbound msg too big: (%d, %d)\n", len,
msg_len);
return -EINVAL;
@@ -706,7 +706,7 @@ static int rpmsg_recv_single(struct virtproc_info
*vrp, struct device *dev,
dev_warn_ratelimited(dev, "msg received with no recipient\n");
/* publish the real size of the buffer */
- rpmsg_sg_init(&sg, msg, vrp->buf_size);
+ rpmsg_sg_init(&sg, msg, vrp->rx_buf_size);
/* add the buffer back to the remote processor's virtqueue */
err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
@@ -824,6 +824,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
int err = 0, i;
size_t total_buf_space;
bool notify;
+ u16 version;
vrp = kzalloc_obj(*vrp);
if (!vrp)
@@ -855,9 +856,41 @@ static int rpmsg_probe(struct virtio_device *vdev)
else
vrp->num_tx_buf = MAX_RPMSG_NUM_BUFS;
- vrp->buf_size = MAX_RPMSG_BUF_SIZE;
+ /*
+ * If VIRTIO_RPMSG_F_BUFSZ feature is supported, then configure buf
+ * size from virtio device config space from the resource table.
+ * If the feature is not supported, then assign default buf size.
+ */
+ if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_BUFSZ)) {
+ /* note: virtio_rpmsg_config is defined from remote view */
+ version = 0;
+ virtio_cread(vdev, struct virtio_rpmsg_config,
+ version, &version);
+ virtio_cread(vdev, struct virtio_rpmsg_config,
+ txbuf_size, &vrp->rx_buf_size);
+ virtio_cread(vdev, struct virtio_rpmsg_config,
+ rxbuf_size, &vrp->tx_buf_size);
+