netif.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /******************************************************************************
  2. * netif.h
  3. *
  4. * Unified network-device I/O interface for Xen guest OSes.
  5. *
  6. * Copyright (c) 2003-2004, Keir Fraser
  7. */
  8. #ifndef __XEN_PUBLIC_IO_NETIF_H__
  9. #define __XEN_PUBLIC_IO_NETIF_H__
  10. #include <xen/interface/io/ring.h>
  11. #include <xen/interface/grant_table.h>
  12. /*
  13. * Notifications after enqueuing any type of message should be conditional on
  14. * the appropriate req_event or rsp_event field in the shared ring.
  15. * If the client sends notification for rx requests then it should specify
  16. * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
  17. * that it cannot safely queue packets (as it may not be kicked to send them).
  18. */
  19. /*
  20. * This is the 'wire' format for packets:
  21. * Request 1: xen_netif_tx_request -- XEN_NETTXF_* (any flags)
  22. * [Request 2: xen_netif_extra_info] (only if request 1 has XEN_NETTXF_extra_info)
  23. * [Request 3: xen_netif_extra_info] (only if request 2 has XEN_NETIF_EXTRA_MORE)
  24. * Request 4: xen_netif_tx_request -- XEN_NETTXF_more_data
  25. * Request 5: xen_netif_tx_request -- XEN_NETTXF_more_data
  26. * ...
  27. * Request N: xen_netif_tx_request -- 0
  28. */
  29. /* Protocol checksum field is blank in the packet (hardware offload)? */
  30. #define _XEN_NETTXF_csum_blank (0)
  31. #define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
  32. /* Packet data has been validated against protocol checksum. */
  33. #define _XEN_NETTXF_data_validated (1)
  34. #define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
  35. /* Packet continues in the next request descriptor. */
  36. #define _XEN_NETTXF_more_data (2)
  37. #define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
  38. /* Packet to be followed by extra descriptor(s). */
  39. #define _XEN_NETTXF_extra_info (3)
  40. #define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
  41. #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
  42. struct xen_netif_tx_request {
  43. grant_ref_t gref; /* Reference to buffer page */
  44. uint16_t offset; /* Offset within buffer page */
  45. uint16_t flags; /* XEN_NETTXF_* */
  46. uint16_t id; /* Echoed in response message. */
  47. uint16_t size; /* Packet size in bytes. */
  48. };
  49. /* Types of xen_netif_extra_info descriptors. */
  50. #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
  51. #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
  52. #define XEN_NETIF_EXTRA_TYPE_MAX (2)
  53. /* xen_netif_extra_info flags. */
  54. #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
  55. #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
  56. /* GSO types - only TCPv4 currently supported. */
  57. #define XEN_NETIF_GSO_TYPE_TCPV4 (1)
  58. /*
  59. * This structure needs to fit within both netif_tx_request and
  60. * netif_rx_response for compatibility.
  61. */
  62. struct xen_netif_extra_info {
  63. uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
  64. uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
  65. union {
  66. struct {
  67. /*
  68. * Maximum payload size of each segment. For
  69. * example, for TCP this is just the path MSS.
  70. */
  71. uint16_t size;
  72. /*
  73. * GSO type. This determines the protocol of
  74. * the packet and any extra features required
  75. * to segment the packet properly.
  76. */
  77. uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
  78. /* Future expansion. */
  79. uint8_t pad;
  80. /*
  81. * GSO features. This specifies any extra GSO
  82. * features required to process this packet,
  83. * such as ECN support for TCPv4.
  84. */
  85. uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
  86. } gso;
  87. uint16_t pad[3];
  88. } u;
  89. };
  90. struct xen_netif_tx_response {
  91. uint16_t id;
  92. int16_t status; /* XEN_NETIF_RSP_* */
  93. };
  94. struct xen_netif_rx_request {
  95. uint16_t id; /* Echoed in response message. */
  96. grant_ref_t gref; /* Reference to incoming granted frame */
  97. };
  98. /* Packet data has been validated against protocol checksum. */
  99. #define _XEN_NETRXF_data_validated (0)
  100. #define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
  101. /* Protocol checksum field is blank in the packet (hardware offload)? */
  102. #define _XEN_NETRXF_csum_blank (1)
  103. #define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
  104. /* Packet continues in the next request descriptor. */
  105. #define _XEN_NETRXF_more_data (2)
  106. #define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
  107. /* Packet to be followed by extra descriptor(s). */
  108. #define _XEN_NETRXF_extra_info (3)
  109. #define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
  110. /* GSO Prefix descriptor. */
  111. #define _XEN_NETRXF_gso_prefix (4)
  112. #define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
  113. struct xen_netif_rx_response {
  114. uint16_t id;
  115. uint16_t offset; /* Offset in page of start of received packet */
  116. uint16_t flags; /* XEN_NETRXF_* */
  117. int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
  118. };
  119. /*
  120. * Generate netif ring structures and types.
  121. */
  122. DEFINE_RING_TYPES(xen_netif_tx,
  123. struct xen_netif_tx_request,
  124. struct xen_netif_tx_response);
  125. DEFINE_RING_TYPES(xen_netif_rx,
  126. struct xen_netif_rx_request,
  127. struct xen_netif_rx_response);
  128. #define XEN_NETIF_RSP_DROPPED -2
  129. #define XEN_NETIF_RSP_ERROR -1
  130. #define XEN_NETIF_RSP_OKAY 0
  131. /* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
  132. #define XEN_NETIF_RSP_NULL 1
  133. #endif