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