Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 *
4 * Copyright (c) 2011, Microsoft Corporation.
5 *
6 * Authors:
7 * Haiyang Zhang <haiyangz@microsoft.com>
8 * Hank Janssen <hjanssen@microsoft.com>
9 * K. Y. Srinivasan <kys@microsoft.com>
10 */
11
12#ifndef _HYPERV_NET_H
13#define _HYPERV_NET_H
14
15#include <linux/list.h>
16#include <linux/hyperv.h>
17#include <linux/rndis.h>
18
19/* RSS related */
20#define OID_GEN_RECEIVE_SCALE_CAPABILITIES 0x00010203 /* query only */
21#define OID_GEN_RECEIVE_SCALE_PARAMETERS 0x00010204 /* query and set */
22
23#define NDIS_OBJECT_TYPE_RSS_CAPABILITIES 0x88
24#define NDIS_OBJECT_TYPE_RSS_PARAMETERS 0x89
25#define NDIS_OBJECT_TYPE_OFFLOAD 0xa7
26
27#define NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2
28#define NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2
29
30struct ndis_obj_header {
31 u8 type;
32 u8 rev;
33 u16 size;
34} __packed;
35
36/* ndis_recv_scale_cap/cap_flag */
37#define NDIS_RSS_CAPS_MESSAGE_SIGNALED_INTERRUPTS 0x01000000
38#define NDIS_RSS_CAPS_CLASSIFICATION_AT_ISR 0x02000000
39#define NDIS_RSS_CAPS_CLASSIFICATION_AT_DPC 0x04000000
40#define NDIS_RSS_CAPS_USING_MSI_X 0x08000000
41#define NDIS_RSS_CAPS_RSS_AVAILABLE_ON_PORTS 0x10000000
42#define NDIS_RSS_CAPS_SUPPORTS_MSI_X 0x20000000
43#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV4 0x00000100
44#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6 0x00000200
45#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6_EX 0x00000400
46
47struct ndis_recv_scale_cap { /* NDIS_RECEIVE_SCALE_CAPABILITIES */
48 struct ndis_obj_header hdr;
49 u32 cap_flag;
50 u32 num_int_msg;
51 u32 num_recv_que;
52 u16 num_indirect_tabent;
53} __packed;
54
55
56/* ndis_recv_scale_param flags */
57#define NDIS_RSS_PARAM_FLAG_BASE_CPU_UNCHANGED 0x0001
58#define NDIS_RSS_PARAM_FLAG_HASH_INFO_UNCHANGED 0x0002
59#define NDIS_RSS_PARAM_FLAG_ITABLE_UNCHANGED 0x0004
60#define NDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED 0x0008
61#define NDIS_RSS_PARAM_FLAG_DISABLE_RSS 0x0010
62
63/* Hash info bits */
64#define NDIS_HASH_FUNC_TOEPLITZ 0x00000001
65#define NDIS_HASH_IPV4 0x00000100
66#define NDIS_HASH_TCP_IPV4 0x00000200
67#define NDIS_HASH_IPV6 0x00000400
68#define NDIS_HASH_IPV6_EX 0x00000800
69#define NDIS_HASH_TCP_IPV6 0x00001000
70#define NDIS_HASH_TCP_IPV6_EX 0x00002000
71
72#define NDIS_RSS_INDIRECTION_TABLE_MAX_SIZE_REVISION_2 (128 * 4)
73#define NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2 40
74
75#define ITAB_NUM 128
76
77struct ndis_recv_scale_param { /* NDIS_RECEIVE_SCALE_PARAMETERS */
78 struct ndis_obj_header hdr;
79
80 /* Qualifies the rest of the information */
81 u16 flag;
82
83 /* The base CPU number to do receive processing. not used */
84 u16 base_cpu_number;
85
86 /* This describes the hash function and type being enabled */
87 u32 hashinfo;
88
89 /* The size of indirection table array */
90 u16 indirect_tabsize;
91
92 /* The offset of the indirection table from the beginning of this
93 * structure
94 */
95 u32 indirect_taboffset;
96
97 /* The size of the hash secret key */
98 u16 hashkey_size;
99
100 /* The offset of the secret key from the beginning of this structure */
101 u32 hashkey_offset;
102
103 u32 processor_masks_offset;
104 u32 num_processor_masks;
105 u32 processor_masks_entry_size;
106};
107
108struct ndis_tcp_ip_checksum_info {
109 union {
110 struct {
111 u32 is_ipv4:1;
112 u32 is_ipv6:1;
113 u32 tcp_checksum:1;
114 u32 udp_checksum:1;
115 u32 ip_header_checksum:1;
116 u32 reserved:11;
117 u32 tcp_header_offset:10;
118 } transmit;
119 struct {
120 u32 tcp_checksum_failed:1;
121 u32 udp_checksum_failed:1;
122 u32 ip_checksum_failed:1;
123 u32 tcp_checksum_succeeded:1;
124 u32 udp_checksum_succeeded:1;
125 u32 ip_checksum_succeeded:1;
126 u32 loopback:1;
127 u32 tcp_checksum_value_invalid:1;
128 u32 ip_checksum_value_invalid:1;
129 } receive;
130 u32 value;
131 };
132};
133
134struct ndis_pkt_8021q_info {
135 union {
136 struct {
137 u32 pri:3; /* User Priority */
138 u32 cfi:1; /* Canonical Format ID */
139 u32 vlanid:12; /* VLAN ID */
140 u32 reserved:16;
141 };
142 u32 value;
143 };
144};
145
146/*
147 * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
148 * within the RNDIS
149 *
150 * The size of this structure is less than 48 bytes and we can now
151 * place this structure in the skb->cb field.
152 */
153struct hv_netvsc_packet {
154 /* Bookkeeping stuff */
155 u8 cp_partial; /* partial copy into send buffer */
156
157 u8 rmsg_size; /* RNDIS header and PPI size */
158 u8 rmsg_pgcnt; /* page count of RNDIS header and PPI */
159 u8 page_buf_cnt;
160
161 u16 q_idx;
162 u16 total_packets;
163
164 u32 total_bytes;
165 u32 send_buf_index;
166 u32 total_data_buflen;
167 struct hv_dma_range *dma_range;
168};
169
170#define NETVSC_HASH_KEYLEN 40
171
172struct netvsc_device_info {
173 unsigned char mac_adr[ETH_ALEN];
174 u32 num_chn;
175 u32 send_sections;
176 u32 recv_sections;
177 u32 send_section_size;
178 u32 recv_section_size;
179
180 struct bpf_prog *bprog;
181
182 u8 rss_key[NETVSC_HASH_KEYLEN];
183};
184
185enum rndis_device_state {
186 RNDIS_DEV_UNINITIALIZED = 0,
187 RNDIS_DEV_INITIALIZING,
188 RNDIS_DEV_INITIALIZED,
189 RNDIS_DEV_DATAINITIALIZED,
190};
191
192struct rndis_device {
193 struct net_device *ndev;
194
195 enum rndis_device_state state;
196
197 atomic_t new_req_id;
198
199 spinlock_t request_lock;
200 struct list_head req_list;
201
202 struct work_struct mcast_work;
203 u32 filter;
204
205 bool link_state; /* 0 - link up, 1 - link down */
206
207 u8 hw_mac_adr[ETH_ALEN];
208 u8 rss_key[NETVSC_HASH_KEYLEN];
209};
210
211
212/* Interface */
213struct rndis_message;
214struct ndis_offload_params;
215struct netvsc_device;
216struct netvsc_channel;
217struct net_device_context;
218
219extern u32 netvsc_ring_bytes;
220
221struct netvsc_device *netvsc_device_add(struct hv_device *device,
222 const struct netvsc_device_info *info);
223int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx);
224void netvsc_device_remove(struct hv_device *device);
225int netvsc_send(struct net_device *net,
226 struct hv_netvsc_packet *packet,
227 struct rndis_message *rndis_msg,
228 struct hv_page_buffer *page_buffer,
229 struct sk_buff *skb,
230 bool xdp_tx);
231void netvsc_linkstatus_callback(struct net_device *net,
232 struct rndis_message *resp,
233 void *data, u32 data_buflen);
234int netvsc_recv_callback(struct net_device *net,
235 struct netvsc_device *nvdev,
236 struct netvsc_channel *nvchan);
237void netvsc_channel_cb(void *context);
238int netvsc_poll(struct napi_struct *napi, int budget);
239
240u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan,
241 struct xdp_buff *xdp);
242unsigned int netvsc_xdp_fraglen(unsigned int len);
243struct bpf_prog *netvsc_xdp_get(struct netvsc_device *nvdev);
244int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog,
245 struct netlink_ext_ack *extack,
246 struct netvsc_device *nvdev);
247int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog);
248int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf);
249
250int rndis_set_subchannel(struct net_device *ndev,
251 struct netvsc_device *nvdev,
252 struct netvsc_device_info *dev_info);
253int rndis_filter_open(struct netvsc_device *nvdev);
254int rndis_filter_close(struct netvsc_device *nvdev);
255struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
256 struct netvsc_device_info *info);
257void rndis_filter_update(struct netvsc_device *nvdev);
258void rndis_filter_device_remove(struct hv_device *dev,
259 struct netvsc_device *nvdev);
260int rndis_filter_set_rss_param(struct rndis_device *rdev,
261 const u8 *key);
262int rndis_filter_set_offload_params(struct net_device *ndev,
263 struct netvsc_device *nvdev,
264 struct ndis_offload_params *req_offloads);
265int rndis_filter_receive(struct net_device *ndev,
266 struct netvsc_device *net_dev,
267 struct netvsc_channel *nvchan,
268 void *data, u32 buflen);
269
270int rndis_filter_set_device_mac(struct netvsc_device *ndev,
271 const char *mac);
272
273int netvsc_switch_datapath(struct net_device *nv_dev, bool vf);
274
275#define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
276
277#define NVSP_PROTOCOL_VERSION_1 2
278#define NVSP_PROTOCOL_VERSION_2 0x30002
279#define NVSP_PROTOCOL_VERSION_4 0x40000
280#define NVSP_PROTOCOL_VERSION_5 0x50000
281#define NVSP_PROTOCOL_VERSION_6 0x60000
282#define NVSP_PROTOCOL_VERSION_61 0x60001
283
284enum {
285 NVSP_MSG_TYPE_NONE = 0,
286
287 /* Init Messages */
288 NVSP_MSG_TYPE_INIT = 1,
289 NVSP_MSG_TYPE_INIT_COMPLETE = 2,
290
291 NVSP_VERSION_MSG_START = 100,
292
293 /* Version 1 Messages */
294 NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START,
295
296 NVSP_MSG1_TYPE_SEND_RECV_BUF,
297 NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
298 NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
299
300 NVSP_MSG1_TYPE_SEND_SEND_BUF,
301 NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
302 NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
303
304 NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
305 NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
306
307 /* Version 2 messages */
308 NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF,
309 NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF_COMP,
310 NVSP_MSG2_TYPE_REVOKE_CHIMNEY_DELEGATED_BUF,
311
312 NVSP_MSG2_TYPE_RESUME_CHIMNEY_RX_INDICATION,
313
314 NVSP_MSG2_TYPE_TERMINATE_CHIMNEY,
315 NVSP_MSG2_TYPE_TERMINATE_CHIMNEY_COMP,
316
317 NVSP_MSG2_TYPE_INDICATE_CHIMNEY_EVENT,
318
319 NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT,
320 NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT_COMP,
321
322 NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ,
323 NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ_COMP,
324
325 NVSP_MSG2_TYPE_ALLOC_RXBUF,
326 NVSP_MSG2_TYPE_ALLOC_RXBUF_COMP,
327
328 NVSP_MSG2_TYPE_FREE_RXBUF,
329
330 NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT,
331 NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT_COMP,
332
333 NVSP_MSG2_TYPE_SEND_NDIS_CONFIG,
334
335 NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE,
336 NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
337
338 NVSP_MSG2_MAX = NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
339
340 /* Version 4 messages */
341 NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION,
342 NVSP_MSG4_TYPE_SWITCH_DATA_PATH,
343 NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
344
345 NVSP_MSG4_MAX = NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
346
347 /* Version 5 messages */
348 NVSP_MSG5_TYPE_OID_QUERY_EX,
349 NVSP_MSG5_TYPE_OID_QUERY_EX_COMP,
350 NVSP_MSG5_TYPE_SUBCHANNEL,
351 NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
352
353 NVSP_MSG5_MAX = NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
354
355 /* Version 6 messages */
356 NVSP_MSG6_TYPE_PD_API,
357 NVSP_MSG6_TYPE_PD_POST_BATCH,
358
359 NVSP_MSG6_MAX = NVSP_MSG6_TYPE_PD_POST_BATCH
360};
361
362enum {
363 NVSP_STAT_NONE = 0,
364 NVSP_STAT_SUCCESS,
365 NVSP_STAT_FAIL,
366 NVSP_STAT_PROTOCOL_TOO_NEW,
367 NVSP_STAT_PROTOCOL_TOO_OLD,
368 NVSP_STAT_INVALID_RNDIS_PKT,
369 NVSP_STAT_BUSY,
370 NVSP_STAT_PROTOCOL_UNSUPPORTED,
371 NVSP_STAT_MAX,
372};
373
374struct nvsp_message_header {
375 u32 msg_type;
376};
377
378/* Init Messages */
379
380/*
381 * This message is used by the VSC to initialize the channel after the channels
382 * has been opened. This message should never include anything other then
383 * versioning (i.e. this message will be the same for ever).
384 */
385struct nvsp_message_init {
386 u32 min_protocol_ver;
387 u32 max_protocol_ver;
388} __packed;
389
390/*
391 * This message is used by the VSP to complete the initialization of the
392 * channel. This message should never include anything other then versioning
393 * (i.e. this message will be the same for ever).
394 */
395struct nvsp_message_init_complete {
396 u32 negotiated_protocol_ver;
397 u32 max_mdl_chain_len;
398 u32 status;
399} __packed;
400
401union nvsp_message_init_uber {
402 struct nvsp_message_init init;
403 struct nvsp_message_init_complete init_complete;
404} __packed;
405
406/* Version 1 Messages */
407
408/*
409 * This message is used by the VSC to send the NDIS version to the VSP. The VSP
410 * can use this information when handling OIDs sent by the VSC.
411 */
412struct nvsp_1_message_send_ndis_version {
413 u32 ndis_major_ver;
414 u32 ndis_minor_ver;
415} __packed;
416
417/*
418 * This message is used by the VSC to send a receive buffer to the VSP. The VSP
419 * can then use the receive buffer to send data to the VSC.
420 */
421struct nvsp_1_message_send_receive_buffer {
422 u32 gpadl_handle;
423 u16 id;
424} __packed;
425
426struct nvsp_1_receive_buffer_section {
427 u32 offset;
428 u32 sub_alloc_size;
429 u32 num_sub_allocs;
430 u32 end_offset;
431} __packed;
432
433/*
434 * This message is used by the VSP to acknowledge a receive buffer send by the
435 * VSC. This message must be sent by the VSP before the VSP uses the receive
436 * buffer.
437 */
438struct nvsp_1_message_send_receive_buffer_complete {
439 u32 status;
440 u32 num_sections;
441
442 /*
443 * The receive buffer is split into two parts, a large suballocation
444 * section and a small suballocation section. These sections are then
445 * suballocated by a certain size.
446 */
447
448 /*
449 * For example, the following break up of the receive buffer has 6
450 * large suballocations and 10 small suballocations.
451 */
452
453 /*
454 * | Large Section | | Small Section |
455 * ------------------------------------------------------------
456 * | | | | | | | | | | | | | | | | | |
457 * | |
458 * LargeOffset SmallOffset
459 */
460
461 struct nvsp_1_receive_buffer_section sections[1];
462} __packed;
463
464/*
465 * This message is sent by the VSC to revoke the receive buffer. After the VSP
466 * completes this transaction, the vsp should never use the receive buffer
467 * again.
468 */
469struct nvsp_1_message_revoke_receive_buffer {
470 u16 id;
471};
472
473/*
474 * This message is used by the VSC to send a send buffer to the VSP. The VSC
475 * can then use the send buffer to send data to the VSP.
476 */
477struct nvsp_1_message_send_send_buffer {
478 u32 gpadl_handle;
479 u16 id;
480} __packed;
481
482/*
483 * This message is used by the VSP to acknowledge a send buffer sent by the
484 * VSC. This message must be sent by the VSP before the VSP uses the sent
485 * buffer.
486 */
487struct nvsp_1_message_send_send_buffer_complete {
488 u32 status;
489
490 /*
491 * The VSC gets to choose the size of the send buffer and the VSP gets
492 * to choose the sections size of the buffer. This was done to enable
493 * dynamic reconfigurations when the cost of GPA-direct buffers
494 * decreases.
495 */
496 u32 section_size;
497} __packed;
498
499/*
500 * This message is sent by the VSC to revoke the send buffer. After the VSP
501 * completes this transaction, the vsp should never use the send buffer again.
502 */
503struct nvsp_1_message_revoke_send_buffer {
504 u16 id;
505};
506
507/*
508 * This message is used by both the VSP and the VSC to send a RNDIS message to
509 * the opposite channel endpoint.
510 */
511struct nvsp_1_message_send_rndis_packet {
512 /*
513 * This field is specified by RNDIS. They assume there's two different
514 * channels of communication. However, the Network VSP only has one.
515 * Therefore, the channel travels with the RNDIS packet.
516 */
517 u32 channel_type;
518
519 /*
520 * This field is used to send part or all of the data through a send
521 * buffer. This values specifies an index into the send buffer. If the
522 * index is 0xFFFFFFFF, then the send buffer is not being used and all
523 * of the data was sent through other VMBus mechanisms.
524 */
525 u32 send_buf_section_index;
526 u32 send_buf_section_size;
527} __packed;
528
529/*
530 * This message is used by both the VSP and the VSC to complete a RNDIS message
531 * to the opposite channel endpoint. At this point, the initiator of this
532 * message cannot use any resources associated with the original RNDIS packet.
533 */
534struct nvsp_1_message_send_rndis_packet_complete {
535 u32 status;
536};
537
538union nvsp_1_message_uber {
539 struct nvsp_1_message_send_ndis_version send_ndis_ver;
540
541 struct nvsp_1_message_send_receive_buffer send_recv_buf;
542 struct nvsp_1_message_send_receive_buffer_complete
543 send_recv_buf_complete;
544 struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
545
546 struct nvsp_1_message_send_send_buffer send_send_buf;
547 struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
548 struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
549
550 struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
551 struct nvsp_1_message_send_rndis_packet_complete
552 send_rndis_pkt_complete;
553} __packed;
554
555
556/*
557 * Network VSP protocol version 2 messages:
558 */
559struct nvsp_2_vsc_capability {
560 union {
561 u64 data;
562 struct {
563 u64 vmq:1;
564 u64 chimney:1;
565 u64 sriov:1;
566 u64 ieee8021q:1;
567 u64 correlation_id:1;
568 u64 teaming:1;
569 u64 vsubnetid:1;
570 u64 rsc:1;
571 };
572 };
573} __packed;
574
575struct nvsp_2_send_ndis_config {
576 u32 mtu;
577 u32 reserved;
578 struct nvsp_2_vsc_capability capability;
579} __packed;
580
581/* Allocate receive buffer */
582struct nvsp_2_alloc_rxbuf {
583 /* Allocation ID to match the allocation request and response */
584 u32 alloc_id;
585
586 /* Length of the VM shared memory receive buffer that needs to
587 * be allocated
588 */
589 u32 len;
590} __packed;
591
592/* Allocate receive buffer complete */
593struct nvsp_2_alloc_rxbuf_comp {
594 /* The NDIS_STATUS code for buffer allocation */
595 u32 status;
596
597 u32 alloc_id;
598
599 /* GPADL handle for the allocated receive buffer */
600 u32 gpadl_handle;
601
602 /* Receive buffer ID */
603 u64 recv_buf_id;
604} __packed;
605
606struct nvsp_2_free_rxbuf {
607 u64 recv_buf_id;
608} __packed;
609
610union nvsp_2_message_uber {
611 struct nvsp_2_send_ndis_config send_ndis_config;
612 struct nvsp_2_alloc_rxbuf alloc_rxbuf;
613 struct nvsp_2_alloc_rxbuf_comp alloc_rxbuf_comp;
614 struct nvsp_2_free_rxbuf free_rxbuf;
615} __packed;
616
617struct nvsp_4_send_vf_association {
618 /* 1: allocated, serial number is valid. 0: not allocated */
619 u32 allocated;
620
621 /* Serial number of the VF to team with */
622 u32 serial;
623} __packed;
624
625enum nvsp_vm_datapath {
626 NVSP_DATAPATH_SYNTHETIC = 0,
627 NVSP_DATAPATH_VF,
628 NVSP_DATAPATH_MAX
629};
630
631struct nvsp_4_sw_datapath {
632 u32 active_datapath; /* active data path in VM */
633} __packed;
634
635union nvsp_4_message_uber {
636 struct nvsp_4_send_vf_association vf_assoc;
637 struct nvsp_4_sw_datapath active_dp;
638} __packed;
639
640enum nvsp_subchannel_operation {
641 NVSP_SUBCHANNEL_NONE = 0,
642 NVSP_SUBCHANNEL_ALLOCATE,
643 NVSP_SUBCHANNEL_MAX
644};
645
646struct nvsp_5_subchannel_request {
647 u32 op;
648 u32 num_subchannels;
649} __packed;
650
651struct nvsp_5_subchannel_complete {
652 u32 status;
653 u32 num_subchannels; /* Actual number of subchannels allocated */
654} __packed;
655
656struct nvsp_5_send_indirect_table {
657 /* The number of entries in the send indirection table */
658 u32 count;
659
660 /* The offset of the send indirection table from the beginning of
661 * struct nvsp_message.
662 * The send indirection table tells which channel to put the send
663 * traffic on. Each entry is a channel number.
664 */
665 u32 offset;
666} __packed;
667
668union nvsp_5_message_uber {
669 struct nvsp_5_subchannel_request subchn_req;
670 struct nvsp_5_subchannel_complete subchn_comp;
671 struct nvsp_5_send_indirect_table send_table;
672} __packed;
673
674enum nvsp_6_pd_api_op {
675 PD_API_OP_CONFIG = 1,
676 PD_API_OP_SW_DATAPATH, /* Switch Datapath */
677 PD_API_OP_OPEN_PROVIDER,
678 PD_API_OP_CLOSE_PROVIDER,
679 PD_API_OP_CREATE_QUEUE,
680 PD_API_OP_FLUSH_QUEUE,
681 PD_API_OP_FREE_QUEUE,
682 PD_API_OP_ALLOC_COM_BUF, /* Allocate Common Buffer */
683 PD_API_OP_FREE_COM_BUF, /* Free Common Buffer */
684 PD_API_OP_MAX
685};
686
687struct grp_affinity {
688 u64 mask;
689 u16 grp;
690 u16 reserved[3];
691} __packed;
692
693struct nvsp_6_pd_api_req {
694 u32 op;
695
696 union {
697 /* MMIO information is sent from the VM to VSP */
698 struct __packed {
699 u64 mmio_pa; /* MMIO Physical Address */
700 u32 mmio_len;
701
702 /* Number of PD queues a VM can support */
703 u16 num_subchn;
704 } config;
705
706 /* Switch Datapath */
707 struct __packed {
708 /* Host Datapath Is PacketDirect */
709 u8 host_dpath_is_pd;
710
711 /* Guest PacketDirect Is Enabled */
712 u8 guest_pd_enabled;
713 } sw_dpath;
714
715 /* Open Provider*/
716 struct __packed {
717 u32 prov_id; /* Provider id */
718 u32 flag;
719 } open_prov;
720
721 /* Close Provider */
722 struct __packed {
723 u32 prov_id;
724 } cls_prov;
725
726 /* Create Queue*/
727 struct __packed {
728 u32 prov_id;
729 u16 q_id;
730 u16 q_size;
731 u8 is_recv_q;
732 u8 is_rss_q;
733 u32 recv_data_len;
734 struct grp_affinity affy;
735 } cr_q;
736
737 /* Delete Queue*/
738 struct __packed {
739 u32 prov_id;
740 u16 q_id;
741 } del_q;
742
743 /* Flush Queue */
744 struct __packed {
745 u32 prov_id;
746 u16 q_id;
747 } flush_q;
748
749 /* Allocate Common Buffer */
750 struct __packed {
751 u32 len;
752 u32 pf_node; /* Preferred Node */
753 u16 region_id;
754 } alloc_com_buf;
755
756 /* Free Common Buffer */
757 struct __packed {
758 u32 len;
759 u64 pa; /* Physical Address */
760 u32 pf_node; /* Preferred Node */
761 u16 region_id;
762 u8 cache_type;
763 } free_com_buf;
764 } __packed;
765} __packed;
766
767struct nvsp_6_pd_api_comp {
768 u32 op;
769 u32 status;
770
771 union {
772 struct __packed {
773 /* actual number of PD queues allocated to the VM */
774 u16 num_pd_q;
775
776 /* Num Receive Rss PD Queues */
777 u8 num_rss_q;
778
779 u8 is_supported; /* Is supported by VSP */
780 u8 is_enabled; /* Is enabled by VSP */
781 } config;
782
783 /* Open Provider */
784 struct __packed {
785 u32 prov_id;
786 } open_prov;
787
788 /* Create Queue */
789 struct __packed {
790 u32 prov_id;
791 u16 q_id;
792 u16 q_size;
793 u32 recv_data_len;
794 struct grp_affinity affy;
795 } cr_q;
796
797 /* Allocate Common Buffer */
798 struct __packed {
799 u64 pa; /* Physical Address */
800 u32 len;
801 u32 pf_node; /* Preferred Node */
802 u16 region_id;
803 u8 cache_type;
804 } alloc_com_buf;
805 } __packed;
806} __packed;
807
808struct nvsp_6_pd_buf {
809 u32 region_offset;
810 u16 region_id;
811 u16 is_partial:1;
812 u16 reserved:15;
813} __packed;
814
815struct nvsp_6_pd_batch_msg {
816 struct nvsp_message_header hdr;
817 u16 count;
818 u16 guest2host:1;
819 u16 is_recv:1;
820 u16 reserved:14;
821 struct nvsp_6_pd_buf pd_buf[0];
822} __packed;
823
824union nvsp_6_message_uber {
825 struct nvsp_6_pd_api_req pd_req;
826 struct nvsp_6_pd_api_comp pd_comp;
827} __packed;
828
829union nvsp_all_messages {
830 union nvsp_message_init_uber init_msg;
831 union nvsp_1_message_uber v1_msg;
832 union nvsp_2_message_uber v2_msg;
833 union nvsp_4_message_uber v4_msg;
834 union nvsp_5_message_uber v5_msg;
835 union nvsp_6_message_uber v6_msg;
836} __packed;
837
838/* ALL Messages */
839struct nvsp_message {
840 struct nvsp_message_header hdr;
841 union nvsp_all_messages msg;
842} __packed;
843
844
845#define NETVSC_MTU 65535
846#define NETVSC_MTU_MIN ETH_MIN_MTU
847
848/* Max buffer sizes allowed by a host */
849#define NETVSC_RECEIVE_BUFFER_SIZE (1024 * 1024 * 31) /* 31MB */
850#define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024 * 1024 * 15) /* 15MB */
851#define NETVSC_RECEIVE_BUFFER_DEFAULT (1024 * 1024 * 16)
852
853#define NETVSC_SEND_BUFFER_SIZE (1024 * 1024 * 15) /* 15MB */
854#define NETVSC_SEND_BUFFER_DEFAULT (1024 * 1024)
855
856#define NETVSC_INVALID_INDEX -1
857
858#define NETVSC_SEND_SECTION_SIZE 6144
859#define NETVSC_RECV_SECTION_SIZE 1728
860
861/* Default size of TX buf: 1MB, RX buf: 16MB */
862#define NETVSC_MIN_TX_SECTIONS 10
863#define NETVSC_DEFAULT_TX (NETVSC_SEND_BUFFER_DEFAULT \
864 / NETVSC_SEND_SECTION_SIZE)
865#define NETVSC_MIN_RX_SECTIONS 10
866#define NETVSC_DEFAULT_RX (NETVSC_RECEIVE_BUFFER_DEFAULT \
867 / NETVSC_RECV_SECTION_SIZE)
868
869#define NETVSC_RECEIVE_BUFFER_ID 0xcafe
870#define NETVSC_SEND_BUFFER_ID 0
871
872#define NETVSC_SUPPORTED_HW_FEATURES (NETIF_F_RXCSUM | NETIF_F_IP_CSUM | \
873 NETIF_F_TSO | NETIF_F_IPV6_CSUM | \
874 NETIF_F_TSO6 | NETIF_F_LRO | \
875 NETIF_F_SG | NETIF_F_RXHASH)
876
877#define VRSS_SEND_TAB_SIZE 16 /* must be power of 2 */
878#define VRSS_CHANNEL_MAX 64
879#define VRSS_CHANNEL_DEFAULT 8
880
881#define RNDIS_MAX_PKT_DEFAULT 8
882#define RNDIS_PKT_ALIGN_DEFAULT 8
883
884#define NETVSC_XDP_HDRM 256
885
886#define NETVSC_MIN_OUT_MSG_SIZE (sizeof(struct vmpacket_descriptor) + \
887 sizeof(struct nvsp_message))
888#define NETVSC_MIN_IN_MSG_SIZE sizeof(struct vmpacket_descriptor)
889
890/* Estimated requestor size:
891 * out_ring_size/min_out_msg_size + in_ring_size/min_in_msg_size
892 */
893static inline u32 netvsc_rqstor_size(unsigned long ringbytes)
894{
895 return ringbytes / NETVSC_MIN_OUT_MSG_SIZE +
896 ringbytes / NETVSC_MIN_IN_MSG_SIZE;
897}
898
899/* XFER PAGE packets can specify a maximum of 375 ranges for NDIS >= 6.0
900 * and a maximum of 64 ranges for NDIS < 6.0 with no RSC; with RSC, this
901 * limit is raised to 562 (= NVSP_RSC_MAX).
902 */
903#define NETVSC_MAX_XFER_PAGE_RANGES NVSP_RSC_MAX
904#define NETVSC_XFER_HEADER_SIZE(rng_cnt) \
905 (offsetof(struct vmtransfer_page_packet_header, ranges) + \
906 (rng_cnt) * sizeof(struct vmtransfer_page_range))
907#define NETVSC_MAX_PKT_SIZE (NETVSC_XFER_HEADER_SIZE(NETVSC_MAX_XFER_PAGE_RANGES) + \
908 sizeof(struct nvsp_message) + (sizeof(u32) * VRSS_SEND_TAB_SIZE))
909
910struct multi_send_data {
911 struct sk_buff *skb; /* skb containing the pkt */
912 struct hv_netvsc_packet *pkt; /* netvsc pkt pending */
913 u32 count; /* counter of batched packets */
914};
915
916struct recv_comp_data {
917 u64 tid; /* transaction id */
918 u32 status;
919};
920
921struct multi_recv_comp {
922 struct recv_comp_data *slots;
923 u32 first; /* first data entry */
924 u32 next; /* next entry for writing */
925};
926
927#define NVSP_RSC_MAX 562 /* Max #RSC frags in a vmbus xfer page pkt */
928
929struct nvsc_rsc {
930 struct ndis_pkt_8021q_info vlan;
931 struct ndis_tcp_ip_checksum_info csum_info;
932 u32 hash_info;
933 u8 ppi_flags; /* valid/present bits for the above PPIs */
934 u8 is_last; /* last RNDIS msg in a vmtransfer_page */
935 u32 cnt; /* #fragments in an RSC packet */
936 u32 pktlen; /* Full packet length */
937 void *data[NVSP_RSC_MAX];
938 u32 len[NVSP_RSC_MAX];
939};
940
941#define NVSC_RSC_VLAN BIT(0) /* valid/present bit for 'vlan' */
942#define NVSC_RSC_CSUM_INFO BIT(1) /* valid/present bit for 'csum_info' */
943#define NVSC_RSC_HASH_INFO BIT(2) /* valid/present bit for 'hash_info' */
944
945struct netvsc_stats {
946 u64 packets;
947 u64 bytes;
948 u64 broadcast;
949 u64 multicast;
950 u64 xdp_drop;
951 struct u64_stats_sync syncp;
952};
953
954struct netvsc_ethtool_stats {
955 unsigned long tx_scattered;
956 unsigned long tx_no_memory;
957 unsigned long tx_no_space;
958 unsigned long tx_too_big;
959 unsigned long tx_busy;
960 unsigned long tx_send_full;
961 unsigned long rx_comp_busy;
962 unsigned long rx_no_memory;
963 unsigned long stop_queue;
964 unsigned long wake_queue;
965 unsigned long vlan_error;
966};
967
968struct netvsc_ethtool_pcpu_stats {
969 u64 rx_packets;
970 u64 rx_bytes;
971 u64 tx_packets;
972 u64 tx_bytes;
973 u64 vf_rx_packets;
974 u64 vf_rx_bytes;
975 u64 vf_tx_packets;
976 u64 vf_tx_bytes;
977};
978
979struct netvsc_vf_pcpu_stats {
980 u64 rx_packets;
981 u64 rx_bytes;
982 u64 tx_packets;
983 u64 tx_bytes;
984 struct u64_stats_sync syncp;
985 u32 tx_dropped;
986};
987
988struct netvsc_reconfig {
989 struct list_head list;
990 u32 event;
991};
992
993/* L4 hash bits for different protocols */
994#define HV_TCP4_L4HASH 1
995#define HV_TCP6_L4HASH 2
996#define HV_UDP4_L4HASH 4
997#define HV_UDP6_L4HASH 8
998#define HV_DEFAULT_L4HASH (HV_TCP4_L4HASH | HV_TCP6_L4HASH | HV_UDP4_L4HASH | \
999 HV_UDP6_L4HASH)
1000
1001/* The context of the netvsc device */
1002struct net_device_context {
1003 /* point back to our device context */
1004 struct hv_device *device_ctx;
1005 /* netvsc_device */
1006 struct netvsc_device __rcu *nvdev;
1007 /* list of netvsc net_devices */
1008 struct list_head list;
1009 /* reconfigure work */
1010 struct delayed_work dwork;
1011 /* last reconfig time */
1012 unsigned long last_reconfig;
1013 /* reconfig events */
1014 struct list_head reconfig_events;
1015 /* list protection */
1016 spinlock_t lock;
1017
1018 u32 msg_enable; /* debug level */
1019
1020 u32 tx_checksum_mask;
1021
1022 u32 tx_table[VRSS_SEND_TAB_SIZE];
1023
1024 u16 rx_table[ITAB_NUM];
1025
1026 /* Ethtool settings */
1027 u8 duplex;
1028 u32 speed;
1029 u32 l4_hash; /* L4 hash settings */
1030 struct netvsc_ethtool_stats eth_stats;
1031
1032 /* State to manage the associated VF interface. */
1033 struct net_device __rcu *vf_netdev;
1034 struct netvsc_vf_pcpu_stats __percpu *vf_stats;
1035 struct delayed_work vf_takeover;
1036
1037 /* 1: allocated, serial number is valid. 0: not allocated */
1038 u32 vf_alloc;
1039 /* Serial number of the VF to team with */
1040 u32 vf_serial;
1041
1042 /* Is the current data path through the VF NIC? */
1043 bool data_path_is_vf;
1044
1045 /* Used to temporarily save the config info across hibernation */
1046 struct netvsc_device_info *saved_netvsc_dev_info;
1047};
1048
1049/* Per channel data */
1050struct netvsc_channel {
1051 struct vmbus_channel *channel;
1052 struct netvsc_device *net_device;
1053 void *recv_buf; /* buffer to copy packets out from the receive buffer */
1054 const struct vmpacket_descriptor *desc;
1055 struct napi_struct napi;
1056 struct multi_send_data msd;
1057 struct multi_recv_comp mrc;
1058 atomic_t queue_sends;
1059 struct nvsc_rsc rsc;
1060
1061 struct bpf_prog __rcu *bpf_prog;
1062 struct xdp_rxq_info xdp_rxq;
1063
1064 struct netvsc_stats tx_stats;
1065 struct netvsc_stats rx_stats;
1066};
1067
1068/* Per netvsc device */
1069struct netvsc_device {
1070 u32 nvsp_version;
1071
1072 wait_queue_head_t wait_drain;
1073 bool destroy;
1074 bool tx_disable; /* if true, do not wake up queue again */
1075
1076 /* Receive buffer allocated by us but manages by NetVSP */
1077 void *recv_buf;
1078 void *recv_original_buf;
1079 u32 recv_buf_size; /* allocated bytes */
1080 struct vmbus_gpadl recv_buf_gpadl_handle;
1081 u32 recv_section_cnt;
1082 u32 recv_section_size;
1083 u32 recv_completion_cnt;
1084
1085 /* Send buffer allocated by us */
1086 void *send_buf;
1087 void *send_original_buf;
1088 u32 send_buf_size;
1089 struct vmbus_gpadl send_buf_gpadl_handle;
1090 u32 send_section_cnt;
1091 u32 send_section_size;
1092 unsigned long *send_section_map;
1093
1094 /* Used for NetVSP initialization protocol */
1095 struct completion channel_init_wait;
1096 struct nvsp_message channel_init_pkt;
1097
1098 struct nvsp_message revoke_packet;
1099
1100 u32 max_chn;
1101 u32 num_chn;
1102
1103 atomic_t open_chn;
1104 struct work_struct subchan_work;
1105 wait_queue_head_t subchan_open;
1106
1107 struct rndis_device *extension;
1108
1109 u32 max_pkt; /* max number of pkt in one send, e.g. 8 */
1110 u32 pkt_align; /* alignment bytes, e.g. 8 */
1111
1112 struct netvsc_channel chan_table[VRSS_CHANNEL_MAX];
1113
1114 struct rcu_head rcu;
1115};
1116
1117/* NdisInitialize message */
1118struct rndis_initialize_request {
1119 u32 req_id;
1120 u32 major_ver;
1121 u32 minor_ver;
1122 u32 max_xfer_size;
1123};
1124
1125/* Response to NdisInitialize */
1126struct rndis_initialize_complete {
1127 u32 req_id;
1128 u32 status;
1129 u32 major_ver;
1130 u32 minor_ver;
1131 u32 dev_flags;
1132 u32 medium;
1133 u32 max_pkt_per_msg;
1134 u32 max_xfer_size;
1135 u32 pkt_alignment_factor;
1136 u32 af_list_offset;
1137 u32 af_list_size;
1138};
1139
1140/* Call manager devices only: Information about an address family */
1141/* supported by the device is appended to the response to NdisInitialize. */
1142struct rndis_co_address_family {
1143 u32 address_family;
1144 u32 major_ver;
1145 u32 minor_ver;
1146};
1147
1148/* NdisHalt message */
1149struct rndis_halt_request {
1150 u32 req_id;
1151};
1152
1153/* NdisQueryRequest message */
1154struct rndis_query_request {
1155 u32 req_id;
1156 u32 oid;
1157 u32 info_buflen;
1158 u32 info_buf_offset;
1159 u32 dev_vc_handle;
1160};
1161
1162/* Response to NdisQueryRequest */
1163struct rndis_query_complete {
1164 u32 req_id;
1165 u32 status;
1166 u32 info_buflen;
1167 u32 info_buf_offset;
1168};
1169
1170/* NdisSetRequest message */
1171struct rndis_set_request {
1172 u32 req_id;
1173 u32 oid;
1174 u32 info_buflen;
1175 u32 info_buf_offset;
1176 u32 dev_vc_handle;
1177 u8 info_buf[];
1178};
1179
1180/* Response to NdisSetRequest */
1181struct rndis_set_complete {
1182 u32 req_id;
1183 u32 status;
1184};
1185
1186/* NdisReset message */
1187struct rndis_reset_request {
1188 u32 reserved;
1189};
1190
1191/* Response to NdisReset */
1192struct rndis_reset_complete {
1193 u32 status;
1194 u32 addressing_reset;
1195};
1196
1197/* NdisMIndicateStatus message */
1198struct rndis_indicate_status {
1199 u32 status;
1200 u32 status_buflen;
1201 u32 status_buf_offset;
1202};
1203
1204/* Diagnostic information passed as the status buffer in */
1205/* struct rndis_indicate_status messages signifying error conditions. */
1206struct rndis_diagnostic_info {
1207 u32 diag_status;
1208 u32 error_offset;
1209};
1210
1211/* NdisKeepAlive message */
1212struct rndis_keepalive_request {
1213 u32 req_id;
1214};
1215
1216/* Response to NdisKeepAlive */
1217struct rndis_keepalive_complete {
1218 u32 req_id;
1219 u32 status;
1220};
1221
1222/*
1223 * Data message. All Offset fields contain byte offsets from the beginning of
1224 * struct rndis_packet. All Length fields are in bytes. VcHandle is set
1225 * to 0 for connectionless data, otherwise it contains the VC handle.
1226 */
1227struct rndis_packet {
1228 u32 data_offset;
1229 u32 data_len;
1230 u32 oob_data_offset;
1231 u32 oob_data_len;
1232 u32 num_oob_data_elements;
1233 u32 per_pkt_info_offset;
1234 u32 per_pkt_info_len;
1235 u32 vc_handle;
1236 u32 reserved;
1237};
1238
1239/* Optional Out of Band data associated with a Data message. */
1240struct rndis_oobd {
1241 u32 size;
1242 u32 type;
1243 u32 class_info_offset;
1244};
1245
1246/* Packet extension field contents associated with a Data message. */
1247struct rndis_per_packet_info {
1248 u32 size;
1249 u32 type:31;
1250 u32 internal:1;
1251 u32 ppi_offset;
1252};
1253
1254enum ndis_per_pkt_info_type {
1255 TCPIP_CHKSUM_PKTINFO,
1256 IPSEC_PKTINFO,
1257 TCP_LARGESEND_PKTINFO,
1258 CLASSIFICATION_HANDLE_PKTINFO,
1259 NDIS_RESERVED,
1260 SG_LIST_PKTINFO,
1261 IEEE_8021Q_INFO,
1262 ORIGINAL_PKTINFO,
1263 PACKET_CANCEL_ID,
1264 NBL_HASH_VALUE = PACKET_CANCEL_ID,
1265 ORIGINAL_NET_BUFLIST,
1266 CACHED_NET_BUFLIST,
1267 SHORT_PKT_PADINFO,
1268 MAX_PER_PKT_INFO
1269};
1270
1271enum rndis_per_pkt_info_interal_type {
1272 RNDIS_PKTINFO_ID = 1,
1273 /* Add more members here */
1274
1275 RNDIS_PKTINFO_MAX
1276};
1277
1278#define RNDIS_PKTINFO_SUBALLOC BIT(0)
1279#define RNDIS_PKTINFO_1ST_FRAG BIT(1)
1280#define RNDIS_PKTINFO_LAST_FRAG BIT(2)
1281
1282#define RNDIS_PKTINFO_ID_V1 1
1283
1284struct rndis_pktinfo_id {
1285 u8 ver;
1286 u8 flag;
1287 u16 pkt_id;
1288};
1289
1290struct ndis_object_header {
1291 u8 type;
1292 u8 revision;
1293 u16 size;
1294};
1295
1296#define NDIS_OBJECT_TYPE_DEFAULT 0x80
1297#define NDIS_OFFLOAD_PARAMETERS_REVISION_3 3
1298#define NDIS_OFFLOAD_PARAMETERS_REVISION_2 2
1299#define NDIS_OFFLOAD_PARAMETERS_REVISION_1 1
1300
1301#define NDIS_OFFLOAD_PARAMETERS_NO_CHANGE 0
1302#define NDIS_OFFLOAD_PARAMETERS_LSOV2_DISABLED 1
1303#define NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED 2
1304#define NDIS_OFFLOAD_PARAMETERS_LSOV1_ENABLED 2
1305#define NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED 1
1306#define NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED 2
1307#define NDIS_OFFLOAD_PARAMETERS_TX_RX_DISABLED 1
1308#define NDIS_OFFLOAD_PARAMETERS_TX_ENABLED_RX_DISABLED 2
1309#define NDIS_OFFLOAD_PARAMETERS_RX_ENABLED_TX_DISABLED 3
1310#define NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED 4
1311
1312#define NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE 1
1313#define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4 0
1314#define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6 1
1315
1316#define VERSION_4_OFFLOAD_SIZE 22
1317/*
1318 * New offload OIDs for NDIS 6
1319 */
1320#define OID_TCP_OFFLOAD_CURRENT_CONFIG 0xFC01020B /* query only */
1321#define OID_TCP_OFFLOAD_PARAMETERS 0xFC01020C /* set only */
1322#define OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020D/* query only */
1323#define OID_TCP_CONNECTION_OFFLOAD_CURRENT_CONFIG 0xFC01020E /* query only */
1324#define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020F /* query */
1325#define OID_OFFLOAD_ENCAPSULATION 0x0101010A /* set/query */
1326
1327/*
1328 * OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES
1329 * ndis_type: NDIS_OBJTYPE_OFFLOAD
1330 */
1331
1332#define NDIS_OFFLOAD_ENCAP_NONE 0x0000
1333#define NDIS_OFFLOAD_ENCAP_NULL 0x0001
1334#define NDIS_OFFLOAD_ENCAP_8023 0x0002
1335#define NDIS_OFFLOAD_ENCAP_8023PQ 0x0004
1336#define NDIS_OFFLOAD_ENCAP_8023PQ_OOB 0x0008
1337#define NDIS_OFFLOAD_ENCAP_RFC1483 0x0010
1338
1339struct ndis_csum_offload {
1340 u32 ip4_txenc;
1341 u32 ip4_txcsum;
1342#define NDIS_TXCSUM_CAP_IP4OPT 0x001
1343#define NDIS_TXCSUM_CAP_TCP4OPT 0x004
1344#define NDIS_TXCSUM_CAP_TCP4 0x010
1345#define NDIS_TXCSUM_CAP_UDP4 0x040
1346#define NDIS_TXCSUM_CAP_IP4 0x100
1347
1348#define NDIS_TXCSUM_ALL_TCP4 (NDIS_TXCSUM_CAP_TCP4 | NDIS_TXCSUM_CAP_TCP4OPT)
1349
1350 u32 ip4_rxenc;
1351 u32 ip4_rxcsum;
1352#define NDIS_RXCSUM_CAP_IP4OPT 0x001
1353#define NDIS_RXCSUM_CAP_TCP4OPT 0x004
1354#define NDIS_RXCSUM_CAP_TCP4 0x010
1355#define NDIS_RXCSUM_CAP_UDP4 0x040
1356#define NDIS_RXCSUM_CAP_IP4 0x100
1357 u32 ip6_txenc;
1358 u32 ip6_txcsum;
1359#define NDIS_TXCSUM_CAP_IP6EXT 0x001
1360#define NDIS_TXCSUM_CAP_TCP6OPT 0x004
1361#define NDIS_TXCSUM_CAP_TCP6 0x010
1362#define NDIS_TXCSUM_CAP_UDP6 0x040
1363 u32 ip6_rxenc;
1364 u32 ip6_rxcsum;
1365#define NDIS_RXCSUM_CAP_IP6EXT 0x001
1366#define NDIS_RXCSUM_CAP_TCP6OPT 0x004
1367#define NDIS_RXCSUM_CAP_TCP6 0x010
1368#define NDIS_RXCSUM_CAP_UDP6 0x040
1369
1370#define NDIS_TXCSUM_ALL_TCP6 (NDIS_TXCSUM_CAP_TCP6 | \
1371 NDIS_TXCSUM_CAP_TCP6OPT | \
1372 NDIS_TXCSUM_CAP_IP6EXT)
1373};
1374
1375struct ndis_lsov1_offload {
1376 u32 encap;
1377 u32 maxsize;
1378 u32 minsegs;
1379 u32 opts;
1380};
1381
1382struct ndis_ipsecv1_offload {
1383 u32 encap;
1384 u32 ah_esp;
1385 u32 xport_tun;
1386 u32 ip4_opts;
1387 u32 flags;
1388 u32 ip4_ah;
1389 u32 ip4_esp;
1390};
1391
1392struct ndis_lsov2_offload {
1393 u32 ip4_encap;
1394 u32 ip4_maxsz;
1395 u32 ip4_minsg;
1396 u32 ip6_encap;
1397 u32 ip6_maxsz;
1398 u32 ip6_minsg;
1399 u32 ip6_opts;
1400#define NDIS_LSOV2_CAP_IP6EXT 0x001
1401#define NDIS_LSOV2_CAP_TCP6OPT 0x004
1402
1403#define NDIS_LSOV2_CAP_IP6 (NDIS_LSOV2_CAP_IP6EXT | \
1404 NDIS_LSOV2_CAP_TCP6OPT)
1405};
1406
1407struct ndis_ipsecv2_offload {
1408 u32 encap;
1409 u8 ip6;
1410 u8 ip4opt;
1411 u8 ip6ext;
1412 u8 ah;
1413 u8 esp;
1414 u8 ah_esp;
1415 u8 xport;
1416 u8 tun;
1417 u8 xport_tun;
1418 u8 lso;
1419 u8 extseq;
1420 u32 udp_esp;
1421 u32 auth;
1422 u32 crypto;
1423 u32 sa_caps;
1424};
1425
1426struct ndis_rsc_offload {
1427 u8 ip4;
1428 u8 ip6;
1429};
1430
1431struct ndis_encap_offload {
1432 u32 flags;
1433 u32 maxhdr;
1434};
1435
1436struct ndis_offload {
1437 struct ndis_object_header header;
1438 struct ndis_csum_offload csum;
1439 struct ndis_lsov1_offload lsov1;
1440 struct ndis_ipsecv1_offload ipsecv1;
1441 struct ndis_lsov2_offload lsov2;
1442 u32 flags;
1443 /* NDIS >= 6.1 */
1444 struct ndis_ipsecv2_offload ipsecv2;
1445 /* NDIS >= 6.30 */
1446 struct ndis_rsc_offload rsc;
1447 struct ndis_encap_offload encap_gre;
1448};
1449
1450#define NDIS_OFFLOAD_SIZE sizeof(struct ndis_offload)
1451#define NDIS_OFFLOAD_SIZE_6_0 offsetof(struct ndis_offload, ipsecv2)
1452#define NDIS_OFFLOAD_SIZE_6_1 offsetof(struct ndis_offload, rsc)
1453
1454struct ndis_offload_params {
1455 struct ndis_object_header header;
1456 u8 ip_v4_csum;
1457 u8 tcp_ip_v4_csum;
1458 u8 udp_ip_v4_csum;
1459 u8 tcp_ip_v6_csum;
1460 u8 udp_ip_v6_csum;
1461 u8 lso_v1;
1462 u8 ip_sec_v1;
1463 u8 lso_v2_ipv4;
1464 u8 lso_v2_ipv6;
1465 u8 tcp_connection_ip_v4;
1466 u8 tcp_connection_ip_v6;
1467 u32 flags;
1468 u8 ip_sec_v2;
1469 u8 ip_sec_v2_ip_v4;
1470 struct {
1471 u8 rsc_ip_v4;
1472 u8 rsc_ip_v6;
1473 };
1474 struct {
1475 u8 encapsulated_packet_task_offload;
1476 u8 encapsulation_types;
1477 };
1478};
1479
1480struct ndis_tcp_lso_info {
1481 union {
1482 struct {
1483 u32 unused:30;
1484 u32 type:1;
1485 u32 reserved2:1;
1486 } transmit;
1487 struct {
1488 u32 mss:20;
1489 u32 tcp_header_offset:10;
1490 u32 type:1;
1491 u32 reserved2:1;
1492 } lso_v1_transmit;
1493 struct {
1494 u32 tcp_payload:30;
1495 u32 type:1;
1496 u32 reserved2:1;
1497 } lso_v1_transmit_complete;
1498 struct {
1499 u32 mss:20;
1500 u32 tcp_header_offset:10;
1501 u32 type:1;
1502 u32 ip_version:1;
1503 } lso_v2_transmit;
1504 struct {
1505 u32 reserved:30;
1506 u32 type:1;
1507 u32 reserved2:1;
1508 } lso_v2_transmit_complete;
1509 u32 value;
1510 };
1511};
1512
1513#define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
1514 sizeof(struct ndis_pkt_8021q_info))
1515
1516#define NDIS_CSUM_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
1517 sizeof(struct ndis_tcp_ip_checksum_info))
1518
1519#define NDIS_LSO_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
1520 sizeof(struct ndis_tcp_lso_info))
1521
1522#define NDIS_HASH_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
1523 sizeof(u32))
1524
1525/* Total size of all PPI data */
1526#define NDIS_ALL_PPI_SIZE (NDIS_VLAN_PPI_SIZE + NDIS_CSUM_PPI_SIZE + \
1527 NDIS_LSO_PPI_SIZE + NDIS_HASH_PPI_SIZE)
1528
1529/* Format of Information buffer passed in a SetRequest for the OID */
1530/* OID_GEN_RNDIS_CONFIG_PARAMETER. */
1531struct rndis_config_parameter_info {
1532 u32 parameter_name_offset;
1533 u32 parameter_name_length;
1534 u32 parameter_type;
1535 u32 parameter_value_offset;
1536 u32 parameter_value_length;
1537};
1538
1539/* Values for ParameterType in struct rndis_config_parameter_info */
1540#define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0
1541#define RNDIS_CONFIG_PARAM_TYPE_STRING 2
1542
1543/* CONDIS Miniport messages for connection oriented devices */
1544/* that do not implement a call manager. */
1545
1546/* CoNdisMiniportCreateVc message */
1547struct rcondis_mp_create_vc {
1548 u32 req_id;
1549 u32 ndis_vc_handle;
1550};
1551
1552/* Response to CoNdisMiniportCreateVc */
1553struct rcondis_mp_create_vc_complete {
1554 u32 req_id;
1555 u32 dev_vc_handle;
1556 u32 status;
1557};
1558
1559/* CoNdisMiniportDeleteVc message */
1560struct rcondis_mp_delete_vc {
1561 u32 req_id;
1562 u32 dev_vc_handle;
1563};
1564
1565/* Response to CoNdisMiniportDeleteVc */
1566struct rcondis_mp_delete_vc_complete {
1567 u32 req_id;
1568 u32 status;
1569};
1570
1571/* CoNdisMiniportQueryRequest message */
1572struct rcondis_mp_query_request {
1573 u32 req_id;
1574 u32 request_type;
1575 u32 oid;
1576 u32 dev_vc_handle;
1577 u32 info_buflen;
1578 u32 info_buf_offset;
1579};
1580
1581/* CoNdisMiniportSetRequest message */
1582struct rcondis_mp_set_request {
1583 u32 req_id;
1584 u32 request_type;
1585 u32 oid;
1586 u32 dev_vc_handle;
1587 u32 info_buflen;
1588 u32 info_buf_offset;
1589};
1590
1591/* CoNdisIndicateStatus message */
1592struct rcondis_indicate_status {
1593 u32 ndis_vc_handle;
1594 u32 status;
1595 u32 status_buflen;
1596 u32 status_buf_offset;
1597};
1598
1599/* CONDIS Call/VC parameters */
1600struct rcondis_specific_parameters {
1601 u32 parameter_type;
1602 u32 parameter_length;
1603 u32 parameter_lffset;
1604};
1605
1606struct rcondis_media_parameters {
1607 u32 flags;
1608 u32 reserved1;
1609 u32 reserved2;
1610 struct rcondis_specific_parameters media_specific;
1611};
1612
1613struct rndis_flowspec {
1614 u32 token_rate;
1615 u32 token_bucket_size;
1616 u32 peak_bandwidth;
1617 u32 latency;
1618 u32 delay_variation;
1619 u32 service_type;
1620 u32 max_sdu_size;
1621 u32 minimum_policed_size;
1622};
1623
1624struct rcondis_call_manager_parameters {
1625 struct rndis_flowspec transmit;
1626 struct rndis_flowspec receive;
1627 struct rcondis_specific_parameters call_mgr_specific;
1628};
1629
1630/* CoNdisMiniportActivateVc message */
1631struct rcondis_mp_activate_vc_request {
1632 u32 req_id;
1633 u32 flags;
1634 u32 dev_vc_handle;
1635 u32 media_params_offset;
1636 u32 media_params_length;
1637 u32 call_mgr_params_offset;
1638 u32 call_mgr_params_length;
1639};
1640
1641/* Response to CoNdisMiniportActivateVc */
1642struct rcondis_mp_activate_vc_complete {
1643 u32 req_id;
1644 u32 status;
1645};
1646
1647/* CoNdisMiniportDeactivateVc message */
1648struct rcondis_mp_deactivate_vc_request {
1649 u32 req_id;
1650 u32 flags;
1651 u32 dev_vc_handle;
1652};
1653
1654/* Response to CoNdisMiniportDeactivateVc */
1655struct rcondis_mp_deactivate_vc_complete {
1656 u32 req_id;
1657 u32 status;
1658};
1659
1660
1661/* union with all of the RNDIS messages */
1662union rndis_message_container {
1663 struct rndis_packet pkt;
1664 struct rndis_initialize_request init_req;
1665 struct rndis_halt_request halt_req;
1666 struct rndis_query_request query_req;
1667 struct rndis_set_request set_req;
1668 struct rndis_reset_request reset_req;
1669 struct rndis_keepalive_request keep_alive_req;
1670 struct rndis_indicate_status indicate_status;
1671 struct rndis_initialize_complete init_complete;
1672 struct rndis_query_complete query_complete;
1673 struct rndis_set_complete set_complete;
1674 struct rndis_reset_complete reset_complete;
1675 struct rndis_keepalive_complete keep_alive_complete;
1676 struct rcondis_mp_create_vc co_miniport_create_vc;
1677 struct rcondis_mp_delete_vc co_miniport_delete_vc;
1678 struct rcondis_indicate_status co_indicate_status;
1679 struct rcondis_mp_activate_vc_request co_miniport_activate_vc;
1680 struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc;
1681 struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete;
1682 struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete;
1683 struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete;
1684 struct rcondis_mp_deactivate_vc_complete
1685 co_miniport_deactivate_vc_complete;
1686};
1687
1688/* Remote NDIS message format */
1689struct rndis_message {
1690 u32 ndis_msg_type;
1691
1692 /* Total length of this message, from the beginning */
1693 /* of the struct rndis_message, in bytes. */
1694 u32 msg_len;
1695
1696 /* Actual message */
1697 union rndis_message_container msg;
1698};
1699
1700
1701/* Handy macros */
1702
1703/* get the size of an RNDIS message. Pass in the message type, */
1704/* struct rndis_set_request, struct rndis_packet for example */
1705#define RNDIS_MESSAGE_SIZE(msg) \
1706 (sizeof(msg) + (sizeof(struct rndis_message) - \
1707 sizeof(union rndis_message_container)))
1708
1709#define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \
1710 sizeof(union rndis_message_container))
1711
1712#define RNDIS_AND_PPI_SIZE (sizeof(struct rndis_message) + NDIS_ALL_PPI_SIZE)
1713
1714#define NDIS_PACKET_TYPE_DIRECTED 0x00000001
1715#define NDIS_PACKET_TYPE_MULTICAST 0x00000002
1716#define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
1717#define NDIS_PACKET_TYPE_BROADCAST 0x00000008
1718#define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
1719#define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
1720#define NDIS_PACKET_TYPE_SMT 0x00000040
1721#define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
1722#define NDIS_PACKET_TYPE_GROUP 0x00000100
1723#define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
1724#define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
1725#define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
1726
1727#define TRANSPORT_INFO_NOT_IP 0
1728#define TRANSPORT_INFO_IPV4_TCP 0x01
1729#define TRANSPORT_INFO_IPV4_UDP 0x02
1730#define TRANSPORT_INFO_IPV6_TCP 0x10
1731#define TRANSPORT_INFO_IPV6_UDP 0x20
1732
1733#define RETRY_US_LO 5000
1734#define RETRY_US_HI 10000
1735#define RETRY_MAX 2000 /* >10 sec */
1736
1737void netvsc_dma_unmap(struct hv_device *hv_dev,
1738 struct hv_netvsc_packet *packet);
1739#endif /* _HYPERV_NET_H */