aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/asm_mips.h
blob: 7c9e69586f4a5343ecfb7a1fa9f90c23f7e18777 (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
.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) 2015 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/ipsec/ipsec.h>
#include <vnet/ipsec/ipsec_io.h>

int
ipsec_add_del_spd (vlib_main_t * vm, u32 spd_id, int is_add)
{
  ipsec_main_t *im = &ipsec_main;
  ipsec_spd_t *spd = 0;
  uword *p;
  u32 spd_index, k, v;

  p = hash_get (im->spd_index_by_spd_id, spd_id);
  if (p && is_add)
    return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
  if (!p && !is_add)
    return VNET_API_ERROR_NO_SUCH_ENTRY;

  if (!is_add)			/* delete */
    {
      spd_index = p[0];
      spd = pool_elt_at_index (im->spds, spd_index);
      if (!spd)
	return VNET_API_ERROR_INVALID_VALUE;
      /* *INDENT-OFF* */
      hash_foreach (k, v, im->spd_index_by_sw_if_index, ({
        if (v == spd_index)
          ipsec_set_interface_spd(vm, k, spd_id, 0);
      }));
      /* *INDENT-ON* */
      hash_unset (im->spd_index_by_spd_id, spd_id);
#define _(s,v) vec_free(spd->policies[IPSEC_SPD_POLICY_##s]);
      foreach_ipsec_spd_policy_type
#undef _
	pool_put (im->spds, spd);
    }
  else				/* create new SPD */
    {
      pool_get (im->spds, spd);
      clib_memset (spd, 0, sizeof (*spd));
      spd_index = spd - im->spds;
      spd->id = spd_id;
      hash_set (im->spd_index_by_spd_id, spd_id, spd_index);
    }
  return 0;
}

