if_snc_cbus.c revision 66550
166550Snyan/* 266550Snyan * Copyright (c) 1995, David Greenman 366550Snyan * All rights reserved. 466550Snyan * 566550Snyan * Redistribution and use in source and binary forms, with or without 666550Snyan * modification, are permitted provided that the following conditions 766550Snyan * are met: 866550Snyan * 1. Redistributions of source code must retain the above copyright 966550Snyan * notice unmodified, this list of conditions, and the following 1066550Snyan * disclaimer. 1166550Snyan * 2. Redistributions in binary form must reproduce the above copyright 1266550Snyan * notice, this list of conditions and the following disclaimer in the 1366550Snyan * documentation and/or other materials provided with the distribution. 1466550Snyan * 1566550Snyan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1666550Snyan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1766550Snyan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1866550Snyan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1966550Snyan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2066550Snyan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2166550Snyan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2266550Snyan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366550Snyan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2466550Snyan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2566550Snyan * SUCH DAMAGE. 2666550Snyan * 2766550Snyan * $FreeBSD: head/sys/dev/snc/if_snc_cbus.c 66550 2000-10-02 14:27:20Z nyan $ 2866550Snyan */ 2966550Snyan 3066550Snyan/* 3166550Snyan * National Semiconductor DP8393X SONIC Driver 3266550Snyan * 3366550Snyan * This is the C-bus specific attachment on FreeBSD 3466550Snyan * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp> 3566550Snyan */ 3666550Snyan 3766550Snyan#include <sys/param.h> 3866550Snyan#include <sys/systm.h> 3966550Snyan#include <sys/socket.h> 4066550Snyan#include <sys/kernel.h> 4166550Snyan 4266550Snyan#include <sys/module.h> 4366550Snyan#include <sys/bus.h> 4466550Snyan#include <machine/bus.h> 4566550Snyan#include <sys/rman.h> 4666550Snyan#include <machine/resource.h> 4766550Snyan 4866550Snyan#include <net/ethernet.h> 4966550Snyan#include <net/if.h> 5066550Snyan#include <net/if_arp.h> 5166550Snyan#include <net/if_media.h> 5266550Snyan#include <net/if_mib.h> 5366550Snyan 5466550Snyan#include <isa/isavar.h> 5566550Snyan#include <isa/pnpvar.h> 5666550Snyan#include <sys/malloc.h> /* as dependency for isa/isa_common.h */ 5766550Snyan#include <isa/isa_common.h> /* for snc_isapnp_reconfig() */ 5866550Snyan 5966550Snyan#include <dev/snc/dp83932var.h> 6066550Snyan#include <dev/snc/dp83932subr.h> 6166550Snyan#include <dev/snc/if_sncreg.h> 6266550Snyan#include <dev/snc/if_sncvar.h> 6366550Snyan 6466550Snyanstatic void snc_isapnp_reconfig __P((device_t)); 6566550Snyanstatic int snc_isa_probe __P((device_t)); 6666550Snyanstatic int snc_isa_attach __P((device_t)); 6766550Snyan 6866550Snyanstatic struct isa_pnp_id snc_ids[] = { 6966550Snyan { 0x6180a3b8, NULL }, /* NEC8061 NEC PC-9801-104 */ 7066550Snyan { 0, NULL } 7166550Snyan}; 7266550Snyan 7366550Snyanstatic void 7466550Snyansnc_isapnp_reconfig(dev) 7566550Snyan device_t dev; 7666550Snyan{ 7766550Snyan struct isa_device *idev = DEVTOISA(dev); 7866550Snyan struct isa_config config; 7966550Snyan u_long start, count; 8066550Snyan int rid; 8166550Snyan 8266550Snyan bzero(&config, sizeof(config)); 8366550Snyan 8466550Snyan for (rid = 0; rid < ISA_NMEM; rid++) { 8566550Snyan if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count)) 8666550Snyan break; 8766550Snyan config.ic_mem[rid].ir_start = start; 8866550Snyan config.ic_mem[rid].ir_end = start; 8966550Snyan config.ic_mem[rid].ir_size = count; 9066550Snyan } 9166550Snyan config.ic_nmem = rid; 9266550Snyan for (rid = 0; rid < ISA_NPORT; rid++) { 9366550Snyan if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count)) 9466550Snyan break; 9566550Snyan config.ic_port[rid].ir_start = start; 9666550Snyan config.ic_port[rid].ir_end = start; 9766550Snyan config.ic_port[rid].ir_size = count; 9866550Snyan } 9966550Snyan config.ic_nport = rid; 10066550Snyan for (rid = 0; rid < ISA_NIRQ; rid++) { 10166550Snyan if (bus_get_resource(dev, SYS_RES_IRQ, rid, &start, &count)) 10266550Snyan break; 10366550Snyan config.ic_irqmask[rid] = 1 << start; 10466550Snyan } 10566550Snyan config.ic_nirq = rid; 10666550Snyan for (rid = 0; rid < ISA_NDRQ; rid++) { 10766550Snyan if (bus_get_resource(dev, SYS_RES_DRQ, rid, &start, &count)) 10866550Snyan break; 10966550Snyan config.ic_drqmask[rid] = 1 << start; 11066550Snyan } 11166550Snyan config.ic_ndrq = rid; 11266550Snyan 11366550Snyan idev->id_config_cb(idev->id_config_arg, &config, 1); 11466550Snyan} 11566550Snyan 11666550Snyanstatic int 11766550Snyansnc_isa_probe(dev) 11866550Snyan device_t dev; 11966550Snyan{ 12066550Snyan struct snc_softc *sc = device_get_softc(dev); 12166550Snyan int type; 12266550Snyan int error = 0; 12366550Snyan 12466550Snyan bzero(sc, sizeof(struct snc_softc)); 12566550Snyan 12666550Snyan /* Check isapnp ids */ 12766550Snyan error = ISA_PNP_PROBE(device_get_parent(dev), dev, snc_ids); 12866550Snyan 12966550Snyan /* If the card had a PnP ID that didn't match any we know about */ 13066550Snyan if (error == ENXIO) { 13166550Snyan return(error); 13266550Snyan } 13366550Snyan 13466550Snyan switch (error) { 13566550Snyan case 0: /* Matched PnP */ 13666550Snyan type = SNEC_TYPE_PNP; 13766550Snyan break; 13866550Snyan 13966550Snyan case ENOENT: /* Legacy ISA */ 14066550Snyan type = SNEC_TYPE_LEGACY; 14166550Snyan break; 14266550Snyan 14366550Snyan default: /* If we had some other problem. */ 14466550Snyan return(error); 14566550Snyan } 14666550Snyan 14766550Snyan if (type == SNEC_TYPE_PNP && isa_get_portsize(dev) == 0) { 14866550Snyan int port; 14966550Snyan int rid = 0; 15066550Snyan struct resource *res = NULL; 15166550Snyan 15266550Snyan for (port = 0x0888; port <= 0x3888; port += 0x1000) { 15366550Snyan bus_set_resource(dev, SYS_RES_IOPORT, rid, 15466550Snyan port, SNEC_NREGS); 15566550Snyan res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 15666550Snyan 0, ~0, SNEC_NREGS, 15766550Snyan 0 /* !RF_ACTIVE */); 15866550Snyan if (res) break; 15966550Snyan } 16066550Snyan 16166550Snyan printf("snc_isa_probe: broken PnP resource, "); 16266550Snyan if (res) { 16366550Snyan printf("use port 0x%x\n", port); 16466550Snyan bus_release_resource(dev, SYS_RES_IOPORT, rid, res); 16566550Snyan snc_isapnp_reconfig(dev); 16666550Snyan } else { 16766550Snyan printf("and can't find port\n"); 16866550Snyan } 16966550Snyan } 17066550Snyan 17166550Snyan error = snc_alloc_port(dev, 0); 17266550Snyan error = max(error, snc_alloc_memory(dev, 0)); 17366550Snyan error = max(error, snc_alloc_irq(dev, 0, 0)); 17466550Snyan 17566550Snyan if (!error && !snc_probe(dev, type)) 17666550Snyan error = ENOENT; 17766550Snyan 17866550Snyan snc_release_resources(dev); 17966550Snyan return (error); 18066550Snyan} 18166550Snyan 18266550Snyanstatic int 18366550Snyansnc_isa_attach(dev) 18466550Snyan device_t dev; 18566550Snyan{ 18666550Snyan struct snc_softc *sc = device_get_softc(dev); 18766550Snyan int error; 18866550Snyan 18966550Snyan bzero(sc, sizeof(struct snc_softc)); 19066550Snyan 19166550Snyan snc_alloc_port(dev, 0); 19266550Snyan snc_alloc_memory(dev, 0); 19366550Snyan snc_alloc_irq(dev, 0, 0); 19466550Snyan 19566550Snyan error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, 19666550Snyan sncintr, sc, &sc->irq_handle); 19766550Snyan if (error) { 19866550Snyan printf("snc_isa_attach: bus_setup_intr() failed\n"); 19966550Snyan snc_release_resources(dev); 20066550Snyan return (error); 20166550Snyan } 20266550Snyan 20366550Snyan /* This interface is always enabled. */ 20466550Snyan sc->sc_enabled = 1; 20566550Snyan 20666550Snyan return snc_attach(dev); 20766550Snyan} 20866550Snyan 20966550Snyanstatic device_method_t snc_isa_methods[] = { 21066550Snyan /* Device interface */ 21166550Snyan DEVMETHOD(device_probe, snc_isa_probe), 21266550Snyan DEVMETHOD(device_attach, snc_isa_attach), 21366550Snyan DEVMETHOD(device_shutdown, snc_shutdown), 21466550Snyan 21566550Snyan { 0, 0 } 21666550Snyan}; 21766550Snyan 21866550Snyanstatic driver_t snc_isa_driver = { 21966550Snyan "snc", 22066550Snyan snc_isa_methods, 22166550Snyan sizeof(struct snc_softc) 22266550Snyan}; 22366550Snyan 22466550SnyanDRIVER_MODULE(if_snc, isa, snc_isa_driver, snc_devclass, 0, 0); 225