hyperv_net.h 33 KB

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