Add Lib, Readme
[profile/ivi/OpenAVB.git] / lib / igb_internal.h
1 /******************************************************************************
2
3   Copyright (c) 2001-2012, Intel Corporation 
4   All rights reserved.
5   
6   Redistribution and use in source and binary forms, with or without 
7   modification, are permitted provided that the following conditions are met:
8   
9    1. Redistributions of source code must retain the above copyright notice, 
10       this list of conditions and the following disclaimer.
11   
12    2. Redistributions in binary form must reproduce the above copyright 
13       notice, this list of conditions and the following disclaimer in the 
14       documentation and/or other materials provided with the distribution.
15   
16    3. Neither the name of the Intel Corporation nor the names of its 
17       contributors may be used to endorse or promote products derived from 
18       this software without specific prior written permission.
19   
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31
32 ******************************************************************************/
33 /*$FreeBSD$*/
34
35 #ifndef _IGB_INTERNAL_H_DEFINED_
36 #define _IGB_INTERNAL_H_DEFINED_
37
38 #include "igb.h"
39
40 /*
41  * Micellaneous constants
42  */
43 #define IGB_VENDOR_ID                   0x8086
44
45 #define IGB_DEFAULT_PBA                 0x00000030
46
47 #define PCI_ANY_ID                      (~0U)
48 #define ETHER_ALIGN                     2
49 #define IGB_TX_BUFFER_SIZE              ((uint32_t) 1514)
50
51 #define IGB_TX_PTHRESH                  8
52 #define IGB_TX_HTHRESH                  1
53 #define IGB_TX_WTHRESH                  16
54
55 /*
56  * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
57  * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
58  * also optimize cache line size effect. H/W supports up to cache line size 128.
59  */
60 #define IGB_DBA_ALIGN                   128
61
62 #define SPEED_MODE_BIT (1<<21)          /* On PCI-E MACs only */
63
64 #define IGB_MAX_SCATTER         64
65 #define IGB_VFTA_SIZE           128
66 #define IGB_BR_SIZE             4096    /* ring buf size */
67 #define IGB_TSO_SIZE            (65535 + sizeof(struct ether_vlan_header))
68 #define IGB_TSO_SEG_SIZE        4096    /* Max dma segment size */
69 #define IGB_HDR_BUF             128
70 #define IGB_PKTTYPE_MASK        0x0000FFF0
71 #define ETH_ZLEN                60
72 #define ETH_ADDR_LEN            6
73
74
75 /* Queue bit defines */
76 #define IGB_QUEUE_IDLE                  1
77 #define IGB_QUEUE_WORKING               2
78 #define IGB_QUEUE_HUNG                  4
79 #define IGB_QUEUE_DEPLETED              8
80
81 /*
82  * This parameter controls when the driver calls the routine to reclaim
83  * transmit descriptors. Cleaning earlier seems a win.
84  **/
85 #define IGB_TX_CLEANUP_THRESHOLD        (adapter->num_tx_desc / 2)
86 #define IGB_QUEUE_THRESHOLD             (2)
87
88 /* Precision Time Sync (IEEE 1588) defines */
89 #define ETHERTYPE_IEEE1588      0x88F7
90 #define PICOSECS_PER_TICK       20833
91 #define TSYNC_PORT              319 /* UDP port for the protocol */
92
93 struct igb_tx_buffer {
94         int             next_eop;       /* Index of the desc to watch */
95         struct igb_packet *packet;      /* app-relevant handle */
96         
97 };
98
99 /*
100  * Transmit ring: one per queue
101  */
102 struct tx_ring {
103         struct adapter          *adapter;
104         u32                     me;
105         struct resource         txdma;
106         struct e1000_tx_desc    *tx_base;
107         struct igb_tx_buffer    *tx_buffers;
108         u32                     next_avail_desc;
109         u32                     next_to_clean;
110         volatile u16            tx_avail;
111
112         u32                     bytes;
113         u32                     packets;
114
115         int                     tdt;
116         int                     tdh;
117         u64                     no_desc_avail;
118         u64                     tx_packets;
119         int                     queue_status;
120 };
121
122 struct adapter {
123         struct e1000_hw hw;
124
125         int             ldev;   /* file descriptor to igb */
126
127         struct resource csr;
128         int             max_frame_size;
129         int             min_frame_size;
130         int             igb_insert_vlan_header;
131         u16             num_queues;
132
133         /* Interface queues */
134         struct igb_queue        *queues;
135
136         /*
137          * Transmit rings
138          */
139         struct tx_ring          *tx_rings;
140         u16                     num_tx_desc;
141
142 #ifdef IGB_IEEE1588
143         /* IEEE 1588 precision time support */
144         struct cyclecounter     cycles;
145         struct nettimer         clock;
146         struct nettime_compare  compare;
147         struct hwtstamp_ctrl    hwtstamp;
148 #endif
149
150 };
151
152 /* ******************************************************************************
153  * vendor_info_array
154  *
155  * This array contains the list of Subvendor/Subdevice IDs on which the driver
156  * should load.
157  *
158  * ******************************************************************************/
159 typedef struct _igb_vendor_info_t {
160         unsigned int vendor_id;
161         unsigned int device_id;
162         unsigned int subvendor_id;
163         unsigned int subdevice_id;
164         unsigned int index;
165 } igb_vendor_info_t;
166
167 /* external API requirements */
168 #define IGB_BIND       _IOW('E', 200, int)
169 #define IGB_UNBIND     _IOW('E', 201, int)
170 #define IGB_MAPRING    _IOW('E', 202, int)
171 #define IGB_UNMAPRING  _IOW('E', 203, int)
172 #define IGB_MAPBUF     _IOW('E', 204, int)
173 #define IGB_UNMAPBUF   _IOW('E', 205, int)
174 #define IGB_LINKSPEED  _IOW('E', 206, int)
175
176 #define IGB_BIND_NAMESZ 24
177
178 struct igb_bind_cmd {
179         char    iface[IGB_BIND_NAMESZ];
180         unsigned     mmap_size;
181 };
182
183 struct igb_buf_cmd {
184         u_int64_t       physaddr; /* dma_addr_t is 64-bit */
185         unsigned int    queue;
186         unsigned int    mmap_size;
187 };
188
189 struct igb_link_cmd {
190         u_int32_t       up; /* dma_addr_t is 64-bit */
191         u_int32_t       speed;
192         u_int32_t       duplex;
193 };
194
195
196 #endif /* _IGB_H_DEFINED_ */
197
198