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