summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/virtio/pci.h
blob: 70aa9833c2d3ea41dd34c1a230d4245946cf9db4 (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

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #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
/*
 * 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.
 */

#ifndef __included_crc32_h__
#define __included_crc32_h__

#include <vppinfra/clib.h>

#if __SSE4_2__
#define clib_crc32c_uses_intrinsics
#include <x86intrin.h>

#define crc32_u64 _mm_crc32_u64
#define crc32_u32 _mm_crc32_u32

static_always_inline u32
clib_crc32c (u8 * s, int len)
{
  u32 v = 0;

#if __x86_64__
  for (; len >= 8; len -= 8, s += 8)
    v = _mm_crc32_u64 (v, *((u64 *) s));
#else
  /* workaround weird GCC bug when using _mm_crc32_u32
     which happens with -O2 optimization */
#if !defined (__i686__)
  volatile ("":::"memory");
#endif
#endif

  for (; len >= 4; len -= 4, s += 4)
    v = _mm_crc32_u32 (v, *((u32 *) s));

  for (; len >= 2; len -= 2, s += 2)
    v = _mm_crc32_u16 (v, *((u16 *) s));

  for (; len >= 1; len -= 1, s += 1)
    v = _mm_crc32_u8 (v, *((u16 *) s));

  return v;
}

#elif __ARM_FEATURE_CRC32
#define clib_crc32c_uses_intrinsics
#include <arm_acle.h>


#define crc32_u64 __crc32cd
#define crc32_u32 __crc32cw

static_always_inline u32
clib_crc32c (u8 * s, int 
/*
 * Copyright (c) 2018 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 __included_virtio_pci_h__
#define __included_virtio_pci_h__

/* VirtIO ABI version, this must match exactly. */
#define VIRTIO_PCI_ABI_VERSION 0

/* VirtIO device IDs. */
#define VIRTIO_ID_NETWORK  0x01

/*
 * Vector value used to disable MSI for queue.
 * define in include/linux/virtio_pci.h
 */
#define VIRTIO_MSI_NO_VECTOR 0xFFFF

/* The bit of the ISR which indicates a device has an interrupt. */
#define VIRTIO_PCI_ISR_INTR   0x1
/* The bit of the ISR which indicates a device configuration change. */
#define VIRTIO_PCI_ISR_CONFIG 0x2

/* Status byte for guest to report progress. */
#define foreach_virtio_config_status_flags	\
  _ (VIRTIO_CONFIG_STATUS_RESET, 0x00)		\
  _ (VIRTIO_CONFIG_STATUS_ACK, 0x01)		\
  _ (VIRTIO_CONFIG_STATUS_DRIVER, 0x02)		\
  _ (VIRTIO_CONFIG_STATUS_DRIVER_OK, 0x04)	\
  _ (VIRTIO_CONFIG_STATUS_FEATURES_OK, 0x08)	\
  _ (VIRTIO_CONFIG_STATUS_DEVICE_NEEDS_RESET, 0x40) \
  _ (VIRTIO_CONFIG_STATUS_FAILED, 0x80)

typedef enum
{
#define _(a, b) a = b,
  foreach_virtio_config_status_flags
#undef _
} virtio_config_status_flags_t;


#define VIRTIO_NET_S_LINK_UP    1	/* Link is up */
#define VIRTIO_NET_S_ANNOUNCE   2	/* Announcement is needed */

#define VIRTIO_NET_OK     0
#define VIRTIO_NET_ERR    1

/* If multiqueue is provided by host, then we support it. */
#define VIRTIO_NET_CTRL_MQ   4
#define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
#define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1

  
ine VIRTIO_PCI_CAP_NOTIFY_CFG 2 /* ISR Status */ #define VIRTIO_PCI_CAP_ISR_CFG 3 /* Device specific configuration */ #define VIRTIO_PCI_CAP_DEVICE_CFG 4 /* PCI configuration access */ #define VIRTIO_PCI_CAP_PCI_CFG 5 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12 #define VIRTIO_PCI_VRING_ALIGN 4096 typedef enum { VIRTIO_MSIX_NONE = 0, VIRTIO_MSIX_DISABLED = 1, VIRTIO_MSIX_ENABLED = 2 } virtio_msix_status_t; /* This is the PCI capability header: */ typedef struct { u8 cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */ u8 cap_next; /* Generic PCI field: next ptr. */ u8 cap_len; /* Generic PCI field: capability length */ u8 cfg_type; /* Identifies the structure. */ u8 bar; /* Where to find it. */ u8 padding[3]; /* Pad to full dword. */ u32 offset; /* Offset within bar. */ u32 length; /* Length of the structure, in bytes. */ } virtio_pci_cap_t; typedef struct { virtio_pci_cap_t cap; u32 notify_off_multiplier; /* Multiplier for queue_notify_off. */ } virtio_pci_notify_cap_t; /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */ typedef struct { /* About the whole device. */ u32 device_feature_select; /* read-write */ u32 device_feature; /* read-only */ u32 driver_feature_select; /* read-write */ u32 driver_feature; /* read-write */ u16 msix_config; /* read-write */ u16 num_queues; /* read-only */ u8 device_status; /* read-write */ u8 config_generation; /* read-only */ /* About a specific virtqueue. */ u16 queue_select; /* read-write */ u16 queue_size; /* read-write, power of 2. */ u16 queue_msix_vector; /* read-write */ u16 queue_enable; /* read-write */ u16 queue_notify_off; /* read-only */ u64 queue_desc; /* read-write */ u64 queue_driver; /* read-write */ u64 queue_device; /* read-write */ } virtio_pci_common_cfg_t; typedef struct { u8 mac[6]; u16 status; u16 max_virtqueue_pairs; u16 mtu; } virtio_net_config_t; /* * Control virtqueue data structures * * The control virtqueue expects a header in the first sg entry * and an ack/status response in the last entry. Data for the * command goes in between. */ /* *INDENT-OFF* */ typedef CLIB_PACKED (struct { u8 class; u8 cmd; }) virtio_net_ctrl_hdr_t; /* *INDENT-ON* */ typedef u8 virtio_net_ctrl_ack_t; typedef struct { virtio_net_ctrl_hdr_t ctrl; virtio_net_ctrl_ack_t status; u8 data[1024]; } virtio_ctrl_msg_t; typedef struct _virtio_pci_func { void (*read_config) (vlib_main_t * vm, virtio_if_t * vif, void *dst, int len, u32 addr); void (*write_config) (vlib_main_t * vm, virtio_if_t * vif, void *src, int len, u32 addr); u64 (*get_device_features) (vlib_main_t * vm, virtio_if_t * vif); u64 (*get_driver_features) (vlib_main_t * vm, virtio_if_t * vif); void (*set_driver_features) (vlib_main_t * vm, virtio_if_t * vif, u64 features); u8 (*get_status) (vlib_main_t * vm, virtio_if_t * vif); void (*set_status) (vlib_main_t * vm, virtio_if_t * vif, u8 status); u8 (*device_reset) (vlib_main_t * vm, virtio_if_t * vif); u8 (*get_isr) (vlib_main_t * vm, virtio_if_t * vif); u16 (*get_queue_size) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id); void (*set_queue_size) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id, u16 queue_size); u8 (*setup_queue) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id, void *p); void (*del_queue) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id); u16 (*get_queue_notify_off) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id); void (*notify_queue) (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id, u16 queue_notify_offset); u16 (*set_config_irq) (vlib_main_t * vm, virtio_if_t * vif, u16 vec); u16 (*set_queue_irq) (vlib_main_t * vm, virtio_if_t * vif, u16 vec, u16 queue_id); void (*get_mac) (vlib_main_t * vm, virtio_if_t * vif); void (*set_mac) (vlib_main_t * vm, virtio_if_t * vif); u16 (*get_device_status) (vlib_main_t * vm, virtio_if_t * vif); u16 (*get_max_queue_pairs) (vlib_main_t * vm, virtio_if_t * vif); u16 (*get_mtu) (vlib_main_t * vm, virtio_if_t * vif); void (*device_debug_config_space) (vlib_main_t * vm, virtio_if_t * vif); } virtio_pci_func_t; #define foreach_virtio_flags \ _ (GSO, 0) \ _ (CSUM_OFFLOAD, 1) \ _ (GRO_COALESCE, 2) \ _ (PACKED, 3) \ _ (IN_ORDER, 4) \ _ (BUFFERING, 5) typedef enum { #define _(a, b) VIRTIO_FLAG_##a = (1 << b), foreach_virtio_flags #undef _ } virtio_flag_t; typedef struct { u32 addr; /* return */ i32 rv; u32 sw_if_index; u8 mac_addr_set; u8 mac_addr[6]; u64 features; u8 gso_enabled; u8 checksum_offload_enabled; u32 buffering_size; u32 virtio_flags; clib_error_t *error; } virtio_pci_create_if_args_t; extern const virtio_pci_func_t virtio_pci_legacy_func; extern const virtio_pci_func_t virtio_pci_modern_func; extern void device_status (vlib_main_t * vm, virtio_if_t * vif); void virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args); int virtio_pci_delete_if (vlib_main_t * vm, virtio_if_t * ad); int virtio_pci_enable_disable_offloads (vlib_main_t * vm, virtio_if_t * vif, int gso_enabled, int checksum_offload_enabled, int offloads_disabled); #endif /* __included_virtio_pci_h__ */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */