iPXE
netif.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * netif.h
00003  *
00004  * Unified network-device I/O interface for Xen guest OSes.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to
00008  * deal in the Software without restriction, including without limitation the
00009  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00010  * sell copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00022  * DEALINGS IN THE SOFTWARE.
00023  *
00024  * Copyright (c) 2003-2004, Keir Fraser
00025  */
00026 
00027 #ifndef __XEN_PUBLIC_IO_NETIF_H__
00028 #define __XEN_PUBLIC_IO_NETIF_H__
00029 
00030 FILE_LICENCE ( MIT );
00031 
00032 #include "ring.h"
00033 #include "../grant_table.h"
00034 
00035 /*
00036  * Older implementation of Xen network frontend / backend has an
00037  * implicit dependency on the MAX_SKB_FRAGS as the maximum number of
00038  * ring slots a skb can use. Netfront / netback may not work as
00039  * expected when frontend and backend have different MAX_SKB_FRAGS.
00040  *
00041  * A better approach is to add mechanism for netfront / netback to
00042  * negotiate this value. However we cannot fix all possible
00043  * frontends, so we need to define a value which states the minimum
00044  * slots backend must support.
00045  *
00046  * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS
00047  * (18), which is proved to work with most frontends. Any new backend
00048  * which doesn't negotiate with frontend should expect frontend to
00049  * send a valid packet using slots up to this value.
00050  */
00051 #define XEN_NETIF_NR_SLOTS_MIN 18
00052 
00053 /*
00054  * Notifications after enqueuing any type of message should be conditional on
00055  * the appropriate req_event or rsp_event field in the shared ring.
00056  * If the client sends notification for rx requests then it should specify
00057  * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
00058  * that it cannot safely queue packets (as it may not be kicked to send them).
00059  */
00060 
00061 /*
00062  * "feature-split-event-channels" is introduced to separate guest TX
00063  * and RX notification. Backend either doesn't support this feature or
00064  * advertises it via xenstore as 0 (disabled) or 1 (enabled).
00065  *
00066  * To make use of this feature, frontend should allocate two event
00067  * channels for TX and RX, advertise them to backend as
00068  * "event-channel-tx" and "event-channel-rx" respectively. If frontend
00069  * doesn't want to use this feature, it just writes "event-channel"
00070  * node as before.
00071  */
00072 
00073 /*
00074  * Multiple transmit and receive queues:
00075  * If supported, the backend will write the key "multi-queue-max-queues" to
00076  * the directory for that vif, and set its value to the maximum supported
00077  * number of queues.
00078  * Frontends that are aware of this feature and wish to use it can write the
00079  * key "multi-queue-num-queues", set to the number they wish to use, which
00080  * must be greater than zero, and no more than the value reported by the backend
00081  * in "multi-queue-max-queues".
00082  *
00083  * Queues replicate the shared rings and event channels.
00084  * "feature-split-event-channels" may optionally be used when using
00085  * multiple queues, but is not mandatory.
00086  *
00087  * Each queue consists of one shared ring pair, i.e. there must be the same
00088  * number of tx and rx rings.
00089  *
00090  * For frontends requesting just one queue, the usual event-channel and
00091  * ring-ref keys are written as before, simplifying the backend processing
00092  * to avoid distinguishing between a frontend that doesn't understand the
00093  * multi-queue feature, and one that does, but requested only one queue.
00094  *
00095  * Frontends requesting two or more queues must not write the toplevel
00096  * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,
00097  * instead writing those keys under sub-keys having the name "queue-N" where
00098  * N is the integer ID of the queue for which those keys belong. Queues
00099  * are indexed from zero. For example, a frontend with two queues and split
00100  * event channels must write the following set of queue-related keys:
00101  *
00102  * /local/domain/1/device/vif/0/multi-queue-num-queues = "2"
00103  * /local/domain/1/device/vif/0/queue-0 = ""
00104  * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"
00105  * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"
00106  * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"
00107  * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"
00108  * /local/domain/1/device/vif/0/queue-1 = ""
00109  * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"
00110  * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"
00111  * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"
00112  * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"
00113  *
00114  * If there is any inconsistency in the XenStore data, the backend may
00115  * choose not to connect any queues, instead treating the request as an
00116  * error. This includes scenarios where more (or fewer) queues were
00117  * requested than the frontend provided details for.
00118  *
00119  * Mapping of packets to queues is considered to be a function of the
00120  * transmitting system (backend or frontend) and is not negotiated
00121  * between the two. Guests are free to transmit packets on any queue
00122  * they choose, provided it has been set up correctly. Guests must be
00123  * prepared to receive packets on any queue they have requested be set up.
00124  */
00125 
00126 /*
00127  * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
00128  * offload off or on. If it is missing then the feature is assumed to be on.
00129  * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
00130  * offload on or off. If it is missing then the feature is assumed to be off.
00131  */
00132 
00133 /*
00134  * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
00135  * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
00136  * frontends nor backends are assumed to be capable unless the flags are
00137  * present.
00138  */
00139 
00140 /*
00141  * This is the 'wire' format for packets:
00142  *  Request 1: netif_tx_request -- NETTXF_* (any flags)
00143  * [Request 2: netif_tx_extra]  (only if request 1 has NETTXF_extra_info)
00144  * [Request 3: netif_tx_extra]  (only if request 2 has XEN_NETIF_EXTRA_MORE)
00145  *  Request 4: netif_tx_request -- NETTXF_more_data
00146  *  Request 5: netif_tx_request -- NETTXF_more_data
00147  *  ...
00148  *  Request N: netif_tx_request -- 0
00149  */
00150 
00151 /* Protocol checksum field is blank in the packet (hardware offload)? */
00152 #define _NETTXF_csum_blank     (0)
00153 #define  NETTXF_csum_blank     (1U<<_NETTXF_csum_blank)
00154 
00155 /* Packet data has been validated against protocol checksum. */
00156 #define _NETTXF_data_validated (1)
00157 #define  NETTXF_data_validated (1U<<_NETTXF_data_validated)
00158 
00159 /* Packet continues in the next request descriptor. */
00160 #define _NETTXF_more_data      (2)
00161 #define  NETTXF_more_data      (1U<<_NETTXF_more_data)
00162 
00163 /* Packet to be followed by extra descriptor(s). */
00164 #define _NETTXF_extra_info     (3)
00165 #define  NETTXF_extra_info     (1U<<_NETTXF_extra_info)
00166 
00167 #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
00168 struct netif_tx_request {
00169     grant_ref_t gref;      /* Reference to buffer page */
00170     uint16_t offset;       /* Offset within buffer page */
00171     uint16_t flags;        /* NETTXF_* */
00172     uint16_t id;           /* Echoed in response message. */
00173     uint16_t size;         /* Packet size in bytes.       */
00174 };
00175 typedef struct netif_tx_request netif_tx_request_t;
00176 
00177 /* Types of netif_extra_info descriptors. */
00178 #define XEN_NETIF_EXTRA_TYPE_NONE      (0)  /* Never used - invalid */
00179 #define XEN_NETIF_EXTRA_TYPE_GSO       (1)  /* u.gso */
00180 #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2)  /* u.mcast */
00181 #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3)  /* u.mcast */
00182 #define XEN_NETIF_EXTRA_TYPE_MAX       (4)
00183 
00184 /* netif_extra_info flags. */
00185 #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
00186 #define XEN_NETIF_EXTRA_FLAG_MORE  (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
00187 
00188 /* GSO types */
00189 #define XEN_NETIF_GSO_TYPE_NONE         (0)
00190 #define XEN_NETIF_GSO_TYPE_TCPV4        (1)
00191 #define XEN_NETIF_GSO_TYPE_TCPV6        (2)
00192 
00193 /*
00194  * This structure needs to fit within both netif_tx_request and
00195  * netif_rx_response for compatibility.
00196  */
00197 struct netif_extra_info {
00198     uint8_t type;  /* XEN_NETIF_EXTRA_TYPE_* */
00199     uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
00200 
00201     union {
00202         /*
00203          * XEN_NETIF_EXTRA_TYPE_GSO:
00204          */
00205         struct {
00206             /*
00207              * Maximum payload size of each segment. For example, for TCP this
00208              * is just the path MSS.
00209              */
00210             uint16_t size;
00211 
00212             /*
00213              * GSO type. This determines the protocol of the packet and any
00214              * extra features required to segment the packet properly.
00215              */
00216             uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
00217 
00218             /* Future expansion. */
00219             uint8_t pad;
00220 
00221             /*
00222              * GSO features. This specifies any extra GSO features required
00223              * to process this packet, such as ECN support for TCPv4.
00224              */
00225             uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
00226         } gso;
00227 
00228         /*
00229          * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
00230          * Backend advertises availability via 'feature-multicast-control'
00231          * xenbus node containing value '1'.
00232          * Frontend requests this feature by advertising
00233          * 'request-multicast-control' xenbus node containing value '1'.
00234          * If multicast control is requested then multicast flooding is
00235          * disabled and the frontend must explicitly register its interest
00236          * in multicast groups using dummy transmit requests containing
00237          * MCAST_{ADD,DEL} extra-info fragments.
00238          */
00239         struct {
00240             uint8_t addr[6]; /* Address to add/remove. */
00241         } mcast;
00242 
00243         uint16_t pad[3];
00244     } u;
00245 };
00246 typedef struct netif_extra_info netif_extra_info_t;
00247 
00248 struct netif_tx_response {
00249     uint16_t id;
00250     int16_t  status;       /* NETIF_RSP_* */
00251 };
00252 typedef struct netif_tx_response netif_tx_response_t;
00253 
00254 struct netif_rx_request {
00255     uint16_t    id;        /* Echoed in response message.        */
00256     grant_ref_t gref;      /* Reference to incoming granted frame */
00257 };
00258 typedef struct netif_rx_request netif_rx_request_t;
00259 
00260 /* Packet data has been validated against protocol checksum. */
00261 #define _NETRXF_data_validated (0)
00262 #define  NETRXF_data_validated (1U<<_NETRXF_data_validated)
00263 
00264 /* Protocol checksum field is blank in the packet (hardware offload)? */
00265 #define _NETRXF_csum_blank     (1)
00266 #define  NETRXF_csum_blank     (1U<<_NETRXF_csum_blank)
00267 
00268 /* Packet continues in the next request descriptor. */
00269 #define _NETRXF_more_data      (2)
00270 #define  NETRXF_more_data      (1U<<_NETRXF_more_data)
00271 
00272 /* Packet to be followed by extra descriptor(s). */
00273 #define _NETRXF_extra_info     (3)
00274 #define  NETRXF_extra_info     (1U<<_NETRXF_extra_info)
00275 
00276 struct netif_rx_response {
00277     uint16_t id;
00278     uint16_t offset;       /* Offset in page of start of received packet  */
00279     uint16_t flags;        /* NETRXF_* */
00280     int16_t  status;       /* -ve: NETIF_RSP_* ; +ve: Rx'ed pkt size. */
00281 };
00282 typedef struct netif_rx_response netif_rx_response_t;
00283 
00284 /*
00285  * Generate netif ring structures and types.
00286  */
00287 
00288 DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);
00289 DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
00290 
00291 #define NETIF_RSP_DROPPED         -2
00292 #define NETIF_RSP_ERROR           -1
00293 #define NETIF_RSP_OKAY             0
00294 /* No response: used for auxiliary requests (e.g., netif_tx_extra). */
00295 #define NETIF_RSP_NULL             1
00296 
00297 #endif
00298 
00299 /*
00300  * Local variables:
00301  * mode: C
00302  * c-file-style: "BSD"
00303  * c-basic-offset: 4
00304  * tab-width: 4
00305  * indent-tabs-mode: nil
00306  * End:
00307  */