aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/dev_octeon/counter.c
blob: 5763237d105d29901338f80361167760f5842d90 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
 * Copyright (c) 2024 Marvell.
 * SPDX-License-Identifier: Apache-2.0
 * https://spdx.org/licenses/Apache-2.0.html
 */

#include <vnet/vnet.h>
#include <vnet/dev/dev.h>
#include <vnet/dev/pci.h>
#include <vnet/dev/counters.h>
#include <dev_octeon/octeon.h>
#include <dev_octeon/common.h>

VLIB_REGISTER_LOG_CLASS (oct_log, static) = {
  .class_name = "oct",
  .subclass_name = "counters",
};

typedef enum
{
  OCT_PORT_CTR_RX_BYTES,
  OCT_PORT_CTR_TX_BYTES,
  OCT_PORT_CTR_RX_PACKETS,
  OCT_PORT_CTR_TX_PACKETS,
  OCT_PORT_CTR_RX_DROPS,
  OCT_PORT_CTR_TX_DROPS,
  OCT_PORT_CTR_RX_DROP_BYTES,
  OCT_PORT_CTR_RX_UCAST,
  OCT_PORT_CTR_TX_UCAST,
  OCT_PORT_CTR_RX_MCAST,
  OCT_PORT_CTR_TX_MCAST,
  OCT_PORT_CTR_RX_BCAST,
  OCT_PORT_CTR_TX_BCAST,
  OCT_PORT_CTR_RX_FCS,
  OCT_PORT_CTR_RX_ERR,
  OCT_PORT_CTR_RX_DROP_MCAST,
  OCT_PORT_CTR_RX_DROP_BCAST,
  OCT_PORT_CTR_RX_DROP_L3_MCAST,
  OCT_PORT_CTR_RX_DROP_L3_BCAST,
} oct_port_counter_id_t;

vnet_dev_counter_t oct_port_counters[] = {
  VNET_DEV_CTR_RX_BYTES (OCT_PORT_CTR_RX_BYTES),
  VNET_DEV_CTR_RX_PACKETS (OCT_PORT_CTR_RX_PACKETS),
  VNET_DEV_CTR_RX_DROPS (OCT_PORT_CTR_RX_DROPS),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_DROP_BYTES, RX, BYTES, "drop bytes"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_UCAST, RX, PACKETS, "unicast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_MCAST, RX, PACKETS, "multicast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_BCAST, RX, PACKETS, "broadcast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_FCS, RX, PACKETS, "fcs"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_ERR, RX, PACKETS, "error"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_DROP_MCAST, RX, PACKETS,
		       "drop multicast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_DROP_BCAST, RX, PACKETS,
		       "drop broadcast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_DROP_L3_MCAST, RX, PACKETS,
		       "drop L3 multicast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_RX_DROP_L3_BCAST, RX, PACKETS,
		       "drop L3 broadcast"),

  VNET_DEV_CTR_TX_BYTES (OCT_PORT_CTR_TX_BYTES),
  VNET_DEV_CTR_TX_PACKETS (OCT_PORT_CTR_TX_PACKETS),
  VNET_DEV_CTR_TX_DROPS (OCT_PORT_CTR_TX_DROPS),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_TX_UCAST, TX, PACKETS, "unicast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_TX_MCAST, TX, PACKETS, "multicast"),
  VNET_DEV_CTR_VENDOR (OCT_PORT_CTR_TX_BCAST, TX, PACKETS, "broadcast"),
};

typedef enum
{
  OCT_RXQ_CTR_BYTES,
  OCT_RXQ_CTR_PKTS,
  OCT_RXQ_CTR_DROPS,
  OCT_RXQ_CTR_DROP_BYTES,
  OCT_RXQ_CTR_ERR,
} oct_rxq_counter_id_t;

vnet_dev_counter_t oct_rxq_counters[] = {
  VNET_DEV_CTR_RX_BYTES (OCT_RXQ_CTR_BYTES),
  VNET_DEV_CTR_RX_PACKETS (OCT_RXQ_CTR_PKTS),
  VNET_DEV_CTR_RX_DROPS (OCT_RXQ_CTR_DROPS),
  VNET_DEV_CTR_VENDOR (OCT_RXQ_CTR_DROP_BYTES, RX, BYTES, "drop bytes"),
  VNET_DEV_CTR_VENDOR (OCT_RXQ_CTR_ERR, RX, PACKETS, "error"),
};

