summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorRobert Shearman <robertshearman@gmail.com>2021-02-26 11:24:59 +0000
committerDamjan Marion <dmarion@me.com>2021-03-05 08:26:34 +0000
commit83a09c6b3cc2444132f90826b7e2ceb2a3f3347c (patch)
treee8b61e27e1ad8fcb65420fb9c293ee99dd6b6522 /src/plugins
parentf9e82a229179e7c76dd4548132933ac4947d37f1 (diff)
marvell: fix implicit declaration of function
Fix compile error due to implicit declaration of vnet_hw_if_get_rxq_poll_vector by including the header file that declares this. Type: fix Fixes: b85b0df2a039b694fb2f3c09a01decfb89d7bce2 Signed-off-by: Robert Shearman <robertshearman@gmail.com> Change-Id: I4a21743df93ffaa637641838d30b3b5c70dd79ef
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/marvell/pp2/input.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/plugins/marvell/pp2/input.c b/src/plugins/marvell/pp2/input.c
index d4a53fb627e..0c51d7d8ff6 100644
--- a/src/plugins/marvell/pp2/input.c
+++ b/src/plugins/marvell/pp2/input.c
@@ -25,6 +25,7 @@
#include <vlib/unix/unix.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/devices/devices.h>
+#include <vnet/interface/rx_queue_funcs.h>
#include <marvell/pp2/pp2.h>
7'>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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
/*
 * mdata.c - Buffer metadata change tracker
 *
 * Copyright (c) 2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <mdata/mdata.h>

#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vpp/app/version.h>
#include <stdbool.h>

#include <mdata/mdata.api_enum.h>
#include <mdata/mdata.api_types.h>

#define REPLY_MSG_ID_BASE mmp->msg_id_base
#include <vlibapi/api_helper_macros.h>

mdata_main_t mdata_main;

/** @file mdata.c
 * buffer metadata change tracker
 */

static mdata_t mdata_none;

/** Metadata tracking callback
    before_or_after: 0 => before, 1=> after
*/
static void
mdata_trace_callback (vlib_main_t * vm, u64 * c0, u64 * c1,
		      vlib_node_runtime_t * node,
		      vlib_frame_t * frame, int before_or_after)
{
  int i;
  mdata_main_t *mm = &mdata_main;
  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
  u32 *from;
  u32 n_left_from;
  mdata_t *before, *modifies;
  u8 *after;

  /* Input nodes don't have frames, etc. */
  if (frame == 0)
    return;

  n_left_from = frame->n_vectors;

  if (n_left_from == 0)
    return;

  from = vlib_frame_vector_args (frame);

  vlib_get_buffers (vm, from, bufs, n_left_from);
  b = bufs;

  if (before_or_after == 1 /* after */ )
    goto after_pass;

  /* Resize the per-thread "before" vector to cover the current frame */
  vec_reset_length (mm->before_per_thread[vm->thread_index]);
  vec_validate (mm->before_per_thread[vm->thread_index], n_left_from - 1);
  before = mm->before_per_thread[vm->thread_index];
  before->node_index = ~0;

  /* Before we call the dispatch fn, copy metadata. */
  while (n_left_from > 0)
    {
      clib_memcpy_fast (before->mdata, b[0], sizeof (before->mdata));
      b++;
      before++;
      n_left_from--;
    }
  return;

after_pass:

  /* Recover the metadata copy we saved a moment ago */
  before = mm->before_per_thread[vm->thread_index];

  /* We'd better have the same number of buffers... */
  ASSERT (n_left_from == vec_len (before));
  ASSERT (node->node_index);

  clib_spinlock_lock_if_init (&mm->modify_lock);

  /*
   * Resize the per-node accumulator vector as needed
   * Paint the "no data" patter across any nodes we haven't seen yet
   */
  vec_validate_init_empty (mm->modifies, node->node_index, mdata_none);
  modifies = vec_elt_at_index (mm->modifies, node->node_index);
  modifies->node_index = node->node_index;
  before = mm->before_per_thread[vm->thread_index];

  /* Walk the frame */
  while (n_left_from > 0)
    {
      after = (u8 *) b[0];

      /* Compare metadata before and after node dispatch fn */
      for (i = 0; i < ARRAY_LEN (before->mdata); i++)
	{
	  /* Mark mdata octet changed */
	  if (before->mdata[i] != after[i])
	    modifies->mdata[i] = 0xff;
	}

      b++;
      before++;
      n_left_from--;
    }

  clib_spinlock_unlock_if_init (&mm->modify_lock);
}

