Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / drivers / net / hp.c
blob60b723bfadee7399fd0a003631b0847d0b1c81e7
1 /* hp.c: A HP LAN ethernet driver for linux. */
2 /*
3 Written 1993-94 by Donald Becker.
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency.
8 This software may be used and distributed according to the terms
9 of the GNU Public License, incorporated herein by reference.
11 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
12 Center of Excellence in Space Data and Information Sciences
13 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
15 This is a driver for the HP PC-LAN adaptors.
17 Sources:
18 The Crynwr packet driver.
21 static const char*version =
22 "hp.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
25 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/errno.h>
30 #include <linux/ioport.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/init.h>
34 #include <linux/delay.h>
36 #include <asm/system.h>
37 #include <asm/io.h>
39 #include"8390.h"
41 /* A zero-terminated list of I/O addresses to be probed. */
42 static unsigned int hppclan_portlist[] __initdata =
43 {0x300,0x320,0x340,0x280,0x2C0,0x200,0x240,0};
45 #define HP_IO_EXTENT 32
47 #define HP_DATAPORT 0x0c/* "Remote DMA" data port. */
48 #define HP_ID 0x07
49 #define HP_CONFIGURE 0x08/* Configuration register. */
50 #define HP_RUN 0x01/* 1 == Run, 0 == reset. */
51 #define HP_IRQ 0x0E/* Mask for software-configured IRQ line. */
52 #define HP_DATAON 0x10/* Turn on dataport */
53 #define NIC_OFFSET 0x10/* Offset the 8390 registers. */
55 #define HP_START_PG 0x00/* First page of TX buffer */
56 #define HP_8BSTOP_PG 0x80/* Last page +1 of RX ring */
57 #define HP_16BSTOP_PG 0xFF/* Same, for 16 bit cards. */
59 inthp_probe(struct net_device *dev);
60 static inthp_probe1(struct net_device *dev,int ioaddr);
62 static inthp_open(struct net_device *dev);
63 static inthp_close(struct net_device *dev);
64 static voidhp_reset_8390(struct net_device *dev);
65 static voidhp_get_8390_hdr(struct net_device *dev,struct e8390_pkt_hdr *hdr,
66 int ring_page);
67 static voidhp_block_input(struct net_device *dev,int count,
68 struct sk_buff *skb ,int ring_offset);
69 static voidhp_block_output(struct net_device *dev,int count,
70 const unsigned char*buf,int start_page);
72 static voidhp_init_card(struct net_device *dev);
74 /* The map from IRQ number to HP_CONFIGURE register setting. */
75 /* My default is IRQ5 0 1 2 3 4 5 6 7 8 9 10 11 */
76 static char irqmap[16] __initdata= {0,0,4,6,8,10,0,14,0,4,2,12,0,0,0,0};
79 /* Probe for an HP LAN adaptor.
80 Also initialize the card and fill in STATION_ADDR with the station
81 address. */
83 int __init hp_probe(struct net_device *dev)
85 int i;
86 int base_addr = dev->base_addr;
88 SET_MODULE_OWNER(dev);
90 if(base_addr >0x1ff)/* Check a single specified location. */
91 returnhp_probe1(dev, base_addr);
92 else if(base_addr !=0)/* Don't probe at all. */
93 return-ENXIO;
95 for(i =0; hppclan_portlist[i]; i++)
96 if(hp_probe1(dev, hppclan_portlist[i]) ==0)
97 return0;
99 return-ENODEV;
102 static int __init hp_probe1(struct net_device *dev,int ioaddr)
104 int i, retval, board_id, wordmode;
105 const char*name;
106 static unsigned version_printed;
108 if(!request_region(ioaddr, HP_IO_EXTENT, dev->name))
109 return-EBUSY;
111 /* Check for the HP physical address, 08 00 09 xx xx xx. */
112 /* This really isn't good enough: we may pick up HP LANCE boards
113 also! Avoid the lance 0x5757 signature. */
114 if(inb(ioaddr) !=0x08
115 ||inb(ioaddr+1) !=0x00
116 ||inb(ioaddr+2) !=0x09
117 ||inb(ioaddr+14) ==0x57) {
118 retval = -ENODEV;
119 goto out;
122 /* Set up the parameters based on the board ID.
123 If you have additional mappings, please mail them to me -djb. */
124 if((board_id =inb(ioaddr + HP_ID)) &0x80) {
125 name ="HP27247";
126 wordmode =1;
127 }else{
128 name ="HP27250";
129 wordmode =0;
132 if(ei_debug && version_printed++ ==0)
133 printk(version);
135 /* Allocate dev->priv and fill in 8390 specific dev fields. */
136 if(ethdev_init(dev)) {
137 printk(" unable to get memory for dev->priv.\n");
138 retval = -ENOMEM;
139 goto out;
142 printk("%s: %s (ID %02x) at %#3x,", dev->name, name, board_id, ioaddr);
144 for(i =0; i < ETHER_ADDR_LEN; i++)
145 printk(" %2.2x", dev->dev_addr[i] =inb(ioaddr + i));
147 /* Snarf the interrupt now. Someday this could be moved to open(). */
148 if(dev->irq <2) {
149 int irq_16list[] = {11,10,5,3,4,7,9,0};
150 int irq_8list[] = {7,5,3,4,9,0};
151 int*irqp = wordmode ? irq_16list : irq_8list;
153 int irq = *irqp;
154 if(request_irq(irq, NULL,0,"bogus", NULL) != -EBUSY) {
155 unsigned long cookie =probe_irq_on();
156 /* Twinkle the interrupt, and check if it's seen. */
157 outb_p(irqmap[irq] | HP_RUN, ioaddr + HP_CONFIGURE);
158 outb_p(0x00| HP_RUN, ioaddr + HP_CONFIGURE);
159 if(irq ==probe_irq_off(cookie)/* It's a good IRQ line! */
160 &&request_irq(irq, ei_interrupt,0, dev->name, dev) ==0) {
161 printk(" selecting IRQ %d.\n", irq);
162 dev->irq = *irqp;
163 break;
166 }while(*++irqp);
167 if(*irqp ==0) {
168 printk(" no free IRQ lines.\n");
169 retval = -EBUSY;
170 goto out1;
172 }else{
173 if(dev->irq ==2)
174 dev->irq =9;
175 if((retval =request_irq(dev->irq, ei_interrupt,0, dev->name, dev))) {
176 printk(" unable to get IRQ %d.\n", dev->irq);
177 goto out1;
181 /* Set the base address to point to the NIC, not the "real" base! */
182 dev->base_addr = ioaddr + NIC_OFFSET;
183 dev->open = &hp_open;
184 dev->stop = &hp_close;
186 ei_status.name = name;
187 ei_status.word16 = wordmode;
188 ei_status.tx_start_page = HP_START_PG;
189 ei_status.rx_start_page = HP_START_PG + TX_PAGES;
190 ei_status.stop_page = wordmode ? HP_16BSTOP_PG : HP_8BSTOP_PG;
192 ei_status.reset_8390 = &hp_reset_8390;
193 ei_status.get_8390_hdr = &hp_get_8390_hdr;
194 ei_status.block_input = &hp_block_input;
195 ei_status.block_output = &hp_block_output;
196 hp_init_card(dev);
198 return0;
199 out1:
200 kfree(dev->priv);
201 dev->priv = NULL;
202 out:
203 release_region(ioaddr, HP_IO_EXTENT);
204 return retval;
207 static int
208 hp_open(struct net_device *dev)
210 ei_open(dev);
211 return0;
214 static int
215 hp_close(struct net_device *dev)
217 ei_close(dev);
218 return0;
221 static void
222 hp_reset_8390(struct net_device *dev)
224 int hp_base = dev->base_addr - NIC_OFFSET;
225 int saved_config =inb_p(hp_base + HP_CONFIGURE);
227 if(ei_debug >1)printk("resetting the 8390 time=%ld...", jiffies);
228 outb_p(0x00, hp_base + HP_CONFIGURE);
229 ei_status.txing =0;
230 /* Pause just a few cycles for the hardware reset to take place. */
231 udelay(5);
233 outb_p(saved_config, hp_base + HP_CONFIGURE);
234 udelay(5);
236 if((inb_p(hp_base+NIC_OFFSET+EN0_ISR) & ENISR_RESET) ==0)
237 printk("%s: hp_reset_8390() did not complete.\n", dev->name);
239 if(ei_debug >1)printk("8390 reset done (%ld).", jiffies);
240 return;
243 static void
244 hp_get_8390_hdr(struct net_device *dev,struct e8390_pkt_hdr *hdr,int ring_page)
246 int nic_base = dev->base_addr;
247 int saved_config =inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
249 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
250 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
251 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
252 outb_p(0, nic_base + EN0_RCNTHI);
253 outb_p(0, nic_base + EN0_RSARLO);/* On page boundary */
254 outb_p(ring_page, nic_base + EN0_RSARHI);
255 outb_p(E8390_RREAD+E8390_START, nic_base);
257 if(ei_status.word16)
258 insw(nic_base - NIC_OFFSET + HP_DATAPORT, hdr,sizeof(struct e8390_pkt_hdr)>>1);
259 else
260 insb(nic_base - NIC_OFFSET + HP_DATAPORT, hdr,sizeof(struct e8390_pkt_hdr));
262 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
265 /* Block input and output, similar to the Crynwr packet driver. If you are
266 porting to a new ethercard look at the packet driver source for hints.
267 The HP LAN doesn't use shared memory -- we put the packet
268 out through the "remote DMA" dataport. */
270 static void
271 hp_block_input(struct net_device *dev,int count,struct sk_buff *skb,int ring_offset)
273 int nic_base = dev->base_addr;
274 int saved_config =inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
275 int xfer_count = count;
276 char*buf = skb->data;
278 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
279 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
280 outb_p(count &0xff, nic_base + EN0_RCNTLO);
281 outb_p(count >>8, nic_base + EN0_RCNTHI);
282 outb_p(ring_offset &0xff, nic_base + EN0_RSARLO);
283 outb_p(ring_offset >>8, nic_base + EN0_RSARHI);
284 outb_p(E8390_RREAD+E8390_START, nic_base);
285 if(ei_status.word16) {
286 insw(nic_base - NIC_OFFSET + HP_DATAPORT,buf,count>>1);
287 if(count &0x01)
288 buf[count-1] =inb(nic_base - NIC_OFFSET + HP_DATAPORT), xfer_count++;
289 }else{
290 insb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
292 /* This is for the ALPHA version only, remove for later releases. */
293 if(ei_debug >0) {/* DMA termination address check... */
294 int high =inb_p(nic_base + EN0_RSARHI);
295 int low =inb_p(nic_base + EN0_RSARLO);
296 int addr = (high <<8) + low;
297 /* Check only the lower 8 bits so we can ignore ring wrap. */
298 if(((ring_offset + xfer_count) &0xff) != (addr &0xff))
299 printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
300 dev->name, ring_offset + xfer_count, addr);
302 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
305 static void
306 hp_block_output(struct net_device *dev,int count,
307 const unsigned char*buf,int start_page)
309 int nic_base = dev->base_addr;
310 int saved_config =inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
312 outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
313 /* Round the count up for word writes. Do we need to do this?
314 What effect will an odd byte count have on the 8390?
315 I should check someday. */
316 if(ei_status.word16 && (count &0x01))
317 count++;
318 /* We should already be in page 0, but to be safe... */
319 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base);
321 #ifdef NE8390_RW_BUGFIX
322 /* Handle the read-before-write bug the same way as the
323 Crynwr packet driver -- the NatSemi method doesn't work. */
324 outb_p(0x42, nic_base + EN0_RCNTLO);
325 outb_p(0, nic_base + EN0_RCNTHI);
326 outb_p(0xff, nic_base + EN0_RSARLO);
327 outb_p(0x00, nic_base + EN0_RSARHI);
328 #define NE_CMD 0x00
329 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
330 /* Make certain that the dummy read has occurred. */
331 inb_p(0x61);
332 inb_p(0x61);
333 #endif
335 outb_p(count &0xff, nic_base + EN0_RCNTLO);
336 outb_p(count >>8, nic_base + EN0_RCNTHI);
337 outb_p(0x00, nic_base + EN0_RSARLO);
338 outb_p(start_page, nic_base + EN0_RSARHI);
340 outb_p(E8390_RWRITE+E8390_START, nic_base);
341 if(ei_status.word16) {
342 /* Use the 'rep' sequence for 16 bit boards. */
343 outsw(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count>>1);
344 }else{
345 outsb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
348 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here -- it's broken! */
350 /* This is for the ALPHA version only, remove for later releases. */
351 if(ei_debug >0) {/* DMA termination address check... */
352 int high =inb_p(nic_base + EN0_RSARHI);
353 int low =inb_p(nic_base + EN0_RSARLO);
354 int addr = (high <<8) + low;
355 if((start_page <<8) + count != addr)
356 printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
357 dev->name, (start_page <<8) + count, addr);
359 outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
360 return;
363 /* This function resets the ethercard if something screws up. */
364 static void
365 hp_init_card(struct net_device *dev)
367 int irq = dev->irq;
368 NS8390_init(dev,0);
369 outb_p(irqmap[irq&0x0f] | HP_RUN,
370 dev->base_addr - NIC_OFFSET + HP_CONFIGURE);
371 return;
374 #ifdef MODULE
375 #define MAX_HP_CARDS 4/* Max number of HP cards per module */
376 static struct net_device dev_hp[MAX_HP_CARDS];
377 static int io[MAX_HP_CARDS];
378 static int irq[MAX_HP_CARDS];
380 MODULE_PARM(io,"1-"__MODULE_STRING(MAX_HP_CARDS)"i");
381 MODULE_PARM(irq,"1-"__MODULE_STRING(MAX_HP_CARDS)"i");
383 /* This is set up so that only a single autoprobe takes place per call.
384 ISA device autoprobes on a running machine are not recommended. */
386 init_module(void)
388 int this_dev, found =0;
390 for(this_dev =0; this_dev < MAX_HP_CARDS; this_dev++) {
391 struct net_device *dev = &dev_hp[this_dev];
392 dev->irq = irq[this_dev];
393 dev->base_addr = io[this_dev];
394 dev->init = hp_probe;
395 if(io[this_dev] ==0) {
396 if(this_dev !=0)break;/* only autoprobe 1st one */
397 printk(KERN_NOTICE "hp.c: Presently autoprobing (not recommended) for a single card.\n");
399 if(register_netdev(dev) !=0) {
400 printk(KERN_WARNING "hp.c: No HP card found (i/o = 0x%x).\n", io[this_dev]);
401 if(found !=0) {/* Got at least one. */
402 return0;
404 return-ENXIO;
406 found++;
408 return0;
411 void
412 cleanup_module(void)
414 int this_dev;
416 for(this_dev =0; this_dev < MAX_HP_CARDS; this_dev++) {
417 struct net_device *dev = &dev_hp[this_dev];
418 if(dev->priv != NULL) {
419 int ioaddr = dev->base_addr - NIC_OFFSET;
420 void*priv = dev->priv;
421 free_irq(dev->irq, dev);
422 release_region(ioaddr, HP_IO_EXTENT);
423 unregister_netdev(dev);
424 kfree(priv);
428 #endif/* MODULE */
431 * Local variables:
432 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp.c"
433 * version-control: t
434 * kept-new-versions: 5
435 * tab-width: 4
436 * c-indent-level: 4
437 * End:
close