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