aboutsummaryrefslogtreecommitdiffstats
path: root/LICENSE
blob: 7a4a3ea2424c09fbe48d455aed1eaa94d9124835 (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
                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   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.
7' href='#n707'>707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
/* SPDX-License-Identifier: Apache-2.0
 * Copyright (c) 2023 Cisco Systems, Inc.
 */

#ifndef _VNET_DEV_H_
#define _VNET_DEV_H_

#include <vppinfra/clib.h>
#include <vppinfra/error_bootstrap.h>
#include <vppinfra/format.h>
#include <vnet/vnet.h>
#include <vnet/dev/types.h>
#include <vnet/dev/args.h>

#define VNET_DEV_DEVICE_ID_PREFIX_DELIMITER "/"

#define foreach_vnet_dev_port_type                                            \
  _ (0, UNKNOWN)                                                              \
  _ (1, ETHERNET)

typedef enum
{
#define _(b, n) VNET_DEV_PORT_TYPE_##n = (1U << (b)),
  foreach_vnet_dev_port_type
#undef _
} vnet_dev_port_type_t;

#define foreach_vnet_dev_port_caps                                            \
  _ (interrupt_mode)                                                          \
  _ (rss)                                                                     \
  _ (change_max_rx_frame_size)                                                \
  _ (mac_filter)                                                              \
  _ (secondary_interfaces)

#define foreach_vnet_dev_port_rx_offloads _ (ip4_cksum)

#define foreach_vnet_dev_port_tx_offloads                                     \
  _ (ip4_cksum)                                                               \
  _ (tcp_gso)                                                                 \
  _ (udp_gso)

typedef union
{
  struct
  {
#define _(n) u8 n : 1;
    foreach_vnet_dev_port_caps
#undef _
  };
  u8 as_number;
} vnet_dev_port_caps_t;

typedef union
{
  struct
  {
#define _(n) u8 n : 1;
    foreach_vnet_dev_port_rx_offloads
#undef _
  };
  u8 as_number;
} vnet_dev_port_rx_offloads_t;

typedef union
{
  struct
  {
#define _(n) u8 n : 1;
    foreach_vnet_dev_port_tx_offloads
#undef _
  };
  u8 as_number;
} vnet_dev_port_tx_offloads_t;

typedef union
{
  u8 eth_mac[6];
  u8 raw[8];
} vnet_dev_hw_addr_t;

typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t;
typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t;

typedef struct vnet_dev vnet_dev_t;
typedef struct vnet_dev_port vnet_dev_port_t;
typedef struct vnet_dev_rx_queue vnet_dev_rx_queue_t;
typedef struct vnet_dev_tx_queue vnet_dev_tx_queue_t;
typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t;
typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t;
typedef struct vnet_dev_counter vnet_dev_counter_t;
typedef struct vnet_dev_counter_main vnet_dev_counter_main_t;
typedef struct vnet_dev_port_cfg_change_req vnet_dev_port_cfg_change_req_t;

typedef vnet_dev_rv_t (vnet_dev_op_t) (vlib_main_t *, vnet_dev_t *);
typedef vnet_dev_rv_t (vnet_dev_port_op_t) (vlib_main_t *, vnet_dev_port_t *);
typedef vnet_dev_rv_t (vnet_dev_port_cfg_change_op_t) (
  vlib_main_t *, vnet_dev_port_t *, vnet_dev_port_cfg_change_req_t *);
typedef vnet_dev_rv_t (vnet_dev_rx_queue_op_t) (vlib_main_t *,
						vnet_dev_rx_queue_t *);
typedef vnet_dev_rv_t (vnet_dev_tx_queue_op_t) (vlib_main_t *,
						vnet_dev_tx_queue_t *);
typedef void (vnet_dev_op_no_rv_t) (vlib_main_t *, vnet_dev_t *);
typedef void (vnet_dev_port_op_no_rv_t) (vlib_main_t *, vnet_dev_port_t *);
typedef void (vnet_dev_rx_queue_op_no_rv_t) (vlib_main_t *,
					     vnet_dev_rx_queue_t *);
typedef void (vnet_dev_tx_queue_op_no_rv_t) (vlib_main_t *,
					     vnet_dev_tx_queue_t *);
typedef vnet_dev_rv_t (vnet_dev_op_with_ptr_t) (vlib_main_t *, vnet_dev_t *,
						void *);
typedef vnet_dev_rv_t (vnet_dev_port_op_with_ptr_t) (vlib_main_t *,
						     vnet_dev_port_t *,
						     void *);

typedef u16 vnet_dev_queue_id_t;
typedef u16 vnet_dev_bus_index_t;
typedef u16 vnet_dev_driver_index_t;

typedef struct
{
  vnet_dev_rx_queue_op_t *alloc;
  vnet_dev_rx_queue_op_t *start;
  vnet_dev_rx_queue_op_no_rv_t *stop;
  vnet_dev_rx_queue_op_no_rv_t *free;
  vnet_dev_rx_queue_op_no_rv_t *clear_counters;
  format_function_t *format_info;
} vnet_dev_rx_queue_ops_t;

typedef struct
{
  vnet_dev_tx_queue_op_t *alloc;
  vnet_dev_tx_queue_op_t *start;
  vnet_dev_tx_queue_op_no_rv_t *stop;
  vnet_dev_tx_queue_op_no_rv_t *free;
  vnet_dev_tx_queue_op_no_rv_t *clear_counters;
  format_function_t *format_info;
} vnet_dev_tx_queue_ops_t;

typedef struct
{
  u16 data_size;
  u16 min_size;
  u16 max_size;
  u16 default_size;
  u8 multiplier;
  u8 size_is_power_of_two : 1;
} vnet_dev_queue_config_t;

#define foreach_vnet_dev_port_cfg_type                                        \
  _ (PROMISC_MODE)                                                            \
  _ (MAX_RX_FRAME_SIZE)                                                       \
  _ (CHANGE_PRIMARY_HW_ADDR)                                                  \
  _ (ADD_SECONDARY_HW_ADDR)                                                   \
  _ (REMOVE_SECONDARY_HW_ADDR)                                                \
  _ (RXQ_INTR_MODE_ENABLE)                                                    \
  _ (RXQ_INTR_MODE_DISABLE)                                                   \
  _ (ADD_RX_FLOW)                                                             \
  _ (DEL_RX_FLOW)                                                             \
  _ (GET_RX_FLOW_COUNTER)                                                     \
  _ (RESET_RX_FLOW_COUNTER)

typedef enum
{
  VNET_DEV_PORT_CFG_UNKNOWN,
#define _(n) VNET_DEV_PORT_CFG_##n,
  foreach_vnet_dev_port_cfg_type
#undef _
} __clib_packed vnet_dev_port_cfg_type_t;

typedef struct vnet_dev_port_cfg_change_req
{
  vnet_dev_port_cfg_type_t type;
  u8 validated : 1;
  u8 all_queues : 1;

  union
  {
    u8 promisc : 1;
    vnet_dev_hw_addr_t addr;
    u16 max_rx_frame_size;
    vnet_dev_queue_id_t queue_id;
    struct
    {
      u32 flow_index;
      uword *private_data;
    };
  };

} vnet_dev_port_cfg_change_req_t;

typedef struct
{
  vnet_dev_hw_addr_t hw_addr;
  u16 max_rx_queues;
  u16 max_tx_queues;
  u16 max_supported_rx_frame_size;
  vnet_dev_port_type_t type;
  vnet_dev_port_caps_t caps;
  vnet_dev_port_rx_offloads_t rx_offloads;
  vnet_dev_port_tx_offloads_t tx_offloads;
} vnet_dev_port_attr_t;

typedef enum
{
  VNET_DEV_PERIODIC_OP_TYPE_DEV = 1,
  VNET_DEV_PERIODIC_OP_TYPE_PORT = 2,
} __clib_packed vnet_dev_periodic_op_type_t;

typedef struct
{
  f64 interval;
  f64 last_run;
  vnet_dev_periodic_op_type_t type;
  union
  {
    vnet_dev_t *dev;
    vnet_dev_port_t *port;
    void *arg;
  };
  union
  {
    vnet_dev_op_no_rv_t *dev_op;
    vnet_dev_port_op_no_rv_t *port_op;
    void *op;
  };
} vnet_dev_periodic_op_t;

typedef struct
{
  struct _vlib_node_fn_registration *registrations;
  format_function_t *format_trace;
  vlib_error_desc_t *error_counters;
  u16 n_error_counters;
} vnet_dev_node_t;

typedef struct
{
  vnet_dev_op_t *alloc;
  vnet_dev_op_t *init;
  vnet_dev_op_no_rv_t *deinit;
  vnet_dev_op_t *reset;
  vnet_dev_op_no_rv_t *free;
  u8 *(*probe) (vlib_main_t *, vnet_dev_bus_index_t, void *);
  format_function_t *format_info;
} vnet_dev_ops_t;

typedef struct
{
  vnet_dev_port_op_t *alloc;
  vnet_dev_port_op_t *init;
  vnet_dev_port_cfg_change_op_t *config_change;
  vnet_dev_port_cfg_change_op_t *config_change_validate;
  vnet_dev_port_op_t *start;
  vnet_dev_port_op_no_rv_t *stop;
  vnet_dev_port_op_no_rv_t *deinit;
  vnet_dev_port_op_no_rv_t *free;
  vnet_dev_port_op_no_rv_t *clear_counters;
  vnet_dev_port_op_with_ptr_t *add_sec_if;
  vnet_dev_port_op_with_ptr_t *del_sec_if;
  format_function_t *format_status;
  format_function_t *format_flow;
} vnet_dev_port_ops_t;

typedef union
{
  struct
  {
    u8 update_next_index : 1;
    u8 update_feature_arc : 1;
    u8 suspend_off : 1;
    u8 suspend_on : 1;
  };
  u8 as_number;
} vnet_dev_rx_queue_rt_req_t;

typedef struct
{
  vlib_buffer_template_t buffer_template;
  u32 sw_if_index;
  u16 next_index;
  u16 sec_if_index;
} vnet_dev_rx_queue_if_rt_data_t;

typedef struct vnet_dev_rx_queue
{
  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
  vnet_dev_port_t *port;
  u16 rx_thread_index;
  u16 index;
  u16 size;
  u8 interrupt_mode : 1;
  u8 enabled : 1;
  u8 started : 1;
  u8 suspended : 1;
  vnet_dev_rx_queue_rt_req_t runtime_request;
  vnet_dev_counter_main_t *counter_main;
  vnet_dev_rx_queue_t *next_on_thread;
  vnet_dev_queue_id_t queue_id;
  vnet_dev_rx_queue_if_rt_data_t **sec_if_rt_data;
  CLIB_CACHE_LINE_ALIGN_MARK (runtime1);
  vnet_dev_rx_queue_if_rt_data_t if_rt_data;
  CLIB_CACHE_LINE_ALIGN_MARK (driver_data);
  u8 data[];
} vnet_dev_rx_queue_t;

#if CLIB_CACHE_LINE_BYTES > 64
STATIC_ASSERT_SIZEOF (vnet_dev_rx_queue_t, 2 * CLIB_CACHE_LINE_BYTES);
#else
STATIC_ASSERT_SIZEOF (vnet_dev_rx_queue_t, 3 * CLIB_CACHE_LINE_BYTES);
#endif

typedef struct vnet_dev_tx_queue
{
  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
  vnet_dev_port_t *port;
  clib_bitmap_t *assigned_threads;
  u16 index;
  vnet_dev_counter_main_t *counter_main;
  CLIB_CACHE_LINE_ALIGN_MARK (runtime0);
  vnet_dev_queue_id_t queue_id;
  u8 started : 1;
  u8 enabled : 1;
  u8 lock_needed : 1;
  u8 lock;
  u16 size;
  CLIB_ALIGN_MARK (private_data, 16);
  u8 data[];
} vnet_dev_tx_queue_t;

STATIC_ASSERT_SIZEOF (vnet_dev_tx_queue_t, 2 * CLIB_CACHE_LINE_BYTES);

typedef struct
{
  vnet_dev_if_name_t name;
  u8 interface_created : 1;
  u8 feature_arc : 1;
  u8 redirect_to_node : 1;
  u8 feature_arc_index;
  u16 rx_next_index;
  u32 index;
  u32 sw_if_index;
  u32 hw_if_index;
  u32 dev_instance;
  u32 tx_node_index;
  u32 next_index;
  u32 current_config_index;
  u16 redirect_to_node_next_index;
  u32 user_data;
  vnet_dev_arg_t *args;
} vnet_dev_port_interface_t;

typedef struct
{
  u32 rx_node_index;
  u8 default_is_intr_mode : 1;
  u16 num_rx_queues;
  u16 num_tx_queues;
  u16 txq_sz;
  u16 rxq_sz;
  vnet_dev_port_interface_t primary_interface;
  vnet_dev_port_interface_t **secondary_interfaces;
} vnet_dev_port_interfaces_t;

typedef struct vnet_dev_port
{
  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
  vnet_dev_t *dev;
  vnet_dev_port_id_t port_id;
  vnet_dev_driver_index_t driver_index;
  u8 initialized : 1;
  u8 started : 1;
  u8 link_up : 1;
  u8 promisc : 1;
  u8 rx_node_assigned : 1;
  vnet_dev_counter_main_t *counter_main;
  vnet_dev_queue_config_t rx_queue_config;
  vnet_dev_queue_config_t tx_queue_config;
  vnet_dev_port_attr_t attr;
  u32 max_rx_frame_size;
  vnet_dev_hw_addr_t primary_hw_addr;
  vnet_dev_hw_addr_t *secondary_hw_addr;
  u32 index;
  u32 speed;
  vnet_dev_rx_queue_t **rx_queues;
  vnet_dev_tx_queue_t **tx_queues;
  vnet_dev_port_ops_t port_ops;
  vnet_dev_arg_t *args;
  vnet_dev_arg_t *sec_if_args;
  vnet_dev_rx_queue_ops_t rx_queue_ops;
  vnet_dev_tx_queue_ops_t tx_queue_ops;
  vnet_dev_node_t rx_node;
  vnet_dev_node_t tx_node;
  vnet_dev_port_interfaces_t *interfaces;

  CLIB_CACHE_LINE_ALIGN_MARK (data0);
  u8 data[];
} vnet_dev_port_t;

typedef struct vnet_dev
{
  vnet_dev_device_id_t device_id;
  u16 initialized : 1;
  u16 not_first_init : 1;
  u16 va_dma : 1;
  u16 process_node_quit : 1;
  u16 process_node_periodic : 1;
  u16 poll_stats : 1;
  u16 bus_index;
  u8 numa_node;
  u16 max_rx_queues;
  u16 max_tx_queues;
  vnet_dev_driver_index_t driver_index;
  u32 index;
  u32 process_node_index;
  u8 bus_data[32] __clib_aligned (16);
  vnet_dev_ops_t ops;
  vnet_dev_port_t **ports;
  vnet_dev_periodic_op_t *periodic_ops;
  u8 *description;
  vnet_dev_arg_t *args;
  u8 __clib_aligned (16)
  data[];
} vnet_dev_t;

typedef struct
{
  u16 vendor_id, device_id;
  char *description;
} vnet_dev_match_t;

#define VNET_DEV_MATCH(...)                                                   \
  (vnet_dev_match_t[])                                                        \
  {                                                                           \
    __VA_ARGS__, {}                                                           \
  }

typedef struct
{
  vnet_dev_op_t *device_open;
  vnet_dev_op_no_rv_t *device_close;
  vnet_dev_rv_t (*dma_mem_alloc_fn) (vlib_main_t *, vnet_dev_t *, u32, u32,
				     void **);
  void (*dma_mem_free_fn) (vlib_main_t *, vnet_dev_t *, void *);
  void *(*get_device_info) (vlib_main_t *, char *);
  void (*free_device_info) (vlib_main_t *, void *);
  format_function_t *format_device_info;
  format_function_t *format_device_addr;
} vnet_dev_bus_ops_t;

struct vnet_dev_bus_registration
{
  vnet_dev_bus_registration_t *next_registration;
  vnet_dev_driver_name_t name;
  u16 device_data_size;
  vnet_dev_bus_ops_t ops;
};

struct vnet_dev_driver_registration
{
  vnet_dev_driver_registration_t *next_registration;
  u8 bus_master_enable : 1;
  vnet_dev_driver_name_t name;
  vnet_dev_bus_name_t bus;
  u16 device_data_sz;
  u16 runtime_temp_space_sz;
  vnet_dev_match_t *match;
  int priority;
  vnet_dev_ops_t ops;
  vnet_dev_arg_t *args;
};

typedef struct
{
  u32 index;
  vnet_dev_bus_registration_t *registration;
  vnet_dev_bus_ops_t ops;
} vnet_dev_bus_t;

typedef struct
{
  u32 index;
  void *dev_data;
  vnet_dev_driver_registration_t *registration;
  u32 dev_class_index;
  vnet_dev_bus_index_t bus_index;
  vnet_dev_ops_t ops;
} vnet_dev_driver_t;

typedef struct
{
  vnet_dev_port_t *port;
  u32 sec_if_index;
  u8 is_primary_if : 1;
} vnet_dev_instance_t;

typedef struct
{
  vnet_dev_bus_t *buses;
  vnet_dev_driver_t *drivers;
  vnet_dev_t **devices;
  vnet_dev_instance_t *dev_instances;
  vnet_dev_bus_registration_t *bus_registrations;
  vnet_dev_driver_registration_t *driver_registrations;
  void *runtime_temp_spaces;
  u32 log2_runtime_temp_space_sz;
  u32 *free_process_node_indices;
  u32 *free_rx_node_indices;
  uword *device_index_by_id;

  u8 *startup_config;
  u16 next_rx_queue_thread;
  u8 eth_port_rx_feature_arc_index;
} vnet_dev_main_t;

extern vnet_dev_main_t vnet_dev_main;

typedef struct
{
  struct
  {
    vnet_dev_port_attr_t attr;
    vnet_dev_port_ops_t ops;
    vnet_dev_arg_t *args;
    vnet_dev_arg_t *sec_if_args;
    u16 data_size;
    void *initial_data;
  } port;

  vnet_dev_node_t *rx_node;
  vnet_dev_node_t *tx_node;

  struct
  {
    vnet_dev_queue_config_t config;
    vnet_dev_rx_queue_ops_t ops;
  } rx_queue;

  struct
  {
    vnet_dev_queue_config_t config;
    vnet_dev_tx_queue_ops_t ops;
  } tx_queue;
} vnet_dev_port_add_args_t;

typedef struct
{
  union
  {
    struct
    {
      u8 link_speed : 1;
      u8 link_state : 1;
      u8 link_duplex : 1;
    };
    u8 any;
  } change;
  u8 link_state : 1;
  u8 full_duplex : 1;
  u32 link_speed;
} vnet_dev_port_state_changes_t;

/* args.c */
vnet_dev_rv_t vnet_dev_arg_parse (vlib_main_t *, vnet_dev_t *,
				  vnet_dev_arg_t *, u8 *);
void vnet_dev_arg_free (vnet_dev_arg_t **);
void vnet_dev_arg_clear_value (vnet_dev_arg_t *);
format_function_t format_vnet_dev_arg_type;
format_function_t format_vnet_dev_arg_value;
format_function_t format_vnet_dev_args;

/* dev.c */
vnet_dev_t *vnet_dev_alloc (vlib_main_t *, vnet_dev_device_id_t,
			    vnet_dev_driver_t *);
vnet_dev_op_no_rv_t vnet_dev_free;
vnet_dev_op_t vnet_dev_init;
vnet_dev_op_no_rv_t vnet_dev_deinit;
vnet_dev_op_t vnet_dev_reset;
vnet_dev_op_no_rv_t vnet_dev_detach;
vnet_dev_rv_t vnet_dev_port_add (vlib_main_t *, vnet_dev_t *,
				 vnet_dev_port_id_t,
				 vnet_dev_port_add_args_t *);
vnet_dev_rv_t vnet_dev_dma_mem_alloc (vlib_main_t *, vnet_dev_t *, u32, u32,
				      void **);
void vnet_dev_dma_mem_free (vlib_main_t *, vnet_dev_t *, void *);
vnet_dev_bus_t *vnet_dev_find_device_bus (vlib_main_t *, vnet_dev_device_id_t);
void *vnet_dev_get_device_info (vlib_main_t *, vnet_dev_device_id_t);

/* error.c */
clib_error_t *vnet_dev_port_err (vlib_main_t *, vnet_dev_port_t *,
				 vnet_dev_rv_t, char *, ...);
int vnet_dev_flow_err (vlib_main_t *, vnet_dev_rv_t);

/* handlers.c */
clib_error_t *vnet_dev_port_set_max_frame_size (vnet_main_t *,
						vnet_hw_interface_t *, u32);
u32 vnet_dev_port_eth_flag_change (vnet_main_t *, vnet_hw_interface_t *, u32);
clib_error_t *vnet_dev_port_mac_change (vnet_hw_interface_t *, const u8 *,
					const u8 *);
clib_error_t *vnet_dev_add_del_mac_address (vnet_hw_interface_t *, const u8 *,
					    u8);
int vnet_dev_flow_ops_fn (vnet_main_t *, vnet_flow_dev_op_t, u32, u32,
			  uword *);
clib_error_t *vnet_dev_interface_set_rss_queues (vnet_main_t *,
						 vnet_hw_interface_t *,
						 clib_bitmap_t *);
void vnet_dev_clear_hw_interface_counters (u32);
void vnet_dev_set_interface_next_node (vnet_main_t *, u32, u32);

/* port.c */

typedef struct
{
  vnet_dev_if_name_t name;
  u16 num_rx_queues;
  u16 num_tx_queues;
  u16 rxq_sz;
  u16 txq_sz;
  u8 default_is_intr_mode : 1;
  u8 consistent_qp : 1;

  /* return */
  u32 sw_if_index;
} vnet_dev_port_if_create_args_t;

typedef struct
{
  vnet_dev_if_name_t name;
  u8 *args;

  /* return */
  u32 sw_if_index;
} vnet_dev_port_sec_if_create_args_t;

typedef struct
{
  u32 sw_if_index;
} vnet_dev_port_del_sec_if_args_t;

vnet_dev_port_op_t vnet_dev_port_start;
vnet_dev_port_op_t vnet_dev_port_start_all_rx_queues;
vnet_dev_port_op_t vnet_dev_port_start_all_tx_queues;
vnet_dev_port_op_no_rv_t vnet_dev_port_stop;
vnet_dev_port_op_no_rv_t vnet_dev_port_deinit;
vnet_dev_port_op_no_rv_t vnet_dev_port_free;
vnet_dev_port_op_with_ptr_t vnet_dev_port_add_sec_if;
vnet_dev_port_op_with_ptr_t vnet_dev_port_del_sec_if;

void vnet_dev_port_add_counters (vlib_main_t *, vnet_dev_port_t *,
				 vnet_dev_counter_t *, u16);
vnet_dev_port_op_no_rv_t vnet_dev_port_free_counters;
vnet_dev_port_op_no_rv_t vnet_dev_port_update_tx_node_runtime;
void vnet_dev_port_state_change (vlib_main_t *, vnet_dev_port_t *,
				 vnet_dev_port_state_changes_t);
vnet_dev_port_op_no_rv_t vnet_dev_port_clear_counters;
vnet_dev_rv_t
vnet_dev_port_cfg_change_req_validate (vlib_main_t *, vnet_dev_port_t *,
				       vnet_dev_port_cfg_change_req_t *);
vnet_dev_rv_t vnet_dev_port_cfg_change (vlib_main_t *, vnet_dev_port_t *,
					vnet_dev_port_cfg_change_req_t *);
vnet_dev_port_op_with_ptr_t vnet_dev_port_if_create;
vnet_dev_port_op_t vnet_dev_port_if_remove;

/* queue.c */
vnet_dev_rv_t vnet_dev_rx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16);
vnet_dev_rv_t vnet_dev_tx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16);
vnet_dev_rx_queue_op_no_rv_t vnet_dev_rx_queue_free;
vnet_dev_tx_queue_op_no_rv_t vnet_dev_tx_queue_free;
void vnet_dev_rx_queue_add_counters (vlib_main_t *, vnet_dev_rx_queue_t *,
				     vnet_dev_counter_t *, u16);
vnet_dev_rx_queue_op_no_rv_t vnet_dev_rx_queue_free_counters;
void vnet_dev_tx_queue_add_counters (vlib_main_t *, vnet_dev_tx_queue_t *,
				     vnet_dev_counter_t *, u16);
vnet_dev_tx_queue_op_no_rv_t vnet_dev_tx_queue_free_counters;
vnet_dev_rx_queue_op_t vnet_dev_rx_queue_start;
vnet_dev_tx_queue_op_t vnet_dev_tx_queue_start;
vnet_dev_rx_queue_op_no_rv_t vnet_dev_rx_queue_stop;
vnet_dev_tx_queue_op_no_rv_t vnet_dev_tx_queue_stop;

/* process.c */
vnet_dev_op_t vnet_dev_process_create;
vnet_dev_rv_t vnet_dev_process_call_op (vlib_main_t *, vnet_dev_t *,
					vnet_dev_op_t *);
vnet_dev_rv_t vnet_dev_process_call_op_no_rv (vlib_main_t *, vnet_dev_t *,
					      vnet_dev_op_no_rv_t *);
vnet_dev_rv_t vnet_dev_process_call_op_with_ptr (vlib_main_t *, vnet_dev_t *,
						 vnet_dev_op_with_ptr_t *,
						 void *);
