1 /*- 2 * Copyright (c) 2016-2017 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 27 #ifndef _IF_HNREG_H_ 28 #define _IF_HNREG_H_ 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 33 /* 34 * NDIS protocol version numbers 35 */ 36 #define HN_NDIS_VERSION_6_1 0x00060001 37 #define HN_NDIS_VERSION_6_20 0x00060014 38 #define HN_NDIS_VERSION_6_30 0x0006001e 39 #define HN_NDIS_VERSION_MAJOR(ver) (((ver) & 0xffff0000) >> 16) 40 #define HN_NDIS_VERSION_MINOR(ver) ((ver) & 0xffff) 41 42 /* 43 * NVS versions. 44 */ 45 #define HN_NVS_VERSION_1 0x00002 46 #define HN_NVS_VERSION_2 0x30002 47 #define HN_NVS_VERSION_4 0x40000 48 #define HN_NVS_VERSION_5 0x50000 49 #define HN_NVS_VERSION_6 0x60000 50 #define HN_NVS_VERSION_61 0x60001 51 52 #define HN_NVS_RXBUF_SIG 0xcafe 53 #define HN_NVS_CHIM_SIG 0xface 54 55 #define HN_NVS_CHIM_IDX_INVALID 0xffffffff 56 57 #define HN_NVS_RNDIS_MTYPE_DATA 0 58 #define HN_NVS_RNDIS_MTYPE_CTRL 1 59 60 /* 61 * NVS message transaction status codes. 62 */ 63 #define HN_NVS_STATUS_OK 1 64 #define HN_NVS_STATUS_FAILED 2 65 66 /* 67 * NVS request/response message types. 68 */ 69 #define HN_NVS_TYPE_INIT 1 70 #define HN_NVS_TYPE_INIT_RESP 2 71 #define HN_NVS_TYPE_NDIS_INIT 100 72 #define HN_NVS_TYPE_RXBUF_CONN 101 73 #define HN_NVS_TYPE_RXBUF_CONNRESP 102 74 #define HN_NVS_TYPE_RXBUF_DISCONN 103 75 #define HN_NVS_TYPE_CHIM_CONN 104 76 #define HN_NVS_TYPE_CHIM_CONNRESP 105 77 #define HN_NVS_TYPE_CHIM_DISCONN 106 78 #define HN_NVS_TYPE_RNDIS 107 79 #define HN_NVS_TYPE_RNDIS_ACK 108 80 #define HN_NVS_TYPE_NDIS_CONF 125 81 #define HN_NVS_TYPE_VFASSOC_NOTE 128 /* notification */ 82 #define HN_NVS_TYPE_SET_DATAPATH 129 83 #define HN_NVS_TYPE_SUBCH_REQ 133 84 #define HN_NVS_TYPE_SUBCH_RESP 133 /* same as SUBCH_REQ */ 85 #define HN_NVS_TYPE_TXTBL_NOTE 134 /* notification */ 86 87 /* 88 * Any size less than this one will _not_ work, e.g. hn_nvs_init 89 * only has 12B valid data, however, if only 12B data were sent, 90 * Hypervisor would never reply. 91 */ 92 #define HN_NVS_REQSIZE_MIN 32 93 94 /* NVS message common header */ 95 struct hn_nvs_hdr { 96 uint32_t nvs_type; 97 } __packed; 98 99 struct hn_nvs_init { 100 uint32_t nvs_type; /* HN_NVS_TYPE_INIT */ 101 uint32_t nvs_ver_min; 102 uint32_t nvs_ver_max; 103 uint8_t nvs_rsvd[20]; 104 uint8_t nvs_msg_pad[8]; 105 } __packed; 106 CTASSERT(sizeof(struct hn_nvs_init) >= HN_NVS_REQSIZE_MIN); 107 108 struct hn_nvs_init_resp { 109 uint32_t nvs_type; /* HN_NVS_TYPE_INIT_RESP */ 110 uint32_t nvs_ver; /* deprecated */ 111 uint32_t nvs_rsvd; 112 uint32_t nvs_status; /* HN_NVS_STATUS_ */ 113 } __packed; 114 115 /* No reponse */ 116 struct hn_nvs_ndis_conf { 117 uint32_t nvs_type; /* HN_NVS_TYPE_NDIS_CONF */ 118 uint32_t nvs_mtu; 119 uint32_t nvs_rsvd; 120 uint64_t nvs_caps; /* HN_NVS_NDIS_CONF_ */ 121 uint8_t nvs_rsvd1[12]; 122 uint8_t nvs_msg_pad[8]; 123 } __packed; 124 CTASSERT(sizeof(struct hn_nvs_ndis_conf) >= HN_NVS_REQSIZE_MIN); 125 126 #define HN_NVS_NDIS_CONF_SRIOV 0x0004 127 #define HN_NVS_NDIS_CONF_VLAN 0x0008 128 #define HN_NVS_NDIS_CONF_RSC 0x0080 129 130 /* No response */ 131 struct hn_nvs_ndis_init { 132 uint32_t nvs_type; /* HN_NVS_TYPE_NDIS_INIT */ 133 uint32_t nvs_ndis_major; /* NDIS_VERSION_MAJOR_ */ 134 uint32_t nvs_ndis_minor; /* NDIS_VERSION_MINOR_ */ 135 uint8_t nvs_rsvd[20]; 136 uint8_t nvs_msg_pad[8]; 137 } __packed; 138 CTASSERT(sizeof(struct hn_nvs_ndis_init) >= HN_NVS_REQSIZE_MIN); 139 140 #define HN_NVS_DATAPATH_SYNTH 0 141 #define HN_NVS_DATAPATH_VF 1 142 143 struct hn_nvs_vfassoc { 144 uint32_t nvs_type; /* HN_NVS_TYPE_VFASSOC_NOTE */ 145 uint32_t nvs_alloc; 146 uint32_t nvs_serial; 147 } __packed; 148 149 /* Empty VMBus completion, no NVS response. */ 150 struct hn_nvs_datapath { 151 uint32_t nvs_type; /* HN_NVS_TYPE_SET_DATAPATH */ 152 uint32_t nvs_active_path;/* HN_NVS_DATAPATH_* */ 153 uint32_t nvs_rsvd[6]; 154 uint8_t nvs_msg_pad[8]; 155 } __packed; 156 CTASSERT(sizeof(struct hn_nvs_datapath) >= HN_NVS_REQSIZE_MIN); 157 158 struct hn_nvs_rxbuf_conn { 159 uint32_t nvs_type; /* HN_NVS_TYPE_RXBUF_CONN */ 160 uint32_t nvs_gpadl; /* RXBUF vmbus GPADL */ 161 uint16_t nvs_sig; /* HN_NVS_RXBUF_SIG */ 162 uint8_t nvs_rsvd[22]; 163 uint8_t nvs_msg_pad[8]; 164 } __packed; 165 CTASSERT(sizeof(struct hn_nvs_rxbuf_conn) >= HN_NVS_REQSIZE_MIN); 166 167 struct hn_nvs_rxbuf_sect { 168 uint32_t nvs_start; 169 uint32_t nvs_slotsz; 170 uint32_t nvs_slotcnt; 171 uint32_t nvs_end; 172 } __packed; 173 174 struct hn_nvs_rxbuf_connresp { 175 uint32_t nvs_type; /* HN_NVS_TYPE_RXBUF_CONNRESP */ 176 uint32_t nvs_status; /* HN_NVS_STATUS_ */ 177 uint32_t nvs_nsect; /* # of elem in nvs_sect */ 178 struct hn_nvs_rxbuf_sect nvs_sect[]; 179 } __packed; 180 181 /* No response */ 182 struct hn_nvs_rxbuf_disconn { 183 uint32_t nvs_type; /* HN_NVS_TYPE_RXBUF_DISCONN */ 184 uint16_t nvs_sig; /* HN_NVS_RXBUF_SIG */ 185 uint8_t nvs_rsvd[26]; 186 uint8_t nvs_msg_pad[8]; 187 } __packed; 188 CTASSERT(sizeof(struct hn_nvs_rxbuf_disconn) >= HN_NVS_REQSIZE_MIN); 189 190 struct hn_nvs_chim_conn { 191 uint32_t nvs_type; /* HN_NVS_TYPE_CHIM_CONN */ 192 uint32_t nvs_gpadl; /* chimney buf vmbus GPADL */ 193 uint16_t nvs_sig; /* NDIS_NVS_CHIM_SIG */ 194 uint8_t nvs_rsvd[22]; 195 uint8_t nvs_msg_pad[8]; 196 } __packed; 197 CTASSERT(sizeof(struct hn_nvs_chim_conn) >= HN_NVS_REQSIZE_MIN); 198 199 struct hn_nvs_chim_connresp { 200 uint32_t nvs_type; /* HN_NVS_TYPE_CHIM_CONNRESP */ 201 uint32_t nvs_status; /* HN_NVS_STATUS_ */ 202 uint32_t nvs_sectsz; /* section size */ 203 } __packed; 204 205 /* No response */ 206 struct hn_nvs_chim_disconn { 207 uint32_t nvs_type; /* HN_NVS_TYPE_CHIM_DISCONN */ 208 uint16_t nvs_sig; /* HN_NVS_CHIM_SIG */ 209 uint8_t nvs_rsvd[26]; 210 uint8_t nvs_msg_pad[8]; 211 } __packed; 212 CTASSERT(sizeof(struct hn_nvs_chim_disconn) >= HN_NVS_REQSIZE_MIN); 213 214 #define HN_NVS_SUBCH_OP_ALLOC 1 215 216 struct hn_nvs_subch_req { 217 uint32_t nvs_type; /* HN_NVS_TYPE_SUBCH_REQ */ 218 uint32_t nvs_op; /* HN_NVS_SUBCH_OP_ */ 219 uint32_t nvs_nsubch; 220 uint8_t nvs_rsvd[20]; 221 uint8_t nvs_msg_pad[8]; 222 } __packed; 223 CTASSERT(sizeof(struct hn_nvs_subch_req) >= HN_NVS_REQSIZE_MIN); 224 225 struct hn_nvs_subch_resp { 226 uint32_t nvs_type; /* HN_NVS_TYPE_SUBCH_RESP */ 227 uint32_t nvs_status; /* HN_NVS_STATUS_ */ 228 uint32_t nvs_nsubch; 229 } __packed; 230 231 struct hn_nvs_rndis { 232 uint32_t nvs_type; /* HN_NVS_TYPE_RNDIS */ 233 uint32_t nvs_rndis_mtype;/* HN_NVS_RNDIS_MTYPE_ */ 234 /* 235 * Chimney sending buffer index and size. 236 * 237 * NOTE: 238 * If nvs_chim_idx is set to HN_NVS_CHIM_IDX_INVALID 239 * and nvs_chim_sz is set to 0, then chimney sending 240 * buffer is _not_ used by this RNDIS message. 241 */ 242 uint32_t nvs_chim_idx; 243 uint32_t nvs_chim_sz; 244 uint8_t nvs_rsvd[16]; 245 uint8_t nvs_msg_pad[8]; 246 } __packed; 247 CTASSERT(sizeof(struct hn_nvs_rndis) >= HN_NVS_REQSIZE_MIN); 248 249 struct hn_nvs_rndis_ack { 250 uint32_t nvs_type; /* HN_NVS_TYPE_RNDIS_ACK */ 251 uint32_t nvs_status; /* HN_NVS_STATUS_ */ 252 uint8_t nvs_rsvd[24]; 253 uint8_t nvs_msg_pad[8]; 254 } __packed; 255 CTASSERT(sizeof(struct hn_nvs_rndis_ack) >= HN_NVS_REQSIZE_MIN); 256 257 /* 258 * RNDIS extension 259 */ 260 261 /* Per-packet hash info */ 262 #define HN_NDIS_HASH_INFO_SIZE sizeof(uint32_t) 263 #define HN_NDIS_PKTINFO_TYPE_HASHINF NDIS_PKTINFO_TYPE_ORIG_NBLIST 264 /* NDIS_HASH_ */ 265 266 /* Per-packet hash value */ 267 #define HN_NDIS_HASH_VALUE_SIZE sizeof(uint32_t) 268 #define HN_NDIS_PKTINFO_TYPE_HASHVAL NDIS_PKTINFO_TYPE_PKT_CANCELID 269 270 /* Per-packet-info size */ 271 #define HN_RNDIS_PKTINFO_SIZE(dlen) \ 272 __offsetof(struct rndis_pktinfo, rm_data[dlen]) 273 274 #endif /* !_IF_HNREG_H_ */ 275