hyperv_net.h 29 KB

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