hyperv_net.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /*
  2. *
  3. * Copyright (c) 2011, Microsoft Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * Authors:
  18. * Haiyang Zhang <haiyangz@microsoft.com>
  19. * Hank Janssen <hjanssen@microsoft.com>
  20. * K. Y. Srinivasan <kys@microsoft.com>
  21. *
  22. */
  23. #ifndef _HYPERV_NET_H
  24. #define _HYPERV_NET_H
  25. #include <linux/list.h>
  26. #include <linux/hyperv.h>
  27. #include <linux/rndis.h>
  28. /* Fwd declaration */
  29. struct hv_netvsc_packet;
  30. struct ndis_tcp_ip_checksum_info;
  31. /* Represent the xfer page packet which contains 1 or more netvsc packet */
  32. struct xferpage_packet {
  33. struct list_head list_ent;
  34. u32 status;
  35. /* # of netvsc packets this xfer packet contains */
  36. u32 count;
  37. };
  38. /*
  39. * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
  40. * within the RNDIS
  41. */
  42. struct hv_netvsc_packet {
  43. /* Bookkeeping stuff */
  44. struct list_head list_ent;
  45. u32 status;
  46. struct hv_device *device;
  47. bool is_data_pkt;
  48. u16 vlan_tci;
  49. /*
  50. * Valid only for receives when we break a xfer page packet
  51. * into multiple netvsc packets
  52. */
  53. struct xferpage_packet *xfer_page_pkt;
  54. union {
  55. struct {
  56. u64 recv_completion_tid;
  57. void *recv_completion_ctx;
  58. void (*recv_completion)(void *context);
  59. } recv;
  60. struct {
  61. u64 send_completion_tid;
  62. void *send_completion_ctx;
  63. void (*send_completion)(void *context);
  64. } send;
  65. } completion;
  66. /* This points to the memory after page_buf */
  67. struct rndis_message *rndis_msg;
  68. u32 total_data_buflen;
  69. /* Points to the send/receive buffer where the ethernet frame is */
  70. void *data;
  71. u32 page_buf_cnt;
  72. struct hv_page_buffer page_buf[0];
  73. };
  74. struct netvsc_device_info {
  75. unsigned char mac_adr[ETH_ALEN];
  76. bool link_state; /* 0 - link up, 1 - link down */
  77. int ring_size;
  78. };
  79. enum rndis_device_state {
  80. RNDIS_DEV_UNINITIALIZED = 0,
  81. RNDIS_DEV_INITIALIZING,
  82. RNDIS_DEV_INITIALIZED,
  83. RNDIS_DEV_DATAINITIALIZED,
  84. };
  85. struct rndis_device {
  86. struct netvsc_device *net_dev;
  87. enum rndis_device_state state;
  88. bool link_state;
  89. atomic_t new_req_id;
  90. spinlock_t request_lock;
  91. struct list_head req_list;
  92. unsigned char hw_mac_adr[ETH_ALEN];
  93. };
  94. /* Interface */
  95. int netvsc_device_add(struct hv_device *device, void *additional_info);
  96. int netvsc_device_remove(struct hv_device *device);
  97. int netvsc_send(struct hv_device *device,
  98. struct hv_netvsc_packet *packet);
  99. void netvsc_linkstatus_callback(struct hv_device *device_obj,
  100. unsigned int status);
  101. int netvsc_recv_callback(struct hv_device *device_obj,
  102. struct hv_netvsc_packet *packet,
  103. struct ndis_tcp_ip_checksum_info *csum_info);
  104. int rndis_filter_open(struct hv_device *dev);
  105. int rndis_filter_close(struct hv_device *dev);
  106. int rndis_filter_device_add(struct hv_device *dev,
  107. void *additional_info);
  108. void rndis_filter_device_remove(struct hv_device *dev);
  109. int rndis_filter_receive(struct hv_device *dev,
  110. struct hv_netvsc_packet *pkt);
  111. int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter);
  112. int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac);
  113. #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
  114. #define NVSP_PROTOCOL_VERSION_1 2
  115. #define NVSP_PROTOCOL_VERSION_2 0x30002
  116. #define NVSP_PROTOCOL_VERSION_4 0x40000
  117. #define NVSP_PROTOCOL_VERSION_5 0x50000
  118. enum {
  119. NVSP_MSG_TYPE_NONE = 0,
  120. /* Init Messages */
  121. NVSP_MSG_TYPE_INIT = 1,
  122. NVSP_MSG_TYPE_INIT_COMPLETE = 2,
  123. NVSP_VERSION_MSG_START = 100,
  124. /* Version 1 Messages */
  125. NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START,
  126. NVSP_MSG1_TYPE_SEND_RECV_BUF,
  127. NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
  128. NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
  129. NVSP_MSG1_TYPE_SEND_SEND_BUF,
  130. NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
  131. NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
  132. NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
  133. NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
  134. /* Version 2 messages */
  135. NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF,
  136. NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF_COMP,
  137. NVSP_MSG2_TYPE_REVOKE_CHIMNEY_DELEGATED_BUF,
  138. NVSP_MSG2_TYPE_RESUME_CHIMNEY_RX_INDICATION,
  139. NVSP_MSG2_TYPE_TERMINATE_CHIMNEY,
  140. NVSP_MSG2_TYPE_TERMINATE_CHIMNEY_COMP,
  141. NVSP_MSG2_TYPE_INDICATE_CHIMNEY_EVENT,
  142. NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT,
  143. NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT_COMP,
  144. NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ,
  145. NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ_COMP,
  146. NVSP_MSG2_TYPE_ALLOC_RXBUF,
  147. NVSP_MSG2_TYPE_ALLOC_RXBUF_COMP,
  148. NVSP_MSG2_TYPE_FREE_RXBUF,
  149. NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT,
  150. NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT_COMP,
  151. NVSP_MSG2_TYPE_SEND_NDIS_CONFIG,
  152. NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE,
  153. NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
  154. NVSP_MSG2_MAX = NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
  155. /* Version 4 messages */
  156. NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION,
  157. NVSP_MSG4_TYPE_SWITCH_DATA_PATH,
  158. NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
  159. NVSP_MSG4_MAX = NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
  160. /* Version 5 messages */
  161. NVSP_MSG5_TYPE_OID_QUERY_EX,
  162. NVSP_MSG5_TYPE_OID_QUERY_EX_COMP,
  163. NVSP_MSG5_TYPE_SUBCHANNEL,
  164. NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
  165. NVSP_MSG5_MAX = NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
  166. };
  167. enum {
  168. NVSP_STAT_NONE = 0,
  169. NVSP_STAT_SUCCESS,
  170. NVSP_STAT_FAIL,
  171. NVSP_STAT_PROTOCOL_TOO_NEW,
  172. NVSP_STAT_PROTOCOL_TOO_OLD,
  173. NVSP_STAT_INVALID_RNDIS_PKT,
  174. NVSP_STAT_BUSY,
  175. NVSP_STAT_PROTOCOL_UNSUPPORTED,
  176. NVSP_STAT_MAX,
  177. };
  178. struct nvsp_message_header {
  179. u32 msg_type;
  180. };
  181. /* Init Messages */
  182. /*
  183. * This message is used by the VSC to initialize the channel after the channels
  184. * has been opened. This message should never include anything other then
  185. * versioning (i.e. this message will be the same for ever).
  186. */
  187. struct nvsp_message_init {
  188. u32 min_protocol_ver;
  189. u32 max_protocol_ver;
  190. } __packed;
  191. /*
  192. * This message is used by the VSP to complete the initialization of the
  193. * channel. This message should never include anything other then versioning
  194. * (i.e. this message will be the same for ever).
  195. */
  196. struct nvsp_message_init_complete {
  197. u32 negotiated_protocol_ver;
  198. u32 max_mdl_chain_len;
  199. u32 status;
  200. } __packed;
  201. union nvsp_message_init_uber {
  202. struct nvsp_message_init init;
  203. struct nvsp_message_init_complete init_complete;
  204. } __packed;
  205. /* Version 1 Messages */
  206. /*
  207. * This message is used by the VSC to send the NDIS version to the VSP. The VSP
  208. * can use this information when handling OIDs sent by the VSC.
  209. */
  210. struct nvsp_1_message_send_ndis_version {
  211. u32 ndis_major_ver;
  212. u32 ndis_minor_ver;
  213. } __packed;
  214. /*
  215. * This message is used by the VSC to send a receive buffer to the VSP. The VSP
  216. * can then use the receive buffer to send data to the VSC.
  217. */
  218. struct nvsp_1_message_send_receive_buffer {
  219. u32 gpadl_handle;
  220. u16 id;
  221. } __packed;
  222. struct nvsp_1_receive_buffer_section {
  223. u32 offset;
  224. u32 sub_alloc_size;
  225. u32 num_sub_allocs;
  226. u32 end_offset;
  227. } __packed;
  228. /*
  229. * This message is used by the VSP to acknowledge a receive buffer send by the
  230. * VSC. This message must be sent by the VSP before the VSP uses the receive
  231. * buffer.
  232. */
  233. struct nvsp_1_message_send_receive_buffer_complete {
  234. u32 status;
  235. u32 num_sections;
  236. /*
  237. * The receive buffer is split into two parts, a large suballocation
  238. * section and a small suballocation section. These sections are then
  239. * suballocated by a certain size.
  240. */
  241. /*
  242. * For example, the following break up of the receive buffer has 6
  243. * large suballocations and 10 small suballocations.
  244. */
  245. /*
  246. * | Large Section | | Small Section |
  247. * ------------------------------------------------------------
  248. * | | | | | | | | | | | | | | | | | |
  249. * | |
  250. * LargeOffset SmallOffset
  251. */
  252. struct nvsp_1_receive_buffer_section sections[1];
  253. } __packed;
  254. /*
  255. * This message is sent by the VSC to revoke the receive buffer. After the VSP
  256. * completes this transaction, the vsp should never use the receive buffer
  257. * again.
  258. */
  259. struct nvsp_1_message_revoke_receive_buffer {
  260. u16 id;
  261. };
  262. /*
  263. * This message is used by the VSC to send a send buffer to the VSP. The VSC
  264. * can then use the send buffer to send data to the VSP.
  265. */
  266. struct nvsp_1_message_send_send_buffer {
  267. u32 gpadl_handle;
  268. u16 id;
  269. } __packed;
  270. /*
  271. * This message is used by the VSP to acknowledge a send buffer sent by the
  272. * VSC. This message must be sent by the VSP before the VSP uses the sent
  273. * buffer.
  274. */
  275. struct nvsp_1_message_send_send_buffer_complete {
  276. u32 status;
  277. /*
  278. * The VSC gets to choose the size of the send buffer and the VSP gets
  279. * to choose the sections size of the buffer. This was done to enable
  280. * dynamic reconfigurations when the cost of GPA-direct buffers
  281. * decreases.
  282. */
  283. u32 section_size;
  284. } __packed;
  285. /*
  286. * This message is sent by the VSC to revoke the send buffer. After the VSP
  287. * completes this transaction, the vsp should never use the send buffer again.
  288. */
  289. struct nvsp_1_message_revoke_send_buffer {
  290. u16 id;
  291. };
  292. /*
  293. * This message is used by both the VSP and the VSC to send a RNDIS message to
  294. * the opposite channel endpoint.
  295. */
  296. struct nvsp_1_message_send_rndis_packet {
  297. /*
  298. * This field is specified by RNIDS. They assume there's two different
  299. * channels of communication. However, the Network VSP only has one.
  300. * Therefore, the channel travels with the RNDIS packet.
  301. */
  302. u32 channel_type;
  303. /*
  304. * This field is used to send part or all of the data through a send
  305. * buffer. This values specifies an index into the send buffer. If the
  306. * index is 0xFFFFFFFF, then the send buffer is not being used and all
  307. * of the data was sent through other VMBus mechanisms.
  308. */
  309. u32 send_buf_section_index;
  310. u32 send_buf_section_size;
  311. } __packed;
  312. /*
  313. * This message is used by both the VSP and the VSC to complete a RNDIS message
  314. * to the opposite channel endpoint. At this point, the initiator of this
  315. * message cannot use any resources associated with the original RNDIS packet.
  316. */
  317. struct nvsp_1_message_send_rndis_packet_complete {
  318. u32 status;
  319. };
  320. union nvsp_1_message_uber {
  321. struct nvsp_1_message_send_ndis_version send_ndis_ver;
  322. struct nvsp_1_message_send_receive_buffer send_recv_buf;
  323. struct nvsp_1_message_send_receive_buffer_complete
  324. send_recv_buf_complete;
  325. struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
  326. struct nvsp_1_message_send_send_buffer send_send_buf;
  327. struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
  328. struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
  329. struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
  330. struct nvsp_1_message_send_rndis_packet_complete
  331. send_rndis_pkt_complete;
  332. } __packed;
  333. /*
  334. * Network VSP protocol version 2 messages:
  335. */
  336. struct nvsp_2_vsc_capability {
  337. union {
  338. u64 data;
  339. struct {
  340. u64 vmq:1;
  341. u64 chimney:1;
  342. u64 sriov:1;
  343. u64 ieee8021q:1;
  344. u64 correlation_id:1;
  345. };
  346. };
  347. } __packed;
  348. struct nvsp_2_send_ndis_config {
  349. u32 mtu;
  350. u32 reserved;
  351. struct nvsp_2_vsc_capability capability;
  352. } __packed;
  353. /* Allocate receive buffer */
  354. struct nvsp_2_alloc_rxbuf {
  355. /* Allocation ID to match the allocation request and response */
  356. u32 alloc_id;
  357. /* Length of the VM shared memory receive buffer that needs to
  358. * be allocated
  359. */
  360. u32 len;
  361. } __packed;
  362. /* Allocate receive buffer complete */
  363. struct nvsp_2_alloc_rxbuf_comp {
  364. /* The NDIS_STATUS code for buffer allocation */
  365. u32 status;
  366. u32 alloc_id;
  367. /* GPADL handle for the allocated receive buffer */
  368. u32 gpadl_handle;
  369. /* Receive buffer ID */
  370. u64 recv_buf_id;
  371. } __packed;
  372. struct nvsp_2_free_rxbuf {
  373. u64 recv_buf_id;
  374. } __packed;
  375. union nvsp_2_message_uber {
  376. struct nvsp_2_send_ndis_config send_ndis_config;
  377. struct nvsp_2_alloc_rxbuf alloc_rxbuf;
  378. struct nvsp_2_alloc_rxbuf_comp alloc_rxbuf_comp;
  379. struct nvsp_2_free_rxbuf free_rxbuf;
  380. } __packed;
  381. enum nvsp_subchannel_operation {
  382. NVSP_SUBCHANNEL_NONE = 0,
  383. NVSP_SUBCHANNEL_ALLOCATE,
  384. NVSP_SUBCHANNEL_MAX
  385. };
  386. struct nvsp_5_subchannel_request {
  387. u32 op;
  388. u32 num_subchannels;
  389. } __packed;
  390. struct nvsp_5_subchannel_complete {
  391. u32 status;
  392. u32 num_subchannels; /* Actual number of subchannels allocated */
  393. } __packed;
  394. struct nvsp_5_send_indirect_table {
  395. /* The number of entries in the send indirection table */
  396. u32 count;
  397. /* The offset of the send indireciton table from top of this struct.
  398. * The send indirection table tells which channel to put the send
  399. * traffic on. Each entry is a channel number.
  400. */
  401. u32 offset;
  402. } __packed;
  403. union nvsp_5_message_uber {
  404. struct nvsp_5_subchannel_request subchn_req;
  405. struct nvsp_5_subchannel_complete subchn_comp;
  406. struct nvsp_5_send_indirect_table send_table;
  407. } __packed;
  408. union nvsp_all_messages {
  409. union nvsp_message_init_uber init_msg;
  410. union nvsp_1_message_uber v1_msg;
  411. union nvsp_2_message_uber v2_msg;
  412. union nvsp_5_message_uber v5_msg;
  413. } __packed;
  414. /* ALL Messages */
  415. struct nvsp_message {
  416. struct nvsp_message_header hdr;
  417. union nvsp_all_messages msg;
  418. } __packed;
  419. #define NETVSC_MTU 65536
  420. #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
  421. #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
  422. #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
  423. /* Preallocated receive packets */
  424. #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
  425. #define NETVSC_PACKET_SIZE 2048
  426. /* Per netvsc channel-specific */
  427. struct netvsc_device {
  428. struct hv_device *dev;
  429. u32 nvsp_version;
  430. atomic_t num_outstanding_sends;
  431. wait_queue_head_t wait_drain;
  432. bool start_remove;
  433. bool destroy;
  434. /*
  435. * List of free preallocated hv_netvsc_packet to represent receive
  436. * packet
  437. */
  438. struct list_head recv_pkt_list;
  439. spinlock_t recv_pkt_list_lock;
  440. /* Receive buffer allocated by us but manages by NetVSP */
  441. void *recv_buf;
  442. u32 recv_buf_size;
  443. u32 recv_buf_gpadl_handle;
  444. u32 recv_section_cnt;
  445. struct nvsp_1_receive_buffer_section *recv_section;
  446. /* Used for NetVSP initialization protocol */
  447. struct completion channel_init_wait;
  448. struct nvsp_message channel_init_pkt;
  449. struct nvsp_message revoke_packet;
  450. /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
  451. struct net_device *ndev;
  452. /* Holds rndis device info */
  453. void *extension;
  454. /* The recive buffer for this device */
  455. unsigned char cb_buffer[NETVSC_PACKET_SIZE];
  456. };
  457. /* NdisInitialize message */
  458. struct rndis_initialize_request {
  459. u32 req_id;
  460. u32 major_ver;
  461. u32 minor_ver;
  462. u32 max_xfer_size;
  463. };
  464. /* Response to NdisInitialize */
  465. struct rndis_initialize_complete {
  466. u32 req_id;
  467. u32 status;
  468. u32 major_ver;
  469. u32 minor_ver;
  470. u32 dev_flags;
  471. u32 medium;
  472. u32 max_pkt_per_msg;
  473. u32 max_xfer_size;
  474. u32 pkt_alignment_factor;
  475. u32 af_list_offset;
  476. u32 af_list_size;
  477. };
  478. /* Call manager devices only: Information about an address family */
  479. /* supported by the device is appended to the response to NdisInitialize. */
  480. struct rndis_co_address_family {
  481. u32 address_family;
  482. u32 major_ver;
  483. u32 minor_ver;
  484. };
  485. /* NdisHalt message */
  486. struct rndis_halt_request {
  487. u32 req_id;
  488. };
  489. /* NdisQueryRequest message */
  490. struct rndis_query_request {
  491. u32 req_id;
  492. u32 oid;
  493. u32 info_buflen;
  494. u32 info_buf_offset;
  495. u32 dev_vc_handle;
  496. };
  497. /* Response to NdisQueryRequest */
  498. struct rndis_query_complete {
  499. u32 req_id;
  500. u32 status;
  501. u32 info_buflen;
  502. u32 info_buf_offset;
  503. };
  504. /* NdisSetRequest message */
  505. struct rndis_set_request {
  506. u32 req_id;
  507. u32 oid;
  508. u32 info_buflen;
  509. u32 info_buf_offset;
  510. u32 dev_vc_handle;
  511. };
  512. /* Response to NdisSetRequest */
  513. struct rndis_set_complete {
  514. u32 req_id;
  515. u32 status;
  516. };
  517. /* NdisReset message */
  518. struct rndis_reset_request {
  519. u32 reserved;
  520. };
  521. /* Response to NdisReset */
  522. struct rndis_reset_complete {
  523. u32 status;
  524. u32 addressing_reset;
  525. };
  526. /* NdisMIndicateStatus message */
  527. struct rndis_indicate_status {
  528. u32 status;
  529. u32 status_buflen;
  530. u32 status_buf_offset;
  531. };
  532. /* Diagnostic information passed as the status buffer in */
  533. /* struct rndis_indicate_status messages signifying error conditions. */
  534. struct rndis_diagnostic_info {
  535. u32 diag_status;
  536. u32 error_offset;
  537. };
  538. /* NdisKeepAlive message */
  539. struct rndis_keepalive_request {
  540. u32 req_id;
  541. };
  542. /* Response to NdisKeepAlive */
  543. struct rndis_keepalive_complete {
  544. u32 req_id;
  545. u32 status;
  546. };
  547. /*
  548. * Data message. All Offset fields contain byte offsets from the beginning of
  549. * struct rndis_packet. All Length fields are in bytes. VcHandle is set
  550. * to 0 for connectionless data, otherwise it contains the VC handle.
  551. */
  552. struct rndis_packet {
  553. u32 data_offset;
  554. u32 data_len;
  555. u32 oob_data_offset;
  556. u32 oob_data_len;
  557. u32 num_oob_data_elements;
  558. u32 per_pkt_info_offset;
  559. u32 per_pkt_info_len;
  560. u32 vc_handle;
  561. u32 reserved;
  562. };
  563. /* Optional Out of Band data associated with a Data message. */
  564. struct rndis_oobd {
  565. u32 size;
  566. u32 type;
  567. u32 class_info_offset;
  568. };
  569. /* Packet extension field contents associated with a Data message. */
  570. struct rndis_per_packet_info {
  571. u32 size;
  572. u32 type;
  573. u32 ppi_offset;
  574. };
  575. enum ndis_per_pkt_info_type {
  576. TCPIP_CHKSUM_PKTINFO,
  577. IPSEC_PKTINFO,
  578. TCP_LARGESEND_PKTINFO,
  579. CLASSIFICATION_HANDLE_PKTINFO,
  580. NDIS_RESERVED,
  581. SG_LIST_PKTINFO,
  582. IEEE_8021Q_INFO,
  583. ORIGINAL_PKTINFO,
  584. PACKET_CANCEL_ID,
  585. ORIGINAL_NET_BUFLIST,
  586. CACHED_NET_BUFLIST,
  587. SHORT_PKT_PADINFO,
  588. MAX_PER_PKT_INFO
  589. };
  590. struct ndis_pkt_8021q_info {
  591. union {
  592. struct {
  593. u32 pri:3; /* User Priority */
  594. u32 cfi:1; /* Canonical Format ID */
  595. u32 vlanid:12; /* VLAN ID */
  596. u32 reserved:16;
  597. };
  598. u32 value;
  599. };
  600. };
  601. struct ndis_oject_header {
  602. u8 type;
  603. u8 revision;
  604. u16 size;
  605. };
  606. #define NDIS_OBJECT_TYPE_DEFAULT 0x80
  607. #define NDIS_OFFLOAD_PARAMETERS_REVISION_3 3
  608. #define NDIS_OFFLOAD_PARAMETERS_NO_CHANGE 0
  609. #define NDIS_OFFLOAD_PARAMETERS_LSOV2_DISABLED 1
  610. #define NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED 2
  611. #define NDIS_OFFLOAD_PARAMETERS_LSOV1_ENABLED 2
  612. #define NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED 1
  613. #define NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED 2
  614. #define NDIS_OFFLOAD_PARAMETERS_TX_RX_DISABLED 1
  615. #define NDIS_OFFLOAD_PARAMETERS_TX_ENABLED_RX_DISABLED 2
  616. #define NDIS_OFFLOAD_PARAMETERS_RX_ENABLED_TX_DISABLED 3
  617. #define NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED 4
  618. #define NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE 1
  619. #define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4 0
  620. #define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6 1
  621. #define VERSION_4_OFFLOAD_SIZE 22
  622. /*
  623. * New offload OIDs for NDIS 6
  624. */
  625. #define OID_TCP_OFFLOAD_CURRENT_CONFIG 0xFC01020B /* query only */
  626. #define OID_TCP_OFFLOAD_PARAMETERS 0xFC01020C /* set only */
  627. #define OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020D/* query only */
  628. #define OID_TCP_CONNECTION_OFFLOAD_CURRENT_CONFIG 0xFC01020E /* query only */
  629. #define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020F /* query */
  630. #define OID_OFFLOAD_ENCAPSULATION 0x0101010A /* set/query */
  631. struct ndis_offload_params {
  632. struct ndis_oject_header header;
  633. u8 ip_v4_csum;
  634. u8 tcp_ip_v4_csum;
  635. u8 udp_ip_v4_csum;
  636. u8 tcp_ip_v6_csum;
  637. u8 udp_ip_v6_csum;
  638. u8 lso_v1;
  639. u8 ip_sec_v1;
  640. u8 lso_v2_ipv4;
  641. u8 lso_v2_ipv6;
  642. u8 tcp_connection_ip_v4;
  643. u8 tcp_connection_ip_v6;
  644. u32 flags;
  645. u8 ip_sec_v2;
  646. u8 ip_sec_v2_ip_v4;
  647. struct {
  648. u8 rsc_ip_v4;
  649. u8 rsc_ip_v6;
  650. };
  651. struct {
  652. u8 encapsulated_packet_task_offload;
  653. u8 encapsulation_types;
  654. };
  655. };
  656. struct ndis_tcp_ip_checksum_info {
  657. union {
  658. struct {
  659. u32 is_ipv4:1;
  660. u32 is_ipv6:1;
  661. u32 tcp_checksum:1;
  662. u32 udp_checksum:1;
  663. u32 ip_header_checksum:1;
  664. u32 reserved:11;
  665. u32 tcp_header_offset:10;
  666. } transmit;
  667. struct {
  668. u32 tcp_checksum_failed:1;
  669. u32 udp_checksum_failed:1;
  670. u32 ip_checksum_failed:1;
  671. u32 tcp_checksum_succeeded:1;
  672. u32 udp_checksum_succeeded:1;
  673. u32 ip_checksum_succeeded:1;
  674. u32 loopback:1;
  675. u32 tcp_checksum_value_invalid:1;
  676. u32 ip_checksum_value_invalid:1;
  677. } receive;
  678. u32 value;
  679. };
  680. };
  681. struct ndis_tcp_lso_info {
  682. union {
  683. struct {
  684. u32 unused:30;
  685. u32 type:1;
  686. u32 reserved2:1;
  687. } transmit;
  688. struct {
  689. u32 mss:20;
  690. u32 tcp_header_offset:10;
  691. u32 type:1;
  692. u32 reserved2:1;
  693. } lso_v1_transmit;
  694. struct {
  695. u32 tcp_payload:30;
  696. u32 type:1;
  697. u32 reserved2:1;
  698. } lso_v1_transmit_complete;
  699. struct {
  700. u32 mss:20;
  701. u32 tcp_header_offset:10;
  702. u32 type:1;
  703. u32 ip_version:1;
  704. } lso_v2_transmit;
  705. struct {
  706. u32 reserved:30;
  707. u32 type:1;
  708. u32 reserved2:1;
  709. } lso_v2_transmit_complete;
  710. u32 value;
  711. };
  712. };
  713. #define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  714. sizeof(struct ndis_pkt_8021q_info))
  715. #define NDIS_CSUM_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  716. sizeof(struct ndis_tcp_ip_checksum_info))
  717. #define NDIS_LSO_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  718. sizeof(struct ndis_tcp_lso_info))
  719. /* Format of Information buffer passed in a SetRequest for the OID */
  720. /* OID_GEN_RNDIS_CONFIG_PARAMETER. */
  721. struct rndis_config_parameter_info {
  722. u32 parameter_name_offset;
  723. u32 parameter_name_length;
  724. u32 parameter_type;
  725. u32 parameter_value_offset;
  726. u32 parameter_value_length;
  727. };
  728. /* Values for ParameterType in struct rndis_config_parameter_info */
  729. #define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0
  730. #define RNDIS_CONFIG_PARAM_TYPE_STRING 2
  731. /* CONDIS Miniport messages for connection oriented devices */
  732. /* that do not implement a call manager. */
  733. /* CoNdisMiniportCreateVc message */
  734. struct rcondis_mp_create_vc {
  735. u32 req_id;
  736. u32 ndis_vc_handle;
  737. };
  738. /* Response to CoNdisMiniportCreateVc */
  739. struct rcondis_mp_create_vc_complete {
  740. u32 req_id;
  741. u32 dev_vc_handle;
  742. u32 status;
  743. };
  744. /* CoNdisMiniportDeleteVc message */
  745. struct rcondis_mp_delete_vc {
  746. u32 req_id;
  747. u32 dev_vc_handle;
  748. };
  749. /* Response to CoNdisMiniportDeleteVc */
  750. struct rcondis_mp_delete_vc_complete {
  751. u32 req_id;
  752. u32 status;
  753. };
  754. /* CoNdisMiniportQueryRequest message */
  755. struct rcondis_mp_query_request {
  756. u32 req_id;
  757. u32 request_type;
  758. u32 oid;
  759. u32 dev_vc_handle;
  760. u32 info_buflen;
  761. u32 info_buf_offset;
  762. };
  763. /* CoNdisMiniportSetRequest message */
  764. struct rcondis_mp_set_request {
  765. u32 req_id;
  766. u32 request_type;
  767. u32 oid;
  768. u32 dev_vc_handle;
  769. u32 info_buflen;
  770. u32 info_buf_offset;
  771. };
  772. /* CoNdisIndicateStatus message */
  773. struct rcondis_indicate_status {
  774. u32 ndis_vc_handle;
  775. u32 status;
  776. u32 status_buflen;
  777. u32 status_buf_offset;
  778. };
  779. /* CONDIS Call/VC parameters */
  780. struct rcondis_specific_parameters {
  781. u32 parameter_type;
  782. u32 parameter_length;
  783. u32 parameter_lffset;
  784. };
  785. struct rcondis_media_parameters {
  786. u32 flags;
  787. u32 reserved1;
  788. u32 reserved2;
  789. struct rcondis_specific_parameters media_specific;
  790. };
  791. struct rndis_flowspec {
  792. u32 token_rate;
  793. u32 token_bucket_size;
  794. u32 peak_bandwidth;
  795. u32 latency;
  796. u32 delay_variation;
  797. u32 service_type;
  798. u32 max_sdu_size;
  799. u32 minimum_policed_size;
  800. };
  801. struct rcondis_call_manager_parameters {
  802. struct rndis_flowspec transmit;
  803. struct rndis_flowspec receive;
  804. struct rcondis_specific_parameters call_mgr_specific;
  805. };
  806. /* CoNdisMiniportActivateVc message */
  807. struct rcondis_mp_activate_vc_request {
  808. u32 req_id;
  809. u32 flags;
  810. u32 dev_vc_handle;
  811. u32 media_params_offset;
  812. u32 media_params_length;
  813. u32 call_mgr_params_offset;
  814. u32 call_mgr_params_length;
  815. };
  816. /* Response to CoNdisMiniportActivateVc */
  817. struct rcondis_mp_activate_vc_complete {
  818. u32 req_id;
  819. u32 status;
  820. };
  821. /* CoNdisMiniportDeactivateVc message */
  822. struct rcondis_mp_deactivate_vc_request {
  823. u32 req_id;
  824. u32 flags;
  825. u32 dev_vc_handle;
  826. };
  827. /* Response to CoNdisMiniportDeactivateVc */
  828. struct rcondis_mp_deactivate_vc_complete {
  829. u32 req_id;
  830. u32 status;
  831. };
  832. /* union with all of the RNDIS messages */
  833. union rndis_message_container {
  834. struct rndis_packet pkt;
  835. struct rndis_initialize_request init_req;
  836. struct rndis_halt_request halt_req;
  837. struct rndis_query_request query_req;
  838. struct rndis_set_request set_req;
  839. struct rndis_reset_request reset_req;
  840. struct rndis_keepalive_request keep_alive_req;
  841. struct rndis_indicate_status indicate_status;
  842. struct rndis_initialize_complete init_complete;
  843. struct rndis_query_complete query_complete;
  844. struct rndis_set_complete set_complete;
  845. struct rndis_reset_complete reset_complete;
  846. struct rndis_keepalive_complete keep_alive_complete;
  847. struct rcondis_mp_create_vc co_miniport_create_vc;
  848. struct rcondis_mp_delete_vc co_miniport_delete_vc;
  849. struct rcondis_indicate_status co_indicate_status;
  850. struct rcondis_mp_activate_vc_request co_miniport_activate_vc;
  851. struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc;
  852. struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete;
  853. struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete;
  854. struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete;
  855. struct rcondis_mp_deactivate_vc_complete
  856. co_miniport_deactivate_vc_complete;
  857. };
  858. /* Remote NDIS message format */
  859. struct rndis_message {
  860. u32 ndis_msg_type;
  861. /* Total length of this message, from the beginning */
  862. /* of the sruct rndis_message, in bytes. */
  863. u32 msg_len;
  864. /* Actual message */
  865. union rndis_message_container msg;
  866. };
  867. /* Handy macros */
  868. /* get the size of an RNDIS message. Pass in the message type, */
  869. /* struct rndis_set_request, struct rndis_packet for example */
  870. #define RNDIS_MESSAGE_SIZE(msg) \
  871. (sizeof(msg) + (sizeof(struct rndis_message) - \
  872. sizeof(union rndis_message_container)))
  873. /* get pointer to info buffer with message pointer */
  874. #define MESSAGE_TO_INFO_BUFFER(msg) \
  875. (((unsigned char *)(msg)) + msg->info_buf_offset)
  876. /* get pointer to status buffer with message pointer */
  877. #define MESSAGE_TO_STATUS_BUFFER(msg) \
  878. (((unsigned char *)(msg)) + msg->status_buf_offset)
  879. /* get pointer to OOBD buffer with message pointer */
  880. #define MESSAGE_TO_OOBD_BUFFER(msg) \
  881. (((unsigned char *)(msg)) + msg->oob_data_offset)
  882. /* get pointer to data buffer with message pointer */
  883. #define MESSAGE_TO_DATA_BUFFER(msg) \
  884. (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
  885. /* get pointer to contained message from NDIS_MESSAGE pointer */
  886. #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \
  887. ((void *) &rndis_msg->msg)
  888. /* get pointer to contained message from NDIS_MESSAGE pointer */
  889. #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
  890. ((void *) rndis_msg)
  891. #define __struct_bcount(x)
  892. #define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \
  893. sizeof(union rndis_message_container))
  894. #define NDIS_PACKET_TYPE_DIRECTED 0x00000001
  895. #define NDIS_PACKET_TYPE_MULTICAST 0x00000002
  896. #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
  897. #define NDIS_PACKET_TYPE_BROADCAST 0x00000008
  898. #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
  899. #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
  900. #define NDIS_PACKET_TYPE_SMT 0x00000040
  901. #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
  902. #define NDIS_PACKET_TYPE_GROUP 0x00000100
  903. #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
  904. #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
  905. #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
  906. #define INFO_IPV4 2
  907. #define INFO_IPV6 4
  908. #define INFO_TCP 2
  909. #define INFO_UDP 4
  910. #define TRANSPORT_INFO_NOT_IP 0
  911. #define TRANSPORT_INFO_IPV4_TCP ((INFO_IPV4 << 16) | INFO_TCP)
  912. #define TRANSPORT_INFO_IPV4_UDP ((INFO_IPV4 << 16) | INFO_UDP)
  913. #define TRANSPORT_INFO_IPV6_TCP ((INFO_IPV6 << 16) | INFO_TCP)
  914. #define TRANSPORT_INFO_IPV6_UDP ((INFO_IPV6 << 16) | INFO_UDP)
  915. #endif /* _HYPERV_NET_H */