]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/hyperv/netvsc/hv_net_vsc.h
MFC 307012,307013,307262
[FreeBSD/stable/10.git] / sys / dev / hyperv / netvsc / hv_net_vsc.h
1 /*-
2  * Copyright (c) 2009-2012,2016 Microsoft Corp.
3  * Copyright (c) 2010-2012 Citrix Inc.
4  * Copyright (c) 2012 NetApp Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30
31 /*
32  * HyperV vmbus (virtual machine bus) network VSC (virtual services client)
33  * header file
34  *
35  * (Updated from unencumbered NvspProtocol.h)
36  */
37
38 #ifndef __HV_NET_VSC_H__
39 #define __HV_NET_VSC_H__
40
41 #include <sys/param.h>
42 #include <sys/kernel.h>
43 #include <sys/lock.h>
44 #include <sys/malloc.h>
45 #include <sys/queue.h>
46 #include <sys/taskqueue.h>
47 #include <sys/sema.h>
48 #include <sys/sx.h>
49
50 #include <machine/bus.h>
51 #include <sys/bus.h>
52 #include <sys/bus_dma.h>
53
54 #include <netinet/in.h>
55 #include <netinet/tcp_lro.h>
56
57 #include <net/ethernet.h>
58 #include <net/if.h>
59 #include <net/if_media.h>
60
61 #include <dev/hyperv/include/hyperv.h>
62 #include <dev/hyperv/include/hyperv_busdma.h>
63 #include <dev/hyperv/include/vmbus.h>
64
65 #include <dev/hyperv/netvsc/ndis.h>
66
67 #define HN_USE_TXDESC_BUFRING
68
69 MALLOC_DECLARE(M_NETVSC);
70
71 /*
72  * The following arguably belongs in a separate header file
73  */
74
75 /*
76  * Defines
77  */
78
79 #define NETVSC_SEND_BUFFER_SIZE                 (1024*1024*15)   /* 15M */
80
81 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY       (1024*1024*15) /* 15MB */
82 #define NETVSC_RECEIVE_BUFFER_SIZE              (1024*1024*16) /* 16MB */
83
84 /*
85  * Maximum MTU we permit to be configured for a netvsc interface.
86  * When the code was developed, a max MTU of 12232 was tested and
87  * proven to work.  9K is a reasonable maximum for an Ethernet.
88  */
89 #define NETVSC_MAX_CONFIGURABLE_MTU             (9 * 1024)
90
91 #define NETVSC_PACKET_SIZE                      PAGE_SIZE
92
93 /*
94  * Data types
95  */
96
97 struct vmbus_channel;
98
99 #define NETVSC_DEVICE_RING_BUFFER_SIZE  (128 * PAGE_SIZE)
100 #define NETVSC_PACKET_MAXPAGE           32
101
102 #define HN_XACT_REQ_PGCNT               2
103 #define HN_XACT_RESP_PGCNT              2
104 #define HN_XACT_REQ_SIZE                (HN_XACT_REQ_PGCNT * PAGE_SIZE)
105 #define HN_XACT_RESP_SIZE               (HN_XACT_RESP_PGCNT * PAGE_SIZE)
106
107 #ifndef HN_USE_TXDESC_BUFRING
108 struct hn_txdesc;
109 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
110 #else
111 struct buf_ring;
112 #endif
113
114 struct hn_tx_ring;
115
116 struct hn_rx_ring {
117         struct ifnet    *hn_ifp;
118         struct hn_tx_ring *hn_txr;
119         void            *hn_rdbuf;
120         uint8_t         *hn_rxbuf;      /* shadow sc->hn_rxbuf */
121         int             hn_rx_idx;
122
123         /* Trust csum verification on host side */
124         int             hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
125         struct lro_ctrl hn_lro;
126
127         u_long          hn_csum_ip;
128         u_long          hn_csum_tcp;
129         u_long          hn_csum_udp;
130         u_long          hn_csum_trusted;
131         u_long          hn_lro_tried;
132         u_long          hn_small_pkts;
133         u_long          hn_pkts;
134         u_long          hn_rss_pkts;
135
136         /* Rarely used stuffs */
137         struct sysctl_oid *hn_rx_sysctl_tree;
138         int             hn_rx_flags;
139
140         void            *hn_br;         /* TX/RX bufring */
141         struct hyperv_dma hn_br_dma;
142 } __aligned(CACHE_LINE_SIZE);
143
144 #define HN_TRUST_HCSUM_IP       0x0001
145 #define HN_TRUST_HCSUM_TCP      0x0002
146 #define HN_TRUST_HCSUM_UDP      0x0004
147
148 #define HN_RX_FLAG_ATTACHED     0x1
149
150 struct hn_tx_ring {
151 #ifndef HN_USE_TXDESC_BUFRING
152         struct mtx      hn_txlist_spin;
153         struct hn_txdesc_list hn_txlist;
154 #else
155         struct buf_ring *hn_txdesc_br;
156 #endif
157         int             hn_txdesc_cnt;
158         int             hn_txdesc_avail;
159         u_short         hn_has_txeof;
160         u_short         hn_txdone_cnt;
161
162         int             hn_sched_tx;
163         void            (*hn_txeof)(struct hn_tx_ring *);
164         struct taskqueue *hn_tx_taskq;
165         struct task     hn_tx_task;
166         struct task     hn_txeof_task;
167
168         struct buf_ring *hn_mbuf_br;
169         int             hn_oactive;
170         int             hn_tx_idx;
171         int             hn_tx_flags;
172
173         struct mtx      hn_tx_lock;
174         struct hn_softc *hn_sc;
175         struct vmbus_channel *hn_chan;
176
177         int             hn_direct_tx_size;
178         int             hn_chim_size;
179         bus_dma_tag_t   hn_tx_data_dtag;
180         uint64_t        hn_csum_assist;
181
182         int             hn_suspended;
183         int             hn_gpa_cnt;
184         struct vmbus_gpa hn_gpa[NETVSC_PACKET_MAXPAGE];
185
186         u_long          hn_no_txdescs;
187         u_long          hn_send_failed;
188         u_long          hn_txdma_failed;
189         u_long          hn_tx_collapsed;
190         u_long          hn_tx_chimney_tried;
191         u_long          hn_tx_chimney;
192         u_long          hn_pkts;
193
194         /* Rarely used stuffs */
195         struct hn_txdesc *hn_txdesc;
196         bus_dma_tag_t   hn_tx_rndis_dtag;
197         struct sysctl_oid *hn_tx_sysctl_tree;
198 } __aligned(CACHE_LINE_SIZE);
199
200 #define HN_TX_FLAG_ATTACHED     0x1
201 #define HN_TX_FLAG_HASHVAL      0x2     /* support HASHVAL pktinfo */
202
203 /*
204  * Device-specific softc structure
205  */
206 struct hn_softc {
207         struct ifnet    *hn_ifp;
208         struct arpcom   arpcom;
209         struct ifmedia  hn_media;
210         device_t        hn_dev;
211         int             hn_carrier;
212         int             hn_if_flags;
213         struct sx       hn_lock;
214         struct vmbus_channel *hn_prichan;
215
216         int             hn_rx_ring_cnt;
217         int             hn_rx_ring_inuse;
218         struct hn_rx_ring *hn_rx_ring;
219
220         int             hn_tx_ring_cnt;
221         int             hn_tx_ring_inuse;
222         struct hn_tx_ring *hn_tx_ring;
223
224         uint8_t         *hn_chim;
225         u_long          *hn_chim_bmap;
226         int             hn_chim_bmap_cnt;
227         int             hn_chim_cnt;
228         int             hn_chim_szmax;
229
230         int             hn_cpu;
231         struct taskqueue *hn_tx_taskq;
232         struct sysctl_oid *hn_tx_sysctl_tree;
233         struct sysctl_oid *hn_rx_sysctl_tree;
234         struct vmbus_xact_ctx *hn_xact;
235         uint32_t        hn_nvs_ver;
236
237         struct taskqueue        *hn_mgmt_taskq;
238         struct taskqueue        *hn_mgmt_taskq0;
239         struct task             hn_link_task;
240
241         uint32_t                hn_caps;        /* HN_CAP_ */
242         uint32_t                hn_flags;       /* HN_FLAG_ */
243         void                    *hn_rxbuf;
244         uint32_t                hn_rxbuf_gpadl;
245         struct hyperv_dma       hn_rxbuf_dma;
246
247         uint32_t                hn_chim_gpadl;
248         struct hyperv_dma       hn_chim_dma;
249
250         uint32_t                hn_rndis_rid;
251         uint32_t                hn_ndis_ver;
252         int                     hn_ndis_tso_szmax;
253         int                     hn_ndis_tso_sgmin;
254
255         struct ndis_rssprm_toeplitz hn_rss;
256 };
257
258 #define HN_FLAG_RXBUF_CONNECTED         0x0001
259 #define HN_FLAG_CHIM_CONNECTED          0x0002
260 #define HN_FLAG_HAS_RSSKEY              0x0004
261 #define HN_FLAG_HAS_RSSIND              0x0008
262 #define HN_FLAG_SYNTH_ATTACHED          0x0010
263
264 #define HN_CAP_VLAN                     0x0001
265 #define HN_CAP_MTU                      0x0002
266 #define HN_CAP_IPCS                     0x0004
267 #define HN_CAP_TCP4CS                   0x0008
268 #define HN_CAP_TCP6CS                   0x0010
269 #define HN_CAP_UDP4CS                   0x0020
270 #define HN_CAP_UDP6CS                   0x0040
271 #define HN_CAP_TSO4                     0x0080
272 #define HN_CAP_TSO6                     0x0100
273
274 /*
275  * Externs
276  */
277 struct hn_send_ctx;
278
279 int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
280         struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
281
282 #endif  /* __HV_NET_VSC_H__ */
283