kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / net / i4b / layer1 / isic / i4b_siemens_isurf.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1999, 2000 Udo Schweigert. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 * 4. Altered versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software and/or documentation.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 *---------------------------------------------------------------------------
32 *
33 * Siemens I-Surf 2.0 PnP specific routines for isic driver
34 * --------------------------------------------------------
35 *
36 * Based on ELSA Quickstep 1000pro PCI driver (i4b_elsa_qs1p.c)
37 * In case of trouble please contact Udo Schweigert <ust@cert.siemens.de>
38
39 * $FreeBSD: src/sys/i4b/layer1/isic/i4b_siemens_isurf.c,v 1.5.2.1 2001/08/10 14:08:38 obrien Exp $
d2438d69 40 * $DragonFly: src/sys/net/i4b/layer1/isic/i4b_siemens_isurf.c,v 1.4 2003/08/07 21:54:31 dillon Exp $
984263bc
MD
41 *
42 * last edit-date: [Wed Jan 24 09:13:25 2001]
43 *
44 *---------------------------------------------------------------------------*/
45
1f2de5d4 46#include "use_isic.h"
984263bc
MD
47#include "opt_i4b.h"
48
49#if NISIC > 0 && defined(SIEMENS_ISURF2)
50
51#include <sys/param.h>
52#include <sys/systm.h>
53#include <sys/socket.h>
54
55#include <net/if.h>
56
d2438d69 57#include <net/i4b/include/machine/i4b_ioctl.h>
984263bc 58
1f2de5d4
MD
59#include "i4b_isic.h"
60#include "i4b_ipac.h"
984263bc
MD
61
62/* masks for register encoded in base addr */
63
64#define SIE_ISURF_BASE_MASK 0x0ffff
65#define SIE_ISURF_OFF_MASK 0xf0000
66
67/* register id's to be encoded in base addr */
68
69#define SIE_ISURF_IDISAC 0x00000
70#define SIE_ISURF_IDHSCXA 0x10000
71#define SIE_ISURF_IDHSCXB 0x20000
72#define SIE_ISURF_IDIPAC 0x40000
73
74/* offsets from base address */
75
76#define SIE_ISURF_OFF_ALE 0x00
77#define SIE_ISURF_OFF_RW 0x01
78
79/*---------------------------------------------------------------------------*
80 * Siemens I-Surf 2.0 PnP ISAC get fifo routine
81 *---------------------------------------------------------------------------*/
82static void
83siemens_isurf_read_fifo(struct l1_softc *sc,int what,void *buf,size_t size)
84{
85 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
86 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
87
88 switch ( what )
89 {
90 case ISIC_WHAT_ISAC:
91 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,IPAC_ISAC_OFF);
92 bus_space_read_multi_1(t,h,SIE_ISURF_OFF_RW,buf,size);
93 break;
94 case ISIC_WHAT_HSCXA:
95 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,IPAC_HSCXA_OFF);
96 bus_space_read_multi_1(t,h,SIE_ISURF_OFF_RW,buf,size);
97 break;
98 case ISIC_WHAT_HSCXB:
99 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,IPAC_HSCXB_OFF);
100 bus_space_read_multi_1(t,h,SIE_ISURF_OFF_RW,buf,size);
101 break;
102 }
103}
104
105/*---------------------------------------------------------------------------*
106 * Siemens I-Surf 2.0 PnP ISAC put fifo routine
107 *---------------------------------------------------------------------------*/
108static void
109siemens_isurf_write_fifo(struct l1_softc *sc,int what,void *buf,size_t size)
110{
111 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
112 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
113
114 switch ( what )
115 {
116 case ISIC_WHAT_ISAC:
117 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,IPAC_ISAC_OFF);
118 bus_space_write_multi_1(t,h,SIE_ISURF_OFF_RW,buf,size);
119 break;
120 case ISIC_WHAT_HSCXA:
121 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,IPAC_HSCXA_OFF);
122 bus_space_write_multi_1(t,h,SIE_ISURF_OFF_RW,buf,size);
123 break;
124 case ISIC_WHAT_HSCXB:
125 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,IPAC_HSCXB_OFF);
126 bus_space_write_multi_1(t,h,SIE_ISURF_OFF_RW,buf,size);
127 break;
128 }
129}
130
131/*---------------------------------------------------------------------------*
132 * Siemens I-Surf 2.0 PnP ISAC put register routine
133 *---------------------------------------------------------------------------*/
134static void
135siemens_isurf_write_reg(struct l1_softc *sc,int what,bus_size_t reg,u_int8_t data)
136{
137 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
138 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
139
140 switch ( what )
141 {
142 case ISIC_WHAT_ISAC:
143 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_ISAC_OFF);
144 bus_space_write_1(t,h,SIE_ISURF_OFF_RW,data);
145 break;
146 case ISIC_WHAT_HSCXA:
147 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_HSCXA_OFF);
148 bus_space_write_1(t,h,SIE_ISURF_OFF_RW,data);
149 break;
150 case ISIC_WHAT_HSCXB:
151 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_HSCXB_OFF);
152 bus_space_write_1(t,h,SIE_ISURF_OFF_RW,data);
153 break;
154 case ISIC_WHAT_IPAC:
155 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_IPAC_OFF);
156 bus_space_write_1(t,h,SIE_ISURF_OFF_RW,data);
157 break;
158 }
159}
160
161/*---------------------------------------------------------------------------*
162 * Siemens I-Surf 2.0 PnP ISAC get register routine
163 *---------------------------------------------------------------------------*/
164static u_int8_t
165siemens_isurf_read_reg(struct l1_softc *sc,int what,bus_size_t reg)
166{
167 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
168 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
169
170 switch ( what )
171 {
172 case ISIC_WHAT_ISAC:
173 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_ISAC_OFF);
174 return bus_space_read_1(t,h,SIE_ISURF_OFF_RW);
175 case ISIC_WHAT_HSCXA:
176 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_HSCXA_OFF);
177 return bus_space_read_1(t,h,SIE_ISURF_OFF_RW);
178 case ISIC_WHAT_HSCXB:
179 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_HSCXB_OFF);
180 return bus_space_read_1(t,h,SIE_ISURF_OFF_RW);
181 case ISIC_WHAT_IPAC:
182 bus_space_write_1(t,h,SIE_ISURF_OFF_ALE,reg+IPAC_IPAC_OFF);
183 return bus_space_read_1(t,h,SIE_ISURF_OFF_RW);
184 default:
185 return 0;
186 }
187}
188
189/*---------------------------------------------------------------------------*
190 * isic_attach_siemens_isurf - attach for Siemens I-Surf 2.0 PnP
191 *---------------------------------------------------------------------------*/
192int
193isic_attach_siemens_isurf(device_t dev)
194{
195 int unit = device_get_unit(dev);
196 struct l1_softc *sc = &l1_sc[unit];
197
198 /* setup access routines */
199
200 sc->clearirq = NULL;
201 sc->readreg = siemens_isurf_read_reg;
202 sc->writereg = siemens_isurf_write_reg;
203
204 sc->readfifo = siemens_isurf_read_fifo;
205 sc->writefifo = siemens_isurf_write_fifo;
206
207 /* setup card type */
208
209 sc->sc_cardtyp = CARD_TYPEP_SIE_ISURF2;
210
211 /* setup IOM bus type */
212
213 sc->sc_bustyp = BUS_TYPE_IOM2;
214
215 /* setup chip type = IPAC ! */
216
217 sc->sc_ipac = 1;
218 sc->sc_bfifolen = IPAC_BFIFO_LEN;
219
220 /* enable hscx/isac irq's */
221
222 IPAC_WRITE(IPAC_MASK, (IPAC_MASK_INT1 | IPAC_MASK_INT0));
223
224 IPAC_WRITE(IPAC_ACFG, 0); /* outputs are open drain */
225 IPAC_WRITE(IPAC_AOE, /* aux 5..2 are inputs, 7, 6 outputs */
226 (IPAC_AOE_OE5 | IPAC_AOE_OE4 | IPAC_AOE_OE3 | IPAC_AOE_OE2));
227 IPAC_WRITE(IPAC_ATX, 0xff); /* set all output lines high */
228
229 return(0);
230}
231#endif /* NISIC > 0 && defined(SIEMENS_ISURF2) */