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