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