1 /*******************************************************************************
2
3 Copyright (c) 2006-2013, 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: stable/9/sys/dev/mxge/if_mxge_var.h 247795 2013-03-04 15:32:38Z gallatin $
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 IFCAP_TSO6
77 #define IFCAP_TSO6 0
78 #endif
79
80 #ifndef IFCAP_TXCSUM_IPV6
81 #define IFCAP_TXCSUM_IPV6 0
82 #endif
83
84 #ifndef IFCAP_RXCSUM_IPV6
85 #define IFCAP_RXCSUM_IPV6 0
86 #endif
87
88 #ifndef CSUM_TSO
89 #define CSUM_TSO 0
90 #endif
91
92 #ifndef CSUM_TCP_IPV6
93 #define CSUM_TCP_IPV6 0
94 #endif
95
96 #ifndef CSUM_UDP_IPV6
97 #define CSUM_UDP_IPV6 0
98 #endif
99
100 #ifndef CSUM_DELAY_DATA_IPV6
101 #define CSUM_DELAY_DATA_IPV6 0
102 #endif
103
104 typedef struct {
105 void *addr;
106 bus_addr_t bus_addr;
107 bus_dma_tag_t dmat;
108 bus_dmamap_t map;
109 } mxge_dma_t;
110
111
112 typedef struct {
113 mcp_slot_t *entry;
114 mxge_dma_t dma;
115 int cnt;
116 int idx;
117 int mask;
118 } mxge_rx_done_t;
119
120 typedef struct
121 {
122 uint32_t data0;
123 uint32_t data1;
124 uint32_t data2;
125 } mxge_cmd_t;
126
127 struct mxge_rx_buffer_state {
128 struct mbuf *m;
129 bus_dmamap_t map;
130 };
131
132 struct mxge_tx_buffer_state {
133 struct mbuf *m;
134 bus_dmamap_t map;
135 int flag;
136 };
137
138 typedef struct
139 {
140 volatile mcp_kreq_ether_recv_t *lanai; /* lanai ptr for recv ring */
141 mcp_kreq_ether_recv_t *shadow; /* host shadow of recv ring */
142 struct mxge_rx_buffer_state *info;
143 bus_dma_tag_t dmat;
144 bus_dmamap_t extra_map;
145 int cnt;
146 int nbufs;
147 int cl_size;
148 int alloc_fail;
149 int mask; /* number of rx slots -1 */
150 int mlen;
151 } mxge_rx_ring_t;
152
153 typedef struct
154 {
155 struct mtx mtx;
156 #ifdef IFNET_BUF_RING
157 struct buf_ring *br;
158 #endif
159 volatile mcp_kreq_ether_send_t *lanai; /* lanai ptr for sendq */
160 volatile uint32_t *send_go; /* doorbell for sendq */
161 volatile uint32_t *send_stop; /* doorbell for sendq */
162 mcp_kreq_ether_send_t *req_list; /* host shadow of sendq */
163 char *req_bytes;
164 bus_dma_segment_t *seg_list;
165 struct mxge_tx_buffer_state *info;
166 bus_dma_tag_t dmat;
167 int req; /* transmits submitted */
168 int mask; /* number of transmit slots -1 */
169 int done; /* transmits completed */
170 int pkt_done; /* packets completed */
171 int max_desc; /* max descriptors per xmit */
172 int queue_active; /* fw currently polling this queue*/
173 int activate;
174 int deactivate;
175 int stall; /* #times hw queue exhausted */
176 int wake; /* #times irq re-enabled xmit */
177 int watchdog_req; /* cache of req */
178 int watchdog_done; /* cache of done */
179 int watchdog_rx_pause; /* cache of pause rq recvd */
180 int defrag;
181 char mtx_name[16];
182 } mxge_tx_ring_t;
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_ctrl lc;
202 mxge_dma_t fw_stats_dma;
203 struct sysctl_oid *sysctl_tree;
204 struct sysctl_ctx_list sysctl_ctx;
205 char scratch[256];
206 };
207
208 struct mxge_softc {
209 struct ifnet* ifp;
210 struct mxge_slice_state *ss;
211 int tx_boundary; /* boundary transmits cannot cross*/
212 int lro_cnt;
213 bus_dma_tag_t parent_dmat;
214 volatile uint8_t *sram;
215 int sram_size;
216 volatile uint32_t *irq_deassert;
217 mcp_cmd_response_t *cmd;
218 mxge_dma_t cmd_dma;
219 mxge_dma_t zeropad_dma;
220 struct pci_dev *pdev;
221 int legacy_irq;
222 int link_state;
223 unsigned int rdma_tags_available;
224 int intr_coal_delay;
225 volatile uint32_t *intr_coal_delay_ptr;
226 int wc;
227 struct mtx cmd_mtx;
228 struct mtx driver_mtx;
229 int wake_queue;
230 int stop_queue;
231 int down_cnt;
232 int watchdog_resets;
233 int watchdog_countdown;
234 int pause;
235 struct resource *mem_res;
236 struct resource *irq_res;
237 struct resource **msix_irq_res;
238 struct resource *msix_table_res;
239 struct resource *msix_pba_res;
240 void *ih;
241 void **msix_ih;
242 char *fw_name;
243 char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
244 char fw_version[128];
245 int fw_ver_major;
246 int fw_ver_minor;
247 int fw_ver_tiny;
248 int adopted_rx_filter_bug;
249 device_t dev;
250 struct ifmedia media;
251 int read_dma;
252 int write_dma;
253 int read_write_dma;
254 int fw_multicast_support;
255 int link_width;
256 int max_mtu;
257 int throttle;
258 int tx_defrag;
259 int media_flags;
260 int need_media_probe;
261 int num_slices;
262 int rx_ring_size;
263 int dying;
264 int connector;
265 int current_media;
266 int max_tso6_hlen;
267 mxge_dma_t dmabench_dma;
268 struct callout co_hdl;
269 struct taskqueue *tq;
270 struct task watchdog_task;
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 uint16_t pectl; /* save PCIe CTL state */
276 char product_code_string[64];
277 char serial_number_string[64];
278 char cmd_mtx_name[16];
279 char driver_mtx_name[16];
280 };
281
282 #define MXGE_PCI_VENDOR_MYRICOM 0x14c1
283 #define MXGE_PCI_DEVICE_Z8E 0x0008
284 #define MXGE_PCI_DEVICE_Z8E_9 0x0009
285 #define MXGE_PCI_REV_Z8E 0
286 #define MXGE_PCI_REV_Z8ES 1
287 #define MXGE_XFP_COMPLIANCE_BYTE 131
288 #define MXGE_SFP_COMPLIANCE_BYTE 3
289 #define MXGE_MIN_THROTTLE 416
290 #define MXGE_MAX_THROTTLE 4096
291
292 /* Types of connectors on NICs supported by this driver */
293 #define MXGE_CX4 0
294 #define MXGE_XFP 1
295 #define MXGE_SFP 2
296 #define MXGE_QRF 3
297
298 #define MXGE_HIGHPART_TO_U32(X) \
299 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
300 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
301
302 struct mxge_media_type
303 {
304 int flag;
305 uint8_t bitmask;
306 char *name;
307 };
308
309 struct mxge_pkt_info {
310 int ip_off;
311 int ip_hlen;
312 struct ip *ip;
313 struct ip6_hdr *ip6;
314 struct tcphdr *tcp;
315 };
316
317
318 /* implement our own memory barriers, since bus_space_barrier
319 cannot handle write-combining regions */
320
321 #if __FreeBSD_version < 800053
322
323 #if defined (__GNUC__)
324 #if #cpu(i386) || defined __i386 || defined i386 || defined __i386__ || #cpu(x86_64) || defined __x86_64__
325 #define wmb() __asm__ __volatile__ ("sfence;": : :"memory")
326 #elif #cpu(sparc64) || defined sparc64 || defined __sparcv9
327 #define wmb() __asm__ __volatile__ ("membar #MemIssue": : :"memory")
328 #elif #cpu(sparc) || defined sparc || defined __sparc__
329 #define wmb() __asm__ __volatile__ ("stbar;": : :"memory")
330 #else
331 #define wmb() /* XXX just to make this compile */
332 #endif
333 #else
334 #error "unknown compiler"
335 #endif
336
337 #endif
338
339 static inline void
mxge_pio_copy(volatile void * to_v,void * from_v,size_t size)340 mxge_pio_copy(volatile void *to_v, void *from_v, size_t size)
341 {
342 register volatile uintptr_t *to;
343 volatile uintptr_t *from;
344 size_t i;
345
346 to = (volatile uintptr_t *) to_v;
347 from = from_v;
348 for (i = (size / sizeof (uintptr_t)); i; i--) {
349 *to = *from;
350 to++;
351 from++;
352 }
353
354 }
355
356 void mxge_lro_flush(struct mxge_slice_state *ss, struct lro_entry *lro);
357 int mxge_lro_rx(struct mxge_slice_state *ss, struct mbuf *m_head,
358 uint32_t csum);
359
360
361
362 /*
363 This file uses Myri10GE driver indentation.
364
365 Local Variables:
366 c-file-style:"linux"
367 tab-width:8
368 End:
369 */
370