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