mxge: Limit MTU to ~4K
[dragonfly.git] / sys / dev / netif / mxge / if_mxge_var.h
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: head/sys/dev/mxge/if_mxge_var.h 247160 2013-02-22 19:23:33Z 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 #define MXGE_INTR_COAL_DELAY            150
43
44 typedef struct {
45         mcp_slot_t *entry;
46         bus_dmamem_t dma;
47         int cnt;
48         int idx;
49         int mask;
50 } mxge_rx_done_t;
51
52 typedef struct {
53         uint32_t data0;
54         uint32_t data1;
55         uint32_t data2;
56 } mxge_cmd_t;
57
58 struct mxge_rx_buffer_state {
59         struct mbuf *m;
60         bus_dmamap_t map;
61 };
62
63 struct mxge_tx_buffer_state {
64         struct mbuf *m;
65         bus_dmamap_t map;
66         int flag;
67 };
68
69 typedef struct {
70         volatile mcp_kreq_ether_recv_t *lanai;  /* lanai ptr for recv ring */
71         mcp_kreq_ether_recv_t *shadow;  /* host shadow of recv ring */
72         struct mxge_rx_buffer_state *info;
73         bus_dma_tag_t dmat;
74         bus_dmamap_t extra_map;
75         int cnt;
76         int cl_size;
77         int alloc_fail;
78         int mask;                       /* number of rx slots -1 */
79         int mlen;
80 } mxge_rx_ring_t;
81
82 typedef struct {
83 #ifdef IFNET_BUF_RING
84         struct buf_ring *br;
85 #endif
86         volatile mcp_kreq_ether_send_t *lanai;  /* lanai ptr for sendq  */
87         volatile uint32_t *send_go;             /* doorbell for sendq */
88         volatile uint32_t *send_stop;           /* doorbell for sendq */
89         mcp_kreq_ether_send_t *req_list;        /* host shadow of sendq */
90         char *req_bytes;
91         bus_dma_segment_t *seg_list;
92         struct mxge_tx_buffer_state *info;
93         bus_dma_tag_t dmat;
94         int req;                        /* transmits submitted  */
95         int mask;                       /* number of transmit slots -1 */
96         int done;                       /* transmits completed  */
97         int pkt_done;                   /* packets completed */
98         int max_desc;                   /* max descriptors per xmit */
99         int queue_active;               /* fw currently polling this queue*/
100         int activate;
101         int deactivate;
102         int stall;                      /* #times hw queue exhausted */
103         int wake;                       /* #times irq re-enabled xmit */
104         int watchdog_req;               /* cache of req */
105         int watchdog_done;              /* cache of done */
106         int watchdog_rx_pause;          /* cache of pause rq recvd */
107         int defrag;
108 } mxge_tx_ring_t;
109
110 struct mxge_softc;
111 typedef struct mxge_softc mxge_softc_t;
112
113 struct mxge_slice_state {
114         mxge_softc_t *sc;
115         mxge_tx_ring_t tx;              /* transmit ring */
116         mxge_rx_ring_t rx_small;
117         mxge_rx_ring_t rx_big;
118         mxge_rx_done_t rx_done;
119         mcp_irq_data_t *fw_stats;
120         volatile uint32_t *irq_claim;
121         u_long ipackets;
122         u_long opackets;
123         u_long obytes;
124         u_long omcasts;
125         u_long oerrors;
126         int if_drv_flags;
127         bus_dmamem_t fw_stats_dma;
128         struct sysctl_oid *sysctl_tree;
129         struct sysctl_ctx_list sysctl_ctx;
130         char scratch[256];
131 };
132
133 struct mxge_softc {
134         struct arpcom arpcom;
135         struct ifnet* ifp;              /* points to arpcom.ac_if */
136         struct mxge_slice_state *ss;
137         int tx_boundary;                /* boundary transmits cannot cross*/
138         bus_dma_tag_t   parent_dmat;
139         volatile uint8_t *sram;
140         int sram_size;
141         volatile uint32_t *irq_deassert;
142         mcp_cmd_response_t *cmd;
143         bus_dmamem_t cmd_dma;
144         bus_dmamem_t zeropad_dma;
145         struct pci_dev *pdev;
146         int irq_rid;
147         int irq_type;
148         int link_state;
149         unsigned int rdma_tags_available;
150         int intr_coal_delay;
151         volatile uint32_t *intr_coal_delay_ptr;
152         int wc;
153         int wake_queue;
154         int stop_queue;
155         int down_cnt;
156         int watchdog_resets;
157         int watchdog_countdown;
158         int pause;
159         struct resource *mem_res;
160         struct resource *irq_res;
161         struct resource **msix_irq_res;
162         struct resource *msix_table_res;
163         struct resource *msix_pba_res;
164         void *ih; 
165         void **msix_ih;
166         char *fw_name;
167         char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
168         char fw_version[128];
169         int fw_ver_major;
170         int fw_ver_minor;
171         int fw_ver_tiny;
172         int adopted_rx_filter_bug;
173         device_t dev;
174         struct ifmedia media;
175         int read_dma;
176         int write_dma;
177         int read_write_dma;
178         int fw_multicast_support;
179         int link_width;
180         int max_mtu;
181         int throttle;
182         int tx_defrag;
183         int media_flags;
184         int need_media_probe;
185         int num_slices;
186         int rx_ring_size;
187         int dying;
188         int connector;
189         int current_media;
190         bus_dmamem_t dmabench_dma;
191         struct callout co_hdl;
192         struct sysctl_ctx_list sysctl_ctx;
193         struct sysctl_oid *sysctl_tree;
194         struct sysctl_oid *slice_sysctl_tree;
195         struct sysctl_ctx_list slice_sysctl_ctx;
196         char *mac_addr_string;
197         uint8_t mac_addr[6];            /* eeprom mac address */
198         uint16_t pectl;                 /* save PCIe CTL state */
199         char product_code_string[64];
200         char serial_number_string[64];
201 };
202
203 #define MXGE_PCI_VENDOR_MYRICOM         0x14c1
204 #define MXGE_PCI_DEVICE_Z8E             0x0008
205 #define MXGE_PCI_DEVICE_Z8E_9           0x0009
206 #define MXGE_PCI_REV_Z8E                0
207 #define MXGE_PCI_REV_Z8ES               1
208
209 #define MXGE_XFP_COMPLIANCE_BYTE        131
210 #define MXGE_SFP_COMPLIANCE_BYTE        3
211
212 #define MXGE_MIN_THROTTLE               416
213 #define MXGE_MAX_THROTTLE               4096
214
215 /* Types of connectors on NICs supported by this driver */
216 #define MXGE_CX4 0
217 #define MXGE_XFP 1
218 #define MXGE_SFP 2
219 #define MXGE_QRF 3
220
221 #define MXGE_HIGHPART_TO_U32(X) \
222         (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
223 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
224
225 struct mxge_media_type {
226         int flag;
227         uint8_t bitmask;
228         char *name;
229 };
230
231 #if defined(__GNUC__)
232 #if defined(__i386__) || defined(__x86_64__)
233 #define wmb()  __asm__ __volatile__ ("sfence;": : :"memory")
234 #else
235 #error "unknown arch"
236 #endif
237 #else
238 #error "unknown compiler"
239 #endif
240
241 static __inline void
242 mxge_pio_copy(volatile void *to_v, void *from_v, size_t size)
243 {
244         register volatile uintptr_t *to;
245         volatile uintptr_t *from;
246         size_t i;
247
248         to = (volatile uintptr_t *)to_v;
249         from = from_v;
250         for (i = (size / sizeof(uintptr_t)); i; i--) {
251                 *to = *from;
252                 to++;
253                 from++;
254         }
255 }