]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/mxge/if_mxge_var.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / 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$
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 #ifndef VLAN_CAPABILITIES
50 #define VLAN_CAPABILITIES(ifp)
51 #define mxge_vlans_active(sc) (sc)->ifp->if_nvlans
52 #else
53 #define mxge_vlans_active(sc) (sc)->ifp->if_vlantrunk
54 #endif
55
56 #ifndef VLAN_TAG_VALUE
57 #define MXGE_NEW_VLAN_API
58 #endif
59
60 #ifndef IFCAP_LRO
61 #define IFCAP_LRO 0
62 #endif
63
64 #ifndef IFCAP_TSO
65 #define IFCAP_TSO 0
66 #endif
67  
68 #ifndef IFCAP_TSO4
69 #define IFCAP_TSO4 0
70 #endif
71
72 #ifndef CSUM_TSO
73 #define CSUM_TSO 0
74 #endif
75
76
77 typedef struct {
78         void *addr;
79         bus_addr_t bus_addr;
80         bus_dma_tag_t dmat;
81         bus_dmamap_t map;
82 } mxge_dma_t;
83
84
85 typedef struct {
86         mcp_slot_t *entry;
87         mxge_dma_t dma;
88         int cnt;
89         int idx;
90         int mask;
91 } mxge_rx_done_t;
92
93 typedef struct
94 {
95   uint32_t data0;
96   uint32_t data1;
97   uint32_t data2;
98 } mxge_cmd_t;
99
100 struct mxge_rx_buffer_state {
101         struct mbuf *m;
102         bus_dmamap_t map;
103 };
104
105 struct mxge_tx_buffer_state {
106         struct mbuf *m;
107         bus_dmamap_t map;
108         int flag;
109 };
110
111 typedef struct
112 {
113         volatile mcp_kreq_ether_recv_t *lanai;  /* lanai ptr for recv ring */
114         mcp_kreq_ether_recv_t *shadow;  /* host shadow of recv ring */
115         struct mxge_rx_buffer_state *info;
116         bus_dma_tag_t dmat;
117         bus_dmamap_t extra_map;
118         int cnt;
119         int nbufs;
120         int cl_size;
121         int alloc_fail;
122         int mask;                       /* number of rx slots -1 */
123 } mxge_rx_ring_t;
124
125 typedef struct
126 {
127         struct mtx mtx;
128         volatile mcp_kreq_ether_send_t *lanai;  /* lanai ptr for sendq  */
129         mcp_kreq_ether_send_t *req_list;        /* host shadow of sendq */
130         char *req_bytes;
131         bus_dma_segment_t *seg_list;
132         struct mxge_tx_buffer_state *info;
133         bus_dma_tag_t dmat;
134         int req;                        /* transmits submitted  */
135         int mask;                       /* number of transmit slots -1 */
136         int done;                       /* transmits completed  */
137         int pkt_done;                   /* packets completed */
138         int max_desc;                   /* max descriptors per xmit */
139         int stall;                      /* #times hw queue exhausted */
140         int wake;                       /* #times irq re-enabled xmit */
141         int watchdog_req;               /* cache of req */
142         int watchdog_done;              /* cache of done */
143         int watchdog_rx_pause;          /* cache of pause rq recvd */
144         int defrag;
145         char mtx_name[16];
146 } mxge_tx_ring_t;
147
148 struct lro_entry;
149 struct lro_entry
150 {
151         SLIST_ENTRY(lro_entry) next;
152         struct mbuf     *m_head;
153         struct mbuf     *m_tail;
154         int             timestamp;
155         struct ip       *ip;
156         uint32_t        tsval;
157         uint32_t        tsecr;
158         uint32_t        source_ip;
159         uint32_t        dest_ip;
160         uint32_t        next_seq;
161         uint32_t        ack_seq;
162         uint32_t        len;
163         uint32_t        data_csum;
164         uint16_t        window;
165         uint16_t        source_port;
166         uint16_t        dest_port;
167         uint16_t        append_cnt;
168         uint16_t        mss;
169         
170 };
171 SLIST_HEAD(lro_head, lro_entry);
172
173 struct mxge_softc;
174 typedef struct mxge_softc mxge_softc_t;
175
176 struct mxge_slice_state {
177         mxge_softc_t *sc;
178         mxge_tx_ring_t tx;              /* transmit ring        */
179         mxge_rx_ring_t rx_small;
180         mxge_rx_ring_t rx_big;
181         mxge_rx_done_t rx_done;
182         mcp_irq_data_t *fw_stats;
183         volatile uint32_t *irq_claim;
184         u_long ipackets;
185         struct lro_head lro_active;
186         struct lro_head lro_free;
187         int lro_queued;
188         int lro_flushed;
189         int lro_bad_csum;
190         mxge_dma_t fw_stats_dma;
191         struct sysctl_oid *sysctl_tree;
192         struct sysctl_ctx_list sysctl_ctx;
193         char scratch[256];
194 };
195
196 struct mxge_softc {
197         struct ifnet* ifp;
198         struct mxge_slice_state *ss;
199         int csum_flag;                  /* rx_csums?            */
200         int tx_boundary;                /* boundary transmits cannot cross*/
201         int lro_cnt;
202         bus_dma_tag_t   parent_dmat;
203         volatile uint8_t *sram;
204         int sram_size;
205         volatile uint32_t *irq_deassert;
206         mcp_cmd_response_t *cmd;
207         mxge_dma_t cmd_dma;
208         mxge_dma_t zeropad_dma;
209         struct pci_dev *pdev;
210         int legacy_irq;
211         int link_state;
212         unsigned int rdma_tags_available;
213         int intr_coal_delay;
214         volatile uint32_t *intr_coal_delay_ptr;
215         int wc;
216         struct mtx cmd_mtx;
217         struct mtx driver_mtx;
218         int wake_queue;
219         int stop_queue;
220         int down_cnt;
221         int watchdog_resets;
222         int watchdog_countdown;
223         int pause;
224         struct resource *mem_res;
225         struct resource *irq_res;
226         struct resource **msix_irq_res;
227         struct resource *msix_table_res;
228         struct resource *msix_pba_res;
229         void *ih; 
230         void **msix_ih;
231         char *fw_name;
232         char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
233         char fw_version[128];
234         int fw_ver_major;
235         int fw_ver_minor;
236         int fw_ver_tiny;
237         int adopted_rx_filter_bug;
238         device_t dev;
239         struct ifmedia media;
240         int read_dma;
241         int write_dma;
242         int read_write_dma;
243         int fw_multicast_support;
244         int link_width;
245         int max_mtu;
246         int tx_defrag;
247         int media_flags;
248         int need_media_probe;
249         int num_slices;
250         int rx_ring_size;
251         mxge_dma_t dmabench_dma;
252         struct callout co_hdl;
253         struct sysctl_oid *slice_sysctl_tree;
254         struct sysctl_ctx_list slice_sysctl_ctx;
255         char *mac_addr_string;
256         uint8_t mac_addr[6];            /* eeprom mac address */
257         char product_code_string[64];
258         char serial_number_string[64];
259         char cmd_mtx_name[16];
260         char driver_mtx_name[16];
261 };
262
263 #define MXGE_PCI_VENDOR_MYRICOM         0x14c1
264 #define MXGE_PCI_DEVICE_Z8E     0x0008
265 #define MXGE_PCI_DEVICE_Z8E_9   0x0009
266 #define MXGE_PCI_REV_Z8E        0
267 #define MXGE_PCI_REV_Z8ES       1
268 #define MXGE_XFP_COMPLIANCE_BYTE        131
269 #define MXGE_SFP_COMPLIANCE_BYTE          3
270
271 #define MXGE_HIGHPART_TO_U32(X) \
272 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
273 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
274
275 struct mxge_media_type
276 {
277         int flag;
278         uint8_t bitmask;
279         char *name;
280 };
281
282 /* implement our own memory barriers, since bus_space_barrier
283    cannot handle write-combining regions */
284
285 #if defined (__GNUC__)
286   #if #cpu(i386) || defined __i386 || defined i386 || defined __i386__ || #cpu(x86_64) || defined __x86_64__
287     #define mb()  __asm__ __volatile__ ("sfence;": : :"memory")
288   #elif #cpu(sparc64) || defined sparc64 || defined __sparcv9 
289     #define mb()  __asm__ __volatile__ ("membar #MemIssue": : :"memory")
290   #elif #cpu(sparc) || defined sparc || defined __sparc__
291     #define mb()  __asm__ __volatile__ ("stbar;": : :"memory")
292   #else
293     #define mb()        /* XXX just to make this compile */
294   #endif
295 #else
296   #error "unknown compiler"
297 #endif
298
299 static inline void
300 mxge_pio_copy(volatile void *to_v, void *from_v, size_t size)
301 {
302   register volatile uintptr_t *to;
303   volatile uintptr_t *from;
304   size_t i;
305
306   to = (volatile uintptr_t *) to_v;
307   from = from_v;
308   for (i = (size / sizeof (uintptr_t)); i; i--) {
309           *to = *from;
310           to++;
311           from++;
312   }
313
314 }
315
316 void mxge_lro_flush(struct mxge_slice_state *ss, struct lro_entry *lro);
317 int mxge_lro_rx(struct mxge_slice_state *ss, struct mbuf *m_head,
318                 uint32_t csum);
319                 
320
321
322 /*
323   This file uses Myri10GE driver indentation.
324
325   Local Variables:
326   c-file-style:"linux"
327   tab-width:8
328   End:
329 */