hn_nvs.h revision 308505
1228753Smm/*- 2228753Smm * Copyright (c) 2009-2012,2016 Microsoft Corp. 3228753Smm * Copyright (c) 2010-2012 Citrix Inc. 4228753Smm * Copyright (c) 2012 NetApp Inc. 5228753Smm * All rights reserved. 6228753Smm * 7228753Smm * Redistribution and use in source and binary forms, with or without 8228753Smm * modification, are permitted provided that the following conditions 9228753Smm * are met: 10228753Smm * 1. Redistributions of source code must retain the above copyright 11228753Smm * notice unmodified, this list of conditions, and the following 12228753Smm * disclaimer. 13228753Smm * 2. Redistributions in binary form must reproduce the above copyright 14228753Smm * notice, this list of conditions and the following disclaimer in the 15228753Smm * documentation and/or other materials provided with the distribution. 16228753Smm * 17228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20228753Smm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26228763Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27228753Smm * 28228753Smm * $FreeBSD: stable/10/sys/dev/hyperv/netvsc/hn_nvs.h 308505 2016-11-11 05:53:58Z sephe $ 29232153Smm */ 30228753Smm 31228753Smm#ifndef _HN_NVS_H_ 32232153Smm#define _HN_NVS_H_ 33232153Smm 34228753Smmstruct hn_nvs_sendctx; 35232153Smmstruct vmbus_channel; 36228753Smmstruct hn_softc; 37228753Smm 38228753Smmtypedef void (*hn_nvs_sent_t) 39228753Smm (struct hn_nvs_sendctx *, struct hn_softc *, 40228753Smm struct vmbus_channel *, const void *, int); 41228753Smm 42228753Smmstruct hn_nvs_sendctx { 43228753Smm hn_nvs_sent_t hn_cb; 44232153Smm void *hn_cbarg; 45228753Smm}; 46228753Smm 47232153Smm#define HN_NVS_SENDCTX_INITIALIZER(cb, cbarg) \ 48232153Smm{ \ 49232153Smm .hn_cb = cb, \ 50232153Smm .hn_cbarg = cbarg \ 51232153Smm} 52232153Smm 53232153Smmstatic __inline void 54228753Smmhn_nvs_sendctx_init(struct hn_nvs_sendctx *sndc, hn_nvs_sent_t cb, void *cbarg) 55232153Smm{ 56228753Smm 57228753Smm sndc->hn_cb = cb; 58228753Smm sndc->hn_cbarg = cbarg; 59228753Smm} 60228753Smm 61228753Smmstatic __inline int 62228753Smmhn_nvs_send(struct vmbus_channel *chan, uint16_t flags, 63228753Smm void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc) 64228753Smm{ 65228753Smm 66228753Smm return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags, 67228753Smm nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc)); 68228753Smm} 69228753Smm 70228753Smmstatic __inline int 71228753Smmhn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen, 72228753Smm void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc) 73228753Smm{ 74232153Smm 75228753Smm return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen, 76232153Smm (uint64_t)(uintptr_t)sndc)); 77228753Smm} 78228753Smm 79232153Smmstatic __inline int 80228753Smmhn_nvs_send_rndis_sglist(struct vmbus_channel *chan, uint32_t rndis_mtype, 81228753Smm struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) 82228753Smm{ 83228753Smm struct hn_nvs_rndis rndis; 84228753Smm 85228753Smm rndis.nvs_type = HN_NVS_TYPE_RNDIS; 86228753Smm rndis.nvs_rndis_mtype = rndis_mtype; 87228753Smm rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID; 88228753Smm rndis.nvs_chim_sz = 0; 89228753Smm 90228753Smm return (hn_nvs_send_sglist(chan, gpa, gpa_cnt, 91228753Smm &rndis, sizeof(rndis), sndc)); 92228753Smm} 93228753Smm 94228753Smmint hn_nvs_attach(struct hn_softc *sc, int mtu); 95228753Smmvoid hn_nvs_detach(struct hn_softc *sc); 96228753Smmint hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch); 97228753Smmvoid hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc, 98228753Smm struct hn_softc *sc, struct vmbus_channel *chan, 99228753Smm const void *data, int dlen); 100228753Smmint hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan, 101228753Smm struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, 102228753Smm int gpa_cnt); 103228753Smm 104228753Smmextern struct hn_nvs_sendctx hn_nvs_sendctx_none; 105228753Smm 106228753Smm#endif /* !_HN_NVS_H_ */ 107228753Smm