This source file includes following definitions.
- hp_probe
- hp_probe1
- hp_reset_8390
- hp_get_8390_hdr
- hp_block_input
- hp_block_output
- hp_init_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 static const char *version =
22 "hp.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
23
24
25 #include <linux/module.h>
26
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 #include "8390.h"
38
39
40 static unsigned int hppclan_portlist[] =
41 { 0x300, 0x320, 0x340, 0x280, 0x2C0, 0x200, 0x240, 0};
42
43 #define HP_IO_EXTENT 32
44
45 #define HP_DATAPORT 0x0c
46 #define HP_ID 0x07
47 #define HP_CONFIGURE 0x08
48 #define HP_RUN 0x01
49 #define HP_IRQ 0x0E
50 #define HP_DATAON 0x10
51 #define NIC_OFFSET 0x10
52
53 #define HP_START_PG 0x00
54 #define HP_8BSTOP_PG 0x80
55 #define HP_16BSTOP_PG 0xFF
56
57 int hp_probe(struct device *dev);
58 int hp_probe1(struct device *dev, int ioaddr);
59
60 static void hp_reset_8390(struct device *dev);
61 static void hp_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
62 int ring_page);
63 static void hp_block_input(struct device *dev, int count,
64 struct sk_buff *skb , int ring_offset);
65 static void hp_block_output(struct device *dev, int count,
66 const unsigned char *buf, const start_page);
67
68 static void hp_init_card(struct device *dev);
69
70
71
72 static char irqmap[16] = { 0, 0, 4, 6, 8,10, 0,14, 0, 4, 2,12,0,0,0,0};
73
74
75
76
77
78 #ifdef HAVE_DEVLIST
79 struct netdev_entry netcard_drv =
80 {"hp", hp_probe1, HP_IO_EXTENT, hppclan_portlist};
81 #else
82
83 int hp_probe(struct device *dev)
84 {
85 int i;
86 int base_addr = dev ? dev->base_addr : 0;
87
88 if (base_addr > 0x1ff)
89 return hp_probe1(dev, base_addr);
90 else if (base_addr != 0)
91 return ENXIO;
92
93 for (i = 0; hppclan_portlist[i]; i++) {
94 int ioaddr = hppclan_portlist[i];
95 if (check_region(ioaddr, HP_IO_EXTENT))
96 continue;
97 if (hp_probe1(dev, ioaddr) == 0)
98 return 0;
99 }
100
101 return ENODEV;
102 }
103 #endif
104
105 int hp_probe1(struct device *dev, int ioaddr)
106 {
107 int i, board_id, wordmode;
108 const char *name;
109
110
111
112
113 if (inb(ioaddr) != 0x08
114 || inb(ioaddr+1) != 0x00
115 || inb(ioaddr+2) != 0x09
116 || inb(ioaddr+14) == 0x57)
117 return ENODEV;
118
119
120
121 if ((board_id = inb(ioaddr + HP_ID)) & 0x80) {
122 name = "HP27247";
123 wordmode = 1;
124 } else {
125 name = "HP27250";
126 wordmode = 0;
127 }
128
129 if (dev == NULL)
130 dev = init_etherdev(0, sizeof(struct ei_device));
131
132 printk("%s: %s (ID %02x) at %#3x,", dev->name, name, board_id, ioaddr);
133
134 for(i = 0; i < ETHER_ADDR_LEN; i++)
135 printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
136
137
138 if (dev->irq < 2) {
139 int irq_16list[] = { 11, 10, 5, 3, 4, 7, 9, 0};
140 int irq_8list[] = { 7, 5, 3, 4, 9, 0};
141 int *irqp = wordmode ? irq_16list : irq_8list;
142 do {
143 int irq = *irqp;
144 if (request_irq (irq, NULL, 0, "bogus") != -EBUSY) {
145 autoirq_setup(0);
146
147 outb_p(irqmap[irq] | HP_RUN, ioaddr + HP_CONFIGURE);
148 outb_p( 0x00 | HP_RUN, ioaddr + HP_CONFIGURE);
149 if (irq == autoirq_report(0)
150 && request_irq (irq, &ei_interrupt, 0, "hp") == 0) {
151 printk(" selecting IRQ %d.\n", irq);
152 dev->irq = *irqp;
153 break;
154 }
155 }
156 } while (*++irqp);
157 if (*irqp == 0) {
158 printk(" no free IRQ lines.\n");
159 return EBUSY;
160 }
161 } else {
162 if (dev->irq == 2)
163 dev->irq = 9;
164 if (request_irq(dev->irq, ei_interrupt, 0, "hp")) {
165 printk (" unable to get IRQ %d.\n", dev->irq);
166 return EBUSY;
167 }
168 }
169
170
171 request_region(ioaddr, HP_IO_EXTENT,"hp");
172
173 if (ei_debug > 1)
174 printk(version);
175
176
177 dev->base_addr = ioaddr + NIC_OFFSET;
178
179 ethdev_init(dev);
180
181 ei_status.name = name;
182 ei_status.word16 = wordmode;
183 ei_status.tx_start_page = HP_START_PG;
184 ei_status.rx_start_page = HP_START_PG + TX_PAGES;
185 ei_status.stop_page = wordmode ? HP_16BSTOP_PG : HP_8BSTOP_PG;
186
187 ei_status.reset_8390 = &hp_reset_8390;
188 ei_status.get_8390_hdr = &hp_get_8390_hdr;
189 ei_status.block_input = &hp_block_input;
190 ei_status.block_output = &hp_block_output;
191 hp_init_card(dev);
192
193 return 0;
194 }
195
196 static void
197 hp_reset_8390(struct device *dev)
198 {
199 int hp_base = dev->base_addr - NIC_OFFSET;
200 int saved_config = inb_p(hp_base + HP_CONFIGURE);
201
202 if (ei_debug > 1) printk("resetting the 8390 time=%ld...", jiffies);
203 outb_p(0x00, hp_base + HP_CONFIGURE);
204 ei_status.txing = 0;
205
206 SLOW_DOWN_IO;
207 SLOW_DOWN_IO;
208
209 outb_p(saved_config, hp_base + HP_CONFIGURE);
210 SLOW_DOWN_IO; SLOW_DOWN_IO;
211
212 if ((inb_p(hp_base+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
213 printk("%s: hp_reset_8390() did not complete.\n", dev->name);
214
215 if (ei_debug > 1) printk("8390 reset done (%ld).", jiffies);
216 return;
217 }
218
219 static void
220 hp_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
221 {
222 int nic_base = dev->base_addr;
223 int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
224
225 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
226 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
227 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
228 outb_p(0, nic_base + EN0_RCNTHI);
229 outb_p(0, nic_base + EN0_RSARLO);
230 outb_p(ring_page, nic_base + EN0_RSARHI);
231 outb_p(E8390_RREAD+E8390_START, nic_base);
232
233 if (ei_status.word16)
234 insw(nic_base - NIC_OFFSET + HP_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
235 else
236 insb(nic_base - NIC_OFFSET + HP_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
237
238 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
239 }
240
241
242
243
244
245
246 static void
247 hp_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
248 {
249 int nic_base = dev->base_addr;
250 int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
251 int xfer_count = count;
252 char *buf = skb->data;
253
254 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
255 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
256 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
257 outb_p(count >> 8, nic_base + EN0_RCNTHI);
258 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
259 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
260 outb_p(E8390_RREAD+E8390_START, nic_base);
261 if (ei_status.word16) {
262 insw(nic_base - NIC_OFFSET + HP_DATAPORT,buf,count>>1);
263 if (count & 0x01)
264 buf[count-1] = inb(nic_base - NIC_OFFSET + HP_DATAPORT), xfer_count++;
265 } else {
266 insb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
267 }
268
269 if (ei_debug > 0) {
270 int high = inb_p(nic_base + EN0_RSARHI);
271 int low = inb_p(nic_base + EN0_RSARLO);
272 int addr = (high << 8) + low;
273
274 if (((ring_offset + xfer_count) & 0xff) != (addr & 0xff))
275 printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
276 dev->name, ring_offset + xfer_count, addr);
277 }
278 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
279 }
280
281 static void
282 hp_block_output(struct device *dev, int count,
283 const unsigned char *buf, const start_page)
284 {
285 int nic_base = dev->base_addr;
286 int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
287
288 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
289
290
291
292 if (ei_status.word16 && (count & 0x01))
293 count++;
294
295 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base);
296
297 #ifdef NE8390_RW_BUGFIX
298
299
300 outb_p(0x42, nic_base + EN0_RCNTLO);
301 outb_p(0, nic_base + EN0_RCNTHI);
302 outb_p(0xff, nic_base + EN0_RSARLO);
303 outb_p(0x00, nic_base + EN0_RSARHI);
304 #define NE_CMD 0x00
305 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
306
307 inb_p(0x61);
308 inb_p(0x61);
309 #endif
310
311 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
312 outb_p(count >> 8, nic_base + EN0_RCNTHI);
313 outb_p(0x00, nic_base + EN0_RSARLO);
314 outb_p(start_page, nic_base + EN0_RSARHI);
315
316 outb_p(E8390_RWRITE+E8390_START, nic_base);
317 if (ei_status.word16) {
318
319 outsw(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count>>1);
320 } else {
321 outsb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
322 }
323
324
325
326
327 if (ei_debug > 0) {
328 int high = inb_p(nic_base + EN0_RSARHI);
329 int low = inb_p(nic_base + EN0_RSARLO);
330 int addr = (high << 8) + low;
331 if ((start_page << 8) + count != addr)
332 printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
333 dev->name, (start_page << 8) + count, addr);
334 }
335 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
336 return;
337 }
338
339
340 static void
341 hp_init_card(struct device *dev)
342 {
343 int irq = dev->irq;
344 NS8390_init(dev, 0);
345 outb_p(irqmap[irq&0x0f] | HP_RUN,
346 dev->base_addr - NIC_OFFSET + HP_CONFIGURE);
347 return;
348 }
349
350 #ifdef MODULE
351 static char devicename[9] = { 0, };
352 static struct device dev_hp = {
353 devicename,
354 0, 0, 0, 0,
355 0, 0,
356 0, 0, 0, NULL, hp_probe };
357
358 static int io = 300;
359 static int irq = 0;
360
361 int init_module(void)
362 {
363 if (io == 0)
364 printk("hp: You should not use auto-probing with insmod!\n");
365 dev_hp.base_addr = io;
366 dev_hp.irq = irq;
367 if (register_netdev(&dev_hp) != 0) {
368 printk("hp: register_netdev() returned non-zero.\n");
369 return -EIO;
370 }
371 return 0;
372 }
373
374 void
375 cleanup_module(void)
376 {
377 int ioaddr = dev_hp.base_addr - NIC_OFFSET;
378
379 unregister_netdev(&dev_hp);
380
381
382 free_irq(dev_hp.irq);
383 release_region(ioaddr, HP_IO_EXTENT);
384 }
385 #endif
386
387
388
389
390
391
392
393
394
395