void vnet_dev_process_call_op_no_wait (vlib_main_t *, vnet_dev_t *,
				       vnet_dev_op_no_rv_t *);
vnet_dev_rv_t vnet_dev_process_call_port_op (vlib_main_t *, vnet_dev_port_t *,
					     vnet_dev_port_op_t *);
vnet_dev_rv_t vnet_dev_process_call_port_op_no_rv (vlib_main_t *vm,
						   vnet_dev_port_t *,
						   vnet_dev_port_op_no_rv_t *);
vnet_dev_rv_t
vnet_dev_process_call_port_op_with_ptr (vlib_main_t *, vnet_dev_port_t *,
					vnet_dev_port_op_with_ptr_t *, void *);
void vnet_dev_process_call_port_op_no_wait (vlib_main_t *, vnet_dev_port_t *,
					    vnet_dev_port_op_no_rv_t *);
vnet_dev_rv_t
vnet_dev_process_port_cfg_change_req (vlib_main_t *, vnet_dev_port_t *,
				      vnet_dev_port_cfg_change_req_t *);
vnet_dev_op_no_rv_t vnet_dev_process_quit;
void vnet_dev_poll_dev_add (vlib_main_t *, vnet_dev_t *, f64,
			    vnet_dev_op_no_rv_t *);
