hyperv_net.h 29 KB

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