hyperv_net.h 41 KB

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