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 _NET_NDIS_H_ 28#define _NET_NDIS_H_ 29 30#define NDIS_MEDIA_STATE_CONNECTED 0 31#define NDIS_MEDIA_STATE_DISCONNECTED 1 32 33#define NDIS_NETCHANGE_TYPE_POSSIBLE 1 34#define NDIS_NETCHANGE_TYPE_DEFINITE 2 35#define NDIS_NETCHANGE_TYPE_FROMMEDIA 3 36 37#define NDIS_OFFLOAD_SET_NOCHG 0 38#define NDIS_OFFLOAD_SET_ON 1 39#define NDIS_OFFLOAD_SET_OFF 2 40 41/* a.k.a GRE MAC */ 42#define NDIS_ENCAP_TYPE_NVGRE 0x00000001 43 44#define NDIS_HASH_FUNCTION_MASK 0x000000FF /* see hash function */ 45#define NDIS_HASH_TYPE_MASK 0x00FFFF00 /* see hash type */ 46 47/* hash function */ 48#define NDIS_HASH_FUNCTION_TOEPLITZ 0x00000001 49 50/* hash type */ 51#define NDIS_HASH_IPV4 0x00000100 52#define NDIS_HASH_TCP_IPV4 0x00000200 53#define NDIS_HASH_IPV6 0x00000400 54#define NDIS_HASH_IPV6_EX 0x00000800 55#define NDIS_HASH_TCP_IPV6 0x00001000 56#define NDIS_HASH_TCP_IPV6_EX 0x00002000 57#define NDIS_HASH_UDP_IPV4_X 0x00004000 /* XXX non-standard */ 58 59#define NDIS_HASH_ALL (NDIS_HASH_IPV4 | \ 60 NDIS_HASH_TCP_IPV4 | \ 61 NDIS_HASH_IPV6 | \ 62 NDIS_HASH_IPV6_EX | \ 63 NDIS_HASH_TCP_IPV6 | \ 64 NDIS_HASH_TCP_IPV6_EX |\ 65 NDIS_HASH_UDP_IPV4_X) 66 67#define NDIS_HASH_STD (NDIS_HASH_IPV4 | \ 68 NDIS_HASH_TCP_IPV4 | \ 69 NDIS_HASH_IPV6 | \ 70 NDIS_HASH_IPV6_EX | \ 71 NDIS_HASH_TCP_IPV6 | \ 72 NDIS_HASH_TCP_IPV6_EX) 73 74/* Hash description for use with printf(9) %b identifier. */ 75#define NDIS_HASH_BITS \ 76 "\20\1TOEPLITZ\11IP4\12TCP4\13IP6\14IP6EX\15TCP6\16TCP6EX\17UDP4_X" 77 78#define NDIS_HASH_KEYSIZE_TOEPLITZ 40 79#define NDIS_HASH_INDCNT 128 80 81#define NDIS_OBJTYPE_DEFAULT 0x80 82#define NDIS_OBJTYPE_RSS_CAPS 0x88 83#define NDIS_OBJTYPE_RSS_PARAMS 0x89 84#define NDIS_OBJTYPE_OFFLOAD 0xa7 85 86struct ndis_object_hdr { 87 uint8_t ndis_type; /* NDIS_OBJTYPE_ */ 88 uint8_t ndis_rev; /* type specific */ 89 uint16_t ndis_size; /* incl. this hdr */ 90}; 91 92/* 93 * OID_TCP_OFFLOAD_PARAMETERS 94 * ndis_type: NDIS_OBJTYPE_DEFAULT 95 */ 96struct ndis_offload_params { 97 struct ndis_object_hdr ndis_hdr; 98 uint8_t ndis_ip4csum; /* NDIS_OFFLOAD_PARAM_ */ 99 uint8_t ndis_tcp4csum; /* NDIS_OFFLOAD_PARAM_ */ 100 uint8_t ndis_udp4csum; /* NDIS_OFFLOAD_PARAM_ */ 101 uint8_t ndis_tcp6csum; /* NDIS_OFFLOAD_PARAM_ */ 102 uint8_t ndis_udp6csum; /* NDIS_OFFLOAD_PARAM_ */ 103 uint8_t ndis_lsov1; /* NDIS_OFFLOAD_PARAM_ */ 104 uint8_t ndis_ipsecv1; /* NDIS_OFFLOAD_IPSECV1_ */ 105 uint8_t ndis_lsov2_ip4; /* NDIS_OFFLOAD_LSOV2_ */ 106 uint8_t ndis_lsov2_ip6; /* NDIS_OFFLOAD_LSOV2_ */ 107 uint8_t ndis_tcp4conn; /* 0 */ 108 uint8_t ndis_tcp6conn; /* 0 */ 109 uint32_t ndis_flags; /* 0 */ 110 /* NDIS >= 6.1 */ 111 uint8_t ndis_ipsecv2; /* NDIS_OFFLOAD_IPSECV2_ */ 112 uint8_t ndis_ipsecv2_ip4;/* NDIS_OFFLOAD_IPSECV2_ */ 113 /* NDIS >= 6.30 */ 114 uint8_t ndis_rsc_ip4; /* NDIS_OFFLOAD_RSC_ */ 115 uint8_t ndis_rsc_ip6; /* NDIS_OFFLOAD_RSC_ */ 116 uint8_t ndis_encap; /* NDIS_OFFLOAD_SET_ */ 117 uint8_t ndis_encap_types;/* NDIS_ENCAP_TYPE_ */ 118}; 119 120#define NDIS_OFFLOAD_PARAMS_SIZE sizeof(struct ndis_offload_params) 121#define NDIS_OFFLOAD_PARAMS_SIZE_6_1 \ 122 __offsetof(struct ndis_offload_params, ndis_rsc_ip4) 123 124#define NDIS_OFFLOAD_PARAMS_REV_2 2 /* NDIS 6.1 */ 125#define NDIS_OFFLOAD_PARAMS_REV_3 3 /* NDIS 6.30 */ 126 127#define NDIS_OFFLOAD_PARAM_NOCHG 0 /* common */ 128#define NDIS_OFFLOAD_PARAM_OFF 1 129#define NDIS_OFFLOAD_PARAM_TX 2 130#define NDIS_OFFLOAD_PARAM_RX 3 131#define NDIS_OFFLOAD_PARAM_TXRX 4 132 133/* NDIS_OFFLOAD_PARAM_NOCHG */ 134#define NDIS_OFFLOAD_LSOV1_OFF 1 135#define NDIS_OFFLOAD_LSOV1_ON 2 136 137/* NDIS_OFFLOAD_PARAM_NOCHG */ 138#define NDIS_OFFLOAD_IPSECV1_OFF 1 139#define NDIS_OFFLOAD_IPSECV1_AH 2 140#define NDIS_OFFLOAD_IPSECV1_ESP 3 141#define NDIS_OFFLOAD_IPSECV1_AH_ESP 4 142 143/* NDIS_OFFLOAD_PARAM_NOCHG */ 144#define NDIS_OFFLOAD_LSOV2_OFF 1 145#define NDIS_OFFLOAD_LSOV2_ON 2 146 147/* NDIS_OFFLOAD_PARAM_NOCHG */ 148#define NDIS_OFFLOAD_IPSECV2_OFF 1 149#define NDIS_OFFLOAD_IPSECV2_AH 2 150#define NDIS_OFFLOAD_IPSECV2_ESP 3 151#define NDIS_OFFLOAD_IPSECV2_AH_ESP 4 152 153/* NDIS_OFFLOAD_PARAM_NOCHG */ 154#define NDIS_OFFLOAD_RSC_OFF 1 155#define NDIS_OFFLOAD_RSC_ON 2 156 157/* 158 * OID_GEN_RECEIVE_SCALE_CAPABILITIES 159 * ndis_type: NDIS_OBJTYPE_RSS_CAPS 160 */ 161struct ndis_rss_caps { 162 struct ndis_object_hdr ndis_hdr; 163 uint32_t ndis_caps; /* NDIS_RSS_CAP_ */ 164 uint32_t ndis_nmsi; /* # of MSIs */ 165 uint32_t ndis_nrxr; /* # of RX rings */ 166 /* NDIS >= 6.30 */ 167 uint16_t ndis_nind; /* # of indtbl ent. */ 168 uint16_t ndis_pad; 169}; 170 171#define NDIS_RSS_CAPS_SIZE \ 172 __offsetof(struct ndis_rss_caps, ndis_pad) 173#define NDIS_RSS_CAPS_SIZE_6_0 \ 174 __offsetof(struct ndis_rss_caps, ndis_nind) 175 176#define NDIS_RSS_CAPS_REV_1 1 /* NDIS 6.{0,1,20} */ 177#define NDIS_RSS_CAPS_REV_2 2 /* NDIS 6.30 */ 178 179#define NDIS_RSS_CAP_MSI 0x01000000 180#define NDIS_RSS_CAP_CLASSIFY_ISR 0x02000000 181#define NDIS_RSS_CAP_CLASSIFY_DPC 0x04000000 182#define NDIS_RSS_CAP_MSIX 0x08000000 183#define NDIS_RSS_CAP_IPV4 0x00000100 184#define NDIS_RSS_CAP_IPV6 0x00000200 185#define NDIS_RSS_CAP_IPV6_EX 0x00000400 186#define NDIS_RSS_CAP_HASH_TOEPLITZ NDIS_HASH_FUNCTION_TOEPLITZ 187#define NDIS_RSS_CAP_HASHFUNC_MASK NDIS_HASH_FUNCTION_MASK 188 189/* 190 * OID_GEN_RECEIVE_SCALE_PARAMETERS 191 * ndis_type: NDIS_OBJTYPE_RSS_PARAMS 192 */ 193struct ndis_rss_params { 194 struct ndis_object_hdr ndis_hdr; 195 uint16_t ndis_flags; /* NDIS_RSS_FLAG_ */ 196 uint16_t ndis_bcpu; /* base cpu 0 */ 197 uint32_t ndis_hash; /* NDIS_HASH_ */ 198 uint16_t ndis_indsize; /* indirect table */ 199 uint32_t ndis_indoffset; 200 uint16_t ndis_keysize; /* hash key */ 201 uint32_t ndis_keyoffset; 202 /* NDIS >= 6.20 */ 203 uint32_t ndis_cpumaskoffset; 204 uint32_t ndis_cpumaskcnt; 205 uint32_t ndis_cpumaskentsz; 206}; 207 208#define NDIS_RSS_PARAMS_SIZE sizeof(struct ndis_rss_params) 209#define NDIS_RSS_PARAMS_SIZE_6_0 \ 210 __offsetof(struct ndis_rss_params, ndis_cpumaskoffset) 211 212#define NDIS_RSS_PARAMS_REV_1 1 /* NDIS 6.0 */ 213#define NDIS_RSS_PARAMS_REV_2 2 /* NDIS 6.20 */ 214 215#define NDIS_RSS_FLAG_NONE 0x0000 216#define NDIS_RSS_FLAG_BCPU_UNCHG 0x0001 217#define NDIS_RSS_FLAG_HASH_UNCHG 0x0002 218#define NDIS_RSS_FLAG_IND_UNCHG 0x0004 219#define NDIS_RSS_FLAG_KEY_UNCHG 0x0008 220#define NDIS_RSS_FLAG_DISABLE 0x0010 221 222/* non-standard convenient struct */ 223struct ndis_rssprm_toeplitz { 224 struct ndis_rss_params rss_params; 225 /* Toeplitz hash key */ 226 uint8_t rss_key[NDIS_HASH_KEYSIZE_TOEPLITZ]; 227 /* Indirect table */ 228 uint32_t rss_ind[NDIS_HASH_INDCNT]; 229}; 230 231#define NDIS_RSSPRM_TOEPLITZ_SIZE(nind) \ 232 __offsetof(struct ndis_rssprm_toeplitz, rss_ind[nind]) 233 234/* 235 * OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES 236 * ndis_type: NDIS_OBJTYPE_OFFLOAD 237 */ 238 239#define NDIS_OFFLOAD_ENCAP_NONE 0x0000 240#define NDIS_OFFLOAD_ENCAP_NULL 0x0001 241#define NDIS_OFFLOAD_ENCAP_8023 0x0002 242#define NDIS_OFFLOAD_ENCAP_8023PQ 0x0004 243#define NDIS_OFFLOAD_ENCAP_8023PQ_OOB 0x0008 244#define NDIS_OFFLOAD_ENCAP_RFC1483 0x0010 245 246struct ndis_csum_offload { 247 uint32_t ndis_ip4_txenc; /*NDIS_OFFLOAD_ENCAP_*/ 248 uint32_t ndis_ip4_txcsum; 249#define NDIS_TXCSUM_CAP_IP4OPT 0x001 250#define NDIS_TXCSUM_CAP_TCP4OPT 0x004 251#define NDIS_TXCSUM_CAP_TCP4 0x010 252#define NDIS_TXCSUM_CAP_UDP4 0x040 253#define NDIS_TXCSUM_CAP_IP4 0x100 254 uint32_t ndis_ip4_rxenc; /*NDIS_OFFLOAD_ENCAP_*/ 255 uint32_t ndis_ip4_rxcsum; 256#define NDIS_RXCSUM_CAP_IP4OPT 0x001 257#define NDIS_RXCSUM_CAP_TCP4OPT 0x004 258#define NDIS_RXCSUM_CAP_TCP4 0x010 259#define NDIS_RXCSUM_CAP_UDP4 0x040 260#define NDIS_RXCSUM_CAP_IP4 0x100 261 uint32_t ndis_ip6_txenc; /*NDIS_OFFLOAD_ENCAP_*/ 262 uint32_t ndis_ip6_txcsum; 263#define NDIS_TXCSUM_CAP_IP6EXT 0x001 264#define NDIS_TXCSUM_CAP_TCP6OPT 0x004 265#define NDIS_TXCSUM_CAP_TCP6 0x010 266#define NDIS_TXCSUM_CAP_UDP6 0x040 267 uint32_t ndis_ip6_rxenc; /*NDIS_OFFLOAD_ENCAP_*/ 268 uint32_t ndis_ip6_rxcsum; 269#define NDIS_RXCSUM_CAP_IP6EXT 0x001 270#define NDIS_RXCSUM_CAP_TCP6OPT 0x004 271#define NDIS_RXCSUM_CAP_TCP6 0x010 272#define NDIS_RXCSUM_CAP_UDP6 0x040 273}; 274 275struct ndis_lsov1_offload { 276 uint32_t ndis_encap; /*NDIS_OFFLOAD_ENCAP_*/ 277 uint32_t ndis_maxsize; 278 uint32_t ndis_minsegs; 279 uint32_t ndis_opts; 280}; 281 282struct ndis_ipsecv1_offload { 283 uint32_t ndis_encap; /*NDIS_OFFLOAD_ENCAP_*/ 284 uint32_t ndis_ah_esp; 285 uint32_t ndis_xport_tun; 286 uint32_t ndis_ip4_opts; 287 uint32_t ndis_flags; 288 uint32_t ndis_ip4_ah; 289 uint32_t ndis_ip4_esp; 290}; 291 292struct ndis_lsov2_offload { 293 uint32_t ndis_ip4_encap; /*NDIS_OFFLOAD_ENCAP_*/ 294 uint32_t ndis_ip4_maxsz; 295 uint32_t ndis_ip4_minsg; 296 uint32_t ndis_ip6_encap; /*NDIS_OFFLOAD_ENCAP_*/ 297 uint32_t ndis_ip6_maxsz; 298 uint32_t ndis_ip6_minsg; 299 uint32_t ndis_ip6_opts; 300#define NDIS_LSOV2_CAP_IP6EXT 0x001 301#define NDIS_LSOV2_CAP_TCP6OPT 0x004 302}; 303 304struct ndis_ipsecv2_offload { 305 uint32_t ndis_encap; /*NDIS_OFFLOAD_ENCAP_*/ 306 uint8_t ndis_ip6; 307 uint8_t ndis_ip4opt; 308 uint8_t ndis_ip6ext; 309 uint8_t ndis_ah; 310 uint8_t ndis_esp; 311 uint8_t ndis_ah_esp; 312 uint8_t ndis_xport; 313 uint8_t ndis_tun; 314 uint8_t ndis_xport_tun; 315 uint8_t ndis_lso; 316 uint8_t ndis_extseq; 317 uint32_t ndis_udp_esp; 318 uint32_t ndis_auth; 319 uint32_t ndis_crypto; 320 uint32_t ndis_sa_caps; 321}; 322 323struct ndis_rsc_offload { 324 uint8_t ndis_ip4; 325 uint8_t ndis_ip6; 326}; 327 328struct ndis_encap_offload { 329 uint32_t ndis_flags; 330 uint32_t ndis_maxhdr; 331}; 332 333struct ndis_offload { 334 struct ndis_object_hdr ndis_hdr; 335 struct ndis_csum_offload ndis_csum; 336 struct ndis_lsov1_offload ndis_lsov1; 337 struct ndis_ipsecv1_offload ndis_ipsecv1; 338 struct ndis_lsov2_offload ndis_lsov2; 339 uint32_t ndis_flags; 340 /* NDIS >= 6.1 */ 341 struct ndis_ipsecv2_offload ndis_ipsecv2; 342 /* NDIS >= 6.30 */ 343 struct ndis_rsc_offload ndis_rsc; 344 struct ndis_encap_offload ndis_encap_gre; 345}; 346 347#define NDIS_OFFLOAD_SIZE sizeof(struct ndis_offload) 348#define NDIS_OFFLOAD_SIZE_6_0 \ 349 __offsetof(struct ndis_offload, ndis_ipsecv2) 350#define NDIS_OFFLOAD_SIZE_6_1 \ 351 __offsetof(struct ndis_offload, ndis_rsc) 352 353#define NDIS_OFFLOAD_REV_1 1 /* NDIS 6.0 */ 354#define NDIS_OFFLOAD_REV_2 2 /* NDIS 6.1 */ 355#define NDIS_OFFLOAD_REV_3 3 /* NDIS 6.30 */ 356 357/* 358 * Per-packet-info 359 */ 360 361/* VLAN */ 362#define NDIS_VLAN_INFO_SIZE sizeof(uint32_t) 363#define NDIS_VLAN_INFO_PRI_MASK 0x0007 364#define NDIS_VLAN_INFO_CFI_MASK 0x0008 365#define NDIS_VLAN_INFO_ID_MASK 0xfff0 366#define NDIS_VLAN_INFO_MAKE(id, pri, cfi) \ 367 (((pri) & NDIS_VLAN_INFO_PRI_MASK) | \ 368 (((cfi) & 0x1) << 3) | (((id) & 0xfff) << 4)) 369#define NDIS_VLAN_INFO_ID(inf) (((inf) & NDIS_VLAN_INFO_ID_MASK) >> 4) 370#define NDIS_VLAN_INFO_CFI(inf) (((inf) & NDIS_VLAN_INFO_CFI_MASK) >> 3) 371#define NDIS_VLAN_INFO_PRI(inf) ((inf) & NDIS_VLAN_INFO_PRI_MASK) 372 373/* Reception checksum */ 374#define NDIS_RXCSUM_INFO_SIZE sizeof(uint32_t) 375#define NDIS_RXCSUM_INFO_TCPCS_FAILED 0x0001 376#define NDIS_RXCSUM_INFO_UDPCS_FAILED 0x0002 377#define NDIS_RXCSUM_INFO_IPCS_FAILED 0x0004 378#define NDIS_RXCSUM_INFO_TCPCS_OK 0x0008 379#define NDIS_RXCSUM_INFO_UDPCS_OK 0x0010 380#define NDIS_RXCSUM_INFO_IPCS_OK 0x0020 381#define NDIS_RXCSUM_INFO_LOOPBACK 0x0040 382#define NDIS_RXCSUM_INFO_TCPCS_INVAL 0x0080 383#define NDIS_RXCSUM_INFO_IPCS_INVAL 0x0100 384 385/* LSOv2 */ 386#define NDIS_LSO2_INFO_SIZE sizeof(uint32_t) 387#define NDIS_LSO2_INFO_MSS_MASK 0x000fffff 388#define NDIS_LSO2_INFO_THOFF_MASK 0x3ff00000 389#define NDIS_LSO2_INFO_ISLSO2 0x40000000 390#define NDIS_LSO2_INFO_ISIPV6 0x80000000 391 392#define NDIS_LSO2_INFO_MAKE(thoff, mss) \ 393 ((((uint32_t)(mss)) & NDIS_LSO2_INFO_MSS_MASK) | \ 394 ((((uint32_t)(thoff)) & 0x3ff) << 20) | \ 395 NDIS_LSO2_INFO_ISLSO2) 396 397#define NDIS_LSO2_INFO_MAKEIPV4(thoff, mss) \ 398 NDIS_LSO2_INFO_MAKE((thoff), (mss)) 399 400#define NDIS_LSO2_INFO_MAKEIPV6(thoff, mss) \ 401 (NDIS_LSO2_INFO_MAKE((thoff), (mss)) | NDIS_LSO2_INFO_ISIPV6) 402 403/* Transmission checksum */ 404#define NDIS_TXCSUM_INFO_SIZE sizeof(uint32_t) 405#define NDIS_TXCSUM_INFO_IPV4 0x00000001 406#define NDIS_TXCSUM_INFO_IPV6 0x00000002 407#define NDIS_TXCSUM_INFO_TCPCS 0x00000004 408#define NDIS_TXCSUM_INFO_UDPCS 0x00000008 409#define NDIS_TXCSUM_INFO_IPCS 0x00000010 410#define NDIS_TXCSUM_INFO_THOFF 0x03ff0000 411 412#define NDIS_TXCSUM_INFO_MKL4CS(thoff, flag) \ 413 ((((uint32_t)(thoff)) << 16) | (flag)) 414 415#define NDIS_TXCSUM_INFO_MKTCPCS(thoff) \ 416 NDIS_TXCSUM_INFO_MKL4CS((thoff), NDIS_TXCSUM_INFO_TCPCS) 417 418#define NDIS_TXCSUM_INFO_MKUDPCS(thoff) \ 419 NDIS_TXCSUM_INFO_MKL4CS((thoff), NDIS_TXCSUM_INFO_UDPCS) 420#endif /* !_NET_NDIS_H_ */ 421