void vnet_dev_poll_dev_remove (vlib_main_t *, vnet_dev_t *,
			       vnet_dev_op_no_rv_t *);
void vnet_dev_poll_port_add (vlib_main_t *, vnet_dev_port_t *, f64,
			     vnet_dev_port_op_no_rv_t *);
void vnet_dev_poll_port_remove (vlib_main_t *, vnet_dev_port_t *,
				vnet_dev_port_op_no_rv_t *);

typedef struct
{
  u16 thread_index;
  u8 completed;
  u8 in_order;
  vnet_dev_port_t *port;
} vnet_dev_rt_op_t;

vnet_dev_rv_t vnet_dev_rt_exec_ops (vlib_main_t *, vnet_dev_t *,
				    vnet_dev_rt_op_t *, u32);

/* format.c */
typedef struct
{
  u8 counters : 1;
  u8 show_zero_counters : 1;
  u8 debug : 1;
} vnet_dev_format_args_t;

format_function_t format_vnet_dev_addr;
format_function_t format_vnet_dev_flags;
format_function_t format_vnet_dev_hw_addr;
format_function_t format_vnet_dev_info;
format_function_t format_vnet_dev_interface_info;
format_function_t format_vnet_dev_interface_name;
format_function_t format_vnet_dev_log;
format_function_t format_vnet_dev_port_caps;
format_function_t format_vnet_dev_port_flags;
format_function_t format_vnet_dev_port_info;
format_function_t format_vnet_dev_port_rx_offloads;
format_function_t format_vnet_dev_port_tx_offloads;
format_function_t format_vnet_dev_rv;
format_function_t format_vnet_dev_rx_queue_info;
format_function_t format_vnet_dev_tx_queue_info;
format_function_t format_vnet_dev_flow;
unformat_function_t unformat_vnet_dev_flags;
unformat_function_t unformat_vnet_dev_port_flags;

