Commit d8fefda8 authored by Michael Tretter's avatar Michael Tretter Committed by Mauro Carvalho Chehab

media: allegro: drop length field from message header

The length of the message will be determined when the message is
encoded.  Writing the size of the struct into the message in the driver
won't be the actual length of the message that is send to the firmware.
Therefore, drop the length field from the message.

Since the header is the same for all response messages, it does not make
sense to read the header in each decoding function, but we can simply
decode it once before dispatching to the respective functions.
Signed-off-by: default avatarMichael Tretter <m.tretter@pengutronix.de>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent c7ce107f
...@@ -776,7 +776,6 @@ static void allegro_mcu_send_init(struct allegro_dev *dev, ...@@ -776,7 +776,6 @@ static void allegro_mcu_send_init(struct allegro_dev *dev,
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
msg.header.type = MCU_MSG_TYPE_INIT; msg.header.type = MCU_MSG_TYPE_INIT;
msg.header.length = sizeof(msg) - sizeof(msg.header);
msg.suballoc_dma = to_mcu_addr(dev, suballoc_dma); msg.suballoc_dma = to_mcu_addr(dev, suballoc_dma);
msg.suballoc_size = to_mcu_size(dev, suballoc_size); msg.suballoc_size = to_mcu_size(dev, suballoc_size);
...@@ -995,7 +994,6 @@ static int allegro_mcu_send_create_channel(struct allegro_dev *dev, ...@@ -995,7 +994,6 @@ static int allegro_mcu_send_create_channel(struct allegro_dev *dev,
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
msg.header.type = MCU_MSG_TYPE_CREATE_CHANNEL; msg.header.type = MCU_MSG_TYPE_CREATE_CHANNEL;
msg.header.length = sizeof(msg) - sizeof(msg.header);
msg.user_id = channel->user_id; msg.user_id = channel->user_id;
...@@ -1016,7 +1014,6 @@ static int allegro_mcu_send_destroy_channel(struct allegro_dev *dev, ...@@ -1016,7 +1014,6 @@ static int allegro_mcu_send_destroy_channel(struct allegro_dev *dev,
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
msg.header.type = MCU_MSG_TYPE_DESTROY_CHANNEL; msg.header.type = MCU_MSG_TYPE_DESTROY_CHANNEL;
msg.header.length = sizeof(msg) - sizeof(msg.header);
msg.channel_id = channel->mcu_channel_id; msg.channel_id = channel->mcu_channel_id;
...@@ -1036,7 +1033,6 @@ static int allegro_mcu_send_put_stream_buffer(struct allegro_dev *dev, ...@@ -1036,7 +1033,6 @@ static int allegro_mcu_send_put_stream_buffer(struct allegro_dev *dev,
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
msg.header.type = MCU_MSG_TYPE_PUT_STREAM_BUFFER; msg.header.type = MCU_MSG_TYPE_PUT_STREAM_BUFFER;
msg.header.length = sizeof(msg) - sizeof(msg.header);
msg.channel_id = channel->mcu_channel_id; msg.channel_id = channel->mcu_channel_id;
msg.dma_addr = to_codec_addr(dev, paddr); msg.dma_addr = to_codec_addr(dev, paddr);
...@@ -1061,7 +1057,6 @@ static int allegro_mcu_send_encode_frame(struct allegro_dev *dev, ...@@ -1061,7 +1057,6 @@ static int allegro_mcu_send_encode_frame(struct allegro_dev *dev,
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
msg.header.type = MCU_MSG_TYPE_ENCODE_FRAME; msg.header.type = MCU_MSG_TYPE_ENCODE_FRAME;
msg.header.length = sizeof(msg) - sizeof(msg.header);
msg.channel_id = channel->mcu_channel_id; msg.channel_id = channel->mcu_channel_id;
msg.encoding_options = AL_OPT_FORCE_LOAD; msg.encoding_options = AL_OPT_FORCE_LOAD;
...@@ -1125,7 +1120,6 @@ static int allegro_mcu_push_buffer_internal(struct allegro_channel *channel, ...@@ -1125,7 +1120,6 @@ static int allegro_mcu_push_buffer_internal(struct allegro_channel *channel,
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
msg->header.length = size - sizeof(msg->header);
msg->header.type = type; msg->header.type = type;
msg->channel_id = channel->mcu_channel_id; msg->channel_id = channel->mcu_channel_id;
msg->num_buffers = num_buffers; msg->num_buffers = num_buffers;
......
...@@ -257,8 +257,6 @@ allegro_dec_init(struct mcu_msg_init_response *msg, u32 *src) ...@@ -257,8 +257,6 @@ allegro_dec_init(struct mcu_msg_init_response *msg, u32 *src)
{ {
unsigned int i = 0; unsigned int i = 0;
msg->header.type = FIELD_GET(GENMASK(31, 16), src[i]);
msg->header.length = FIELD_GET(GENMASK(15, 0), src[i++]);
msg->reserved0 = src[i++]; msg->reserved0 = src[i++];
return i * sizeof(*src); return i * sizeof(*src);
...@@ -270,8 +268,6 @@ allegro_dec_create_channel(struct mcu_msg_create_channel_response *msg, ...@@ -270,8 +268,6 @@ allegro_dec_create_channel(struct mcu_msg_create_channel_response *msg,
{ {
unsigned int i = 0; unsigned int i = 0;
msg->header.type = FIELD_GET(GENMASK(31, 16), src[i]);
msg->header.length = FIELD_GET(GENMASK(15, 0), src[i++]);
msg->channel_id = src[i++]; msg->channel_id = src[i++];
msg->user_id = src[i++]; msg->user_id = src[i++];
msg->options = src[i++]; msg->options = src[i++];
...@@ -294,8 +290,6 @@ allegro_dec_destroy_channel(struct mcu_msg_destroy_channel_response *msg, ...@@ -294,8 +290,6 @@ allegro_dec_destroy_channel(struct mcu_msg_destroy_channel_response *msg,
{ {
unsigned int i = 0; unsigned int i = 0;
msg->header.type = FIELD_GET(GENMASK(31, 16), src[i]);
msg->header.length = FIELD_GET(GENMASK(15, 0), src[i++]);
msg->channel_id = src[i++]; msg->channel_id = src[i++];
return i * sizeof(*src); return i * sizeof(*src);
...@@ -307,8 +301,6 @@ allegro_dec_encode_frame(struct mcu_msg_encode_frame_response *msg, u32 *src) ...@@ -307,8 +301,6 @@ allegro_dec_encode_frame(struct mcu_msg_encode_frame_response *msg, u32 *src)
unsigned int i = 0; unsigned int i = 0;
unsigned int j; unsigned int j;
msg->header.type = FIELD_GET(GENMASK(31, 16), src[i]);
msg->header.length = FIELD_GET(GENMASK(15, 0), src[i++]);
msg->channel_id = src[i++]; msg->channel_id = src[i++];
msg->stream_id = src[i++]; msg->stream_id = src[i++];
...@@ -418,7 +410,10 @@ int allegro_decode_mail(void *msg, u32 *src) ...@@ -418,7 +410,10 @@ int allegro_decode_mail(void *msg, u32 *src)
if (!src || !msg) if (!src || !msg)
return -EINVAL; return -EINVAL;
header = (struct mcu_msg_header *)src; header = msg;
header->type = FIELD_GET(GENMASK(31, 16), src[0]);
src++;
switch (header->type) { switch (header->type) {
case MCU_MSG_TYPE_INIT: case MCU_MSG_TYPE_INIT:
allegro_dec_init(msg, src); allegro_dec_init(msg, src);
......
...@@ -23,8 +23,7 @@ enum mcu_msg_type { ...@@ -23,8 +23,7 @@ enum mcu_msg_type {
const char *msg_type_name(enum mcu_msg_type type); const char *msg_type_name(enum mcu_msg_type type);
struct mcu_msg_header { struct mcu_msg_header {
u16 length; /* length of the body in bytes */ enum mcu_msg_type type;
u16 type;
}; };
struct mcu_msg_init_request { struct mcu_msg_init_request {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment