if_fe_pccard.c revision 140543
1139749Simp/*- 265832Snyan * All Rights Reserved, Copyright (C) Fujitsu Limited 1995 365832Snyan * 465832Snyan * This software may be used, modified, copied, distributed, and sold, in 565832Snyan * both source and binary form provided that the above copyright, these 665832Snyan * terms and the following disclaimer are retained. The name of the author 765832Snyan * and/or the contributor may not be used to endorse or promote products 865832Snyan * derived from this software without specific prior written permission. 965832Snyan * 1065832Snyan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND 1165832Snyan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1265832Snyan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1365832Snyan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE 1465832Snyan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1565832Snyan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1665832Snyan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION. 1765832Snyan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1865832Snyan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1965832Snyan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2065832Snyan * SUCH DAMAGE. 2165832Snyan * 2265832Snyan */ 2365832Snyan 24119418Sobrien#include <sys/cdefs.h> 25119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/fe/if_fe_pccard.c 140543 2005-01-21 02:14:40Z imp $"); 26119418Sobrien 2765832Snyan#include <sys/param.h> 2865832Snyan#include <sys/kernel.h> 2965832Snyan#include <sys/socket.h> 3067158Sphk#include <sys/systm.h> 3165832Snyan#include <sys/module.h> 3265832Snyan 3365832Snyan#include <sys/bus.h> 3465832Snyan#include <machine/bus.h> 3565832Snyan#include <machine/resource.h> 36140543Simp#include <sys/rman.h> 3765832Snyan 3865832Snyan#include <net/ethernet.h> 3965832Snyan#include <net/if.h> 4065832Snyan#include <net/if_mib.h> 4165832Snyan#include <net/if_media.h> 4265832Snyan 4365832Snyan#include <netinet/in.h> 4465832Snyan#include <netinet/if_ether.h> 4565832Snyan 4665832Snyan#include <i386/isa/ic/mb86960.h> 4765832Snyan#include <dev/fe/if_fereg.h> 4865832Snyan#include <dev/fe/if_fevar.h> 4965832Snyan 5065832Snyan#include <dev/pccard/pccardvar.h> 51140528Simp#include <dev/pccard/pccard_cis.h> 52129764Simp 53129764Simp#include "card_if.h" 54129740Simp#include "pccarddevs.h" 5565832Snyan 5665832Snyan/* 5765832Snyan * PC-Card (PCMCIA) specific code. 5865832Snyan */ 5965832Snyanstatic int fe_pccard_probe(device_t); 6065832Snyanstatic int fe_pccard_attach(device_t); 6165832Snyanstatic int fe_pccard_detach(device_t); 6282778Sshibastatic int fe_pccard_match(device_t); 63140543Simpstatic int fe_pccard_mem_ether(device_t dev, bus_addr_t cardoff, 64140543Simp u_char *enaddr); 6565832Snyan 6682778Sshibastatic const struct fe_pccard_product { 6782778Sshiba struct pccard_product mpp_product; 68140041Simp uint32_t mpp_ioalign; /* required alignment */ 6982778Sshiba int mpp_enet_maddr; 70140041Simp int mpp_flags; 71140543Simp#define MPP_MBH10302 1 7282778Sshiba} fe_pccard_products[] = { 73140041Simp /* These need to be first */ 74140543Simp { PCMCIA_CARD(FUJITSU2, FMV_J181, 0), 0, -1, MPP_MBH10302}, 75140041Simp { PCMCIA_CARD(FUJITSU2, FMV_J182, 0), 0, 0xf2c}, 76140041Simp { PCMCIA_CARD(FUJITSU2, FMV_J182A, 0), 0, 0x1cc}, 77140041Simp { PCMCIA_CARD(FUJITSU2, ITCFJ182A, 0), 0, 0x1cc}, 78140041Simp /* These need to be second */ 7986394Simp { PCMCIA_CARD(TDK, LAK_CD021BX, 0), 0, -1 }, 8086394Simp { PCMCIA_CARD(TDK, LAK_CF010, 0), 0, -1 }, 8182778Sshiba#if 0 /* XXX 86960-based? */ 8286394Simp { PCMCIA_CARD(TDK, LAK_DFL9610, 1), 0, -1 }, 8382778Sshiba#endif 8486394Simp { PCMCIA_CARD(CONTEC, CNETPC, 0), 0, -1 }, 8586394Simp { PCMCIA_CARD(FUJITSU, LA501, 0), 0x20, -1 }, 8686394Simp { PCMCIA_CARD(FUJITSU, LA10S, 0), 0, -1 }, 87140543Simp { PCMCIA_CARD(FUJITSU, NE200T, 0), 0, -1, MPP_MBH10302},/* Sold by Eagle */ 8886394Simp { PCMCIA_CARD(RATOC, REX_R280, 0), 0, 0x1fc }, 8982778Sshiba { { NULL } } 9082778Sshiba}; 9182778Sshiba 9282778Sshibastatic int 9382778Sshibafe_pccard_match(device_t dev) 9482778Sshiba{ 9582778Sshiba const struct pccard_product *pp; 96140528Simp int error; 97140528Simp uint32_t fcn = PCCARD_FUNCTION_UNSPEC; 9882778Sshiba 99140528Simp /* Make sure we're a network function */ 100140528Simp error = pccard_get_function(dev, &fcn); 101140528Simp if (error != 0) 102140528Simp return (error); 103140528Simp if (fcn != PCCARD_FUNCTION_NETWORK) 104140528Simp return (ENXIO); 105140528Simp 10682778Sshiba if ((pp = pccard_product_lookup(dev, 10782778Sshiba (const struct pccard_product *)fe_pccard_products, 10882778Sshiba sizeof(fe_pccard_products[0]), NULL)) != NULL) { 109113315Simp if (pp->pp_name != NULL) 110113315Simp device_set_desc(dev, pp->pp_name); 11182778Sshiba return 0; 11282778Sshiba } 11382778Sshiba return EIO; 11482778Sshiba} 11582778Sshiba 11665832Snyanstatic device_method_t fe_pccard_methods[] = { 11782778Sshiba /* Device interface */ 11882778Sshiba DEVMETHOD(device_probe, pccard_compat_probe), 11982778Sshiba DEVMETHOD(device_attach, pccard_compat_attach), 12082778Sshiba DEVMETHOD(device_detach, fe_pccard_detach), 12165832Snyan 12282778Sshiba /* Card interface */ 12382778Sshiba DEVMETHOD(card_compat_match, fe_pccard_match), 12482778Sshiba DEVMETHOD(card_compat_probe, fe_pccard_probe), 12582778Sshiba DEVMETHOD(card_compat_attach, fe_pccard_attach), 12682778Sshiba 12765832Snyan { 0, 0 } 12865832Snyan}; 12965832Snyan 13065832Snyanstatic driver_t fe_pccard_driver = { 13165832Snyan "fe", 13265832Snyan fe_pccard_methods, 13365832Snyan sizeof (struct fe_softc) 13465832Snyan}; 13565832Snyan 13665832SnyanDRIVER_MODULE(fe, pccard, fe_pccard_driver, fe_devclass, 0, 0); 13765832Snyan 138140543Simpstatic int fe_probe_mbh(device_t, const struct fe_pccard_product *); 139140543Simpstatic int fe_probe_tdk(device_t, const struct fe_pccard_product *); 14065832Snyan/* 14165832Snyan * Initialize the device - called from Slot manager. 14265832Snyan */ 14365832Snyanstatic int 14465832Snyanfe_pccard_probe(device_t dev) 14565832Snyan{ 14665832Snyan struct fe_softc *sc; 147140543Simp const struct fe_pccard_product *pp; 14865832Snyan int error; 14965832Snyan 15065832Snyan /* Prepare for the device probe process. */ 15165832Snyan sc = device_get_softc(dev); 15265832Snyan sc->sc_unit = device_get_unit(dev); 15365832Snyan 154140543Simp pp = (const struct fe_pccard_product *) pccard_product_lookup(dev, 155140543Simp (const struct pccard_product *)fe_pccard_products, 156140543Simp sizeof(fe_pccard_products[0]), NULL); 157140543Simp if (pp == NULL) 158140543Simp return (ENXIO); 15965832Snyan 160140543Simp if (pp->mpp_flags & MPP_MBH10302) 161140543Simp error = fe_probe_mbh(dev, pp); 162140543Simp else 163140543Simp error = fe_probe_tdk(dev, pp); 16465832Snyan if (error == 0) 16565832Snyan error = fe_alloc_irq(dev, 0); 16665832Snyan 16765832Snyan fe_release_resource(dev); 16865832Snyan return (error); 16965832Snyan} 17065832Snyan 17165832Snyanstatic int 17265832Snyanfe_pccard_attach(device_t dev) 17365832Snyan{ 17465832Snyan struct fe_softc *sc = device_get_softc(dev); 17565832Snyan 17665832Snyan if (sc->port_used) 17765832Snyan fe_alloc_port(dev, sc->port_used); 17865832Snyan fe_alloc_irq(dev, 0); 17965832Snyan 18065832Snyan return fe_attach(dev); 18165832Snyan} 18265832Snyan 18365832Snyan/* 18465832Snyan * feunload - unload the driver and clear the table. 18565832Snyan */ 18665832Snyanstatic int 18765832Snyanfe_pccard_detach(device_t dev) 18865832Snyan{ 18965832Snyan struct fe_softc *sc = device_get_softc(dev); 19065832Snyan struct ifnet *ifp = &sc->arpcom.ac_if; 19165832Snyan 19265832Snyan fe_stop(sc); 193106937Ssam ether_ifdetach(ifp); 19465832Snyan bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); 19565832Snyan fe_release_resource(dev); 19665832Snyan 19765832Snyan return 0; 19865832Snyan} 19965832Snyan 20065832Snyan 20165832Snyan/* 20265832Snyan * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface. 20365832Snyan * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk(). 20465832Snyan */ 20565832Snyanstatic void 20665832Snyanfe_init_mbh(struct fe_softc *sc) 20765832Snyan{ 20865832Snyan /* Minimal initialization of 86960. */ 20965832Snyan DELAY(200); 21065832Snyan fe_outb(sc, FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE); 21165832Snyan DELAY(200); 21265832Snyan 21365832Snyan /* Disable all interrupts. */ 21465832Snyan fe_outb(sc, FE_DLCR2, 0); 21565832Snyan fe_outb(sc, FE_DLCR3, 0); 21665832Snyan 21765832Snyan /* Enable master interrupt flag. */ 21865832Snyan fe_outb(sc, FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE); 21965832Snyan} 22065832Snyan 22165832Snyanstatic int 222140543Simpfe_probe_mbh(device_t dev, const struct fe_pccard_product *pp) 22365832Snyan{ 22465832Snyan struct fe_softc *sc = device_get_softc(dev); 22565832Snyan 22665832Snyan static struct fe_simple_probe_struct probe_table [] = { 22765832Snyan { FE_DLCR2, 0x58, 0x00 }, 22865832Snyan { FE_DLCR4, 0x08, 0x00 }, 22965832Snyan { FE_DLCR6, 0xFF, 0xB6 }, 23065832Snyan { 0 } 23165832Snyan }; 23265832Snyan 23365832Snyan /* MBH10302 occupies 32 I/O addresses. */ 23465832Snyan if (fe_alloc_port(dev, 32)) 23565832Snyan return ENXIO; 23665832Snyan 23765832Snyan /* Fill the softc struct with default values. */ 23865832Snyan fe_softc_defaults(sc); 23965832Snyan 24065832Snyan /* 24165832Snyan * See if MBH10302 is on its address. 24265832Snyan * I'm not sure the following probe code works. FIXME. 24365832Snyan */ 24465832Snyan if (!fe_simple_probe(sc, probe_table)) 24565832Snyan return ENXIO; 24665832Snyan 24765832Snyan /* Get our station address from EEPROM. */ 24865832Snyan fe_inblk(sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN); 24965832Snyan 25065832Snyan /* Make sure we got a valid station address. */ 251139972Simp if (!fe_valid_Ether_p(sc->sc_enaddr, 0)) 25265832Snyan return ENXIO; 25365832Snyan 25465832Snyan /* Determine the card type. */ 25565832Snyan sc->type = FE_TYPE_MBH; 25665832Snyan sc->typestr = "MBH10302 (PCMCIA)"; 25765832Snyan 25865832Snyan /* We seems to need our own IDENT bits... FIXME. */ 25965832Snyan sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE; 26065832Snyan 26165832Snyan /* Setup hooks. We need a special initialization procedure. */ 26265832Snyan sc->init = fe_init_mbh; 26365832Snyan 26465832Snyan return 0; 26565832Snyan} 26665832Snyan 26765832Snyan/* 26865832Snyan * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface. 26965832Snyan * by MASUI Kenji <masui@cs.titech.ac.jp> 27065832Snyan * 27165832Snyan * (Contec uses TDK Ethenet chip -- hosokawa) 27265832Snyan * 27365832Snyan * This version of fe_probe_tdk has been rewrote to handle 27465832Snyan * *generic* PC card implementation of Fujitsu MB8696x family. The 27565832Snyan * name _tdk is just for a historical reason. :-) 27665832Snyan */ 27765832Snyanstatic int 278140543Simpfe_probe_tdk (device_t dev, const struct fe_pccard_product *pp) 27965832Snyan{ 28065832Snyan struct fe_softc *sc = device_get_softc(dev); 28165832Snyan 28265832Snyan static struct fe_simple_probe_struct probe_table [] = { 28365832Snyan { FE_DLCR2, 0x50, 0x00 }, 28465832Snyan { FE_DLCR4, 0x08, 0x00 }, 28565832Snyan /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */ 28665832Snyan { 0 } 28765832Snyan }; 28865832Snyan 28965832Snyan /* C-NET(PC)C occupies 16 I/O addresses. */ 29065832Snyan if (fe_alloc_port(dev, 16)) 29165832Snyan return ENXIO; 29265832Snyan 29365832Snyan /* Fill the softc struct with default values. */ 29465832Snyan fe_softc_defaults(sc); 29565832Snyan 29665832Snyan /* 29765832Snyan * See if C-NET(PC)C is on its address. 29865832Snyan */ 29965832Snyan if (!fe_simple_probe(sc, probe_table)) 30065832Snyan return ENXIO; 30165832Snyan 30265832Snyan /* Determine the card type. */ 30365832Snyan sc->type = FE_TYPE_TDK; 30465832Snyan sc->typestr = "Generic MB8696x/78Q837x Ethernet (PCMCIA)"; 30565832Snyan 306140543Simp pccard_get_ether(dev, sc->sc_enaddr); 307140543Simp 30865832Snyan /* Make sure we got a valid station address. */ 309139972Simp if (!fe_valid_Ether_p(sc->sc_enaddr, 0)) 31065832Snyan return ENXIO; 31165832Snyan 31265832Snyan return 0; 31365832Snyan} 314