Skip to content

Commit

Permalink
[media] siano: simplify message endianness logic
Browse files Browse the repository at this point in the history
Currently, every time a message is sent or received, the endiannes
need to be fixed on big endian machines. This is currently done
on every call to the send API, and on every msg reception logic.
Instead of doing that, move it to the send/receive functions.
That simplifies the logic and avoids the risk of forgetting to
fix it somewhere.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Mauro Carvalho Chehab committed Mar 21, 2013
1 parent fe802fd commit 80ccb51
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
14 changes: 0 additions & 14 deletions drivers/media/common/siano/smscoreapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "smscoreapi.h"
#include "sms-cards.h"
#include "smsir.h"
#include "smsendian.h"

static int sms_dbg;
module_param_named(debug, sms_dbg, int, 0644);
Expand Down Expand Up @@ -807,8 +806,6 @@ static int smscore_init_ir(struct smscore_device_t *coredev)
msg->msgData[0] = coredev->ir.controller;
msg->msgData[1] = coredev->ir.timeout;

smsendian_handle_tx_message(
(struct SmsMsgHdr_ST2 *)msg);
rc = smscore_sendrequest_and_wait(coredev, msg,
msg->xMsgHeader. msgLength,
&coredev->ir_init_done);
Expand Down Expand Up @@ -853,7 +850,6 @@ int smscore_configure_board(struct smscore_device_t *coredev)
MtuMsg.xMsgHeader.msgLength = sizeof(MtuMsg);
MtuMsg.msgData[0] = board->mtu;

smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&MtuMsg);
coredev->sendrequest_handler(coredev->context, &MtuMsg,
sizeof(MtuMsg));
}
Expand All @@ -867,7 +863,6 @@ int smscore_configure_board(struct smscore_device_t *coredev)
sizeof(CrysMsg));
CrysMsg.msgData[0] = board->crystal;

smsendian_handle_tx_message((struct SmsMsgHdr_S *)&CrysMsg);
coredev->sendrequest_handler(coredev->context, &CrysMsg,
sizeof(CrysMsg));
}
Expand Down Expand Up @@ -989,7 +984,6 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
/* Entry point */
msg->msgData[1] = firmware->Length;
msg->msgData[2] = 0; /* Regular checksum*/
smsendian_handle_tx_message(msg);
rc = smscore_sendrequest_and_wait(coredev, msg,
msg->xMsgHeader.msgLength,
&coredev->data_validity_done);
Expand All @@ -1013,14 +1007,12 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
TriggerMsg->msgData[3] = 0; /* Parameter */
TriggerMsg->msgData[4] = 4; /* Task ID */

smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
rc = smscore_sendrequest_and_wait(coredev, TriggerMsg,
TriggerMsg->xMsgHeader.msgLength,
&coredev->trigger_done);
} else {
SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_EXEC_REQ,
sizeof(struct SmsMsgHdr_ST));
smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
rc = coredev->sendrequest_handler(coredev->context, msg,
msg->xMsgHeader.msgLength);
}
Expand Down Expand Up @@ -1305,7 +1297,6 @@ int smscore_init_device(struct smscore_device_t *coredev, int mode)
sizeof(struct SmsMsgData_ST));
msg->msgData[0] = mode;

smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
rc = smscore_sendrequest_and_wait(coredev, msg,
msg->xMsgHeader. msgLength,
&coredev->init_device_done);
Expand Down Expand Up @@ -1526,8 +1517,6 @@ void smscore_onresponse(struct smscore_device_t *coredev,
rc = client->onresponse_handler(client->context, cb);

if (rc < 0) {
smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);

switch (phdr->msgType) {
case MSG_SMS_ISDBT_TUNE_RES:
break;
Expand Down Expand Up @@ -2008,7 +1997,6 @@ int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
pMsg->msgData[5] = 0;
}

smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
&coredev->gpio_configuration_done);

