]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/hyperv/utilities/vmbus_icreg.h
MFC 307845
[FreeBSD/stable/10.git] / sys / dev / hyperv / utilities / vmbus_icreg.h
1 /*-
2  * Copyright (c) 2016 Microsoft Corp.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _VMBUS_ICREG_H_
30 #define _VMBUS_ICREG_H_
31
32 #define VMBUS_ICMSG_TYPE_NEGOTIATE      0
33 #define VMBUS_ICMSG_TYPE_HEARTBEAT      1
34 #define VMBUS_ICMSG_TYPE_KVP            2
35 #define VMBUS_ICMSG_TYPE_SHUTDOWN       3
36 #define VMBUS_ICMSG_TYPE_TIMESYNC       4
37 #define VMBUS_ICMSG_TYPE_VSS            5
38
39 #define VMBUS_ICMSG_STATUS_OK           0x00000000
40 #define VMBUS_ICMSG_STATUS_FAIL         0x80004005
41
42 #define VMBUS_IC_VERSION(major, minor)  ((major) | (((uint32_t)(minor)) << 16))
43 #define VMBUS_ICVER_MAJOR(ver)          ((ver) & 0xffff)
44 #define VMBUS_ICVER_MINOR(ver)          (((ver) & 0xffff0000) >> 16)
45 #define VMBUS_ICVER_SWAP(ver)           \
46         ((VMBUS_ICVER_MAJOR((ver)) << 16) | VMBUS_ICVER_MINOR((ver)))
47 #define VMBUS_ICVER_LE(v1, v2)          \
48         (VMBUS_ICVER_SWAP((v1)) <= VMBUS_ICVER_SWAP((v2)))
49 #define VMBUS_ICVER_GT(v1, v2)          \
50         (VMBUS_ICVER_SWAP((v1)) > VMBUS_ICVER_SWAP((v2)))
51
52 struct vmbus_pipe_hdr {
53         uint32_t                ph_flags;
54         uint32_t                ph_msgsz;
55 } __packed;
56
57 struct vmbus_icmsg_hdr {
58         struct vmbus_pipe_hdr   ic_pipe;
59         uint32_t                ic_fwver;       /* framework version */
60         uint16_t                ic_type;
61         uint32_t                ic_msgver;      /* message version */
62         uint16_t                ic_dsize;       /* data size */
63         uint32_t                ic_status;      /* VMBUS_ICMSG_STATUS_ */
64         uint8_t                 ic_xactid;
65         uint8_t                 ic_flags;       /* VMBUS_ICMSG_FLAG_ */
66         uint8_t                 ic_rsvd[2];
67 } __packed;
68
69 #define VMBUS_ICMSG_FLAG_XACT           0x0001
70 #define VMBUS_ICMSG_FLAG_REQ            0x0002
71 #define VMBUS_ICMSG_FLAG_RESP           0x0004
72
73 /* VMBUS_ICMSG_TYPE_NEGOTIATE */
74 struct vmbus_icmsg_negotiate {
75         struct vmbus_icmsg_hdr  ic_hdr;
76         uint16_t                ic_fwver_cnt;
77         uint16_t                ic_msgver_cnt;
78         uint32_t                ic_rsvd;
79         /*
80          * This version array contains two set of supported
81          * versions:
82          * - The first set consists of #ic_fwver_cnt supported framework
83          *   versions.
84          * - The second set consists of #ic_msgver_cnt supported message
85          *   versions.
86          */
87         uint32_t                ic_ver[];
88 } __packed;
89
90 /* VMBUS_ICMSG_TYPE_HEARTBEAT */
91 struct vmbus_icmsg_heartbeat {
92         struct vmbus_icmsg_hdr  ic_hdr;
93         uint64_t                ic_seq;
94         uint32_t                ic_rsvd[8];
95 } __packed;
96
97 #define VMBUS_ICMSG_HEARTBEAT_SIZE_MIN  \
98         __offsetof(struct vmbus_icmsg_heartbeat, ic_rsvd[0])
99
100 /* VMBUS_ICMSG_TYPE_SHUTDOWN */
101 struct vmbus_icmsg_shutdown {
102         struct vmbus_icmsg_hdr  ic_hdr;
103         uint32_t                ic_code;
104         uint32_t                ic_timeo;
105         uint32_t                ic_haltflags;
106         uint8_t                 ic_msg[2048];
107 } __packed;
108
109 #define VMBUS_ICMSG_SHUTDOWN_SIZE_MIN   \
110         __offsetof(struct vmbus_icmsg_shutdown, ic_msg[0])
111
112 /* VMBUS_ICMSG_TYPE_TIMESYNC */
113 struct vmbus_icmsg_timesync {
114         struct vmbus_icmsg_hdr  ic_hdr;
115         uint64_t                ic_hvtime;
116         uint64_t                ic_vmtime;
117         uint64_t                ic_rtt;
118         uint8_t                 ic_tsflags;     /* VMBUS_ICMSG_TS_FLAG_ */
119 } __packed;
120
121 #define VMBUS_ICMSG_TS_FLAG_SYNC        0x01
122 #define VMBUS_ICMSG_TS_FLAG_SAMPLE      0x02
123
124 /* XXX consolidate w/ hyperv */
125 #define VMBUS_ICMSG_TS_BASE             116444736000000000ULL
126 #define VMBUS_ICMSG_TS_FACTOR           100ULL
127 #ifndef NANOSEC
128 #define NANOSEC                         1000000000ULL
129 #endif
130
131 #endif  /* !_VMBUS_ICREG_H_ */