if_sbni_isa.c revision 86752
1233294Sstas/*
2233294Sstas * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved.
3233294Sstas * Author: Denis I.Timofeev <timofeev@granch.ru>
455682Smarkm *
5233294Sstas * Redistributon and use in source and binary forms, with or without
6233294Sstas * modification, are permitted provided that the following conditions
7233294Sstas * are met:
8120945Snectar * 1. Redistributions of source code must retain the above copyright
9233294Sstas *    notice unmodified, this list of conditions, and the following
10233294Sstas *    disclaimer.
11120945Snectar * 2. Redistributions in binary form must reproduce the above copyright
12233294Sstas *    notice, this list of conditions and the following disclaimer in the
13233294Sstas *    documentation and/or other materials provided with the distribution.
14233294Sstas *
15120945Snectar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18233294Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19120945Snectar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23233294Sstas * LIABILITY, OR TORT (INCLUDING NEIGENCE OR OTHERWISE) ARISING IN ANY WAY
24233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25233294Sstas * SUCH DAMAGE.
26233294Sstas *
27233294Sstas * $FreeBSD: head/sys/dev/sbni/if_sbni_isa.c 86752 2001-11-21 22:29:35Z fjoe $
28233294Sstas */
29233294Sstas
30233294Sstas
31120945Snectar#include <sys/param.h>
32233294Sstas#include <sys/systm.h>
33233294Sstas#include <sys/socket.h>
34178825Sdfr
3555682Smarkm#include <sys/bus.h>
3655682Smarkm#include <sys/bus_private.h>
3755682Smarkm#include <sys/kernel.h>
3855682Smarkm#include <sys/module.h>
3976371Sassar#include <machine/bus.h>
4055682Smarkm#include <machine/resource.h>
4155682Smarkm#include <sys/rman.h>
42233294Sstas
43178825Sdfr#include <net/if.h>
44233294Sstas#include <net/ethernet.h>
45178825Sdfr#include <net/if_arp.h>
46178825Sdfr
47178825Sdfr#include <isa/isavar.h>
4855682Smarkm
4955682Smarkm#include <dev/sbni/if_sbnireg.h>
5055682Smarkm#include <dev/sbni/if_sbnivar.h>
51178825Sdfr
52178825Sdfrstatic int	sbni_probe_isa(device_t);
53178825Sdfrstatic int	sbni_attach_isa(device_t);
54178825Sdfr
55178825Sdfrstatic device_method_t sbni_isa_methods[] = {
56178825Sdfr	/* Device interface */
57178825Sdfr	DEVMETHOD(device_probe,	sbni_probe_isa),
58178825Sdfr	DEVMETHOD(device_attach, sbni_attach_isa),
59178825Sdfr	{ 0, 0 }
60178825Sdfr};
61233294Sstas
62178825Sdfrstatic driver_t sbni_isa_driver = {
63178825Sdfr	"sbni",
6455682Smarkm	sbni_isa_methods,
6555682Smarkm	sizeof(struct sbni_softc)
6655682Smarkm};
6755682Smarkm
6855682Smarkmstatic devclass_t sbni_isa_devclass;
69static struct isa_pnp_id  sbni_ids[] = {
70	{ 0, NULL }	/* we have no pnp sbni cards atm.  */
71};
72
73DRIVER_MODULE(sbni, isa, sbni_isa_driver, sbni_isa_devclass, 0, 0);
74
75
76static int
77sbni_probe_isa(device_t dev)
78{
79	struct sbni_softc *sc;
80	int error;
81
82	error = ISA_PNP_PROBE(device_get_parent(dev), dev, sbni_ids);
83	if (error && error != ENOENT)
84		return (error);
85
86	sc = device_get_softc(dev);
87	bzero(sc, sizeof(struct sbni_softc));
88
89 	sc->io_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->io_rid,
90					0ul, ~0ul, SBNI_PORTS, RF_ACTIVE);
91	if (!sc->io_res) {
92		printf("sbni: cannot allocate io ports!\n");
93		return (ENOENT);
94	}
95
96	sc->base_addr = rman_get_start(sc->io_res);
97	if (sbni_probe(sc) != 0) {
98		bus_release_resource(dev, SYS_RES_IOPORT,
99				     sc->io_rid, sc->io_res);
100		return (ENXIO);
101	}
102
103	device_quiet(dev);
104	return (0);
105}
106
107
108static int
109sbni_attach_isa(device_t dev)
110{
111	struct sbni_softc *sc;
112	struct sbni_flags flags;
113	int error;
114
115	sc = device_get_softc(dev);
116
117	printf("sbni%d: <Granch SBNI12/ISA adapter> port 0x%x",
118	       next_sbni_unit, sc->base_addr);
119	sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
120					 0ul, ~0ul, 1, RF_ACTIVE);
121
122	if (sc->irq_res) {
123		printf(" irq %ld\n", rman_get_start(sc->irq_res));
124		error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
125				       sbni_intr, sc, &sc->irq_handle);
126		if (error) {
127			printf("sbni%d: bus_setup_intr\n", next_sbni_unit);
128			bus_release_resource(dev, SYS_RES_IOPORT,
129					     sc->io_rid, sc->io_res);
130			return (error);
131		}
132
133#ifndef SBNI_DUAL_COMPOUND
134
135	} else {
136		printf("\nsbni%d: irq conflict!\n", next_sbni_unit);
137		bus_release_resource(dev, SYS_RES_IOPORT,
138				     sc->io_rid, sc->io_res);
139		return (ENOENT);
140	}
141
142#else	/* SBNI_DUAL_COMPOUND */
143
144		sc->link = headlist;
145		headlist = sc;
146	} else {
147		struct sbni_softc  *master;
148
149		if ((master = connect_to_master(sc)) == 0) {
150			printf("\nsbni%d: failed to alloc irq\n",
151			       next_sbni_unit);
152			bus_release_resource(dev, SYS_RES_IOPORT,
153					     sc->io_rid, sc->io_res);
154			return (ENXIO);
155		} else
156			printf(" shared irq with sbni%d\n",
157			       master->arpcom.ac_if.if_unit);
158	}
159#endif	/* SBNI_DUAL_COMPOUND */
160
161	*(u_int32_t*)&flags = device_get_flags(dev);
162
163	sbni_attach(sc, next_sbni_unit++, flags);
164	return (0);
165}
166