int
mdata_enable_disable (mdata_main_t * mmp, int enable_disable)
{
  int rv = 0;
  vlib_thread_main_t *thread_main = vlib_get_thread_main ();
  int i;

  if (mmp->modify_lock == 0 && thread_main->n_vlib_mains > 1)
    clib_spinlock_init (&mmp->modify_lock);

  if (vec_len (mmp->before_per_thread) == 0)
    {
      mdata_none.node_index = ~0;
      vec_validate (mmp->before_per_thread, vec_len (vlib_mains) - 1);
    }

  /* Reset the per-node accumulator, see vec_validate_init_empty above */
  vec_reset_length (mmp->modifies);

  for (i = 0; i < vec_len (vlib_mains); i++)
    {
      if (vlib_mains[i] == 0)
	continue;

      clib_callback_enable_disable
	(vlib_mains[i]->vlib_node_runtime_perf_counter_cbs,
	 vlib_mains[i]->vlib_node_runtime_perf_counter_cb_tmp,
	 vlib_mains[i]->worker_thread_main_loop_callback_lock,
	 (void *) mdata_trace_callback, enable_disable);
    }

  return rv;
}

static clib_error_t *
mdata_enable_disable_command_fn (vlib_main_t * vm,
				 unformat_input_t * input,
				 vlib_cli_command_t * cmd)
{
  mdata_main_t *mmp = &mdata_main;
  int enable_disable = 1;

  int rv;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "disable") || unformat (input, "off"))
	enable_disable = 0;
      if (unformat (input, "enable") || unformat (input, "on"))
	enable_disable = 1;
      else
	break;
    }

  rv = mdata_enable_disable (mmp, enable_disable);

  switch (rv)
    {
    case 0:
      break;

    default:
      return clib_error_return (0, "mdata_enable_disable returned %d", rv);
    }
  return 0;
}

/*?
 * This command enables or disables buffer metadata change tracking
 *
 *@cliexpar
 * To enable buffer metadata change tracking:
 *@cliexstart{buffer metadata tracking on}
 * Tracking enabled
 *@cliexend
 *
 *@cliexstart{buffer metadata tracking off}
 * Tracking disabled
 *@cliexend
?*/

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (mdata_enable_disable_command, static) =
{
  .path = "buffer metadata tracking",
  .short_help = "buffer metadata tracking [on][off]",
  .function = mdata_enable_disable_command_fn,
};
/* *INDENT-ON* */

/* API message handler */
static void vl_api_mdata_enable_disable_t_handler
  (vl_api_mdata_enable_disable_t * mp)
{
  vl_api_mdata_enable_disable_reply_t *rmp;
  mdata_main_t *mmp = &mdata_main;
  int rv;

  rv = mdata_enable_disable (mmp, (int) (mp->enable_disable));

  REPLY_MACRO (VL_API_MDATA_ENABLE_DISABLE_REPLY);
}

/* API definitions */
#include <mdata/mdata.api.c>

static clib_error_t *
mdata_init (vlib_main_t * vm)
{
  mdata_main_t *mmp = &mdata_main;
  clib_error_t *error = 0;

  mmp->vlib_main = vm;
  mmp->vnet_main = vnet_get_main ();

  /* Add our API messages to the global name_crc hash table */
  mmp->msg_id_base = setup_message_id_table ();

  return error;
}

VLIB_INIT_FUNCTION (mdata_init);

/* *INDENT-OFF* */
VLIB_PLUGIN_REGISTER () =
{
  .version = VPP_BUILD_VER,
  .description = "Buffer metadata change tracker."
};
/* *INDENT-ON* */


#define foreach_primary_metadata_field          \
_(current_data)                                 \
_(current_length)                               \
_(flags)                                        \
_(flow_id)                                      \
_(ref_count)                                    \
_(buffer_pool_index)                            \
_(error)                                        \
_(next_buffer)                                  \
_(current_config_index)                         \
_(punt_reason)

#define foreach_opaque_metadata_field           \
_(sw_if_index[0])                               \
_(sw_if_index[1])                               \
_(l2_hdr_offset)                                \
_(l3_hdr_offset)                                \
_(l4_hdr_offset)                                \
_(feature_arc_index)                            \
_(ip.adj_index[0])                              \
_(ip.adj_index[1])                              \
_(ip.flow_hash)                                 \
_(ip.save_protocol)                             \
_(ip.fib_index)                                 \
_(ip.icmp.type)                                 \
_(ip.icmp.code)                                 \
_(ip.icmp.data)                                 \
_(ip.reass.next_index)                          \
_(ip.reass.error_next_index)                    \
_(ip.reass.owner_thread_index)                  \
_(ip.reass.ip_proto)                            \
_(ip.reass.l4_src_port)                         \
_(ip.reass.l4_dst_port)                         \
_(ip.reass.estimated_mtu)                       \
_(ip.reass.fragment_first)                      \
_(ip.reass.fragment_last)                       \
_(ip.reass.range_first)                         \
_(ip.reass.range_last)                          \
_(ip.reass.next_range_bi)                       \
_(ip.reass.ip6_frag_hdr_offset)                 \
_(mpls.ttl)                                     \
_(mpls.exp)                                     \
_(mpls.first)                                   \
_(mpls.save_rewrite_length)                     \
_(mpls.mpls_hdr_length)                         \
_(mpls.bier.n_bytes)                            \
_(l2.feature_bitmap)                            \
_(l2.bd_index)                                  \
_(l2.l2fib_sn)                                  \
_(l2.l2_len)                                    \
_(l2.shg)                                       \
_(l2.bd_age)                                    \
_(l2t.next_index)                               \
_(l2t.session_index)                            \
_(l2_classify.table_index)                      \
_(l2_classify.opaque_index)                     \
_(l2_classify.hash)                             \
_(policer.index)                                \
_(ipsec.sad_index)                              \
_(ipsec.protect_index)                          \
_(map.mtu)                                      \
_(map_t.map_domain_index)			\
_(map_t.v6.saddr)                               \
_(map_t.v6.daddr)                               \
_(map_t.v6.frag_offset)                         \
_(map_t.v6.l4_offset)                           \
_(map_t.v6.l4_protocol)                         \
_(map_t.checksum_offset)			\
_(map_t.mtu)                                    \
_(ip_frag.mtu)                                  \
_(ip_frag.next_index)                           \
_(ip_frag.flags)                                \
_(cop.current_config_index)                     \
_(lisp.overlay_afi)                             \
_(tcp.connection_index)                         \
_(tcp.seq_number)                               \
_(tcp.next_node_opaque)                         \
_(tcp.seq_end)                                  \
_(tcp.ack_number)                               \
_(tcp.hdr_offset)                               \
_(tcp.data_offset)                              \
_(tcp.data_len)                                 \
_(tcp.flags)                                    \
_(snat.flags)