Expand Down Expand Up @@ -2058,7 +2046,6 @@ int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
pMsg->msgData[1] = NewLevel;

/* Send message to SMS */
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
&coredev->gpio_set_level_done);

Expand Down Expand Up @@ -2107,7 +2094,6 @@ int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum,
pMsg->msgData[1] = 0;

/* Send message to SMS */
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
&coredev->gpio_get_level_done);

Expand Down
8 changes: 0 additions & 8 deletions drivers/media/common/siano/smsdvb.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dvb_frontend.h"

#include "smscoreapi.h"
#include "smsendian.h"
#include "sms-cards.h"

DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
Expand Down Expand Up @@ -324,8 +323,6 @@ static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
/*u32 MsgDataLen = phdr->msgLength - sizeof(struct SmsMsgHdr_ST);*/
bool is_status_update = false;

smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);

switch (phdr->msgType) {
case MSG_SMS_DVBT_BDA_DATA:
dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1),
Expand Down Expand Up @@ -545,7 +542,6 @@ static int smsdvb_start_feed(struct dvb_demux_feed *feed)
PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
PidMsg.msgData[0] = feed->pid;

smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
return smsclient_sendrequest(client->smsclient,
&PidMsg, sizeof(PidMsg));
}
Expand All @@ -566,7 +562,6 @@ static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
PidMsg.msgData[0] = feed->pid;

smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
return smsclient_sendrequest(client->smsclient,
&PidMsg, sizeof(PidMsg));
}
Expand All @@ -577,7 +572,6 @@ static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
{
int rc;

smsendian_handle_tx_message((struct SmsMsgHdr_ST *)buffer);
rc = smsclient_sendrequest(client->smsclient, buffer, size);
if (rc < 0)
return rc;
Expand Down Expand Up @@ -606,8 +600,6 @@ static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
else
Msg.msgType = MSG_SMS_GET_STATISTICS_REQ;

smsendian_handle_tx_message((struct SmsMsgHdr_S *)&Msg);

rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
&client->stats_done);

Expand Down
3 changes: 3 additions & 0 deletions drivers/media/mmc/siano/smssdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#include "smscoreapi.h"
#include "sms-cards.h"
#include "smsendian.h"

/* Registers */

Expand Down Expand Up @@ -97,6 +98,7 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size)

sdio_claim_host(smsdev->func);

smsendian_handle_tx_message((struct SmsMsgData_ST *) buffer);
while (size >= smsdev->func->cur_blksize) {
ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
buffer, smsdev->func->cur_blksize);
Expand Down Expand Up @@ -231,6 +233,7 @@ static void smssdio_interrupt(struct sdio_func *func)
cb->size = hdr->msgLength;
cb->offset = 0;

smsendian_handle_rx_message((struct SmsMsgData_ST *) cb->p);
smscore_onresponse(smsdev->coredev, cb);
}

Expand Down
9 changes: 6 additions & 3 deletions drivers/media/usb/siano/smsusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ static void smsusb_onresponse(struct urb *urb)
smscore_translate_msg(phdr->msgType),
phdr->msgType, phdr->msgLength);

smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);

smscore_onresponse(dev->coredev, surb->cb);
surb->cb = NULL;
} else {
Expand Down Expand Up @@ -207,13 +209,14 @@ static int smsusb_sendrequest(void *context, void *buffer, size_t size)
struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
int dummy;

if (dev->state != SMSUSB_ACTIVE)
return -ENOENT;

sms_debug("sending %s(%d) size: %d",
smscore_translate_msg(phdr->msgType), phdr->msgType,
phdr->msgLength);

if (dev->state != SMSUSB_ACTIVE)
return -ENOENT;

smsendian_handle_tx_message((struct SmsMsgData_ST *) phdr);
smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer);
return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
buffer, size, &dummy, 1000);
Expand Down

0 comments on commit 80ccb51

Please sign in to comment.