17dd8881cSSepherosa Ziehau /*- 27dd8881cSSepherosa Ziehau * Copyright (c) 2009-2012,2016 Microsoft Corp. 37dd8881cSSepherosa Ziehau * Copyright (c) 2012 NetApp Inc. 47dd8881cSSepherosa Ziehau * Copyright (c) 2012 Citrix Inc. 57dd8881cSSepherosa Ziehau * All rights reserved. 67dd8881cSSepherosa Ziehau * 77dd8881cSSepherosa Ziehau * Redistribution and use in source and binary forms, with or without 87dd8881cSSepherosa Ziehau * modification, are permitted provided that the following conditions 97dd8881cSSepherosa Ziehau * are met: 107dd8881cSSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright 117dd8881cSSepherosa Ziehau * notice unmodified, this list of conditions, and the following 127dd8881cSSepherosa Ziehau * disclaimer. 137dd8881cSSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright 147dd8881cSSepherosa Ziehau * notice, this list of conditions and the following disclaimer in the 157dd8881cSSepherosa Ziehau * documentation and/or other materials provided with the distribution. 167dd8881cSSepherosa Ziehau * 177dd8881cSSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 187dd8881cSSepherosa Ziehau * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 197dd8881cSSepherosa Ziehau * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 207dd8881cSSepherosa Ziehau * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 217dd8881cSSepherosa Ziehau * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 227dd8881cSSepherosa Ziehau * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237dd8881cSSepherosa Ziehau * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247dd8881cSSepherosa Ziehau * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257dd8881cSSepherosa Ziehau * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 267dd8881cSSepherosa Ziehau * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277dd8881cSSepherosa Ziehau * 287dd8881cSSepherosa Ziehau * $FreeBSD$ 297dd8881cSSepherosa Ziehau */ 307dd8881cSSepherosa Ziehau 31afffab7eSSepherosa Ziehau #ifndef _VMBUS_BRVAR_H_ 32afffab7eSSepherosa Ziehau #define _VMBUS_BRVAR_H_ 337dd8881cSSepherosa Ziehau 347dd8881cSSepherosa Ziehau #include <sys/param.h> 357dd8881cSSepherosa Ziehau #include <sys/lock.h> 367dd8881cSSepherosa Ziehau #include <sys/mutex.h> 377dd8881cSSepherosa Ziehau #include <sys/_iovec.h> 387dd8881cSSepherosa Ziehau 39ea06b5d3SSepherosa Ziehau struct vmbus_br { 40ea06b5d3SSepherosa Ziehau struct vmbus_bufring *vbr; 41ea06b5d3SSepherosa Ziehau uint32_t vbr_dsize; /* total data size */ 42ea06b5d3SSepherosa Ziehau }; 43ea06b5d3SSepherosa Ziehau 44ea06b5d3SSepherosa Ziehau #define vbr_windex vbr->br_windex 45ea06b5d3SSepherosa Ziehau #define vbr_rindex vbr->br_rindex 46ea06b5d3SSepherosa Ziehau #define vbr_imask vbr->br_imask 47ea06b5d3SSepherosa Ziehau #define vbr_data vbr->br_data 48ea06b5d3SSepherosa Ziehau 49ea06b5d3SSepherosa Ziehau struct vmbus_rxbr { 50ea06b5d3SSepherosa Ziehau struct mtx rxbr_lock; 51ea06b5d3SSepherosa Ziehau struct vmbus_br rxbr; 52ea06b5d3SSepherosa Ziehau }; 53ea06b5d3SSepherosa Ziehau 54ea06b5d3SSepherosa Ziehau #define rxbr_windex rxbr.vbr_windex 55ea06b5d3SSepherosa Ziehau #define rxbr_rindex rxbr.vbr_rindex 56ea06b5d3SSepherosa Ziehau #define rxbr_imask rxbr.vbr_imask 57ea06b5d3SSepherosa Ziehau #define rxbr_data rxbr.vbr_data 58ea06b5d3SSepherosa Ziehau #define rxbr_dsize rxbr.vbr_dsize 59ea06b5d3SSepherosa Ziehau 60ea06b5d3SSepherosa Ziehau struct vmbus_txbr { 61ea06b5d3SSepherosa Ziehau struct mtx txbr_lock; 62ea06b5d3SSepherosa Ziehau struct vmbus_br txbr; 63ea06b5d3SSepherosa Ziehau }; 64ea06b5d3SSepherosa Ziehau 65ea06b5d3SSepherosa Ziehau #define txbr_windex txbr.vbr_windex 66ea06b5d3SSepherosa Ziehau #define txbr_rindex txbr.vbr_rindex 67ea06b5d3SSepherosa Ziehau #define txbr_imask txbr.vbr_imask 68ea06b5d3SSepherosa Ziehau #define txbr_data txbr.vbr_data 69ea06b5d3SSepherosa Ziehau #define txbr_dsize txbr.vbr_dsize 707dd8881cSSepherosa Ziehau 717dd8881cSSepherosa Ziehau struct sysctl_ctx_list; 727dd8881cSSepherosa Ziehau struct sysctl_oid; 737dd8881cSSepherosa Ziehau 749d6016a7SSepherosa Ziehau static __inline int 759d6016a7SSepherosa Ziehau vmbus_txbr_maxpktsz(const struct vmbus_txbr *tbr) 769d6016a7SSepherosa Ziehau { 77*6fd14eb9SSepherosa Ziehau /* 78*6fd14eb9SSepherosa Ziehau * - 64 bits for the trailing start index (- sizeof(uint64_t)). 79*6fd14eb9SSepherosa Ziehau * - The rindex and windex can't be same (- 1). See 80*6fd14eb9SSepherosa Ziehau * the comment near vmbus_bufring.br_{r,w}index. 81*6fd14eb9SSepherosa Ziehau */ 82*6fd14eb9SSepherosa Ziehau return (tbr->txbr_dsize - sizeof(uint64_t) - 1); 839d6016a7SSepherosa Ziehau } 849d6016a7SSepherosa Ziehau 857dd8881cSSepherosa Ziehau void vmbus_br_sysctl_create(struct sysctl_ctx_list *ctx, 86ea06b5d3SSepherosa Ziehau struct sysctl_oid *br_tree, struct vmbus_br *br, 877dd8881cSSepherosa Ziehau const char *name); 887dd8881cSSepherosa Ziehau 89ea06b5d3SSepherosa Ziehau void vmbus_rxbr_init(struct vmbus_rxbr *rbr); 90ea06b5d3SSepherosa Ziehau void vmbus_rxbr_deinit(struct vmbus_rxbr *rbr); 91ea06b5d3SSepherosa Ziehau void vmbus_rxbr_setup(struct vmbus_rxbr *rbr, void *buf, int blen); 92ea06b5d3SSepherosa Ziehau int vmbus_rxbr_peek(struct vmbus_rxbr *rbr, void *data, int dlen); 93ea06b5d3SSepherosa Ziehau int vmbus_rxbr_read(struct vmbus_rxbr *rbr, void *data, int dlen, 94b5ddb409SSepherosa Ziehau uint32_t skip); 95ea06b5d3SSepherosa Ziehau void vmbus_rxbr_intr_mask(struct vmbus_rxbr *rbr); 96ea06b5d3SSepherosa Ziehau uint32_t vmbus_rxbr_intr_unmask(struct vmbus_rxbr *rbr); 977dd8881cSSepherosa Ziehau 98ea06b5d3SSepherosa Ziehau void vmbus_txbr_init(struct vmbus_txbr *tbr); 99ea06b5d3SSepherosa Ziehau void vmbus_txbr_deinit(struct vmbus_txbr *tbr); 100ea06b5d3SSepherosa Ziehau void vmbus_txbr_setup(struct vmbus_txbr *tbr, void *buf, int blen); 101ea06b5d3SSepherosa Ziehau int vmbus_txbr_write(struct vmbus_txbr *tbr, 102ea06b5d3SSepherosa Ziehau const struct iovec iov[], int iovlen, boolean_t *need_sig); 1037dd8881cSSepherosa Ziehau 104afffab7eSSepherosa Ziehau #endif /* _VMBUS_BRVAR_H_ */ 105