if_ed_sic.c revision 141586
1/*-
2 * Copyright (c) 2005, M. Warner Losh
3 * All rights reserved.
4 * Copyright (c) 1995, David Greenman
5 * 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 unmodified, this list of conditions, and the following
12 *    disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/ed/if_ed_sic.c 141586 2005-02-09 20:03:40Z imp $");
32
33#include "opt_ed.h"
34
35#ifdef ED_SIC
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sockio.h>
39#include <sys/mbuf.h>
40#include <sys/kernel.h>
41#include <sys/socket.h>
42#include <sys/syslog.h>
43
44#include <sys/bus.h>
45
46#include <machine/bus.h>
47#include <sys/rman.h>
48#include <machine/resource.h>
49
50#include <net/ethernet.h>
51#include <net/if.h>
52#include <net/if_arp.h>
53#include <net/if_dl.h>
54#include <net/if_mib.h>
55#include <net/if_media.h>
56
57#include <net/bpf.h>
58
59#include <dev/ed/if_edreg.h>
60#include <dev/ed/if_edvar.h>
61
62/*
63 * Probe and vendor-specific initialization routine for SIC boards
64 */
65int
66ed_probe_SIC(device_t dev, int port_rid, int flags)
67{
68	struct ed_softc *sc = device_get_softc(dev);
69	int	error;
70	int	i;
71	u_int	memsize;
72	u_long	pmem;
73	u_char	sum;
74
75	error = ed_alloc_port(dev, 0, ED_SIC_IO_PORTS);
76	if (error)
77		return (error);
78
79	sc->asic_offset = ED_SIC_ASIC_OFFSET;
80	sc->nic_offset  = ED_SIC_NIC_OFFSET;
81
82	memsize = 16384;
83	/* XXX Needs to allow different msize */
84	error = ed_alloc_memory(dev, 0, memsize);
85	if (error)
86		return (error);
87
88	sc->mem_start = (caddr_t) rman_get_virtual(sc->mem_res);
89	sc->mem_size  = memsize;
90
91	pmem = rman_get_start(sc->mem_res);
92	error = ed_isa_mem_ok(dev, pmem, memsize);
93	if (error)
94		return (error);
95
96	/* Reset card to force it into a known state. */
97	ed_asic_outb(sc, 0, 0x00);
98	DELAY(100);
99
100	/*
101	 * Here we check the card ROM, if the checksum passes, and the
102	 * type code and ethernet address check out, then we know we have
103	 * an SIC card.
104	 */
105	ed_asic_outb(sc, 0, 0x81);
106	DELAY(100);
107
108	sum = sc->mem_start[6];
109	for (i = 0; i < ETHER_ADDR_LEN; i++) {
110		sum ^= (sc->arpcom.ac_enaddr[i] = sc->mem_start[i]);
111	}
112#ifdef ED_DEBUG
113	device_printf(dev, "ed_probe_sic: got address %6D\n",
114		      sc->arpcom.ac_enaddr, ":");
115#endif
116	if (sum != 0) {
117		return (ENXIO);
118	}
119	if ((sc->arpcom.ac_enaddr[0] | sc->arpcom.ac_enaddr[1] |
120	     sc->arpcom.ac_enaddr[2]) == 0) {
121		return (ENXIO);
122	}
123
124	sc->vendor   = ED_VENDOR_SIC;
125	sc->type_str = "SIC";
126	sc->isa16bit = 0;
127	sc->cr_proto = 0;
128
129	/*
130	 * SIC RAM page 0x0000-0x3fff(or 0x7fff)
131	 */
132	ed_asic_outb(sc, 0, 0x80);
133	DELAY(100);
134
135	error = ed_clear_memory(dev);
136	if (error)
137		return (error);
138
139	sc->mem_shared = 1;
140	sc->mem_end = sc->mem_start + sc->mem_size;
141
142	/*
143	 * allocate one xmit buffer if < 16k, two buffers otherwise
144	 */
145	if ((sc->mem_size < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING))
146		sc->txb_cnt = 1;
147	else
148		sc->txb_cnt = 2;
149	sc->tx_page_start = 0;
150
151	sc->rec_page_start = sc->tx_page_start + ED_TXBUF_SIZE * sc->txb_cnt;
152	sc->rec_page_stop = sc->tx_page_start + sc->mem_size / ED_PAGE_SIZE;
153
154	sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
155
156	return (0);
157}
158
159#endif /* ED_SIL */
160