summaryrefslogtreecommitdiffstats
path: root/src/plugins/dev_armada/pp2/rx.c
blob: 81101ef931394aaaba8ec6e6c681465e9a8c142b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* SPDX-License-Identifier: Apache-2.0
 * Copyright (c) 2024 Cisco Systems, Inc.
 */

#include <vlib/vlib.h>
#include <vnet/dev/dev.h>
#include <vnet/ethernet/ethernet.h>

#include <dev_armada/pp2/pp2.h>

static_always_inline void
mvpp2_rx_trace (vlib_main_t *vm, vlib_node_runtime_t *node,
		vnet_dev_rx_queue_t *rxq, vlib_buffer_t *b0, uword *n_trace,
		struct pp2_ppio_desc *d)
{
  if (PREDICT_TRUE (vlib_trace_buffer (vm, node, rxq->next_index, b0,
				       /* follow_chain */ 0)))
    {
      mvpp2_rx_trace_t *tr;
      vlib_set_trace_count (vm, node, --(*n_trace));
      tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
      tr->desc = *d;
      tr->rxq = rxq;
    }
}

static_always_inline uword
mrvl_pp2_rx_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
		    vlib_frame_t *frame, vnet_dev_rx_queue_t *rxq)
{
  vnet_main_t *vnm = vnet_get_main ();
  vnet_dev_port_t *port = rxq->port;
  vnet_dev_t *dev = port->dev;
  mvpp2_device_t *md = vnet_dev_get_data (dev);
  mvpp2_port_t *mp = vnet_dev_get_port_data (port);
  vlib_buffer_template_t bt = rxq->buffer_template;
  u32 thread_index = vm->thread_index;
  uword n_trace = vlib_get_trace_count (vm, node);
  u32 next_index = rxq->next_index;
  u32 n_rx_packets = 0, n_rx_bytes = 0;
  struct pp2_hif *hif = md->hif[thread_index];
  struct pp2_ppio_desc descs[VLIB_FRAME_SIZE], *d;
  struct pp2_bpool *bpool = md->thread[thread_index].bpool;
  struct buff_release_entry *bre = md->thread[thread_index].bre;
  u16 n_desc = VLIB_FRAME_SIZE;
  u32 buffers[VLIB_FRAME_SIZE];
  u32 n_bufs, *bi, i;
  vlib_buffer_t *b0, *b1;

  if (PREDICT_FALSE (
	pp2_ppio_recv (mp->ppio, 0, rxq->queue_id, descs, &n_desc)))
    {
      vlib_error_count (vm, node->node_index, MVPP2_RX_NODE_CTR_PPIO_RECV, 1);
      n_desc = 0;
    }

  n_rx_packets = n_desc;

  for (i = 0; i < n_desc; i++)
    buffers[i] = pp2_ppio_inq_desc_get_cookie (descs + i);

  bt.current_data = 2;

  for (d = descs, bi = buffers; n_desc >= 4; d += 2, bi += 2, n_desc -= 2)
    {
      /* prefetch */
      b0 = vlib_get_buffer (vm, bi[0]);
      b1 = vlib_get_buffer (vm, bi[1]);
      b0->template = bt;
      b1->template = bt;

      n_rx_bytes += b0->current_length = pp2_ppio_inq_desc_get_pkt_len (d);
      n_rx_bytes += b1->current_length = pp2_ppio_inq_desc_get_pkt_len (d + 1);

      if (PREDICT_FALSE (n_trace > 0))
	{
	  mvpp2_rx_trace (vm, node, rxq, b0, &n_trace, d);
	  if (n_trace > 0)
	    mvpp2_rx_trace (vm, node, rxq, b1, &n_trace, d + 1);
	}
    }

  for (; n_desc; d++, bi++, n_desc--)
    {
      b0 = vlib_get_buffer (vm, bi[0]);
      b0->template = bt;

      n_rx_bytes += b0->current_length = pp2_ppio_inq_desc_get_pkt_len (d);

      if (PREDICT_FALSE (n_trace > 0))
	mvpp2_rx_trace (vm, node, rxq, b0, &n_trace, d);
    }

  vlib_buffer_enqueue_to_single_next (vm, node, buffers, next_index,
				      n_rx_packets);

  vlib_increment_combined_counter (
    vnm->interface_main.combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
    thread_index, port->intf.sw_if_index, n_rx_packets, n_rx_bytes);

  if (PREDICT_FALSE (pp2_bpool_get_num_buffs (bpool, &n_bufs)))
    {
      vlib_error_count (vm, node->node_index,
			MVPP2_RX_NODE_CTR_BPOOL_GET_NUM_BUFFS, 1);
      goto done;
    }

  n_bufs = rxq->size - n_bufs;
  while (n_bufs >= MRVL_PP2_BUFF_BATCH_SZ)
    {
      u16 n_alloc, i;
      struct buff_release_entry *e = bre;

      n_alloc = vlib_buffer_alloc (vm, buffers, MRVL_PP2_BUFF_BATCH_SZ);
      i = n_alloc;

      if (PREDICT_FALSE (n_alloc == 0))
	{
	  vlib_error_count (vm, node->node_index,
			    MVPP2_RX_NODE_CTR_BUFFER_ALLOC, 1);
	  goto done;
	}

      for (bi = buffers; i--; e++, bi++)
	{

	  vlib_buffer_t *b = vlib_get_buffer (vm, bi[0]);
	  e->buff.addr = vlib_buffer_get_pa (vm, b) - 64;
	  e->buff.cookie = bi[0];
	}

      i = n_alloc;
      if (PREDICT_FALSE (pp2_bpool_put_buffs (hif, bre, &i)))
	{
	  vlib_error_count (vm, node->node_index,
			    MVPP2_RX_NODE_CTR_BPOOL_PUT_BUFFS, 1);
	  vlib_buffer_free (vm, buffers, n_alloc);
	  goto done;
	}

      if (PREDICT_FALSE (i != n_alloc))
	vlib_buffer_free (vm, buffers + i, n_alloc - i);

      n_bufs -= i;
    }

done:
  return n_rx_packets;
}

VNET_DEV_NODE_FN (mvpp2_rx_node)
(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
{
  u32 n_rx = 0;
  foreach_vnet_dev_rx_queue_runtime (rxq, node)
    n_rx += mrvl_pp2_rx_inline (vm, node, frame, rxq);
  return n_rx;
}