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 _VMBUS_H_ 30 #define _VMBUS_H_ 31 32 #include <sys/param.h> 33 34 /* 35 * VMBUS version is 32 bit, upper 16 bit for major_number and lower 36 * 16 bit for minor_number. 37 * 38 * 0.13 -- Windows Server 2008 39 * 1.1 -- Windows 7 40 * 2.4 -- Windows 8 41 * 3.0 -- Windows 8.1 42 */ 43 #define VMBUS_VERSION_WS2008 ((0 << 16) | (13)) 44 #define VMBUS_VERSION_WIN7 ((1 << 16) | (1)) 45 #define VMBUS_VERSION_WIN8 ((2 << 16) | (4)) 46 #define VMBUS_VERSION_WIN8_1 ((3 << 16) | (0)) 47 48 #define VMBUS_VERSION_MAJOR(ver) (((uint32_t)(ver)) >> 16) 49 #define VMBUS_VERSION_MINOR(ver) (((uint32_t)(ver)) & 0xffff) 50 51 /* 52 * GPA stuffs. 53 */ 54 struct vmbus_gpa_range { 55 uint32_t gpa_len; 56 uint32_t gpa_ofs; 57 uint64_t gpa_page[0]; 58 } __packed; 59 60 /* This is actually vmbus_gpa_range.gpa_page[1] */ 61 struct vmbus_gpa { 62 uint32_t gpa_len; 63 uint32_t gpa_ofs; 64 uint64_t gpa_page; 65 } __packed; 66 67 #define VMBUS_CHANPKT_SIZE_SHIFT 3 68 69 #define VMBUS_CHANPKT_GETLEN(pktlen) \ 70 (((int)(pktlen)) << VMBUS_CHANPKT_SIZE_SHIFT) 71 72 struct vmbus_chanpkt_hdr { 73 uint16_t cph_type; /* VMBUS_CHANPKT_TYPE_ */ 74 uint16_t cph_hlen; /* header len, in 8 bytes */ 75 uint16_t cph_tlen; /* total len, in 8 bytes */ 76 uint16_t cph_flags; /* VMBUS_CHANPKT_FLAG_ */ 77 uint64_t cph_xactid; 78 } __packed; 79 80 #define VMBUS_CHANPKT_TYPE_INBAND 0x0006 81 #define VMBUS_CHANPKT_TYPE_RXBUF 0x0007 82 #define VMBUS_CHANPKT_TYPE_GPA 0x0009 83 #define VMBUS_CHANPKT_TYPE_COMP 0x000b 84 85 #define VMBUS_CHANPKT_FLAG_RC 0x0001 /* report completion */ 86 87 #define VMBUS_CHANPKT_CONST_DATA(pkt) \ 88 (const void *)((const uint8_t *)(pkt) + \ 89 VMBUS_CHANPKT_GETLEN((pkt)->cph_hlen)) 90 91 struct vmbus_rxbuf_desc { 92 uint32_t rb_len; 93 uint32_t rb_ofs; 94 } __packed; 95 96 struct vmbus_chanpkt_rxbuf { 97 struct vmbus_chanpkt_hdr cp_hdr; 98 uint16_t cp_rxbuf_id; 99 uint16_t cp_rsvd; 100 uint32_t cp_rxbuf_cnt; 101 struct vmbus_rxbuf_desc cp_rxbuf[]; 102 } __packed; 103 104 #define VMBUS_CHAN_SGLIST_MAX 32 105 #define VMBUS_CHAN_PRPLIST_MAX 32 106 107 struct vmbus_channel; 108 struct hyperv_guid; 109 110 typedef void (*vmbus_chan_callback_t)(struct vmbus_channel *, void *); 111 112 static __inline struct vmbus_channel * 113 vmbus_get_channel(device_t dev) 114 { 115 return device_get_ivars(dev); 116 } 117 118 int vmbus_chan_open(struct vmbus_channel *chan, 119 int txbr_size, int rxbr_size, const void *udata, int udlen, 120 vmbus_chan_callback_t cb, void *cbarg); 121 void vmbus_chan_close(struct vmbus_channel *chan); 122 123 int vmbus_chan_gpadl_connect(struct vmbus_channel *chan, 124 bus_addr_t paddr, int size, uint32_t *gpadl); 125 int vmbus_chan_gpadl_disconnect(struct vmbus_channel *chan, 126 uint32_t gpadl); 127 128 void vmbus_chan_cpu_set(struct vmbus_channel *chan, int cpu); 129 void vmbus_chan_cpu_rr(struct vmbus_channel *chan); 130 struct vmbus_channel * 131 vmbus_chan_cpu2chan(struct vmbus_channel *chan, int cpu); 132 void vmbus_chan_set_readbatch(struct vmbus_channel *chan, bool on); 133 134 struct vmbus_channel ** 135 vmbus_subchan_get(struct vmbus_channel *pri_chan, int subchan_cnt); 136 void vmbus_subchan_rel(struct vmbus_channel **subchan, int subchan_cnt); 137 void vmbus_subchan_drain(struct vmbus_channel *pri_chan); 138 139 int vmbus_chan_recv(struct vmbus_channel *chan, void *data, int *dlen, 140 uint64_t *xactid); 141 int vmbus_chan_recv_pkt(struct vmbus_channel *chan, 142 struct vmbus_chanpkt_hdr *pkt, int *pktlen); 143 144 int vmbus_chan_send(struct vmbus_channel *chan, uint16_t type, 145 uint16_t flags, void *data, int dlen, uint64_t xactid); 146 int vmbus_chan_send_sglist(struct vmbus_channel *chan, 147 struct vmbus_gpa sg[], int sglen, void *data, int dlen, 148 uint64_t xactid); 149 int vmbus_chan_send_prplist(struct vmbus_channel *chan, 150 struct vmbus_gpa_range *prp, int prp_cnt, void *data, int dlen, 151 uint64_t xactid); 152 153 uint32_t vmbus_chan_id(const struct vmbus_channel *chan); 154 uint32_t vmbus_chan_subidx(const struct vmbus_channel *chan); 155 bool vmbus_chan_is_primary(const struct vmbus_channel *chan); 156 const struct hyperv_guid * 157 vmbus_chan_guid_inst(const struct vmbus_channel *chan); 158 159 #endif /* !_VMBUS_H_ */ 160