hyperv_net.h 44 KB

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