This source file includes following definitions.
- hp_probe
- hpprobe1
- hp_reset_8390
- hp_block_input
- hp_block_output
- hp_init_card
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 static char *version =
16 "hp.c:v0.99.15k 3/3/94 Donald Becker (becker@super.org)\n";
17
18 #include <linux/config.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/errno.h>
22 #include <linux/ioport.h>
23 #include <asm/system.h>
24 #include <asm/io.h>
25
26 #include "dev.h"
27 #include "8390.h"
28
29 #ifndef HAVE_PORTRESERVE
30 #define check_region(ioaddr, size) 0
31 #define snarf_region(ioaddr, size); do ; while (0)
32 #endif
33
34 #define HP_IO_EXTENT 32
35
36 #define HP_DATAPORT 0x0c
37 #define HP_ID 0x07
38 #define HP_CONFIGURE 0x08
39 #define HP_RUN 0x01
40 #define HP_IRQ 0x0E
41 #define HP_DATAON 0x10
42 #define NIC_OFFSET 0x10
43
44 #define HP_START_PG 0x00
45 #define HP_8BSTOP_PG 0x80
46 #define HP_16BSTOP_PG 0xFF
47
48 int hp_probe(struct device *dev);
49 int hpprobe1(struct device *dev, int ioaddr);
50
51 static void hp_reset_8390(struct device *dev);
52 static int hp_block_input(struct device *dev, int count,
53 char *buf, int ring_offset);
54 static void hp_block_output(struct device *dev, int count,
55 const unsigned char *buf, const start_page);
56 static void hp_init_card(struct device *dev);
57
58
59
60 static char irqmap[16] = { 0, 0, 4, 6, 8,10, 0,14, 0, 4, 2,12,0,0,0,0};
61
62
63
64
65
66
67 int hp_probe(struct device *dev)
68 {
69 int *port, ports[] = {0x300, 0x320, 0x340, 0x280, 0x2C0, 0x200, 0x240, 0};
70 short ioaddr = dev->base_addr;
71
72 if (ioaddr > 0x1ff)
73 return hpprobe1(dev, ioaddr);
74 else if (ioaddr > 0)
75 return ENXIO;
76
77 for (port = &ports[0]; *port; port++) {
78 if (check_region(*port, HP_IO_EXTENT))
79 continue;
80 if (hpprobe1(dev, *port) == 0) {
81 return 0;
82 }
83 }
84 return ENODEV;
85 }
86
87 int hpprobe1(struct device *dev, int ioaddr)
88 {
89 int i, board_id, wordmode;
90 char *name;
91 unsigned char *station_addr = dev->dev_addr;
92
93
94
95
96 if (inb(ioaddr) != 0x08
97 || inb(ioaddr+1) != 0x00
98 || inb(ioaddr+2) != 0x09
99 || inb(ioaddr+14) == 0x57)
100 return ENODEV;
101
102
103
104 if ((board_id = inb(ioaddr + HP_ID)) & 0x80) {
105 name = "HP27247";
106 wordmode = 1;
107 } else {
108 name = "HP27250";
109 wordmode = 0;
110 }
111
112
113 snarf_region(ioaddr, HP_IO_EXTENT);
114
115 printk("%s: %s (ID %02x) at %#3x,", dev->name, name, board_id, ioaddr);
116
117 for(i = 0; i < ETHER_ADDR_LEN; i++)
118 printk(" %2.2x", station_addr[i] = inb(ioaddr + i));
119
120
121 if (dev->irq < 2) {
122 int irq_16list[] = { 11, 10, 5, 3, 4, 7, 9, 0};
123 int irq_8list[] = { 7, 5, 3, 4, 9, 0};
124 int *irqp = wordmode ? irq_16list : irq_8list;
125 do {
126 int irq = *irqp;
127 if (request_irq (irq, NULL) != -EBUSY) {
128 autoirq_setup(0);
129
130 outb_p(irqmap[irq] | HP_RUN, ioaddr + HP_CONFIGURE);
131 outb_p( 0x00 | HP_RUN, ioaddr + HP_CONFIGURE);
132 if (irq == autoirq_report(0)
133 && request_irq (irq, &ei_interrupt) == 0) {
134 printk(" selecting IRQ %d.\n", irq);
135 dev->irq = *irqp;
136 break;
137 }
138 }
139 } while (*++irqp);
140 if (*irqp == 0) {
141 printk(" no free IRQ lines.\n");
142 return EBUSY;
143 }
144 } else {
145 if (dev->irq == 2)
146 dev->irq = 9;
147 if (irqaction(dev->irq, &ei_sigaction)) {
148 printk (" unable to get IRQ %d.\n", dev->irq);
149 return EBUSY;
150 }
151 }
152
153 if (ei_debug > 1)
154 printk(version);
155
156
157 dev->base_addr = ioaddr + NIC_OFFSET;
158
159 ethdev_init(dev);
160
161 ei_status.name = name;
162 ei_status.word16 = wordmode;
163 ei_status.tx_start_page = HP_START_PG;
164 ei_status.rx_start_page = HP_START_PG + TX_PAGES;
165 ei_status.stop_page = wordmode ? HP_16BSTOP_PG : HP_8BSTOP_PG;
166
167 ei_status.reset_8390 = &hp_reset_8390;
168 ei_status.block_input = &hp_block_input;
169 ei_status.block_output = &hp_block_output;
170 hp_init_card(dev);
171
172 return 0;
173 }
174
175 static void
176 hp_reset_8390(struct device *dev)
177 {
178 int hp_base = dev->base_addr - NIC_OFFSET;
179 int saved_config = inb_p(hp_base + HP_CONFIGURE);
180
181 if (ei_debug > 1) printk("resetting the 8390 time=%ld...", jiffies);
182 outb_p(0x00, hp_base + HP_CONFIGURE);
183 ei_status.txing = 0;
184
185 SLOW_DOWN_IO;
186 SLOW_DOWN_IO;
187
188 outb_p(saved_config, hp_base + HP_CONFIGURE);
189 SLOW_DOWN_IO; SLOW_DOWN_IO;
190
191 if ((inb_p(hp_base+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
192 printk("%s: hp_reset_8390() did not complete.\n", dev->name);
193
194 if (ei_debug > 1) printk("8390 reset done (%ld).", jiffies);
195 return;
196 }
197
198
199
200
201
202
203 static int
204 hp_block_input(struct device *dev, int count, char *buf, int ring_offset)
205 {
206 int nic_base = dev->base_addr;
207 int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
208 int xfer_count = count;
209
210 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
211 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
212 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
213 outb_p(count >> 8, nic_base + EN0_RCNTHI);
214 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
215 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
216 outb_p(E8390_RREAD+E8390_START, nic_base);
217 if (ei_status.word16) {
218 insw(nic_base - NIC_OFFSET + HP_DATAPORT,buf,count>>1);
219 if (count & 0x01)
220 buf[count-1] = inb(nic_base - NIC_OFFSET + HP_DATAPORT), xfer_count++;
221 } else {
222 insb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
223 }
224
225 if (ei_debug > 0) {
226 int high = inb_p(nic_base + EN0_RSARHI);
227 int low = inb_p(nic_base + EN0_RSARLO);
228 int addr = (high << 8) + low;
229
230 if (((ring_offset + xfer_count) & 0xff) != (addr & 0xff))
231 printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
232 dev->name, ring_offset + xfer_count, addr);
233 }
234 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
235 return ring_offset + count;
236 }
237
238 static void
239 hp_block_output(struct device *dev, int count,
240 const unsigned char *buf, const start_page)
241 {
242 int nic_base = dev->base_addr;
243 int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
244
245 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
246
247
248
249 if (ei_status.word16 && (count & 0x01))
250 count++;
251
252 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base);
253
254 #ifdef ei8390_bug
255
256
257 outb_p(0x42, nic_base + EN0_RCNTLO);
258 outb_p(0, nic_base + EN0_RCNTHI);
259 outb_p(0xff, nic_base + EN0_RSARLO);
260 outb_p(0x00, nic_base + EN0_RSARHI);
261 outb_p(E8390_RREAD+E8390_START, EN_CMD);
262
263 inb_p(0x61);
264 inb_p(0x61);
265 #endif
266
267 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
268 outb_p(count >> 8, nic_base + EN0_RCNTHI);
269 outb_p(0x00, nic_base + EN0_RSARLO);
270 outb_p(start_page, nic_base + EN0_RSARHI);
271
272 outb_p(E8390_RWRITE+E8390_START, nic_base);
273 if (ei_status.word16) {
274
275 outsw(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count>>1);
276 } else {
277 outsb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
278 }
279
280
281
282
283 if (ei_debug > 0) {
284 int high = inb_p(nic_base + EN0_RSARHI);
285 int low = inb_p(nic_base + EN0_RSARLO);
286 int addr = (high << 8) + low;
287 if ((start_page << 8) + count != addr)
288 printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
289 dev->name, (start_page << 8) + count, addr);
290 }
291 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
292 return;
293 }
294
295
296 static void
297 hp_init_card(struct device *dev)
298 {
299 int irq = dev->irq;
300 NS8390_init(dev, 0);
301 outb_p(irqmap[irq&0x0f] | HP_RUN,
302 dev->base_addr - NIC_OFFSET + HP_CONFIGURE);
303 return;
304 }
305
306
307
308
309
310
311
312
313
314
315