Home | History | Annotate | Line # | Download | only in pcmcia
if_ep_pcmcia.c revision 1.1.2.5
      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(struct pcmcia_tuple *, void *);
     58 
     59 struct ep_pcmcia_softc {
     60 	struct ep_softc sc_ep;			/* real "ep" softc */
     61 
     62 	/* PCMCIA-specific goo */
     63 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
     64 	int sc_io_window;			/* our i/o window */
     65 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     66 };
     67 
     68 struct cfattach ep_pcmcia_ca = {
     69     sizeof(struct ep_pcmcia_softc), ep_pcmcia_match, ep_pcmcia_attach
     70 };
     71 
     72 int
     73 ep_pcmcia_match(parent, match, aux)
     74      struct device *parent;
     75 #ifdef __BROKEN_INDIRECT_CONFIG
     76      void *match;
     77 #else
     78      struct cfdata *cf;
     79 #endif
     80      void *aux;
     81 {
     82     struct pcmcia_attach_args *pa = (struct pcmcia_attach_args *) aux;
     83 
     84     if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
     85 	(pa->product == PCMCIA_PRODUCT_3COM_3C562) &&
     86 	(pa->pf->number == 0))
     87 	return(1);
     88 
     89     if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
     90 	(pa->product == PCMCIA_PRODUCT_3COM_3C589) &&
     91 	(pa->pf->number == 0))
     92 	return(1);
     93 
     94     return(0);
     95 }
     96 
     97 void
     98 ep_pcmcia_attach(parent, self, aux)
     99      struct device *parent, *self;
    100      void *aux;
    101 {
    102     struct ep_pcmcia_softc *psc = (void *) self;
    103     struct ep_softc *sc = &psc->sc_ep;
    104     struct pcmcia_attach_args *pa = aux;
    105     struct pcmcia_config_entry *cfe;
    106     int i;
    107     u_int8_t myla[ETHER_ADDR_LEN];
    108     u_int8_t *enaddr;
    109     char *model;
    110 
    111     psc->sc_pf = pa->pf;
    112     cfe = pa->pf->cfe_head.sqh_first;
    113 
    114     /* Enable the card. */
    115     pcmcia_function_init(pa->pf, cfe);
    116     if (pcmcia_function_enable(pa->pf))
    117 	printf(": function enable failed\n");
    118 
    119     /* turn off the bit which disables the modem */
    120     if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    121 	int reg;
    122 
    123 	reg = pcmcia_ccr_read(pa->pf, PCMCIA_CCR_OPTION);
    124 	reg &= ~0x08;
    125 	pcmcia_ccr_write(pa->pf, PCMCIA_CCR_OPTION, reg);
    126     }
    127 
    128     if (cfe->num_memspace != 0)
    129 	printf(": unexpected number of memory spaces %d should be 0\n",
    130 	       cfe->num_memspace);
    131 
    132     if (cfe->num_iospace != 1)
    133 	printf(": unexpected number of I/O spaces %d should be 1\n",
    134 	       cfe->num_iospace);
    135 
    136     /* XXX there's a comment in the linux driver about the io address
    137        having to be between 0x00 and 0x70 mod 0x100.  weird. */
    138 
    139     if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    140 	for (i = 0x300; i < 0x1000; i += ((i%0x100) == 0x70)?0x90:0x10) {
    141 	    if (pcmcia_io_alloc(pa->pf, i, cfe->iospace[0].length,
    142 				&psc->sc_pcioh) == 0)
    143 		break;
    144 	}
    145 	if (i == 0x1000) {
    146 	    printf(": can't allocate i/o space\n");
    147 	    return;
    148 	}
    149     } else {
    150 	if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
    151 			    &psc->sc_pcioh))
    152 	    printf(": can't allocate i/o space\n");
    153     }
    154 
    155     sc->sc_iot = psc->sc_pcioh.iot;
    156     sc->sc_ioh = psc->sc_pcioh.ioh;
    157 
    158     if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
    159 			       PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8),
    160 		      0, cfe->iospace[0].length, &psc->sc_pcioh,
    161 		      &psc->sc_io_window)) {
    162 	printf(": can't map i/o space\n");
    163 	return;
    164     }
    165 
    166     if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    167 	if (pcmcia_scan_cis(parent, ep_pcmcia_get_enaddr, myla)) {
    168 	    printf(": can't read ethernet address from CIS\n");
    169 	    return;
    170 	}
    171 	enaddr = myla;
    172     } else {
    173 	enaddr = NULL;
    174     }
    175 
    176     sc->bustype = EP_BUS_PCMCIA;
    177 
    178     switch (pa->product) {
    179     case PCMCIA_PRODUCT_3COM_3C589:
    180 	model = "3Com 3C589 Ethernet";
    181 	break;
    182     case PCMCIA_PRODUCT_3COM_3C562:
    183 	model = "3Com 3C562 Ethernet";
    184 	break;
    185     default:
    186 	model = "3Com Ethernet, model unknown";
    187 	break;
    188     }
    189 
    190     printf(": %s\n", model);
    191 
    192     epconfig(sc, EP_CHIPSET_3C509, enaddr);
    193 
    194     /* establish the interrupt. */
    195     sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, epintr, sc);
    196     if (sc->sc_ih == NULL) {
    197 	printf("%s: couldn't establish interrupt\n",
    198 	       sc->sc_dev.dv_xname);
    199 	return;
    200     }
    201 }
    202 
    203 int
    204 ep_pcmcia_get_enaddr(tuple, arg)
    205      struct pcmcia_tuple *tuple;
    206      void *arg;
    207 {
    208     u_int8_t *myla = (u_int8_t *) arg;
    209     int i;
    210 
    211     /* this is 3c562 magic */
    212 
    213     if (tuple->code == 0x88) {
    214 	if (tuple->length < ETHER_ADDR_LEN)
    215 	    return(0);
    216 
    217 	for (i=0; i<ETHER_ADDR_LEN; i+=2) {
    218 	    myla[i] = pcmcia_tuple_read_1(tuple, i+1);
    219 	    myla[i+1] = pcmcia_tuple_read_1(tuple, i);
    220 	}
    221 
    222 	return(1);
    223     }
    224 
    225     return(0);
    226 }
    227