#define foreach_opaque2_metadata_field          \
_(qos.bits)                                     \
_(qos.source)                                   \
_(loop_counter)                                 \
_(gbp.flags)                                    \
_(gbp.sclass)                                   \
_(gso_size)                                     \
_(gso_l4_hdr_sz)                                \
_(pg_replay_timestamp)

static u8 *
format_buffer_metadata_changes (u8 * s, va_list * args)
{
  mdata_main_t *mm = va_arg (*args, mdata_main_t *);
  int verbose = va_arg (*args, int);
  mdata_t *modifies;
  vlib_buffer_t *b;
  vnet_buffer_opaque_t *o;
  vnet_buffer_opaque2_t *o2;
  vlib_node_t *node;
  int i, j;
  int printed;

  clib_spinlock_lock_if_init (&mm->modify_lock);

  for (i = 0; i < vec_len (mm->modifies); i++)
    {
      modifies = vec_elt_at_index (mm->modifies, i);
      node = vlib_get_node (mm->vlib_main, i);

      /* No data for this node? */
      if (modifies->node_index == ~0)
	{
	  if (verbose)
	    s = format (s, "\n%v: no data\n", node->name);
	  continue;
	}

      /* We visited the node, but it may not have changed any metadata... */
      for (j = 0; j < ARRAY_LEN (modifies->mdata); j++)
	{
	  if (modifies->mdata[j])
	    goto found;
	}
      s = format (s, "\n%v: no metadata changes\n", node->name);
      continue;

    found:
      /* Fields which the node modifies will be non-zero */
      b = (vlib_buffer_t *) (modifies->mdata);

      /* Dump primary metadata changes */
      s = format (s, "\n%v: ", node->name);

      printed = 0;
#define _(n) if (b->n) {s = format (s, "%s ", #n); printed = 1;}
      foreach_primary_metadata_field;
#undef _

      if (printed == 0)
	s = format (s, "no vlib_buffer_t metadata changes");

      vec_add1 (s, '\n');

      /*
       * Dump opaque union changes.
       * Hopefully this will give folks a clue about opaque
       * union data conflicts. That's the point of the exercise...
       */
      o = vnet_buffer (b);
      printed = 0;
      s = format (s, "  vnet_buffer_t: ");

#define _(n) if (o->n) {s = format (s, "%s ", #n); printed = 1;}
      foreach_opaque_metadata_field;
#undef _

      if (printed == 0)
	s = format (s, "no changes");

      vec_add1 (s, '\n');

      o2 = vnet_buffer2 (b);
      printed = 0;
      s = format (s, "  vnet_buffer2_t: ");

#define _(n) if (o2->n) {s = format (s, "%s ", #n); printed = 1;}
      foreach_opaque2_metadata_field;
#undef _
      if (printed == 0)
	s = format (s, "no changes");

      vec_add1 (s, '\n');

    }

  clib_spinlock_unlock_if_init (&mm->modify_lock);

  return s;
}

static clib_error_t *
show_metadata_command_fn (vlib_main_t * vm,
			  unformat_input_t * input, vlib_cli_command_t * cmd)
{
  int verbose = 0;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "verbose %=", &verbose, 1))
	;
      else
	break;
    }

  vlib_cli_output (vm, "%U", format_buffer_metadata_changes, &mdata_main,
		   verbose);
  return 0;
}

/*?
 * This command displays buffer metadata change information
 *@cliexpar
 * How to display buffer metadata change information
 *@cliexstart{show buffer metadata}
 * ethernet-input: current_data current_length flags error
 * vnet_buffer_t: l2_hdr_offset l3_hdr_offset
 * vnet_buffer2_t: no changes
 *@cliexend
?*/

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_metadata_command, static) =
{
  .path = "show buffer metadata",
  .short_help = "show buffer metadata",
  .function = show_metadata_command_fn,
};
/* *INDENT-OFF* */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */