This source file includes following definitions.
- hp_plus_probe
- hpp_probe1
- hpp_open
- hpp_close
- hpp_reset_8390
- hpp_io_get_8390_hdr
- hpp_io_block_input
- hpp_mem_get_8390_hdr
- hpp_mem_block_input
- hpp_io_block_output
- hpp_mem_block_output
- 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 static const char *version =
22 "hp-plus.c:v1.10 9/24/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
23
24 #include <linux/module.h>
25
26 #include <linux/string.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/errno.h>
30 #include <linux/ioport.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33
34 #include <asm/system.h>
35 #include <asm/io.h>
36
37
38 #include "8390.h"
39
40
41 static unsigned int hpplus_portlist[] =
42 {0x200, 0x240, 0x280, 0x2C0, 0x300, 0x320, 0x340, 0};
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 #define HP_ID 0x00
70 #define HP_PAGING 0x02
71 #define HPP_OPTION 0x04
72 #define HPP_OUT_ADDR 0x08
73 #define HPP_IN_ADDR 0x0A
74 #define HP_DATAPORT 0x0c
75 #define NIC_OFFSET 0x10
76 #define HP_IO_EXTENT 32
77
78 #define HP_START_PG 0x00
79 #define HP_STOP_PG 0x80
80
81
82 enum PageName {
83 Perf_Page = 0,
84 MAC_Page = 1,
85 HW_Page = 2,
86 LAN_Page = 4,
87 ID_Page = 6 };
88
89
90 enum HP_Option {
91 NICReset = 1, ChipReset = 2,
92 EnableIRQ = 4, FakeIntr = 8, BootROMEnb = 0x10, IOEnb = 0x20,
93 MemEnable = 0x40, ZeroWait = 0x80, MemDisable = 0x1000, };
94
95 int hp_plus_probe(struct device *dev);
96 int hpp_probe1(struct device *dev, int ioaddr);
97
98 static void hpp_reset_8390(struct device *dev);
99 static int hpp_open(struct device *dev);
100 static int hpp_close(struct device *dev);
101 static void hpp_mem_block_input(struct device *dev, int count,
102 struct sk_buff *skb, int ring_offset);
103 static void hpp_mem_block_output(struct device *dev, int count,
104 const unsigned char *buf, const start_page);
105 static void hpp_mem_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
106 int ring_page);
107 static void hpp_io_block_input(struct device *dev, int count,
108 struct sk_buff *skb, int ring_offset);
109 static void hpp_io_block_output(struct device *dev, int count,
110 const unsigned char *buf, const start_page);
111 static void hpp_io_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
112 int ring_page);
113
114
115
116
117 #ifdef HAVE_DEVLIST
118
119
120 struct netdev_entry hpplus_drv =
121 {"hpplus", hpp_probe1, HP_IO_EXTENT, hpplus_portlist};
122 #else
123
124 int hp_plus_probe(struct device *dev)
125 {
126 int i;
127 int base_addr = dev ? dev->base_addr : 0;
128
129 if (base_addr > 0x1ff)
130 return hpp_probe1(dev, base_addr);
131 else if (base_addr != 0)
132 return ENXIO;
133
134 for (i = 0; hpplus_portlist[i]; i++) {
135 int ioaddr = hpplus_portlist[i];
136 if (check_region(ioaddr, HP_IO_EXTENT))
137 continue;
138 if (hpp_probe1(dev, ioaddr) == 0)
139 return 0;
140 }
141
142 return ENODEV;
143 }
144 #endif
145
146
147 int hpp_probe1(struct device *dev, int ioaddr)
148 {
149 int i;
150 unsigned char checksum = 0;
151 const char *name = "HP-PC-LAN+";
152 int mem_start;
153
154
155 if (inw(ioaddr + HP_ID) != 0x4850
156 || (inw(ioaddr + HP_PAGING) & 0xfff0) != 0x5300)
157 return ENODEV;
158
159 if (dev == NULL)
160 dev = init_etherdev(0, sizeof(struct ei_device));
161
162 printk("%s: %s at %#3x,", dev->name, name, ioaddr);
163
164
165 outw(MAC_Page, ioaddr + HP_PAGING);
166
167 for(i = 0; i < ETHER_ADDR_LEN; i++) {
168 unsigned char inval = inb(ioaddr + 8 + i);
169 dev->dev_addr[i] = inval;
170 checksum += inval;
171 printk(" %2.2x", inval);
172 }
173 checksum += inb(ioaddr + 14);
174
175 if (checksum != 0xff) {
176 printk(" bad checksum %2.2x.\n", checksum);
177 return ENODEV;
178 } else {
179
180 outw(ID_Page, ioaddr + HP_PAGING);
181 printk(" ID %4.4x", inw(ioaddr + 12));
182 }
183
184
185 request_region(ioaddr, HP_IO_EXTENT,"hp-plus");
186
187
188 outw(HW_Page, ioaddr + HP_PAGING);
189 {
190 int irq = inb(ioaddr + 13) & 0x0f;
191 int option = inw(ioaddr + HPP_OPTION);
192
193 dev->irq = irq;
194 if (option & MemEnable) {
195 mem_start = inw(ioaddr + 9) << 8;
196 printk(", IRQ %d, memory address %#x.\n", irq, mem_start);
197 } else {
198 mem_start = 0;
199 printk(", IRQ %d, programmed-I/O mode.\n", irq);
200 }
201 }
202
203 printk( "%s%s", KERN_INFO, version);
204
205
206 outw((HP_START_PG + TX_2X_PAGES) | ((HP_STOP_PG - 1) << 8), ioaddr + 14);
207
208
209 dev->base_addr = ioaddr + NIC_OFFSET;
210
211 ethdev_init(dev);
212
213 dev->open = &hpp_open;
214 dev->stop = &hpp_close;
215
216 ei_status.name = name;
217 ei_status.word16 = 0;
218 ei_status.tx_start_page = HP_START_PG;
219 ei_status.rx_start_page = HP_START_PG + TX_2X_PAGES;
220 ei_status.stop_page = HP_STOP_PG;
221
222 ei_status.reset_8390 = &hpp_reset_8390;
223 ei_status.block_input = &hpp_io_block_input;
224 ei_status.block_output = &hpp_io_block_output;
225 ei_status.get_8390_hdr = &hpp_io_get_8390_hdr;
226
227
228 if (mem_start) {
229 ei_status.block_input = &hpp_mem_block_input;
230 ei_status.block_output = &hpp_mem_block_output;
231 ei_status.get_8390_hdr = &hpp_mem_get_8390_hdr;
232 dev->mem_start = mem_start;
233 dev->rmem_start = dev->mem_start + TX_2X_PAGES*256;
234 dev->mem_end = dev->rmem_end
235 = dev->mem_start + (HP_STOP_PG - HP_START_PG)*256;
236 }
237
238 outw(Perf_Page, ioaddr + HP_PAGING);
239 NS8390_init(dev, 0);
240
241 outw(inw(ioaddr + HPP_OPTION) & ~EnableIRQ, ioaddr + HPP_OPTION);
242
243 return 0;
244 }
245
246 static int
247 hpp_open(struct device *dev)
248 {
249 int ioaddr = dev->base_addr - NIC_OFFSET;
250 int option_reg;
251
252 if (request_irq(dev->irq, &ei_interrupt, 0, "hp-plus")) {
253 return -EAGAIN;
254 }
255
256
257 option_reg = inw(ioaddr + HPP_OPTION);
258 outw(option_reg & ~(NICReset + ChipReset), ioaddr + HPP_OPTION);
259 SLOW_DOWN_IO; SLOW_DOWN_IO;
260
261 outw(option_reg | (EnableIRQ + NICReset + ChipReset), ioaddr + HPP_OPTION);
262
263
264 outw(HW_Page, ioaddr + HP_PAGING);
265 outw((HP_START_PG + TX_2X_PAGES) | ((HP_STOP_PG - 1) << 8), ioaddr + 14);
266
267
268 outw(Perf_Page, ioaddr + HP_PAGING);
269
270 return ei_open(dev);
271 }
272
273 static int
274 hpp_close(struct device *dev)
275 {
276 int ioaddr = dev->base_addr - NIC_OFFSET;
277 int option_reg = inw(ioaddr + HPP_OPTION);
278
279 free_irq(dev->irq);
280 irq2dev_map[dev->irq] = NULL;
281 NS8390_init(dev, 0);
282 outw((option_reg & ~EnableIRQ) | MemDisable | NICReset | ChipReset,
283 ioaddr + HPP_OPTION);
284
285 return 0;
286 }
287
288 static void
289 hpp_reset_8390(struct device *dev)
290 {
291 int ioaddr = dev->base_addr - NIC_OFFSET;
292 int option_reg = inw(ioaddr + HPP_OPTION);
293
294 if (ei_debug > 1) printk("resetting the 8390 time=%ld...", jiffies);
295
296 outw(option_reg & ~(NICReset + ChipReset), ioaddr + HPP_OPTION);
297
298 SLOW_DOWN_IO;
299 SLOW_DOWN_IO;
300 ei_status.txing = 0;
301 outw(option_reg | (EnableIRQ + NICReset + ChipReset), ioaddr + HPP_OPTION);
302
303 SLOW_DOWN_IO; SLOW_DOWN_IO;
304
305
306 if ((inb_p(ioaddr+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
307 printk("%s: hp_reset_8390() did not complete.\n", dev->name);
308
309 if (ei_debug > 1) printk("8390 reset done (%ld).", jiffies);
310 return;
311 }
312
313
314
315
316 static void
317 hpp_io_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
318 {
319 int ioaddr = dev->base_addr - NIC_OFFSET;
320
321 outw((ring_page<<8), ioaddr + HPP_IN_ADDR);
322 insw(ioaddr + HP_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
323 }
324
325
326
327 static void
328 hpp_io_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
329 {
330 int ioaddr = dev->base_addr - NIC_OFFSET;
331 char *buf = skb->data;
332
333 outw(ring_offset, ioaddr + HPP_IN_ADDR);
334 insw(ioaddr + HP_DATAPORT, buf, count>>1);
335 if (count & 0x01)
336 buf[count-1] = inw(ioaddr + HP_DATAPORT);
337 }
338
339
340
341 static void
342 hpp_mem_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
343 {
344 int ioaddr = dev->base_addr - NIC_OFFSET;
345 int option_reg = inw(ioaddr + HPP_OPTION);
346
347 outw((ring_page<<8), ioaddr + HPP_IN_ADDR);
348 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
349 memcpy_fromio(hdr, dev->mem_start, sizeof(struct e8390_pkt_hdr));
350 outw(option_reg, ioaddr + HPP_OPTION);
351 hdr->count = (hdr->count + 3) & ~3;
352 }
353
354 static void
355 hpp_mem_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
356 {
357 int ioaddr = dev->base_addr - NIC_OFFSET;
358 int option_reg = inw(ioaddr + HPP_OPTION);
359
360 outw(ring_offset, ioaddr + HPP_IN_ADDR);
361
362 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
363
364
365
366
367
368 memcpy_fromio(skb->data, dev->mem_start, count);
369 outw(option_reg, ioaddr + HPP_OPTION);
370 }
371
372
373
374 static void
375 hpp_io_block_output(struct device *dev, int count,
376 const unsigned char *buf, const start_page)
377 {
378 int ioaddr = dev->base_addr - NIC_OFFSET;
379 outw(start_page << 8, ioaddr + HPP_OUT_ADDR);
380 outsl(ioaddr + HP_DATAPORT, buf, (count+3)>>2);
381 return;
382 }
383
384 static void
385 hpp_mem_block_output(struct device *dev, int count,
386 const unsigned char *buf, const start_page)
387 {
388 int ioaddr = dev->base_addr - NIC_OFFSET;
389 int option_reg = inw(ioaddr + HPP_OPTION);
390
391 outw(start_page << 8, ioaddr + HPP_OUT_ADDR);
392 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
393 memcpy_toio(dev->mem_start, buf, (count + 3) & ~3);
394 outw(option_reg, ioaddr + HPP_OPTION);
395
396 return;
397 }
398
399 #ifdef MODULE
400 static char devicename[9] = { 0, };
401 static struct device dev_hp = {
402 devicename,
403 0, 0, 0, 0,
404 0, 0,
405 0, 0, 0, NULL, hp_plus_probe };
406
407 static int io = 0x200;
408 static int irq = 0;
409
410 int init_module(void)
411 {
412 if (io == 0)
413 printk("HP-plus: You should not use auto-probing with insmod!\n");
414 dev_hp.base_addr = io;
415 dev_hp.irq = irq;
416 if (register_netdev(&dev_hp) != 0) {
417 printk("HP-plus: register_netdev() returned non-zero.\n");
418 return -EIO;
419 }
420 return 0;
421 }
422
423 void
424 cleanup_module(void)
425 {
426 int ioaddr = dev_hp.base_addr - NIC_OFFSET;
427
428 unregister_netdev(&dev_hp);
429
430
431 release_region(ioaddr, HP_IO_EXTENT);
432 }
433 #endif
434
435
436
437
438
439
440
441
442
443