summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/netmap
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/devices/netmap')
-rw-r--r--src/vnet/devices/netmap/device.c9
-rw-r--r--src/vnet/devices/netmap/netmap.c6
-rw-r--r--src/vnet/devices/netmap/netmap.h4
3 files changed, 6 insertions, 13 deletions
diff --git a/src/vnet/devices/netmap/device.c b/src/vnet/devices/netmap/device.c
index 2152824f733..aea9ddf4eb1 100644
--- a/src/vnet/devices/netmap/device.c
+++ b/src/vnet/devices/netmap/device.c
@@ -105,11 +105,7 @@ netmap_interface_tx (vlib_main_t * vm,
netmap_if_t *nif = pool_elt_at_index (nm->interfaces, rd->dev_instance);
int cur_ring;
- if (PREDICT_FALSE (nif->lockp != 0))
- {
- while (__sync_lock_test_and_set (nif->lockp, 1))
- ;
- }
+ clib_spinlock_lock_if_init (&nif->lockp);
cur_ring = nif->first_tx_ring;
@@ -165,8 +161,7 @@ netmap_interface_tx (vlib_main_t * vm,
if (n_left < frame->n_vectors)
ioctl (nif->fd, NIOCTXSYNC, NULL);
- if (PREDICT_FALSE (nif->lockp != 0))
- *nif->lockp = 0;
+ clib_spinlock_unlock_if_init (&nif->lockp);
if (n_left)
vlib_error_count (vm, node->node_index,
diff --git a/src/vnet/devices/netmap/netmap.c b/src/vnet/devices/netmap/netmap.c
index 3bdb442dda2..09afc7640ad 100644
--- a/src/vnet/devices/netmap/netmap.c
+++ b/src/vnet/devices/netmap/netmap.c
@@ -185,11 +185,7 @@ netmap_create_if (vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
nif->per_interface_next_index = ~0;
if (tm->n_vlib_mains > 1)
- {
- nif->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
- CLIB_CACHE_LINE_BYTES);
- memset ((void *) nif->lockp, 0, CLIB_CACHE_LINE_BYTES);
- }
+ clib_spinlock_init (&nif->lockp);
{
unix_file_t template = { 0 };
diff --git a/src/vnet/devices/netmap/netmap.h b/src/vnet/devices/netmap/netmap.h
index 39a94043c3c..e04f045d6e2 100644
--- a/src/vnet/devices/netmap/netmap.h
+++ b/src/vnet/devices/netmap/netmap.h
@@ -40,10 +40,12 @@
* SUCH DAMAGE.
*/
+#include <vppinfra/lock.h>
+
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- volatile u32 *lockp;
+ clib_spinlock_t lockp;
u8 *host_if_name;
uword if_index;
u32 hw_if_index;
: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2016 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.
 */

#ifndef __LOOKUP_DPO_H__
#define __LOOKUP_DPO_H__

#include <vnet/vnet.h>
#include <vnet/fib/fib_types.h>
#include <vnet/dpo/dpo.h>

/**
 * Switch to use the packet's source or destination address for lookup
 */
typedef enum lookup_input_t_ {
    LOOKUP_INPUT_SRC_ADDR,
    LOOKUP_INPUT_DST_ADDR,
} __attribute__ ((packed)) lookup_input_t;

#define LOOKUP_INPUTS {                         \
    [LOOKUP_INPUT_SRC_ADDR] = "src-address",    \
    [LOOKUP_INPUT_DST_ADDR] = "dst-address",    \
}

/**
 * Switch to use the packet's source or destination address for lookup
 */
typedef enum lookup_table_t_ {
    LOOKUP_TABLE_FROM_INPUT_INTERFACE,
    LOOKUP_TABLE_FROM_CONFIG,
} __attribute__ ((packed)) lookup_table_t;

#define LOOKUP_TABLES {                                   \
    [LOOKUP_TABLE_FROM_INPUT_INTERFACE] = "table-input-interface",    \
    [LOOKUP_TABLE_FROM_CONFIG] = "table-configured",         \
}

/**
 * Switch to use the packet's source or destination address for lookup
 */
typedef enum lookup_cast_t_ {
    LOOKUP_UNICAST,
    LOOKUP_MULTICAST,
} __attribute__ ((packed)) lookup_cast_t;

#define LOOKUP_CASTS {                 \
    [LOOKUP_UNICAST]   = "unicast",    \
    [LOOKUP_MULTICAST] = "multicast",  \
}

/**
 * A representation of an MPLS label for imposition in the data-path
 */
typedef struct lookup_dpo_t
{
    /**
     * required for pool_get_aligned.
     *  memebers used in the switch path come first!
     */
    CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);

    /**
     * The FIB, or interface from which to get a FIB, in which to perform
     * the next lookup;
     */
    fib_node_index_t lkd_fib_index;

    /**
     * The protocol of the FIB for the lookup, and hence
     * the protocol of the packet
     */
    dpo_proto_t lkd_proto;

    /**
     * Switch to use src or dst address
     */
    lookup_input_t lkd_input;

    /**
     * Switch to use the table index passed, or the table of the input interface
     */
    lookup_table_t lkd_table;

    /**
     * Unicast of rmulticast FIB lookup
     */
    lookup_cast_t lkd_cast;

    /**
     * Number of locks
     */
    u16 lkd_locks;
} lookup_dpo_t;

extern void lookup_dpo_add_or_lock_w_fib_index(fib_node_index_t fib_index,
                                               dpo_proto_t proto,
                                               lookup_cast_t cast,
                                               lookup_input_t input,
                                               lookup_table_t table,
                                               dpo_id_t *dpo);
extern void lookup_dpo_add_or_lock_w_table_id(u32 table_id,
                                              dpo_proto_t proto,
                                              lookup_cast_t cast,
                                              lookup_input_t input,
                                              lookup_table_t table,
                                              dpo_id_t *dpo);

extern u8* format_lookup_dpo(u8 *s, va_list *args);

/*
 * Encapsulation violation for fast data-path access
 */
extern lookup_dpo_t *lookup_dpo_pool;

static inline lookup_dpo_t *
lookup_dpo_get (index_t index)
{
    return (pool_elt_at_index(lookup_dpo_pool, index));
}

extern void lookup_dpo_module_init(void);

#endif