Home | History | Annotate | Line # | Download | only in cardbus
if_fxp_cardbus.c revision 1.1
      1 /*	$Id: if_fxp_cardbus.c,v 1.1 1999/10/15 06:07:24 haya Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999
      5  *       Johan Danielsson <joda (at) pdc.kth.se>.  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, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the author.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     26  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     30  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  * POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 
     36 #include "opt_inet.h"
     37 #include "opt_ns.h"
     38 #include "bpfilter.h"
     39 #include "rnd.h"
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/mbuf.h>
     44 #include <sys/malloc.h>
     45 #include <sys/kernel.h>
     46 #include <sys/socket.h>
     47 #include <sys/ioctl.h>
     48 #include <sys/errno.h>
     49 #include <sys/device.h>
     50 
     51 #if NRND > 0
     52 #include <sys/rnd.h>
     53 #endif
     54 
     55 #include <net/if.h>
     56 #include <net/if_dl.h>
     57 #include <net/if_media.h>
     58 #include <net/if_ether.h>
     59 
     60 #if NBPFILTER > 0
     61 #include <net/bpf.h>
     62 #endif
     63 
     64 #ifdef INET
     65 #include <netinet/in.h>
     66 #include <netinet/if_inarp.h>
     67 #endif
     68 
     69 #ifdef NS
     70 #include <netns/ns.h>
     71 #include <netns/ns_if.h>
     72 #endif
     73 
     74 #include <machine/bus.h>
     75 #include <machine/intr.h>
     76 
     77 #include <dev/mii/miivar.h>
     78 
     79 #include <dev/pci/if_fxpreg.h>
     80 #include <dev/pci/if_fxpvar.h>
     81 
     82 #include <dev/pci/pcivar.h>
     83 #include <dev/pci/pcireg.h>
     84 #include <dev/pci/pcidevs.h>
     85 
     86 #include <dev/cardbus/cardbusvar.h>
     87 #include <dev/cardbus/cardbusdevs.h>
     88 
     89 static int fxp_cardbus_match __P((struct device *, struct cfdata *, void *));
     90 static void fxp_cardbus_attach __P((struct device *, struct device *, void *));
     91 
     92 struct fxp_cardbus_softc {
     93     struct fxp_softc sc;
     94     cardbustag_t tag;
     95     pcireg_t base1_reg;
     96 };
     97 
     98 struct cfattach fxp_cardbus_ca = {
     99     sizeof(struct fxp_cardbus_softc), fxp_cardbus_match, fxp_cardbus_attach
    100 };
    101 
    102 #ifdef CBB_DEBUG
    103 #define DPRINTF(X) printf X
    104 #else
    105 #define DPRINTF(X)
    106 #endif
    107 
    108 /*
    109  * Check if a device is an 82557.
    110  */
    111 static int
    112 fxp_cardbus_match(parent, match, aux)
    113      struct device *parent;
    114      struct cfdata *match;
    115      void *aux;
    116 {
    117     /* should check CIS */
    118     struct cardbus_attach_args *ca = aux;
    119 
    120     if (CARDBUS_VENDOR(ca->ca_id) != CARDBUS_VENDOR_INTEL)
    121 	return (0);
    122 
    123     switch (CARDBUS_PRODUCT(ca->ca_id)) {
    124     case CARDBUS_PRODUCT_INTEL_82557:
    125 	return (1);
    126     }
    127 
    128     return (0);
    129 }
    130 
    131 int
    132 fxp_enable(struct fxp_softc *sc);
    133 
    134 static int
    135 fxp_cardbus_enable(struct fxp_softc *sc);
    136 static void
    137 fxp_cardbus_disable(struct fxp_softc *sc);
    138 
    139 static void
    140 fxp_cardbus_setup(struct fxp_softc *sc);
    141 
    142 static void
    143 fxp_cardbus_attach(parent, self, aux)
    144      struct device *parent, *self;
    145      void *aux;
    146 {
    147     struct fxp_softc *sc = (struct fxp_softc*)self;
    148     struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc*)self;
    149     struct cardbus_attach_args *ca = aux;
    150     cardbus_function_tag_t cf = ca->ca_cf;
    151     bus_space_handle_t ioh, memh;
    152 
    153     bus_addr_t adr;
    154 
    155     /*
    156      * Map control/status registers.
    157      */
    158 #if rbus
    159     cardbus_function_tag_t cf = ct->ct_cf;
    160 
    161     if (cardbus_mapreg_map(ct, CARDBUS_BASE1_REG, CARDBUS_MAPREG_TYPE_IO, 0,
    162 			   &(sc->sc_iot), &ioh, &adr, NULL)) {
    163       panic("io alloc in ex_attach_cardbus\n");
    164     }
    165     csc->base1_reg = adr | 1;
    166     sc->sc_sh = ioh;
    167 
    168 #elif unibus
    169     printf("fxp_cardbus_attach: uni %p\n", ca->ca_uni);
    170     if ((*cf->cf_ub.unibus_space_alloc)(ca->ca_uni, ca->bar_info[1].tag, 0,
    171 					ca->bar_info[1].size,
    172 					ca->bar_info[1].size - 1,
    173 					ca->bar_info[1].size,
    174 					0, 0, &adr, &ioh))
    175 	panic("io alloc");
    176 
    177 
    178     csc->base1_reg = adr | 1;
    179     sc->sc_st = ca->bar_info[1].tag;
    180     sc->sc_sh = ioh;
    181 
    182     if (0) {
    183 	/*
    184 	 * Map control/status registers.
    185 	 */
    186 	if ((*cf->cf_ub.unibus_space_alloc)(ca->ca_uni, ca->bar_info[0].tag, 0,
    187 					    ca->bar_info[0].size,
    188 					    ca->bar_info[0].size - 1,
    189 					    ca->bar_info[0].size,
    190 					    0, 0, &adr, &memh))
    191 	    panic("mem alloc");
    192 
    193 
    194 	sc->sc_st = ca->bar_info[0].tag;
    195 	sc->sc_sh = memh;
    196     }
    197 #endif
    198 
    199     csc->tag = ca->ca_tag;
    200 
    201     sc->sc_dmat = ca->ca_dmat;
    202     sc->enable = fxp_cardbus_enable;
    203     sc->disable = fxp_cardbus_disable;
    204     sc->enabled = 0;
    205 
    206     fxp_cardbus_setup(sc);
    207     printf(": Intel EtherExpress Pro 10+/100B Ethernet\n");
    208 
    209     fxp_attach_common(sc);
    210 }
    211 
    212 
    213 static void
    214 fxp_cardbus_setup(struct fxp_softc *sc)
    215 {
    216     struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc*)sc;
    217     struct cardbus_softc *psc = (struct cardbus_softc *)sc->sc_dev.dv_parent;
    218     cardbus_chipset_tag_t cc = psc->sc_cc;
    219     cardbus_function_tag_t cf = psc->sc_cf;
    220     pcireg_t command;
    221 
    222     printf("fxp_cardbus_setup\n");
    223 
    224     cardbus_conf_write(cc, cf, csc->tag, CARDBUS_BASE1_REG, csc->base1_reg);
    225 
    226     (cf->cardbus_ctrl)(cc, CARDBUS_IO_ENABLE);
    227 
    228     /* enable the card */
    229     command = cardbus_conf_read(cc, cf, csc->tag, CARDBUS_COMMAND_STATUS_REG);
    230     command |= (CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MASTER_ENABLE);
    231     cardbus_conf_write(cc, cf, csc->tag, CARDBUS_COMMAND_STATUS_REG, command);
    232 #if 0
    233     cardbus_conf_write(cc, cf, ca->tag, CARDBUS_BASE0_REG, adr);
    234 
    235     (ca->ca_cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE);
    236 
    237     /* enable card mem */
    238     command = cardbus_conf_read(cc, cf, ca->tag, CARDBUS_COMMAND_STATUS_REG);
    239     command |= CARDBUS_COMMAND_MEM_ENABLE;
    240     cardbus_conf_write(cc, cf, ca->tag, CARDBUS_COMMAND_STATUS_REG, command);
    241 #endif
    242 }
    243 
    244 static int
    245 fxp_cardbus_enable(struct fxp_softc *sc)
    246 {
    247     struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc*)sc;
    248     struct cardbus_softc *psc = (struct cardbus_softc *)sc->sc_dev.dv_parent;
    249     cardbus_chipset_tag_t cc = psc->sc_cc;
    250     cardbus_function_tag_t cf = psc->sc_cf;
    251 
    252     cardbus_function_enable(psc, csc->tag);
    253 
    254     fxp_cardbus_setup(sc);
    255 
    256     /* Map and establish the interrupt. */
    257 
    258     sc->sc_ih = cardbus_intr_establish(cc, cf, psc->sc_intrline, IPL_NET,
    259 				       fxp_intr, sc);
    260     if (NULL == sc->sc_ih) {
    261 	printf("%s: couldn't establish interrupt\n", sc->sc_dev.dv_xname);
    262 	return 1;
    263     }
    264 
    265     printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname, psc->sc_intrline);
    266 
    267     return 0;
    268 }
    269 
    270 static void
    271 fxp_cardbus_disable(struct fxp_softc *sc)
    272 {
    273     struct cardbus_softc *psc = (struct cardbus_softc *)sc->sc_dev.dv_parent;
    274     cardbus_chipset_tag_t cc = psc->sc_cc;
    275     cardbus_function_tag_t cf = psc->sc_cf;
    276 
    277     fxp_stop(sc);
    278     cardbus_intr_disestablish(cc, cf, sc->sc_ih); /* remove intr handler */
    279 
    280     cardbus_function_disable(psc);
    281 }
    282