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