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