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