hyperv_net.h 30 KB

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