1 /*- 2 * Copyright (c) 2009-2012 Microsoft Corp. 3 * Copyright (c) 2010-2012 Citrix Inc. 4 * Copyright (c) 2012 NetApp Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice unmodified, this list of conditions, and the following 12 * disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 /* 32 * HyperV vmbus (virtual machine bus) network VSC (virtual services client) 33 * header file 34 * 35 * (Updated from unencumbered NvspProtocol.h) 36 */ 37 38 #ifndef __HV_NET_VSC_H__ 39 #define __HV_NET_VSC_H__ 40 41 #include <sys/types.h> 42 #include <sys/param.h> 43 #include <sys/lock.h> 44 #include <sys/sx.h> 45 46 #include <dev/hyperv/include/hyperv.h> 47 48 49 #define NVSP_INVALID_PROTOCOL_VERSION (0xFFFFFFFF) 50 51 #define NVSP_PROTOCOL_VERSION_1 2 52 #define NVSP_PROTOCOL_VERSION_2 0x30002 53 #define NVSP_MIN_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_1) 54 #define NVSP_MAX_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_2) 55 56 #define NVSP_PROTOCOL_VERSION_CURRENT NVSP_PROTOCOL_VERSION_2 57 58 #define NVSP_OPERATIONAL_STATUS_OK (0x00000000) 59 #define NVSP_OPERATIONAL_STATUS_DEGRADED (0x00000001) 60 #define NVSP_OPERATIONAL_STATUS_NONRECOVERABLE (0x00000002) 61 #define NVSP_OPERATIONAL_STATUS_NO_CONTACT (0x00000003) 62 #define NVSP_OPERATIONAL_STATUS_LOST_COMMUNICATION (0x00000004) 63 64 /* 65 * Maximun number of transfer pages (packets) the VSP will use on a receive 66 */ 67 #define NVSP_MAX_PACKETS_PER_RECEIVE 375 68 69 70 typedef enum nvsp_msg_type_ { 71 nvsp_msg_type_none = 0, 72 73 /* 74 * Init Messages 75 */ 76 nvsp_msg_type_init = 1, 77 nvsp_msg_type_init_complete = 2, 78 79 nvsp_version_msg_start = 100, 80 81 /* 82 * Version 1 Messages 83 */ 84 nvsp_msg_1_type_send_ndis_vers = nvsp_version_msg_start, 85 86 nvsp_msg_1_type_send_rx_buf, 87 nvsp_msg_1_type_send_rx_buf_complete, 88 nvsp_msg_1_type_revoke_rx_buf, 89 90 nvsp_msg_1_type_send_send_buf, 91 nvsp_msg_1_type_send_send_buf_complete, 92 nvsp_msg_1_type_revoke_send_buf, 93 94 nvsp_msg_1_type_send_rndis_pkt, 95 nvsp_msg_1_type_send_rndis_pkt_complete, 96 97 /* 98 * Version 2 Messages 99 */ 100 nvsp_msg_2_type_send_chimney_delegated_buf, 101 nvsp_msg_2_type_send_chimney_delegated_buf_complete, 102 nvsp_msg_2_type_revoke_chimney_delegated_buf, 103 104 nvsp_msg_2_type_resume_chimney_rx_indication, 105 106 nvsp_msg_2_type_terminate_chimney, 107 nvsp_msg_2_type_terminate_chimney_complete, 108 109 nvsp_msg_2_type_indicate_chimney_event, 110 111 nvsp_msg_2_type_send_chimney_packet, 112 nvsp_msg_2_type_send_chimney_packet_complete, 113 114 nvsp_msg_2_type_post_chimney_rx_request, 115 nvsp_msg_2_type_post_chimney_rx_request_complete, 116 117 nvsp_msg_2_type_alloc_rx_buf, 118 nvsp_msg_2_type_alloc_rx_buf_complete, 119 120 nvsp_msg_2_type_free_rx_buf, 121 122 nvsp_msg_2_send_vmq_rndis_pkt, 123 nvsp_msg_2_send_vmq_rndis_pkt_complete, 124 125 nvsp_msg_2_type_send_ndis_config, 126 127 nvsp_msg_2_type_alloc_chimney_handle, 128 nvsp_msg_2_type_alloc_chimney_handle_complete, 129 } nvsp_msg_type; 130 131 typedef enum nvsp_status_ { 132 nvsp_status_none = 0, 133 nvsp_status_success, 134 nvsp_status_failure, 135 /* Deprecated */ 136 nvsp_status_prot_vers_range_too_new, 137 /* Deprecated */ 138 nvsp_status_prot_vers_range_too_old, 139 nvsp_status_invalid_rndis_pkt, 140 nvsp_status_busy, 141 nvsp_status_max, 142 } nvsp_status; 143 144 typedef struct nvsp_msg_hdr_ { 145 uint32_t msg_type; 146 } __packed nvsp_msg_hdr; 147 148 /* 149 * Init Messages 150 */ 151 152 /* 153 * This message is used by the VSC to initialize the channel 154 * after the channels has been opened. This message should 155 * never include anything other then versioning (i.e. this 156 * message will be the same for ever). 157 * 158 * Forever is a long time. The values have been redefined 159 * in Win7 to indicate major and minor protocol version 160 * number. 161 */ 162 typedef struct nvsp_msg_init_ { 163 union { 164 struct { 165 uint16_t minor_protocol_version; 166 uint16_t major_protocol_version; 167 } s; 168 /* Formerly min_protocol_version */ 169 uint32_t protocol_version; 170 } p1; 171 /* Formerly max_protocol_version */ 172 uint32_t protocol_version_2; 173 } __packed nvsp_msg_init; 174 175 /* 176 * This message is used by the VSP to complete the initialization 177 * of the channel. This message should never include anything other 178 * then versioning (i.e. this message will be the same forever). 179 */ 180 typedef struct nvsp_msg_init_complete_ { 181 /* Deprecated */ 182 uint32_t negotiated_prot_vers; 183 uint32_t max_mdl_chain_len; 184 uint32_t status; 185 } __packed nvsp_msg_init_complete; 186 187 typedef union nvsp_msg_init_uber_ { 188 nvsp_msg_init init; 189 nvsp_msg_init_complete init_compl; 190 } __packed nvsp_msg_init_uber; 191 192 /* 193 * Version 1 Messages 194 */ 195 196 /* 197 * This message is used by the VSC to send the NDIS version 198 * to the VSP. The VSP can use this information when handling 199 * OIDs sent by the VSC. 200 */ 201 typedef struct nvsp_1_msg_send_ndis_version_ { 202 uint32_t ndis_major_vers; 203 /* Deprecated */ 204 uint32_t ndis_minor_vers; 205 } __packed nvsp_1_msg_send_ndis_version; 206 207 /* 208 * This message is used by the VSC to send a receive buffer 209 * to the VSP. The VSP can then use the receive buffer to 210 * send data to the VSC. 211 */ 212 typedef struct nvsp_1_msg_send_rx_buf_ { 213 uint32_t gpadl_handle; 214 uint16_t id; 215 } __packed nvsp_1_msg_send_rx_buf; 216 217 typedef struct nvsp_1_rx_buf_section_ { 218 uint32_t offset; 219 uint32_t sub_allocation_size; 220 uint32_t num_sub_allocations; 221 uint32_t end_offset; 222 } __packed nvsp_1_rx_buf_section; 223 224 /* 225 * This message is used by the VSP to acknowledge a receive 226 * buffer send by the VSC. This message must be sent by the 227 * VSP before the VSP uses the receive buffer. 228 */ 229 typedef struct nvsp_1_msg_send_rx_buf_complete_ { 230 uint32_t status; 231 uint32_t num_sections; 232 233 /* 234 * The receive buffer is split into two parts, a large 235 * suballocation section and a small suballocation 236 * section. These sections are then suballocated by a 237 * certain size. 238 * 239 * For example, the following break up of the receive 240 * buffer has 6 large suballocations and 10 small 241 * suballocations. 242 * 243 * | Large Section | | Small Section | 244 * ------------------------------------------------------------ 245 * | | | | | | | | | | | | | | | | | | 246 * | | 247 * LargeOffset SmallOffset 248 */ 249 nvsp_1_rx_buf_section sections[1]; 250 251 } __packed nvsp_1_msg_send_rx_buf_complete; 252 253 /* 254 * This message is sent by the VSC to revoke the receive buffer. 255 * After the VSP completes this transaction, the VSP should never 256 * use the receive buffer again. 257 */ 258 typedef struct nvsp_1_msg_revoke_rx_buf_ { 259 uint16_t id; 260 } __packed nvsp_1_msg_revoke_rx_buf; 261 262 /* 263 * This message is used by the VSC to send a send buffer 264 * to the VSP. The VSC can then use the send buffer to 265 * send data to the VSP. 266 */ 267 typedef struct nvsp_1_msg_send_send_buf_ { 268 uint32_t gpadl_handle; 269 uint16_t id; 270 } __packed nvsp_1_msg_send_send_buf; 271 272 /* 273 * This message is used by the VSP to acknowledge a send 274 * buffer sent by the VSC. This message must be sent by the 275 * VSP before the VSP uses the sent buffer. 276 */ 277 typedef struct nvsp_1_msg_send_send_buf_complete_ { 278 uint32_t status; 279 280 /* 281 * The VSC gets to choose the size of the send buffer and 282 * the VSP gets to choose the sections size of the buffer. 283 * This was done to enable dynamic reconfigurations when 284 * the cost of GPA-direct buffers decreases. 285 */ 286 uint32_t section_size; 287 } __packed nvsp_1_msg_send_send_buf_complete; 288 289 /* 290 * This message is sent by the VSC to revoke the send buffer. 291 * After the VSP completes this transaction, the vsp should never 292 * use the send buffer again. 293 */ 294 typedef struct nvsp_1_msg_revoke_send_buf_ { 295 uint16_t id; 296 } __packed nvsp_1_msg_revoke_send_buf; 297 298 /* 299 * This message is used by both the VSP and the VSC to send 300 * an RNDIS message to the opposite channel endpoint. 301 */ 302 typedef struct nvsp_1_msg_send_rndis_pkt_ { 303 /* 304 * This field is specified by RNIDS. They assume there's 305 * two different channels of communication. However, 306 * the Network VSP only has one. Therefore, the channel 307 * travels with the RNDIS packet. 308 */ 309 uint32_t chan_type; 310 311 /* 312 * This field is used to send part or all of the data 313 * through a send buffer. This values specifies an 314 * index into the send buffer. If the index is 315 * 0xFFFFFFFF, then the send buffer is not being used 316 * and all of the data was sent through other VMBus 317 * mechanisms. 318 */ 319 uint32_t send_buf_section_idx; 320 uint32_t send_buf_section_size; 321 } __packed nvsp_1_msg_send_rndis_pkt; 322 323 /* 324 * This message is used by both the VSP and the VSC to complete 325 * a RNDIS message to the opposite channel endpoint. At this 326 * point, the initiator of this message cannot use any resources 327 * associated with the original RNDIS packet. 328 */ 329 typedef struct nvsp_1_msg_send_rndis_pkt_complete_ { 330 uint32_t status; 331 } __packed nvsp_1_msg_send_rndis_pkt_complete; 332 333 334 /* 335 * Version 2 Messages 336 */ 337 338 /* 339 * This message is used by the VSC to send the NDIS version 340 * to the VSP. The VSP can use this information when handling 341 * OIDs sent by the VSC. 342 */ 343 typedef struct nvsp_2_netvsc_capabilities_ { 344 union { 345 uint64_t as_uint64; 346 struct { 347 uint64_t vmq : 1; 348 uint64_t chimney : 1; 349 uint64_t sriov : 1; 350 uint64_t ieee8021q : 1; 351 uint64_t correlationid : 1; 352 uint64_t teaming : 1; 353 } u2; 354 } u1; 355 } __packed nvsp_2_netvsc_capabilities; 356 357 typedef struct nvsp_2_msg_send_ndis_config_ { 358 uint32_t mtu; 359 uint32_t reserved; 360 nvsp_2_netvsc_capabilities capabilities; 361 } __packed nvsp_2_msg_send_ndis_config; 362 363 /* 364 * NvspMessage2TypeSendChimneyDelegatedBuffer 365 */ 366 typedef struct nvsp_2_msg_send_chimney_buf_ 367 { 368 /* 369 * On WIN7 beta, delegated_obj_max_size is defined as a uint32_t 370 * Since WIN7 RC, it was split into two uint16_t. To have the same 371 * struct layout, delegated_obj_max_size shall be the first field. 372 */ 373 uint16_t delegated_obj_max_size; 374 375 /* 376 * The revision # of chimney protocol used between NVSC and NVSP. 377 * 378 * This revision is NOT related to the chimney revision between 379 * NDIS protocol and miniport drivers. 380 */ 381 uint16_t revision; 382 383 uint32_t gpadl_handle; 384 } __packed nvsp_2_msg_send_chimney_buf; 385 386 387 /* Unsupported chimney revision 0 (only present in WIN7 beta) */ 388 #define NVSP_CHIMNEY_REVISION_0 0 389 390 /* WIN7 Beta Chimney QFE */ 391 #define NVSP_CHIMNEY_REVISION_1 1 392 393 /* The chimney revision since WIN7 RC */ 394 #define NVSP_CHIMNEY_REVISION_2 2 395 396 397 /* 398 * NvspMessage2TypeSendChimneyDelegatedBufferComplete 399 */ 400 typedef struct nvsp_2_msg_send_chimney_buf_complete_ { 401 uint32_t status; 402 403 /* 404 * Maximum number outstanding sends and pre-posted receives. 405 * 406 * NVSC should not post more than SendQuota/ReceiveQuota packets. 407 * Otherwise, it can block the non-chimney path for an indefinite 408 * amount of time. 409 * (since chimney sends/receives are affected by the remote peer). 410 * 411 * Note: NVSP enforces the quota restrictions on a per-VMBCHANNEL 412 * basis. It doesn't enforce the restriction separately for chimney 413 * send/receive. If NVSC doesn't voluntarily enforce "SendQuota", 414 * it may kill its own network connectivity. 415 */ 416 uint32_t send_quota; 417 uint32_t rx_quota; 418 } __packed nvsp_2_msg_send_chimney_buf_complete; 419 420 /* 421 * NvspMessage2TypeRevokeChimneyDelegatedBuffer 422 */ 423 typedef struct nvsp_2_msg_revoke_chimney_buf_ { 424 uint32_t gpadl_handle; 425 } __packed nvsp_2_msg_revoke_chimney_buf; 426 427 428 #define NVSP_CHIMNEY_OBJECT_TYPE_NEIGHBOR 0 429 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH4 1 430 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH6 2 431 #define NVSP_CHIMNEY_OBJECT_TYPE_TCP 3 432 433 /* 434 * NvspMessage2TypeAllocateChimneyHandle 435 */ 436 typedef struct nvsp_2_msg_alloc_chimney_handle_ { 437 uint64_t vsc_context; 438 uint32_t object_type; 439 } __packed nvsp_2_msg_alloc_chimney_handle; 440 441 /* 442 * NvspMessage2TypeAllocateChimneyHandleComplete 443 */ 444 typedef struct nvsp_2_msg_alloc_chimney_handle_complete_ { 445 uint32_t vsp_handle; 446 } __packed nvsp_2_msg_alloc_chimney_handle_complete; 447 448 449 /* 450 * NvspMessage2TypeResumeChimneyRXIndication 451 */ 452 typedef struct nvsp_2_msg_resume_chimney_rx_indication { 453 /* 454 * Handle identifying the offloaded connection 455 */ 456 uint32_t vsp_tcp_handle; 457 } __packed nvsp_2_msg_resume_chimney_rx_indication; 458 459 460 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_FIRST_STAGE (0x01u) 461 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_RESERVED (~(0x01u)) 462 463 /* 464 * NvspMessage2TypeTerminateChimney 465 */ 466 typedef struct nvsp_2_msg_terminate_chimney_ { 467 /* 468 * Handle identifying the offloaded object 469 */ 470 uint32_t vsp_handle; 471 472 /* 473 * Terminate Offload Flags 474 * Bit 0: 475 * When set to 0, terminate the offload at the destination NIC 476 * Bit 1-31: Reserved, shall be zero 477 */ 478 uint32_t flags; 479 480 union { 481 /* 482 * This field is valid only when bit 0 of flags is clear. 483 * It specifies the index into the premapped delegated 484 * object buffer. The buffer was sent through the 485 * NvspMessage2TypeSendChimneyDelegatedBuffer 486 * message at initialization time. 487 * 488 * NVSP will write the delegated state into the delegated 489 * buffer upon upload completion. 490 */ 491 uint32_t index; 492 493 /* 494 * This field is valid only when bit 0 of flags is set. 495 * 496 * The seqence number of the most recently accepted RX 497 * indication when VSC sets its TCP context into 498 * "terminating" state. 499 * 500 * This allows NVSP to determines if there are any in-flight 501 * RX indications for which the acceptance state is still 502 * undefined. 503 */ 504 uint64_t last_accepted_rx_seq_no; 505 } f0; 506 } __packed nvsp_2_msg_terminate_chimney; 507 508 509 #define NVSP_TERMINATE_CHIMNEY_COMPLETE_FLAG_DATA_CORRUPTED 0x0000001u 510 511 /* 512 * NvspMessage2TypeTerminateChimneyComplete 513 */ 514 typedef struct nvsp_2_msg_terminate_chimney_complete_ { 515 uint64_t vsc_context; 516 uint32_t flags; 517 } __packed nvsp_2_msg_terminate_chimney_complete; 518 519 /* 520 * NvspMessage2TypeIndicateChimneyEvent 521 */ 522 typedef struct nvsp_2_msg_indicate_chimney_event_ { 523 /* 524 * When VscTcpContext is 0, event_type is an NDIS_STATUS event code 525 * Otherwise, EventType is an TCP connection event (defined in 526 * NdisTcpOffloadEventHandler chimney DDK document). 527 */ 528 uint32_t event_type; 529 530 /* 531 * When VscTcpContext is 0, EventType is an NDIS_STATUS event code 532 * Otherwise, EventType is an TCP connection event specific information 533 * (defined in NdisTcpOffloadEventHandler chimney DDK document). 534 */ 535 uint32_t event_specific_info; 536 537 /* 538 * If not 0, the event is per-TCP connection event. This field 539 * contains the VSC's TCP context. 540 * If 0, the event indication is global. 541 */ 542 uint64_t vsc_tcp_context; 543 } __packed nvsp_2_msg_indicate_chimney_event; 544 545 546 #define NVSP_1_CHIMNEY_SEND_INVALID_OOB_INDEX 0xffffu 547 #define NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX 0xffffu 548 549 /* 550 * NvspMessage2TypeSendChimneyPacket 551 */ 552 typedef struct nvsp_2_msg_send_chimney_pkt_ { 553 /* 554 * Identify the TCP connection for which this chimney send is 555 */ 556 uint32_t vsp_tcp_handle; 557 558 /* 559 * This field is used to send part or all of the data 560 * through a send buffer. This values specifies an 561 * index into the send buffer. If the index is 562 * 0xFFFF, then the send buffer is not being used 563 * and all of the data was sent through other VMBus 564 * mechanisms. 565 */ 566 uint16_t send_buf_section_index; 567 uint16_t send_buf_section_size; 568 569 /* 570 * OOB Data Index 571 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF, 572 * then there is no OOB data. 573 * 574 * This field shall be always 0xFFFFFFFF for now. It is reserved for 575 * the future. 576 */ 577 uint16_t oob_data_index; 578 579 /* 580 * DisconnectFlags = 0 581 * Normal chimney send. See MiniportTcpOffloadSend for details. 582 * 583 * DisconnectFlags = TCP_DISCONNECT_GRACEFUL_CLOSE (0x01) 584 * Graceful disconnect. See MiniportTcpOffloadDisconnect for details. 585 * 586 * DisconnectFlags = TCP_DISCONNECT_ABORTIVE_CLOSE (0x02) 587 * Abortive disconnect. See MiniportTcpOffloadDisconnect for details. 588 */ 589 uint16_t disconnect_flags; 590 591 uint32_t seq_no; 592 } __packed nvsp_2_msg_send_chimney_pkt; 593 594 /* 595 * NvspMessage2TypeSendChimneyPacketComplete 596 */ 597 typedef struct nvsp_2_msg_send_chimney_pkt_complete_ { 598 /* 599 * The NDIS_STATUS for the chimney send 600 */ 601 uint32_t status; 602 603 /* 604 * Number of bytes that have been sent to the peer (and ACKed by the peer). 605 */ 606 uint32_t bytes_transferred; 607 } __packed nvsp_2_msg_send_chimney_pkt_complete; 608 609 610 #define NVSP_1_CHIMNEY_RECV_FLAG_NO_PUSH 0x0001u 611 #define NVSP_1_CHIMNEY_RECV_INVALID_OOB_INDEX 0xffffu 612 613 /* 614 * NvspMessage2TypePostChimneyRecvRequest 615 */ 616 typedef struct nvsp_2_msg_post_chimney_rx_request_ { 617 /* 618 * Identify the TCP connection which this chimney receive request 619 * is for. 620 */ 621 uint32_t vsp_tcp_handle; 622 623 /* 624 * OOB Data Index 625 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF, 626 * then there is no OOB data. 627 * 628 * This field shall be always 0xFFFFFFFF for now. It is reserved for 629 * the future. 630 */ 631 uint32_t oob_data_index; 632 633 /* 634 * Bit 0 635 * When it is set, this is a "no-push" receive. 636 * When it is clear, this is a "push" receive. 637 * 638 * Bit 1-15: Reserved and shall be zero 639 */ 640 uint16_t flags; 641 642 /* 643 * For debugging and diagnoses purpose. 644 * The SeqNo is per TCP connection and starts from 0. 645 */ 646 uint32_t seq_no; 647 } __packed nvsp_2_msg_post_chimney_rx_request; 648 649 /* 650 * NvspMessage2TypePostChimneyRecvRequestComplete 651 */ 652 typedef struct nvsp_2_msg_post_chimney_rx_request_complete_ { 653 /* 654 * The NDIS_STATUS for the chimney send 655 */ 656 uint32_t status; 657 658 /* 659 * Number of bytes that have been sent to the peer (and ACKed by 660 * the peer). 661 */ 662 uint32_t bytes_xferred; 663 } __packed nvsp_2_msg_post_chimney_rx_request_complete; 664 665 /* 666 * NvspMessage2TypeAllocateReceiveBuffer 667 */ 668 typedef struct nvsp_2_msg_alloc_rx_buf_ { 669 /* 670 * Allocation ID to match the allocation request and response 671 */ 672 uint32_t allocation_id; 673 674 /* 675 * Length of the VM shared memory receive buffer that needs to 676 * be allocated 677 */ 678 uint32_t length; 679 } __packed nvsp_2_msg_alloc_rx_buf; 680 681 /* 682 * NvspMessage2TypeAllocateReceiveBufferComplete 683 */ 684 typedef struct nvsp_2_msg_alloc_rx_buf_complete_ { 685 /* 686 * The NDIS_STATUS code for buffer allocation 687 */ 688 uint32_t status; 689 690 /* 691 * Allocation ID from NVSP_2_MESSAGE_ALLOCATE_RECEIVE_BUFFER 692 */ 693 uint32_t allocation_id; 694 695 /* 696 * GPADL handle for the allocated receive buffer 697 */ 698 uint32_t gpadl_handle; 699 700 /* 701 * Receive buffer ID that is further used in 702 * NvspMessage2SendVmqRndisPacket 703 */ 704 uint64_t rx_buf_id; 705 } __packed nvsp_2_msg_alloc_rx_buf_complete; 706 707 /* 708 * NvspMessage2TypeFreeReceiveBuffer 709 */ 710 typedef struct nvsp_2_msg_free_rx_buf_ { 711 /* 712 * Receive buffer ID previous returned in 713 * NvspMessage2TypeAllocateReceiveBufferComplete message 714 */ 715 uint64_t rx_buf_id; 716 } __packed nvsp_2_msg_free_rx_buf; 717 718 /* 719 * This structure is used in defining the buffers in 720 * NVSP_2_MESSAGE_SEND_VMQ_RNDIS_PACKET structure 721 */ 722 typedef struct nvsp_xfer_page_range_ { 723 /* 724 * Specifies the ID of the receive buffer that has the buffer. This 725 * ID can be the general receive buffer ID specified in 726 * NvspMessage1TypeSendReceiveBuffer or it can be the shared memory 727 * receive buffer ID allocated by the VSC and specified in 728 * NvspMessage2TypeAllocateReceiveBufferComplete message 729 */ 730 uint64_t xfer_page_set_id; 731 732 /* 733 * Number of bytes 734 */ 735 uint32_t byte_count; 736 737 /* 738 * Offset in bytes from the beginning of the buffer 739 */ 740 uint32_t byte_offset; 741 } __packed nvsp_xfer_page_range; 742 743 /* 744 * NvspMessage2SendVmqRndisPacket 745 */ 746 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_ { 747 /* 748 * This field is specified by RNIDS. They assume there's 749 * two different channels of communication. However, 750 * the Network VSP only has one. Therefore, the channel 751 * travels with the RNDIS packet. It must be RMC_DATA 752 */ 753 uint32_t channel_type; 754 755 /* 756 * Only the Range element corresponding to the RNDIS header of 757 * the first RNDIS message in the multiple RNDIS messages sent 758 * in one NVSP message. Information about the data portions as well 759 * as the subsequent RNDIS messages in the same NVSP message are 760 * embedded in the RNDIS header itself 761 */ 762 nvsp_xfer_page_range range; 763 } __packed nvsp_2_msg_send_vmq_rndis_pkt; 764 765 /* 766 * This message is used by the VSC to complete 767 * a RNDIS VMQ message to the VSP. At this point, 768 * the initiator of this message can use any resources 769 * associated with the original RNDIS VMQ packet. 770 */ 771 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_complete_ 772 { 773 uint32_t status; 774 } __packed nvsp_2_msg_send_vmq_rndis_pkt_complete; 775 776 777 typedef union nvsp_1_msg_uber_ { 778 nvsp_1_msg_send_ndis_version send_ndis_vers; 779 780 nvsp_1_msg_send_rx_buf send_rx_buf; 781 nvsp_1_msg_send_rx_buf_complete send_rx_buf_complete; 782 nvsp_1_msg_revoke_rx_buf revoke_rx_buf; 783 784 nvsp_1_msg_send_send_buf send_send_buf; 785 nvsp_1_msg_send_send_buf_complete send_send_buf_complete; 786 nvsp_1_msg_revoke_send_buf revoke_send_buf; 787 788 nvsp_1_msg_send_rndis_pkt send_rndis_pkt; 789 nvsp_1_msg_send_rndis_pkt_complete send_rndis_pkt_complete; 790 } __packed nvsp_1_msg_uber; 791 792 793 typedef union nvsp_2_msg_uber_ { 794 nvsp_2_msg_send_ndis_config send_ndis_config; 795 796 nvsp_2_msg_send_chimney_buf send_chimney_buf; 797 nvsp_2_msg_send_chimney_buf_complete send_chimney_buf_complete; 798 nvsp_2_msg_revoke_chimney_buf revoke_chimney_buf; 799 800 nvsp_2_msg_resume_chimney_rx_indication resume_chimney_rx_indication; 801 nvsp_2_msg_terminate_chimney terminate_chimney; 802 nvsp_2_msg_terminate_chimney_complete terminate_chimney_complete; 803 nvsp_2_msg_indicate_chimney_event indicate_chimney_event; 804 805 nvsp_2_msg_send_chimney_pkt send_chimney_packet; 806 nvsp_2_msg_send_chimney_pkt_complete send_chimney_packet_complete; 807 nvsp_2_msg_post_chimney_rx_request post_chimney_rx_request; 808 nvsp_2_msg_post_chimney_rx_request_complete 809 post_chimney_rx_request_complete; 810 811 nvsp_2_msg_alloc_rx_buf alloc_rx_buffer; 812 nvsp_2_msg_alloc_rx_buf_complete alloc_rx_buffer_complete; 813 nvsp_2_msg_free_rx_buf free_rx_buffer; 814 815 nvsp_2_msg_send_vmq_rndis_pkt send_vmq_rndis_pkt; 816 nvsp_2_msg_send_vmq_rndis_pkt_complete send_vmq_rndis_pkt_complete; 817 nvsp_2_msg_alloc_chimney_handle alloc_chimney_handle; 818 nvsp_2_msg_alloc_chimney_handle_complete alloc_chimney_handle_complete; 819 } __packed nvsp_2_msg_uber; 820 821 822 typedef union nvsp_all_msgs_ { 823 nvsp_msg_init_uber init_msgs; 824 nvsp_1_msg_uber vers_1_msgs; 825 nvsp_2_msg_uber vers_2_msgs; 826 } __packed nvsp_all_msgs; 827 828 /* 829 * ALL Messages 830 */ 831 typedef struct nvsp_msg_ { 832 nvsp_msg_hdr hdr; 833 nvsp_all_msgs msgs; 834 } __packed nvsp_msg; 835 836 837 /* 838 * The following arguably belongs in a separate header file 839 */ 840 841 /* 842 * Defines 843 */ 844 845 #define NETVSC_SEND_BUFFER_SIZE (64*1024) /* 64K */ 846 #define NETVSC_SEND_BUFFER_ID 0xface 847 848 849 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024) /* 1MB */ 850 851 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe 852 853 #define NETVSC_RECEIVE_SG_COUNT 1 854 855 /* Preallocated receive packets */ 856 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256 857 858 /* 859 * Maximum MTU we permit to be configured for a netvsc interface. 860 * When the code was developed, a max MTU of 12232 was tested and 861 * proven to work. 9K is a reasonable maximum for an Ethernet. 862 */ 863 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024) 864 865 /* 866 * Data types 867 */ 868 869 /* 870 * Per netvsc channel-specific 871 */ 872 typedef struct netvsc_dev_ { 873 struct hv_device *dev; 874 int num_outstanding_sends; 875 876 /* List of free preallocated NETVSC_PACKET to represent RX packet */ 877 STAILQ_HEAD(PQ, netvsc_packet_) myrx_packet_list; 878 struct mtx rx_pkt_list_lock; 879 880 /* Send buffer allocated by us but manages by NetVSP */ 881 void *send_buf; 882 uint32_t send_buf_size; 883 uint32_t send_buf_gpadl_handle; 884 uint32_t send_section_size; 885 886 /* Receive buffer allocated by us but managed by NetVSP */ 887 void *rx_buf; 888 uint32_t rx_buf_size; 889 uint32_t rx_buf_gpadl_handle; 890 uint32_t rx_section_count; 891 nvsp_1_rx_buf_section *rx_sections; 892 893 /* Used for NetVSP initialization protocol */ 894 struct sema channel_init_sema; 895 nvsp_msg channel_init_packet; 896 897 nvsp_msg revoke_packet; 898 /*uint8_t hw_mac_addr[HW_MACADDR_LEN];*/ 899 900 /* Holds rndis device info */ 901 void *extension; 902 903 hv_bool_uint8_t destroy; 904 /* Negotiated NVSP version */ 905 uint32_t nvsp_version; 906 } netvsc_dev; 907 908 909 typedef void (*pfn_on_send_rx_completion)(void *); 910 911 #define NETVSC_DEVICE_RING_BUFFER_SIZE (64 * PAGE_SIZE) 912 #define NETVSC_PACKET_MAXPAGE 16 913 914 915 typedef struct xfer_page_packet_ { 916 /* 917 * This needs to be here because the network RX code casts 918 * an instantiation of this structure to a netvsc_packet. 919 */ 920 STAILQ_ENTRY(netvsc_packet_) mylist_entry; 921 922 uint32_t count; 923 } xfer_page_packet; 924 925 typedef struct netvsc_packet_ { 926 /* 927 * List used when enqueued on &net_dev->rx_packet_list, 928 * and when enqueued within the netvsc code 929 */ 930 STAILQ_ENTRY(netvsc_packet_) mylist_entry; 931 struct hv_device *device; 932 hv_bool_uint8_t is_data_pkt; /* One byte */ 933 uint16_t vlan_tci; 934 xfer_page_packet *xfer_page_pkt; 935 936 /* Completion */ 937 union { 938 struct { 939 uint64_t rx_completion_tid; 940 void *rx_completion_context; 941 /* This is no longer used */ 942 pfn_on_send_rx_completion on_rx_completion; 943 } rx; 944 struct { 945 uint64_t send_completion_tid; 946 void *send_completion_context; 947 /* Still used in netvsc and filter code */ 948 pfn_on_send_rx_completion on_send_completion; 949 } send; 950 } compl; 951 952 void *extension; 953 uint32_t tot_data_buf_len; 954 uint32_t page_buf_count; 955 hv_vmbus_page_buffer page_buffers[NETVSC_PACKET_MAXPAGE]; 956 } netvsc_packet; 957 958 typedef struct { 959 uint8_t mac_addr[6]; /* Assumption unsigned long */ 960 hv_bool_uint8_t link_state; 961 } netvsc_device_info; 962 963 /* 964 * Device-specific softc structure 965 */ 966 typedef struct hn_softc { 967 struct ifnet *hn_ifp; 968 struct arpcom arpcom; 969 device_t hn_dev; 970 uint8_t hn_unit; 971 int hn_carrier; 972 int hn_if_flags; 973 struct mtx hn_lock; 974 int hn_initdone; 975 /* See hv_netvsc_drv_freebsd.c for rules on how to use */ 976 int temp_unusable; 977 struct hv_device *hn_dev_obj; 978 netvsc_dev *net_dev; 979 } hn_softc_t; 980 981 982 /* 983 * Externs 984 */ 985 extern int hv_promisc_mode; 986 987 extern void netvsc_linkstatus_callback(struct hv_device *device_obj, 988 uint32_t status); 989 extern int netvsc_recv(struct hv_device *device_obj, netvsc_packet *packet); 990 extern void netvsc_xmit_completion(void *context); 991 992 extern void hv_nv_on_receive_completion(void *context); 993 extern netvsc_dev *hv_nv_on_device_add(struct hv_device *device, void *additional_info); 994 extern int hv_nv_on_device_remove(struct hv_device *device, 995 boolean_t destroy_channel); 996 extern int hv_nv_on_send(struct hv_device *device, netvsc_packet *pkt); 997 998 #endif /* __HV_NET_VSC_H__ */ 999 1000