get mxge to build, stage 27/many
[dragonfly.git] / sys / dev / netif / mxge / if_mxge_var.h
1 /*******************************************************************************
2
3 Copyright (c) 2006-2009, Myricom Inc.
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. Neither the name of the Myricom Inc, nor the names of its
13     contributors may be used to endorse or promote products derived from
14     this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27
28 $FreeBSD: src/sys/dev/mxge/if_mxge_var.h,v 1.30 2009/06/24 21:09:56 gallatin Exp $
29
30 ***************************************************************************/
31
32 #define MXGE_ETH_STOPPED 0
33 #define MXGE_ETH_STOPPING 1
34 #define MXGE_ETH_STARTING 2
35 #define MXGE_ETH_RUNNING 3
36 #define MXGE_ETH_OPEN_FAILED 4
37
38 #define MXGE_FW_OFFSET 1024*1024
39 #define MXGE_EEPROM_STRINGS_SIZE 256
40 #define MXGE_MAX_SEND_DESC 128
41
42 #if ((__FreeBSD_version > 800000 && __FreeBSD_version < 800005) \
43      || __FreeBSD_version < 700111)
44 #define MXGE_VIRT_JUMBOS 1
45 #else
46 #define MXGE_VIRT_JUMBOS 0
47 #endif
48
49 #if (__FreeBSD_version > 800082)
50 #define IFNET_BUF_RING 1
51 #endif
52
53 #ifndef VLAN_CAPABILITIES
54 #define VLAN_CAPABILITIES(ifp)
55 #define mxge_vlans_active(sc) (sc)->ifp->if_nvlans
56 #else
57 #define mxge_vlans_active(sc) (sc)->ifp->if_vlantrunk
58 #endif
59
60 #ifndef VLAN_TAG_VALUE
61 #define MXGE_NEW_VLAN_API
62 #endif
63
64 #ifndef IFCAP_LRO
65 #define IFCAP_LRO 0
66 #endif
67
68 #ifndef IFCAP_TSO
69 #define IFCAP_TSO 0
70 #endif
71  
72 #ifndef IFCAP_TSO4
73 #define IFCAP_TSO4 0
74 #endif
75
76 #ifndef CSUM_TSO
77 #define CSUM_TSO 0
78 #endif
79
80
81 typedef struct {
82         void *addr;
83         bus_addr_t bus_addr;
84         bus_dma_tag_t dmat;
85         bus_dmamap_t map;
86 } mxge_dma_t;
87
88
89 typedef struct {
90         mcp_slot_t *entry;
91         mxge_dma_t dma;
92         int cnt;
93         int idx;
94         int mask;
95 } mxge_rx_done_t;
96
97 typedef struct
98 {
99   uint32_t data0;
100   uint32_t data1;
101   uint32_t data2;
102 } mxge_cmd_t;
103
104 struct mxge_rx_buffer_state {
105         struct mbuf *m;
106         bus_dmamap_t map;
107 };
108
109 struct mxge_tx_buffer_state {
110         struct mbuf *m;
111         bus_dmamap_t map;
112         int flag;
113 };
114
115 typedef struct
116 {
117         volatile mcp_kreq_ether_recv_t *lanai;  /* lanai ptr for recv ring */
118         mcp_kreq_ether_recv_t *shadow;  /* host shadow of recv ring */
119         struct mxge_rx_buffer_state *info;
120         bus_dma_tag_t dmat;
121         bus_dmamap_t extra_map;
122         int cnt;
123         int nbufs;
124         int cl_size;
125         int alloc_fail;
126         int mask;                       /* number of rx slots -1 */
127         int mlen;
128 } mxge_rx_ring_t;
129
130 typedef struct
131 {
132 #ifdef IFNET_BUF_RING
133         struct buf_ring *br;
134 #endif
135         volatile mcp_kreq_ether_send_t *lanai;  /* lanai ptr for sendq  */
136         volatile uint32_t *send_go;             /* doorbell for sendq */
137         volatile uint32_t *send_stop;           /* doorbell for sendq */
138         mcp_kreq_ether_send_t *req_list;        /* host shadow of sendq */
139         char *req_bytes;
140         bus_dma_segment_t *seg_list;
141         struct mxge_tx_buffer_state *info;
142         bus_dma_tag_t dmat;
143         int req;                        /* transmits submitted  */
144         int mask;                       /* number of transmit slots -1 */
145         int done;                       /* transmits completed  */
146         int pkt_done;                   /* packets completed */
147         int max_desc;                   /* max descriptors per xmit */
148         int queue_active;               /* fw currently polling this queue*/
149         int activate;
150         int deactivate;
151         int stall;                      /* #times hw queue exhausted */
152         int wake;                       /* #times irq re-enabled xmit */
153         int watchdog_req;               /* cache of req */
154         int watchdog_done;              /* cache of done */
155         int watchdog_rx_pause;          /* cache of pause rq recvd */
156         int defrag;
157 } mxge_tx_ring_t;
158
159 struct lro_entry;
160 struct lro_entry
161 {
162         SLIST_ENTRY(lro_entry) next;
163         struct mbuf     *m_head;
164         struct mbuf     *m_tail;
165         int             timestamp;
166         struct ip       *ip;
167         uint32_t        tsval;
168         uint32_t        tsecr;
169         uint32_t        source_ip;
170         uint32_t        dest_ip;
171         uint32_t        next_seq;
172         uint32_t        ack_seq;
173         uint32_t        len;
174         uint32_t        data_csum;
175         uint16_t        window;
176         uint16_t        source_port;
177         uint16_t        dest_port;
178         uint16_t        append_cnt;
179         uint16_t        mss;
180         
181 };
182 SLIST_HEAD(lro_head, lro_entry);
183
184 struct mxge_softc;
185 typedef struct mxge_softc mxge_softc_t;
186
187 struct mxge_slice_state {
188         mxge_softc_t *sc;
189         mxge_tx_ring_t tx;              /* transmit ring        */
190         mxge_rx_ring_t rx_small;
191         mxge_rx_ring_t rx_big;
192         mxge_rx_done_t rx_done;
193         mcp_irq_data_t *fw_stats;
194         volatile uint32_t *irq_claim;
195         u_long ipackets;
196         u_long opackets;
197         u_long obytes;
198         u_long omcasts;
199         u_long oerrors;
200         int if_drv_flags;
201         struct lro_head lro_active;
202         struct lro_head lro_free;
203         int lro_queued;
204         int lro_flushed;
205         int lro_bad_csum;
206         mxge_dma_t fw_stats_dma;
207         struct sysctl_oid *sysctl_tree;
208         struct sysctl_ctx_list sysctl_ctx;
209         char scratch[256];
210 };
211
212 struct mxge_softc {
213         struct arpcom arpcom;
214         struct ifnet* ifp;              /* points to arpcom.ac_if */
215         struct mxge_slice_state *ss;
216         int csum_flag;                  /* rx_csums?            */
217         int tx_boundary;                /* boundary transmits cannot cross*/
218         int lro_cnt;
219         bus_dma_tag_t   parent_dmat;
220         volatile uint8_t *sram;
221         int sram_size;
222         volatile uint32_t *irq_deassert;
223         mcp_cmd_response_t *cmd;
224         mxge_dma_t cmd_dma;
225         mxge_dma_t zeropad_dma;
226         struct pci_dev *pdev;
227         int legacy_irq;
228         int link_state;
229         unsigned int rdma_tags_available;
230         int intr_coal_delay;
231         volatile uint32_t *intr_coal_delay_ptr;
232         int wc;
233         int wake_queue;
234         int stop_queue;
235         int down_cnt;
236         int watchdog_resets;
237         int watchdog_countdown;
238         int pause;
239         struct resource *mem_res;
240         struct resource *irq_res;
241         struct resource **msix_irq_res;
242         struct resource *msix_table_res;
243         struct resource *msix_pba_res;
244         void *ih; 
245         void **msix_ih;
246         char *fw_name;
247         char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
248         char fw_version[128];
249         int fw_ver_major;
250         int fw_ver_minor;
251         int fw_ver_tiny;
252         int adopted_rx_filter_bug;
253         device_t dev;
254         struct ifmedia media;
255         int read_dma;
256         int write_dma;
257         int read_write_dma;
258         int fw_multicast_support;
259         int link_width;
260         int max_mtu;
261         int tx_defrag;
262         int media_flags;
263         int need_media_probe;
264         int num_slices;
265         int rx_ring_size;
266         int dying;
267         mxge_dma_t dmabench_dma;
268         struct callout co_hdl;
269         struct sysctl_ctx_list sysctl_ctx;
270         struct sysctl_oid *sysctl_tree;
271         struct sysctl_oid *slice_sysctl_tree;
272         struct sysctl_ctx_list slice_sysctl_ctx;
273         char *mac_addr_string;
274         uint8_t mac_addr[6];            /* eeprom mac address */
275         char product_code_string[64];
276         char serial_number_string[64];
277 };
278
279 #define MXGE_PCI_VENDOR_MYRICOM         0x14c1
280 #define MXGE_PCI_DEVICE_Z8E     0x0008
281 #define MXGE_PCI_DEVICE_Z8E_9   0x0009
282 #define MXGE_PCI_REV_Z8E        0
283 #define MXGE_PCI_REV_Z8ES       1
284 #define MXGE_XFP_COMPLIANCE_BYTE        131
285 #define MXGE_SFP_COMPLIANCE_BYTE          3
286
287 #define MXGE_HIGHPART_TO_U32(X) \
288 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
289 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
290
291 struct mxge_media_type
292 {
293         int flag;
294         uint8_t bitmask;
295         char *name;
296 };
297
298 /* implement our own memory barriers, since bus_space_barrier
299    cannot handle write-combining regions */
300
301 #if __FreeBSD_version < 800053
302
303 #if defined (__GNUC__)
304   #if #cpu(i386) || defined __i386 || defined i386 || defined __i386__ || #cpu(x86_64) || defined __x86_64__
305     #define wmb()  __asm__ __volatile__ ("sfence;": : :"memory")
306   #elif #cpu(sparc64) || defined sparc64 || defined __sparcv9 
307     #define wmb()  __asm__ __volatile__ ("membar #MemIssue": : :"memory")
308   #elif #cpu(sparc) || defined sparc || defined __sparc__
309     #define wmb()  __asm__ __volatile__ ("stbar;": : :"memory")
310   #else
311     #define wmb()       /* XXX just to make this compile */
312   #endif
313 #else
314   #error "unknown compiler"
315 #endif
316
317 #endif
318
319 static inline void
320 mxge_pio_copy(volatile void *to_v, void *from_v, size_t size)
321 {
322   register volatile uintptr_t *to;
323   volatile uintptr_t *from;
324   size_t i;
325
326   to = (volatile uintptr_t *) to_v;
327   from = from_v;
328   for (i = (size / sizeof (uintptr_t)); i; i--) {
329           *to = *from;
330           to++;
331           from++;
332   }
333
334 }
335
336 void mxge_lro_flush(struct mxge_slice_state *ss, struct lro_entry *lro);
337 int mxge_lro_rx(struct mxge_slice_state *ss, struct mbuf *m_head,
338                 uint32_t csum);
339                 
340
341
342 /*
343   This file uses Myri10GE driver indentation.
344
345   Local Variables:
346   c-file-style:"linux"
347   tab-width:8
348   End:
349 */