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