vmbus.h revision 307599
1145256Sjkoshy/*- 2177107Sjkoshy * Copyright (c) 2016 Microsoft Corp. 3145256Sjkoshy * All rights reserved. 4145256Sjkoshy * 5145256Sjkoshy * Redistribution and use in source and binary forms, with or without 6145256Sjkoshy * modification, are permitted provided that the following conditions 7145256Sjkoshy * are met: 8145256Sjkoshy * 1. Redistributions of source code must retain the above copyright 9145256Sjkoshy * notice unmodified, this list of conditions, and the following 10145256Sjkoshy * disclaimer. 11145256Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright 12145256Sjkoshy * notice, this list of conditions and the following disclaimer in the 13145256Sjkoshy * documentation and/or other materials provided with the distribution. 14145256Sjkoshy * 15145256Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16145256Sjkoshy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17145256Sjkoshy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18145256Sjkoshy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19145256Sjkoshy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20145256Sjkoshy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21145256Sjkoshy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22145256Sjkoshy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23145256Sjkoshy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24145256Sjkoshy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25145256Sjkoshy * 26145256Sjkoshy * $FreeBSD: stable/11/sys/dev/hyperv/include/vmbus.h 307599 2016-10-19 02:24:17Z sephe $ 27145256Sjkoshy */ 28145256Sjkoshy 29145256Sjkoshy#ifndef _VMBUS_H_ 30145256Sjkoshy#define _VMBUS_H_ 31145256Sjkoshy 32145256Sjkoshy#include <sys/param.h> 33145256Sjkoshy#include <sys/bus.h> 34145256Sjkoshy 35145256Sjkoshy/* 36145256Sjkoshy * VMBUS version is 32 bit, upper 16 bit for major_number and lower 37145256Sjkoshy * 16 bit for minor_number. 38145256Sjkoshy * 39145256Sjkoshy * 0.13 -- Windows Server 2008 40145256Sjkoshy * 1.1 -- Windows 7 41145256Sjkoshy * 2.4 -- Windows 8 42145256Sjkoshy * 3.0 -- Windows 8.1 43145256Sjkoshy */ 44145256Sjkoshy#define VMBUS_VERSION_WS2008 ((0 << 16) | (13)) 45185363Sjkoshy#define VMBUS_VERSION_WIN7 ((1 << 16) | (1)) 46185363Sjkoshy#define VMBUS_VERSION_WIN8 ((2 << 16) | (4)) 47145256Sjkoshy#define VMBUS_VERSION_WIN8_1 ((3 << 16) | (0)) 48145340Smarcel 49145256Sjkoshy#define VMBUS_VERSION_MAJOR(ver) (((uint32_t)(ver)) >> 16) 50145256Sjkoshy#define VMBUS_VERSION_MINOR(ver) (((uint32_t)(ver)) & 0xffff) 51147191Sjkoshy 52147759Sjkoshy/* 53185363Sjkoshy * GPA stuffs. 54185363Sjkoshy */ 55185363Sjkoshystruct vmbus_gpa_range { 56185363Sjkoshy uint32_t gpa_len; 57206089Sfabient uint32_t gpa_ofs; 58206089Sfabient uint64_t gpa_page[0]; 59206089Sfabient} __packed; 60206089Sfabient 61147191Sjkoshy/* This is actually vmbus_gpa_range.gpa_page[1] */ 62145256Sjkoshystruct vmbus_gpa { 63147759Sjkoshy uint32_t gpa_len; 64147759Sjkoshy uint32_t gpa_ofs; 65147191Sjkoshy uint64_t gpa_page; 66147191Sjkoshy} __packed; 67145256Sjkoshy 68145256Sjkoshy#define VMBUS_CHANPKT_SIZE_SHIFT 3 69147191Sjkoshy 70145256Sjkoshy#define VMBUS_CHANPKT_GETLEN(pktlen) \ 71145256Sjkoshy (((int)(pktlen)) << VMBUS_CHANPKT_SIZE_SHIFT) 72183725Sjkoshy 73183725Sjkoshystruct vmbus_chanpkt_hdr { 74183725Sjkoshy uint16_t cph_type; /* VMBUS_CHANPKT_TYPE_ */ 75183725Sjkoshy uint16_t cph_hlen; /* header len, in 8 bytes */ 76200928Srpaulo uint16_t cph_tlen; /* total len, in 8 bytes */ 77200928Srpaulo uint16_t cph_flags; /* VMBUS_CHANPKT_FLAG_ */ 78200928Srpaulo uint64_t cph_xactid; 79200928Srpaulo} __packed; 80145256Sjkoshy 81204635Sgnn#define VMBUS_CHANPKT_TYPE_INBAND 0x0006 82204635Sgnn#define VMBUS_CHANPKT_TYPE_RXBUF 0x0007 83204635Sgnn#define VMBUS_CHANPKT_TYPE_GPA 0x0009 84204635Sgnn#define VMBUS_CHANPKT_TYPE_COMP 0x000b 85204635Sgnn 86228869Sjhibbits#define VMBUS_CHANPKT_FLAG_NONE 0 87228869Sjhibbits#define VMBUS_CHANPKT_FLAG_RC 0x0001 /* report completion */ 88228869Sjhibbits 89228869Sjhibbits#define VMBUS_CHANPKT_CONST_DATA(pkt) \ 90204635Sgnn (const void *)((const uint8_t *)(pkt) + \ 91145256Sjkoshy VMBUS_CHANPKT_GETLEN((pkt)->cph_hlen)) 92145256Sjkoshy 93145256Sjkoshy/* Include padding */ 94145256Sjkoshy#define VMBUS_CHANPKT_DATALEN(pkt) \ 95145256Sjkoshy (VMBUS_CHANPKT_GETLEN((pkt)->cph_tlen) -\ 96145256Sjkoshy VMBUS_CHANPKT_GETLEN((pkt)->cph_hlen)) 97145256Sjkoshy 98145256Sjkoshystruct vmbus_rxbuf_desc { 99145256Sjkoshy uint32_t rb_len; 100145256Sjkoshy uint32_t rb_ofs; 101145256Sjkoshy} __packed; 102145256Sjkoshy 103145256Sjkoshystruct vmbus_chanpkt_rxbuf { 104145256Sjkoshy struct vmbus_chanpkt_hdr cp_hdr; 105145256Sjkoshy uint16_t cp_rxbuf_id; 106145256Sjkoshy uint16_t cp_rsvd; 107145256Sjkoshy uint32_t cp_rxbuf_cnt; 108183725Sjkoshy struct vmbus_rxbuf_desc cp_rxbuf[]; 109145256Sjkoshy} __packed; 110145256Sjkoshy 111145256Sjkoshystruct vmbus_chan_br { 112145256Sjkoshy void *cbr; 113145256Sjkoshy bus_addr_t cbr_paddr; 114145256Sjkoshy int cbr_txsz; 115145256Sjkoshy int cbr_rxsz; 116183725Sjkoshy}; 117183725Sjkoshy 118183725Sjkoshystruct vmbus_channel; 119183725Sjkoshystruct hyperv_guid; 120183725Sjkoshy 121183725Sjkoshytypedef void (*vmbus_chan_callback_t)(struct vmbus_channel *, void *); 122183725Sjkoshy 123183725Sjkoshystatic __inline struct vmbus_channel * 124183725Sjkoshyvmbus_get_channel(device_t dev) 125183725Sjkoshy{ 126183725Sjkoshy return device_get_ivars(dev); 127183725Sjkoshy} 128183725Sjkoshy 129183725Sjkoshyint vmbus_chan_open(struct vmbus_channel *chan, 130183725Sjkoshy int txbr_size, int rxbr_size, const void *udata, int udlen, 131183725Sjkoshy vmbus_chan_callback_t cb, void *cbarg); 132183725Sjkoshyint vmbus_chan_open_br(struct vmbus_channel *chan, 133183725Sjkoshy const struct vmbus_chan_br *cbr, const void *udata, 134183725Sjkoshy int udlen, vmbus_chan_callback_t cb, void *cbarg); 135183725Sjkoshyvoid vmbus_chan_close(struct vmbus_channel *chan); 136183725Sjkoshyvoid vmbus_chan_intr_drain(struct vmbus_channel *chan); 137185363Sjkoshy 138183725Sjkoshyint vmbus_chan_gpadl_connect(struct vmbus_channel *chan, 139185363Sjkoshy bus_addr_t paddr, int size, uint32_t *gpadl); 140183725Sjkoshyint vmbus_chan_gpadl_disconnect(struct vmbus_channel *chan, 141185363Sjkoshy uint32_t gpadl); 142183725Sjkoshy 143183725Sjkoshyvoid vmbus_chan_cpu_set(struct vmbus_channel *chan, int cpu); 144183725Sjkoshyvoid vmbus_chan_cpu_rr(struct vmbus_channel *chan); 145185363Sjkoshystruct vmbus_channel * 146185363Sjkoshy vmbus_chan_cpu2chan(struct vmbus_channel *chan, int cpu); 147185363Sjkoshyvoid vmbus_chan_set_readbatch(struct vmbus_channel *chan, bool on); 148185363Sjkoshy 149185363Sjkoshystruct vmbus_channel ** 150185363Sjkoshy vmbus_subchan_get(struct vmbus_channel *pri_chan, 151185363Sjkoshy int subchan_cnt); 152185363Sjkoshyvoid vmbus_subchan_rel(struct vmbus_channel **subchan, 153200928Srpaulo int subchan_cnt); 154204635Sgnnvoid vmbus_subchan_drain(struct vmbus_channel *pri_chan); 155206089Sfabient 156228869Sjhibbitsint vmbus_chan_recv(struct vmbus_channel *chan, void *data, int *dlen, 157185363Sjkoshy uint64_t *xactid); 158185363Sjkoshyint vmbus_chan_recv_pkt(struct vmbus_channel *chan, 159185363Sjkoshy struct vmbus_chanpkt_hdr *pkt, int *pktlen); 160185363Sjkoshy 161185363Sjkoshyint vmbus_chan_send(struct vmbus_channel *chan, uint16_t type, 162185363Sjkoshy uint16_t flags, void *data, int dlen, uint64_t xactid); 163185363Sjkoshyint vmbus_chan_send_sglist(struct vmbus_channel *chan, 164185363Sjkoshy struct vmbus_gpa sg[], int sglen, void *data, int dlen, 165185363Sjkoshy uint64_t xactid); 166185363Sjkoshyint vmbus_chan_send_prplist(struct vmbus_channel *chan, 167185363Sjkoshy struct vmbus_gpa_range *prp, int prp_cnt, void *data, 168185363Sjkoshy int dlen, uint64_t xactid); 169185363Sjkoshy 170185363Sjkoshyuint32_t vmbus_chan_id(const struct vmbus_channel *chan); 171185363Sjkoshyuint32_t vmbus_chan_subidx(const struct vmbus_channel *chan); 172185363Sjkoshybool vmbus_chan_is_primary(const struct vmbus_channel *chan); 173185363Sjkoshyconst struct hyperv_guid * 174185363Sjkoshy vmbus_chan_guid_inst(const struct vmbus_channel *chan); 175185363Sjkoshyint vmbus_chan_prplist_nelem(int br_size, int prpcnt_max, 176185363Sjkoshy int dlen_max); 177187761Sjeffbool vmbus_chan_rx_empty(const struct vmbus_channel *chan); 178187761Sjeffbool vmbus_chan_tx_empty(const struct vmbus_channel *chan); 179187761Sjeff 180187761Sjeff#endif /* !_VMBUS_H_ */ 181187761Sjeff