net_tx_pkt.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * QEMU TX packets abstraction
  3. *
  4. * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
  5. *
  6. * Developed by Daynix Computing LTD (http://www.daynix.com)
  7. *
  8. * Authors:
  9. * Dmitry Fleytman <dmitry@daynix.com>
  10. * Tamir Shomer <tamirs@daynix.com>
  11. * Yan Vugenfirer <yan@daynix.com>
  12. *
  13. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  14. * See the COPYING file in the top-level directory.
  15. *
  16. */
  17. #ifndef NET_TX_PKT_H
  18. #define NET_TX_PKT_H
  19. #include "net/eth.h"
  20. #include "exec/hwaddr.h"
  21. /* define to enable packet dump functions */
  22. /*#define NET_TX_PKT_DEBUG*/
  23. struct NetTxPkt;
  24. typedef void (* NetTxPktCallback)(void *, const struct iovec *, int, const struct iovec *, int);
  25. /**
  26. * Init function for tx packet functionality
  27. *
  28. * @pkt: packet pointer
  29. * @pci_dev: PCI device processing this packet
  30. * @max_frags: max tx ip fragments
  31. */
  32. void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev,
  33. uint32_t max_frags);
  34. /**
  35. * Clean all tx packet resources.
  36. *
  37. * @pkt: packet.
  38. */
  39. void net_tx_pkt_uninit(struct NetTxPkt *pkt);
  40. /**
  41. * get virtio header
  42. *
  43. * @pkt: packet
  44. * @ret: virtio header
  45. */
  46. struct virtio_net_hdr *net_tx_pkt_get_vhdr(struct NetTxPkt *pkt);
  47. /**
  48. * build virtio header (will be stored in module context)
  49. *
  50. * @pkt: packet
  51. * @tso_enable: TSO enabled
  52. * @csum_enable: CSO enabled
  53. * @gso_size: MSS size for TSO
  54. * @ret: operation result
  55. *
  56. */
  57. bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
  58. bool csum_enable, uint32_t gso_size);
  59. /**
  60. * updates vlan tag, and adds vlan header with custom ethernet type
  61. * in case it is missing.
  62. *
  63. * @pkt: packet
  64. * @vlan: VLAN tag
  65. * @vlan_ethtype: VLAN header Ethernet type
  66. *
  67. */
  68. void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt,
  69. uint16_t vlan, uint16_t vlan_ethtype);
  70. /**
  71. * updates vlan tag, and adds vlan header in case it is missing
  72. *
  73. * @pkt: packet
  74. * @vlan: VLAN tag
  75. *
  76. */
  77. static inline void
  78. net_tx_pkt_setup_vlan_header(struct NetTxPkt *pkt, uint16_t vlan)
  79. {
  80. net_tx_pkt_setup_vlan_header_ex(pkt, vlan, ETH_P_VLAN);
  81. }
  82. /**
  83. * populate data fragment into pkt context.
  84. *
  85. * @pkt: packet
  86. * @pa: physical address of fragment
  87. * @len: length of fragment
  88. *
  89. */
  90. bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa,
  91. size_t len);
  92. /**
  93. * Fix ip header fields and calculate IP header and pseudo header checksums.
  94. *
  95. * @pkt: packet
  96. *
  97. */
  98. void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt);
  99. /**
  100. * Calculate the IP header checksum.
  101. *
  102. * @pkt: packet
  103. *
  104. */
  105. void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt);
  106. /**
  107. * get length of all populated data.
  108. *
  109. * @pkt: packet
  110. * @ret: total data length
  111. *
  112. */
  113. size_t net_tx_pkt_get_total_len(struct NetTxPkt *pkt);
  114. /**
  115. * get packet type
  116. *
  117. * @pkt: packet
  118. * @ret: packet type
  119. *
  120. */
  121. eth_pkt_types_e net_tx_pkt_get_packet_type(struct NetTxPkt *pkt);
  122. /**
  123. * prints packet data if debug is enabled
  124. *
  125. * @pkt: packet
  126. *
  127. */
  128. void net_tx_pkt_dump(struct NetTxPkt *pkt);
  129. /**
  130. * reset tx packet private context (needed to be called between packets)
  131. *
  132. * @pkt: packet
  133. * @dev: PCI device processing the next packet
  134. *
  135. */
  136. void net_tx_pkt_reset(struct NetTxPkt *pkt, PCIDevice *dev);
  137. /**
  138. * Send packet to qemu. handles sw offloads if vhdr is not supported.
  139. *
  140. * @pkt: packet
  141. * @nc: NetClientState
  142. * @ret: operation result
  143. *
  144. */
  145. bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc);
  146. /**
  147. * Send packet with a custom function.
  148. *
  149. * @pkt: packet
  150. * @offload: whether the callback implements offloading
  151. * @callback: a function to be called back for each transformed packet
  152. * @context: a pointer to be passed to the callback.
  153. * @ret: operation result
  154. */
  155. bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
  156. NetTxPktCallback callback, void *context);
  157. /**
  158. * parse raw packet data and analyze offload requirements.
  159. *
  160. * @pkt: packet
  161. *
  162. */
  163. bool net_tx_pkt_parse(struct NetTxPkt *pkt);
  164. /**
  165. * indicates if there are data fragments held by this packet object.
  166. *
  167. * @pkt: packet
  168. *
  169. */
  170. bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt);
  171. /**
  172. * Fix IPv6 'plen' field.
  173. * If ipv6 payload length field is 0 - then there should be Hop-by-Hop
  174. * option for packets greater than 65,535.
  175. * For packets with a payload less than 65,535: fix 'plen' field.
  176. * For backends with vheader, we need just one packet with proper
  177. * payload size. For now, qemu drops every packet with size greater 64K
  178. * (see net_tx_pkt_send()) so, there is no reason to add jumbo option to ip6
  179. * hop-by-hop extension if it's missed
  180. *
  181. * @pkt packet
  182. */
  183. void net_tx_pkt_fix_ip6_payload_len(struct NetTxPkt *pkt);
  184. #endif