hyperv_net.h 39 KB

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