xref: /freebsd/sys/dev/mxge/if_mxge_var.h (revision 35a04710d7286aa9538917fd7f8e417dbee95b82)
1 /*******************************************************************************
2 
3 Copyright (c) 2006-2007, 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 typedef struct {
43 	void *addr;
44 	bus_addr_t bus_addr;
45 	bus_dma_tag_t dmat;
46 	bus_dmamap_t map;
47 } mxge_dma_t;
48 
49 
50 typedef struct {
51 	mcp_slot_t *entry;
52 	mxge_dma_t dma;
53 	int cnt;
54 	int idx;
55 	int mask;
56 } mxge_rx_done_t;
57 
58 typedef struct
59 {
60   uint32_t data0;
61   uint32_t data1;
62   uint32_t data2;
63 } mxge_cmd_t;
64 
65 struct mxge_rx_buffer_state {
66 	struct mbuf *m;
67 	bus_dmamap_t map;
68 };
69 
70 struct mxge_tx_buffer_state {
71 	struct mbuf *m;
72 	bus_dmamap_t map;
73 	int flag;
74 };
75 
76 typedef struct
77 {
78 	volatile mcp_kreq_ether_recv_t *lanai;	/* lanai ptr for recv ring */
79 	mcp_kreq_ether_recv_t *shadow;	/* host shadow of recv ring */
80 	struct mxge_rx_buffer_state *info;
81 	bus_dma_tag_t dmat;
82 	bus_dmamap_t extra_map;
83 	int cnt;
84 	int nbufs;
85 	int cl_size;
86 	int alloc_fail;
87 	int mask;			/* number of rx slots -1 */
88 } mxge_rx_buf_t;
89 
90 typedef struct
91 {
92 	volatile mcp_kreq_ether_send_t *lanai;	/* lanai ptr for sendq	*/
93 	mcp_kreq_ether_send_t *req_list;	/* host shadow of sendq */
94 	char *req_bytes;
95 	bus_dma_segment_t *seg_list;
96 	struct mxge_tx_buffer_state *info;
97 	bus_dma_tag_t dmat;
98 	int req;			/* transmits submitted	*/
99 	int mask;			/* number of transmit slots -1 */
100 	int done;			/* transmits completed	*/
101 	int pkt_done;			/* packets completed */
102 	int boundary;			/* boundary transmits cannot cross*/
103 	int max_desc;			/* max descriptors per xmit */
104 	int stall;			/* #times hw queue exhausted */
105 	int wake;			/* #times irq re-enabled xmit */
106 	int watchdog_req;		/* cache of req */
107 	int watchdog_done;		/* cache of done */
108 	int watchdog_rx_pause;		/* cache of pause rq recvd */
109 } mxge_tx_buf_t;
110 
111 struct lro_entry;
112 struct lro_entry
113 {
114 	SLIST_ENTRY(lro_entry) next;
115 	struct mbuf  	*m_head;
116 	struct mbuf	*m_tail;
117 	int		timestamp;
118 	struct ip	*ip;
119 	uint32_t	tsval;
120 	uint32_t	tsecr;
121 	uint32_t	source_ip;
122 	uint32_t	dest_ip;
123 	uint32_t	next_seq;
124 	uint32_t	ack_seq;
125 	uint32_t	len;
126 	uint32_t	data_csum;
127 	uint16_t	window;
128 	uint16_t	source_port;
129 	uint16_t	dest_port;
130 	uint16_t	append_cnt;
131 	uint16_t	mss;
132 
133 };
134 SLIST_HEAD(lro_head, lro_entry);
135 
136 typedef struct {
137 	struct ifnet* ifp;
138 	struct mtx tx_mtx;
139 	int csum_flag;			/* rx_csums? 		*/
140 	mxge_tx_buf_t tx;		/* transmit ring 	*/
141 	mxge_rx_buf_t rx_small;
142 	mxge_rx_buf_t rx_big;
143 	mxge_rx_done_t rx_done;
144 	mcp_irq_data_t *fw_stats;
145 	bus_dma_tag_t	parent_dmat;
146 	volatile uint8_t *sram;
147 	struct lro_head lro_active;
148 	struct lro_head lro_free;
149 	int lro_queued;
150 	int lro_flushed;
151 	int lro_bad_csum;
152 	int lro_cnt;
153 	int sram_size;
154 	volatile uint32_t *irq_deassert;
155 	volatile uint32_t *irq_claim;
156 	mcp_cmd_response_t *cmd;
157 	mxge_dma_t cmd_dma;
158 	mxge_dma_t zeropad_dma;
159 	mxge_dma_t fw_stats_dma;
160 	struct pci_dev *pdev;
161 	int msi_enabled;
162 	int link_state;
163 	unsigned int rdma_tags_available;
164 	int intr_coal_delay;
165 	volatile uint32_t *intr_coal_delay_ptr;
166 	int wc;
167 	struct mtx cmd_mtx;
168 	struct mtx driver_mtx;
169 	int wake_queue;
170 	int stop_queue;
171 	int down_cnt;
172 	int watchdog_resets;
173 	int tx_defragged;
174 	int pause;
175 	struct resource *mem_res;
176 	struct resource *irq_res;
177 	void *ih;
178 	char *fw_name;
179 	char eeprom_strings[MXGE_EEPROM_STRINGS_SIZE];
180 	char fw_version[128];
181 	int fw_ver_major;
182 	int fw_ver_minor;
183 	int fw_ver_tiny;
184 	int adopted_rx_filter_bug;
185 	device_t dev;
186 	struct ifmedia media;
187 	int read_dma;
188 	int write_dma;
189 	int read_write_dma;
190 	int fw_multicast_support;
191 	int link_width;
192 	int max_mtu;
193 	int tx_defrag;
194 	int media_flags;
195 	int need_media_probe;
196 	mxge_dma_t dmabench_dma;
197 	struct callout co_hdl;
198 	char *mac_addr_string;
199 	uint8_t	mac_addr[6];		/* eeprom mac address */
200 	char product_code_string[64];
201 	char serial_number_string[64];
202 	char scratch[256];
203 	char tx_mtx_name[16];
204 	char cmd_mtx_name[16];
205 	char driver_mtx_name[16];
206 } mxge_softc_t;
207 
208 #define MXGE_PCI_VENDOR_MYRICOM 	0x14c1
209 #define MXGE_PCI_DEVICE_Z8E 	0x0008
210 #define MXGE_PCI_DEVICE_Z8E_9 	0x0009
211 #define MXGE_XFP_COMPLIANCE_BYTE	131
212 
213 #define MXGE_HIGHPART_TO_U32(X) \
214 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
215 #define MXGE_LOWPART_TO_U32(X) ((uint32_t)(X))
216 
217 struct mxge_media_type
218 {
219 	int flag;
220 	uint8_t bitmask;
221 	char *name;
222 };
223 
224 /* implement our own memory barriers, since bus_space_barrier
225    cannot handle write-combining regions */
226 
227 #if defined (__GNUC__)
228   #if #cpu(i386) || defined __i386 || defined i386 || defined __i386__ || #cpu(x86_64) || defined __x86_64__
229     #define mb()  __asm__ __volatile__ ("sfence;": : :"memory")
230   #elif #cpu(sparc64) || defined sparc64 || defined __sparcv9
231     #define mb()  __asm__ __volatile__ ("membar #MemIssue": : :"memory")
232   #elif #cpu(sparc) || defined sparc || defined __sparc__
233     #define mb()  __asm__ __volatile__ ("stbar;": : :"memory")
234   #else
235     #define mb() 	/* XXX just to make this compile */
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 
256 }
257 
258 void mxge_lro_flush(mxge_softc_t *mgp, struct lro_entry *lro);
259 int mxge_lro_rx(mxge_softc_t *mgp, struct mbuf *m_head, uint32_t csum);
260 
261 
262 
263 /*
264   This file uses Myri10GE driver indentation.
265 
266   Local Variables:
267   c-file-style:"linux"
268   tab-width:8
269   End:
270 */
271