hyperv_net.h 39 KB

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