if_ep_mca.c revision 1.3
1/* $NetBSD: if_ep_mca.c,v 1.3 2001/04/23 06:10:08 jdolecek Exp $ */ 2 3/*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jaromir Dolecek. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39/* 40 * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org> 41 * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org> 42 * All rights reserved. 43 * 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions 46 * are met: 47 * 1. Redistributions of source code must retain the above copyright 48 * notice, this list of conditions and the following disclaimer. 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 3. All advertising materials mentioning features or use of this software 53 * must display the following acknowledgement: 54 * This product includes software developed by Herb Peyerl. 55 * 4. The name of Herb Peyerl may not be used to endorse or promote products 56 * derived from this software without specific prior written permission. 57 * 58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 64 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 65 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 66 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 67 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 68 */ 69 70/* 71 * Driver for 3Com 3c529 cards. 72 * 73 * Known issues: 74 * - on my 386DX, speed of network is like 100KB/s at best; for bigger 75 * files fetched e.g. via ftp, I get as low as 5KB/s, mostly due 76 * to excessive number of overrun packets. Configuring system to 77 * use smaller TCP window might help, though the performance is 78 * still expected to be very dependant on CPU speed, especially 79 * since ISA and PCI attachments are reported to work OK on pentium 80 * class systems. 81 * Changing ic/elink3.c to use RX Early might help here potentially. 82 */ 83 84#include <sys/param.h> 85#include <sys/systm.h> 86#include <sys/mbuf.h> 87#include <sys/socket.h> 88#include <sys/ioctl.h> 89#include <sys/errno.h> 90#include <sys/device.h> 91 92#include <net/if.h> 93#include <net/if_ether.h> 94#include <net/if_media.h> 95 96#include <machine/bus.h> 97 98#include <dev/mii/miivar.h> 99 100#include <dev/ic/elink3var.h> 101#include <dev/ic/elink3reg.h> 102 103#include <dev/mca/mcavar.h> 104#include <dev/mca/mcadevs.h> 105 106/* 107 * MCA constants. 108 */ 109#define MCA_CBIO 0x200 /* Configuration Base IO Address */ 110#define MCA_IOSZ 0x10 /* I/O space size */ 111 112int ep_mca_match __P((struct device *, struct cfdata *, void *)); 113void ep_mca_attach __P((struct device *, struct device *, void *)); 114 115struct cfattach ep_mca_ca = { 116 sizeof(struct ep_softc), ep_mca_match, ep_mca_attach 117}; 118 119const struct ep_mca_product { 120 u_int32_t epp_prodid; /* MCA product ID */ 121 const char *epp_name; /* device name */ 122} ep_mca_products[] = { 123 { MCA_PRODUCT_3C529_TP, "3c529-TP Ethernet Adapter" }, 124 { MCA_PRODUCT_3C529_TM, "3c529 Ethernet Adapter (test mode)" }, 125 { MCA_PRODUCT_3C529_2T, "3c529 Ethernet Adapter (10base2/T)" }, 126 { MCA_PRODUCT_3C529_T, "3c529 Ethernet Adapter (10baseT)" }, 127 128 { 0, NULL }, 129}; 130 131static const struct ep_mca_product *ep_mca_lookup 132 __P((const struct mca_attach_args *)); 133 134static const struct ep_mca_product * 135ep_mca_lookup(ma) 136 const struct mca_attach_args *ma; 137{ 138 const struct ep_mca_product *epp; 139 140 for (epp = ep_mca_products; epp->epp_name != NULL; epp++) 141 if (ma->ma_id == epp->epp_prodid) 142 return (epp); 143 144 return (NULL); 145} 146 147int 148ep_mca_match(parent, match, aux) 149 struct device *parent; 150 struct cfdata *match; 151 void *aux; 152{ 153 struct mca_attach_args *ma = (struct mca_attach_args *) aux; 154 155 if (ep_mca_lookup(ma) != NULL) 156 return (1); 157 158 return (0); 159} 160 161void 162ep_mca_attach(parent, self, aux) 163 struct device *parent, *self; 164 void *aux; 165{ 166 struct ep_softc *sc = (void *)self; 167 struct mca_attach_args *ma = aux; 168 bus_space_handle_t ioh; 169 int pos4, pos5, iobase, irq, media; 170 const struct ep_mca_product *epp; 171 172 pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4); 173 pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5); 174 175 /* 176 * POS register 2: (adf pos0) 177 * 7 6 5 4 3 2 1 0 178 * \__ enable: 0=adapter disabled, 1=adapter enabled 179 * 180 * POS register 3: (adf pos1) 181 * 182 * 7 6 5 4 3 2 1 0 183 * \________/ 184 * \_______ Boot ROM Address Range: 0=disabled 185 * X=0xc2000-0xc3fff + (x * 0x2000) 186 * 187 * POS register 4: (adf pos2) 188 * 189 * 7 6 5 4 3 2 1 0 190 * \________/ \_/ 191 * \ \__ Transceiver Type: 00=on-board (RJ45), 01=ext(AUI) 192 * \______ I/O Address Range: 0x200-0x20f + ((x>>2) * 0x400) 193 * 194 * POS register 5: (adf pos3) 195 * 196 * 7 6 5 4 3 2 1 0 197 * \____/ 198 * \__ Interrupt level 199 */ 200 201 iobase = MCA_CBIO + (((pos4 & 0xfc) >> 2) * 0x400); 202 irq = (pos5 & 0x0f); 203 204 /* map the pio registers */ 205 if (bus_space_map(ma->ma_iot, iobase, MCA_IOSZ, 0, &ioh)) { 206 printf(": unable to map i/o space\n", sc->sc_dev.dv_xname); 207 return; 208 } 209 210 sc->sc_iot = ma->ma_iot; 211 sc->sc_ioh = ioh; 212 213 epp = ep_mca_lookup(ma); 214 if (epp == NULL) { 215 printf("\n"); 216 panic("ep_mca_attach: impossible"); 217 } 218 219 printf(" slot %d irq %d: 3Com %s\n", ma->ma_slot + 1, 220 irq, epp->epp_name); 221 222 sc->enable = NULL; 223 sc->disable = NULL; 224 sc->enabled = 1; 225 226 sc->bustype = ELINK_BUS_MCA; 227 sc->ep_flags = 0; 228 229 if (epconfig(sc, ELINK_CHIPSET_3C509, NULL)) 230 return; 231 232 /* Map and establish the interrupt. */ 233 sc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, epintr, sc); 234 if (sc->sc_ih == NULL) { 235 printf("%s: couldn't establish interrupt handler\n", 236 sc->sc_dev.dv_xname); 237 return; 238 } 239 240 /* 241 * Set default media to be same as the one selected in POS. 242 */ 243 switch (pos4 & 0x03) { 244 case 0x00: 245 /* on-board RJ-45 */ 246 media = IFM_10_T; 247 break; 248 case 0x01: 249 /* external AUI */ 250 media = IFM_10_5; 251 break; 252 case 0x02: 253 /* undefined, should never be set */ 254 media = IFM_NONE; 255 break; 256 case 0x03: 257 /* BNC */ 258 media = IFM_10_2; 259 break; 260 } 261 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|media); 262} 263