hyperv_net.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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_ID 0xcafe
  422. /* Preallocated receive packets */
  423. #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
  424. #define NETVSC_PACKET_SIZE 2048
  425. /* Per netvsc channel-specific */
  426. struct netvsc_device {
  427. struct hv_device *dev;
  428. u32 nvsp_version;
  429. atomic_t num_outstanding_sends;
  430. wait_queue_head_t wait_drain;
  431. bool start_remove;
  432. bool destroy;
  433. /*
  434. * List of free preallocated hv_netvsc_packet to represent receive
  435. * packet
  436. */
  437. struct list_head recv_pkt_list;
  438. spinlock_t recv_pkt_list_lock;
  439. /* Receive buffer allocated by us but manages by NetVSP */
  440. void *recv_buf;
  441. u32 recv_buf_size;
  442. u32 recv_buf_gpadl_handle;
  443. u32 recv_section_cnt;
  444. struct nvsp_1_receive_buffer_section *recv_section;
  445. /* Used for NetVSP initialization protocol */
  446. struct completion channel_init_wait;
  447. struct nvsp_message channel_init_pkt;
  448. struct nvsp_message revoke_packet;
  449. /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
  450. struct net_device *ndev;
  451. /* Holds rndis device info */
  452. void *extension;
  453. /* The recive buffer for this device */
  454. unsigned char cb_buffer[NETVSC_PACKET_SIZE];
  455. };
  456. /* NdisInitialize message */
  457. struct rndis_initialize_request {
  458. u32 req_id;
  459. u32 major_ver;
  460. u32 minor_ver;
  461. u32 max_xfer_size;
  462. };
  463. /* Response to NdisInitialize */
  464. struct rndis_initialize_complete {
  465. u32 req_id;
  466. u32 status;
  467. u32 major_ver;
  468. u32 minor_ver;
  469. u32 dev_flags;
  470. u32 medium;
  471. u32 max_pkt_per_msg;
  472. u32 max_xfer_size;
  473. u32 pkt_alignment_factor;
  474. u32 af_list_offset;
  475. u32 af_list_size;
  476. };
  477. /* Call manager devices only: Information about an address family */
  478. /* supported by the device is appended to the response to NdisInitialize. */
  479. struct rndis_co_address_family {
  480. u32 address_family;
  481. u32 major_ver;
  482. u32 minor_ver;
  483. };
  484. /* NdisHalt message */
  485. struct rndis_halt_request {
  486. u32 req_id;
  487. };
  488. /* NdisQueryRequest message */
  489. struct rndis_query_request {
  490. u32 req_id;
  491. u32 oid;
  492. u32 info_buflen;
  493. u32 info_buf_offset;
  494. u32 dev_vc_handle;
  495. };
  496. /* Response to NdisQueryRequest */
  497. struct rndis_query_complete {
  498. u32 req_id;
  499. u32 status;
  500. u32 info_buflen;
  501. u32 info_buf_offset;
  502. };
  503. /* NdisSetRequest message */
  504. struct rndis_set_request {
  505. u32 req_id;
  506. u32 oid;
  507. u32 info_buflen;
  508. u32 info_buf_offset;
  509. u32 dev_vc_handle;
  510. };
  511. /* Response to NdisSetRequest */
  512. struct rndis_set_complete {
  513. u32 req_id;
  514. u32 status;
  515. };
  516. /* NdisReset message */
  517. struct rndis_reset_request {
  518. u32 reserved;
  519. };
  520. /* Response to NdisReset */
  521. struct rndis_reset_complete {
  522. u32 status;
  523. u32 addressing_reset;
  524. };
  525. /* NdisMIndicateStatus message */
  526. struct rndis_indicate_status {
  527. u32 status;
  528. u32 status_buflen;
  529. u32 status_buf_offset;
  530. };
  531. /* Diagnostic information passed as the status buffer in */
  532. /* struct rndis_indicate_status messages signifying error conditions. */
  533. struct rndis_diagnostic_info {
  534. u32 diag_status;
  535. u32 error_offset;
  536. };
  537. /* NdisKeepAlive message */
  538. struct rndis_keepalive_request {
  539. u32 req_id;
  540. };
  541. /* Response to NdisKeepAlive */
  542. struct rndis_keepalive_complete {
  543. u32 req_id;
  544. u32 status;
  545. };
  546. /*
  547. * Data message. All Offset fields contain byte offsets from the beginning of
  548. * struct rndis_packet. All Length fields are in bytes. VcHandle is set
  549. * to 0 for connectionless data, otherwise it contains the VC handle.
  550. */
  551. struct rndis_packet {
  552. u32 data_offset;
  553. u32 data_len;
  554. u32 oob_data_offset;
  555. u32 oob_data_len;
  556. u32 num_oob_data_elements;
  557. u32 per_pkt_info_offset;
  558. u32 per_pkt_info_len;
  559. u32 vc_handle;
  560. u32 reserved;
  561. };
  562. /* Optional Out of Band data associated with a Data message. */
  563. struct rndis_oobd {
  564. u32 size;
  565. u32 type;
  566. u32 class_info_offset;
  567. };
  568. /* Packet extension field contents associated with a Data message. */
  569. struct rndis_per_packet_info {
  570. u32 size;
  571. u32 type;
  572. u32 ppi_offset;
  573. };
  574. enum ndis_per_pkt_info_type {
  575. TCPIP_CHKSUM_PKTINFO,
  576. IPSEC_PKTINFO,
  577. TCP_LARGESEND_PKTINFO,
  578. CLASSIFICATION_HANDLE_PKTINFO,
  579. NDIS_RESERVED,
  580. SG_LIST_PKTINFO,
  581. IEEE_8021Q_INFO,
  582. ORIGINAL_PKTINFO,
  583. PACKET_CANCEL_ID,
  584. ORIGINAL_NET_BUFLIST,
  585. CACHED_NET_BUFLIST,
  586. SHORT_PKT_PADINFO,
  587. MAX_PER_PKT_INFO
  588. };
  589. struct ndis_pkt_8021q_info {
  590. union {
  591. struct {
  592. u32 pri:3; /* User Priority */
  593. u32 cfi:1; /* Canonical Format ID */
  594. u32 vlanid:12; /* VLAN ID */
  595. u32 reserved:16;
  596. };
  597. u32 value;
  598. };
  599. };
  600. struct ndis_oject_header {
  601. u8 type;
  602. u8 revision;
  603. u16 size;
  604. };
  605. #define NDIS_OBJECT_TYPE_DEFAULT 0x80
  606. #define NDIS_OFFLOAD_PARAMETERS_REVISION_3 3
  607. #define NDIS_OFFLOAD_PARAMETERS_NO_CHANGE 0
  608. #define NDIS_OFFLOAD_PARAMETERS_LSOV2_DISABLED 1
  609. #define NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED 2
  610. #define NDIS_OFFLOAD_PARAMETERS_LSOV1_ENABLED 2
  611. #define NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED 1
  612. #define NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED 2
  613. #define NDIS_OFFLOAD_PARAMETERS_TX_RX_DISABLED 1
  614. #define NDIS_OFFLOAD_PARAMETERS_TX_ENABLED_RX_DISABLED 2
  615. #define NDIS_OFFLOAD_PARAMETERS_RX_ENABLED_TX_DISABLED 3
  616. #define NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED 4
  617. /*
  618. * New offload OIDs for NDIS 6
  619. */
  620. #define OID_TCP_OFFLOAD_CURRENT_CONFIG 0xFC01020B /* query only */
  621. #define OID_TCP_OFFLOAD_PARAMETERS 0xFC01020C /* set only */
  622. #define OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020D/* query only */
  623. #define OID_TCP_CONNECTION_OFFLOAD_CURRENT_CONFIG 0xFC01020E /* query only */
  624. #define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020F /* query */
  625. #define OID_OFFLOAD_ENCAPSULATION 0x0101010A /* set/query */
  626. struct ndis_offload_params {
  627. struct ndis_oject_header header;
  628. u8 ip_v4_csum;
  629. u8 tcp_ip_v4_csum;
  630. u8 udp_ip_v4_csum;
  631. u8 tcp_ip_v6_csum;
  632. u8 udp_ip_v6_csum;
  633. u8 lso_v1;
  634. u8 ip_sec_v1;
  635. u8 lso_v2_ipv4;
  636. u8 lso_v2_ipv6;
  637. u8 tcp_connection_ip_v4;
  638. u8 tcp_connection_ip_v6;
  639. u32 flags;
  640. u8 ip_sec_v2;
  641. u8 ip_sec_v2_ip_v4;
  642. struct {
  643. u8 rsc_ip_v4;
  644. u8 rsc_ip_v6;
  645. };
  646. struct {
  647. u8 encapsulated_packet_task_offload;
  648. u8 encapsulation_types;
  649. };
  650. };
  651. struct ndis_tcp_ip_checksum_info {
  652. union {
  653. struct {
  654. u32 is_ipv4:1;
  655. u32 is_ipv6:1;
  656. u32 tcp_checksum:1;
  657. u32 udp_checksum:1;
  658. u32 ip_header_checksum:1;
  659. u32 reserved:11;
  660. u32 tcp_header_offset:10;
  661. } transmit;
  662. struct {
  663. u32 tcp_checksum_failed:1;
  664. u32 udp_checksum_failed:1;
  665. u32 ip_checksum_failed:1;
  666. u32 tcp_checksum_succeeded:1;
  667. u32 udp_checksum_succeeded:1;
  668. u32 ip_checksum_succeeded:1;
  669. u32 loopback:1;
  670. u32 tcp_checksum_value_invalid:1;
  671. u32 ip_checksum_value_invalid:1;
  672. } receive;
  673. u32 value;
  674. };
  675. };
  676. #define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  677. sizeof(struct ndis_pkt_8021q_info))
  678. #define NDIS_CSUM_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  679. sizeof(struct ndis_tcp_ip_checksum_info))
  680. /* Format of Information buffer passed in a SetRequest for the OID */
  681. /* OID_GEN_RNDIS_CONFIG_PARAMETER. */
  682. struct rndis_config_parameter_info {
  683. u32 parameter_name_offset;
  684. u32 parameter_name_length;
  685. u32 parameter_type;
  686. u32 parameter_value_offset;
  687. u32 parameter_value_length;
  688. };
  689. /* Values for ParameterType in struct rndis_config_parameter_info */
  690. #define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0
  691. #define RNDIS_CONFIG_PARAM_TYPE_STRING 2
  692. /* CONDIS Miniport messages for connection oriented devices */
  693. /* that do not implement a call manager. */
  694. /* CoNdisMiniportCreateVc message */
  695. struct rcondis_mp_create_vc {
  696. u32 req_id;
  697. u32 ndis_vc_handle;
  698. };
  699. /* Response to CoNdisMiniportCreateVc */
  700. struct rcondis_mp_create_vc_complete {
  701. u32 req_id;
  702. u32 dev_vc_handle;
  703. u32 status;
  704. };
  705. /* CoNdisMiniportDeleteVc message */
  706. struct rcondis_mp_delete_vc {
  707. u32 req_id;
  708. u32 dev_vc_handle;
  709. };
  710. /* Response to CoNdisMiniportDeleteVc */
  711. struct rcondis_mp_delete_vc_complete {
  712. u32 req_id;
  713. u32 status;
  714. };
  715. /* CoNdisMiniportQueryRequest message */
  716. struct rcondis_mp_query_request {
  717. u32 req_id;
  718. u32 request_type;
  719. u32 oid;
  720. u32 dev_vc_handle;
  721. u32 info_buflen;
  722. u32 info_buf_offset;
  723. };
  724. /* CoNdisMiniportSetRequest message */
  725. struct rcondis_mp_set_request {
  726. u32 req_id;
  727. u32 request_type;
  728. u32 oid;
  729. u32 dev_vc_handle;
  730. u32 info_buflen;
  731. u32 info_buf_offset;
  732. };
  733. /* CoNdisIndicateStatus message */
  734. struct rcondis_indicate_status {
  735. u32 ndis_vc_handle;
  736. u32 status;
  737. u32 status_buflen;
  738. u32 status_buf_offset;
  739. };
  740. /* CONDIS Call/VC parameters */
  741. struct rcondis_specific_parameters {
  742. u32 parameter_type;
  743. u32 parameter_length;
  744. u32 parameter_lffset;
  745. };
  746. struct rcondis_media_parameters {
  747. u32 flags;
  748. u32 reserved1;
  749. u32 reserved2;
  750. struct rcondis_specific_parameters media_specific;
  751. };
  752. struct rndis_flowspec {
  753. u32 token_rate;
  754. u32 token_bucket_size;
  755. u32 peak_bandwidth;
  756. u32 latency;
  757. u32 delay_variation;
  758. u32 service_type;
  759. u32 max_sdu_size;
  760. u32 minimum_policed_size;
  761. };
  762. struct rcondis_call_manager_parameters {
  763. struct rndis_flowspec transmit;
  764. struct rndis_flowspec receive;
  765. struct rcondis_specific_parameters call_mgr_specific;
  766. };
  767. /* CoNdisMiniportActivateVc message */
  768. struct rcondis_mp_activate_vc_request {
  769. u32 req_id;
  770. u32 flags;
  771. u32 dev_vc_handle;
  772. u32 media_params_offset;
  773. u32 media_params_length;
  774. u32 call_mgr_params_offset;
  775. u32 call_mgr_params_length;
  776. };
  777. /* Response to CoNdisMiniportActivateVc */
  778. struct rcondis_mp_activate_vc_complete {
  779. u32 req_id;
  780. u32 status;
  781. };
  782. /* CoNdisMiniportDeactivateVc message */
  783. struct rcondis_mp_deactivate_vc_request {
  784. u32 req_id;
  785. u32 flags;
  786. u32 dev_vc_handle;
  787. };
  788. /* Response to CoNdisMiniportDeactivateVc */
  789. struct rcondis_mp_deactivate_vc_complete {
  790. u32 req_id;
  791. u32 status;
  792. };
  793. /* union with all of the RNDIS messages */
  794. union rndis_message_container {
  795. struct rndis_packet pkt;
  796. struct rndis_initialize_request init_req;
  797. struct rndis_halt_request halt_req;
  798. struct rndis_query_request query_req;
  799. struct rndis_set_request set_req;
  800. struct rndis_reset_request reset_req;
  801. struct rndis_keepalive_request keep_alive_req;
  802. struct rndis_indicate_status indicate_status;
  803. struct rndis_initialize_complete init_complete;
  804. struct rndis_query_complete query_complete;
  805. struct rndis_set_complete set_complete;
  806. struct rndis_reset_complete reset_complete;
  807. struct rndis_keepalive_complete keep_alive_complete;
  808. struct rcondis_mp_create_vc co_miniport_create_vc;
  809. struct rcondis_mp_delete_vc co_miniport_delete_vc;
  810. struct rcondis_indicate_status co_indicate_status;
  811. struct rcondis_mp_activate_vc_request co_miniport_activate_vc;
  812. struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc;
  813. struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete;
  814. struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete;
  815. struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete;
  816. struct rcondis_mp_deactivate_vc_complete
  817. co_miniport_deactivate_vc_complete;
  818. };
  819. /* Remote NDIS message format */
  820. struct rndis_message {
  821. u32 ndis_msg_type;
  822. /* Total length of this message, from the beginning */
  823. /* of the sruct rndis_message, in bytes. */
  824. u32 msg_len;
  825. /* Actual message */
  826. union rndis_message_container msg;
  827. };
  828. /* Handy macros */
  829. /* get the size of an RNDIS message. Pass in the message type, */
  830. /* struct rndis_set_request, struct rndis_packet for example */
  831. #define RNDIS_MESSAGE_SIZE(msg) \
  832. (sizeof(msg) + (sizeof(struct rndis_message) - \
  833. sizeof(union rndis_message_container)))
  834. /* get pointer to info buffer with message pointer */
  835. #define MESSAGE_TO_INFO_BUFFER(msg) \
  836. (((unsigned char *)(msg)) + msg->info_buf_offset)
  837. /* get pointer to status buffer with message pointer */
  838. #define MESSAGE_TO_STATUS_BUFFER(msg) \
  839. (((unsigned char *)(msg)) + msg->status_buf_offset)
  840. /* get pointer to OOBD buffer with message pointer */
  841. #define MESSAGE_TO_OOBD_BUFFER(msg) \
  842. (((unsigned char *)(msg)) + msg->oob_data_offset)
  843. /* get pointer to data buffer with message pointer */
  844. #define MESSAGE_TO_DATA_BUFFER(msg) \
  845. (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
  846. /* get pointer to contained message from NDIS_MESSAGE pointer */
  847. #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \
  848. ((void *) &rndis_msg->msg)
  849. /* get pointer to contained message from NDIS_MESSAGE pointer */
  850. #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
  851. ((void *) rndis_msg)
  852. #define __struct_bcount(x)
  853. #define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \
  854. sizeof(union rndis_message_container))
  855. #define NDIS_PACKET_TYPE_DIRECTED 0x00000001
  856. #define NDIS_PACKET_TYPE_MULTICAST 0x00000002
  857. #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
  858. #define NDIS_PACKET_TYPE_BROADCAST 0x00000008
  859. #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
  860. #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
  861. #define NDIS_PACKET_TYPE_SMT 0x00000040
  862. #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
  863. #define NDIS_PACKET_TYPE_GROUP 0x00000100
  864. #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
  865. #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
  866. #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
  867. #define INFO_IPV4 2
  868. #define INFO_IPV6 4
  869. #define INFO_TCP 2
  870. #define INFO_UDP 4
  871. #define TRANSPORT_INFO_NOT_IP 0
  872. #define TRANSPORT_INFO_IPV4_TCP ((INFO_IPV4 << 16) | INFO_TCP)
  873. #define TRANSPORT_INFO_IPV4_UDP ((INFO_IPV4 << 16) | INFO_UDP)
  874. #define TRANSPORT_INFO_IPV6_TCP ((INFO_IPV6 << 16) | INFO_TCP)
  875. #define TRANSPORT_INFO_IPV6_UDP ((INFO_IPV6 << 16) | INFO_UDP)
  876. #endif /* _HYPERV_NET_H */