2 * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved.
3 * Author: Denis I.Timofeev <timofeev@granch.ru>
5 * Redistributon and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/sbni/if_sbni_isa.c,v 1.1.2.5 2002/08/11 09:32:00 fjoe Exp $
28 * $DragonFly: src/sys/dev/netif/sbni/Attic/if_sbni_isa.c,v 1.4 2004/01/06 01:40:48 dillon Exp $
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/socket.h>
37 #include <sys/bus_private.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
45 #include <net/ethernet.h>
46 #include <net/if_arp.h>
48 #include <bus/isa/isavar.h>
50 #include "if_sbnireg.h"
51 #include "if_sbnivar.h"
53 static int sbni_probe_isa(device_t);
54 static int sbni_attach_isa(device_t);
56 static device_method_t sbni_isa_methods[] = {
57 /* Device interface */
58 DEVMETHOD(device_probe, sbni_probe_isa),
59 DEVMETHOD(device_attach, sbni_attach_isa),
63 static driver_t sbni_isa_driver = {
66 sizeof(struct sbni_softc)
69 static devclass_t sbni_isa_devclass;
70 static struct isa_pnp_id sbni_ids[] = {
71 { 0, NULL } /* we have no pnp sbni cards atm. */
74 DRIVER_MODULE(if_sbni, isa, sbni_isa_driver, sbni_isa_devclass, 0, 0);
78 sbni_probe_isa(device_t dev)
80 struct sbni_softc *sc;
83 error = ISA_PNP_PROBE(device_get_parent(dev), dev, sbni_ids);
84 if (error && error != ENOENT)
87 sc = device_get_softc(dev);
88 bzero(sc, sizeof(struct sbni_softc));
90 sc->io_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->io_rid,
91 0ul, ~0ul, SBNI_PORTS, RF_ACTIVE);
93 printf("sbni: cannot allocate io ports!\n");
97 if (sbni_probe(sc) != 0) {
98 bus_release_resource(dev, SYS_RES_IOPORT,
99 sc->io_rid, sc->io_res);
109 sbni_attach_isa(device_t dev)
111 struct sbni_softc *sc;
112 struct sbni_flags flags;
115 sc = device_get_softc(dev);
117 printf("sbni%d: <Granch SBNI12/ISA adapter> port 0x%lx",
118 next_sbni_unit, rman_get_start(sc->io_res));
119 sc->irq_res = bus_alloc_resource(
120 dev, SYS_RES_IRQ, &sc->irq_rid, 0ul, ~0ul, 1, RF_ACTIVE);
123 printf(" irq %ld\n", rman_get_start(sc->irq_res));
124 error = bus_setup_intr(
125 dev, sc->irq_res, INTR_TYPE_NET,
126 sbni_intr, sc, &sc->irq_handle);
128 printf("sbni%d: bus_setup_intr\n", next_sbni_unit);
129 bus_release_resource(
130 dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res);
131 bus_release_resource(
132 dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res);
136 #ifndef SBNI_DUAL_COMPOUND
139 printf("\nsbni%d: irq conflict!\n", next_sbni_unit);
140 bus_release_resource(dev, SYS_RES_IOPORT,
141 sc->io_rid, sc->io_res);
145 #else /* SBNI_DUAL_COMPOUND */
147 sc->link = sbni_headlist;
150 struct sbni_softc *master;
152 if ((master = connect_to_master(sc)) == 0) {
153 printf("\nsbni%d: failed to alloc irq\n",
155 bus_release_resource(
156 dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res);
159 printf(" shared irq with %s\n",
160 master->arpcom.ac_if.if_xname);
163 #endif /* SBNI_DUAL_COMPOUND */
165 *(u_int32_t*)&flags = device_get_flags(dev);
167 sbni_attach(sc, next_sbni_unit++, flags);