net_tx_pkt.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. /**
  25. * Init function for tx packet functionality
  26. *
  27. * @pkt: packet pointer
  28. * @pci_dev: PCI device processing this packet
  29. * @max_frags: max tx ip fragments
  30. * @has_virt_hdr: device uses virtio header.
  31. */
  32. void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev,
  33. uint32_t max_frags, bool has_virt_hdr);
  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. *
  55. */
  56. void net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
  57. bool csum_enable, uint32_t gso_size);
  58. /**
  59. * updates vlan tag, and adds vlan header with custom ethernet type
  60. * in case it is missing.
  61. *
  62. * @pkt: packet
  63. * @vlan: VLAN tag
  64. * @vlan_ethtype: VLAN header Ethernet type
  65. *
  66. */
  67. void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt,
  68. uint16_t vlan, uint16_t vlan_ethtype);
  69. /**
  70. * updates vlan tag, and adds vlan header in case it is missing
  71. *
  72. * @pkt: packet
  73. * @vlan: VLAN tag
  74. *
  75. */
  76. static inline void
  77. net_tx_pkt_setup_vlan_header(struct NetTxPkt *pkt, uint16_t vlan)
  78. {
  79. net_tx_pkt_setup_vlan_header_ex(pkt, vlan, ETH_P_VLAN);
  80. }
  81. /**
  82. * populate data fragment into pkt context.
  83. *
  84. * @pkt: packet
  85. * @pa: physical address of fragment
  86. * @len: length of fragment
  87. *
  88. */
  89. bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa,
  90. size_t len);
  91. /**
  92. * Fix ip header fields and calculate IP header and pseudo header checksums.
  93. *
  94. * @pkt: packet
  95. *
  96. */
  97. void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt);
  98. /**
  99. * Calculate the IP header checksum.
  100. *
  101. * @pkt: packet
  102. *
  103. */
  104. void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt);
  105. /**
  106. * get length of all populated data.
  107. *
  108. * @pkt: packet
  109. * @ret: total data length
  110. *
  111. */
  112. size_t net_tx_pkt_get_total_len(struct NetTxPkt *pkt);
  113. /**
  114. * get packet type
  115. *
  116. * @pkt: packet
  117. * @ret: packet type
  118. *
  119. */
  120. eth_pkt_types_e net_tx_pkt_get_packet_type(struct NetTxPkt *pkt);
  121. /**
  122. * prints packet data if debug is enabled
  123. *
  124. * @pkt: packet
  125. *
  126. */
  127. void net_tx_pkt_dump(struct NetTxPkt *pkt);
  128. /**
  129. * reset tx packet private context (needed to be called between packets)
  130. *
  131. * @pkt: packet
  132. *
  133. */
  134. void net_tx_pkt_reset(struct NetTxPkt *pkt);
  135. /**
  136. * Send packet to qemu. handles sw offloads if vhdr is not supported.
  137. *
  138. * @pkt: packet
  139. * @nc: NetClientState
  140. * @ret: operation result
  141. *
  142. */
  143. bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc);
  144. /**
  145. * Redirect packet directly to receive path (emulate loopback phy).
  146. * Handles sw offloads if vhdr is not supported.
  147. *
  148. * @pkt: packet
  149. * @nc: NetClientState
  150. * @ret: operation result
  151. *
  152. */
  153. bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);
  154. /**
  155. * parse raw packet data and analyze offload requirements.
  156. *
  157. * @pkt: packet
  158. *
  159. */
  160. bool net_tx_pkt_parse(struct NetTxPkt *pkt);
  161. /**
  162. * indicates if there are data fragments held by this packet object.
  163. *
  164. * @pkt: packet
  165. *
  166. */
  167. bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt);
  168. /**
  169. * Fix IPv6 'plen' field.
  170. * If ipv6 payload length field is 0 - then there should be Hop-by-Hop
  171. * option for packets greater than 65,535.
  172. * For packets with a payload less than 65,535: fix 'plen' field.
  173. * For backends with vheader, we need just one packet with proper
  174. * payload size. For now, qemu drops every packet with size greater 64K
  175. * (see net_tx_pkt_send()) so, there is no reason to add jumbo option to ip6
  176. * hop-by-hop extension if it's missed
  177. *
  178. * @pkt packet
  179. */
  180. void net_tx_pkt_fix_ip6_payload_len(struct NetTxPkt *pkt);
  181. #endif