typedef struct
{
  vnet_dev_rx_queue_t *first_rx_queue;
} vnet_dev_rx_node_runtime_t;

STATIC_ASSERT (sizeof (vnet_dev_rx_node_runtime_t) <=
		 VLIB_NODE_RUNTIME_DATA_SIZE,
	       "must fit into runtime data");

#define foreach_vnet_dev_port_rx_next                                         \
  _ (ETH_INPUT, "ethernet-input")                                             \
  _ (DROP, "error-drop")

typedef enum
{
#define _(n, s) VNET_DEV_ETH_RX_PORT_NEXT_##n,
  foreach_vnet_dev_port_rx_next
#undef _
    VNET_DEV_ETH_RX_PORT_N_NEXTS
} vnet_dev_eth_port_rx_next_t;

extern u16 vnet_dev_default_next_index_by_port_type[];
extern vlib_node_registration_t port_rx_eth_node;

typedef vnet_interface_output_runtime_t vnet_dev_tx_node_runtime_t;

STATIC_ASSERT (sizeof (vnet_dev_tx_node_runtime_t) <=
		 VLIB_NODE_RUNTIME_DATA_SIZE,
	       "must fit into runtime data");

#define VNET_DEV_REGISTER_BUS(x, ...)                                         \
  __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x;    \
  static void __clib_constructor __vnet_dev_bus_registration_fn_##x (void)    \
  {                                                                           \
    vnet_dev_main_t *dm = &vnet_dev_main;                                     \
    __vnet_dev_bus_registration_##x.next_registration =                       \
      dm->bus_registrations;                                                  \
    dm->bus_registrations = &__vnet_dev_bus_registration_##x;                 \
  }                                                                           \
  __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x

