PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/staging/hv/netvsc.h

https://bitbucket.org/flyhalf205/kernel-tegra
C Header | 332 lines | 143 code | 62 blank | 127 comment | 0 complexity | a20b39e2b7021c846cc96a6c6372bba1 MD5 | raw file
  1. /*
  2. *
  3. * Copyright (c) 2009, Microsoft Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. * Place - Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. * Authors:
  19. * Haiyang Zhang <haiyangz@microsoft.com>
  20. * Hank Janssen <hjanssen@microsoft.com>
  21. *
  22. */
  23. #ifndef _NETVSC_H_
  24. #define _NETVSC_H_
  25. #include <linux/list.h>
  26. #include "vmbus_packet_format.h"
  27. #include "vmbus_channel_interface.h"
  28. #include "netvsc_api.h"
  29. #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
  30. #define NVSP_PROTOCOL_VERSION_1 2
  31. #define NVSP_MIN_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1
  32. #define NVSP_MAX_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1
  33. enum {
  34. NVSP_MSG_TYPE_NONE = 0,
  35. /* Init Messages */
  36. NVSP_MSG_TYPE_INIT = 1,
  37. NVSP_MSG_TYPE_INIT_COMPLETE = 2,
  38. NVSP_VERSION_MSG_START = 100,
  39. /* Version 1 Messages */
  40. NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START,
  41. NVSP_MSG1_TYPE_SEND_RECV_BUF,
  42. NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
  43. NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
  44. NVSP_MSG1_TYPE_SEND_SEND_BUF,
  45. NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
  46. NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
  47. NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
  48. NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
  49. /*
  50. * This should be set to the number of messages for the version with
  51. * the maximum number of messages.
  52. */
  53. NVSP_NUM_MSG_PER_VERSION = 9,
  54. };
  55. enum {
  56. NVSP_STAT_NONE = 0,
  57. NVSP_STAT_SUCCESS,
  58. NVSP_STAT_FAIL,
  59. NVSP_STAT_PROTOCOL_TOO_NEW,
  60. NVSP_STAT_PROTOCOL_TOO_OLD,
  61. NVSP_STAT_INVALID_RNDIS_PKT,
  62. NVSP_STAT_BUSY,
  63. NVSP_STAT_MAX,
  64. };
  65. struct nvsp_message_header {
  66. u32 msg_type;
  67. };
  68. /* Init Messages */
  69. /*
  70. * This message is used by the VSC to initialize the channel after the channels
  71. * has been opened. This message should never include anything other then
  72. * versioning (i.e. this message will be the same for ever).
  73. */
  74. struct nvsp_message_init {
  75. u32 min_protocol_ver;
  76. u32 max_protocol_ver;
  77. } __packed;
  78. /*
  79. * This message is used by the VSP to complete the initialization of the
  80. * channel. This message should never include anything other then versioning
  81. * (i.e. this message will be the same for ever).
  82. */
  83. struct nvsp_message_init_complete {
  84. u32 negotiated_protocol_ver;
  85. u32 max_mdl_chain_len;
  86. u32 status;
  87. } __packed;
  88. union nvsp_message_init_uber {
  89. struct nvsp_message_init init;
  90. struct nvsp_message_init_complete init_complete;
  91. } __packed;
  92. /* Version 1 Messages */
  93. /*
  94. * This message is used by the VSC to send the NDIS version to the VSP. The VSP
  95. * can use this information when handling OIDs sent by the VSC.
  96. */
  97. struct nvsp_1_message_send_ndis_version {
  98. u32 ndis_major_ver;
  99. u32 ndis_minor_ver;
  100. } __packed;
  101. /*
  102. * This message is used by the VSC to send a receive buffer to the VSP. The VSP
  103. * can then use the receive buffer to send data to the VSC.
  104. */
  105. struct nvsp_1_message_send_receive_buffer {
  106. u32 gpadl_handle;
  107. u16 id;
  108. } __packed;
  109. struct nvsp_1_receive_buffer_section {
  110. u32 offset;
  111. u32 sub_alloc_size;
  112. u32 num_sub_allocs;
  113. u32 end_offset;
  114. } __packed;
  115. /*
  116. * This message is used by the VSP to acknowledge a receive buffer send by the
  117. * VSC. This message must be sent by the VSP before the VSP uses the receive
  118. * buffer.
  119. */
  120. struct nvsp_1_message_send_receive_buffer_complete {
  121. u32 status;
  122. u32 num_sections;
  123. /*
  124. * The receive buffer is split into two parts, a large suballocation
  125. * section and a small suballocation section. These sections are then
  126. * suballocated by a certain size.
  127. */
  128. /*
  129. * For example, the following break up of the receive buffer has 6
  130. * large suballocations and 10 small suballocations.
  131. */
  132. /*
  133. * | Large Section | | Small Section |
  134. * ------------------------------------------------------------
  135. * | | | | | | | | | | | | | | | | | |
  136. * | |
  137. * LargeOffset SmallOffset
  138. */
  139. struct nvsp_1_receive_buffer_section sections[1];
  140. } __packed;
  141. /*
  142. * This message is sent by the VSC to revoke the receive buffer. After the VSP
  143. * completes this transaction, the vsp should never use the receive buffer
  144. * again.
  145. */
  146. struct nvsp_1_message_revoke_receive_buffer {
  147. u16 id;
  148. };
  149. /*
  150. * This message is used by the VSC to send a send buffer to the VSP. The VSC
  151. * can then use the send buffer to send data to the VSP.
  152. */
  153. struct nvsp_1_message_send_send_buffer {
  154. u32 gpadl_handle;
  155. u16 id;
  156. } __packed;
  157. /*
  158. * This message is used by the VSP to acknowledge a send buffer sent by the
  159. * VSC. This message must be sent by the VSP before the VSP uses the sent
  160. * buffer.
  161. */
  162. struct nvsp_1_message_send_send_buffer_complete {
  163. u32 status;
  164. /*
  165. * The VSC gets to choose the size of the send buffer and the VSP gets
  166. * to choose the sections size of the buffer. This was done to enable
  167. * dynamic reconfigurations when the cost of GPA-direct buffers
  168. * decreases.
  169. */
  170. u32 section_size;
  171. } __packed;
  172. /*
  173. * This message is sent by the VSC to revoke the send buffer. After the VSP
  174. * completes this transaction, the vsp should never use the send buffer again.
  175. */
  176. struct nvsp_1_message_revoke_send_buffer {
  177. u16 id;
  178. };
  179. /*
  180. * This message is used by both the VSP and the VSC to send a RNDIS message to
  181. * the opposite channel endpoint.
  182. */
  183. struct nvsp_1_message_send_rndis_packet {
  184. /*
  185. * This field is specified by RNIDS. They assume there's two different
  186. * channels of communication. However, the Network VSP only has one.
  187. * Therefore, the channel travels with the RNDIS packet.
  188. */
  189. u32 channel_type;
  190. /*
  191. * This field is used to send part or all of the data through a send
  192. * buffer. This values specifies an index into the send buffer. If the
  193. * index is 0xFFFFFFFF, then the send buffer is not being used and all
  194. * of the data was sent through other VMBus mechanisms.
  195. */
  196. u32 send_buf_section_index;
  197. u32 send_buf_section_size;
  198. } __packed;
  199. /*
  200. * This message is used by both the VSP and the VSC to complete a RNDIS message
  201. * to the opposite channel endpoint. At this point, the initiator of this
  202. * message cannot use any resources associated with the original RNDIS packet.
  203. */
  204. struct nvsp_1_message_send_rndis_packet_complete {
  205. u32 status;
  206. };
  207. union nvsp_1_message_uber {
  208. struct nvsp_1_message_send_ndis_version send_ndis_ver;
  209. struct nvsp_1_message_send_receive_buffer send_recv_buf;
  210. struct nvsp_1_message_send_receive_buffer_complete
  211. send_recv_buf_complete;
  212. struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
  213. struct nvsp_1_message_send_send_buffer send_send_buf;
  214. struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
  215. struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
  216. struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
  217. struct nvsp_1_message_send_rndis_packet_complete
  218. send_rndis_pkt_complete;
  219. } __packed;
  220. union nvsp_all_messages {
  221. union nvsp_message_init_uber init_msg;
  222. union nvsp_1_message_uber v1_msg;
  223. } __packed;
  224. /* ALL Messages */
  225. struct nvsp_message {
  226. struct nvsp_message_header hdr;
  227. union nvsp_all_messages msg;
  228. } __packed;
  229. /* #define NVSC_MIN_PROTOCOL_VERSION 1 */
  230. /* #define NVSC_MAX_PROTOCOL_VERSION 1 */
  231. #define NETVSC_SEND_BUFFER_SIZE (64*1024) /* 64K */
  232. #define NETVSC_SEND_BUFFER_ID 0xface
  233. #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024) /* 1MB */
  234. #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
  235. #define NETVSC_RECEIVE_SG_COUNT 1
  236. /* Preallocated receive packets */
  237. #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
  238. #define NETVSC_PACKET_SIZE 2048
  239. /* Per netvsc channel-specific */
  240. struct netvsc_device {
  241. struct hv_device *dev;
  242. atomic_t refcnt;
  243. atomic_t num_outstanding_sends;
  244. /*
  245. * List of free preallocated hv_netvsc_packet to represent receive
  246. * packet
  247. */
  248. struct list_head recv_pkt_list;
  249. spinlock_t recv_pkt_list_lock;
  250. /* Send buffer allocated by us but manages by NetVSP */
  251. void *send_buf;
  252. u32 send_buf_size;
  253. u32 send_buf_gpadl_handle;
  254. u32 send_section_size;
  255. /* Receive buffer allocated by us but manages by NetVSP */
  256. void *recv_buf;
  257. u32 recv_buf_size;
  258. u32 recv_buf_gpadl_handle;
  259. u32 recv_section_cnt;
  260. struct nvsp_1_receive_buffer_section *recv_section;
  261. /* Used for NetVSP initialization protocol */
  262. int wait_condition;
  263. wait_queue_head_t channel_init_wait;
  264. struct nvsp_message channel_init_pkt;
  265. struct nvsp_message revoke_packet;
  266. /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
  267. /* Holds rndis device info */
  268. void *extension;
  269. };
  270. #endif /* _NETVSC_H_ */