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