hyperv_net.h 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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. #define NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE 1
  618. #define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4 0
  619. #define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6 1
  620. /*
  621. * New offload OIDs for NDIS 6
  622. */
  623. #define OID_TCP_OFFLOAD_CURRENT_CONFIG 0xFC01020B /* query only */
  624. #define OID_TCP_OFFLOAD_PARAMETERS 0xFC01020C /* set only */
  625. #define OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020D/* query only */
  626. #define OID_TCP_CONNECTION_OFFLOAD_CURRENT_CONFIG 0xFC01020E /* query only */
  627. #define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020F /* query */
  628. #define OID_OFFLOAD_ENCAPSULATION 0x0101010A /* set/query */
  629. struct ndis_offload_params {
  630. struct ndis_oject_header header;
  631. u8 ip_v4_csum;
  632. u8 tcp_ip_v4_csum;
  633. u8 udp_ip_v4_csum;
  634. u8 tcp_ip_v6_csum;
  635. u8 udp_ip_v6_csum;
  636. u8 lso_v1;
  637. u8 ip_sec_v1;
  638. u8 lso_v2_ipv4;
  639. u8 lso_v2_ipv6;
  640. u8 tcp_connection_ip_v4;
  641. u8 tcp_connection_ip_v6;
  642. u32 flags;
  643. u8 ip_sec_v2;
  644. u8 ip_sec_v2_ip_v4;
  645. struct {
  646. u8 rsc_ip_v4;
  647. u8 rsc_ip_v6;
  648. };
  649. struct {
  650. u8 encapsulated_packet_task_offload;
  651. u8 encapsulation_types;
  652. };
  653. };
  654. struct ndis_tcp_ip_checksum_info {
  655. union {
  656. struct {
  657. u32 is_ipv4:1;
  658. u32 is_ipv6:1;
  659. u32 tcp_checksum:1;
  660. u32 udp_checksum:1;
  661. u32 ip_header_checksum:1;
  662. u32 reserved:11;
  663. u32 tcp_header_offset:10;
  664. } transmit;
  665. struct {
  666. u32 tcp_checksum_failed:1;
  667. u32 udp_checksum_failed:1;
  668. u32 ip_checksum_failed:1;
  669. u32 tcp_checksum_succeeded:1;
  670. u32 udp_checksum_succeeded:1;
  671. u32 ip_checksum_succeeded:1;
  672. u32 loopback:1;
  673. u32 tcp_checksum_value_invalid:1;
  674. u32 ip_checksum_value_invalid:1;
  675. } receive;
  676. u32 value;
  677. };
  678. };
  679. struct ndis_tcp_lso_info {
  680. union {
  681. struct {
  682. u32 unused:30;
  683. u32 type:1;
  684. u32 reserved2:1;
  685. } transmit;
  686. struct {
  687. u32 mss:20;
  688. u32 tcp_header_offset:10;
  689. u32 type:1;
  690. u32 reserved2:1;
  691. } lso_v1_transmit;
  692. struct {
  693. u32 tcp_payload:30;
  694. u32 type:1;
  695. u32 reserved2:1;
  696. } lso_v1_transmit_complete;
  697. struct {
  698. u32 mss:20;
  699. u32 tcp_header_offset:10;
  700. u32 type:1;
  701. u32 ip_version:1;
  702. } lso_v2_transmit;
  703. struct {
  704. u32 reserved:30;
  705. u32 type:1;
  706. u32 reserved2:1;
  707. } lso_v2_transmit_complete;
  708. u32 value;
  709. };
  710. };
  711. #define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  712. sizeof(struct ndis_pkt_8021q_info))
  713. #define NDIS_CSUM_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  714. sizeof(struct ndis_tcp_ip_checksum_info))
  715. #define NDIS_LSO_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  716. sizeof(struct ndis_tcp_lso_info))
  717. /* Format of Information buffer passed in a SetRequest for the OID */
  718. /* OID_GEN_RNDIS_CONFIG_PARAMETER. */
  719. struct rndis_config_parameter_info {
  720. u32 parameter_name_offset;
  721. u32 parameter_name_length;
  722. u32 parameter_type;
  723. u32 parameter_value_offset;
  724. u32 parameter_value_length;
  725. };
  726. /* Values for ParameterType in struct rndis_config_parameter_info */
  727. #define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0
  728. #define RNDIS_CONFIG_PARAM_TYPE_STRING 2
  729. /* CONDIS Miniport messages for connection oriented devices */
  730. /* that do not implement a call manager. */
  731. /* CoNdisMiniportCreateVc message */
  732. struct rcondis_mp_create_vc {
  733. u32 req_id;
  734. u32 ndis_vc_handle;
  735. };
  736. /* Response to CoNdisMiniportCreateVc */
  737. struct rcondis_mp_create_vc_complete {
  738. u32 req_id;
  739. u32 dev_vc_handle;
  740. u32 status;
  741. };
  742. /* CoNdisMiniportDeleteVc message */
  743. struct rcondis_mp_delete_vc {
  744. u32 req_id;
  745. u32 dev_vc_handle;
  746. };
  747. /* Response to CoNdisMiniportDeleteVc */
  748. struct rcondis_mp_delete_vc_complete {
  749. u32 req_id;
  750. u32 status;
  751. };
  752. /* CoNdisMiniportQueryRequest message */
  753. struct rcondis_mp_query_request {
  754. u32 req_id;
  755. u32 request_type;
  756. u32 oid;
  757. u32 dev_vc_handle;
  758. u32 info_buflen;
  759. u32 info_buf_offset;
  760. };
  761. /* CoNdisMiniportSetRequest message */
  762. struct rcondis_mp_set_request {
  763. u32 req_id;
  764. u32 request_type;
  765. u32 oid;
  766. u32 dev_vc_handle;
  767. u32 info_buflen;
  768. u32 info_buf_offset;
  769. };
  770. /* CoNdisIndicateStatus message */
  771. struct rcondis_indicate_status {
  772. u32 ndis_vc_handle;
  773. u32 status;
  774. u32 status_buflen;
  775. u32 status_buf_offset;
  776. };
  777. /* CONDIS Call/VC parameters */
  778. struct rcondis_specific_parameters {
  779. u32 parameter_type;
  780. u32 parameter_length;
  781. u32 parameter_lffset;
  782. };
  783. struct rcondis_media_parameters {
  784. u32 flags;
  785. u32 reserved1;
  786. u32 reserved2;
  787. struct rcondis_specific_parameters media_specific;
  788. };
  789. struct rndis_flowspec {
  790. u32 token_rate;
  791. u32 token_bucket_size;
  792. u32 peak_bandwidth;
  793. u32 latency;
  794. u32 delay_variation;
  795. u32 service_type;
  796. u32 max_sdu_size;
  797. u32 minimum_policed_size;
  798. };
  799. struct rcondis_call_manager_parameters {
  800. struct rndis_flowspec transmit;
  801. struct rndis_flowspec receive;
  802. struct rcondis_specific_parameters call_mgr_specific;
  803. };
  804. /* CoNdisMiniportActivateVc message */
  805. struct rcondis_mp_activate_vc_request {
  806. u32 req_id;
  807. u32 flags;
  808. u32 dev_vc_handle;
  809. u32 media_params_offset;
  810. u32 media_params_length;
  811. u32 call_mgr_params_offset;
  812. u32 call_mgr_params_length;
  813. };
  814. /* Response to CoNdisMiniportActivateVc */
  815. struct rcondis_mp_activate_vc_complete {
  816. u32 req_id;
  817. u32 status;
  818. };
  819. /* CoNdisMiniportDeactivateVc message */
  820. struct rcondis_mp_deactivate_vc_request {
  821. u32 req_id;
  822. u32 flags;
  823. u32 dev_vc_handle;
  824. };
  825. /* Response to CoNdisMiniportDeactivateVc */
  826. struct rcondis_mp_deactivate_vc_complete {
  827. u32 req_id;
  828. u32 status;
  829. };
  830. /* union with all of the RNDIS messages */
  831. union rndis_message_container {
  832. struct rndis_packet pkt;
  833. struct rndis_initialize_request init_req;
  834. struct rndis_halt_request halt_req;
  835. struct rndis_query_request query_req;
  836. struct rndis_set_request set_req;
  837. struct rndis_reset_request reset_req;
  838. struct rndis_keepalive_request keep_alive_req;
  839. struct rndis_indicate_status indicate_status;
  840. struct rndis_initialize_complete init_complete;
  841. struct rndis_query_complete query_complete;
  842. struct rndis_set_complete set_complete;
  843. struct rndis_reset_complete reset_complete;
  844. struct rndis_keepalive_complete keep_alive_complete;
  845. struct rcondis_mp_create_vc co_miniport_create_vc;
  846. struct rcondis_mp_delete_vc co_miniport_delete_vc;
  847. struct rcondis_indicate_status co_indicate_status;
  848. struct rcondis_mp_activate_vc_request co_miniport_activate_vc;
  849. struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc;
  850. struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete;
  851. struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete;
  852. struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete;
  853. struct rcondis_mp_deactivate_vc_complete
  854. co_miniport_deactivate_vc_complete;
  855. };
  856. /* Remote NDIS message format */
  857. struct rndis_message {
  858. u32 ndis_msg_type;
  859. /* Total length of this message, from the beginning */
  860. /* of the sruct rndis_message, in bytes. */
  861. u32 msg_len;
  862. /* Actual message */
  863. union rndis_message_container msg;
  864. };
  865. /* Handy macros */
  866. /* get the size of an RNDIS message. Pass in the message type, */
  867. /* struct rndis_set_request, struct rndis_packet for example */
  868. #define RNDIS_MESSAGE_SIZE(msg) \
  869. (sizeof(msg) + (sizeof(struct rndis_message) - \
  870. sizeof(union rndis_message_container)))
  871. /* get pointer to info buffer with message pointer */
  872. #define MESSAGE_TO_INFO_BUFFER(msg) \
  873. (((unsigned char *)(msg)) + msg->info_buf_offset)
  874. /* get pointer to status buffer with message pointer */
  875. #define MESSAGE_TO_STATUS_BUFFER(msg) \
  876. (((unsigned char *)(msg)) + msg->status_buf_offset)
  877. /* get pointer to OOBD buffer with message pointer */
  878. #define MESSAGE_TO_OOBD_BUFFER(msg) \
  879. (((unsigned char *)(msg)) + msg->oob_data_offset)
  880. /* get pointer to data buffer with message pointer */
  881. #define MESSAGE_TO_DATA_BUFFER(msg) \
  882. (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
  883. /* get pointer to contained message from NDIS_MESSAGE pointer */
  884. #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \
  885. ((void *) &rndis_msg->msg)
  886. /* get pointer to contained message from NDIS_MESSAGE pointer */
  887. #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
  888. ((void *) rndis_msg)
  889. #define __struct_bcount(x)
  890. #define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \
  891. sizeof(union rndis_message_container))
  892. #define NDIS_PACKET_TYPE_DIRECTED 0x00000001
  893. #define NDIS_PACKET_TYPE_MULTICAST 0x00000002
  894. #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
  895. #define NDIS_PACKET_TYPE_BROADCAST 0x00000008
  896. #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
  897. #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
  898. #define NDIS_PACKET_TYPE_SMT 0x00000040
  899. #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
  900. #define NDIS_PACKET_TYPE_GROUP 0x00000100
  901. #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
  902. #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
  903. #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
  904. #define INFO_IPV4 2
  905. #define INFO_IPV6 4
  906. #define INFO_TCP 2
  907. #define INFO_UDP 4
  908. #define TRANSPORT_INFO_NOT_IP 0
  909. #define TRANSPORT_INFO_IPV4_TCP ((INFO_IPV4 << 16) | INFO_TCP)
  910. #define TRANSPORT_INFO_IPV4_UDP ((INFO_IPV4 << 16) | INFO_UDP)
  911. #define TRANSPORT_INFO_IPV6_TCP ((INFO_IPV6 << 16) | INFO_TCP)
  912. #define TRANSPORT_INFO_IPV6_UDP ((INFO_IPV6 << 16) | INFO_UDP)
  913. #endif /* _HYPERV_NET_H */