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