]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/hyperv/netvsc/hv_net_vsc.h
MFC 305454,305455,305521,305524-305526
[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 #define NVSP_INVALID_PROTOCOL_VERSION           (0xFFFFFFFF)
72
73 #define NVSP_PROTOCOL_VERSION_1                 2
74 #define NVSP_PROTOCOL_VERSION_2                 0x30002
75 #define NVSP_PROTOCOL_VERSION_4                 0x40000
76 #define NVSP_PROTOCOL_VERSION_5                 0x50000
77
78 /*
79  * The following arguably belongs in a separate header file
80  */
81
82 /*
83  * Defines
84  */
85
86 #define NETVSC_SEND_BUFFER_SIZE                 (1024*1024*15)   /* 15M */
87
88 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY       (1024*1024*15) /* 15MB */
89 #define NETVSC_RECEIVE_BUFFER_SIZE              (1024*1024*16) /* 16MB */
90
91 /*
92  * Maximum MTU we permit to be configured for a netvsc interface.
93  * When the code was developed, a max MTU of 12232 was tested and
94  * proven to work.  9K is a reasonable maximum for an Ethernet.
95  */
96 #define NETVSC_MAX_CONFIGURABLE_MTU             (9 * 1024)
97
98 #define NETVSC_PACKET_SIZE                      PAGE_SIZE
99
100 /*
101  * Data types
102  */
103
104 struct vmbus_channel;
105
106 #define NETVSC_DEVICE_RING_BUFFER_SIZE  (128 * PAGE_SIZE)
107 #define NETVSC_PACKET_MAXPAGE           32
108
109 typedef struct {
110         uint8_t         mac_addr[ETHER_ADDR_LEN];
111         uint32_t        link_state;
112 } netvsc_device_info;
113
114 #define HN_XACT_REQ_PGCNT               2
115 #define HN_XACT_RESP_PGCNT              2
116 #define HN_XACT_REQ_SIZE                (HN_XACT_REQ_PGCNT * PAGE_SIZE)
117 #define HN_XACT_RESP_SIZE               (HN_XACT_RESP_PGCNT * PAGE_SIZE)
118
119 #ifndef HN_USE_TXDESC_BUFRING
120 struct hn_txdesc;
121 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
122 #else
123 struct buf_ring;
124 #endif
125
126 struct hn_tx_ring;
127
128 struct hn_rx_ring {
129         struct ifnet    *hn_ifp;
130         struct hn_tx_ring *hn_txr;
131         void            *hn_rdbuf;
132         uint8_t         *hn_rxbuf;      /* shadow sc->hn_rxbuf */
133         int             hn_rx_idx;
134
135         /* Trust csum verification on host side */
136         int             hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
137         struct lro_ctrl hn_lro;
138
139         u_long          hn_csum_ip;
140         u_long          hn_csum_tcp;
141         u_long          hn_csum_udp;
142         u_long          hn_csum_trusted;
143         u_long          hn_lro_tried;
144         u_long          hn_small_pkts;
145         u_long          hn_pkts;
146         u_long          hn_rss_pkts;
147
148         /* Rarely used stuffs */
149         struct sysctl_oid *hn_rx_sysctl_tree;
150         int             hn_rx_flags;
151 } __aligned(CACHE_LINE_SIZE);
152
153 #define HN_TRUST_HCSUM_IP       0x0001
154 #define HN_TRUST_HCSUM_TCP      0x0002
155 #define HN_TRUST_HCSUM_UDP      0x0004
156
157 #define HN_RX_FLAG_ATTACHED     0x1
158
159 struct hn_tx_ring {
160 #ifndef HN_USE_TXDESC_BUFRING
161         struct mtx      hn_txlist_spin;
162         struct hn_txdesc_list hn_txlist;
163 #else
164         struct buf_ring *hn_txdesc_br;
165 #endif
166         int             hn_txdesc_cnt;
167         int             hn_txdesc_avail;
168         u_short         hn_has_txeof;
169         u_short         hn_txdone_cnt;
170
171         int             hn_sched_tx;
172         void            (*hn_txeof)(struct hn_tx_ring *);
173         struct taskqueue *hn_tx_taskq;
174         struct task     hn_tx_task;
175         struct task     hn_txeof_task;
176
177         struct buf_ring *hn_mbuf_br;
178         int             hn_oactive;
179         int             hn_tx_idx;
180
181         struct mtx      hn_tx_lock;
182         struct hn_softc *hn_sc;
183         struct vmbus_channel *hn_chan;
184
185         int             hn_direct_tx_size;
186         int             hn_chim_size;
187         bus_dma_tag_t   hn_tx_data_dtag;
188         uint64_t        hn_csum_assist;
189
190         int             hn_gpa_cnt;
191         struct vmbus_gpa hn_gpa[NETVSC_PACKET_MAXPAGE];
192
193         u_long          hn_no_txdescs;
194         u_long          hn_send_failed;
195         u_long          hn_txdma_failed;
196         u_long          hn_tx_collapsed;
197         u_long          hn_tx_chimney_tried;
198         u_long          hn_tx_chimney;
199         u_long          hn_pkts;
200
201         /* Rarely used stuffs */
202         struct hn_txdesc *hn_txdesc;
203         bus_dma_tag_t   hn_tx_rndis_dtag;
204         struct sysctl_oid *hn_tx_sysctl_tree;
205         int             hn_tx_flags;
206 } __aligned(CACHE_LINE_SIZE);
207
208 #define HN_TX_FLAG_ATTACHED     0x1
209
210 /*
211  * Device-specific softc structure
212  */
213 typedef struct hn_softc {
214         struct ifnet    *hn_ifp;
215         struct arpcom   arpcom;
216         struct ifmedia  hn_media;
217         device_t        hn_dev;
218         uint8_t         hn_unit;
219         int             hn_carrier;
220         int             hn_if_flags;
221         struct mtx      hn_lock;
222         int             hn_initdone;
223         /* See hv_netvsc_drv_freebsd.c for rules on how to use */
224         int             temp_unusable;
225         struct vmbus_channel *hn_prichan;
226
227         int             hn_rx_ring_cnt;
228         int             hn_rx_ring_inuse;
229         struct hn_rx_ring *hn_rx_ring;
230
231         int             hn_tx_ring_cnt;
232         int             hn_tx_ring_inuse;
233         struct hn_tx_ring *hn_tx_ring;
234
235         uint8_t         *hn_chim;
236         u_long          *hn_chim_bmap;
237         int             hn_chim_bmap_cnt;
238         int             hn_chim_cnt;
239         int             hn_chim_szmax;
240
241         int             hn_cpu;
242         struct taskqueue *hn_tx_taskq;
243         struct sysctl_oid *hn_tx_sysctl_tree;
244         struct sysctl_oid *hn_rx_sysctl_tree;
245         struct vmbus_xact_ctx *hn_xact;
246         uint32_t        hn_nvs_ver;
247
248         uint32_t                hn_flags;
249         void                    *hn_rxbuf;
250         uint32_t                hn_rxbuf_gpadl;
251         struct hyperv_dma       hn_rxbuf_dma;
252
253         uint32_t                hn_chim_gpadl;
254         struct hyperv_dma       hn_chim_dma;
255
256         uint32_t                hn_rndis_rid;
257         uint32_t                hn_ndis_ver;
258
259         struct ndis_rssprm_toeplitz hn_rss;
260 } hn_softc_t;
261
262 #define HN_FLAG_RXBUF_CONNECTED         0x0001
263 #define HN_FLAG_CHIM_CONNECTED          0x0002
264
265 /*
266  * Externs
267  */
268 extern int hv_promisc_mode;
269 struct hn_send_ctx;
270
271 void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
272 int hv_nv_on_device_add(struct hn_softc *sc, struct hn_rx_ring *rxr);
273 int hv_nv_on_device_remove(struct hn_softc *sc);
274 int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
275         struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
276 void hv_nv_subchan_attach(struct vmbus_channel *chan,
277     struct hn_rx_ring *rxr);
278
279 #endif  /* __HV_NET_VSC_H__ */
280