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