xref: /illumos-gate/usr/src/uts/common/io/pcn/pcnimpl.h (revision e0731422366620894c16c1ee6515551c5f00733d)
1 /*
2  * Copyright (c) 2011 Jason King.
3  * Copyright (c) 2000 Berkeley Software Design, Inc.
4  * Copyright (c) 1997, 1998, 1999, 2000
5  *      Bill Paul <wpaul@ee.columbia.edu>.  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
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Bill Paul.
18  * 4. Neither the name of the author nor the names of any co-contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 #ifndef	_PCNIMPL_H
36 #define	_PCNIMPL_H
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #ifdef	_KERNEL
43 
44 #define	PCN_VENDORID		0x1022
45 #define	PCN_DEVICEID_PCNET	0x2000
46 #define	PCN_DEVICEID_HOME	0x2001
47 
48 typedef struct pcn_type {
49 	uint16_t	pcn_vid;
50 	uint16_t	pcn_did;
51 	char		*pcn_name;	/* ddi_set_prop takes char * */
52 } pcn_type_t;
53 
54 #define	PCN_TXRECLAIM		8
55 #define	PCN_HEADROOM		34
56 #define	PCN_TXRESCHED		120
57 
58 #define	PCN_RXSTAT_BAM		0x0008	/* broadcast address match */
59 #define	PCN_RXSTAT_LAFM		0x0010	/* logical address filter match */
60 #define	PCN_RXSTAT_PAM		0x0020	/* physical address match */
61 #define	PCN_RXSTAT_BPE		0x0080  /* bus parity error */
62 #define	PCN_RXSTAT_ENP		0x0100  /* end of packet */
63 #define	PCN_RXSTAT_STP		0x0200  /* start of packet */
64 #define	PCN_RXSTAT_BUFF		0x0400  /* buffer error */
65 #define	PCN_RXSTAT_CRC		0x0800  /* CRC error */
66 #define	PCN_RXSTAT_OFLOW	0x1000  /* rx overrun */
67 #define	PCN_RXSTAT_FRAM		0x2000  /* framing error */
68 #define	PCN_RXSTAT_ERR		0x4000  /* error summary */
69 #define	PCN_RXSTAT_OWN		0x8000
70 #define	PCN_RXSTAT_STR \
71 	"\020" \
72 	"\004BAM" \
73 	"\005LAFM" \
74 	"\006PAM" \
75 	"\010BPE" \
76 	"\011ENP" \
77 	"\012STP" \
78 	"\013BUFF" \
79 	"\014CRC" \
80 	"\015OFLOW" \
81 	"\016FRAM" \
82 	"\017ERR" \
83 	"\020OWN"
84 
85 #define	PCN_RXLEN_MBO		0xF000
86 #define	PCN_RXLEN_BUFSZ		0x0FFF
87 
88 typedef struct pcn_rx_desc {
89 	uint16_t	pcn_rxlen;
90 	uint16_t	pcn_rsvd0;
91 	uint16_t	pcn_bufsz;
92 	uint16_t	pcn_rxstat;
93 	uint32_t	pcn_rbaddr;
94 	uint32_t	pcn_uspace;
95 } pcn_rx_desc_t;
96 
97 typedef struct pcn_tx_desc {
98 	uint32_t	pcn_txstat;
99 	uint32_t	pcn_txctl;
100 	uint32_t	pcn_tbaddr;
101 	uint32_t	pcn_uspace;
102 } pcn_tx_desc_t;
103 
104 #define	PCN_TXCTL_OWN		0x80000000
105 #define	PCN_TXCTL_ERR		0x40000000	/* error summary */
106 #define	PCN_TXCTL_ADD_FCS	0x20000000	/* add FCS to pkt */
107 #define	PCN_TXCTL_MORE_LTINT	0x10000000
108 #define	PCN_TXCTL_ONE		0x08000000
109 #define	PCN_TXCTL_DEF		0x04000000
110 #define	PCN_TXCTL_STP		0x02000000
111 #define	PCN_TXCTL_ENP		0x01000000
112 #define	PCN_TXCTL_BPE		0x00800000
113 #define	PCN_TXCTL_MBO		0x0000F000
114 #define	PCN_TXCTL_BUFSZ		0x00000FFF
115 #define	PCN_TXCTL_STR \
116 	"\020" \
117 	"\040OWN" \
118 	"\037ERR" \
119 	"\036ADD_FCS" \
120 	"\035MORE_LTINT" \
121 	"\034ONE" \
122 	"\033DEF" \
123 	"\032STP" \
124 	"\031ENP" \
125 	"\030BPE"
126 
127 typedef struct pcn_buf {
128 	caddr_t			pb_buf;
129 	ddi_dma_handle_t	pb_dmah;
130 	ddi_acc_handle_t	pb_acch;
131 	uint32_t		pb_paddr;
132 } pcn_buf_t;
133 
134 /* Constants, do not change */
135 #define	PCN_BUFSZ	(1664)
136 #define	PCN_MCHASH	(64)
137 
138 /* Number of descriptor entries */
139 #define	PCN_RXRING	64
140 #define	PCN_TXRING	256
141 
142 typedef struct pcn {
143 	dev_info_t		*pcn_dip;
144 	mac_handle_t		pcn_mh;
145 	mii_handle_t		pcn_mii;
146 	uint16_t		pcn_cachesize;
147 	int			pcn_flags;
148 	int			pcn_instance;
149 	kmutex_t		pcn_xmtlock;
150 	kmutex_t		pcn_intrlock;
151 	kmutex_t		pcn_reglock;
152 	ddi_iblock_cookie_t	pcn_icookie;
153 	uint_t			pcn_int_pri;
154 	int			pcn_type;
155 	int8_t			pcn_extphyaddr;
156 
157 	/*
158 	 * Register and DMA access
159 	 */
160 	uintptr_t		pcn_regs;
161 	ddi_acc_handle_t	pcn_regshandle;
162 
163 	/*
164 	 * Receive descriptors.
165 	 */
166 	int			pcn_rxhead;
167 	pcn_rx_desc_t		*pcn_rxdescp;
168 	ddi_dma_handle_t	pcn_rxdesc_dmah;
169 	ddi_acc_handle_t	pcn_rxdesc_acch;
170 	uint32_t		pcn_rxdesc_paddr;
171 	pcn_buf_t		**pcn_rxbufs;
172 
173 	/*
174 	 * Transmit descriptors.
175 	 */
176 	int			pcn_txreclaim;
177 	int			pcn_txsend;
178 	int			pcn_txavail;
179 	pcn_tx_desc_t		*pcn_txdescp;
180 	ddi_dma_handle_t	pcn_txdesc_dmah;
181 	ddi_acc_handle_t	pcn_txdesc_acch;
182 	uint32_t		pcn_txdesc_paddr;
183 	pcn_buf_t		**pcn_txbufs;
184 	hrtime_t		pcn_txstall_time;
185 	boolean_t		pcn_wantw;
186 
187 	/*
188 	 * Address management.
189 	 */
190 	uchar_t			pcn_addr[ETHERADDRL];
191 	boolean_t		pcn_promisc;
192 	uint16_t		pcn_mccount[PCN_MCHASH];
193 	uint16_t		pcn_mctab[PCN_MCHASH / 16];
194 
195 	/*
196 	 * stats
197 	 */
198 	uint64_t		pcn_ipackets;
199 	uint64_t		pcn_opackets;
200 	uint64_t		pcn_rbytes;
201 	uint64_t		pcn_obytes;
202 	uint64_t		pcn_brdcstxmt;
203 	uint64_t		pcn_multixmt;
204 	uint64_t		pcn_brdcstrcv;
205 	uint64_t		pcn_multircv;
206 	uint64_t		pcn_norcvbuf;
207 	uint64_t		pcn_errrcv;
208 	uint64_t		pcn_errxmt;
209 	uint64_t		pcn_missed;
210 	uint64_t		pcn_underflow;
211 	uint64_t		pcn_overflow;
212 	uint64_t		pcn_align_errors;
213 	uint64_t		pcn_fcs_errors;
214 	uint64_t		pcn_carrier_errors;
215 	uint64_t		pcn_collisions;
216 	uint64_t		pcn_ex_collisions;
217 	uint64_t		pcn_tx_late_collisions;
218 	uint64_t		pcn_defer_xmts;
219 	uint64_t		pcn_first_collisions;
220 	uint64_t		pcn_multi_collisions;
221 	uint64_t		pcn_sqe_errors;
222 	uint64_t		pcn_macxmt_errors;
223 	uint64_t		pcn_macrcv_errors;
224 	uint64_t		pcn_toolong_errors;
225 	uint64_t		pcn_runt;
226 	uint64_t		pcn_jabber;
227 } pcn_t;
228 
229 /* Flags */
230 #define	PCN_RUNNING		(1L << 0)
231 #define	PCN_SUSPENDED		(1L << 1)
232 #define	PCN_INTR_ENABLED	(1L << 2)
233 #define	PCN_FLAGSTR \
234 	"\020" \
235 	"\001RUNNING" \
236 	"\002SUSPENDED" \
237 	"\003INTR_ENABLED"
238 #define	IS_RUNNING(p)	((p)->pcn_flags & PCN_RUNNING)
239 #define	IS_SUSPENDED(p)	((p)->pcn_flags & PCN_SUSPENDED)
240 
241 #define	SYNCTXDESC(pcnp, index, who) \
242 	(void) ddi_dma_sync(pcnp->pcn_txdesc_dmah, \
243 	    (index * sizeof (pcn_tx_desc_t)), sizeof (pcn_tx_desc_t), who)
244 
245 #define	SYNCRXDESC(pcnp, index, who) \
246 	(void) ddi_dma_sync(pcnp->pcn_rxdesc_dmah, \
247 	    (index * sizeof (pcn_rx_desc_t)), sizeof (pcn_rx_desc_t), who)
248 
249 #define	SYNCBUF(pb, len, who) \
250 	(void) ddi_dma_sync(pb->pb_dmah, 0, len, who)
251 
252 #endif /* _KERNEL */
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif /* _PCNIMPL_H */
259