int
ipsec_set_interface_spd (vlib_main_t * vm, u32 sw_if_index, u32 spd_id,
			 int is_add)
{
  ipsec_main_t *im = &ipsec_main;
  ip4_ipsec_config_t config;

  u32 spd_index;
  uword *p;

  p = hash_get (im->spd_index_by_spd_id, spd_id);
  if (!p)
    return VNET_API_ERROR_SYSCALL_ERROR_1;	/* no such spd-id */

  spd_index = p[0];

  p = hash_get (im->spd_index_by_sw_if_index, sw_if_index);
  if (p && is_add)
    return VNET_API_ERROR_SYSCALL_ERROR_1;	/* spd already assigned */

  if (is_add)
    {
      hash_set (im->spd_index_by_sw_if_index, sw_if_index, spd_index);
    }
  else
    {
      hash_unset (im->spd_index_by_sw_if_index, sw_if_index);
    }

  /* enable IPsec on TX */
  vnet_feature_enable_disable ("ip4-output", "ipsec4-output-feature",
			       sw_if_index, is_add, 0, 0);
  vnet_feature_enable_disable ("ip6-output", "ipsec6-output-feature",
			       sw_if_index, is_add, 0, 0);

  config.spd_index = spd_index;

  /* enable IPsec on RX */
  vnet_feature_enable_disable ("ip4-unicast", "ipsec4-input-feature",
			       sw_if_index, is_add, &config, sizeof (config));
  vnet_feature_enable_disable ("ip6-unicast", "ipsec6-input-feature",
			       sw_if_index, is_add, &config, sizeof (config));

  return 0;
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
ld. */ #define mips_foreach_cop0_rs \ _(mfc0) _(dmfc0) _(o02) _(o03) _(mtc0) _(dmtc0) _(o06) _(o07) \ _(o10) _(o11) _(o12) _(o13) _(o14) _(o15) _(o16) _(o17) \ _(C0) _(o21) _(o22) _(o23) _(o24) _(o25) _(o26) _(o27) \ _(o30) _(o31) _(o32) _(o33) _(o34) _(o35) _(o36) _(o37) /* COP0 encoding of funct when rs == RS_CO */ #define mips_foreach_cop0_funct \ _(o00) _(tlbr) _(tlbwi) _(o03) _(o04) _(o05) _(tlbwr) _(o07) \ _(tlbp) _(o11) _(o12) _(o13) _(o14) _(o15) _(o16) _(o17) \ _(o20) _(o21) _(o22) _(o23) _(o24) _(o25) _(o26) _(o27) \ _(eret) _(o31) _(o32) _(o33) _(o34) _(o35) _(o36) _(deret) \ _(wait) _(o41) _(o42) _(o43) _(o44) _(o45) _(o46) _(o47) \ _(o50) _(o51) _(o52) _(o53) _(o54) _(o55) _(o56) _(o57) \ _(o60) _(o61) _(o62) _(o63) _(o64) _(o65) _(o66) _(o67) \ _(o70) _(o71) _(o72) _(o73) _(o74) _(o75) _(o76) _(o77) /* COP1 encoding of rs field. */ #define mips_foreach_cop1_rs \ _(mfc1) _(dmfc1) _(cfc1) _(o03) _(mtc1) _(dmtc1) _(ctc1) _(o07) \ _(BC1) _(o11) _(o12) _(o13) _(o14) _(o15) _(o16) _(o17) \ _(S) _(D) _(o22) _(o23) _(W) _(L) _(o26) _(o27) \ _(o30) _(o31) _(o32) _(o33) _(o34) _(o35) _(o36) _(o37) /* COP1 encoding of funct for S and D */ #define mips_foreach_cop1_funct \ _(add) _(sub) _(mul) _(div) _(sqrt) _(abs) _(mov) _(neg) \ _(roundl) _(truncl) _(ceill) _(floorl) _(roundw) _(truncw) _(ceilw) _(floorw) \ _(o20) _(MOVCF) _(movz) _(movn) _(o24) _(recip) _(rsqrt) _(o27) \ _(o30) _(o31) _(o32) _(o33) _(o34) _(o35) _(o36) _(o37) \ _(cvts) _(cvtd) _(o42) _(o43) _(cvtw) _(cvtl) _(o46) _(o47) \ _(o50) _(o51) _(o52) _(o53) _(o54) _(o55) _(o56) _(o57) \ _(cf) _(cun) _(ceq) _(cueq) _(colt) _(cult) _(cole) _(cule) \ _(csf) _(cngle) _(cseq) _(cngl) _(clt) _(cnge) _(cle) _(cngt) /* COP1X encoding of funct */ #define mips_foreach_cop1x_funct \ _(lwxc1) _(ldxc1) _(o02) _(o03) _(o04) _(luxc1) _(o06) _(o07) \ _(swxc1) _(sdxc1) _(o12) _(o13) _(o14) _(suxc1) _(o16) _(prefx) \ _(o20) _(o21) _(o22) _(o23) _(o24) _(o25) _(o26) _(o27) \ _(o30) _(o31) _(o32) _(o33) _(o34) _(o35) _(o36) _(o37) \ _(madds) _(maddd) _(o42) _(o43) _(o44) _(o45) _(o46) _(o47) \ _(msubs) _(msubd) _(o52) _(o53) _(o54) _(o55) _(o56) _(o57) \ _(nmadds) _(nmaddd) _(o62) _(o63) _(o64) _(o65) _(o66) _(o67) \ _(nmsubs) _(nmsubd) _(o72) _(o73) _(o74) _(o75) _(o76) _(o77) #define mips_foreach_mdmx_funct \ _(msgn) _(ceq) _(pickf) _(pickt) _(clt) _(cle) _(min) _(max) \ _(o10) _(o11) _(sub) _(add) _(and) _(xor) _(or) _(nor) \ _(sll) _(o21) _(srl) _(sra) _(o24) _(o25) _(o26) _(o27) \ _(alniob) _(alnvob) _(alniqh) _(alnvqh) _(o34) _(o35) _(o36) _(shfl) \ _(rzu) _(rnau) _(rneu) _(o43) _(rzs) _(rnas) _(rnes) _(o47) \ _(o50) _(o51) _(o52) _(o53) _(o54) _(o55) _(o56) _(o57) \ _(mul) _(o61) _(muls) _(mula) _(o64) _(o65) _(suba) _(adda) \ _(o70) _(o71) _(o72) _(o73) _(o74) _(o75) _(wac) _(rac) #define _(f) MIPS_OPCODE_##f, typedef enum { mips_foreach_opcode } mips_insn_opcode_t; #undef _ #define _(f) MIPS_SPECIAL_FUNCT_##f, typedef enum { mips_foreach_special_funct } mips_insn_special_funct_t; #undef _ #define _(f) MIPS_SPECIAL2_FUNCT_##f, typedef enum { mips_foreach_special2_funct } mips_insn_special2_funct_t; #undef _ #define _(f) MIPS_REGIMM_RT_##f, typedef enum { mips_foreach_regimm_rt } mips_insn_regimm_rt_t; #undef _ #define _(f) MIPS_COP0_RS_##f, typedef enum { mips_foreach_cop0_rs } mips_insn_cop0_rs_t; #undef _ #define _(f) MIPS_COP0_FUNCT_##f, typedef enum { mips_foreach_cop0_funct } mips_insn_cop0_funct_t; #undef _ #define _(f) MIPS_COP1_RS_##f, typedef enum { mips_foreach_cop1_rs } mips_insn_cop1_rs_t; #undef _ #define _(f) MIPS_COP1_FUNCT_##f, typedef enum { mips_foreach_cop1_funct } mips_insn_cop1_funct_t; #undef _ #define _(f) MIPS_COP1X_FUNCT_##f, typedef enum { mips_foreach_cop1x_funct } mips_insn_cop1x_funct_t; #undef _ #define _(f) MIPS_MDMX_FUNCT_##f, typedef enum { mips_foreach_mdmx_funct } mips_insn_mdmx_funct_t; #undef _ always_inline mips_insn_opcode_t mips_insn_get_op (u32 insn) { return (insn >> 26) & 0x3f; } always_inline u32 mips_insn_get_rs (u32 insn) { return (insn >> 21) & 0x1f; } always_inline u32 mips_insn_get_rt (u32 insn) { return (insn >> 16) & 0x1f; } always_inline u32 mips_insn_get_rd (u32 insn) { return (insn >> 11) & 0x1f; } always_inline u32 mips_insn_get_sa (u32 insn) { return (insn >> 6) & 0x1f; } always_inline u32 mips_insn_get_funct (u32 insn) { return (insn >> 0) & 0x3f; } always_inline i32 mips_insn_get_immediate (u32 insn) { return (((i32) insn) << 16) >> 16; } always_inline u32 mips_insn_encode_i_type (int op, int rs, int rt, int immediate) { u32 insn; insn = immediate; insn |= rt << 16; insn |= rs << 21; insn |= op << 26; ASSERT (mips_insn_get_immediate (insn) == immediate); ASSERT (mips_insn_get_rt (insn) == rt); ASSERT (mips_insn_get_rs (insn) == rt); ASSERT (mips_insn_get_op (insn) == op); return insn; } always_inline u32 mips_insn_encode_j_type (int op, u32 addr) { u32 insn; insn = (addr & ((1 << 28) - 1)) / 4; insn |= op << 26; return insn; } always_inline u32 mips_insn_encode_r_type (int op, int rs, int rt, int rd, int sa, int funct) { u32 insn; insn = funct; insn |= sa << 6; insn |= rd << 11; insn |= rt << 16; insn |= rs << 21; insn |= op << 26; ASSERT (mips_insn_get_funct (insn) == funct); ASSERT (mips_insn_get_sa (insn) == sa); ASSERT (mips_insn_get_rd (insn) == rd); ASSERT (mips_insn_get_rt (insn) == rt); ASSERT (mips_insn_get_rs (insn) == rt); ASSERT (mips_insn_get_op (insn) == op); return insn; } #define mips_insn_r(op,funct,rd,rs,rt,sa) \ mips_insn_encode_r_type (MIPS_OPCODE_##op, \ (rs), (rt), (rd), (sa), \ MIPS_##op##_FUNCT_##funct) #define mips_insn_i(op,rs,rt,imm) \ mips_insn_encode_i_type (MIPS_OPCODE_##op, (rs), (rt), (imm)) #define mips_insn_j(op,target) \ mips_insn_encode_i_type (MIPS_OPCODE_##op, (rs), (rt), (imm)) /* Generate unsigned load instructions of data of various sizes. */ always_inline u32 mips_insn_load (u32 rd, i32 offset, u32 base, u32 log2_bytes) { int op; ASSERT (log2_bytes < 4); switch (log2_bytes) { case 0: op = MIPS_OPCODE_lbu; break; case 1: op = MIPS_OPCODE_lhu; break; case 2: op = MIPS_OPCODE_lwu; break; case 3: op = MIPS_OPCODE_ld; break; } return mips_insn_encode_i_type (op, base, rd, offset); } typedef enum { MIPS_REG_SP = 29, MIPS_REG_RA = 31, } mips_reg_t; #endif /* included_asm_mips_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */