if_ep_eisa.c revision 18887
1/* 2 * Product specific probe and attach routines for: 3 * 3COM 3C579 and 3C509(in eisa config mode) ethernet controllers 4 * 5 * Copyright (c) 1996 Justin T. Gibbs 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice immediately at the beginning of the file, without modification, 13 * this list of conditions, and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Absolutely no warranty of function or purpose is made by the author 18 * Justin T. Gibbs. 19 * 4. Modifications may be freely made to this file if the above conditions 20 * are met. 21 * 22 * $Id: 3c5x9.c,v 1.5 1996/09/06 23:06:53 phk Exp $ 23 */ 24 25#include "eisa.h" 26#if NEISA > 0 27 28#include <sys/param.h> 29#include <sys/systm.h> 30#include <sys/kernel.h> 31 32#include <machine/clock.h> 33 34#include <net/if.h> 35 36#include <netinet/in.h> 37#include <netinet/if_ether.h> 38 39#include <i386/isa/if_epreg.h> 40#include <i386/eisa/eisaconf.h> 41 42#define EISA_DEVICE_ID_3COM_3C509_TP 0x506d5090 43#define EISA_DEVICE_ID_3COM_3C509_BNC 0x506d5091 44#define EISA_DEVICE_ID_3COM_3C579_TP 0x506d5092 45#define EISA_DEVICE_ID_3COM_3C579_BNC 0x506d5093 46#define EISA_DEVICE_ID_3COM_3C509_COMBO 0x506d5094 47#define EISA_DEVICE_ID_3COM_3C509_TPO 0x506d5095 48 49#define EP_EISA_SLOT_OFFSET 0x0c80 50#define EP_EISA_IOSIZE 0x000a 51 52#define EISA_IOCONF 0x0008 53#define IRQ_CHANNEL 0xf000 54#define INT_3 0x3000 55#define INT_5 0x5000 56#define INT_7 0x7000 57#define INT_9 0x9000 58#define INT_10 0xa000 59#define INT_11 0xb000 60#define INT_12 0xc000 61#define INT_15 0xf000 62#define EISA_BPROM_MEDIA_CONF 0x0006 63#define TRANS_TYPE 0xc000 64#define TRANS_TP 0x0000 65#define TRANS_AUI 0x4000 66#define TRANS_BNC 0xc000 67 68static int ep_eisa_probe __P((void)); 69static int ep_eisa_attach __P((struct eisa_device *e_dev)); 70 71static struct eisa_driver ep_eisa_driver = { 72 "ep", 73 ep_eisa_probe, 74 ep_eisa_attach, 75 /*shutdown*/NULL, 76 &ep_unit 77 }; 78 79DATA_SET (eisadriver_set, ep_eisa_driver); 80 81static char *ep_match __P((eisa_id_t type)); 82 83static char* 84ep_match(type) 85 eisa_id_t type; 86{ 87 switch(type) { 88 case EISA_DEVICE_ID_3COM_3C509_TP: 89 return "3Com 3C509-TP Network Adapter"; 90 break; 91 case EISA_DEVICE_ID_3COM_3C509_BNC: 92 return "3Com 3C509-BNC Network Adapter"; 93 break; 94 case EISA_DEVICE_ID_3COM_3C579_TP: 95 return "3Com 3C579-TP EISA Network Adapter"; 96 break; 97 case EISA_DEVICE_ID_3COM_3C579_BNC: 98 return "3Com 3C579-BNC EISA Network Adapter"; 99 break; 100 case EISA_DEVICE_ID_3COM_3C509_COMBO: 101 return "3Com 3C509-Combo Network Adapter"; 102 break; 103 case EISA_DEVICE_ID_3COM_3C509_TPO: 104 return "3Com 3C509-TPO Network Adapter"; 105 break; 106 default: 107 break; 108 } 109 return (NULL); 110} 111 112static int 113ep_eisa_probe(void) 114{ 115 u_long iobase; 116 struct eisa_device *e_dev = NULL; 117 int count; 118 119 count = 0; 120 while ((e_dev = eisa_match_dev(e_dev, ep_match))) { 121 u_short conf; 122 u_long port; 123 int irq; 124 125 port = (e_dev->ioconf.slot * EISA_SLOT_SIZE); 126 iobase = port + EP_EISA_SLOT_OFFSET; 127 128 /* We must be in EISA configuration mode */ 129 if ((inw(iobase + EP_W0_ADDRESS_CFG) & 0x1f) != 0x1f) 130 continue; 131 132 eisa_add_iospace(e_dev, iobase, EP_EISA_IOSIZE, RESVADDR_NONE); 133 eisa_add_iospace(e_dev, port, EP_IOSIZE, RESVADDR_NONE); 134 135 conf = inw(iobase + EISA_IOCONF); 136 /* Determine our IRQ */ 137 switch (conf & IRQ_CHANNEL) { 138 case INT_3: 139 irq = 3; 140 break; 141 case INT_5: 142 irq = 5; 143 break; 144 case INT_7: 145 irq = 7; 146 break; 147 case INT_9: 148 irq = 9; 149 break; 150 case INT_10: 151 irq = 10; 152 break; 153 case INT_11: 154 irq = 11; 155 break; 156 case INT_12: 157 irq = 12; 158 break; 159 case INT_15: 160 irq = 15; 161 break; 162 default: 163 /* Disabled */ 164 printf("ep: 3COM Network Adapter at " 165 "slot %d has its IRQ disabled. " 166 "Probe failed.\n", 167 e_dev->ioconf.slot); 168 continue; 169 } 170 eisa_add_intr(e_dev, irq); 171 eisa_registerdev(e_dev, &ep_eisa_driver); 172 count++; 173 } 174 return count; 175} 176 177static int 178ep_eisa_attach(e_dev) 179 struct eisa_device *e_dev; 180{ 181 struct ep_softc *sc; 182 struct ep_board *epb; 183 int unit = e_dev->unit; 184 int irq = ffs(e_dev->ioconf.irq) - 1; 185 resvaddr_t *ioport; 186 resvaddr_t *eisa_ioport; 187 u_char level_intr; 188 int i; 189 190 /* 191 * The addresses are sorted in increasing order 192 * so we know the port to pass to the core ep 193 * driver comes first. 194 */ 195 ioport = e_dev->ioconf.ioaddrs.lh_first; 196 197 if(!ioport) 198 return -1; 199 200 eisa_ioport = ioport->links.le_next; 201 202 if(!eisa_ioport) 203 return -1; 204 205 eisa_reg_start(e_dev); 206 if(eisa_reg_iospace(e_dev, ioport)) 207 return -1; 208 209 if(eisa_reg_iospace(e_dev, eisa_ioport)) 210 return -1; 211 212 epb = &ep_board[ep_boards]; 213 214 epb->epb_addr = ioport->addr; 215 epb->epb_used = 1; 216 217 if(!(sc = ep_alloc(unit, epb))) 218 return -1; 219 220 ep_boards++; 221 222 sc->stat = 0; 223 level_intr = FALSE; 224 switch(e_dev->id) { 225 case EISA_DEVICE_ID_3COM_3C509_TP: 226 sc->ep_connectors = UTP|AUI; 227 break; 228 case EISA_DEVICE_ID_3COM_3C509_BNC: 229 sc->ep_connectors = BNC|AUI; 230 break; 231 case EISA_DEVICE_ID_3COM_3C579_TP: 232 sc->ep_connectors = UTP|AUI; 233 sc->stat = F_ACCESS_32_BITS; 234 level_intr = TRUE; 235 break; 236 case EISA_DEVICE_ID_3COM_3C579_BNC: 237 sc->ep_connectors = BNC|AUI; 238 sc->stat = F_ACCESS_32_BITS; 239 level_intr = TRUE; 240 break; 241 case EISA_DEVICE_ID_3COM_3C509_COMBO: 242 sc->ep_connectors = UTP|BNC|AUI; 243 break; 244 case EISA_DEVICE_ID_3COM_3C509_TPO: 245 sc->ep_connectors = UTP; 246 break; 247 default: 248 break; 249 } 250 /* 251 * Set the eisa config selected media type 252 */ 253 sc->ep_connector = inw(eisa_ioport->addr + EISA_BPROM_MEDIA_CONF) 254 >> ACF_CONNECTOR_BITS; 255 256 if(eisa_reg_intr(e_dev, irq, ep_intr, (void *)sc, &net_imask, 257 /*shared ==*/level_intr)) { 258 ep_free(sc); 259 return -1; 260 } 261 eisa_reg_end(e_dev); 262 263 /* Reset and Enable the card */ 264 outb(eisa_ioport->addr + EP_W0_CONFIG_CTRL, W0_P4_CMD_RESET_ADAPTER); 265 DELAY(1000); /* we must wait at least 1 ms */ 266 outb(eisa_ioport->addr + EP_W0_CONFIG_CTRL, W0_P4_CMD_ENABLE_ADAPTER); 267 268 /* Now the registers are availible through the lower ioport */ 269 270 /* 271 * Retrieve our ethernet address 272 */ 273 GO_WINDOW(0); 274 for(i = 0; i < 3; i++) 275 sc->epb->eth_addr[i] = get_e(sc, i); 276 277 /* Even we get irq number from board, we should tell him.. 278 Otherwise we never get a H/W interrupt anymore...*/ 279 if ( irq == 9 ) 280 irq = 2; 281 SET_IRQ(eisa_ioport->addr, irq); 282 283 ep_attach(sc); 284 285 if(eisa_enable_intr(e_dev, irq)) { 286 ep_free(sc); 287 eisa_release_intr(e_dev, irq, ep_intr); 288 return -1; 289 } 290 291 return 0; 292} 293 294#endif /* NEISA > 0 */ 295