summaryrefslogtreecommitdiff
path: root/xpp/xproto.c
diff options
context:
space:
mode:
Diffstat (limited to 'xpp/xproto.c')
-rw-r--r--xpp/xproto.c97
1 files changed, 47 insertions, 50 deletions
diff --git a/xpp/xproto.c b/xpp/xproto.c
index 89417b8..83a66d8 100644
--- a/xpp/xproto.c
+++ b/xpp/xproto.c
@@ -205,59 +205,29 @@ out:
return ret;
}
-int xframe_receive(xbus_t *xbus, xframe_t *xframe)
+static int xframe_receive_cmd(xbus_t *xbus, xframe_t *xframe)
{
- byte *p;
- byte *xpacket_start;
byte *xframe_end;
- int ret = 0;
xpacket_t *pack;
+ byte *p;
int len;
- bool is_pcm;
- struct timeval now;
- int usec;
+ int ret;
- if(!down_read_trylock(&xbus->in_use)) {
- XBUS_DBG(GENERAL, xbus, "Dropped xframe. Is in_use\n");
- return -ENODEV;
- }
- p = xpacket_start = xframe->packets;
- xframe_end = xpacket_start + XFRAME_LEN(xframe);
- if(XFRAME_LEN(xframe) < RPACKET_HEADERSIZE) {
- static int rate_limit;
-
- if((rate_limit++ % 1003) == 0) {
- XBUS_NOTICE(xbus, "short xframe\n");
- dump_xframe("short xframe", xbus, xframe);
- }
- goto bad_proto;
- }
- /*
- * We want to check that xframes do not mix PCM and other commands
- */
- is_pcm = XPACKET_IS_PCM((xpacket_t *)p);
- if(is_pcm && (print_dbg & DBG_PCM))
- dump_xframe("RX_XFRAME_PCM", xbus, xframe);
+ p = xframe->packets;
+ xframe_end = p + XFRAME_LEN(xframe);
do {
pack = (xpacket_t *)p;
len = XPACKET_LEN(pack);
/* Sanity checks */
- if(unlikely(is_pcm && XPACKET_OP(pack) != XPROTO_NAME(GLOBAL,PCM_READ))) {
- static int rate_limit;
-
- if((rate_limit++ % 1003) == 0) {
- XBUS_DBG(GENERAL, xbus, "Non-PCM packet within a PCM xframe\n");
- dump_xframe("In PCM xframe", xbus, xframe);
- }
- // goto bad_proto;
- } else if(unlikely(!is_pcm && XPACKET_OP(pack) == XPROTO_NAME(GLOBAL,PCM_READ))) {
+ if(unlikely(XPACKET_OP(pack) == XPROTO_NAME(GLOBAL,PCM_READ))) {
static int rate_limit;
if((rate_limit++ % 1003) == 0) {
XBUS_DBG(GENERAL, xbus, "A PCM packet within a Non-PCM xframe\n");
dump_xframe("In Non-PCM xframe", xbus, xframe);
}
- // goto bad_proto;
+ ret = -EPROTO;
+ goto out;
}
p += len;
if(p > xframe_end || len < RPACKET_HEADERSIZE) {
@@ -267,33 +237,60 @@ int xframe_receive(xbus_t *xbus, xframe_t *xframe)
XBUS_NOTICE(xbus, "Invalid packet length %d\n", len);
dump_xframe("BAD LENGTH", xbus, xframe);
}
- goto bad_proto;
+ ret = -EPROTO;
+ goto out;
}
ret = packet_process(xbus, pack);
if(unlikely(ret < 0))
- goto out;
+ break;
} while(p < xframe_end);
- if(is_pcm)
- XBUS_COUNTER(xbus, RX_XFRAME_PCM)++;
out:
+ FREE_RECV_XFRAME(xbus, xframe);
+ return ret;
+}
+
+int xframe_receive(xbus_t *xbus, xframe_t *xframe)
+{
+ int ret = 0;
+ struct timeval now;
+ struct timeval tv_received;
+ int usec;
+
+ if(XFRAME_LEN(xframe) < RPACKET_HEADERSIZE) {
+ static int rate_limit;
+
+ if((rate_limit++ % 1003) == 0) {
+ XBUS_NOTICE(xbus, "short xframe\n");
+ dump_xframe("short xframe", xbus, xframe);
+ }
+ return -EPROTO;
+ }
+ if(!XBUS_GET(xbus)) {
+ XBUS_DBG(GENERAL, xbus, "Dropped xframe. Is shutting down.\n");
+ return -ENODEV;
+ }
+ tv_received = xframe->tv_received;
+ /*
+ * We want to check that xframes do not mix PCM and other commands
+ */
+ if(XPACKET_IS_PCM((xpacket_t *)xframe->packets))
+ xframe_receive_pcm(xbus, xframe);
+ else
+ ret = xframe_receive_cmd(xbus, xframe);
/* Calculate total processing time */
do_gettimeofday(&now);
- usec = (now.tv_sec - xframe->tv_received.tv_sec) * 1000000 +
- now.tv_usec - xframe->tv_received.tv_usec;
+ usec = (now.tv_sec - tv_received.tv_sec) * 1000000 +
+ now.tv_usec - tv_received.tv_usec;
if(usec > xbus->max_rx_process)
xbus->max_rx_process = usec;
- xbus->ops->xframe_free(xbus, xframe);
- up_read(&xbus->in_use);
+ XBUS_PUT(xbus);
return ret;
-bad_proto:
- ret = -EPROTO;
- goto out;
}
#define VERBOSE_DEBUG 1
#define ERR_REPORT_LIMIT 20
-void dump_packet(const char *msg, xpacket_t *packet, bool print_dbg)
+void dump_packet(const char *msg, const xpacket_t *packet, bool print_dbg)
{
byte op = XPACKET_OP(packet);
byte *addr = (byte *)&XPACKET_ADDR(packet);