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