hyperv_net.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  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_OBJECT_TYPE_OFFLOAD 0xa7
  34. #define NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2
  35. #define NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2
  36. struct ndis_obj_header {
  37. u8 type;
  38. u8 rev;
  39. u16 size;
  40. } __packed;
  41. /* ndis_recv_scale_cap/cap_flag */
  42. #define NDIS_RSS_CAPS_MESSAGE_SIGNALED_INTERRUPTS 0x01000000
  43. #define NDIS_RSS_CAPS_CLASSIFICATION_AT_ISR 0x02000000
  44. #define NDIS_RSS_CAPS_CLASSIFICATION_AT_DPC 0x04000000
  45. #define NDIS_RSS_CAPS_USING_MSI_X 0x08000000
  46. #define NDIS_RSS_CAPS_RSS_AVAILABLE_ON_PORTS 0x10000000
  47. #define NDIS_RSS_CAPS_SUPPORTS_MSI_X 0x20000000
  48. #define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV4 0x00000100
  49. #define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6 0x00000200
  50. #define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6_EX 0x00000400
  51. struct ndis_recv_scale_cap { /* NDIS_RECEIVE_SCALE_CAPABILITIES */
  52. struct ndis_obj_header hdr;
  53. u32 cap_flag;
  54. u32 num_int_msg;
  55. u32 num_recv_que;
  56. u16 num_indirect_tabent;
  57. } __packed;
  58. /* ndis_recv_scale_param flags */
  59. #define NDIS_RSS_PARAM_FLAG_BASE_CPU_UNCHANGED 0x0001
  60. #define NDIS_RSS_PARAM_FLAG_HASH_INFO_UNCHANGED 0x0002
  61. #define NDIS_RSS_PARAM_FLAG_ITABLE_UNCHANGED 0x0004
  62. #define NDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED 0x0008
  63. #define NDIS_RSS_PARAM_FLAG_DISABLE_RSS 0x0010
  64. /* Hash info bits */
  65. #define NDIS_HASH_FUNC_TOEPLITZ 0x00000001
  66. #define NDIS_HASH_IPV4 0x00000100
  67. #define NDIS_HASH_TCP_IPV4 0x00000200
  68. #define NDIS_HASH_IPV6 0x00000400
  69. #define NDIS_HASH_IPV6_EX 0x00000800
  70. #define NDIS_HASH_TCP_IPV6 0x00001000
  71. #define NDIS_HASH_TCP_IPV6_EX 0x00002000
  72. #define NDIS_RSS_INDIRECTION_TABLE_MAX_SIZE_REVISION_2 (128 * 4)
  73. #define NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2 40
  74. #define ITAB_NUM 128
  75. struct ndis_recv_scale_param { /* NDIS_RECEIVE_SCALE_PARAMETERS */
  76. struct ndis_obj_header hdr;
  77. /* Qualifies the rest of the information */
  78. u16 flag;
  79. /* The base CPU number to do receive processing. not used */
  80. u16 base_cpu_number;
  81. /* This describes the hash function and type being enabled */
  82. u32 hashinfo;
  83. /* The size of indirection table array */
  84. u16 indirect_tabsize;
  85. /* The offset of the indirection table from the beginning of this
  86. * structure
  87. */
  88. u32 indirect_taboffset;
  89. /* The size of the hash secret key */
  90. u16 hashkey_size;
  91. /* The offset of the secret key from the beginning of this structure */
  92. u32 kashkey_offset;
  93. u32 processor_masks_offset;
  94. u32 num_processor_masks;
  95. u32 processor_masks_entry_size;
  96. };
  97. /* Fwd declaration */
  98. struct ndis_tcp_ip_checksum_info;
  99. struct ndis_pkt_8021q_info;
  100. /*
  101. * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
  102. * within the RNDIS
  103. *
  104. * The size of this structure is less than 48 bytes and we can now
  105. * place this structure in the skb->cb field.
  106. */
  107. struct hv_netvsc_packet {
  108. /* Bookkeeping stuff */
  109. u8 cp_partial; /* partial copy into send buffer */
  110. u8 rmsg_size; /* RNDIS header and PPI size */
  111. u8 rmsg_pgcnt; /* page count of RNDIS header and PPI */
  112. u8 page_buf_cnt;
  113. u16 q_idx;
  114. u16 total_packets;
  115. u32 total_bytes;
  116. u32 send_buf_index;
  117. u32 total_data_buflen;
  118. };
  119. struct netvsc_device_info {
  120. unsigned char mac_adr[ETH_ALEN];
  121. int ring_size;
  122. u32 num_chn;
  123. };
  124. enum rndis_device_state {
  125. RNDIS_DEV_UNINITIALIZED = 0,
  126. RNDIS_DEV_INITIALIZING,
  127. RNDIS_DEV_INITIALIZED,
  128. RNDIS_DEV_DATAINITIALIZED,
  129. };
  130. #define NETVSC_HASH_KEYLEN 40
  131. struct rndis_device {
  132. struct net_device *ndev;
  133. enum rndis_device_state state;
  134. atomic_t new_req_id;
  135. spinlock_t request_lock;
  136. struct list_head req_list;
  137. struct work_struct mcast_work;
  138. bool link_state; /* 0 - link up, 1 - link down */
  139. u8 hw_mac_adr[ETH_ALEN];
  140. u8 rss_key[NETVSC_HASH_KEYLEN];
  141. u16 ind_table[ITAB_NUM];
  142. };
  143. /* Interface */
  144. struct rndis_message;
  145. struct netvsc_device;
  146. struct net_device_context;
  147. struct netvsc_device *netvsc_device_add(struct hv_device *device,
  148. const struct netvsc_device_info *info);
  149. int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx);
  150. void netvsc_device_remove(struct hv_device *device);
  151. int netvsc_send(struct net_device_context *ndc,
  152. struct hv_netvsc_packet *packet,
  153. struct rndis_message *rndis_msg,
  154. struct hv_page_buffer *page_buffer,
  155. struct sk_buff *skb);
  156. void netvsc_linkstatus_callback(struct hv_device *device_obj,
  157. struct rndis_message *resp);
  158. int netvsc_recv_callback(struct net_device *net,
  159. struct vmbus_channel *channel,
  160. void *data, u32 len,
  161. const struct ndis_tcp_ip_checksum_info *csum_info,
  162. const struct ndis_pkt_8021q_info *vlan);
  163. void netvsc_channel_cb(void *context);
  164. int netvsc_poll(struct napi_struct *napi, int budget);
  165. bool rndis_filter_opened(const struct netvsc_device *nvdev);
  166. int rndis_filter_open(struct netvsc_device *nvdev);
  167. int rndis_filter_close(struct netvsc_device *nvdev);
  168. struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
  169. struct netvsc_device_info *info);
  170. void rndis_filter_update(struct netvsc_device *nvdev);
  171. void rndis_filter_device_remove(struct hv_device *dev,
  172. struct netvsc_device *nvdev);
  173. int rndis_filter_set_rss_param(struct rndis_device *rdev,
  174. const u8 *key, int num_queue);
  175. int rndis_filter_receive(struct net_device *ndev,
  176. struct netvsc_device *net_dev,
  177. struct hv_device *dev,
  178. struct vmbus_channel *channel,
  179. void *data, u32 buflen);
  180. int rndis_filter_set_device_mac(struct netvsc_device *ndev,
  181. const char *mac);
  182. void netvsc_switch_datapath(struct net_device *nv_dev, bool vf);
  183. #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
  184. #define NVSP_PROTOCOL_VERSION_1 2
  185. #define NVSP_PROTOCOL_VERSION_2 0x30002
  186. #define NVSP_PROTOCOL_VERSION_4 0x40000
  187. #define NVSP_PROTOCOL_VERSION_5 0x50000
  188. enum {
  189. NVSP_MSG_TYPE_NONE = 0,
  190. /* Init Messages */
  191. NVSP_MSG_TYPE_INIT = 1,
  192. NVSP_MSG_TYPE_INIT_COMPLETE = 2,
  193. NVSP_VERSION_MSG_START = 100,
  194. /* Version 1 Messages */
  195. NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START,
  196. NVSP_MSG1_TYPE_SEND_RECV_BUF,
  197. NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
  198. NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
  199. NVSP_MSG1_TYPE_SEND_SEND_BUF,
  200. NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
  201. NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
  202. NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
  203. NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
  204. /* Version 2 messages */
  205. NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF,
  206. NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF_COMP,
  207. NVSP_MSG2_TYPE_REVOKE_CHIMNEY_DELEGATED_BUF,
  208. NVSP_MSG2_TYPE_RESUME_CHIMNEY_RX_INDICATION,
  209. NVSP_MSG2_TYPE_TERMINATE_CHIMNEY,
  210. NVSP_MSG2_TYPE_TERMINATE_CHIMNEY_COMP,
  211. NVSP_MSG2_TYPE_INDICATE_CHIMNEY_EVENT,
  212. NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT,
  213. NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT_COMP,
  214. NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ,
  215. NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ_COMP,
  216. NVSP_MSG2_TYPE_ALLOC_RXBUF,
  217. NVSP_MSG2_TYPE_ALLOC_RXBUF_COMP,
  218. NVSP_MSG2_TYPE_FREE_RXBUF,
  219. NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT,
  220. NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT_COMP,
  221. NVSP_MSG2_TYPE_SEND_NDIS_CONFIG,
  222. NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE,
  223. NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
  224. NVSP_MSG2_MAX = NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
  225. /* Version 4 messages */
  226. NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION,
  227. NVSP_MSG4_TYPE_SWITCH_DATA_PATH,
  228. NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
  229. NVSP_MSG4_MAX = NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
  230. /* Version 5 messages */
  231. NVSP_MSG5_TYPE_OID_QUERY_EX,
  232. NVSP_MSG5_TYPE_OID_QUERY_EX_COMP,
  233. NVSP_MSG5_TYPE_SUBCHANNEL,
  234. NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
  235. NVSP_MSG5_MAX = NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
  236. };
  237. enum {
  238. NVSP_STAT_NONE = 0,
  239. NVSP_STAT_SUCCESS,
  240. NVSP_STAT_FAIL,
  241. NVSP_STAT_PROTOCOL_TOO_NEW,
  242. NVSP_STAT_PROTOCOL_TOO_OLD,
  243. NVSP_STAT_INVALID_RNDIS_PKT,
  244. NVSP_STAT_BUSY,
  245. NVSP_STAT_PROTOCOL_UNSUPPORTED,
  246. NVSP_STAT_MAX,
  247. };
  248. struct nvsp_message_header {
  249. u32 msg_type;
  250. };
  251. /* Init Messages */
  252. /*
  253. * This message is used by the VSC to initialize the channel after the channels
  254. * has been opened. This message should never include anything other then
  255. * versioning (i.e. this message will be the same for ever).
  256. */
  257. struct nvsp_message_init {
  258. u32 min_protocol_ver;
  259. u32 max_protocol_ver;
  260. } __packed;
  261. /*
  262. * This message is used by the VSP to complete the initialization of the
  263. * channel. This message should never include anything other then versioning
  264. * (i.e. this message will be the same for ever).
  265. */
  266. struct nvsp_message_init_complete {
  267. u32 negotiated_protocol_ver;
  268. u32 max_mdl_chain_len;
  269. u32 status;
  270. } __packed;
  271. union nvsp_message_init_uber {
  272. struct nvsp_message_init init;
  273. struct nvsp_message_init_complete init_complete;
  274. } __packed;
  275. /* Version 1 Messages */
  276. /*
  277. * This message is used by the VSC to send the NDIS version to the VSP. The VSP
  278. * can use this information when handling OIDs sent by the VSC.
  279. */
  280. struct nvsp_1_message_send_ndis_version {
  281. u32 ndis_major_ver;
  282. u32 ndis_minor_ver;
  283. } __packed;
  284. /*
  285. * This message is used by the VSC to send a receive buffer to the VSP. The VSP
  286. * can then use the receive buffer to send data to the VSC.
  287. */
  288. struct nvsp_1_message_send_receive_buffer {
  289. u32 gpadl_handle;
  290. u16 id;
  291. } __packed;
  292. struct nvsp_1_receive_buffer_section {
  293. u32 offset;
  294. u32 sub_alloc_size;
  295. u32 num_sub_allocs;
  296. u32 end_offset;
  297. } __packed;
  298. /*
  299. * This message is used by the VSP to acknowledge a receive buffer send by the
  300. * VSC. This message must be sent by the VSP before the VSP uses the receive
  301. * buffer.
  302. */
  303. struct nvsp_1_message_send_receive_buffer_complete {
  304. u32 status;
  305. u32 num_sections;
  306. /*
  307. * The receive buffer is split into two parts, a large suballocation
  308. * section and a small suballocation section. These sections are then
  309. * suballocated by a certain size.
  310. */
  311. /*
  312. * For example, the following break up of the receive buffer has 6
  313. * large suballocations and 10 small suballocations.
  314. */
  315. /*
  316. * | Large Section | | Small Section |
  317. * ------------------------------------------------------------
  318. * | | | | | | | | | | | | | | | | | |
  319. * | |
  320. * LargeOffset SmallOffset
  321. */
  322. struct nvsp_1_receive_buffer_section sections[1];
  323. } __packed;
  324. /*
  325. * This message is sent by the VSC to revoke the receive buffer. After the VSP
  326. * completes this transaction, the vsp should never use the receive buffer
  327. * again.
  328. */
  329. struct nvsp_1_message_revoke_receive_buffer {
  330. u16 id;
  331. };
  332. /*
  333. * This message is used by the VSC to send a send buffer to the VSP. The VSC
  334. * can then use the send buffer to send data to the VSP.
  335. */
  336. struct nvsp_1_message_send_send_buffer {
  337. u32 gpadl_handle;
  338. u16 id;
  339. } __packed;
  340. /*
  341. * This message is used by the VSP to acknowledge a send buffer sent by the
  342. * VSC. This message must be sent by the VSP before the VSP uses the sent
  343. * buffer.
  344. */
  345. struct nvsp_1_message_send_send_buffer_complete {
  346. u32 status;
  347. /*
  348. * The VSC gets to choose the size of the send buffer and the VSP gets
  349. * to choose the sections size of the buffer. This was done to enable
  350. * dynamic reconfigurations when the cost of GPA-direct buffers
  351. * decreases.
  352. */
  353. u32 section_size;
  354. } __packed;
  355. /*
  356. * This message is sent by the VSC to revoke the send buffer. After the VSP
  357. * completes this transaction, the vsp should never use the send buffer again.
  358. */
  359. struct nvsp_1_message_revoke_send_buffer {
  360. u16 id;
  361. };
  362. /*
  363. * This message is used by both the VSP and the VSC to send a RNDIS message to
  364. * the opposite channel endpoint.
  365. */
  366. struct nvsp_1_message_send_rndis_packet {
  367. /*
  368. * This field is specified by RNDIS. They assume there's two different
  369. * channels of communication. However, the Network VSP only has one.
  370. * Therefore, the channel travels with the RNDIS packet.
  371. */
  372. u32 channel_type;
  373. /*
  374. * This field is used to send part or all of the data through a send
  375. * buffer. This values specifies an index into the send buffer. If the
  376. * index is 0xFFFFFFFF, then the send buffer is not being used and all
  377. * of the data was sent through other VMBus mechanisms.
  378. */
  379. u32 send_buf_section_index;
  380. u32 send_buf_section_size;
  381. } __packed;
  382. /*
  383. * This message is used by both the VSP and the VSC to complete a RNDIS message
  384. * to the opposite channel endpoint. At this point, the initiator of this
  385. * message cannot use any resources associated with the original RNDIS packet.
  386. */
  387. struct nvsp_1_message_send_rndis_packet_complete {
  388. u32 status;
  389. };
  390. union nvsp_1_message_uber {
  391. struct nvsp_1_message_send_ndis_version send_ndis_ver;
  392. struct nvsp_1_message_send_receive_buffer send_recv_buf;
  393. struct nvsp_1_message_send_receive_buffer_complete
  394. send_recv_buf_complete;
  395. struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
  396. struct nvsp_1_message_send_send_buffer send_send_buf;
  397. struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
  398. struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
  399. struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
  400. struct nvsp_1_message_send_rndis_packet_complete
  401. send_rndis_pkt_complete;
  402. } __packed;
  403. /*
  404. * Network VSP protocol version 2 messages:
  405. */
  406. struct nvsp_2_vsc_capability {
  407. union {
  408. u64 data;
  409. struct {
  410. u64 vmq:1;
  411. u64 chimney:1;
  412. u64 sriov:1;
  413. u64 ieee8021q:1;
  414. u64 correlation_id:1;
  415. u64 teaming:1;
  416. };
  417. };
  418. } __packed;
  419. struct nvsp_2_send_ndis_config {
  420. u32 mtu;
  421. u32 reserved;
  422. struct nvsp_2_vsc_capability capability;
  423. } __packed;
  424. /* Allocate receive buffer */
  425. struct nvsp_2_alloc_rxbuf {
  426. /* Allocation ID to match the allocation request and response */
  427. u32 alloc_id;
  428. /* Length of the VM shared memory receive buffer that needs to
  429. * be allocated
  430. */
  431. u32 len;
  432. } __packed;
  433. /* Allocate receive buffer complete */
  434. struct nvsp_2_alloc_rxbuf_comp {
  435. /* The NDIS_STATUS code for buffer allocation */
  436. u32 status;
  437. u32 alloc_id;
  438. /* GPADL handle for the allocated receive buffer */
  439. u32 gpadl_handle;
  440. /* Receive buffer ID */
  441. u64 recv_buf_id;
  442. } __packed;
  443. struct nvsp_2_free_rxbuf {
  444. u64 recv_buf_id;
  445. } __packed;
  446. union nvsp_2_message_uber {
  447. struct nvsp_2_send_ndis_config send_ndis_config;
  448. struct nvsp_2_alloc_rxbuf alloc_rxbuf;
  449. struct nvsp_2_alloc_rxbuf_comp alloc_rxbuf_comp;
  450. struct nvsp_2_free_rxbuf free_rxbuf;
  451. } __packed;
  452. struct nvsp_4_send_vf_association {
  453. /* 1: allocated, serial number is valid. 0: not allocated */
  454. u32 allocated;
  455. /* Serial number of the VF to team with */
  456. u32 serial;
  457. } __packed;
  458. enum nvsp_vm_datapath {
  459. NVSP_DATAPATH_SYNTHETIC = 0,
  460. NVSP_DATAPATH_VF,
  461. NVSP_DATAPATH_MAX
  462. };
  463. struct nvsp_4_sw_datapath {
  464. u32 active_datapath; /* active data path in VM */
  465. } __packed;
  466. union nvsp_4_message_uber {
  467. struct nvsp_4_send_vf_association vf_assoc;
  468. struct nvsp_4_sw_datapath active_dp;
  469. } __packed;
  470. enum nvsp_subchannel_operation {
  471. NVSP_SUBCHANNEL_NONE = 0,
  472. NVSP_SUBCHANNEL_ALLOCATE,
  473. NVSP_SUBCHANNEL_MAX
  474. };
  475. struct nvsp_5_subchannel_request {
  476. u32 op;
  477. u32 num_subchannels;
  478. } __packed;
  479. struct nvsp_5_subchannel_complete {
  480. u32 status;
  481. u32 num_subchannels; /* Actual number of subchannels allocated */
  482. } __packed;
  483. struct nvsp_5_send_indirect_table {
  484. /* The number of entries in the send indirection table */
  485. u32 count;
  486. /* The offset of the send indirection table from top of this struct.
  487. * The send indirection table tells which channel to put the send
  488. * traffic on. Each entry is a channel number.
  489. */
  490. u32 offset;
  491. } __packed;
  492. union nvsp_5_message_uber {
  493. struct nvsp_5_subchannel_request subchn_req;
  494. struct nvsp_5_subchannel_complete subchn_comp;
  495. struct nvsp_5_send_indirect_table send_table;
  496. } __packed;
  497. union nvsp_all_messages {
  498. union nvsp_message_init_uber init_msg;
  499. union nvsp_1_message_uber v1_msg;
  500. union nvsp_2_message_uber v2_msg;
  501. union nvsp_4_message_uber v4_msg;
  502. union nvsp_5_message_uber v5_msg;
  503. } __packed;
  504. /* ALL Messages */
  505. struct nvsp_message {
  506. struct nvsp_message_header hdr;
  507. union nvsp_all_messages msg;
  508. } __packed;
  509. #define NETVSC_MTU 65535
  510. #define NETVSC_MTU_MIN ETH_MIN_MTU
  511. #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
  512. #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
  513. #define NETVSC_SEND_BUFFER_SIZE (1024 * 1024 * 15) /* 15MB */
  514. #define NETVSC_INVALID_INDEX -1
  515. #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
  516. #define NETVSC_SEND_BUFFER_ID 0
  517. #define NETVSC_PACKET_SIZE 4096
  518. #define VRSS_SEND_TAB_SIZE 16 /* must be power of 2 */
  519. #define VRSS_CHANNEL_MAX 64
  520. #define VRSS_CHANNEL_DEFAULT 8
  521. #define RNDIS_MAX_PKT_DEFAULT 8
  522. #define RNDIS_PKT_ALIGN_DEFAULT 8
  523. struct multi_send_data {
  524. struct sk_buff *skb; /* skb containing the pkt */
  525. struct hv_netvsc_packet *pkt; /* netvsc pkt pending */
  526. u32 count; /* counter of batched packets */
  527. };
  528. struct recv_comp_data {
  529. u64 tid; /* transaction id */
  530. u32 status;
  531. };
  532. struct multi_recv_comp {
  533. struct recv_comp_data *slots;
  534. u32 first; /* first data entry */
  535. u32 next; /* next entry for writing */
  536. };
  537. struct netvsc_stats {
  538. u64 packets;
  539. u64 bytes;
  540. u64 broadcast;
  541. u64 multicast;
  542. struct u64_stats_sync syncp;
  543. };
  544. struct netvsc_ethtool_stats {
  545. unsigned long tx_scattered;
  546. unsigned long tx_no_memory;
  547. unsigned long tx_no_space;
  548. unsigned long tx_too_big;
  549. unsigned long tx_busy;
  550. };
  551. struct netvsc_vf_pcpu_stats {
  552. u64 rx_packets;
  553. u64 rx_bytes;
  554. u64 tx_packets;
  555. u64 tx_bytes;
  556. struct u64_stats_sync syncp;
  557. u32 tx_dropped;
  558. };
  559. struct netvsc_reconfig {
  560. struct list_head list;
  561. u32 event;
  562. };
  563. /* The context of the netvsc device */
  564. struct net_device_context {
  565. /* point back to our device context */
  566. struct hv_device *device_ctx;
  567. /* netvsc_device */
  568. struct netvsc_device __rcu *nvdev;
  569. /* reconfigure work */
  570. struct delayed_work dwork;
  571. /* last reconfig time */
  572. unsigned long last_reconfig;
  573. /* reconfig events */
  574. struct list_head reconfig_events;
  575. /* list protection */
  576. spinlock_t lock;
  577. u32 msg_enable; /* debug level */
  578. u32 tx_checksum_mask;
  579. u32 tx_send_table[VRSS_SEND_TAB_SIZE];
  580. /* Ethtool settings */
  581. u8 duplex;
  582. u32 speed;
  583. struct netvsc_ethtool_stats eth_stats;
  584. /* State to manage the associated VF interface. */
  585. struct net_device __rcu *vf_netdev;
  586. struct netvsc_vf_pcpu_stats __percpu *vf_stats;
  587. struct work_struct vf_takeover;
  588. /* 1: allocated, serial number is valid. 0: not allocated */
  589. u32 vf_alloc;
  590. /* Serial number of the VF to team with */
  591. u32 vf_serial;
  592. };
  593. /* Per channel data */
  594. struct netvsc_channel {
  595. struct vmbus_channel *channel;
  596. struct netvsc_device *net_device;
  597. const struct vmpacket_descriptor *desc;
  598. struct napi_struct napi;
  599. struct multi_send_data msd;
  600. struct multi_recv_comp mrc;
  601. atomic_t queue_sends;
  602. struct netvsc_stats tx_stats;
  603. struct netvsc_stats rx_stats;
  604. };
  605. /* Per netvsc device */
  606. struct netvsc_device {
  607. u32 nvsp_version;
  608. wait_queue_head_t wait_drain;
  609. bool destroy;
  610. /* Receive buffer allocated by us but manages by NetVSP */
  611. void *recv_buf;
  612. u32 recv_buf_size;
  613. u32 recv_buf_gpadl_handle;
  614. u32 recv_section_cnt;
  615. u32 recv_completion_cnt;
  616. /* Send buffer allocated by us */
  617. void *send_buf;
  618. u32 send_buf_size;
  619. u32 send_buf_gpadl_handle;
  620. u32 send_section_cnt;
  621. u32 send_section_size;
  622. unsigned long *send_section_map;
  623. /* Used for NetVSP initialization protocol */
  624. struct completion channel_init_wait;
  625. struct nvsp_message channel_init_pkt;
  626. struct nvsp_message revoke_packet;
  627. u32 max_chn;
  628. u32 num_chn;
  629. atomic_t open_chn;
  630. wait_queue_head_t subchan_open;
  631. struct rndis_device *extension;
  632. int ring_size;
  633. u32 max_pkt; /* max number of pkt in one send, e.g. 8 */
  634. u32 pkt_align; /* alignment bytes, e.g. 8 */
  635. atomic_t open_cnt;
  636. struct netvsc_channel chan_table[VRSS_CHANNEL_MAX];
  637. struct rcu_head rcu;
  638. };
  639. /* NdisInitialize message */
  640. struct rndis_initialize_request {
  641. u32 req_id;
  642. u32 major_ver;
  643. u32 minor_ver;
  644. u32 max_xfer_size;
  645. };
  646. /* Response to NdisInitialize */
  647. struct rndis_initialize_complete {
  648. u32 req_id;
  649. u32 status;
  650. u32 major_ver;
  651. u32 minor_ver;
  652. u32 dev_flags;
  653. u32 medium;
  654. u32 max_pkt_per_msg;
  655. u32 max_xfer_size;
  656. u32 pkt_alignment_factor;
  657. u32 af_list_offset;
  658. u32 af_list_size;
  659. };
  660. /* Call manager devices only: Information about an address family */
  661. /* supported by the device is appended to the response to NdisInitialize. */
  662. struct rndis_co_address_family {
  663. u32 address_family;
  664. u32 major_ver;
  665. u32 minor_ver;
  666. };
  667. /* NdisHalt message */
  668. struct rndis_halt_request {
  669. u32 req_id;
  670. };
  671. /* NdisQueryRequest message */
  672. struct rndis_query_request {
  673. u32 req_id;
  674. u32 oid;
  675. u32 info_buflen;
  676. u32 info_buf_offset;
  677. u32 dev_vc_handle;
  678. };
  679. /* Response to NdisQueryRequest */
  680. struct rndis_query_complete {
  681. u32 req_id;
  682. u32 status;
  683. u32 info_buflen;
  684. u32 info_buf_offset;
  685. };
  686. /* NdisSetRequest message */
  687. struct rndis_set_request {
  688. u32 req_id;
  689. u32 oid;
  690. u32 info_buflen;
  691. u32 info_buf_offset;
  692. u32 dev_vc_handle;
  693. };
  694. /* Response to NdisSetRequest */
  695. struct rndis_set_complete {
  696. u32 req_id;
  697. u32 status;
  698. };
  699. /* NdisReset message */
  700. struct rndis_reset_request {
  701. u32 reserved;
  702. };
  703. /* Response to NdisReset */
  704. struct rndis_reset_complete {
  705. u32 status;
  706. u32 addressing_reset;
  707. };
  708. /* NdisMIndicateStatus message */
  709. struct rndis_indicate_status {
  710. u32 status;
  711. u32 status_buflen;
  712. u32 status_buf_offset;
  713. };
  714. /* Diagnostic information passed as the status buffer in */
  715. /* struct rndis_indicate_status messages signifying error conditions. */
  716. struct rndis_diagnostic_info {
  717. u32 diag_status;
  718. u32 error_offset;
  719. };
  720. /* NdisKeepAlive message */
  721. struct rndis_keepalive_request {
  722. u32 req_id;
  723. };
  724. /* Response to NdisKeepAlive */
  725. struct rndis_keepalive_complete {
  726. u32 req_id;
  727. u32 status;
  728. };
  729. /*
  730. * Data message. All Offset fields contain byte offsets from the beginning of
  731. * struct rndis_packet. All Length fields are in bytes. VcHandle is set
  732. * to 0 for connectionless data, otherwise it contains the VC handle.
  733. */
  734. struct rndis_packet {
  735. u32 data_offset;
  736. u32 data_len;
  737. u32 oob_data_offset;
  738. u32 oob_data_len;
  739. u32 num_oob_data_elements;
  740. u32 per_pkt_info_offset;
  741. u32 per_pkt_info_len;
  742. u32 vc_handle;
  743. u32 reserved;
  744. };
  745. /* Optional Out of Band data associated with a Data message. */
  746. struct rndis_oobd {
  747. u32 size;
  748. u32 type;
  749. u32 class_info_offset;
  750. };
  751. /* Packet extension field contents associated with a Data message. */
  752. struct rndis_per_packet_info {
  753. u32 size;
  754. u32 type;
  755. u32 ppi_offset;
  756. };
  757. enum ndis_per_pkt_info_type {
  758. TCPIP_CHKSUM_PKTINFO,
  759. IPSEC_PKTINFO,
  760. TCP_LARGESEND_PKTINFO,
  761. CLASSIFICATION_HANDLE_PKTINFO,
  762. NDIS_RESERVED,
  763. SG_LIST_PKTINFO,
  764. IEEE_8021Q_INFO,
  765. ORIGINAL_PKTINFO,
  766. PACKET_CANCEL_ID,
  767. NBL_HASH_VALUE = PACKET_CANCEL_ID,
  768. ORIGINAL_NET_BUFLIST,
  769. CACHED_NET_BUFLIST,
  770. SHORT_PKT_PADINFO,
  771. MAX_PER_PKT_INFO
  772. };
  773. struct ndis_pkt_8021q_info {
  774. union {
  775. struct {
  776. u32 pri:3; /* User Priority */
  777. u32 cfi:1; /* Canonical Format ID */
  778. u32 vlanid:12; /* VLAN ID */
  779. u32 reserved:16;
  780. };
  781. u32 value;
  782. };
  783. };
  784. struct ndis_object_header {
  785. u8 type;
  786. u8 revision;
  787. u16 size;
  788. };
  789. #define NDIS_OBJECT_TYPE_DEFAULT 0x80
  790. #define NDIS_OFFLOAD_PARAMETERS_REVISION_3 3
  791. #define NDIS_OFFLOAD_PARAMETERS_REVISION_2 2
  792. #define NDIS_OFFLOAD_PARAMETERS_REVISION_1 1
  793. #define NDIS_OFFLOAD_PARAMETERS_NO_CHANGE 0
  794. #define NDIS_OFFLOAD_PARAMETERS_LSOV2_DISABLED 1
  795. #define NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED 2
  796. #define NDIS_OFFLOAD_PARAMETERS_LSOV1_ENABLED 2
  797. #define NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED 1
  798. #define NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED 2
  799. #define NDIS_OFFLOAD_PARAMETERS_TX_RX_DISABLED 1
  800. #define NDIS_OFFLOAD_PARAMETERS_TX_ENABLED_RX_DISABLED 2
  801. #define NDIS_OFFLOAD_PARAMETERS_RX_ENABLED_TX_DISABLED 3
  802. #define NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED 4
  803. #define NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE 1
  804. #define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4 0
  805. #define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6 1
  806. #define VERSION_4_OFFLOAD_SIZE 22
  807. /*
  808. * New offload OIDs for NDIS 6
  809. */
  810. #define OID_TCP_OFFLOAD_CURRENT_CONFIG 0xFC01020B /* query only */
  811. #define OID_TCP_OFFLOAD_PARAMETERS 0xFC01020C /* set only */
  812. #define OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020D/* query only */
  813. #define OID_TCP_CONNECTION_OFFLOAD_CURRENT_CONFIG 0xFC01020E /* query only */
  814. #define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020F /* query */
  815. #define OID_OFFLOAD_ENCAPSULATION 0x0101010A /* set/query */
  816. /*
  817. * OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES
  818. * ndis_type: NDIS_OBJTYPE_OFFLOAD
  819. */
  820. #define NDIS_OFFLOAD_ENCAP_NONE 0x0000
  821. #define NDIS_OFFLOAD_ENCAP_NULL 0x0001
  822. #define NDIS_OFFLOAD_ENCAP_8023 0x0002
  823. #define NDIS_OFFLOAD_ENCAP_8023PQ 0x0004
  824. #define NDIS_OFFLOAD_ENCAP_8023PQ_OOB 0x0008
  825. #define NDIS_OFFLOAD_ENCAP_RFC1483 0x0010
  826. struct ndis_csum_offload {
  827. u32 ip4_txenc;
  828. u32 ip4_txcsum;
  829. #define NDIS_TXCSUM_CAP_IP4OPT 0x001
  830. #define NDIS_TXCSUM_CAP_TCP4OPT 0x004
  831. #define NDIS_TXCSUM_CAP_TCP4 0x010
  832. #define NDIS_TXCSUM_CAP_UDP4 0x040
  833. #define NDIS_TXCSUM_CAP_IP4 0x100
  834. #define NDIS_TXCSUM_ALL_TCP4 (NDIS_TXCSUM_CAP_TCP4 | NDIS_TXCSUM_CAP_TCP4OPT)
  835. u32 ip4_rxenc;
  836. u32 ip4_rxcsum;
  837. #define NDIS_RXCSUM_CAP_IP4OPT 0x001
  838. #define NDIS_RXCSUM_CAP_TCP4OPT 0x004
  839. #define NDIS_RXCSUM_CAP_TCP4 0x010
  840. #define NDIS_RXCSUM_CAP_UDP4 0x040
  841. #define NDIS_RXCSUM_CAP_IP4 0x100
  842. u32 ip6_txenc;
  843. u32 ip6_txcsum;
  844. #define NDIS_TXCSUM_CAP_IP6EXT 0x001
  845. #define NDIS_TXCSUM_CAP_TCP6OPT 0x004
  846. #define NDIS_TXCSUM_CAP_TCP6 0x010
  847. #define NDIS_TXCSUM_CAP_UDP6 0x040
  848. u32 ip6_rxenc;
  849. u32 ip6_rxcsum;
  850. #define NDIS_RXCSUM_CAP_IP6EXT 0x001
  851. #define NDIS_RXCSUM_CAP_TCP6OPT 0x004
  852. #define NDIS_RXCSUM_CAP_TCP6 0x010
  853. #define NDIS_RXCSUM_CAP_UDP6 0x040
  854. #define NDIS_TXCSUM_ALL_TCP6 (NDIS_TXCSUM_CAP_TCP6 | \
  855. NDIS_TXCSUM_CAP_TCP6OPT | \
  856. NDIS_TXCSUM_CAP_IP6EXT)
  857. };
  858. struct ndis_lsov1_offload {
  859. u32 encap;
  860. u32 maxsize;
  861. u32 minsegs;
  862. u32 opts;
  863. };
  864. struct ndis_ipsecv1_offload {
  865. u32 encap;
  866. u32 ah_esp;
  867. u32 xport_tun;
  868. u32 ip4_opts;
  869. u32 flags;
  870. u32 ip4_ah;
  871. u32 ip4_esp;
  872. };
  873. struct ndis_lsov2_offload {
  874. u32 ip4_encap;
  875. u32 ip4_maxsz;
  876. u32 ip4_minsg;
  877. u32 ip6_encap;
  878. u32 ip6_maxsz;
  879. u32 ip6_minsg;
  880. u32 ip6_opts;
  881. #define NDIS_LSOV2_CAP_IP6EXT 0x001
  882. #define NDIS_LSOV2_CAP_TCP6OPT 0x004
  883. #define NDIS_LSOV2_CAP_IP6 (NDIS_LSOV2_CAP_IP6EXT | \
  884. NDIS_LSOV2_CAP_TCP6OPT)
  885. };
  886. struct ndis_ipsecv2_offload {
  887. u32 encap;
  888. u16 ip6;
  889. u16 ip4opt;
  890. u16 ip6ext;
  891. u16 ah;
  892. u16 esp;
  893. u16 ah_esp;
  894. u16 xport;
  895. u16 tun;
  896. u16 xport_tun;
  897. u16 lso;
  898. u16 extseq;
  899. u32 udp_esp;
  900. u32 auth;
  901. u32 crypto;
  902. u32 sa_caps;
  903. };
  904. struct ndis_rsc_offload {
  905. u16 ip4;
  906. u16 ip6;
  907. };
  908. struct ndis_encap_offload {
  909. u32 flags;
  910. u32 maxhdr;
  911. };
  912. struct ndis_offload {
  913. struct ndis_object_header header;
  914. struct ndis_csum_offload csum;
  915. struct ndis_lsov1_offload lsov1;
  916. struct ndis_ipsecv1_offload ipsecv1;
  917. struct ndis_lsov2_offload lsov2;
  918. u32 flags;
  919. /* NDIS >= 6.1 */
  920. struct ndis_ipsecv2_offload ipsecv2;
  921. /* NDIS >= 6.30 */
  922. struct ndis_rsc_offload rsc;
  923. struct ndis_encap_offload encap_gre;
  924. };
  925. #define NDIS_OFFLOAD_SIZE sizeof(struct ndis_offload)
  926. #define NDIS_OFFLOAD_SIZE_6_0 offsetof(struct ndis_offload, ipsecv2)
  927. #define NDIS_OFFLOAD_SIZE_6_1 offsetof(struct ndis_offload, rsc)
  928. struct ndis_offload_params {
  929. struct ndis_object_header header;
  930. u8 ip_v4_csum;
  931. u8 tcp_ip_v4_csum;
  932. u8 udp_ip_v4_csum;
  933. u8 tcp_ip_v6_csum;
  934. u8 udp_ip_v6_csum;
  935. u8 lso_v1;
  936. u8 ip_sec_v1;
  937. u8 lso_v2_ipv4;
  938. u8 lso_v2_ipv6;
  939. u8 tcp_connection_ip_v4;
  940. u8 tcp_connection_ip_v6;
  941. u32 flags;
  942. u8 ip_sec_v2;
  943. u8 ip_sec_v2_ip_v4;
  944. struct {
  945. u8 rsc_ip_v4;
  946. u8 rsc_ip_v6;
  947. };
  948. struct {
  949. u8 encapsulated_packet_task_offload;
  950. u8 encapsulation_types;
  951. };
  952. };
  953. struct ndis_tcp_ip_checksum_info {
  954. union {
  955. struct {
  956. u32 is_ipv4:1;
  957. u32 is_ipv6:1;
  958. u32 tcp_checksum:1;
  959. u32 udp_checksum:1;
  960. u32 ip_header_checksum:1;
  961. u32 reserved:11;
  962. u32 tcp_header_offset:10;
  963. } transmit;
  964. struct {
  965. u32 tcp_checksum_failed:1;
  966. u32 udp_checksum_failed:1;
  967. u32 ip_checksum_failed:1;
  968. u32 tcp_checksum_succeeded:1;
  969. u32 udp_checksum_succeeded:1;
  970. u32 ip_checksum_succeeded:1;
  971. u32 loopback:1;
  972. u32 tcp_checksum_value_invalid:1;
  973. u32 ip_checksum_value_invalid:1;
  974. } receive;
  975. u32 value;
  976. };
  977. };
  978. struct ndis_tcp_lso_info {
  979. union {
  980. struct {
  981. u32 unused:30;
  982. u32 type:1;
  983. u32 reserved2:1;
  984. } transmit;
  985. struct {
  986. u32 mss:20;
  987. u32 tcp_header_offset:10;
  988. u32 type:1;
  989. u32 reserved2:1;
  990. } lso_v1_transmit;
  991. struct {
  992. u32 tcp_payload:30;
  993. u32 type:1;
  994. u32 reserved2:1;
  995. } lso_v1_transmit_complete;
  996. struct {
  997. u32 mss:20;
  998. u32 tcp_header_offset:10;
  999. u32 type:1;
  1000. u32 ip_version:1;
  1001. } lso_v2_transmit;
  1002. struct {
  1003. u32 reserved:30;
  1004. u32 type:1;
  1005. u32 reserved2:1;
  1006. } lso_v2_transmit_complete;
  1007. u32 value;
  1008. };
  1009. };
  1010. #define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  1011. sizeof(struct ndis_pkt_8021q_info))
  1012. #define NDIS_CSUM_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  1013. sizeof(struct ndis_tcp_ip_checksum_info))
  1014. #define NDIS_LSO_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  1015. sizeof(struct ndis_tcp_lso_info))
  1016. #define NDIS_HASH_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
  1017. sizeof(u32))
  1018. /* Total size of all PPI data */
  1019. #define NDIS_ALL_PPI_SIZE (NDIS_VLAN_PPI_SIZE + NDIS_CSUM_PPI_SIZE + \
  1020. NDIS_LSO_PPI_SIZE + NDIS_HASH_PPI_SIZE)
  1021. /* Format of Information buffer passed in a SetRequest for the OID */
  1022. /* OID_GEN_RNDIS_CONFIG_PARAMETER. */
  1023. struct rndis_config_parameter_info {
  1024. u32 parameter_name_offset;
  1025. u32 parameter_name_length;
  1026. u32 parameter_type;
  1027. u32 parameter_value_offset;
  1028. u32 parameter_value_length;
  1029. };
  1030. /* Values for ParameterType in struct rndis_config_parameter_info */
  1031. #define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0
  1032. #define RNDIS_CONFIG_PARAM_TYPE_STRING 2
  1033. /* CONDIS Miniport messages for connection oriented devices */
  1034. /* that do not implement a call manager. */
  1035. /* CoNdisMiniportCreateVc message */
  1036. struct rcondis_mp_create_vc {
  1037. u32 req_id;
  1038. u32 ndis_vc_handle;
  1039. };
  1040. /* Response to CoNdisMiniportCreateVc */
  1041. struct rcondis_mp_create_vc_complete {
  1042. u32 req_id;
  1043. u32 dev_vc_handle;
  1044. u32 status;
  1045. };
  1046. /* CoNdisMiniportDeleteVc message */
  1047. struct rcondis_mp_delete_vc {
  1048. u32 req_id;
  1049. u32 dev_vc_handle;
  1050. };
  1051. /* Response to CoNdisMiniportDeleteVc */
  1052. struct rcondis_mp_delete_vc_complete {
  1053. u32 req_id;
  1054. u32 status;
  1055. };
  1056. /* CoNdisMiniportQueryRequest message */
  1057. struct rcondis_mp_query_request {
  1058. u32 req_id;
  1059. u32 request_type;
  1060. u32 oid;
  1061. u32 dev_vc_handle;
  1062. u32 info_buflen;
  1063. u32 info_buf_offset;
  1064. };
  1065. /* CoNdisMiniportSetRequest message */
  1066. struct rcondis_mp_set_request {
  1067. u32 req_id;
  1068. u32 request_type;
  1069. u32 oid;
  1070. u32 dev_vc_handle;
  1071. u32 info_buflen;
  1072. u32 info_buf_offset;
  1073. };
  1074. /* CoNdisIndicateStatus message */
  1075. struct rcondis_indicate_status {
  1076. u32 ndis_vc_handle;
  1077. u32 status;
  1078. u32 status_buflen;
  1079. u32 status_buf_offset;
  1080. };
  1081. /* CONDIS Call/VC parameters */
  1082. struct rcondis_specific_parameters {
  1083. u32 parameter_type;
  1084. u32 parameter_length;
  1085. u32 parameter_lffset;
  1086. };
  1087. struct rcondis_media_parameters {
  1088. u32 flags;
  1089. u32 reserved1;
  1090. u32 reserved2;
  1091. struct rcondis_specific_parameters media_specific;
  1092. };
  1093. struct rndis_flowspec {
  1094. u32 token_rate;
  1095. u32 token_bucket_size;
  1096. u32 peak_bandwidth;
  1097. u32 latency;
  1098. u32 delay_variation;
  1099. u32 service_type;
  1100. u32 max_sdu_size;
  1101. u32 minimum_policed_size;
  1102. };
  1103. struct rcondis_call_manager_parameters {
  1104. struct rndis_flowspec transmit;
  1105. struct rndis_flowspec receive;
  1106. struct rcondis_specific_parameters call_mgr_specific;
  1107. };
  1108. /* CoNdisMiniportActivateVc message */
  1109. struct rcondis_mp_activate_vc_request {
  1110. u32 req_id;
  1111. u32 flags;
  1112. u32 dev_vc_handle;
  1113. u32 media_params_offset;
  1114. u32 media_params_length;
  1115. u32 call_mgr_params_offset;
  1116. u32 call_mgr_params_length;
  1117. };
  1118. /* Response to CoNdisMiniportActivateVc */
  1119. struct rcondis_mp_activate_vc_complete {
  1120. u32 req_id;
  1121. u32 status;
  1122. };
  1123. /* CoNdisMiniportDeactivateVc message */
  1124. struct rcondis_mp_deactivate_vc_request {
  1125. u32 req_id;
  1126. u32 flags;
  1127. u32 dev_vc_handle;
  1128. };
  1129. /* Response to CoNdisMiniportDeactivateVc */
  1130. struct rcondis_mp_deactivate_vc_complete {
  1131. u32 req_id;
  1132. u32 status;
  1133. };
  1134. /* union with all of the RNDIS messages */
  1135. union rndis_message_container {
  1136. struct rndis_packet pkt;
  1137. struct rndis_initialize_request init_req;
  1138. struct rndis_halt_request halt_req;
  1139. struct rndis_query_request query_req;
  1140. struct rndis_set_request set_req;
  1141. struct rndis_reset_request reset_req;
  1142. struct rndis_keepalive_request keep_alive_req;
  1143. struct rndis_indicate_status indicate_status;
  1144. struct rndis_initialize_complete init_complete;
  1145. struct rndis_query_complete query_complete;
  1146. struct rndis_set_complete set_complete;
  1147. struct rndis_reset_complete reset_complete;
  1148. struct rndis_keepalive_complete keep_alive_complete;
  1149. struct rcondis_mp_create_vc co_miniport_create_vc;
  1150. struct rcondis_mp_delete_vc co_miniport_delete_vc;
  1151. struct rcondis_indicate_status co_indicate_status;
  1152. struct rcondis_mp_activate_vc_request co_miniport_activate_vc;
  1153. struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc;
  1154. struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete;
  1155. struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete;
  1156. struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete;
  1157. struct rcondis_mp_deactivate_vc_complete
  1158. co_miniport_deactivate_vc_complete;
  1159. };
  1160. /* Remote NDIS message format */
  1161. struct rndis_message {
  1162. u32 ndis_msg_type;
  1163. /* Total length of this message, from the beginning */
  1164. /* of the struct rndis_message, in bytes. */
  1165. u32 msg_len;
  1166. /* Actual message */
  1167. union rndis_message_container msg;
  1168. };
  1169. /* Handy macros */
  1170. /* get the size of an RNDIS message. Pass in the message type, */
  1171. /* struct rndis_set_request, struct rndis_packet for example */
  1172. #define RNDIS_MESSAGE_SIZE(msg) \
  1173. (sizeof(msg) + (sizeof(struct rndis_message) - \
  1174. sizeof(union rndis_message_container)))
  1175. /* get pointer to info buffer with message pointer */
  1176. #define MESSAGE_TO_INFO_BUFFER(msg) \
  1177. (((unsigned char *)(msg)) + msg->info_buf_offset)
  1178. /* get pointer to status buffer with message pointer */
  1179. #define MESSAGE_TO_STATUS_BUFFER(msg) \
  1180. (((unsigned char *)(msg)) + msg->status_buf_offset)
  1181. /* get pointer to OOBD buffer with message pointer */
  1182. #define MESSAGE_TO_OOBD_BUFFER(msg) \
  1183. (((unsigned char *)(msg)) + msg->oob_data_offset)
  1184. /* get pointer to data buffer with message pointer */
  1185. #define MESSAGE_TO_DATA_BUFFER(msg) \
  1186. (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
  1187. /* get pointer to contained message from NDIS_MESSAGE pointer */
  1188. #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \
  1189. ((void *) &rndis_msg->msg)
  1190. /* get pointer to contained message from NDIS_MESSAGE pointer */
  1191. #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
  1192. ((void *) rndis_msg)
  1193. #define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \
  1194. sizeof(union rndis_message_container))
  1195. #define RNDIS_AND_PPI_SIZE (sizeof(struct rndis_message) + NDIS_ALL_PPI_SIZE)
  1196. #define NDIS_PACKET_TYPE_DIRECTED 0x00000001
  1197. #define NDIS_PACKET_TYPE_MULTICAST 0x00000002
  1198. #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
  1199. #define NDIS_PACKET_TYPE_BROADCAST 0x00000008
  1200. #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
  1201. #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
  1202. #define NDIS_PACKET_TYPE_SMT 0x00000040
  1203. #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
  1204. #define NDIS_PACKET_TYPE_GROUP 0x00000100
  1205. #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
  1206. #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
  1207. #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
  1208. #define TRANSPORT_INFO_NOT_IP 0
  1209. #define TRANSPORT_INFO_IPV4_TCP 0x01
  1210. #define TRANSPORT_INFO_IPV4_UDP 0x02
  1211. #define TRANSPORT_INFO_IPV6_TCP 0x10
  1212. #define TRANSPORT_INFO_IPV6_UDP 0x20
  1213. #endif /* _HYPERV_NET_H */