#define VNET_DEV_REGISTER_DRIVER(x, ...)                                      \
  __VA_ARGS__ vnet_dev_driver_registration_t                                  \
    __vnet_dev_driver_registration_##x;                                       \
  static void __clib_constructor __vnet_dev_driver_registration_fn_##x (void) \
  {                                                                           \
    vnet_dev_main_t *dm = &vnet_dev_main;                                     \
    __vnet_dev_driver_registration_##x.next_registration =                    \
      dm->driver_registrations;                                               \
    dm->driver_registrations = &__vnet_dev_driver_registration_##x;           \
  }                                                                           \
  __VA_ARGS__ vnet_dev_driver_registration_t __vnet_dev_driver_registration_##x

#define VNET_DEV_NODE_FN(node)                                                \
  uword CLIB_MARCH_SFX (node##_fn) (vlib_main_t *, vlib_node_runtime_t *,     \
				    vlib_frame_t *);                          \
  static vlib_node_fn_registration_t CLIB_MARCH_SFX (                         \
    node##_fn_registration) = {                                               \
    .function = &CLIB_MARCH_SFX (node##_fn),                                  \
  };                                                                          \
                                                                              \
  static void __clib_constructor CLIB_MARCH_SFX (                             \
    node##_fn_multiarch_register) (void)                                      \
  {                                                                           \
    extern vnet_dev_node_t node;                                              \
    vlib_node_fn_registration_t *r;                                           \
    r = &CLIB_MARCH_SFX (node##_fn_registration);                             \
    r->march_variant = CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE);              \
    r->next_registration = (node).registrations;                              \
    (node).registrations = r;                                                 \
  }                                                                           \
  uword CLIB_MARCH_SFX (node##_fn)

#define foreach_vnet_dev_port(p, d) pool_foreach_pointer (p, d->ports)
#define foreach_vnet_dev_port_rx_queue(q, p)                                  \
  pool_foreach_pointer (q, p->rx_queues)
#define foreach_vnet_dev_port_tx_queue(q, p)                                  \
  pool_foreach_pointer (q, p->tx_queues)

#include <vnet/dev/dev_funcs.h>

#endif /* _VNET_DEV_H_ */