typedef enum
{
  OCT_TXQ_CTR_BYTES,
  OCT_TXQ_CTR_PKTS,
  OCT_TXQ_CTR_DROPS,
  OCT_TXQ_CTR_DROP_BYTES,
} oct_txq_counter_id_t;

vnet_dev_counter_t oct_txq_counters[] = {
  VNET_DEV_CTR_TX_BYTES (OCT_TXQ_CTR_BYTES),
  VNET_DEV_CTR_TX_PACKETS (OCT_TXQ_CTR_PKTS),
  VNET_DEV_CTR_TX_DROPS (OCT_TXQ_CTR_DROPS),
  VNET_DEV_CTR_VENDOR (OCT_TXQ_CTR_DROP_BYTES, TX, BYTES, "drop bytes"),
};

static vnet_dev_rv_t
oct_roc_err (vnet_dev_t *dev, int rv, char *fmt, ...)
{
  u8 *s = 0;
  va_list va;

  va_start (va, fmt);
  s = va_format (s, fmt, &va);
  va_end (va);

  log_err (dev, "%v - ROC error %s (%d)", s, roc_error_msg_get (rv), rv);

  vec_free (s);
  return VNET_DEV_ERR_INTERNAL;
}

void
oct_port_add_counters (vlib_main_t *vm, vnet_dev_port_t *port)
{
  vnet_dev_port_add_counters (vm, port, oct_port_counters,
			      ARRAY_LEN (oct_port_counters));

  foreach_vnet_dev_port_rx_queue (rxq, port)
    {
      vnet_dev_rx_queue_add_counters (vm, rxq, oct_rxq_counters,
				      ARRAY_LEN (oct_rxq_counters));
    }

  foreach_vnet_dev_port_tx_queue (txq, port)
    {
      vnet_dev_tx_queue_add_counters (vm, txq, oct_txq_counters,
				      ARRAY_LEN (oct_txq_counters));
    }
}

vnet_dev_rv_t
oct_port_get_stats (vlib_main_t *vm, vnet_dev_port_t *port)
{
  vnet_dev_t *dev = port->dev;
  oct_device_t *cd = vnet_dev_get_data (dev);
  struct roc_nix *nix = cd->nix;
  int rrv;
  struct roc_nix_stats stats;

  if ((rrv = roc_nix_stats_get (nix, &stats)))
    return oct_roc_err (dev, rrv, "roc_nix_stats_get() failed");

  foreach_vnet_dev_counter (c, port->counter_main)
    {
      switch (c->user_data)
	{
	case OCT_PORT_CTR_RX_BYTES:
	  vnet_dev_counter_value_update (vm, c, stats.rx_octs);
	  break;
	case OCT_PORT_CTR_TX_BYTES:
	  vnet_dev_counter_value_update (vm, c, stats.tx_octs);
	  break;
	case OCT_PORT_CTR_RX_PACKETS:
	  vnet_dev_counter_value_update (
	    vm, c, stats.rx_ucast + stats.rx_bcast + stats.rx_mcast);
	  break;
	case OCT_PORT_CTR_TX_PACKETS:
	  vnet_dev_counter_value_update (
	    vm, c, stats.tx_ucast + stats.tx_bcast + stats.tx_mcast);
	  break;
	case OCT_PORT_CTR_RX_DROPS:
	  vnet_dev_counter_value_update (vm, c, stats.rx_drop);
	  break;
	case OCT_PORT_CTR_TX_DROPS:
	  vnet_dev_counter_value_update (vm, c, stats.tx_drop);
	  break;
	case OCT_PORT_CTR_RX_DROP_BYTES:
	  vnet_dev_counter_value_update (vm, c, stats.rx_drop_octs);
	  break;
	case OCT_PORT_CTR_RX_UCAST:
	  vnet_dev_counter_value_update (vm, c, stats.rx_ucast);
	  break;
	case OCT_PORT_CTR_TX_UCAST:
	  vnet_dev_counter_value_update (vm, c, stats.tx_ucast);
	  break;
	case OCT_PORT_CTR_RX_MCAST:
	  vnet_dev_counter_value_update (vm, c, stats.rx_mcast);
	  break;
	case OCT_PORT_CTR_TX_MCAST:
	  vnet_dev_counter_value_update (vm, c, stats.tx_mcast);
	  break;
	case OCT_PORT_CTR_RX_BCAST:
	  vnet_dev_counter_value_update (vm, c, stats.rx_bcast);
	  break;
	case OCT_PORT_CTR_TX_BCAST:
	  vnet_dev_counter_value_update (vm, c, stats.tx_bcast);
	  break;
	case OCT_PORT_CTR_RX_FCS:
	  vnet_dev_counter_value_update (vm, c, stats.rx_fcs);
	  break;
	case OCT_PORT_CTR_RX_ERR:
	  vnet_dev_counter_value_update (vm, c, stats.rx_err);
	  break;
	case OCT_PORT_CTR_RX_DROP_MCAST:
	  vnet_dev_counter_value_update (vm, c, stats.rx_drop_mcast);
	  break;
	case OCT_PORT_CTR_RX_DROP_BCAST:
	  vnet_dev_counter_value_update (vm, c, stats.rx_drop_bcast);
	  break;
	case OCT_PORT_CTR_RX_DROP_L3_MCAST:
	  vnet_dev_counter_value_update (vm, c, stats.rx_drop_l3_mcast);
	  break;
	case OCT_PORT_CTR_RX_DROP_L3_BCAST:
	  vnet_dev_counter_value_update (vm, c, stats.rx_drop_l3_bcast);
	  break;
	default:
	  ASSERT (0);
	}
    }

  return VNET_DEV_OK;
}

vnet_dev_rv_t
oct_rxq_get_stats (vlib_main_t *vm, vnet_dev_port_t *port,
		   vnet_dev_rx_queue_t *rxq)
{
  oct_rxq_t *crq = vnet_dev_get_rx_queue_data (rxq);
  struct roc_nix_stats_queue qstats;
  vnet_dev_t *dev = port->dev;
  oct_device_t *cd = vnet_dev_get_data (dev);
  struct roc_nix *nix = cd->nix;
  int rrv;

  if ((rrv = roc_nix_stats_queue_get (nix, crq->rq.qid, 1, &qstats)))
    return oct_roc_err (dev, rrv, "roc_nix_stats_queue_get() failed");

  foreach_vnet_dev_counter (c, rxq->counter_main)
    {
      switch (c->user_data)
	{
	case OCT_RXQ_CTR_BYTES:
	  vnet_dev_counter_value_update (vm, c, qstats.rx_octs);
	  break;
	case OCT_RXQ_CTR_PKTS:
	  vnet_dev_counter_value_update (vm, c, qstats.rx_pkts);
	  break;
	case OCT_RXQ_CTR_DROPS:
	  vnet_dev_counter_value_update (vm, c, qstats.rx_drop_pkts);
	  break;
	case OCT_RXQ_CTR_DROP_BYTES:
	  vnet_dev_counter_value_update (vm, c, qstats.rx_drop_octs);
	  break;
	case OCT_RXQ_CTR_ERR:
	  vnet_dev_counter_value_update (vm, c, qstats.rx_error_pkts);
	  break;
	default:
	  ASSERT (0);
	}
    }

  return VNET_DEV_OK;
}

vnet_dev_rv_t
oct_txq_get_stats (vlib_main_t *vm, vnet_dev_port_t *port,
		   vnet_dev_tx_queue_t *txq)
{
  oct_txq_t *ctq = vnet_dev_get_tx_queue_data (txq);
  struct roc_nix_stats_queue qstats;
  vnet_dev_t *dev = port->dev;
  oct_device_t *cd = vnet_dev_get_data (dev);
  struct roc_nix *nix = cd->nix;
  int rrv;

  if ((rrv = roc_nix_stats_queue_get (nix, ctq->sq.qid, 0, &qstats)))
    return oct_roc_err (dev, rrv, "roc_nix_stats_queue_get() failed");

  foreach_vnet_dev_counter (c, txq->counter_main)
    {
      switch (c->user_data)
	{
	case OCT_TXQ_CTR_BYTES:
	  vnet_dev_counter_value_update (vm, c, qstats.tx_octs);
	  break;
	case OCT_TXQ_CTR_PKTS:
	  vnet_dev_counter_value_update (vm, c, qstats.tx_pkts);
	  break;
	case OCT_TXQ_CTR_DROPS:
	  vnet_dev_counter_value_update (vm, c, qstats.tx_drop_pkts);
	  break;
	case OCT_TXQ_CTR_DROP_BYTES:
	  vnet_dev_counter_value_update (vm, c, qstats.tx_drop_octs);
	  break;
	default:
	  ASSERT (0);
	}
    }

  return VNET_DEV_OK;
}