Home | History | Annotate | Line # | Download | only in pcmcia
if_ep_pcmcia.c revision 1.1.2.8
      1 #include "bpfilter.h"
      2 
      3 #include <sys/param.h>
      4 #include <sys/systm.h>
      5 #include <sys/mbuf.h>
      6 #include <sys/socket.h>
      7 #include <sys/ioctl.h>
      8 #include <sys/errno.h>
      9 #include <sys/syslog.h>
     10 #include <sys/select.h>
     11 #include <sys/device.h>
     12 
     13 #include <net/if.h>
     14 #include <net/if_dl.h>
     15 #include <net/if_ether.h>
     16 #include <net/if_media.h>
     17 
     18 #ifdef INET
     19 #include <netinet/in.h>
     20 #include <netinet/in_systm.h>
     21 #include <netinet/in_var.h>
     22 #include <netinet/ip.h>
     23 #include <netinet/if_inarp.h>
     24 #endif
     25 
     26 #ifdef NS
     27 #include <netns/ns.h>
     28 #include <netns/ns_if.h>
     29 #endif
     30 
     31 #if NBPFILTER > 0
     32 #include <net/bpf.h>
     33 #include <net/bpfdesc.h>
     34 #endif
     35 
     36 #include <machine/cpu.h>
     37 #include <machine/bus.h>
     38 #include <machine/intr.h>
     39 
     40 #include <dev/ic/elink3var.h>
     41 #include <dev/ic/elink3reg.h>
     42 
     43 #include <dev/pcmcia/pcmciareg.h>
     44 #include <dev/pcmcia/pcmciavar.h>
     45 
     46 #define PCMCIA_MANUFACTURER_3COM	0x101
     47 #define PCMCIA_PRODUCT_3COM_3C562	0x562
     48 #define PCMCIA_PRODUCT_3COM_3C589	0x589
     49 
     50 #ifdef __BROKEN_INDIRECT_CONFIG
     51 int ep_pcmcia_match __P((struct device *, void *, void *));
     52 #else
     53 int ep_pcmcia_match __P((struct device *, struct cfdata *, void *));
     54 #endif
     55 void ep_pcmcia_attach __P((struct device *, struct device *, void *));
     56 
     57 int ep_pcmcia_get_enaddr __P((struct pcmcia_tuple *, void *));
     58 int ep_pcmcia_enable __P((struct ep_softc *));
     59 void ep_pcmcia_disable __P((struct ep_softc *));
     60 
     61 struct ep_pcmcia_softc {
     62 	struct ep_softc sc_ep;			/* real "ep" softc */
     63 
     64 	/* PCMCIA-specific goo */
     65 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
     66 	int sc_io_window;			/* our i/o window */
     67 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     68 };
     69 
     70 struct cfattach ep_pcmcia_ca = {
     71     sizeof(struct ep_pcmcia_softc), ep_pcmcia_match, ep_pcmcia_attach
     72 };
     73 
     74 int
     75 ep_pcmcia_match(parent, match, aux)
     76      struct device *parent;
     77 #ifdef __BROKEN_INDIRECT_CONFIG
     78      void *match;
     79 #else
     80      struct cfdata *cf;
     81 #endif
     82      void *aux;
     83 {
     84     struct pcmcia_attach_args *pa = (struct pcmcia_attach_args *) aux;
     85 
     86     if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
     87 	(pa->product == PCMCIA_PRODUCT_3COM_3C562) &&
     88 	(pa->pf->number == 0))
     89 	return(1);
     90 
     91     if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
     92 	(pa->product == PCMCIA_PRODUCT_3COM_3C589) &&
     93 	(pa->pf->number == 0))
     94 	return(1);
     95 
     96     return(0);
     97 }
     98 
     99 int
    100 ep_pcmcia_enable(sc)
    101      struct ep_softc *sc;
    102 {
    103     struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *)sc;
    104 
    105     return (pcmcia_function_enable(psc->sc_pf));
    106 }
    107 
    108 void
    109 ep_pcmcia_disable(sc)
    110      struct ep_softc *sc;
    111 {
    112     struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *)sc;
    113 
    114     pcmcia_function_disable(psc->sc_pf);
    115 }
    116 
    117 void
    118 ep_pcmcia_attach(parent, self, aux)
    119      struct device *parent, *self;
    120      void *aux;
    121 {
    122     struct ep_pcmcia_softc *psc = (void *) self;
    123     struct ep_softc *sc = &psc->sc_ep;
    124     struct pcmcia_attach_args *pa = aux;
    125     struct pcmcia_config_entry *cfe;
    126     int i;
    127     u_int8_t myla[ETHER_ADDR_LEN];
    128     u_int8_t *enaddr;
    129     char *model;
    130 
    131     psc->sc_pf = pa->pf;
    132     cfe = pa->pf->cfe_head.sqh_first;
    133 
    134     /* Enable the card. */
    135     pcmcia_function_init(pa->pf, cfe);
    136     if (pcmcia_function_enable(pa->pf))
    137 	printf(": function enable failed\n");
    138 
    139     sc->enabled = 1;
    140 
    141     /* turn off the bit which disables the modem */
    142     if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    143 	int reg;
    144 
    145 	reg = pcmcia_ccr_read(pa->pf, PCMCIA_CCR_OPTION);
    146 	reg &= ~0x08;
    147 	pcmcia_ccr_write(pa->pf, PCMCIA_CCR_OPTION, reg);
    148     }
    149 
    150     if (cfe->num_memspace != 0)
    151 	printf(": unexpected number of memory spaces %d should be 0\n",
    152 	       cfe->num_memspace);
    153 
    154     if (cfe->num_iospace != 1)
    155 	printf(": unexpected number of I/O spaces %d should be 1\n",
    156 	       cfe->num_iospace);
    157 
    158     /* XXX there's a comment in the linux driver about the io address
    159        having to be between 0x00 and 0x70 mod 0x100.  weird. */
    160 
    161     /* XXX Will have to fix this!! */
    162 
    163     if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    164 	for (i = 0x300; i < 0x1000; i += ((i%0x100) == 0x70)?0x90:0x10) {
    165 	    if (pcmcia_io_alloc(pa->pf, i, cfe->iospace[0].length,
    166 				0, &psc->sc_pcioh) == 0)
    167 		break;
    168 	}
    169 	if (i == 0x1000) {
    170 	    printf(": can't allocate i/o space\n");
    171 	    return;
    172 	}
    173     } else {
    174 	if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
    175 			    cfe->iospace[0].length, &psc->sc_pcioh))
    176 	    printf(": can't allocate i/o space\n");
    177     }
    178 
    179     sc->sc_iot = psc->sc_pcioh.iot;
    180     sc->sc_ioh = psc->sc_pcioh.ioh;
    181 
    182     if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
    183 			       PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8),
    184 		      0, cfe->iospace[0].length, &psc->sc_pcioh,
    185 		      &psc->sc_io_window)) {
    186 	printf(": can't map i/o space\n");
    187 	return;
    188     }
    189 
    190     if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    191 	if (pcmcia_scan_cis(parent, ep_pcmcia_get_enaddr, myla)) {
    192 	    printf(": can't read ethernet address from CIS\n");
    193 	    return;
    194 	}
    195 	enaddr = myla;
    196     } else {
    197 	enaddr = NULL;
    198     }
    199 
    200     sc->bustype = EP_BUS_PCMCIA;
    201 
    202     switch (pa->product) {
    203     case PCMCIA_PRODUCT_3COM_3C589:
    204 	model = "3Com 3C589 Ethernet";
    205 	break;
    206     case PCMCIA_PRODUCT_3COM_3C562:
    207 	model = "3Com 3C562 Ethernet";
    208 	break;
    209     default:
    210 	model = "3Com Ethernet, model unknown";
    211 	break;
    212     }
    213 
    214     printf(": %s\n", model);
    215 
    216     sc->enable = ep_pcmcia_enable;
    217     sc->disable = ep_pcmcia_disable;
    218 
    219     epconfig(sc, EP_CHIPSET_3C509, enaddr);
    220 
    221     /* establish the interrupt. */
    222     sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, epintr, sc);
    223     if (sc->sc_ih == NULL) {
    224 	printf("%s: couldn't establish interrupt\n",
    225 	       sc->sc_dev.dv_xname);
    226 	return;
    227     }
    228 
    229     sc->enabled = 0;
    230 
    231     pcmcia_function_disable(pa->pf);
    232 }
    233 
    234 int
    235 ep_pcmcia_get_enaddr(tuple, arg)
    236      struct pcmcia_tuple *tuple;
    237      void *arg;
    238 {
    239     u_int8_t *myla = (u_int8_t *) arg;
    240     int i;
    241 
    242     /* this is 3c562 magic */
    243 
    244     if (tuple->code == 0x88) {
    245 	if (tuple->length < ETHER_ADDR_LEN)
    246 	    return(0);
    247 
    248 	for (i=0; i<ETHER_ADDR_LEN; i+=2) {
    249 	    myla[i] = pcmcia_tuple_read_1(tuple, i+1);
    250 	    myla[i+1] = pcmcia_tuple_read_1(tuple, i);
    251 	}
    252 
    253 	return(1);
    254     }
    255 
    256     return(0);
    257 }
    258