1 /*	$OpenBSD: if_lmcioctl.h,v 1.4 2000/11/10 15:33:09 provos Exp $ */
2 /*	$Id: if_lmcioctl.h,v 1.4 2000/11/10 15:33:09 provos Exp $	*/
3 
4 /*
5  * Copyright (c) 1997-1999 LAN Media Corporation (LMC)
6  * All rights reserved.  www.lanmedia.com
7  *
8  * This code is written by Michael Graff <graff@vix.com> for LMC.
9  * The code is derived from permitted modifications to software created
10  * by Matt Thomas (matt@3am-software.com).
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above
18  *    copyright notice, this list of conditions and the following disclaimer
19  *    in the documentation and/or other materials provided with the
20  *    distribution.
21  * 3. All marketing or advertising materials mentioning features or
22  *    use of this software must display the following acknowledgement:
23  *      This product includes software developed by LAN Media Corporation
24  *      and its contributors.
25  * 4. Neither the name of LAN Media Corporation nor the names of its
26  *    contributors may be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY LAN MEDIA CORPORATION AND CONTRIBUTORS
30  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
39  * THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 #if defined(linux)
43 #include <linux/types.h>
44 /*
45  * IOCTLs that we use for linux.  The structures passed in really should
46  * go into an OS inspecific file, since BSD will use these as well.
47  *
48  * Under linux, the 16 reserved-for-device IOCTLs are numbered 0x89f0
49  * through 0x89ff.
50  */
51 #define LMCIOCGINFO         SIOCDEVPRIVATE+3 /* get current state */
52 #define LMCIOCSINFO         SIOCDEVPRIVATE+4 /* set state to user values */
53 #define LMCIOCSKEEPALIVE    SIOCDEVPRIVATE+5 /* Turn keepalives on/off */
54 #ifdef  LMC_DEBUG_FILE
55 #define LMCIOCLEARSTATS LMCIOCSINFO + 1 /* Clear debug stats */
56 #endif
57 #ifdef  LMC_BAZ
58 #define LMCIOCGETLMCSTATS       LMCIOCSINFO + 3
59 #define LMCIOCCLEARLMCSTATS     LMCIOCSINFO + 4
60 #define LMCIOCDUMPEVENTLOG      LMCIOCSINFO + 5
61 #define LMCIOCGETXINFO          LMCIOCSINFO + 6
62 #define LMCIOCREADLEDS          LMCIOCSINFO + 7
63 #define LMCIOCSETLEDS           LMCIOCSINFO + 8
64 #define LMCIOCRESET             LMCIOCSINFO + 9
65 #endif
66 
67 #else
68 /*
69  * IOCTLs for the sane world.
70  */
71 #define LMCIOCGINFO	_IOW('i', 240, struct ifreq)
72 #define LMCIOCSINFO	_IOWR('i', 241, struct ifreq)
73 
74 #endif
75 
76 typedef struct {
77 	u_int32_t	n;
78 	u_int32_t	m;
79 	u_int32_t	v;
80 	u_int32_t	x;
81 	u_int32_t	r;
82 	u_int32_t	f;
83 	u_int32_t	exact;
84 } lmc_av9110_t;
85 
86 /*
87  * Common structure passed to the ioctl code.
88  */
89 struct lmc___ctl {
90 	u_int32_t	cardtype;
91 	u_int32_t	clock_source;		/* HSSI, T1 */
92 	u_int32_t	clock_rate;		/* T1 */
93 	u_int32_t	crc_length;
94 	u_int32_t	cable_length;		/* DS3 */
95 	u_int32_t	scrambler_onoff;	/* DS3 */
96 	u_int32_t	cable_type;		/* T1 */
97 	u_int32_t	keepalive_onoff;	/* protocol */
98 	u_int32_t	ticks;			/* ticks/sec */
99 	union {
100 		lmc_av9110_t	ssi;
101 	} cardspec;
102 	u_int32_t       circuit_type;		/* T1 or E1 */
103 };
104 
105 #define LMC_CARDTYPE_UNKNOWN		-1
106 #define LMC_CARDTYPE_HSSI		1	/* probed card is a HSSI card */
107 #define LMC_CARDTYPE_DS3		2	/* probed card is a DS3 card */
108 #define LMC_CARDTYPE_SSI		3	/* probed card is a SSI card */
109 #define LMC_CARDTYPE_T1			4	/* probed card is a T1 card */
110 
111 
112 #define LMC_CTL_CARDTYPE_LMC5200	0	/* HSSI */
113 #define LMC_CTL_CARDTYPE_LMC5245	1	/* DS3 */
114 #define LMC_CTL_CARDTYPE_LMC1000	2	/* SSI, V.35 */
115 #define LMC_CTL_CARDTYPE_LMC1200	3	/* DS1 */
116 
117 #define LMC_CTL_OFF			0	/* generic OFF value */
118 #define LMC_CTL_ON			1	/* generic ON value */
119 
120 #define LMC_CTL_CLOCK_SOURCE_EXT	0	/* clock off line */
121 #define LMC_CTL_CLOCK_SOURCE_INT	1	/* internal clock */
122 
123 #define LMC_CTL_CRC_LENGTH_16		16
124 #define LMC_CTL_CRC_LENGTH_32		32
125 #define LMC_CTL_CRC_BYTESIZE_2		2
126 #define LMC_CTL_CRC_BYTESIZE_4		4
127 
128 
129 #define LMC_CTL_CABLE_LENGTH_LT_100FT	0	/* DS3 cable < 100 feet */
130 #define LMC_CTL_CABLE_LENGTH_GT_100FT	1	/* DS3 cable >= 100 feet */
131 
132 #define LMC_CTL_CIRCUIT_TYPE_E1		0
133 #define LMC_CTL_CIRCUIT_TYPE_T1		1
134 
135 /*
136  * These are not in the least IOCTL related, but I want them common.
137  */
138 /*
139  * assignments for the GPIO register on the DEC chip (common)
140  */
141 #define LMC_GEP_INIT		0x01 /* 0: */
142 #define LMC_GEP_RESET		0x02 /* 1: */
143 #define LMC_GEP_LOAD		0x10 /* 4: */
144 #define LMC_GEP_DP		0x20 /* 5: */
145 #define LMC_GEP_SERIAL		0x40 /* 6: serial out */
146 #define LMC_GEP_SERIALCLK	0x80 /* 7: serial clock */
147 
148 /*
149  * HSSI GPIO assignments
150  */
151 #define LMC_GEP_HSSI_ST		0x04 /* 2: receive timing sense (deprecated) */
152 #define LMC_GEP_HSSI_CLOCK	0x08 /* 3: clock source */
153 
154 /*
155  * T1 GPIO assignments
156  */
157 #define LMC_GEP_SSI_GENERATOR	0x04 /* 2: enable prog freq gen serial i/f */
158 #define LMC_GEP_SSI_TXCLOCK	0x08 /* 3: provide clock on TXCLOCK output */
159 
160 /*
161  * Common MII16 bits
162  */
163 #define LMC_MII16_LED0		0x0080
164 #define LMC_MII16_LED1		0x0100
165 #define LMC_MII16_LED2		0x0200
166 #define LMC_MII16_LED3		0x0400  /* Error, and the red one */
167 #define LMC_MII16_LED_ALL	0x0780  /* LED bit mask */
168 #define LMC_MII16_FIFO_RESET	0x0800
169 
170 /*
171  * definitions for HSSI
172  */
173 #define LMC_MII16_HSSI_TA	0x0001
174 #define LMC_MII16_HSSI_CA	0x0002
175 #define LMC_MII16_HSSI_LA	0x0004
176 #define LMC_MII16_HSSI_LB	0x0008
177 #define LMC_MII16_HSSI_LC	0x0010
178 #define LMC_MII16_HSSI_TM	0x0020
179 #define LMC_MII16_HSSI_CRC	0x0040
180 
181 /*
182  * assignments for the MII register 16 (DS3)
183  */
184 #define LMC_MII16_DS3_ZERO	0x0001
185 #define LMC_MII16_DS3_TRLBK	0x0002
186 #define LMC_MII16_DS3_LNLBK	0x0004
187 #define LMC_MII16_DS3_RAIS	0x0008
188 #define LMC_MII16_DS3_TAIS	0x0010
189 #define LMC_MII16_DS3_BIST	0x0020
190 #define LMC_MII16_DS3_DLOS	0x0040
191 #define LMC_MII16_DS3_CRC	0x1000
192 #define LMC_MII16_DS3_SCRAM	0x2000
193 
194 /* Note: 2 pairs of LEDs where swapped by mistake
195  * in Xilinx code for DS3 & DS1 adapters */
196 #define LMC_DS3_LED0	0x0100		/* bit 08  yellow */
197 #define LMC_DS3_LED1	0x0080		/* bit 07  blue   */
198 #define LMC_DS3_LED2	0x0400		/* bit 10  green  */
199 #define LMC_DS3_LED3	0x0200		/* bit 09  red    */
200 
201 /*
202  * framer register 0 and 7 (7 is latched and reset on read)
203  */
204 #define LMC_FRAMER_REG0_DLOS	0x80	/* digital loss of service */
205 #define LMC_FRAMER_REG0_OOFS	0x40	/* out of frame sync */
206 #define LMC_FRAMER_REG0_AIS	0x20	/* alarm indication signal */
207 #define LMC_FRAMER_REG0_CIS	0x10	/* channel idle */
208 #define LMC_FRAMER_REG0_LOC	0x08	/* loss of clock */
209 
210 
211 /*
212  * And SSI, LMC1000
213  */
214 #define LMC_MII16_SSI_DTR	0x0001	/* DTR output RW */
215 #define LMC_MII16_SSI_DSR	0x0002	/* DSR input RO */
216 #define LMC_MII16_SSI_RTS	0x0004	/* RTS output RW */
217 #define LMC_MII16_SSI_CTS	0x0008	/* CTS input RO */
218 #define LMC_MII16_SSI_DCD	0x0010	/* DCD input RO */
219 #define LMC_MII16_SSI_RI	0x0020	/* RI input RO */
220 #define LMC_MII16_SSI_CRC	0x1000	/* CRC select - RW */
221 
222 /*
223  * bits 0x0080 through 0x0800 are generic, and described
224  * above with LMC_MII16_LED[0123] _LED_ALL, and _FIFO_RESET
225  */
226 #define LMC_MII16_SSI_LL	0x1000	/* LL output RW */
227 #define LMC_MII16_SSI_RL	0x2000	/* RL output RW */
228 #define LMC_MII16_SSI_TM	0x4000	/* TM input RO */
229 #define LMC_MII16_SSI_LOOP	0x8000	/* loopback enable RW */
230 
231 /*
232  * Some of the MII16 bits are mirrored in the MII17 register as well,
233  * but let's keep thing separate for now, and get only the cable from
234  * the MII17.
235  */
236 #define LMC_MII17_SSI_CABLE_MASK	0x0038	/* mask to extract the cable type */
237 #define LMC_MII17_SSI_CABLE_SHIFT 3	/* shift to extract the cable type */
238 
239 /*
240  * And T1, LMC1200
241  */
242 #define LMC_MII16_T1_UNUSED1    0x0003
243 #define LMC_MII16_T1_XOE                0x0004
244 #define LMC_MII16_T1_RST                0x0008  /* T1 chip reset - RW */
245 #define LMC_MII16_T1_Z                  0x0010  /* output impedance T1=1, E1=0 output - RW */
246 #define LMC_MII16_T1_INTR               0x0020  /* interrupt from 8370 - RO */
247 #define LMC_MII16_T1_ONESEC             0x0040  /* one second square wave - ro */
248 
249 #define LMC_MII16_T1_LED0               0x0100
250 #define LMC_MII16_T1_LED1               0x0080
251 #define LMC_MII16_T1_LED2               0x0400
252 #define LMC_MII16_T1_LED3               0x0200
253 #define LMC_MII16_T1_FIFO_RESET 0x0800
254 
255 #define LMC_MII16_T1_CRC                0x1000  /* CRC select - RW */
256 #define LMC_MII16_T1_UNUSED2    0xe000
257 
258 
259 /* 8370 framer registers  */
260 
261 #define T1FRAMER_ALARM1_STATUS  0x47
262 #define T1FRAMER_ALARM2_STATUS  0x48
263 #define T1FRAMER_FERR_LSB               0x50
264 #define T1FRAMER_FERR_MSB               0x51    /* framing bit error counter */
265 #define T1FRAMER_LCV_LSB                0x54
266 #define T1FRAMER_LCV_MSB                0x55    /* line code violation counter */
267 #define T1FRAMER_AERR                   0x5A
268 
269 /* mask for the above AERR register */
270 #define T1FRAMER_LOF_MASK               (0x0f0) /* receive loss of frame */
271 #define T1FRAMER_COFA_MASK              (0x0c0) /* change of frame alignment */
272 #define T1FRAMER_SEF_MASK               (0x03)  /* severely errored frame  */
273 
274 /* 8370 framer register ALM1 (0x47) values
275  * used to determine link status
276  */
277 
278 #define T1F_SIGFRZ      0x01    /* signaling freeze */
279 #define T1F_RLOF        0x02    /* receive loss of frame alignment */
280 #define T1F_RLOS        0x04    /* receive loss of signal */
281 #define T1F_RALOS       0x08    /* receive analog loss of signal or RCKI loss of clock */
282 #define T1F_RAIS        0x10    /* receive alarm indication signal */
283 #define T1F_UNUSED      0x20
284 #define T1F_RYEL        0x40    /* receive yellow alarm */
285 #define T1F_RMYEL       0x80    /* receive multiframe yellow alarm */
286 
287 /* ------------------ end T1 defs ------------------- */
288 
289 #define LMC_MII_LedMask                 0x0780
290 #define LMC_MII_LedBitPos               7
291 
292 /*
293  * OpenBSD, NetBSD uses _KERNEL, FreeBSD uses KERNEL.
294  */
295 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
296 /*
297  * media independent methods to check on media status, link, light LEDs,
298  * etc.
299  */
300 struct lmc___media {
301 	void	(* init)(lmc_softc_t * const);
302 	void	(* defaults)(lmc_softc_t * const);
303 	void	(* set_status)(lmc_softc_t * const, lmc_ctl_t *);
304 	void	(* set_clock_source)(lmc_softc_t * const, int);
305 	void	(* set_speed)(lmc_softc_t * const, lmc_ctl_t *);
306 	void	(* set_cable_length)(lmc_softc_t * const, int);
307 	void	(* set_scrambler)(lmc_softc_t * const, int);
308 	int	(* get_link_status)(lmc_softc_t * const);
309 	void	(* set_link_status)(lmc_softc_t * const, int);
310 	void	(* set_crc_length)(lmc_softc_t * const, int);
311 	void    (* set_circuit_type)(lmc_softc_t * const, int);
312 	void	(* watchdog)(lmc_softc_t * const);
313 };
314 
315 u_int32_t lmc_mii_readreg(lmc_softc_t * const sc, u_int32_t devaddr,
316 			  u_int32_t regno);
317 void lmc_mii_writereg(lmc_softc_t * const sc, u_int32_t devaddr,
318 		      u_int32_t regno, u_int32_t data);
319 void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base,
320 		  size_t csr_size);
321 void lmc_dec_reset(lmc_softc_t * const sc);
322 void lmc_reset(lmc_softc_t * const sc);
323 void lmc_led_on(lmc_softc_t * const sc, u_int32_t led);
324 void lmc_led_off(lmc_softc_t * const sc, u_int32_t led);
325 void lmc_gpio_mkinput(lmc_softc_t * const sc, u_int32_t bits);
326 void lmc_gpio_mkoutput(lmc_softc_t * const sc, u_int32_t bits);
327 lmc_intrfunc_t lmc_intr_normal(void *);
328 int lmc_read_macaddr(lmc_softc_t * const sc);
329 void lmc_attach(lmc_softc_t * const sc);
330 void lmc_initring(lmc_softc_t * const sc, lmc_ringinfo_t * const ri,
331 		  tulip_desc_t *descs, int ndescs);
332 #endif /* LMC_IS_KERNEL */
333