xref: /illumos-gate/usr/src/uts/common/io/myri10ge/drv/myri10ge_var.h (revision 93a18d6d401e844455263f926578e9d2aa6b47ec)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007-2009 Myricom, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef MYRI10GE_VAR_H
28 #define	MYRI10GE_VAR_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/types.h>
35 #include <sys/errno.h>
36 #include <sys/param.h>
37 #include <sys/atomic.h>
38 #include <sys/stropts.h>
39 #include <sys/stream.h>
40 #include <sys/kmem.h>
41 #include <sys/ksynch.h>
42 #include <sys/stat.h>
43 #include <sys/modctl.h>
44 #include <sys/debug.h>
45 #include <sys/dlpi.h>
46 #include <sys/ethernet.h>
47 #include <sys/mac_provider.h>
48 #define	MAC_CAPAB_POLL 0
49 #define	MC_RESOURCES 0
50 #include <sys/mac_ether.h>
51 #ifndef MYRICOM_PRIV
52 #include <sys/vlan.h>
53 #endif
54 #include <sys/pci.h>
55 #include <sys/pcie.h>
56 #include <sys/ddi.h>
57 #include <sys/sunddi.h>
58 #include <sys/strsubr.h>  	/* for hw cksum stuff */
59 #include <sys/pattr.h>		/* for hw cksum stuff */
60 #ifdef MYRICOM_PRIV
61 #include <netinet/in.h>		/* for hw cksum stuff */
62 #endif
63 #include <netinet/ip.h>		/* for hw cksum stuff */
64 #include <netinet/ip6.h>	/* for hw cksum stuff */
65 #include <netinet/tcp.h>	/* for hw cksum stuff */
66 #include <netinet/udp.h>	/* for hw cksum stuff */
67 #include <sys/strsun.h>
68 #include <inet/common.h>
69 #include <inet/mi.h>
70 #include <inet/nd.h>
71 #include <sys/zmod.h>
72 #include <sys/cpuvar.h>
73 #include <sys/proc.h>
74 #include <sys/callb.h>
75 
76 #include "myri10ge_mcp.h"
77 #include "myri10ge_version.h"
78 
79 #define	MYRI10GE_FW_OFFSET 1024*1024
80 #define	MYRI10GE_EEPROM_STRINGS_SIZE 256
81 #define	MYRI10GE_HIGHPART_TO_U32(X) \
82 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
83 #define	MYRI10GE_LOWPART_TO_U32(X) ((uint32_t)(X))
84 
85 #define	MYRI10GE_DDI_REG_SET_32_BIT_MEMORY_SPACE 2
86 #define	MYRI10GE_DDI_REG_SET_64_BIT_MEMORY_SPACE 3
87 
88 /*
89  * Max descriptors a TSO send can use; worst case is every descriptor
90  * crosses a 2KB boundary, as do the headers
91  */
92 
93 #define	MYRI10GE_MAX_SEND_DESC_TSO (2 + (65536 / 2048) * 2)
94 
95 #ifdef MYRICOM_PRIV
96 #define	VLAN_TAGSZ 4
97 #endif
98 
99 #if defined DDI_INTR_IS_MSI_OR_MSIX
100 #define	MYRI10GE_USE_MSI 1
101 #else
102 #define	MYRI10GE_USE_MSI 0
103 #endif
104 
105 
106 struct myri10ge_dma_stuff {
107 	ddi_dma_handle_t handle;
108 	ddi_acc_handle_t acc_handle;
109 	uint32_t low;
110 	uint32_t high;
111 };
112 
113 typedef struct myri10ge_mblkq {
114 	struct myri10ge_priv *mgp;
115 	kmutex_t lock;
116 	mblk_t *head;
117 	mblk_t *tail;
118 	unsigned long cnt;
119 } myri10ge_mblkq_t;
120 
121 typedef struct {
122 	mcp_slot_t *entry;
123 	struct myri10ge_dma_stuff dma;
124 	int cnt;
125 	int idx;
126 } myri10ge_rx_done_t;
127 
128 
129 typedef struct
130 {
131 	uint32_t data0;
132 	uint32_t data1;
133 	uint32_t data2;
134 } myri10ge_cmd_t;
135 
136 struct myri10ge_pci_saved_state {
137 	uint32_t base[16];
138 	uint32_t msi_addr_low;
139 	uint32_t msi_addr_high;
140 	uint16_t msi_data_32;
141 	uint16_t msi_data_64;
142 	uint16_t msi_ctrl;
143 };
144 
145 struct myri10ge_jpool_entry;
146 
147 struct myri10ge_jpool_entry {
148 	struct myri10ge_jpool_entry *next;
149 	ddi_dma_handle_t dma_handle;
150 	ddi_acc_handle_t acc_handle;
151 	caddr_t buf;
152 	struct myri10ge_slice_state *ss;
153 	mcp_dma_addr_t dma;  /* Kept in network byte order */
154 	frtn_t free_func;
155 };
156 
157 #define	MYRI10GE_CPU_CACHE_SZ	64
158 struct myri10ge_per_cpu_jpool {
159 	struct myri10ge_jpool_entry *head;
160 	uint8_t _pad[MYRI10GE_CPU_CACHE_SZ - sizeof (void *)];
161 };
162 
163 #define	MYRI10GE_MAX_CPUS	64
164 #define	MYRI10GE_MAX_CPU_MASK	(64 - 1)
165 
166 struct myri10ge_jpool_stuff {
167 	struct myri10ge_jpool_entry *head;
168 	struct myri10ge_per_cpu_jpool cpu[MYRI10GE_MAX_CPUS];
169 	kmutex_t mtx;
170 	int num_alloc;
171 	int low_water;
172 };
173 
174 struct myri10ge_tx_ring_stats
175 {
176 	uint64_t multixmt;
177 	uint64_t brdcstxmt;
178 	uint64_t opackets;
179 	uint64_t obytes;
180 };
181 
182 struct myri10ge_rx_ring_stats
183 {
184 	uint64_t multircv;
185 	uint64_t brdcstrcv;
186 	uint64_t ipackets;
187 	uint64_t ibytes;
188 };
189 
190 struct myri10ge_tx_ring_entry_stats
191 {
192 	uint32_t  obytes;
193 	uint16_t  opackets;
194 	uint8_t	  brdcstxmt;
195 	uint8_t	  multixmt;
196 };
197 
198 struct myri10ge_tx_pkt_stats {
199 	union {
200 		uint64_t all;
201 		struct myri10ge_tx_ring_entry_stats s;
202 	} un;
203 };
204 
205 #define	ostat stat.un.s
206 
207 struct myri10ge_tx_dma_handle {
208 	struct myri10ge_tx_dma_handle *next;
209 	ddi_dma_handle_t h;
210 };
211 
212 struct myri10ge_tx_dma_handle_head {
213 	struct myri10ge_tx_dma_handle *head;
214 	struct myri10ge_tx_dma_handle *tail;
215 };
216 
217 struct myri10ge_rx_buffer_state {
218 	caddr_t ptr;
219 	struct myri10ge_jpool_entry *j;
220 };
221 
222 struct myri10ge_tx_buffer_state {
223 	mblk_t *m;
224 	struct myri10ge_tx_dma_handle *handle;
225 	struct myri10ge_tx_pkt_stats stat;
226 };
227 
228 struct myri10ge_nic_stat {
229 	struct kstat_named dma_force_physical;
230 	struct kstat_named dma_read_bw_MBs;
231 	struct kstat_named dma_write_bw_MBs;
232 	struct kstat_named dma_read_write_bw_MBs;
233 	struct kstat_named lanes;
234 	struct kstat_named dropped_bad_crc32;
235 	struct kstat_named dropped_bad_phy;
236 	struct kstat_named dropped_link_error_or_filtered;
237 	struct kstat_named dropped_link_overflow;
238 	struct kstat_named dropped_multicast_filtered;
239 	struct kstat_named dropped_no_big_buffer;
240 	struct kstat_named dropped_no_small_buffer;
241 	struct kstat_named dropped_overrun;
242 	struct kstat_named dropped_pause;
243 	struct kstat_named dropped_runt;
244 	struct kstat_named dropped_unicast_filtered;
245 	struct kstat_named link_changes;
246 	struct kstat_named link_up;
247 };
248 
249 struct myri10ge_slice_stat {
250 	struct kstat_named lro_bad_csum;
251 	struct kstat_named lro_flushed;
252 	struct kstat_named lro_queued;
253 	struct kstat_named rx_big;
254 	struct kstat_named rx_bigbuf_firmware;
255 	struct kstat_named rx_bigbuf_pool;
256 	struct kstat_named rx_bigbuf_smalls;
257 	struct kstat_named rx_copy;
258 	struct kstat_named rx_small;
259 	struct kstat_named rx_big_nobuf;
260 	struct kstat_named rx_small_nobuf;
261 	struct kstat_named tx_activate;
262 	struct kstat_named tx_done;
263 	struct kstat_named tx_handles_alloced;
264 	struct kstat_named tx_req;
265 	struct kstat_named xmit_err;
266 	struct kstat_named xmit_lowbuf;
267 	struct kstat_named xmit_lsobadflags;
268 	struct kstat_named xmit_pullup;
269 	struct kstat_named xmit_pullup_first;
270 	struct kstat_named xmit_sched;
271 	struct kstat_named xmit_stall;
272 	struct kstat_named xmit_stall_early;
273 	struct kstat_named xmit_stall_late;
274 	struct kstat_named xmit_zero_len;
275 };
276 
277 struct myri10ge_info {
278 	struct kstat_named driver_version;
279 	struct kstat_named firmware_version;
280 	struct kstat_named firmware_name;
281 	struct kstat_named interrupt_type;
282 	struct kstat_named product_code;
283 	struct kstat_named serial_number;
284 };
285 
286 
287 #define	MYRI10GE_NIC_STAT_INC(field)					\
288 (((struct myri10ge_nic_stat *)mgp->ksp_stat->ks_data)->field.value.ul)++
289 #define	MYRI10GE_SLICE_STAT_INC(field)					\
290 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)++
291 #define	MYRI10GE_SLICE_STAT_ADD(field, val)				\
292 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul) += val
293 #define	MYRI10GE_SLICE_STAT_DEC(field)					\
294 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)--
295 #define	MYRI10GE_ATOMIC_SLICE_STAT_INC(field) 				\
296 atomic_add_long(&(((struct myri10ge_slice_stat *)			\
297 	    ss->ksp_stat->ks_data)->field.value.ul), 1)
298 #define	MYRI10GE_ATOMIC_SLICE_STAT_DEC(field) 				\
299 atomic_add_long(&(((struct myri10ge_slice_stat *)			\
300 	    ss->ksp_stat->ks_data)->field.value.ul), -1)
301 #define	MYRI10GE_SLICE_STAT(field)					\
302 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)
303 
304 
305 struct myri10ge_tx_copybuf
306 {
307 	caddr_t va;
308 	int len;
309 	struct myri10ge_dma_stuff dma;
310 };
311 
312 typedef struct
313 {
314 	mcp_kreq_ether_recv_t *lanai;	/* lanai ptr for recv ring */
315 	mcp_kreq_ether_recv_t *shadow;	/* host shadow of recv ring */
316 	struct myri10ge_rx_buffer_state *info;
317 	int cnt;
318 	int alloc_fail;
319 	int mask;			/* number of rx slots -1 */
320 	boolean_t polling;
321 } myri10ge_rx_ring_t;
322 
323 typedef struct
324 {
325 	mcp_kreq_ether_send_t *lanai;	/* lanai ptr for sendq	*/
326 	char *go;			/* doorbell to poll sendq */
327 	char *stop;			/* doorbell to !poll sendq */
328 	struct myri10ge_tx_buffer_state *info;
329 	struct myri10ge_tx_copybuf *cp;
330 	int req;			/* transmits submitted	*/
331 	int mask;			/* number of transmit slots -1 */
332 	int done;			/* transmits completed	*/
333 	int pkt_done;			/* packets completed */
334 	int active;
335 	uint32_t stall;
336 	uint32_t stall_early;
337 	uint32_t stall_late;
338 	int sched;
339 	kmutex_t lock;
340 	struct myri10ge_tx_ring_stats stats;
341 	int watchdog_req;
342 	int watchdog_done;
343 	unsigned long activate;
344 	kmutex_t handle_lock;
345 	struct myri10ge_tx_dma_handle  *free_tx_handles;
346 	mac_ring_handle_t rh;
347 } myri10ge_tx_ring_t;
348 
349 struct lro_entry;
350 
351 struct lro_entry
352 {
353 	struct lro_entry *next;
354 	mblk_t		*m_head;
355 	mblk_t		*m_tail;
356 	int		timestamp;
357 	struct ip	*ip;
358 	uint32_t	tsval;
359 	uint32_t	tsecr;
360 	uint32_t	source_ip;
361 	uint32_t	dest_ip;
362 	uint32_t	next_seq;
363 	uint32_t	ack_seq;
364 	uint32_t	len;
365 	uint32_t	data_csum;
366 	uint16_t	window;
367 	uint16_t	source_port;
368 	uint16_t	dest_port;
369 	uint16_t	append_cnt;
370 	uint16_t	mss;
371 	uint8_t		flags;
372 };
373 
374 struct myri10ge_mblk_list
375 {
376 	mblk_t *head;
377 	mblk_t **tail;
378 	int cnt;
379 };
380 
381 struct myri10ge_priv;
382 
383 struct myri10ge_slice_state {
384 	struct myri10ge_priv *mgp;
385 	myri10ge_tx_ring_t tx;	/* transmit ring 	*/
386 	myri10ge_rx_ring_t rx_small;
387 	myri10ge_rx_ring_t rx_big;
388 	myri10ge_rx_done_t rx_done;
389 	struct myri10ge_jpool_stuff jpool;
390 	struct myri10ge_rx_ring_stats rx_stats;
391 	volatile uint32_t *irq_claim;
392 	mcp_irq_data_t *fw_stats;
393 	struct lro_entry *lro_active;
394 	struct lro_entry *lro_free;
395 	struct myri10ge_dma_stuff fw_stats_dma;
396 	int jbufs_for_smalls;
397 	struct myri10ge_jpool_entry *small_jpool;
398 	int j_rx_cnt;
399 	mac_resource_handle_t mrh;
400 	kstat_t *ksp_stat;
401 	mac_ring_handle_t rx_rh;
402 	kmutex_t rx_lock;
403 	kmutex_t poll_lock;
404 	uint64_t rx_gen_num;
405 	boolean_t rx_polling;
406 	int rx_token;
407 	int watchdog_rx_copy;
408 };
409 
410 struct myri10ge_priv {
411 	struct myri10ge_slice_state *ss;
412 	int max_intr_slots;
413 	int num_slices;
414 	dev_info_t *dip;
415 	mac_handle_t mh;
416 	ddi_acc_handle_t io_handle;
417 	int tx_boundary;
418 	int watchdog_rx_pause;
419 	kstat_t *ksp_stat;
420 	kstat_t *ksp_info;
421 	int running;			/* running? 		*/
422 	int csum_flag;			/* rx_csums? 		*/
423 	uint8_t	mac_addr[6];		/* eeprom mac address */
424 	volatile uint8_t *sram;
425 	int sram_size;
426 	unsigned long  board_span;
427 	unsigned long iomem_base;
428 	volatile uint32_t *irq_deassert;
429 	char *mac_addr_string;
430 	mcp_cmd_response_t *cmd;
431 	struct myri10ge_dma_stuff cmd_dma;
432 	int msi_enabled;
433 	int link_state;
434 	int rdma_tags_available;
435 	int intr_coal_delay;
436 	volatile uint32_t *intr_coal_delay_ptr;
437 	kmutex_t cmd_lock;
438 	kmutex_t intrlock;
439 	int down_cnt;
440 	int watchdog_resets;
441 	unsigned char *eth_z8e;
442 	unsigned int eth_z8e_length;
443 	ddi_iblock_cookie_t icookie;
444 	ddi_intr_handle_t *htable;
445 	int intr_size;
446 	int intr_cnt;
447 	int intr_cap;
448 	unsigned int intr_pri;
449 	int ddi_intr_type;
450 	int pause;
451 	timeout_id_t timer_id;
452 	clock_t timer_ticks;
453 	int vso;
454 	uint32_t mcp_index;
455 	char fw_version[128];
456 	char name[32];
457 	char *fw_name;
458 	char *intr_type;
459 	char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
460 	char *sn_str;
461 	char *pc_str;
462 	uint32_t read_dma;
463 	uint32_t write_dma;
464 	uint32_t read_write_dma;
465 	uint32_t pcie_link_width;
466 	int max_read_request_4k;
467 	caddr_t nd_head;
468 	struct myri10ge_priv *next;
469 	uint_t refcnt;
470 	int reg_set;
471 	int features;
472 	struct myri10ge_pci_saved_state pci_saved_state;
473 	uint32_t *toeplitz_hash_table;
474 	uint32_t rss_key[8];
475 	ddi_acc_handle_t cfg_hdl;
476 	int macaddr_cnt;
477 };
478 
479 /* features bitmask */
480 #define	MYRI10GE_TSO 1
481 
482 #if defined(__GNUC__)
483 #define	likely(x)	__builtin_expect((x), 1)
484 #define	unlikely(x)	__builtin_expect((x), 0)
485 #else
486 #define	likely(x)	(x)
487 #define	unlikely(x)	(x)
488 #endif /* defined(__GNUC__) */
489 
490 #define	mb membar_producer
491 
492 struct myri10ge_priv *myri10ge_get_instance(uint_t unit);
493 void myri10ge_put_instance(struct myri10ge_priv *);
494 int myri10ge_send_cmd(struct myri10ge_priv *mgp, uint32_t cmd,
495     myri10ge_cmd_t *data);
496 caddr_t myri10ge_dma_alloc(dev_info_t *dip, size_t len,
497     ddi_dma_attr_t *attr, ddi_device_acc_attr_t  *accattr,
498     uint_t alloc_flags, int bind_flags, struct myri10ge_dma_stuff *dma,
499     int warn, int (*waitfp)(caddr_t));
500 void myri10ge_dma_free(struct myri10ge_dma_stuff *dma);
501 
502 void myri10ge_lro_flush(struct myri10ge_slice_state *ss,
503     struct lro_entry *lro, struct myri10ge_mblk_list *mbl);
504 int myri10ge_lro_rx(struct myri10ge_slice_state *ss, mblk_t *m_head,
505     uint32_t csum, struct myri10ge_mblk_list *mbl);
506 void myri10ge_mbl_append(struct myri10ge_slice_state *ss,
507     struct myri10ge_mblk_list *mbl, mblk_t *mp);
508 uint16_t myri10ge_csum_generic(uint16_t *raw, int len);
509 extern int myri10ge_lro_max_aggr;
510 extern int myri10ge_mtu;
511 
512 #ifndef ETHERNET_HEADER_SIZE
513 #define	ETHERNET_HEADER_SIZE 14
514 #endif
515 
516 #define	MYRI10GE_TOEPLITZ_HASH	(MXGEFW_RSS_HASH_TYPE_TCP_IPV4|\
517 	    MXGEFW_RSS_HASH_TYPE_IPV4)
518 #define	MYRI10GE_POLL_NULL INT_MAX
519 
520 /*
521  *  This file uses MyriGE driver indentation.
522  *
523  * Local Variables:
524  * c-file-style:"sun"
525  * tab-width:8
526  * End:
527  */
528 
529 #ifdef	__cplusplus
530 }
531 #endif
532 
533 #endif /* MYRI10GE_VAR_H */
534