summaryrefslogtreecommitdiffstats
path: root/src/vnet/l2/feat_bitmap.c
blob: 6c046467f2ccee4cf06cec0c8b8ee9b080b1a5de (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
/*
 * feat_bitmap.c: bitmap for managing feature invocation
 *
 * Copyright (c) 2013 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 <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vnet/pg/pg.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/ethernet/packet.h>
#include <vlib/cli.h>
#include <vnet/l2/l2_input.h>
#include <vnet/l2/feat_bitmap.h>

#include <vppinfra/error.h>
#include <vppinfra/hash.h>
#include <vppinfra/cache.h>


/*
 * Drop node for feature bitmaps
 * For features that just do a drop, or are not yet implemented.
 * Initial feature dispatch nodes don't need to set b0->error
 * in case of a possible drop because that will be done here.
 *The next node is always error-drop.
 */

static vlib_node_registration_t feat_bitmap_drop_node;

#define foreach_feat_bitmap_drop_error		\
_(NO_FWD,     "L2 feature forwarding disabled")	\
_(NYI,        "L2 feature not implemented")

typedef enum
{
#define _(sym,str) FEAT_BITMAP_DROP_ERROR_##sym,
  foreach_feat_bitmap_drop_error
#undef _
    FEAT_BITMAP_DROP_N_ERROR,
} feat_bitmap_drop_error_t;

static char *feat_bitmap_drop_error_strings[] = {
#define _(sym,string) string,
  foreach_feat_bitmap_drop_error
#undef _
};

typedef enum
{
  FEAT_BITMAP_DROP_NEXT_DROP,
  FEAT_BITMAP_DROP_N_NEXT,
} feat_bitmap_drop_next_t;

typedef struct
{
  u32 feature_bitmap;
} feat_bitmap_drop_trace_t;

/* packet trace format function */
static u8 *
format_feat_bitmap_drop_trace (u8 * s, va_list * args)
{
  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
  feat_bitmap_drop_trace_t *t = va_arg (*args, feat_bitmap_drop_trace_t *);

  s =
    format (s, "feat_bitmap_drop: feature bitmap 0x%08x", t->feature_bitmap);
  return s;
}

static uword
feat_bitmap_drop_node_fn (vlib_main_t * vm,
			  vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  u32 n_left_from, *from, *to_next;
  feat_bitmap_drop_next_t next_index;

  from = vlib_frame_vector_args (frame);
  n_left_from = frame->n_vectors;	/* number of packets to process */
  next_index = node->cached_next_index;

  while (n_left_from > 0)
    {
      u32 n_left_to_next;

      /* get space to enqueue frame to graph node "next_index" */
      vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);

      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  u32 bi0;
	  vlib_buffer_t *b0;
	  u32 next0;

	  /* speculatively enqueue b0 to the current next frame */
	  bi0 = from[0];
	  to_next[0] = bi0;
	  from += 1;
	  to_next += 1;
	  n_left_from -= 1;
	  n_left_to_next -= 1;

	  b0 = vlib_get_buffer (vm, bi0);

	  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
			     && (b0->flags & VLIB_BUFFER_IS_TRACED)))
	    {
	      feat_bitmap_drop_trace_t *t =
		vlib_add_trace (vm, node, b0, sizeof (*t));
	      t->feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap;
	    }

	  if (vnet_buffer (b0)->l2.feature_bitmap == 1)
	    {
	      /*
	       * If we are executing the last feature, this is the
	       * No forwarding catch-all
	       */
	      b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NO_FWD];
	    }
	  else
	    {
	      b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NYI];
	    }
	  next0 = FEAT_BITMAP_DROP_NEXT_DROP;

	  /* verify speculative enqueue, maybe switch current next frame */
	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, next0);
	}

      vlib_put_next_frame (vm, node, next_index, n_left_to_next);
    }
  return frame->n_vectors;
}

clib_error_t *
feat_bitmap_drop_init (vlib_main_t * vm)
{
  return 0;
}

