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