unstack - fix ipcvecs
[minix.git] / sys / arch / i386 / stand / lib / netif / 3c590.c
blob44dd5da14cd57ede91239d3b46116a190d56cb31
1 /* $NetBSD: 3c590.c,v 1.15 2008/12/14 18:46:33 christos Exp $ */
3 /* stripped down from freebsd:sys/i386/netboot/3c509.c */
6 /**************************************************************************
7 NETBOOT - BOOTP/TFTP Bootstrap Program
9 Author: Martin Renters.
10 Date: Mar 22 1995
12 This code is based heavily on David Greenman's if_ed.c driver and
13 Andres Vega Garcia's if_ep.c driver.
15 Copyright (C) 1993-1994, David Greenman, Martin Renters.
16 Copyright (C) 1993-1995, Andres Vega Garcia.
17 Copyright (C) 1995, Serge Babkin.
18 This software may be used, modified, copied, distributed, and sold, in
19 both source and binary form provided that the above copyright and these
20 terms are retained. Under no circumstances are the authors responsible for
21 the proper functioning of this software, nor do the authors assume any
22 responsibility for damages incurred with its use.
24 3c509 support added by Serge Babkin (babkin@hq.icb.chel.su)
26 3c509.c,v 1.2 1995/05/30 07:58:52 rgrimes Exp
28 ***************************************************************************/
30 #include <sys/types.h>
31 #include <machine/pio.h>
33 #include <lib/libsa/stand.h>
35 #include <libi386.h>
36 #include <pcivar.h>
38 #if defined(_STANDALONE) && !defined(SUPPORT_NO_NETBSD)
39 #include <lib/libkern/libkern.h>
40 #include <bootinfo.h>
41 #endif
43 #include "etherdrv.h"
44 #include "3c509.h"
46 #define EP_W3_INTERNAL_CONFIG 0x00 /* 32 bits */
47 #define EP_W3_RESET_OPTIONS 0x08 /* 16 bits */
49 unsigned ether_medium;
50 unsigned short eth_base;
52 extern void epreset(void);
53 extern int ep_get_e(int);
55 u_char eth_myaddr[6];
57 static struct mtabentry {
58 int address_cfg; /* configured connector */
59 int config_bit; /* connector present */
60 char *name;
61 } mediatab[] = { /* indexed by media type - etherdrv.h */
62 {3, 0x10, "BNC"},
63 {0, 0x08, "UTP"},
64 {1, 0x20, "AUI"},
65 {6, 0x40, "MII"},
68 #if defined(_STANDALONE) && !defined(SUPPORT_NO_NETBSD)
69 static struct btinfo_netif bi_netif;
70 #endif
72 /**************************************************************************
73 ETH_PROBE - Look for an adapter
74 ***************************************************************************/
75 int
76 EtherInit(unsigned char *myadr)
78 /* common variables */
79 int i, j;
80 /* variables for 3C509 */
81 u_short *p;
82 struct mtabentry *m;
84 /*********************************************************
85 Search for 3Com 590 card
86 ***********************************************************/
88 pcihdl_t hdl;
89 int iobase;
91 if (pcicheck() == -1) {
92 printf("cannot access PCI\n");
93 return 0;
96 if (pcifinddev(0x10b7, 0x5900, &hdl) &&
97 pcifinddev(0x10b7, 0x5950, &hdl) &&
98 pcifinddev(0x10b7, 0x9000, &hdl) &&
99 pcifinddev(0x10b7, 0x9001, &hdl) &&
100 pcifinddev(0x10b7, 0x9050, &hdl)) {
101 printf("cannot find 3c59x / 3c90x\n");
102 return 0;
105 if (pcicfgread(&hdl, 0x10, &iobase) || !(iobase & 1)) {
106 printf("cannot map IO space\n");
107 return 0;
109 eth_base = iobase & 0xfffffffc;
111 /* test for presence of connectors */
112 GO_WINDOW(3);
113 i = inb(IS_BASE + EP_W3_RESET_OPTIONS);
114 j = (inw(IS_BASE + EP_W3_INTERNAL_CONFIG + 2) >> 4) & 7;
116 GO_WINDOW(0);
118 for (ether_medium = 0, m = mediatab;
119 ether_medium < sizeof(mediatab) / sizeof(mediatab[0]);
120 ether_medium++, m++) {
121 if (j == m->address_cfg) {
122 if (!(i & m->config_bit)) {
123 printf("%s not present\n", m->name);
124 return 0;
126 printf("using %s\n", m->name);
127 goto ok;
130 printf("unknown connector\n");
131 return 0;
135 * Read the station address from the eeprom
137 p = (u_short *) eth_myaddr;
138 for (i = 0; i < 3; i++) {
139 u_short help;
140 GO_WINDOW(0);
141 help = ep_get_e(i);
142 p[i] = ((help & 0xff) << 8) | ((help & 0xff00) >> 8);
143 GO_WINDOW(2);
144 outw(BASE + EP_W2_ADDR_0 + (i * 2), help);
146 for (i = 0; i < 6; i++)
147 myadr[i] = eth_myaddr[i];
149 epreset();
152 #if defined(_STANDALONE) && !defined(SUPPORT_NO_NETBSD)
153 strncpy(bi_netif.ifname, "ep", sizeof(bi_netif.ifname));
154 bi_netif.bus = BI_BUS_PCI;
155 bi_netif.addr.tag = hdl;
157 BI_ADD(&bi_netif, BTINFO_NETIF, sizeof(bi_netif));
158 #endif
160 return 1;