libmemif: Jumbo frames support

Change-Id: I2b316358dcd2de7168a860541bcca35c3dd44649
Signed-off-by: Jakub Grajciar <grajciar.jakub@gmail.com>
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index d1b59ee..49bf50c 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -512,8 +512,8 @@
   if (conn == NULL)
     return MEMIF_ERR_NOCONN;
   uint8_t num =
-    (conn->args.is_master) ? conn->run_args.num_s2m_rings : conn->run_args.
-    num_m2s_rings;
+    (conn->args.is_master) ? conn->run_args.num_s2m_rings : conn->
+    run_args.num_m2s_rings;
   if (qid >= num)
     return MEMIF_ERR_QID;
 
@@ -656,9 +656,9 @@
 		}
 	      DBG ("creating socket file");
 	      ms = malloc (sizeof (memif_socket_t));
-	      ms->filename = malloc (strlen ((char *) conn->args.
-					     socket_filename) +
-				     sizeof (char));
+	      ms->filename =
+		malloc (strlen ((char *) conn->args.socket_filename) +
+			sizeof (char));
 	      memset (ms->filename, 0,
 		      strlen ((char *) conn->args.socket_filename) +
 		      sizeof (char));
@@ -842,17 +842,20 @@
 	  if (((memif_connection_t *) e->data_struct)->on_interrupt != NULL)
 	    {
 	      num =
-		(((memif_connection_t *) e->data_struct)->args.
-		 is_master) ? ((memif_connection_t *) e->data_struct)->
-		run_args.num_s2m_rings : ((memif_connection_t *) e->
-					  data_struct)->run_args.
-		num_m2s_rings;
+		(((memif_connection_t *) e->data_struct)->
+		 args.is_master) ? ((memif_connection_t *) e->
+				    data_struct)->run_args.
+		num_s2m_rings : ((memif_connection_t *) e->data_struct)->
+		run_args.num_m2s_rings;
 	      for (i = 0; i < num; i++)
 		{
-		  if (((memif_connection_t *) e->data_struct)->rx_queues[i].
-		      int_fd == fd)
+		  if (((memif_connection_t *) e->data_struct)->
+		      rx_queues[i].int_fd == fd)
 		    {
-		      ((memif_connection_t *) e->data_struct)->on_interrupt ((void *) e->data_struct, ((memif_connection_t *) e->data_struct)->private_ctx, i);
+		      ((memif_connection_t *) e->data_struct)->
+			on_interrupt ((void *) e->data_struct,
+				      ((memif_connection_t *) e->
+				       data_struct)->private_ctx, i);
 		      return MEMIF_ERR_SUCCESS;
 		    }
 		}
@@ -879,24 +882,24 @@
 	  if (events & MEMIF_FD_EVENT_READ)
 	    {
 	      err =
-		((memif_connection_t *) e->data_struct)->read_fn (e->
-								  data_struct);
+		((memif_connection_t *) e->data_struct)->
+		read_fn (e->data_struct);
 	      if (err != MEMIF_ERR_SUCCESS)
 		return err;
 	    }
 	  if (events & MEMIF_FD_EVENT_WRITE)
 	    {
 	      err =
-		((memif_connection_t *) e->data_struct)->write_fn (e->
-								   data_struct);
+		((memif_connection_t *) e->data_struct)->
+		write_fn (e->data_struct);
 	      if (err != MEMIF_ERR_SUCCESS)
 		return err;
 	    }
 	  if (events & MEMIF_FD_EVENT_ERROR)
 	    {
 	      err =
-		((memif_connection_t *) e->data_struct)->error_fn (e->
-								   data_struct);
+		((memif_connection_t *) e->data_struct)->
+		error_fn (e->data_struct);
 	      if (err != MEMIF_ERR_SUCCESS)
 		return err;
 	    }
@@ -990,8 +993,8 @@
   if (c->tx_queues != NULL)
     {
       num =
-	(c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
-	num_s2m_rings;
+	(c->args.is_master) ? c->run_args.num_m2s_rings : c->
+	run_args.num_s2m_rings;
       for (i = 0; i < num; i++)
 	{
 	  mq = &c->tx_queues[i];
@@ -1011,8 +1014,8 @@
   if (c->rx_queues != NULL)
     {
       num =
-	(c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
-	num_m2s_rings;
+	(c->args.is_master) ? c->run_args.num_s2m_rings : c->
+	run_args.num_m2s_rings;
       for (i = 0; i < num; i++)
 	{
 	  mq = &c->rx_queues[i];
@@ -1164,8 +1167,8 @@
     }
 
   num =
-    (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
-    num_s2m_rings;
+    (c->args.is_master) ? c->run_args.num_m2s_rings : c->
+    run_args.num_s2m_rings;
   for (i = 0; i < num; i++)
     {
       mq = &c->tx_queues[i];
@@ -1182,8 +1185,8 @@
 	}
     }
   num =
-    (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
-    num_m2s_rings;
+    (c->args.is_master) ? c->run_args.num_s2m_rings : c->
+    run_args.num_m2s_rings;
   for (i = 0; i < num; i++)
     {
       mq = &c->rx_queues[i];
@@ -1336,7 +1339,7 @@
 int
 memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
 		    memif_buffer_t * bufs, uint16_t count,
-		    uint16_t * count_out)
+		    uint16_t * count_out, uint16_t size)
 {
   memif_connection_t *c = (memif_connection_t *) conn;
   if (c == NULL)
@@ -1344,17 +1347,18 @@
   if (c->fd < 0)
     return MEMIF_ERR_DISCONNECTED;
   uint8_t num =
-    (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
-    num_s2m_rings;
+    (c->args.is_master) ? c->run_args.num_m2s_rings : c->
+    run_args.num_s2m_rings;
   if (qid >= num)
     return MEMIF_ERR_QID;
   memif_queue_t *mq = &c->tx_queues[qid];
   memif_ring_t *ring = mq->ring;
   memif_buffer_t *b0, *b1;
+  uint8_t chain_buf0, chain_buf1;
   uint16_t mask = (1 << mq->log2_ring_size) - 1;
   uint16_t s0, s1, ns;
   *count_out = 0;
-  int err = MEMIF_ERR_SUCCESS;	/* 0 */
+  int i, err = MEMIF_ERR_SUCCESS;	/* 0 */
 
   if (ring->tail != ring->head)
     {
@@ -1374,39 +1378,86 @@
       while ((count > 2) && (ns > 2))
 	{
 	  s0 = (ring->head + mq->alloc_bufs + *count_out) & mask;
-	  s1 = (ring->head + mq->alloc_bufs + *count_out + 1) & mask;
+	  chain_buf0 = size / ring->desc[s0].buffer_length;
+	  if (((size % ring->desc[s0].buffer_length) != 0) || (size == 0))
+	    chain_buf0++;
+
+	  if (chain_buf0 > ns)
+	    break;
+
+	  s1 = (ring->head + mq->alloc_bufs + *count_out + chain_buf0) & mask;
+	  chain_buf1 = size / ring->desc[s1].buffer_length;
+	  if (((size % ring->desc[s1].buffer_length) != 0) || (size == 0))
+	    chain_buf1++;
+
+	  if ((chain_buf0 + chain_buf1) > ns)
+	    break;
 
 	  b0 = (bufs + *count_out);
 	  b1 = (bufs + *count_out + 1);
 
 	  b0->desc_index = s0;
 	  b1->desc_index = s1;
-	  b0->buffer_len = ring->desc[s0].buffer_length;
-	  b1->buffer_len = ring->desc[s1].buffer_length;
+	  b0->buffer_len = ring->desc[s0].buffer_length * chain_buf0;
+	  b1->buffer_len = ring->desc[s1].buffer_length * chain_buf1;
 	  /* TODO: support multiple regions -> ring descriptor contains region index */
 	  b0->data = c->regions->shm + ring->desc[s0].offset;
 	  b1->data = c->regions->shm + ring->desc[s1].offset;
 
+	  for (i = 0; i < (memif_min (chain_buf0, chain_buf1) - 1); i++)
+	    {
+	      ring->desc[(s0 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+	      ring->desc[(s1 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+	      DBG ("allocating chained buffers");
+	    }
+
+	  if (chain_buf0 > chain_buf1)
+	    {
+	      for (; i < (chain_buf0 - 1); i++)
+		ring->desc[(s0 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+	    }
+	  else
+	    {
+	      for (; i < (chain_buf1 - 1); i++)
+		ring->desc[(s1 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+	    }
+
+	  mq->alloc_bufs += chain_buf0 + chain_buf1;
+
 	  DBG ("allocated ring slots %u, %u", s0, s1);
 	  count -= 2;
-	  ns -= 2;
+	  ns -= chain_buf0 + chain_buf1;
 	  *count_out += 2;
 	}
       s0 = (ring->head + mq->alloc_bufs + *count_out) & mask;
 
       b0 = (bufs + *count_out);
 
+      chain_buf0 = size / ring->desc[s0].buffer_length;
+      if (((size % ring->desc[s0].buffer_length) != 0) || (size == 0))
+	chain_buf0++;
+
+      if (chain_buf0 > ns)
+	break;
+
       b0->desc_index = s0;
-      b0->buffer_len = ring->desc[s0].buffer_length;
+      b0->buffer_len = ring->desc[s0].buffer_length * chain_buf0;
       b0->data = c->regions->shm + ring->desc[s0].offset;
 
+      for (i = 0; i < (chain_buf0 - 1); i++)
+	{
+	  ring->desc[(s0 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+	  DBG ("allocating chained buffers");
+	}
+
+      mq->alloc_bufs += chain_buf0;
+
       DBG ("allocated ring slot %u", s0);
       count--;
-      ns--;
+      ns -= chain_buf0;
       *count_out += 1;
     }
 
-  mq->alloc_bufs += *count_out;
   DBG ("allocated: %u/%u bufs. Total %u allocated bufs", *count_out, count,
        mq->alloc_bufs);
 
@@ -1430,8 +1481,8 @@
   if (c->fd < 0)
     return MEMIF_ERR_DISCONNECTED;
   uint8_t num =
-    (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
-    num_m2s_rings;
+    (c->args.is_master) ? c->run_args.num_s2m_rings : c->
+    run_args.num_m2s_rings;
   if (qid >= num)
     return MEMIF_ERR_QID;
   libmemif_main_t *lm = &libmemif_main;
@@ -1439,6 +1490,7 @@
   memif_ring_t *ring = mq->ring;
   uint16_t tail = ring->tail;
   uint16_t mask = (1 << mq->log2_ring_size) - 1;
+  uint8_t chain_buf0, chain_buf1;
   memif_buffer_t *b0, *b1;
   *count_out = 0;
 
@@ -1451,22 +1503,35 @@
 	{
 	  b0 = (bufs + *count_out);
 	  b1 = (bufs + *count_out + 1);
-	  tail = (b0->desc_index + 1) & mask;
-	  tail = (b1->desc_index + 1) & mask;
+	  chain_buf0 =
+	    b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+	  if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) !=
+	      0)
+	    chain_buf0++;
+	  chain_buf1 =
+	    b1->buffer_len / ring->desc[b1->desc_index].buffer_length;
+	  if ((b1->buffer_len % ring->desc[b1->desc_index].buffer_length) !=
+	      0)
+	    chain_buf1++;
+	  tail = (b0->desc_index + chain_buf0) & mask;
+	  tail = (b1->desc_index + chain_buf1) & mask;
 	  b0->data = NULL;
 	  b1->data = NULL;
 
 	  count -= 2;
 	  *count_out += 2;
-	  mq->alloc_bufs -= 2;
+	  mq->alloc_bufs -= chain_buf0 + chain_buf1;
 	}
       b0 = (bufs + *count_out);
-      tail = (b0->desc_index + 1) & mask;
+      chain_buf0 = b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+      if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) != 0)
+	chain_buf0++;
+      tail = (b0->desc_index + chain_buf0) & mask;
       b0->data = NULL;
 
       count--;
       *count_out += 1;
-      mq->alloc_bufs--;
+      mq->alloc_bufs -= chain_buf0;
     }
   MEMIF_MEORY_BARRIER ();
   ring->tail = tail;
@@ -1484,33 +1549,94 @@
   if (c->fd < 0)
     return MEMIF_ERR_DISCONNECTED;
   uint8_t num =
-    (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
-    num_s2m_rings;
+    (c->args.is_master) ? c->run_args.num_m2s_rings : c->
+    run_args.num_s2m_rings;
   if (qid >= num)
     return MEMIF_ERR_QID;
   memif_queue_t *mq = &c->tx_queues[qid];
   memif_ring_t *ring = mq->ring;
   uint16_t head = ring->head;
   uint16_t mask = (1 << mq->log2_ring_size) - 1;
+  uint8_t chain_buf0, chain_buf1;
   *tx = 0;
+  uint16_t curr_buf = 0;
   memif_buffer_t *b0, *b1;
+  int i;
 
   while (count)
     {
       while (count > 2)
 	{
-	  b0 = (bufs + *tx);
-	  b1 = (bufs + *tx + 1);
-	  ring->desc[b0->desc_index].length = b0->data_len;
-	  ring->desc[b1->desc_index].length = b1->data_len;
+	  b0 = (bufs + curr_buf);
+	  b1 = (bufs + curr_buf + 1);
+	  chain_buf0 =
+	    b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+	  if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) !=
+	      0)
+	    chain_buf0++;
 
+	  chain_buf1 =
+	    b1->buffer_len / ring->desc[b1->desc_index].buffer_length;
+	  if ((b1->buffer_len % ring->desc[b1->desc_index].buffer_length) !=
+	      0)
+	    chain_buf1++;
+
+	  for (i = 0; i < memif_min (chain_buf0, chain_buf1); i++)
+	    {
+	      ring->desc[(b0->desc_index + i) & mask].length = b0->data_len;
+	      ring->desc[(b1->desc_index + i) & mask].length = b1->data_len;
 #ifdef MEMIF_DBG_SHM
-	  print_bytes (b0->data, b0->data_len, DBG_TX_BUF);
-	  print_bytes (b1->data, b1->data_len, DBG_TX_BUF);
+	      print_bytes (b0->data +
+			   ring->desc[(b0->desc_index +
+				       i) & mask].buffer_length *
+			   (chain_buf0 - 1),
+			   ring->desc[(b0->desc_index +
+				       i) & mask].buffer_length, DBG_TX_BUF);
+	      print_bytes (b1->data +
+			   ring->desc[(b1->desc_index +
+				       i) & mask].buffer_length *
+			   (chain_buf1 - 1),
+			   ring->desc[(b1->desc_index +
+				       i) & mask].buffer_length, DBG_TX_BUF);
 #endif
+	    }
 
-	  head = (b0->desc_index + 1) & mask;
-	  head = (b1->desc_index + 1) & mask;
+	  if (chain_buf0 > chain_buf1)
+	    {
+	      for (; i < chain_buf0; i++)
+		{
+		  ring->desc[(b0->desc_index + i) & mask].length =
+		    b0->data_len;
+#ifdef MEMIF_DBG_SHM
+		  print_bytes (b0->data +
+			       ring->desc[(b0->desc_index +
+					   i) & mask].buffer_length *
+			       (chain_buf0 - 1),
+			       ring->desc[(b0->desc_index +
+					   i) & mask].buffer_length,
+			       DBG_TX_BUF);
+#endif
+		}
+	    }
+	  else
+	    {
+	      for (; i < chain_buf1; i++)
+		{
+		  ring->desc[b1->desc_index + i].length = b1->data_len;
+#ifdef MEMIF_DBG_SHM
+		  print_bytes (b1->data +
+			       ring->desc[(b1->desc_index +
+					   i) & mask].buffer_length *
+			       (chain_buf1 - 1),
+			       ring->desc[(b1->desc_index +
+					   i) & mask].buffer_length,
+			       DBG_TX_BUF);
+#endif
+		}
+	    }
+
+	  head = (b0->desc_index + chain_buf0) & mask;
+	  head = (b1->desc_index + chain_buf1) & mask;
 
 	  b0->data = NULL;
 	  b0->data_len = 0;
@@ -1518,29 +1644,44 @@
 	  b1->data_len = 0;
 
 	  count -= 2;
-	  *tx += 2;
+	  *tx += chain_buf0 + chain_buf1;
+	  curr_buf += 2;
 	}
 
       b0 = (bufs + *tx);
-      ring->desc[b0->desc_index].length = b0->data_len;
+      chain_buf0 = b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+      if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) != 0)
+	chain_buf0++;
 
+      for (i = 0; i < chain_buf0; i++)
+	{
+	  ring->desc[(b0->desc_index + i) & mask].length = b0->data_len;
 #ifdef MEMIF_DBG_SHM
-      print_bytes (b0->data, b0->data_len, DBG_TX_BUF);
+	  print_bytes (b0->data +
+		       ring->desc[(b0->desc_index + i) & mask].buffer_length *
+		       (chain_buf0 - 1),
+		       ring->desc[(b0->desc_index + i) & mask].buffer_length,
+		       DBG_TX_BUF);
 #endif
+	}
 
-      head = (b0->desc_index + 1) & mask;
+      head = (b0->desc_index + chain_buf0) & mask;
 
       b0->data = NULL;
       b0->data_len = 0;
 
       count--;
-      *tx += 1;
+      *tx += chain_buf0;
+      curr_buf++;
     }
   MEMIF_MEORY_BARRIER ();
   ring->head = head;
 
   mq->alloc_bufs -= *tx;
 
+  /* TODO: return num of buffers and packets */
+  *tx = curr_buf;
+
   if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0)
     {
       uint64_t a = 1;
@@ -1562,8 +1703,8 @@
   if (c->fd < 0)
     return MEMIF_ERR_DISCONNECTED;
   uint8_t num =
-    (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
-    num_m2s_rings;
+    (c->args.is_master) ? c->run_args.num_s2m_rings : c->
+    run_args.num_m2s_rings;
   if (qid >= num)
     return MEMIF_ERR_QID;
   memif_queue_t *mq = &c->rx_queues[qid];
@@ -1572,7 +1713,9 @@
   uint16_t ns;
   uint16_t mask = (1 << mq->log2_ring_size) - 1;
   memif_buffer_t *b0, *b1;
+  uint16_t curr_buf = 0;
   *rx = 0;
+  int i;
 
   uint64_t b;
   ssize_t r = read (mq->int_fd, &b, sizeof (b));
@@ -1591,49 +1734,79 @@
     {
       while ((ns > 2) && (count > 2))
 	{
-	  b0 = (bufs + *rx);
-	  b1 = (bufs + *rx + 1);
+	  b0 = (bufs + curr_buf);
+	  b1 = (bufs + curr_buf + 1);
 
 	  b0->desc_index = mq->last_head;
-	  b1->desc_index = mq->last_head + 1;
-	  b0->data = memif_get_buffer (conn, ring, mq->last_head);
-	  b1->data = memif_get_buffer (conn, ring, mq->last_head + 1);
-	  b0->data_len = ring->desc[mq->last_head].length;
-	  b1->data_len = ring->desc[mq->last_head + 1].length;
-	  b0->buffer_len = ring->desc[mq->last_head].buffer_length;
-	  b1->buffer_len = ring->desc[mq->last_head + 1].buffer_length;
-
+	  i = 0;
+	  do
+	    {
+	      b0->data = memif_get_buffer (conn, ring, mq->last_head);
+	      b0->data_len = ring->desc[mq->last_head].length;
+	      b0->buffer_len = ring->desc[mq->last_head].buffer_length;
 #ifdef MEMIF_DBG_SHM
-	  print_bytes (b0->data, b0->data_len, DBG_RX_BUF);
-	  print_bytes (b1->data, b1->data_len, DBG_RX_BUF);
+	      print_bytes (b0->data +
+			   ring->desc[b0->desc_index].buffer_length * i++,
+			   ring->desc[b0->desc_index].buffer_length,
+			   DBG_TX_BUF);
 #endif
+	      mq->last_head = (mq->last_head + 1) & mask;
+	      ns--;
+	      *rx += 1;
+	    }
+	  while (ring->desc[mq->last_head].flags & MEMIF_DESC_FLAG_NEXT);
 
-	  mq->last_head = (mq->last_head + 2) & mask;
+	  b1->desc_index = mq->last_head;
+	  i = 0;
+	  do
+	    {
+	      b1->data = memif_get_buffer (conn, ring, mq->last_head);
+	      b1->data_len = ring->desc[mq->last_head].length;
+	      b1->buffer_len = ring->desc[mq->last_head].buffer_length;
+#ifdef MEMIF_DBG_SHM
+	      print_bytes (b1->data +
+			   ring->desc[b1->desc_index].buffer_length * i++,
+			   ring->desc[b1->desc_index].buffer_length,
+			   DBG_TX_BUF);
+#endif
+	      mq->last_head = (mq->last_head + 1) & mask;
+	      ns--;
+	      *rx += 1;
+	    }
+	  while (ring->desc[mq->last_head].flags & MEMIF_DESC_FLAG_NEXT);
 
-	  ns -= 2;
 	  count -= 2;
-	  *rx += 2;
+	  curr_buf += 2;
 	}
-      b0 = (bufs + *rx);
+      b0 = (bufs + curr_buf);
 
       b0->desc_index = mq->last_head;
-      b0->data = memif_get_buffer (conn, ring, mq->last_head);
-      b0->data_len = ring->desc[mq->last_head].length;
-      b0->buffer_len = ring->desc[mq->last_head].buffer_length;
-
+      i = 0;
+      do
+	{
+	  b0->data = memif_get_buffer (conn, ring, mq->last_head);
+	  b0->data_len = ring->desc[mq->last_head].length;
+	  b0->buffer_len = ring->desc[mq->last_head].buffer_length;
 #ifdef MEMIF_DBG_SHM
-      print_bytes (b0->data, b0->data_len, DBG_RX_BUF);
+	  print_bytes (b0->data +
+		       ring->desc[b0->desc_index].buffer_length * i++,
+		       ring->desc[b0->desc_index].buffer_length, DBG_TX_BUF);
 #endif
+	  mq->last_head = (mq->last_head + 1) & mask;
+	  ns--;
+	  *rx += 1;
+	}
+      while (ring->desc[mq->last_head].flags & MEMIF_DESC_FLAG_NEXT);
 
-      mq->last_head = (mq->last_head + 1) & mask;
-
-      ns--;
       count--;
-      *rx += 1;
+      curr_buf++;
     }
 
   mq->alloc_bufs += *rx;
 
+  /* TODO: return num of buffers and packets */
+  *rx = curr_buf;
+
   if (ns)
     {
       DBG ("not enough buffers!");
@@ -1722,8 +1895,8 @@
     err = MEMIF_ERR_NOBUF_DET;
 
   md->rx_queues_num =
-    (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
-    num_m2s_rings;
+    (c->args.is_master) ? c->run_args.num_s2m_rings : c->
+    run_args.num_m2s_rings;
 
   l1 = sizeof (memif_queue_details_t) * md->rx_queues_num;
   if (l0 + l1 <= buflen)
@@ -1742,8 +1915,8 @@
     }
 
   md->tx_queues_num =
-    (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
-    num_s2m_rings;
+    (c->args.is_master) ? c->run_args.num_m2s_rings : c->
+    run_args.num_s2m_rings;
 
   l1 = sizeof (memif_queue_details_t) * md->tx_queues_num;
   if (l0 + l1 <= buflen)
@@ -1776,8 +1949,8 @@
   if (c->fd < 0)
     return MEMIF_ERR_DISCONNECTED;
   uint8_t num =
-    (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
-    num_m2s_rings;
+    (c->args.is_master) ? c->run_args.num_s2m_rings : c->
+    run_args.num_m2s_rings;
   if (qid >= num)
     return MEMIF_ERR_QID;