xref: /freebsd-13-stable/sys/dev/mxge/if_mxge_var.h (revision 27096e41f03f81fd6622e45ec3a91268f0eacdc8)
1 /*******************************************************************************
2 SPDX-License-Identifier: BSD-2-Clause
3 
4 Copyright (c) 2006-2013, Myricom Inc.
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10  1. Redistributions of source code must retain the above copyright notice,
11     this list of conditions and the following disclaimer.
12 
13  2. Neither the name of the Myricom Inc, nor the names of its
14     contributors may be used to endorse or promote products derived from
15     this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28 
29 ***************************************************************************/
30 
31 #define MXGE_ETH_STOPPED 0
32 #define MXGE_ETH_STOPPING 1
33 #define MXGE_ETH_STARTING 2
34 #define MXGE_ETH_RUNNING 3
35 #define MXGE_ETH_OPEN_FAILED 4
36 
37 #define MXGE_FW_OFFSET 1024*1024
38 #define MXGE_EEPROM_STRINGS_SIZE 256
39 #define MXGE_MAX_SEND_DESC 128
40 
41 #if ((__FreeBSD_version > 800000 && __FreeBSD_version < 800005) \
42      || __FreeBSD_version < 700111)
43 #define MXGE_VIRT_JUMBOS 1
44 #else
45 #define MXGE_VIRT_JUMBOS 0
46 #endif
47 
48 #if (__FreeBSD_version > 800082)
49 #define IFNET_BUF_RING 1
50 #endif
51 
52 #if (__FreeBSD_version < 1000020)
53 #undef IF_Kbps
54 #undef IF_Mbps
55 #undef IF_Gbps
56 #define	IF_Kbps(x)	((uintmax_t)(x) * 1000)	/* kilobits/sec. */
57 #define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
58 #define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */
59 #endif
60 
61 #ifndef VLAN_CAPABILITIES
62 #define VLAN_CAPABILITIES(ifp)
63 #define mxge_vlans_active(sc) (sc)->ifp->if_nvlans
64 #else
65 #define mxge_vlans_active(sc) (sc)->ifp->if_vlantrunk
66 #endif
67 
68 #ifndef VLAN_TAG_VALUE
69 #define MXGE_NEW_VLAN_API
70 #endif
71 
72 #ifndef IFCAP_LRO
73 #define IFCAP_LRO 0
74 #endif
75 
76 #ifndef IFCAP_TSO
77 #define IFCAP_TSO 0
78 #endif
79 
80 #ifndef IFCAP_TSO4
81 #define IFCAP_TSO4 0
82 #endif
83 
84 #ifndef IFCAP_TSO6
85 #define IFCAP_TSO6 0
86 #endif
87 
88 #ifndef IFCAP_TXCSUM_IPV6
89 #define IFCAP_TXCSUM_IPV6 0
90 #endif
91 
92 #ifndef IFCAP_RXCSUM_IPV6
93 #define IFCAP_RXCSUM_IPV6 0
94 #endif
95 
96 #ifndef CSUM_TSO
97 #define CSUM_TSO 0
98 #endif
99 
100 #ifndef CSUM_TCP_IPV6
101 #define CSUM_TCP_IPV6 0
102 #endif
103 
104 #ifndef CSUM_UDP_IPV6
105 #define CSUM_UDP_IPV6 0
106 #endif
107 
108 #ifndef CSUM_DELAY_DATA_IPV6
109 #define CSUM_DELAY_DATA_IPV6 0
110 #endif
111 
112 typedef struct {
113 	void *addr;
114 	bus_addr_t bus_addr;
115 	bus_dma_tag_t dmat;
116 	bus_dmamap_t map;
117 } mxge_dma_t;
118 
119 typedef struct {
120 	mcp_slot_t *entry;
121 	mxge_dma_t dma;
122 	int cnt;
123 	int idx;
124 	int mask;
125 } mxge_rx_done_t;
126 
127 typedef struct
128 {
129   uint32_t data0;
130   uint32_t data1;
131   uint32_t data2;
132 } mxge_cmd_t;
133 
134 struct mxge_rx_buffer_state {
135 	struct mbuf *m;
136 	bus_dmamap_t map;
137 };
138 
139 struct mxge_tx_buffer_state {
140 	struct mbuf *m;
141 	bus_dmamap_t map;
142 	int flag;
143 };
144 
145 typedef struct
146 {
147 	volatile mcp_kreq_ether_recv_t *lanai;	/* lanai ptr for recv ring */
148 	mcp_kreq_ether_recv_t *shadow;	/* host shadow of recv ring */
149 	struct mxge_rx_buffer_state *info;
150 	bus_dma_tag_t dmat;
151 	bus_dmamap_t extra_map;
152 	int cnt;
153 	int nbufs;
154 	int cl_size;
155 	int alloc_fail;
156 	int mask;			/* number of rx slots -1 */
157 	int mlen;
158 } mxge_rx_ring_t;
159 
160 typedef struct
161 {
162 	struct mtx mtx;
163 #ifdef IFNET_BUF_RING
164 	struct buf_ring *br;
165 #endif
166 	volatile mcp_kreq_ether_send_t *lanai;	/* lanai ptr for sendq	*/
167 	volatile uint32_t *send_go;		/* doorbell for sendq */
168 	volatile uint32_t *send_stop;		/* doorbell for sendq */
169 	mcp_kreq_ether_send_t *req_list;	/* host shadow of sendq */
170 	char *req_bytes;
171 	bus_dma_segment_t *seg_list;
172 	struct mxge_tx_buffer_state *info;
173 	bus_dma_tag_t dmat;
174 	int req;			/* transmits submitted	*/
175 	int mask;			/* number of transmit slots -1 */
176 	int done;			/* transmits completed	*/
177 	int pkt_done;			/* packets completed */
178 	int max_desc;			/* max descriptors per xmit */
179 	int queue_active;		/* fw currently polling this queue*/
180 	int activate;
181 	int deactivate;
182 	int stall;			/* #times hw queue exhausted */
183 	int wake;			/* #times irq re-enabled xmit */
184 	int watchdog_req;		/* cache of req */
185 	int watchdog_done;		/* cache of done */
186 	int watchdog_rx_pause;		/* cache of pause rq recvd */
187 	int defrag;
188 	char mtx_name[16];
189 } mxge_tx_ring_t;
190 
191 struct mxge_softc;
192 typedef struct mxge_softc mxge_softc_t;
193 
194 struct mxge_slice_state {
195 	mxge_softc_t *sc;
196 	mxge_tx_ring_t tx;		/* transmit ring 	*/
197 	mxge_rx_ring_t rx_small;
198 	mxge_rx_ring_t rx_big;
199 	mxge_rx_done_t rx_done;
200 	mcp_irq_data_t *fw_stats;
201 	volatile uint32_t *irq_claim;
202 	u_long ipackets;
203 	u_long opackets;
204 	u_long obytes;
205 	u_long omcasts;
206 	u_long oerrors;
207 	int if_drv_flags;
208 	struct lro_ctrl lc;
209 	mxge_dma_t fw_stats_dma;
210 	struct sysctl_oid *sysctl_tree;
211 	struct sysctl_ctx_list sysctl_ctx;
212 	char scratch[256];
213 };
214 
215 struct mxge_softc {
216 	struct ifnet* ifp;
217 	struct mxge_slice_state *ss;
218 	int tx_boundary;		/* boundary transmits cannot cross*/
219 	int lro_cnt;
220 	bus_dma_tag_t	parent_dmat;
221 	volatile uint8_t *sram;
222 	int sram_size;
223 	volatile uint32_t *irq_deassert;
224 	mcp_cmd_response_t *cmd;
225 	mxge_dma_t cmd_dma;
226 	mxge_dma_t zeropad_dma;
227 	struct pci_dev *pdev;
228 	int legacy_irq;
229 	int link_state;
230 	unsigned int rdma_tags_available;
231 	int intr_coal_delay;
232 	volatile uint32_t *intr_coal_delay_ptr;
233 	int wc;
234 	struct mtx cmd_mtx;
235 	struct mtx driver_mtx;
236 	int wake_queue;
237 	int stop_queue;
238 	int down_cnt;
239 	int watchdog_resets;
240 	int watchdog_countdown;
241 	int pause;
242 	struct resource *mem_res;
243 	struct resource *irq_res;
244 	struct resource **msix_irq_res;
245 	struct resource *msix_table_res;
246 	struct resource *msix_pba_res;
247 	void *ih;
248 	void **msix_ih;
249 	char *fw_name;
250 	char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
251 	char fw_version[128];
252 	int fw_ver_major;
253 	int fw_ver_minor;
254 	int fw_ver_tiny;
255 	int adopted_rx_filter_bug;
256 	device_t dev;
257 	struct ifmedia media;
258 	int read_dma;
259 	int write_dma;
260 	int read_write_dma;
261 	int fw_multicast_support;
262 	int link_width;
263 	int max_mtu;
264 	int throttle;
265 	int tx_defrag;
266 	int media_flags;
267 	int need_media_probe;
268 	int num_slices;
269 	int rx_ring_size;
270 	int dying;
271 	int connector;
272 	int current_media;
273 	int max_tso6_hlen;
274 	mxge_dma_t dmabench_dma;
275 	struct callout co_hdl;
276 	struct taskqueue *tq;
277 	struct task watchdog_task;
278 	struct sysctl_oid *slice_sysctl_tree;
279 	struct sysctl_ctx_list slice_sysctl_ctx;
280 	char *mac_addr_string;
281 	uint8_t	mac_addr[6];		/* eeprom mac address */
282 	uint16_t pectl;			/* save PCIe CTL state */
283 	char product_code_string[64];
284 	char serial_number_string[64];
285 	char cmd_mtx_name[16];
286 	char driver_mtx_name[16];
287 };
288 
289 #define MXGE_PCI_VENDOR_MYRICOM 	0x14c1
290 #define MXGE_PCI_DEVICE_Z8E 	0x0008
291 #define MXGE_PCI_DEVICE_Z8E_9 	0x0009
292 #define MXGE_PCI_REV_Z8E	0
293 #define MXGE_PCI_REV_Z8ES	1
294 #define MXGE_XFP_COMPLIANCE_BYTE	131
295 #define MXGE_SFP_COMPLIANCE_BYTE	  3
296 #define MXGE_MIN_THROTTLE	416
297 #define MXGE_MAX_THROTTLE	4096
298 
299 /* Types of connectors on NICs supported by this driver */
300 #define MXGE_CX4 0
301 #define MXGE_XFP 1
302 #define MXGE_SFP 2
303 #define MXGE_QRF 3
304 
305 #define MXGE_HIGHPART_TO_U32(X) \
306 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
307 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
308 
309 struct mxge_media_type
310 {
311 	int flag;
312 	uint8_t bitmask;
313 	char *name;
314 };
315 
316 struct mxge_pkt_info {
317 	int ip_off;
318 	int ip_hlen;
319 	struct ip *ip;
320 	struct ip6_hdr *ip6;
321 	struct tcphdr *tcp;
322 };
323 
324 static inline void
mxge_pio_copy(volatile void * to_v,void * from_v,size_t size)325 mxge_pio_copy(volatile void *to_v, void *from_v, size_t size)
326 {
327   register volatile uintptr_t *to;
328   volatile uintptr_t *from;
329   size_t i;
330 
331   to = (volatile uintptr_t *) to_v;
332   from = from_v;
333   for (i = (size / sizeof (uintptr_t)); i; i--) {
334 	  *to = *from;
335 	  to++;
336 	  from++;
337   }
338 
339 }
340 
341 void mxge_lro_flush(struct mxge_slice_state *ss, struct lro_entry *lro);
342 int mxge_lro_rx(struct mxge_slice_state *ss, struct mbuf *m_head,
343 		uint32_t csum);
344 
345 
346 /*
347   This file uses Myri10GE driver indentation.
348 
349   Local Variables:
350   c-file-style:"linux"
351   tab-width:8
352   End:
353 */
354