xref: /onnv-gate/usr/src/uts/common/io/chxge/ch.h (revision 3833:45d8d0ee8613)
1*3833Sxw161283 /*
2*3833Sxw161283  * CDDL HEADER START
3*3833Sxw161283  *
4*3833Sxw161283  * The contents of this file are subject to the terms of the
5*3833Sxw161283  * Common Development and Distribution License (the "License").
6*3833Sxw161283  * You may not use this file except in compliance with the License.
7*3833Sxw161283  *
8*3833Sxw161283  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3833Sxw161283  * or http://www.opensolaris.org/os/licensing.
10*3833Sxw161283  * See the License for the specific language governing permissions
11*3833Sxw161283  * and limitations under the License.
12*3833Sxw161283  *
13*3833Sxw161283  * When distributing Covered Code, include this CDDL HEADER in each
14*3833Sxw161283  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3833Sxw161283  * If applicable, add the following below this CDDL HEADER, with the
16*3833Sxw161283  * fields enclosed by brackets "[]" replaced with your own identifying
17*3833Sxw161283  * information: Portions Copyright [yyyy] [name of copyright owner]
18*3833Sxw161283  *
19*3833Sxw161283  * CDDL HEADER END
20*3833Sxw161283  */
21*3833Sxw161283 
22*3833Sxw161283 /*
23*3833Sxw161283  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*3833Sxw161283  * Use is subject to license terms.
25*3833Sxw161283  */
26*3833Sxw161283 
27*3833Sxw161283 /*
28*3833Sxw161283  * This file is part of the Chelsio T1 Ethernet driver.
29*3833Sxw161283  *
30*3833Sxw161283  * Copyright (C) 2003-2005 Chelsio Communications.  All rights reserved.
31*3833Sxw161283  */
32*3833Sxw161283 
33*3833Sxw161283 #ifndef _CHELSIO_CH_H
34*3833Sxw161283 #define	_CHELSIO_CH_H
35*3833Sxw161283 
36*3833Sxw161283 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37*3833Sxw161283 
38*3833Sxw161283 #include <sys/debug.h>
39*3833Sxw161283 
40*3833Sxw161283 #ifdef __cplusplus
41*3833Sxw161283 extern "C" {
42*3833Sxw161283 #endif
43*3833Sxw161283 
44*3833Sxw161283 /*
45*3833Sxw161283  * Definitions for module_info
46*3833Sxw161283  */
47*3833Sxw161283 
48*3833Sxw161283 #define	CHIDNUM		(666)		/* module ID number */
49*3833Sxw161283 #define	CHNAME		"chxge"		/* module name */
50*3833Sxw161283 #define	CHMINPSZ	(0)		/* min packet size */
51*3833Sxw161283 #define	CHMAXPSZ	ETHERMTU	/* max packet size */
52*3833Sxw161283 #define	CHHIWAT		(32 * 1024)	/* hi-water mark */
53*3833Sxw161283 #define	CHLOWAT		(1)		/* lo-water mark */
54*3833Sxw161283 
55*3833Sxw161283 #define	CH_NO_HWCKSUM	0x1	/* hardware should no add checksum */
56*3833Sxw161283 #define	CH_NO_CPL	0x2	/* no cpl header with data */
57*3833Sxw161283 #define	CH_OFFLOAD	0x4	/* do TCP/IP offload processing */
58*3833Sxw161283 #define	CH_ARP		0x8	/* dummy arp packet (don't free) */
59*3833Sxw161283 #define	CH_TCP_MF	0x10	/* Indicator of Fragmented TCP */
60*3833Sxw161283 #define	CH_UDP_MF	0x20	/* Indicator of Fragmented UDP */
61*3833Sxw161283 #define	CH_UDP		0x40	/* Indicator of regular TCP */
62*3833Sxw161283 
63*3833Sxw161283 #define	SZ_INUSE	64	/* # of in use counters */
64*3833Sxw161283 
65*3833Sxw161283 /*
66*3833Sxw161283  * PCI registers
67*3833Sxw161283  */
68*3833Sxw161283 #define	BAR0 1
69*3833Sxw161283 #define	BAR1 2
70*3833Sxw161283 #define	BAR2 3
71*3833Sxw161283 #define	BAR3 4
72*3833Sxw161283 
73*3833Sxw161283 #ifdef CONFIG_CHELSIO_T1_OFFLOAD
74*3833Sxw161283 /*
75*3833Sxw161283  * TOE pre-mapped buffer structure
76*3833Sxw161283  */
77*3833Sxw161283 typedef struct tbuf {
78*3833Sxw161283 	struct tbuf	*tb_next;	/* next entry in free list */
79*3833Sxw161283 	caddr_t		tb_base;	/* base of buffer */
80*3833Sxw161283 	uint64_t	tb_pa;		/* physical address of buffer */
81*3833Sxw161283 	ulong_t		tb_dh;		/* dma handle */
82*3833Sxw161283 	ulong_t		tb_ah;		/* dma address handle */
83*3833Sxw161283 	void		*tb_sa;		/* address of card ctrl struct */
84*3833Sxw161283 	uint32_t	tb_debug;	/* initally 0 */
85*3833Sxw161283 	uint32_t	tb_len;		/* length of data */
86*3833Sxw161283 } tbuf_t;
87*3833Sxw161283 #endif	/* CONFIG_CHELSIO_T1_OFFLOAD */
88*3833Sxw161283 
89*3833Sxw161283 /*
90*3833Sxw161283  * header structures to hold pre-mapped (DMA) kernel memory buffers.
91*3833Sxw161283  */
92*3833Sxw161283 typedef struct ch_esb {
93*3833Sxw161283 	struct ch_esb   *cs_next;	/* next entry in list */
94*3833Sxw161283 	struct ch_esb   *cs_owner;	/* list of buffers owned by ch_t */
95*3833Sxw161283 	void		*cs_sa;		/* card structure to get ch ptr */
96*3833Sxw161283 	ulong_t		cs_dh;		/* dma handle */
97*3833Sxw161283 	ulong_t		cs_ah;		/* dma address handle */
98*3833Sxw161283 	caddr_t		cs_buf;		/* vaddr of buffer */
99*3833Sxw161283 	uint64_t	cs_pa;		/* paddr of buffer */
100*3833Sxw161283 	uint32_t	cs_index;	/* index of buffer_in_use count */
101*3833Sxw161283 	uint32_t	cs_flag;	/* if set, commit suicide */
102*3833Sxw161283 #ifdef FRAGMENT				/* we assume no fragments */
103*3833Sxw161283 	ddi_dma_cookie_t cs_cookie[MAXFS];
104*3833Sxw161283 	uint_t		cs_ncookie;
105*3833Sxw161283 #endif
106*3833Sxw161283 	frtn_t		cs_frtn;	/* for esballoc */
107*3833Sxw161283 } ch_esb_t;
108*3833Sxw161283 
109*3833Sxw161283 /*
110*3833Sxw161283  * structure for linked list of multicast addresses that have been
111*3833Sxw161283  * assigned to the card.
112*3833Sxw161283  */
113*3833Sxw161283 typedef struct ch_mc {
114*3833Sxw161283 	struct ch_mc *cmc_next;
115*3833Sxw161283 	uint8_t cmc_mca[6];
116*3833Sxw161283 } ch_mc_t;
117*3833Sxw161283 
118*3833Sxw161283 /*
119*3833Sxw161283  * structure for linked list of pre-allocated dma handles for command Q
120*3833Sxw161283  */
121*3833Sxw161283 typedef struct free_dh {
122*3833Sxw161283 	struct free_dh *dhe_next;
123*3833Sxw161283 	ulong_t dhe_dh;
124*3833Sxw161283 } free_dh_t;
125*3833Sxw161283 
126*3833Sxw161283 /*
127*3833Sxw161283  * instance configuration
128*3833Sxw161283  */
129*3833Sxw161283 typedef struct ch_cfg {
130*3833Sxw161283 	uint32_t cksum_enabled: 1;
131*3833Sxw161283 	uint32_t burstsize_set: 1;
132*3833Sxw161283 	uint32_t burstsize: 2;
133*3833Sxw161283 	uint32_t transaction_cnt_set: 1;
134*3833Sxw161283 	uint32_t transaction_cnt: 3;
135*3833Sxw161283 	uint32_t relaxed_ordering: 1;
136*3833Sxw161283 	uint32_t enable_dvma: 1;
137*3833Sxw161283 } ch_cfg_t;
138*3833Sxw161283 
139*3833Sxw161283 /*
140*3833Sxw161283  * Per-card state information
141*3833Sxw161283  */
142*3833Sxw161283 typedef struct ch {
143*3833Sxw161283 	dev_info_t	*ch_dip;	/* device dev info */
144*3833Sxw161283 	gld_mac_info_t	*ch_macp;	/* gld mac structure */
145*3833Sxw161283 
146*3833Sxw161283 	ch_cfg_t	ch_config;	/* instance configuration */
147*3833Sxw161283 	uint_t		ch_flags;	/* state flags */
148*3833Sxw161283 	uint_t		ch_state;	/* card state */
149*3833Sxw161283 	uint_t		ch_blked;	/* card is blked on output */
150*3833Sxw161283 	kmutex_t	ch_lock;	/* lock for ch structure */
151*3833Sxw161283 
152*3833Sxw161283 	caddr_t		ch_pci;		/* PCI configuration vaddr */
153*3833Sxw161283 	ddi_acc_handle_t ch_hpci;	/* PCI configuration access handle */
154*3833Sxw161283 	off_t		ch_pcisz;	/* size of PCI configuration space */
155*3833Sxw161283 
156*3833Sxw161283 	caddr_t		ch_bar0;	/* PCI BAR0 vaddr */
157*3833Sxw161283 	ddi_acc_handle_t ch_hbar0;	/* PCI BAR0 access handle */
158*3833Sxw161283 	off_t		ch_bar0sz;	/* size of BAR0 space */
159*3833Sxw161283 
160*3833Sxw161283 	ddi_iblock_cookie_t ch_icookp; /* hardware interrupt cookie ptr */
161*3833Sxw161283 	kmutex_t	ch_intr;	/* lock for interrupts */
162*3833Sxw161283 
163*3833Sxw161283 	uint32_t	ch_maximum_mtu;	/* maximum mtu for adapter */
164*3833Sxw161283 
165*3833Sxw161283 	uint32_t	ch_sm_buf_sz;	/* size of sm esballoc bufs */
166*3833Sxw161283 	uint32_t	ch_sm_buf_aln;	/* alignment of sm esballoc bufs */
167*3833Sxw161283 	ch_esb_t	*ch_small_esb_free; /* free list sm esballoc bufs */
168*3833Sxw161283 	ch_esb_t	*ch_small_owner; /* list small bufs owned by ch_t */
169*3833Sxw161283 	kmutex_t	ch_small_esbl;	/* lock for ch_small_esb list */
170*3833Sxw161283 	uint_t		ch_sm_index;	/* small buffer in use count index */
171*3833Sxw161283 
172*3833Sxw161283 	uint32_t	ch_bg_buf_sz;	/* size of bg esballoc bufs */
173*3833Sxw161283 	uint32_t	ch_bg_buf_aln;	/* alignment of bg esballoc bufs */
174*3833Sxw161283 	ch_esb_t	*ch_big_esb_free; /* free list of esballoc entries */
175*3833Sxw161283 	ch_esb_t	*ch_big_owner;	/* list big bufs owned by ch_t */
176*3833Sxw161283 	kmutex_t	ch_big_esbl;	/* lock for ch_esb list */
177*3833Sxw161283 	uint_t		ch_big_index;	/* big buffer in use count index */
178*3833Sxw161283 
179*3833Sxw161283 	kmutex_t	ch_mc_lck;	/* lock of mulitcast list */
180*3833Sxw161283 	ch_mc_t		*ch_mc;		/* list of multicast entries */
181*3833Sxw161283 	uint32_t	ch_mc_cnt;	/* cnt of multicast entries */
182*3833Sxw161283 
183*3833Sxw161283 	/* XXX see how we can use cmdQ_ce list and get rid of lock */
184*3833Sxw161283 	kmutex_t	ch_dh_lck;	/* lock for ch_dh list */
185*3833Sxw161283 	free_dh_t	*ch_dh;		/* list of free dma headers for v2p */
186*3833Sxw161283 
187*3833Sxw161283 #if defined(__sparc)
188*3833Sxw161283 	/* XXX see how we can use cmdQ_ce list and get rid of lock */
189*3833Sxw161283 	free_dh_t	*ch_vdh;	/* list of free dvma headers for v2p */
190*3833Sxw161283 #endif
191*3833Sxw161283 
192*3833Sxw161283 	uint32_t	ch_ip;		/* ip address from first arp */
193*3833Sxw161283 
194*3833Sxw161283 	uint32_t	ch_mtu;		/* size of device MTU (1500 default) */
195*3833Sxw161283 
196*3833Sxw161283 	/* XXX config_data needs cleanup */
197*3833Sxw161283 	pe_config_data_t config_data;	/* card configuration vector */
198*3833Sxw161283 
199*3833Sxw161283 	struct pe_port_t port[4];	/* from freebsd/oschtoe.h driver */
200*3833Sxw161283 	pesge		*sge;
201*3833Sxw161283 	struct pemc3	*mc3;
202*3833Sxw161283 	struct pemc4	*mc4;
203*3833Sxw161283 	struct pemc5	*mc5;
204*3833Sxw161283 	struct petp	*tp;
205*3833Sxw161283 	struct pecspi	*cspi;
206*3833Sxw161283 	struct peespi	*espi;
207*3833Sxw161283 	struct peulp	*ulp;
208*3833Sxw161283 #ifdef CONFIG_CHELSIO_T1_OFFLOAD
209*3833Sxw161283 	uint32_t	open_device_map;
210*3833Sxw161283 #endif
211*3833Sxw161283 	struct adapter_params params;
212*3833Sxw161283 	uint16_t	vendor_id;
213*3833Sxw161283 	uint16_t	device_id;
214*3833Sxw161283 	uint16_t	device_subid;
215*3833Sxw161283 	uint16_t	chip_revision;
216*3833Sxw161283 	uint16_t	chip_version;
217*3833Sxw161283 	uint32_t	is_asic;
218*3833Sxw161283 	uint32_t	config;
219*3833Sxw161283 	uint32_t	ch_unit;
220*3833Sxw161283 	uint8_t		init_counter;
221*3833Sxw161283 	char		*ch_name;
222*3833Sxw161283 	/* statistics per card */
223*3833Sxw161283 	uint32_t	isr_intr;	/* # interrupts */
224*3833Sxw161283 	uint32_t	oerr;		/* send error (no mem) */
225*3833Sxw161283 	uint32_t	norcvbuf;
226*3833Sxw161283 #ifdef CONFIG_CHELSIO_T1_OFFLOAD
227*3833Sxw161283 	int		ch_refcnt;
228*3833Sxw161283 	void		*ch_toeinst;
229*3833Sxw161283 	void		(*toe_rcv)(void *, mblk_t *);
230*3833Sxw161283 	void		(*toe_free)(void *, tbuf_t *);
231*3833Sxw161283 	int		(*toe_tunnel)(void *, mblk_t *);
232*3833Sxw161283 	kcondvar_t	*ch_tx_overflow_cv;
233*3833Sxw161283 	kmutex_t	*ch_tx_overflow_mutex;
234*3833Sxw161283 #endif
235*3833Sxw161283 	uint32_t	slow_intr_mask;
236*3833Sxw161283 #ifdef HOST_PAUSE
237*3833Sxw161283 	uint32_t	txxg_cfg1;	/* Place holder for MAC cfg reg1. */
238*3833Sxw161283 	int		pause_on;
239*3833Sxw161283 	hrtime_t	pause_time;
240*3833Sxw161283 #endif
241*3833Sxw161283 	kmutex_t	mac_lock;	/* lock for MAC structure */
242*3833Sxw161283 } ch_t;
243*3833Sxw161283 
244*3833Sxw161283 /* ch_flags */
245*3833Sxw161283 #define	PEIDLE		0x00	/* chip is uninitialized */
246*3833Sxw161283 #define	PERUNNING	0x01	/* chip is initialized */
247*3833Sxw161283 #define	PEPROMISC	0x04	/* promiscuous mode enabled */
248*3833Sxw161283 #define	PEALLMULTI	0x08	/* all multicast enabled */
249*3833Sxw161283 #define	PESUSPENDED	0x20	/* suspended interface */
250*3833Sxw161283 #define	PENORES		0x40	/* ran out of xmit resources */
251*3833Sxw161283 #define	PESTOP		0x80	/* gldm_stop done */
252*3833Sxw161283 #define	PEINITDONE	0x100	/* initialization done */
253*3833Sxw161283 #define	TSO_CAPABLE	0x200	/* TSO able */
254*3833Sxw161283 
255*3833Sxw161283 #ifdef CONFIG_CHELSIO_T1_OFFLOAD
256*3833Sxw161283 /* open_device_map flag */
257*3833Sxw161283 #define	TOEDEV_DEVMAP_BIT 0x1
258*3833Sxw161283 #endif
259*3833Sxw161283 
260*3833Sxw161283 /*
261*3833Sxw161283  * DMA mapping defines
262*3833Sxw161283  */
263*3833Sxw161283 #define	DMA_STREAM 1	/* use DDI_DMA_STREAMING for DMA xfers */
264*3833Sxw161283 #define	DMA_4KALN  2	/* align memory to 4K page boundry */
265*3833Sxw161283 #define	DMA_OUT    4	/* this is a write buffer */
266*3833Sxw161283 #define	DMA_SMALN  8	/* aligned at small buffer boundry */
267*3833Sxw161283 #define	DMA_BGALN  16	/* aligned at big buffer boundry */
268*3833Sxw161283 
269*3833Sxw161283 /*
270*3833Sxw161283  * Number of multicast addresses per stream
271*3833Sxw161283  */
272*3833Sxw161283 #define	CHMAXMC   64
273*3833Sxw161283 #define	CHMCALLOC (CHMAXMC * sizeof (struct ether_addr))
274*3833Sxw161283 
275*3833Sxw161283 /* ----- Solaris memory - PCI - DMA mapping functions ------ */
276*3833Sxw161283 
277*3833Sxw161283 void *ch_alloc_dma_mem(ch_t *, int, int, int, uint64_t *, ulong_t *, ulong_t *);
278*3833Sxw161283 void ch_free_dma_mem(ulong_t, ulong_t);
279*3833Sxw161283 void ch_unbind_dma_handle(ch_t *, free_dh_t *);
280*3833Sxw161283 
281*3833Sxw161283 void ch_send_up(ch_t *, mblk_t *, uint32_t, int);
282*3833Sxw161283 
283*3833Sxw161283 void ch_gld_ok(ch_t *);
284*3833Sxw161283 
285*3833Sxw161283 uint32_t t1_read_reg_4(ch_t *obj, uint32_t reg_val);
286*3833Sxw161283 void t1_write_reg_4(ch_t *obj, uint32_t reg_val, uint32_t write_val);
287*3833Sxw161283 uint32_t t1_os_pci_read_config_2(ch_t *obj, uint32_t reg, uint16_t *val);
288*3833Sxw161283 uint32_t t1_os_pci_read_config_4(ch_t *obj, uint32_t reg, uint32_t *val);
289*3833Sxw161283 int t1_os_pci_write_config_2(ch_t *obj, uint32_t reg, uint16_t val);
290*3833Sxw161283 int t1_os_pci_write_config_4(ch_t *obj, uint32_t reg, uint32_t val);
291*3833Sxw161283 uint32_t le32_to_cpu(uint32_t data);
292*3833Sxw161283 
293*3833Sxw161283 void *t1_os_malloc_wait_zero(size_t len);
294*3833Sxw161283 void t1_os_free(void *adr, size_t len);
295*3833Sxw161283 int t1_num_of_ports(ch_t *obj);
296*3833Sxw161283 int pe_os_mem_copy(ch_t *obj, void *dst, void *src, size_t len);
297*3833Sxw161283 void *pe_os_malloc_contig_wait_zero(ch_t *, size_t, uint64_t *,
298*3833Sxw161283     ulong_t *, ulong_t *, uint32_t);
299*3833Sxw161283 void pe_set_mac(ch_t *sa, unsigned char *ac_enaddr);
300*3833Sxw161283 unsigned char *pe_get_mac(ch_t *sa);
301*3833Sxw161283 void pe_set_promiscuous(ch_t *sa, int flag);
302*3833Sxw161283 int pe_get_stats(ch_t *sa, uint64_t *speed, uint32_t *intrcnt,
303*3833Sxw161283     uint32_t *norcvbuf, uint32_t *oerrors, uint32_t *ierrors,
304*3833Sxw161283     uint32_t *underrun, uint32_t *overrun, uint32_t *framing,
305*3833Sxw161283     uint32_t *crc, uint32_t *carrier, uint32_t *collisions,
306*3833Sxw161283     uint32_t *xcollisions, uint32_t *late, uint32_t *defer,
307*3833Sxw161283     uint32_t *xerrs, uint32_t *rerrs, uint32_t *toolong, uint32_t *runt,
308*3833Sxw161283     ulong_t *multixmt, ulong_t *multircv, ulong_t *brdcstxmt,
309*3833Sxw161283     ulong_t *brdcstrcv);
310*3833Sxw161283 int pe_attach(ch_t *);
311*3833Sxw161283 void pe_detach(ch_t *);
312*3833Sxw161283 void pe_init(void *);
313*3833Sxw161283 uint_t pe_intr(ch_t *);
314*3833Sxw161283 
315*3833Sxw161283 #ifdef CONFIG_CHELSIO_T1_OFFLOAD
316*3833Sxw161283 #define	toe_running(a) (a->open_device_map & TOEDEV_DEVMAP_BIT)
317*3833Sxw161283 #endif
318*3833Sxw161283 
319*3833Sxw161283 int pe_start(ch_t *sa, mblk_t *mb, uint32_t flg);
320*3833Sxw161283 void pe_stop(ch_t *sa);
321*3833Sxw161283 void pe_ioctl(ch_t *, queue_t *, mblk_t *);
322*3833Sxw161283 int pe_set_mc(ch_t *, uint8_t *, int);
323*3833Sxw161283 
324*3833Sxw161283 int tpi_read(ch_t *obj, u32 addr, u32 *value);
325*3833Sxw161283 
326*3833Sxw161283 void CH_ALERT(const char *fmt, ...);
327*3833Sxw161283 void CH_WARN(const char *fmt, ...);
328*3833Sxw161283 void CH_ERR(const char *fmt, ...);
329*3833Sxw161283 void t1_fatal_err(ch_t *chp);
330*3833Sxw161283 
331*3833Sxw161283 #define	memset(s, c, n) bzero(s, n)
332*3833Sxw161283 
333*3833Sxw161283 extern int enable_checksum_offload;
334*3833Sxw161283 
335*3833Sxw161283 void pe_dma_handle_init(ch_t *, int);
336*3833Sxw161283 free_dh_t *ch_get_dma_handle(ch_t *);
337*3833Sxw161283 
338*3833Sxw161283 void pe_free_fake_arp(void *);
339*3833Sxw161283 
340*3833Sxw161283 void pe_mark_freelists(ch_t *chp);
341*3833Sxw161283 
342*3833Sxw161283 #if defined(__sparc)
343*3833Sxw161283 free_dh_t *ch_get_dvma_handle(ch_t *);
344*3833Sxw161283 void ch_unbind_dvma_handle(ch_t *, free_dh_t *);
345*3833Sxw161283 #endif
346*3833Sxw161283 
347*3833Sxw161283 #define	AMD_VENDOR_ID	0x1022
348*3833Sxw161283 #define	AMD_BRIDGE	0x7450
349*3833Sxw161283 #define	AMD_BRIDGE_REV	0x12
350*3833Sxw161283 
351*3833Sxw161283 #ifdef __cplusplus
352*3833Sxw161283 }
353*3833Sxw161283 #endif
354*3833Sxw161283 
355*3833Sxw161283 #endif	/* _CHELSIO_CH_H */
356