Initial revision
[linux-2.6.git] / include / asm-xen / xen-public / io / netif.h
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
9 #ifndef __XEN_PUBLIC_IO_NETIF_H__
10 #define __XEN_PUBLIC_IO_NETIF_H__
11
12 typedef struct {
13     memory_t addr;   /*  0: Machine address of packet.  */
14     MEMORY_PADDING;
15     u16      id;     /*  8: Echoed in response message. */
16     u16      size;   /* 10: Packet size in bytes.       */
17 } PACKED netif_tx_request_t; /* 12 bytes */
18
19 typedef struct {
20     u16      id;     /*  0 */
21     s8       status; /*  2 */
22     u8       __pad;  /*  3 */
23 } PACKED netif_tx_response_t; /* 4 bytes */
24
25 typedef struct {
26     u16       id;    /*  0: Echoed in response message.        */
27 } PACKED netif_rx_request_t; /* 2 bytes */
28
29 typedef struct {
30     memory_t addr;   /*  0: Machine address of packet.              */
31     MEMORY_PADDING;
32     u16      id;     /*  8:  */
33     s16      status; /* 10: -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
34 } PACKED netif_rx_response_t; /* 12 bytes */
35
36 /*
37  * We use a special capitalised type name because it is _essential_ that all 
38  * arithmetic on indexes is done on an integer type of the correct size.
39  */
40 typedef u32 NETIF_RING_IDX;
41
42 /*
43  * Ring indexes are 'free running'. That is, they are not stored modulo the
44  * size of the ring buffer. The following macros convert a free-running counter
45  * into a value that can directly index a ring-buffer array.
46  */
47 #define MASK_NETIF_RX_IDX(_i) ((_i)&(NETIF_RX_RING_SIZE-1))
48 #define MASK_NETIF_TX_IDX(_i) ((_i)&(NETIF_TX_RING_SIZE-1))
49
50 #define NETIF_TX_RING_SIZE 256
51 #define NETIF_RX_RING_SIZE 256
52
53 /* This structure must fit in a memory page. */
54 typedef struct {
55     /*
56      * Frontend places packets into ring at tx_req_prod.
57      * Frontend receives event when tx_resp_prod passes tx_event.
58      * 'req_cons' is a shadow of the backend's request consumer -- the frontend
59      * may use it to determine if all queued packets have been seen by the
60      * backend.
61      */
62     NETIF_RING_IDX req_prod;       /*  0 */
63     NETIF_RING_IDX req_cons;       /*  4 */
64     NETIF_RING_IDX resp_prod;      /*  8 */
65     NETIF_RING_IDX event;          /* 12 */
66     union {                        /* 16 */
67         netif_tx_request_t  req;
68         netif_tx_response_t resp;
69     } PACKED ring[NETIF_TX_RING_SIZE];
70 } PACKED netif_tx_interface_t;
71
72 /* This structure must fit in a memory page. */
73 typedef struct {
74     /*
75      * Frontend places empty buffers into ring at rx_req_prod.
76      * Frontend receives event when rx_resp_prod passes rx_event.
77      */
78     NETIF_RING_IDX req_prod;       /*  0 */
79     NETIF_RING_IDX resp_prod;      /*  4 */
80     NETIF_RING_IDX event;          /*  8 */
81     union {                        /* 12 */
82         netif_rx_request_t  req;
83         netif_rx_response_t resp;
84     } PACKED ring[NETIF_RX_RING_SIZE];
85 } PACKED netif_rx_interface_t;
86
87 /* Descriptor status values */
88 #define NETIF_RSP_DROPPED         -2
89 #define NETIF_RSP_ERROR           -1
90 #define NETIF_RSP_OKAY             0
91
92 #endif