aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/hyperv/vmbus/vmbus_brvar.h
blob: bd967f6e869b8e45e56785bff76cdc13d2d36459 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*-
 * Copyright (c) 2009-2012,2016 Microsoft Corp.
 * Copyright (c) 2012 NetApp Inc.
 * Copyright (c) 2012 Citrix Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _VMBUS_BRVAR_H_
#define _VMBUS_BRVAR_H_

#include <sys/param.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/_iovec.h>

struct vmbus_br {
	struct vmbus_bufring	*vbr;
	uint32_t		vbr_dsize;	/* total data size */
};

#define vbr_windex		vbr->br_windex
#define vbr_rindex		vbr->br_rindex
#define vbr_imask		vbr->br_imask
#define vbr_data		vbr->br_data

struct vmbus_rxbr {
	struct mtx		rxbr_lock;
	struct vmbus_br		rxbr;
};

#define rxbr_windex		rxbr.vbr_windex
#define rxbr_rindex		rxbr.vbr_rindex
#define rxbr_imask		rxbr.vbr_imask
#define rxbr_data		rxbr.vbr_data
#define rxbr_dsize		rxbr.vbr_dsize

struct vmbus_txbr {
	struct mtx		txbr_lock;
	struct vmbus_br		txbr;
};

#define txbr_windex		txbr.vbr_windex
#define txbr_rindex		txbr.vbr_rindex
#define txbr_imask		txbr.vbr_imask
#define txbr_data		txbr.vbr_data
#define txbr_dsize		txbr.vbr_dsize

struct sysctl_ctx_list;
struct sysctl_oid;

static __inline int
vmbus_txbr_maxpktsz(const struct vmbus_txbr *tbr)
{

	/*
	 * - 64 bits for the trailing start index (- sizeof(uint64_t)).
	 * - The rindex and windex can't be same (- 1).  See
	 *   the comment near vmbus_bufring.br_{r,w}index.
	 */
	return (tbr->txbr_dsize - sizeof(uint64_t) - 1);
}

static __inline int
vmbus_br_nelem(int br_size, int elem_size)
{

	/* Strip bufring header */
	br_size -= sizeof(struct vmbus_bufring);
	/* Add per-element trailing index */
	elem_size += sizeof(uint64_t);
	return (br_size / elem_size);
}

void		vmbus_br_sysctl_create(struct sysctl_ctx_list *ctx,
		    struct sysctl_oid *br_tree, struct vmbus_br *br,
		    const char *name);

void		vmbus_rxbr_init(struct vmbus_rxbr *rbr);
void		vmbus_rxbr_deinit(struct vmbus_rxbr *rbr);
void		vmbus_rxbr_setup(struct vmbus_rxbr *rbr, void *buf, int blen);
int		vmbus_rxbr_peek(struct vmbus_rxbr *rbr, void *data, int dlen);
int		vmbus_rxbr_read(struct vmbus_rxbr *rbr, void *data, int dlen,
		    uint32_t skip);
void		vmbus_rxbr_intr_mask(struct vmbus_rxbr *rbr);
uint32_t	vmbus_rxbr_intr_unmask(struct vmbus_rxbr *rbr);

void		vmbus_txbr_init(struct vmbus_txbr *tbr);
void		vmbus_txbr_deinit(struct vmbus_txbr *tbr);
void		vmbus_txbr_setup(struct vmbus_txbr *tbr, void *buf, int blen);
int		vmbus_txbr_write(struct vmbus_txbr *tbr,
		    const struct iovec iov[], int iovlen, boolean_t *need_sig);

#endif  /* _VMBUS_BRVAR_H_ */