VLIB_INIT_FUNCTION (feat_bitmap_drop_init);

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (feat_bitmap_drop_node,static) = {
  .function = feat_bitmap_drop_node_fn,
  .name = "feature-bitmap-drop",
  .vector_size = sizeof (u32),
  .format_trace = format_feat_bitmap_drop_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,

  .n_errors = ARRAY_LEN(feat_bitmap_drop_error_strings),
  .error_strings = feat_bitmap_drop_error_strings,

  .n_next_nodes = FEAT_BITMAP_DROP_N_NEXT,

  /* edit / add dispositions here */
  .next_nodes = {
    [FEAT_BITMAP_DROP_NEXT_DROP]  = "error-drop",
  },
};
/* *INDENT-ON* */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
span> u64 qw1s[AVF_RX_VECTOR_SZ]; avf_rx_tail_t tails[AVF_RX_VECTOR_SZ]; vlib_buffer_t buffer_template; } avf_per_thread_data_t; typedef struct { u16 msg_id_base; avf_device_t *devices; avf_per_thread_data_t *per_thread_data; vlib_log_class_t log_class; } avf_main_t; extern avf_main_t avf_main; typedef struct { vlib_pci_addr_t addr; u8 *name; int enable_elog; u16 rxq_num; u16 rxq_size; u16 txq_size; /* return */ int rv; u32 sw_if_index; clib_error_t *error; } avf_create_if_args_t; void avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args); void avf_delete_if (vlib_main_t * vm, avf_device_t * ad); extern vlib_node_registration_t avf_input_node; extern vnet_device_class_t avf_device_class; /* format.c */ format_function_t format_avf_device; format_function_t format_avf_device_name; format_function_t format_avf_input_trace; static inline u32 avf_get_u32 (void *start, int offset) { return *(u32 *) (((u8 *) start) + offset); } static inline u64 avf_get_u64 (void *start, int offset) { return *(u64 *) (((u8 *) start) + offset); } static inline u32 avf_get_u32_bits (void *start, int offset, int first, int last) { u32 value = avf_get_u32 (start, offset); if ((last == 0) && (first == 31)) return value; value >>= last; value &= (1 << (first - last + 1)) - 1; return value; } static inline u64 avf_get_u64_bits (void *start, int offset, int first, int last) { u64 value = avf_get_u64 (start, offset); if ((last == 0) && (first == 63)) return value; value >>= last; value &= (1 << (first - last + 1)) - 1; return value; } static inline void avf_set_u32 (void *start, int offset, u32 value) { (*(u32 *) (((u8 *) start) + offset)) = value; } static inline void avf_reg_write (avf_device_t * ad, u32 addr, u32 val) { *(volatile u32 *) ((u8 *) ad->bar0 + addr) = val; } static inline u32 avf_reg_read (avf_device_t * ad, u32 addr) { return *(volatile u32 *) (ad->bar0 + addr); } static inline void avf_reg_flush (avf_device_t * ad) { avf_reg_read (ad, AVFGEN_RSTAT); asm volatile ("":::"memory"); } static_always_inline int avf_rxd_is_not_eop (avf_rx_desc_t * d) { return (d->qword[1] & AVF_RXD_STATUS_EOP) == 0; } static_always_inline int avf_rxd_is_not_dd (avf_rx_desc_t * d) { return (d->qword[1] & AVF_RXD_STATUS_DD) == 0; } typedef struct { u32 next_index; u32 hw_if_index; u64 qw1s[AVF_RX_MAX_DESC_IN_CHAIN]; } avf_input_trace_t; #define foreach_avf_tx_func_error \ _(NO_FREE_SLOTS, "no free tx slots") typedef enum { #define _(f,s) AVF_TX_ERROR_##f, foreach_avf_tx_func_error #undef _ AVF_TX_N_ERROR, } avf_tx_func_error_t; #endif /* AVF_H */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */