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