1 1.1 cherry /****************************************************************************** 2 1.1 cherry * netif.h 3 1.1 cherry * 4 1.1 cherry * Unified network-device I/O interface for Xen guest OSes. 5 1.1 cherry * 6 1.1 cherry * Permission is hereby granted, free of charge, to any person obtaining a copy 7 1.1 cherry * of this software and associated documentation files (the "Software"), to 8 1.1 cherry * deal in the Software without restriction, including without limitation the 9 1.1 cherry * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 1.1 cherry * sell copies of the Software, and to permit persons to whom the Software is 11 1.1 cherry * furnished to do so, subject to the following conditions: 12 1.1 cherry * 13 1.1 cherry * The above copyright notice and this permission notice shall be included in 14 1.1 cherry * all copies or substantial portions of the Software. 15 1.1 cherry * 16 1.1 cherry * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 cherry * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 cherry * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 1.1 cherry * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 1.1 cherry * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 1.1 cherry * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 1.1 cherry * DEALINGS IN THE SOFTWARE. 23 1.1 cherry * 24 1.1 cherry * Copyright (c) 2003-2004, Keir Fraser 25 1.1 cherry */ 26 1.1 cherry 27 1.1 cherry #ifndef __XEN_PUBLIC_IO_NETIF_H__ 28 1.1 cherry #define __XEN_PUBLIC_IO_NETIF_H__ 29 1.1 cherry 30 1.1 cherry #include "ring.h" 31 1.1 cherry #include "../grant_table.h" 32 1.1 cherry 33 1.1 cherry /* 34 1.1 cherry * Older implementation of Xen network frontend / backend has an 35 1.1 cherry * implicit dependency on the MAX_SKB_FRAGS as the maximum number of 36 1.1 cherry * ring slots a skb can use. Netfront / netback may not work as 37 1.1 cherry * expected when frontend and backend have different MAX_SKB_FRAGS. 38 1.1 cherry * 39 1.1 cherry * A better approach is to add mechanism for netfront / netback to 40 1.1 cherry * negotiate this value. However we cannot fix all possible 41 1.1 cherry * frontends, so we need to define a value which states the minimum 42 1.1 cherry * slots backend must support. 43 1.1 cherry * 44 1.1 cherry * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS 45 1.1 cherry * (18), which is proved to work with most frontends. Any new backend 46 1.1 cherry * which doesn't negotiate with frontend should expect frontend to 47 1.1 cherry * send a valid packet using slots up to this value. 48 1.1 cherry */ 49 1.1 cherry #define XEN_NETIF_NR_SLOTS_MIN 18 50 1.1 cherry 51 1.1 cherry /* 52 1.1 cherry * Notifications after enqueuing any type of message should be conditional on 53 1.1 cherry * the appropriate req_event or rsp_event field in the shared ring. 54 1.1 cherry * If the client sends notification for rx requests then it should specify 55 1.1 cherry * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume 56 1.1 cherry * that it cannot safely queue packets (as it may not be kicked to send them). 57 1.1 cherry */ 58 1.1 cherry 59 1.1 cherry /* 60 1.1 cherry * "feature-split-event-channels" is introduced to separate guest TX 61 1.1 cherry * and RX notification. Backend either doesn't support this feature or 62 1.1 cherry * advertises it via xenstore as 0 (disabled) or 1 (enabled). 63 1.1 cherry * 64 1.1 cherry * To make use of this feature, frontend should allocate two event 65 1.1 cherry * channels for TX and RX, advertise them to backend as 66 1.1 cherry * "event-channel-tx" and "event-channel-rx" respectively. If frontend 67 1.1 cherry * doesn't want to use this feature, it just writes "event-channel" 68 1.1 cherry * node as before. 69 1.1 cherry */ 70 1.1 cherry 71 1.1 cherry /* 72 1.1 cherry * Multiple transmit and receive queues: 73 1.1 cherry * If supported, the backend will write the key "multi-queue-max-queues" to 74 1.1 cherry * the directory for that vif, and set its value to the maximum supported 75 1.1 cherry * number of queues. 76 1.1 cherry * Frontends that are aware of this feature and wish to use it can write the 77 1.1 cherry * key "multi-queue-num-queues", set to the number they wish to use, which 78 1.1 cherry * must be greater than zero, and no more than the value reported by the backend 79 1.1 cherry * in "multi-queue-max-queues". 80 1.1 cherry * 81 1.1 cherry * Queues replicate the shared rings and event channels. 82 1.1 cherry * "feature-split-event-channels" may optionally be used when using 83 1.1 cherry * multiple queues, but is not mandatory. 84 1.1 cherry * 85 1.1 cherry * Each queue consists of one shared ring pair, i.e. there must be the same 86 1.1 cherry * number of tx and rx rings. 87 1.1 cherry * 88 1.1 cherry * For frontends requesting just one queue, the usual event-channel and 89 1.1 cherry * ring-ref keys are written as before, simplifying the backend processing 90 1.1 cherry * to avoid distinguishing between a frontend that doesn't understand the 91 1.1 cherry * multi-queue feature, and one that does, but requested only one queue. 92 1.1 cherry * 93 1.1 cherry * Frontends requesting two or more queues must not write the toplevel 94 1.1 cherry * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys, 95 1.1 cherry * instead writing those keys under sub-keys having the name "queue-N" where 96 1.1 cherry * N is the integer ID of the queue for which those keys belong. Queues 97 1.1 cherry * are indexed from zero. For example, a frontend with two queues and split 98 1.1 cherry * event channels must write the following set of queue-related keys: 99 1.1 cherry * 100 1.1 cherry * /local/domain/1/device/vif/0/multi-queue-num-queues = "2" 101 1.1 cherry * /local/domain/1/device/vif/0/queue-0 = "" 102 1.1 cherry * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>" 103 1.1 cherry * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>" 104 1.1 cherry * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>" 105 1.1 cherry * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>" 106 1.1 cherry * /local/domain/1/device/vif/0/queue-1 = "" 107 1.1 cherry * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>" 108 1.1 cherry * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1" 109 1.1 cherry * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>" 110 1.1 cherry * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>" 111 1.1 cherry * 112 1.1 cherry * If there is any inconsistency in the XenStore data, the backend may 113 1.1 cherry * choose not to connect any queues, instead treating the request as an 114 1.1 cherry * error. This includes scenarios where more (or fewer) queues were 115 1.1 cherry * requested than the frontend provided details for. 116 1.1 cherry * 117 1.1 cherry * Mapping of packets to queues is considered to be a function of the 118 1.1 cherry * transmitting system (backend or frontend) and is not negotiated 119 1.1 cherry * between the two. Guests are free to transmit packets on any queue 120 1.1 cherry * they choose, provided it has been set up correctly. Guests must be 121 1.1 cherry * prepared to receive packets on any queue they have requested be set up. 122 1.1 cherry */ 123 1.1 cherry 124 1.1 cherry /* 125 1.1 cherry * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum 126 1.1 cherry * offload off or on. If it is missing then the feature is assumed to be on. 127 1.1 cherry * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum 128 1.1 cherry * offload on or off. If it is missing then the feature is assumed to be off. 129 1.1 cherry */ 130 1.1 cherry 131 1.1 cherry /* 132 1.1 cherry * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to 133 1.1 cherry * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither 134 1.1 cherry * frontends nor backends are assumed to be capable unless the flags are 135 1.1 cherry * present. 136 1.1 cherry */ 137 1.1 cherry 138 1.1 cherry /* 139 1.1 cherry * "feature-multicast-control" and "feature-dynamic-multicast-control" 140 1.1 cherry * advertise the capability to filter ethernet multicast packets in the 141 1.1 cherry * backend. If the frontend wishes to take advantage of this feature then 142 1.1 cherry * it may set "request-multicast-control". If the backend only advertises 143 1.1 cherry * "feature-multicast-control" then "request-multicast-control" must be set 144 1.1 cherry * before the frontend moves into the connected state. The backend will 145 1.1 cherry * sample the value on this state transition and any subsequent change in 146 1.1 cherry * value will have no effect. However, if the backend also advertises 147 1.1 cherry * "feature-dynamic-multicast-control" then "request-multicast-control" 148 1.1 cherry * may be set by the frontend at any time. In this case, the backend will 149 1.1 cherry * watch the value and re-sample on watch events. 150 1.1 cherry * 151 1.1 cherry * If the sampled value of "request-multicast-control" is set then the 152 1.1 cherry * backend transmit side should no longer flood multicast packets to the 153 1.1 cherry * frontend, it should instead drop any multicast packet that does not 154 1.1 cherry * match in a filter list. 155 1.1 cherry * The list is amended by the frontend by sending dummy transmit requests 156 1.1 cherry * containing XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL} extra-info fragments as 157 1.1 cherry * specified below. 158 1.1 cherry * Note that the filter list may be amended even if the sampled value of 159 1.1 cherry * "request-multicast-control" is not set, however the filter should only 160 1.1 cherry * be applied if it is set. 161 1.1 cherry */ 162 1.1 cherry 163 1.1 cherry /* 164 1.1 cherry * Control ring 165 1.1 cherry * ============ 166 1.1 cherry * 167 1.1 cherry * Some features, such as hashing (detailed below), require a 168 1.1 cherry * significant amount of out-of-band data to be passed from frontend to 169 1.1 cherry * backend. Use of xenstore is not suitable for large quantities of data 170 1.1 cherry * because of quota limitations and so a dedicated 'control ring' is used. 171 1.1 cherry * The ability of the backend to use a control ring is advertised by 172 1.1 cherry * setting: 173 1.1 cherry * 174 1.1 cherry * /local/domain/X/backend/<domid>/<vif>/feature-ctrl-ring = "1" 175 1.1 cherry * 176 1.1 cherry * The frontend provides a control ring to the backend by setting: 177 1.1 cherry * 178 1.1 cherry * /local/domain/<domid>/device/vif/<vif>/ctrl-ring-ref = <gref> 179 1.1 cherry * /local/domain/<domid>/device/vif/<vif>/event-channel-ctrl = <port> 180 1.1 cherry * 181 1.1 cherry * where <gref> is the grant reference of the shared page used to 182 1.1 cherry * implement the control ring and <port> is an event channel to be used 183 1.1 cherry * as a mailbox interrupt. These keys must be set before the frontend 184 1.1 cherry * moves into the connected state. 185 1.1 cherry * 186 1.1 cherry * The control ring uses a fixed request/response message size and is 187 1.1 cherry * balanced (i.e. one request to one response), so operationally it is much 188 1.1 cherry * the same as a transmit or receive ring. 189 1.1 cherry * Note that there is no requirement that responses are issued in the same 190 1.1 cherry * order as requests. 191 1.1 cherry */ 192 1.1 cherry 193 1.1 cherry /* 194 1.1 cherry * Hash types 195 1.1 cherry * ========== 196 1.1 cherry * 197 1.1 cherry * For the purposes of the definitions below, 'Packet[]' is an array of 198 1.1 cherry * octets containing an IP packet without options, 'Array[X..Y]' means a 199 1.1 cherry * sub-array of 'Array' containing bytes X thru Y inclusive, and '+' is 200 1.1 cherry * used to indicate concatenation of arrays. 201 1.1 cherry */ 202 1.1 cherry 203 1.1 cherry /* 204 1.1 cherry * A hash calculated over an IP version 4 header as follows: 205 1.1 cherry * 206 1.1 cherry * Buffer[0..8] = Packet[12..15] (source address) + 207 1.1 cherry * Packet[16..19] (destination address) 208 1.1 cherry * 209 1.1 cherry * Result = Hash(Buffer, 8) 210 1.1 cherry */ 211 1.1 cherry #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4 0 212 1.1 cherry #define XEN_NETIF_CTRL_HASH_TYPE_IPV4 \ 213 1.1 cherry (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4) 214 1.1 cherry 215 1.1 cherry /* 216 1.1 cherry * A hash calculated over an IP version 4 header and TCP header as 217 1.1 cherry * follows: 218 1.1 cherry * 219 1.1 cherry * Buffer[0..12] = Packet[12..15] (source address) + 220 1.1 cherry * Packet[16..19] (destination address) + 221 1.1 cherry * Packet[20..21] (source port) + 222 1.1 cherry * Packet[22..23] (destination port) 223 1.1 cherry * 224 1.1 cherry * Result = Hash(Buffer, 12) 225 1.1 cherry */ 226 1.1 cherry #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP 1 227 1.1 cherry #define XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP \ 228 1.1 cherry (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP) 229 1.1 cherry 230 1.1 cherry /* 231 1.1 cherry * A hash calculated over an IP version 6 header as follows: 232 1.1 cherry * 233 1.1 cherry * Buffer[0..32] = Packet[8..23] (source address ) + 234 1.1 cherry * Packet[24..39] (destination address) 235 1.1 cherry * 236 1.1 cherry * Result = Hash(Buffer, 32) 237 1.1 cherry */ 238 1.1 cherry #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6 2 239 1.1 cherry #define XEN_NETIF_CTRL_HASH_TYPE_IPV6 \ 240 1.1 cherry (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6) 241 1.1 cherry 242 1.1 cherry /* 243 1.1 cherry * A hash calculated over an IP version 6 header and TCP header as 244 1.1 cherry * follows: 245 1.1 cherry * 246 1.1 cherry * Buffer[0..36] = Packet[8..23] (source address) + 247 1.1 cherry * Packet[24..39] (destination address) + 248 1.1 cherry * Packet[40..41] (source port) + 249 1.1 cherry * Packet[42..43] (destination port) 250 1.1 cherry * 251 1.1 cherry * Result = Hash(Buffer, 36) 252 1.1 cherry */ 253 1.1 cherry #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP 3 254 1.1 cherry #define XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP \ 255 1.1 cherry (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP) 256 1.1 cherry 257 1.1 cherry /* 258 1.1 cherry * Hash algorithms 259 1.1 cherry * =============== 260 1.1 cherry */ 261 1.1 cherry 262 1.1 cherry #define XEN_NETIF_CTRL_HASH_ALGORITHM_NONE 0 263 1.1 cherry 264 1.1 cherry /* 265 1.1 cherry * Toeplitz hash: 266 1.1 cherry */ 267 1.1 cherry 268 1.1 cherry #define XEN_NETIF_CTRL_HASH_ALGORITHM_TOEPLITZ 1 269 1.1 cherry 270 1.1 cherry /* 271 1.1 cherry * This algorithm uses a 'key' as well as the data buffer itself. 272 1.1 cherry * (Buffer[] and Key[] are treated as shift-registers where the MSB of 273 1.1 cherry * Buffer/Key[0] is considered 'left-most' and the LSB of Buffer/Key[N-1] 274 1.1 cherry * is the 'right-most'). 275 1.1 cherry * 276 1.1 cherry * Value = 0 277 1.1 cherry * For number of bits in Buffer[] 278 1.1 cherry * If (left-most bit of Buffer[] is 1) 279 1.1 cherry * Value ^= left-most 32 bits of Key[] 280 1.1 cherry * Key[] << 1 281 1.1 cherry * Buffer[] << 1 282 1.1 cherry * 283 1.1 cherry * The code below is provided for convenience where an operating system 284 1.1 cherry * does not already provide an implementation. 285 1.1 cherry */ 286 1.1 cherry #ifdef XEN_NETIF_DEFINE_TOEPLITZ 287 1.1 cherry static uint32_t xen_netif_toeplitz_hash(const uint8_t *key, 288 1.1 cherry unsigned int keylen, 289 1.1 cherry const uint8_t *buf, 290 1.1 cherry unsigned int buflen) 291 1.1 cherry { 292 1.1 cherry unsigned int keyi, bufi; 293 1.1 cherry uint64_t prefix = 0; 294 1.1 cherry uint64_t hash = 0; 295 1.1 cherry 296 1.1 cherry /* Pre-load prefix with the first 8 bytes of the key */ 297 1.1 cherry for (keyi = 0; keyi < 8; keyi++) { 298 1.1 cherry prefix <<= 8; 299 1.1 cherry prefix |= (keyi < keylen) ? key[keyi] : 0; 300 1.1 cherry } 301 1.1 cherry 302 1.1 cherry for (bufi = 0; bufi < buflen; bufi++) { 303 1.1 cherry uint8_t byte = buf[bufi]; 304 1.1 cherry unsigned int bit; 305 1.1 cherry 306 1.1 cherry for (bit = 0; bit < 8; bit++) { 307 1.1 cherry if (byte & 0x80) 308 1.1 cherry hash ^= prefix; 309 1.1 cherry prefix <<= 1; 310 1.1 cherry byte <<=1; 311 1.1 cherry } 312 1.1 cherry 313 1.1 cherry /* 314 1.1 cherry * 'prefix' has now been left-shifted by 8, so 315 1.1 cherry * OR in the next byte. 316 1.1 cherry */ 317 1.1 cherry prefix |= (keyi < keylen) ? key[keyi] : 0; 318 1.1 cherry keyi++; 319 1.1 cherry } 320 1.1 cherry 321 1.1 cherry /* The valid part of the hash is in the upper 32 bits. */ 322 1.1 cherry return hash >> 32; 323 1.1 cherry } 324 1.1 cherry #endif /* XEN_NETIF_DEFINE_TOEPLITZ */ 325 1.1 cherry 326 1.1 cherry /* 327 1.1 cherry * Control requests (struct xen_netif_ctrl_request) 328 1.1 cherry * ================================================ 329 1.1 cherry * 330 1.1 cherry * All requests have the following format: 331 1.1 cherry * 332 1.1 cherry * 0 1 2 3 4 5 6 7 octet 333 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 334 1.1 cherry * | id | type | data[0] | 335 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 336 1.1 cherry * | data[1] | data[2] | 337 1.1 cherry * +-----+-----+-----+-----+-----------------------+ 338 1.1 cherry * 339 1.1 cherry * id: the request identifier, echoed in response. 340 1.1 cherry * type: the type of request (see below) 341 1.1 cherry * data[]: any data associated with the request (determined by type) 342 1.1 cherry */ 343 1.1 cherry 344 1.1 cherry struct xen_netif_ctrl_request { 345 1.1 cherry uint16_t id; 346 1.1 cherry uint16_t type; 347 1.1 cherry 348 1.1 cherry #define XEN_NETIF_CTRL_TYPE_INVALID 0 349 1.1 cherry #define XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS 1 350 1.1 cherry #define XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS 2 351 1.1 cherry #define XEN_NETIF_CTRL_TYPE_SET_HASH_KEY 3 352 1.1 cherry #define XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 4 353 1.1 cherry #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 5 354 1.1 cherry #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING 6 355 1.1 cherry #define XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM 7 356 1.1 cherry #define XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE 8 357 1.1 cherry #define XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING 9 358 1.1 cherry #define XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING 10 359 1.1 cherry 360 1.1 cherry uint32_t data[3]; 361 1.1 cherry }; 362 1.1 cherry 363 1.1 cherry /* 364 1.1 cherry * Control responses (struct xen_netif_ctrl_response) 365 1.1 cherry * ================================================== 366 1.1 cherry * 367 1.1 cherry * All responses have the following format: 368 1.1 cherry * 369 1.1 cherry * 0 1 2 3 4 5 6 7 octet 370 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 371 1.1 cherry * | id | type | status | 372 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 373 1.1 cherry * | data | 374 1.1 cherry * +-----+-----+-----+-----+ 375 1.1 cherry * 376 1.1 cherry * id: the corresponding request identifier 377 1.1 cherry * type: the type of the corresponding request 378 1.1 cherry * status: the status of request processing 379 1.1 cherry * data: any data associated with the response (determined by type and 380 1.1 cherry * status) 381 1.1 cherry */ 382 1.1 cherry 383 1.1 cherry struct xen_netif_ctrl_response { 384 1.1 cherry uint16_t id; 385 1.1 cherry uint16_t type; 386 1.1 cherry uint32_t status; 387 1.1 cherry 388 1.1 cherry #define XEN_NETIF_CTRL_STATUS_SUCCESS 0 389 1.1 cherry #define XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED 1 390 1.1 cherry #define XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER 2 391 1.1 cherry #define XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW 3 392 1.1 cherry 393 1.1 cherry uint32_t data; 394 1.1 cherry }; 395 1.1 cherry 396 1.1 cherry /* 397 1.1 cherry * Static Grants (struct xen_netif_gref) 398 1.1 cherry * ===================================== 399 1.1 cherry * 400 1.1 cherry * A frontend may provide a fixed set of grant references to be mapped on 401 1.1 cherry * the backend. The message of type XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING 402 1.1 cherry * prior its usage in the command ring allows for creation of these mappings. 403 1.1 cherry * The backend will maintain a fixed amount of these mappings. 404 1.1 cherry * 405 1.1 cherry * XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE lets a frontend query how many 406 1.1 cherry * of these mappings can be kept. 407 1.1 cherry * 408 1.1 cherry * Each entry in the XEN_NETIF_CTRL_TYPE_{ADD,DEL}_GREF_MAPPING input table has 409 1.1 cherry * the following format: 410 1.1 cherry * 411 1.1 cherry * 0 1 2 3 4 5 6 7 octet 412 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 413 1.1 cherry * | grant ref | flags | status | 414 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 415 1.1 cherry * 416 1.1 cherry * grant ref: grant reference (IN) 417 1.1 cherry * flags: flags describing the control operation (IN) 418 1.1 cherry * status: XEN_NETIF_CTRL_STATUS_* (OUT) 419 1.1 cherry * 420 1.1 cherry * 'status' is an output parameter which does not require to be set to zero 421 1.1 cherry * prior to its usage in the corresponding control messages. 422 1.1 cherry */ 423 1.1 cherry 424 1.1 cherry struct xen_netif_gref { 425 1.1 cherry grant_ref_t ref; 426 1.1 cherry uint16_t flags; 427 1.1 cherry 428 1.1 cherry #define _XEN_NETIF_CTRLF_GREF_readonly 0 429 1.1 cherry #define XEN_NETIF_CTRLF_GREF_readonly (1U<<_XEN_NETIF_CTRLF_GREF_readonly) 430 1.1 cherry 431 1.1 cherry uint16_t status; 432 1.1 cherry }; 433 1.1 cherry 434 1.1 cherry /* 435 1.1 cherry * Control messages 436 1.1 cherry * ================ 437 1.1 cherry * 438 1.1 cherry * XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM 439 1.1 cherry * -------------------------------------- 440 1.1 cherry * 441 1.1 cherry * This is sent by the frontend to set the desired hash algorithm. 442 1.1 cherry * 443 1.1 cherry * Request: 444 1.1 cherry * 445 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM 446 1.1 cherry * data[0] = a XEN_NETIF_CTRL_HASH_ALGORITHM_* value 447 1.1 cherry * data[1] = 0 448 1.1 cherry * data[2] = 0 449 1.1 cherry * 450 1.1 cherry * Response: 451 1.1 cherry * 452 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 453 1.1 cherry * supported 454 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The algorithm is not 455 1.1 cherry * supported 456 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 457 1.1 cherry * 458 1.1 cherry * NOTE: Setting data[0] to XEN_NETIF_CTRL_HASH_ALGORITHM_NONE disables 459 1.1 cherry * hashing and the backend is free to choose how it steers packets 460 1.1 cherry * to queues (which is the default behaviour). 461 1.1 cherry * 462 1.1 cherry * XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS 463 1.1 cherry * ---------------------------------- 464 1.1 cherry * 465 1.1 cherry * This is sent by the frontend to query the types of hash supported by 466 1.1 cherry * the backend. 467 1.1 cherry * 468 1.1 cherry * Request: 469 1.1 cherry * 470 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS 471 1.1 cherry * data[0] = 0 472 1.1 cherry * data[1] = 0 473 1.1 cherry * data[2] = 0 474 1.1 cherry * 475 1.1 cherry * Response: 476 1.1 cherry * 477 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported 478 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 479 1.1 cherry * data = supported hash types (if operation was successful) 480 1.1 cherry * 481 1.1 cherry * NOTE: A valid hash algorithm must be selected before this operation can 482 1.1 cherry * succeed. 483 1.1 cherry * 484 1.1 cherry * XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS 485 1.1 cherry * ---------------------------------- 486 1.1 cherry * 487 1.1 cherry * This is sent by the frontend to set the types of hash that the backend 488 1.1 cherry * should calculate. (See above for hash type definitions). 489 1.1 cherry * Note that the 'maximal' type of hash should always be chosen. For 490 1.1 cherry * example, if the frontend sets both IPV4 and IPV4_TCP hash types then 491 1.1 cherry * the latter hash type should be calculated for any TCP packet and the 492 1.1 cherry * former only calculated for non-TCP packets. 493 1.1 cherry * 494 1.1 cherry * Request: 495 1.1 cherry * 496 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS 497 1.1 cherry * data[0] = bitwise OR of XEN_NETIF_CTRL_HASH_TYPE_* values 498 1.1 cherry * data[1] = 0 499 1.1 cherry * data[2] = 0 500 1.1 cherry * 501 1.1 cherry * Response: 502 1.1 cherry * 503 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 504 1.1 cherry * supported 505 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - One or more flag 506 1.1 cherry * value is invalid or 507 1.1 cherry * unsupported 508 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 509 1.1 cherry * data = 0 510 1.1 cherry * 511 1.1 cherry * NOTE: A valid hash algorithm must be selected before this operation can 512 1.1 cherry * succeed. 513 1.1 cherry * Also, setting data[0] to zero disables hashing and the backend 514 1.1 cherry * is free to choose how it steers packets to queues. 515 1.1 cherry * 516 1.1 cherry * XEN_NETIF_CTRL_TYPE_SET_HASH_KEY 517 1.1 cherry * -------------------------------- 518 1.1 cherry * 519 1.1 cherry * This is sent by the frontend to set the key of the hash if the algorithm 520 1.1 cherry * requires it. (See hash algorithms above). 521 1.1 cherry * 522 1.1 cherry * Request: 523 1.1 cherry * 524 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_SET_HASH_KEY 525 1.1 cherry * data[0] = grant reference of page containing the key (assumed to 526 1.1 cherry * start at beginning of grant) 527 1.1 cherry * data[1] = size of key in octets 528 1.1 cherry * data[2] = 0 529 1.1 cherry * 530 1.1 cherry * Response: 531 1.1 cherry * 532 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 533 1.1 cherry * supported 534 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Key size is invalid 535 1.1 cherry * XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Key size is larger 536 1.1 cherry * than the backend 537 1.1 cherry * supports 538 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 539 1.1 cherry * data = 0 540 1.1 cherry * 541 1.1 cherry * NOTE: Any key octets not specified are assumed to be zero (the key 542 1.1 cherry * is assumed to be empty by default) and specifying a new key 543 1.1 cherry * invalidates any previous key, hence specifying a key size of 544 1.1 cherry * zero will clear the key (which ensures that the calculated hash 545 1.1 cherry * will always be zero). 546 1.1 cherry * The maximum size of key is algorithm and backend specific, but 547 1.1 cherry * is also limited by the single grant reference. 548 1.1 cherry * The grant reference may be read-only and must remain valid until 549 1.1 cherry * the response has been processed. 550 1.1 cherry * 551 1.1 cherry * XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 552 1.1 cherry * ----------------------------------------- 553 1.1 cherry * 554 1.1 cherry * This is sent by the frontend to query the maximum size of mapping 555 1.1 cherry * table supported by the backend. The size is specified in terms of 556 1.1 cherry * table entries. 557 1.1 cherry * 558 1.1 cherry * Request: 559 1.1 cherry * 560 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 561 1.1 cherry * data[0] = 0 562 1.1 cherry * data[1] = 0 563 1.1 cherry * data[2] = 0 564 1.1 cherry * 565 1.1 cherry * Response: 566 1.1 cherry * 567 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported 568 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 569 1.1 cherry * data = maximum number of entries allowed in the mapping table 570 1.1 cherry * (if operation was successful) or zero if a mapping table is 571 1.1 cherry * not supported (i.e. hash mapping is done only by modular 572 1.1 cherry * arithmetic). 573 1.1 cherry * 574 1.1 cherry * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 575 1.1 cherry * ------------------------------------- 576 1.1 cherry * 577 1.1 cherry * This is sent by the frontend to set the actual size of the mapping 578 1.1 cherry * table to be used by the backend. The size is specified in terms of 579 1.1 cherry * table entries. 580 1.1 cherry * Any previous table is invalidated by this message and any new table 581 1.1 cherry * is assumed to be zero filled. 582 1.1 cherry * 583 1.1 cherry * Request: 584 1.1 cherry * 585 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 586 1.1 cherry * data[0] = number of entries in mapping table 587 1.1 cherry * data[1] = 0 588 1.1 cherry * data[2] = 0 589 1.1 cherry * 590 1.1 cherry * Response: 591 1.1 cherry * 592 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 593 1.1 cherry * supported 594 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size is invalid 595 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 596 1.1 cherry * data = 0 597 1.1 cherry * 598 1.1 cherry * NOTE: Setting data[0] to 0 means that hash mapping should be done 599 1.1 cherry * using modular arithmetic. 600 1.1 cherry * 601 1.1 cherry * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING 602 1.1 cherry * ------------------------------------ 603 1.1 cherry * 604 1.1 cherry * This is sent by the frontend to set the content of the table mapping 605 1.1 cherry * hash value to queue number. The backend should calculate the hash from 606 1.1 cherry * the packet header, use it as an index into the table (modulo the size 607 1.1 cherry * of the table) and then steer the packet to the queue number found at 608 1.1 cherry * that index. 609 1.1 cherry * 610 1.1 cherry * Request: 611 1.1 cherry * 612 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING 613 1.1 cherry * data[0] = grant reference of page containing the mapping (sub-)table 614 1.1 cherry * (assumed to start at beginning of grant) 615 1.1 cherry * data[1] = size of (sub-)table in entries 616 1.1 cherry * data[2] = offset, in entries, of sub-table within overall table 617 1.1 cherry * 618 1.1 cherry * Response: 619 1.1 cherry * 620 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 621 1.1 cherry * supported 622 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size or content 623 1.1 cherry * is invalid 624 1.1 cherry * XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Table size is larger 625 1.1 cherry * than the backend 626 1.1 cherry * supports 627 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 628 1.1 cherry * data = 0 629 1.1 cherry * 630 1.1 cherry * NOTE: The overall table has the following format: 631 1.1 cherry * 632 1.1 cherry * 0 1 2 3 4 5 6 7 octet 633 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 634 1.1 cherry * | mapping[0] | mapping[1] | 635 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 636 1.1 cherry * | . | 637 1.1 cherry * | . | 638 1.1 cherry * | . | 639 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 640 1.1 cherry * | mapping[N-2] | mapping[N-1] | 641 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 642 1.1 cherry * 643 1.1 cherry * where N is specified by a XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 644 1.1 cherry * message and each mapping must specifies a queue between 0 and 645 1.1 cherry * "multi-queue-num-queues" (see above). 646 1.1 cherry * The backend may support a mapping table larger than can be 647 1.1 cherry * mapped by a single grant reference. Thus sub-tables within a 648 1.1 cherry * larger table can be individually set by sending multiple messages 649 1.1 cherry * with differing offset values. Specifying a new sub-table does not 650 1.1 cherry * invalidate any table data outside that range. 651 1.1 cherry * The grant reference may be read-only and must remain valid until 652 1.1 cherry * the response has been processed. 653 1.1 cherry * 654 1.1 cherry * XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE 655 1.1 cherry * ----------------------------------------- 656 1.1 cherry * 657 1.1 cherry * This is sent by the frontend to fetch the number of grefs that can be kept 658 1.1 cherry * mapped in the backend. 659 1.1 cherry * 660 1.1 cherry * Request: 661 1.1 cherry * 662 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE 663 1.1 cherry * data[0] = queue index (assumed 0 for single queue) 664 1.1 cherry * data[1] = 0 665 1.1 cherry * data[2] = 0 666 1.1 cherry * 667 1.1 cherry * Response: 668 1.1 cherry * 669 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 670 1.1 cherry * supported 671 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The queue index is 672 1.1 cherry * out of range 673 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 674 1.1 cherry * data = maximum number of entries allowed in the gref mapping table 675 1.1 cherry * (if operation was successful) or zero if it is not supported. 676 1.1 cherry * 677 1.1 cherry * XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING 678 1.1 cherry * ------------------------------------ 679 1.1 cherry * 680 1.1 cherry * This is sent by the frontend for backend to map a list of grant 681 1.1 cherry * references. 682 1.1 cherry * 683 1.1 cherry * Request: 684 1.1 cherry * 685 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING 686 1.1 cherry * data[0] = queue index 687 1.1 cherry * data[1] = grant reference of page containing the mapping list 688 1.1 cherry * (r/w and assumed to start at beginning of page) 689 1.1 cherry * data[2] = size of list in entries 690 1.1 cherry * 691 1.1 cherry * Response: 692 1.1 cherry * 693 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 694 1.1 cherry * supported 695 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Operation failed 696 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 697 1.1 cherry * 698 1.1 cherry * NOTE: Each entry in the input table has the format outlined 699 1.1 cherry * in struct xen_netif_gref. 700 1.1 cherry * Contrary to XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING, the struct 701 1.1 cherry * xen_netif_gref 'status' field is not used and therefore the response 702 1.1 cherry * 'status' determines the success of this operation. In case of 703 1.1 cherry * failure none of grants mappings get added in the backend. 704 1.1 cherry * 705 1.1 cherry * XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING 706 1.1 cherry * ------------------------------------ 707 1.1 cherry * 708 1.1 cherry * This is sent by the frontend for backend to unmap a list of grant 709 1.1 cherry * references. 710 1.1 cherry * 711 1.1 cherry * Request: 712 1.1 cherry * 713 1.1 cherry * type = XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING 714 1.1 cherry * data[0] = queue index 715 1.1 cherry * data[1] = grant reference of page containing the mapping list 716 1.1 cherry * (r/w and assumed to start at beginning of page) 717 1.1 cherry * data[2] = size of list in entries 718 1.1 cherry * 719 1.1 cherry * Response: 720 1.1 cherry * 721 1.1 cherry * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not 722 1.1 cherry * supported 723 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Operation failed 724 1.1 cherry * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful 725 1.1 cherry * data = number of entries that were unmapped 726 1.1 cherry * 727 1.1 cherry * NOTE: Each entry in the input table has the format outlined in struct 728 1.1 cherry * xen_netif_gref. 729 1.1 cherry * The struct xen_netif_gref 'status' field determines if the entry 730 1.1 cherry * was successfully removed. 731 1.1 cherry * The entries used are only the ones representing grant references that 732 1.1 cherry * were previously the subject of a XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING 733 1.1 cherry * operation. Any other entries will have their status set to 734 1.1 cherry * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER upon completion. 735 1.1 cherry */ 736 1.1 cherry 737 1.1 cherry DEFINE_RING_TYPES(xen_netif_ctrl, 738 1.1 cherry struct xen_netif_ctrl_request, 739 1.1 cherry struct xen_netif_ctrl_response); 740 1.1 cherry 741 1.1 cherry /* 742 1.1 cherry * Guest transmit 743 1.1 cherry * ============== 744 1.1 cherry * 745 1.1 cherry * This is the 'wire' format for transmit (frontend -> backend) packets: 746 1.1 cherry * 747 1.1 cherry * Fragment 1: netif_tx_request_t - flags = NETTXF_* 748 1.1 cherry * size = total packet size 749 1.1 cherry * [Extra 1: netif_extra_info_t] - (only if fragment 1 flags include 750 1.1 cherry * NETTXF_extra_info) 751 1.1 cherry * ... 752 1.1 cherry * [Extra N: netif_extra_info_t] - (only if extra N-1 flags include 753 1.1 cherry * XEN_NETIF_EXTRA_MORE) 754 1.1 cherry * ... 755 1.1 cherry * Fragment N: netif_tx_request_t - (only if fragment N-1 flags include 756 1.1 cherry * NETTXF_more_data - flags on preceding 757 1.1 cherry * extras are not relevant here) 758 1.1 cherry * flags = 0 759 1.1 cherry * size = fragment size 760 1.1 cherry * 761 1.1 cherry * NOTE: 762 1.1 cherry * 763 1.1 cherry * This format slightly is different from that used for receive 764 1.1 cherry * (backend -> frontend) packets. Specifically, in a multi-fragment 765 1.1 cherry * packet the actual size of fragment 1 can only be determined by 766 1.1 cherry * subtracting the sizes of fragments 2..N from the total packet size. 767 1.1 cherry * 768 1.1 cherry * Ring slot size is 12 octets, however not all request/response 769 1.1 cherry * structs use the full size. 770 1.1 cherry * 771 1.1 cherry * tx request data (netif_tx_request_t) 772 1.1 cherry * ------------------------------------ 773 1.1 cherry * 774 1.1 cherry * 0 1 2 3 4 5 6 7 octet 775 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 776 1.1 cherry * | grant ref | offset | flags | 777 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 778 1.1 cherry * | id | size | 779 1.1 cherry * +-----+-----+-----+-----+ 780 1.1 cherry * 781 1.1 cherry * grant ref: Reference to buffer page. 782 1.1 cherry * offset: Offset within buffer page. 783 1.1 cherry * flags: NETTXF_*. 784 1.1 cherry * id: request identifier, echoed in response. 785 1.1 cherry * size: packet size in bytes. 786 1.1 cherry * 787 1.1 cherry * tx response (netif_tx_response_t) 788 1.1 cherry * --------------------------------- 789 1.1 cherry * 790 1.1 cherry * 0 1 2 3 4 5 6 7 octet 791 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 792 1.1 cherry * | id | status | unused | 793 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 794 1.1 cherry * | unused | 795 1.1 cherry * +-----+-----+-----+-----+ 796 1.1 cherry * 797 1.1 cherry * id: reflects id in transmit request 798 1.1 cherry * status: NETIF_RSP_* 799 1.1 cherry * 800 1.1 cherry * Guest receive 801 1.1 cherry * ============= 802 1.1 cherry * 803 1.1 cherry * This is the 'wire' format for receive (backend -> frontend) packets: 804 1.1 cherry * 805 1.1 cherry * Fragment 1: netif_rx_request_t - flags = NETRXF_* 806 1.1 cherry * size = fragment size 807 1.1 cherry * [Extra 1: netif_extra_info_t] - (only if fragment 1 flags include 808 1.1 cherry * NETRXF_extra_info) 809 1.1 cherry * ... 810 1.1 cherry * [Extra N: netif_extra_info_t] - (only if extra N-1 flags include 811 1.1 cherry * XEN_NETIF_EXTRA_MORE) 812 1.1 cherry * ... 813 1.1 cherry * Fragment N: netif_rx_request_t - (only if fragment N-1 flags include 814 1.1 cherry * NETRXF_more_data - flags on preceding 815 1.1 cherry * extras are not relevant here) 816 1.1 cherry * flags = 0 817 1.1 cherry * size = fragment size 818 1.1 cherry * 819 1.1 cherry * NOTE: 820 1.1 cherry * 821 1.1 cherry * This format slightly is different from that used for transmit 822 1.1 cherry * (frontend -> backend) packets. Specifically, in a multi-fragment 823 1.1 cherry * packet the size of the packet can only be determined by summing the 824 1.1 cherry * sizes of fragments 1..N. 825 1.1 cherry * 826 1.1 cherry * Ring slot size is 8 octets. 827 1.1 cherry * 828 1.1 cherry * rx request (netif_rx_request_t) 829 1.1 cherry * ------------------------------- 830 1.1 cherry * 831 1.1 cherry * 0 1 2 3 4 5 6 7 octet 832 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 833 1.1 cherry * | id | pad | gref | 834 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 835 1.1 cherry * 836 1.1 cherry * id: request identifier, echoed in response. 837 1.1 cherry * gref: reference to incoming granted frame. 838 1.1 cherry * 839 1.1 cherry * rx response (netif_rx_response_t) 840 1.1 cherry * --------------------------------- 841 1.1 cherry * 842 1.1 cherry * 0 1 2 3 4 5 6 7 octet 843 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 844 1.1 cherry * | id | offset | flags | status | 845 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 846 1.1 cherry * 847 1.1 cherry * id: reflects id in receive request 848 1.1 cherry * offset: offset in page of start of received packet 849 1.1 cherry * flags: NETRXF_* 850 1.1 cherry * status: -ve: NETIF_RSP_*; +ve: Rx'ed pkt size. 851 1.1 cherry * 852 1.1 cherry * NOTE: Historically, to support GSO on the frontend receive side, Linux 853 1.1 cherry * netfront does not make use of the rx response id (because, as 854 1.1 cherry * described below, extra info structures overlay the id field). 855 1.1 cherry * Instead it assumes that responses always appear in the same ring 856 1.1 cherry * slot as their corresponding request. Thus, to maintain 857 1.1 cherry * compatibility, backends must make sure this is the case. 858 1.1 cherry * 859 1.1 cherry * Extra Info 860 1.1 cherry * ========== 861 1.1 cherry * 862 1.1 cherry * Can be present if initial request or response has NET{T,R}XF_extra_info, 863 1.1 cherry * or previous extra request has XEN_NETIF_EXTRA_MORE. 864 1.1 cherry * 865 1.1 cherry * The struct therefore needs to fit into either a tx or rx slot and 866 1.1 cherry * is therefore limited to 8 octets. 867 1.1 cherry * 868 1.1 cherry * NOTE: Because extra info data overlays the usual request/response 869 1.1 cherry * structures, there is no id information in the opposite direction. 870 1.1 cherry * So, if an extra info overlays an rx response the frontend can 871 1.1 cherry * assume that it is in the same ring slot as the request that was 872 1.1 cherry * consumed to make the slot available, and the backend must ensure 873 1.1 cherry * this assumption is true. 874 1.1 cherry * 875 1.1 cherry * extra info (netif_extra_info_t) 876 1.1 cherry * ------------------------------- 877 1.1 cherry * 878 1.1 cherry * General format: 879 1.1 cherry * 880 1.1 cherry * 0 1 2 3 4 5 6 7 octet 881 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 882 1.1 cherry * |type |flags| type specific data | 883 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 884 1.1 cherry * | padding for tx | 885 1.1 cherry * +-----+-----+-----+-----+ 886 1.1 cherry * 887 1.1 cherry * type: XEN_NETIF_EXTRA_TYPE_* 888 1.1 cherry * flags: XEN_NETIF_EXTRA_FLAG_* 889 1.1 cherry * padding for tx: present only in the tx case due to 8 octet limit 890 1.1 cherry * from rx case. Not shown in type specific entries 891 1.1 cherry * below. 892 1.1 cherry * 893 1.1 cherry * XEN_NETIF_EXTRA_TYPE_GSO: 894 1.1 cherry * 895 1.1 cherry * 0 1 2 3 4 5 6 7 octet 896 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 897 1.1 cherry * |type |flags| size |type | pad | features | 898 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 899 1.1 cherry * 900 1.1 cherry * type: Must be XEN_NETIF_EXTRA_TYPE_GSO 901 1.1 cherry * flags: XEN_NETIF_EXTRA_FLAG_* 902 1.1 cherry * size: Maximum payload size of each segment. For example, 903 1.1 cherry * for TCP this is just the path MSS. 904 1.1 cherry * type: XEN_NETIF_GSO_TYPE_*: This determines the protocol of 905 1.1 cherry * the packet and any extra features required to segment the 906 1.1 cherry * packet properly. 907 1.1 cherry * features: EN_NETIF_GSO_FEAT_*: This specifies any extra GSO 908 1.1 cherry * features required to process this packet, such as ECN 909 1.1 cherry * support for TCPv4. 910 1.1 cherry * 911 1.1 cherry * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}: 912 1.1 cherry * 913 1.1 cherry * 0 1 2 3 4 5 6 7 octet 914 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 915 1.1 cherry * |type |flags| addr | 916 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 917 1.1 cherry * 918 1.1 cherry * type: Must be XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL} 919 1.1 cherry * flags: XEN_NETIF_EXTRA_FLAG_* 920 1.1 cherry * addr: address to add/remove 921 1.1 cherry * 922 1.1 cherry * XEN_NETIF_EXTRA_TYPE_HASH: 923 1.1 cherry * 924 1.1 cherry * A backend that supports teoplitz hashing is assumed to accept 925 1.1 cherry * this type of extra info in transmit packets. 926 1.1 cherry * A frontend that enables hashing is assumed to accept 927 1.1 cherry * this type of extra info in receive packets. 928 1.1 cherry * 929 1.1 cherry * 0 1 2 3 4 5 6 7 octet 930 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 931 1.1 cherry * |type |flags|htype| alg |LSB ---- value ---- MSB| 932 1.1 cherry * +-----+-----+-----+-----+-----+-----+-----+-----+ 933 1.1 cherry * 934 1.1 cherry * type: Must be XEN_NETIF_EXTRA_TYPE_HASH 935 1.1 cherry * flags: XEN_NETIF_EXTRA_FLAG_* 936 1.1 cherry * htype: Hash type (one of _XEN_NETIF_CTRL_HASH_TYPE_* - see above) 937 1.1 cherry * alg: The algorithm used to calculate the hash (one of 938 1.1 cherry * XEN_NETIF_CTRL_HASH_TYPE_ALGORITHM_* - see above) 939 1.1 cherry * value: Hash value 940 1.1 cherry */ 941 1.1 cherry 942 1.1 cherry /* Protocol checksum field is blank in the packet (hardware offload)? */ 943 1.1 cherry #define _NETTXF_csum_blank (0) 944 1.1 cherry #define NETTXF_csum_blank (1U<<_NETTXF_csum_blank) 945 1.1 cherry 946 1.1 cherry /* Packet data has been validated against protocol checksum. */ 947 1.1 cherry #define _NETTXF_data_validated (1) 948 1.1 cherry #define NETTXF_data_validated (1U<<_NETTXF_data_validated) 949 1.1 cherry 950 1.1 cherry /* Packet continues in the next request descriptor. */ 951 1.1 cherry #define _NETTXF_more_data (2) 952 1.1 cherry #define NETTXF_more_data (1U<<_NETTXF_more_data) 953 1.1 cherry 954 1.1 cherry /* Packet to be followed by extra descriptor(s). */ 955 1.1 cherry #define _NETTXF_extra_info (3) 956 1.1 cherry #define NETTXF_extra_info (1U<<_NETTXF_extra_info) 957 1.1 cherry 958 1.1 cherry #define XEN_NETIF_MAX_TX_SIZE 0xFFFF 959 1.1 cherry struct netif_tx_request { 960 1.1 cherry grant_ref_t gref; 961 1.1 cherry uint16_t offset; 962 1.1 cherry uint16_t flags; 963 1.1 cherry uint16_t id; 964 1.1 cherry uint16_t size; 965 1.1 cherry }; 966 1.1 cherry typedef struct netif_tx_request netif_tx_request_t; 967 1.1 cherry 968 1.1 cherry /* Types of netif_extra_info descriptors. */ 969 1.1 cherry #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */ 970 1.1 cherry #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */ 971 1.1 cherry #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */ 972 1.1 cherry #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */ 973 1.1 cherry #define XEN_NETIF_EXTRA_TYPE_HASH (4) /* u.hash */ 974 1.1 cherry #define XEN_NETIF_EXTRA_TYPE_MAX (5) 975 1.1 cherry 976 1.1 cherry /* netif_extra_info_t flags. */ 977 1.1 cherry #define _XEN_NETIF_EXTRA_FLAG_MORE (0) 978 1.1 cherry #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE) 979 1.1 cherry 980 1.1 cherry /* GSO types */ 981 1.1 cherry #define XEN_NETIF_GSO_TYPE_NONE (0) 982 1.1 cherry #define XEN_NETIF_GSO_TYPE_TCPV4 (1) 983 1.1 cherry #define XEN_NETIF_GSO_TYPE_TCPV6 (2) 984 1.1 cherry 985 1.1 cherry /* 986 1.1 cherry * This structure needs to fit within both netif_tx_request_t and 987 1.1 cherry * netif_rx_response_t for compatibility. 988 1.1 cherry */ 989 1.1 cherry struct netif_extra_info { 990 1.1 cherry uint8_t type; 991 1.1 cherry uint8_t flags; 992 1.1 cherry union { 993 1.1 cherry struct { 994 1.1 cherry uint16_t size; 995 1.1 cherry uint8_t type; 996 1.1 cherry uint8_t pad; 997 1.1 cherry uint16_t features; 998 1.1 cherry } gso; 999 1.1 cherry struct { 1000 1.1 cherry uint8_t addr[6]; 1001 1.1 cherry } mcast; 1002 1.1 cherry struct { 1003 1.1 cherry uint8_t type; 1004 1.1 cherry uint8_t algorithm; 1005 1.1 cherry uint8_t value[4]; 1006 1.1 cherry } hash; 1007 1.1 cherry uint16_t pad[3]; 1008 1.1 cherry } u; 1009 1.1 cherry }; 1010 1.1 cherry typedef struct netif_extra_info netif_extra_info_t; 1011 1.1 cherry 1012 1.1 cherry struct netif_tx_response { 1013 1.1 cherry uint16_t id; 1014 1.1 cherry int16_t status; 1015 1.1 cherry }; 1016 1.1 cherry typedef struct netif_tx_response netif_tx_response_t; 1017 1.1 cherry 1018 1.1 cherry struct netif_rx_request { 1019 1.1 cherry uint16_t id; /* Echoed in response message. */ 1020 1.1 cherry uint16_t pad; 1021 1.1 cherry grant_ref_t gref; 1022 1.1 cherry }; 1023 1.1 cherry typedef struct netif_rx_request netif_rx_request_t; 1024 1.1 cherry 1025 1.1 cherry /* Packet data has been validated against protocol checksum. */ 1026 1.1 cherry #define _NETRXF_data_validated (0) 1027 1.1 cherry #define NETRXF_data_validated (1U<<_NETRXF_data_validated) 1028 1.1 cherry 1029 1.1 cherry /* Protocol checksum field is blank in the packet (hardware offload)? */ 1030 1.1 cherry #define _NETRXF_csum_blank (1) 1031 1.1 cherry #define NETRXF_csum_blank (1U<<_NETRXF_csum_blank) 1032 1.1 cherry 1033 1.1 cherry /* Packet continues in the next request descriptor. */ 1034 1.1 cherry #define _NETRXF_more_data (2) 1035 1.1 cherry #define NETRXF_more_data (1U<<_NETRXF_more_data) 1036 1.1 cherry 1037 1.1 cherry /* Packet to be followed by extra descriptor(s). */ 1038 1.1 cherry #define _NETRXF_extra_info (3) 1039 1.1 cherry #define NETRXF_extra_info (1U<<_NETRXF_extra_info) 1040 1.1 cherry 1041 1.1 cherry /* Packet has GSO prefix. Deprecated but included for compatibility */ 1042 1.1 cherry #define _NETRXF_gso_prefix (4) 1043 1.1 cherry #define NETRXF_gso_prefix (1U<<_NETRXF_gso_prefix) 1044 1.1 cherry 1045 1.1 cherry struct netif_rx_response { 1046 1.1 cherry uint16_t id; 1047 1.1 cherry uint16_t offset; 1048 1.1 cherry uint16_t flags; 1049 1.1 cherry int16_t status; 1050 1.1 cherry }; 1051 1.1 cherry typedef struct netif_rx_response netif_rx_response_t; 1052 1.1 cherry 1053 1.1 cherry /* 1054 1.1 cherry * Generate netif ring structures and types. 1055 1.1 cherry */ 1056 1.1 cherry 1057 1.1 cherry DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response); 1058 1.1 cherry DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response); 1059 1.1 cherry 1060 1.1 cherry #define NETIF_RSP_DROPPED -2 1061 1.1 cherry #define NETIF_RSP_ERROR -1 1062 1.1 cherry #define NETIF_RSP_OKAY 0 1063 1.1 cherry /* No response: used for auxiliary requests (e.g., netif_extra_info_t). */ 1064 1.1 cherry #define NETIF_RSP_NULL 1 1065 1.1 cherry 1066 1.1 cherry #endif 1067 1.1 cherry 1068 1.1 cherry /* 1069 1.1 cherry * Local variables: 1070 1.1 cherry * mode: C 1071 1.1 cherry * c-file-style: "BSD" 1072 1.1 cherry * c-basic-offset: 4 1073 1.1 cherry * tab-width: 4 1074 1.1 cherry * indent-tabs-mode: nil 1075 1.1 cherry * End: 1076 1.1 cherry */ 1077