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