This source file includes following definitions.
- ultra_probe
- ultra_probe1
- ultra_open
- ultra_reset_8390
- ultra_block_input
- ultra_block_output
- ultra_close_card
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 static char *version =
20 "smc-ultra.c:v1.11 11/21/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
21
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/errno.h>
25 #include <linux/string.h>
26 #include <asm/io.h>
27 #include <asm/system.h>
28
29 #include <linux/netdevice.h>
30 #include "8390.h"
31 extern struct device *init_etherdev(struct device *dev, int sizeof_private,
32 unsigned long *mem_startp);
33
34
35 static unsigned int ultra_portlist[] =
36 {0x200, 0x220, 0x240, 0x280, 0x300, 0x340, 0x380, 0};
37
38 int ultra_probe(struct device *dev);
39 int ultra_probe1(struct device *dev, int ioaddr);
40
41 static int ultra_open(struct device *dev);
42 static void ultra_reset_8390(struct device *dev);
43 static int ultra_block_input(struct device *dev, int count,
44 char *buf, int ring_offset);
45 static void ultra_block_output(struct device *dev, int count,
46 const unsigned char *buf, const start_page);
47 static int ultra_close_card(struct device *dev);
48
49
50 #define START_PG 0x00
51
52 #define ULTRA_CMDREG 0
53 #define ULTRA_RESET 0x80
54 #define ULTRA_MEMENB 0x40
55 #define ULTRA_NIC_OFFSET 16
56 #define ULTRA_IO_EXTENT 32
57
58
59
60
61
62 #ifdef HAVE_DEVLIST
63 struct netdev_entry ultra_drv =
64 {"ultra", ultra_probe1, NETCARD_IO_EXTENT, netcard_portlist};
65 #else
66
67 int ultra_probe(struct device *dev)
68 {
69 int i;
70 int base_addr = dev ? dev->base_addr : 0;
71
72 if (base_addr > 0x1ff)
73 return ultra_probe1(dev, base_addr);
74 else if (base_addr != 0)
75 return ENXIO;
76
77 for (i = 0; ultra_portlist[i]; i++) {
78 int ioaddr = ultra_portlist[i];
79 if (check_region(ioaddr, ULTRA_IO_EXTENT))
80 continue;
81 if (ultra_probe1(dev, ioaddr) == 0)
82 return 0;
83 }
84
85 return ENODEV;
86 }
87 #endif
88
89 int ultra_probe1(struct device *dev, int ioaddr)
90 {
91 int i;
92 int checksum = 0;
93 char *model_name;
94 unsigned char eeprom_irq = 0;
95
96 unsigned char num_pages, irqreg, addr, reg4 = inb(ioaddr + 4) & 0x7f;
97
98
99 if ((inb(ioaddr + 7) & 0xF0) != 0x20)
100 return ENODEV;
101
102
103 outb(reg4, ioaddr + 4);
104
105 for (i = 0; i < 8; i++)
106 checksum += inb(ioaddr + 8 + i);
107 if ((checksum & 0xff) != 0xFF)
108 return ENODEV;
109
110 if (dev == NULL)
111 dev = init_etherdev(0, sizeof(struct ei_device), 0);
112
113 printk("%s: SMC Ultra at %#3x,", dev->name, ioaddr);
114
115 for (i = 0; i < 6; i++)
116 printk(" %2.2X", dev->dev_addr[i] = inb(ioaddr + 8 + i));
117
118
119
120 outb(0x80 | reg4, ioaddr + 4);
121
122
123 outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
124 irqreg = inb(ioaddr + 0xd);
125 addr = inb(ioaddr + 0xb);
126
127
128
129 outb(reg4, ioaddr + 4);
130
131 model_name = "SMC Ultra";
132
133 if (dev->irq < 2) {
134 unsigned char irqmap[] = {0, 9, 3, 5, 7, 10, 11, 15};
135 int irq;
136
137
138 irq = irqmap[((irqreg & 0x40) >> 4) + ((irqreg & 0x0c) >> 2)];
139
140 if (irq == 0) {
141 printk(", failed to detect IRQ line.\n");
142 return -EAGAIN;
143 }
144 dev->irq = irq;
145 eeprom_irq = 1;
146 }
147
148
149
150 request_region(ioaddr, 32,"smc-ultra");
151
152
153 dev->base_addr = ioaddr+ULTRA_NIC_OFFSET;
154
155 {
156 int addr_tbl[4] = {0x0C0000, 0x0E0000, 0xFC0000, 0xFE0000};
157 short num_pages_tbl[4] = {0x20, 0x40, 0x80, 0xff};
158
159 dev->mem_start = ((addr & 0x0f) << 13) + addr_tbl[(addr >> 6) & 3] ;
160 num_pages = num_pages_tbl[(addr >> 4) & 3];
161 }
162
163 ethdev_init(dev);
164
165 ei_status.name = model_name;
166 ei_status.word16 = 1;
167 ei_status.tx_start_page = START_PG;
168 ei_status.rx_start_page = START_PG + TX_PAGES;
169 ei_status.stop_page = num_pages;
170
171 dev->rmem_start = dev->mem_start + TX_PAGES*256;
172 dev->mem_end = dev->rmem_end
173 = dev->mem_start + (ei_status.stop_page - START_PG)*256;
174
175 printk(",%s IRQ %d memory %#lx-%#lx.\n", eeprom_irq ? "" : "assigned ",
176 dev->irq, dev->mem_start, dev->mem_end-1);
177 if (ei_debug > 0)
178 printk(version);
179
180 ei_status.reset_8390 = &ultra_reset_8390;
181 ei_status.block_input = &ultra_block_input;
182 ei_status.block_output = &ultra_block_output;
183 dev->open = &ultra_open;
184 dev->stop = &ultra_close_card;
185 NS8390_init(dev, 0);
186
187 return 0;
188 }
189
190 static int
191 ultra_open(struct device *dev)
192 {
193 int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET;
194
195 if (request_irq(dev->irq, ei_interrupt, 0, "SMC Ultra"))
196 return -EAGAIN;
197
198 outb(ULTRA_MEMENB, ioaddr);
199 outb(0x80, ioaddr + 5);
200 outb(0x01, ioaddr + 6);
201 return ei_open(dev);
202 }
203
204 static void
205 ultra_reset_8390(struct device *dev)
206 {
207 int cmd_port = dev->base_addr - ULTRA_NIC_OFFSET;
208
209 outb(ULTRA_RESET, cmd_port);
210 if (ei_debug > 1) printk("resetting Ultra, t=%ld...", jiffies);
211 ei_status.txing = 0;
212
213 outb(ULTRA_MEMENB, cmd_port);
214
215 if (ei_debug > 1) printk("reset done\n");
216 return;
217 }
218
219
220
221
222 static int
223 ultra_block_input(struct device *dev, int count, char *buf, int ring_offset)
224 {
225 void *xfer_start = (void *)(dev->mem_start + ring_offset
226 - (START_PG<<8));
227
228
229 outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
230
231 if (xfer_start + count > (void*) dev->rmem_end) {
232
233 int semi_count = (void*)dev->rmem_end - xfer_start;
234 memcpy(buf, xfer_start, semi_count);
235 count -= semi_count;
236 memcpy(buf + semi_count, (char *)dev->rmem_start, count);
237 outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET);
238 return dev->rmem_start + count;
239 }
240 memcpy(buf, xfer_start, count);
241
242 outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET);
243 return ring_offset + count;
244 }
245
246 static void
247 ultra_block_output(struct device *dev, int count, const unsigned char *buf,
248 int start_page)
249 {
250 unsigned char *shmem
251 = (unsigned char *)dev->mem_start + ((start_page - START_PG)<<8);
252
253
254 outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
255
256 memcpy(shmem, buf, count);
257
258 outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET);
259 }
260
261 static int
262 ultra_close_card(struct device *dev)
263 {
264 int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET;
265
266 dev->start = 0;
267 dev->tbusy = 1;
268
269 if (ei_debug > 1)
270 printk("%s: Shutting down ethercard.\n", dev->name);
271
272 outb(0x00, ioaddr + 6);
273 free_irq(dev->irq);
274 irq2dev_map[dev->irq] = 0;
275
276 NS8390_init(dev, 0);
277
278
279
280
281 return 0;
282 }
283
284
285
286
287
288
289
290
291
292
293