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