1 /* hp.c: A HP LAN ethernet driver for linux. */
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 General Public License, incorporated herein by reference.
11 The author may be reached as becker@scyld.com, or C/O
12 Scyld Computing Corporation
13 410 Severn Ave., Suite 210
16 This is a driver for the HP PC-LAN adaptors.
19 The Crynwr packet driver.
22 static const char version
[] =
23 "hp.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/errno.h>
29 #include <linux/ioport.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/init.h>
33 #include <linux/delay.h>
35 #include <asm/system.h>
40 /* A zero-terminated list of I/O addresses to be probed. */
41 static unsigned int hppclan_portlist
[] __initdata
=
42 { 0x300, 0x320, 0x340, 0x280, 0x2C0, 0x200, 0x240, 0};
44 #define HP_IO_EXTENT 32
46 #define HP_DATAPORT 0x0c /* "Remote DMA" data port. */
48 #define HP_CONFIGURE 0x08 /* Configuration register. */
49 #define HP_RUN 0x01 /* 1 == Run, 0 == reset. */
50 #define HP_IRQ 0x0E /* Mask for software-configured IRQ line. */
51 #define HP_DATAON 0x10 /* Turn on dataport */
52 #define NIC_OFFSET 0x10 /* Offset the 8390 registers. */
54 #define HP_START_PG 0x00 /* First page of TX buffer */
55 #define HP_8BSTOP_PG 0x80 /* Last page +1 of RX ring */
56 #define HP_16BSTOP_PG 0xFF /* Same, for 16 bit cards. */
58 int hp_probe(struct net_device
*dev
);
59 static int hp_probe1(struct net_device
*dev
, int ioaddr
);
61 static int hp_open(struct net_device
*dev
);
62 static int hp_close(struct net_device
*dev
);
63 static void hp_reset_8390(struct net_device
*dev
);
64 static void hp_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
66 static void hp_block_input(struct net_device
*dev
, int count
,
67 struct sk_buff
*skb
, int ring_offset
);
68 static void hp_block_output(struct net_device
*dev
, int count
,
69 const unsigned char *buf
, int start_page
);
71 static void hp_init_card(struct net_device
*dev
);
73 /* The map from IRQ number to HP_CONFIGURE register setting. */
74 /* My default is IRQ5 0 1 2 3 4 5 6 7 8 9 10 11 */
75 static char irqmap
[16] __initdata
= { 0, 0, 4, 6, 8,10, 0,14, 0, 4, 2,12,0,0,0,0};
78 /* Probe for an HP LAN adaptor.
79 Also initialize the card and fill in STATION_ADDR with the station
82 int __init
hp_probe(struct net_device
*dev
)
85 int base_addr
= dev
->base_addr
;
87 SET_MODULE_OWNER(dev
);
89 if (base_addr
> 0x1ff) /* Check a single specified location. */
90 return hp_probe1(dev
, base_addr
);
91 else if (base_addr
!= 0) /* Don't probe at all. */
94 for (i
= 0; hppclan_portlist
[i
]; i
++)
95 if (hp_probe1(dev
, hppclan_portlist
[i
]) == 0)
101 static int __init
hp_probe1(struct net_device
*dev
, int ioaddr
)
103 int i
, retval
, board_id
, wordmode
;
105 static unsigned version_printed
;
107 if (!request_region(ioaddr
, HP_IO_EXTENT
, dev
->name
))
110 /* Check for the HP physical address, 08 00 09 xx xx xx. */
111 /* This really isn't good enough: we may pick up HP LANCE boards
112 also! Avoid the lance 0x5757 signature. */
113 if (inb(ioaddr
) != 0x08
114 || inb(ioaddr
+1) != 0x00
115 || inb(ioaddr
+2) != 0x09
116 || inb(ioaddr
+14) == 0x57) {
121 /* Set up the parameters based on the board ID.
122 If you have additional mappings, please mail them to me -djb. */
123 if ((board_id
= inb(ioaddr
+ HP_ID
)) & 0x80) {
131 if (ei_debug
&& version_printed
++ == 0)
134 /* Allocate dev->priv and fill in 8390 specific dev fields. */
135 if (ethdev_init(dev
)) {
136 printk (" unable to get memory for dev->priv.\n");
141 printk("%s: %s (ID %02x) at %#3x,", dev
->name
, name
, board_id
, ioaddr
);
143 for(i
= 0; i
< ETHER_ADDR_LEN
; i
++)
144 printk(" %2.2x", dev
->dev_addr
[i
] = inb(ioaddr
+ i
));
146 /* Snarf the interrupt now. Someday this could be moved to open(). */
148 int irq_16list
[] = { 11, 10, 5, 3, 4, 7, 9, 0};
149 int irq_8list
[] = { 7, 5, 3, 4, 9, 0};
150 int *irqp
= wordmode
? irq_16list
: irq_8list
;
153 if (request_irq (irq
, NULL
, 0, "bogus", NULL
) != -EBUSY
) {
154 unsigned long cookie
= probe_irq_on();
155 /* Twinkle the interrupt, and check if it's seen. */
156 outb_p(irqmap
[irq
] | HP_RUN
, ioaddr
+ HP_CONFIGURE
);
157 outb_p( 0x00 | HP_RUN
, ioaddr
+ HP_CONFIGURE
);
158 if (irq
== probe_irq_off(cookie
) /* It's a good IRQ line! */
159 && request_irq (irq
, ei_interrupt
, 0, dev
->name
, dev
) == 0) {
160 printk(" selecting IRQ %d.\n", irq
);
167 printk(" no free IRQ lines.\n");
174 if ((retval
= request_irq(dev
->irq
, ei_interrupt
, 0, dev
->name
, dev
))) {
175 printk (" unable to get IRQ %d.\n", dev
->irq
);
180 /* Set the base address to point to the NIC, not the "real" base! */
181 dev
->base_addr
= ioaddr
+ NIC_OFFSET
;
182 dev
->open
= &hp_open
;
183 dev
->stop
= &hp_close
;
185 ei_status
.name
= name
;
186 ei_status
.word16
= wordmode
;
187 ei_status
.tx_start_page
= HP_START_PG
;
188 ei_status
.rx_start_page
= HP_START_PG
+ TX_PAGES
;
189 ei_status
.stop_page
= wordmode
? HP_16BSTOP_PG
: HP_8BSTOP_PG
;
191 ei_status
.reset_8390
= &hp_reset_8390
;
192 ei_status
.get_8390_hdr
= &hp_get_8390_hdr
;
193 ei_status
.block_input
= &hp_block_input
;
194 ei_status
.block_output
= &hp_block_output
;
202 release_region(ioaddr
, HP_IO_EXTENT
);
207 hp_open(struct net_device
*dev
)
214 hp_close(struct net_device
*dev
)
221 hp_reset_8390(struct net_device
*dev
)
223 int hp_base
= dev
->base_addr
- NIC_OFFSET
;
224 int saved_config
= inb_p(hp_base
+ HP_CONFIGURE
);
226 if (ei_debug
> 1) printk("resetting the 8390 time=%ld...", jiffies
);
227 outb_p(0x00, hp_base
+ HP_CONFIGURE
);
229 /* Pause just a few cycles for the hardware reset to take place. */
232 outb_p(saved_config
, hp_base
+ HP_CONFIGURE
);
235 if ((inb_p(hp_base
+NIC_OFFSET
+EN0_ISR
) & ENISR_RESET
) == 0)
236 printk("%s: hp_reset_8390() did not complete.\n", dev
->name
);
238 if (ei_debug
> 1) printk("8390 reset done (%ld).", jiffies
);
243 hp_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
, int ring_page
)
245 int nic_base
= dev
->base_addr
;
246 int saved_config
= inb_p(nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
248 outb_p(saved_config
| HP_DATAON
, nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
249 outb_p(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
);
250 outb_p(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
251 outb_p(0, nic_base
+ EN0_RCNTHI
);
252 outb_p(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
253 outb_p(ring_page
, nic_base
+ EN0_RSARHI
);
254 outb_p(E8390_RREAD
+E8390_START
, nic_base
);
256 if (ei_status
.word16
)
257 insw(nic_base
- NIC_OFFSET
+ HP_DATAPORT
, hdr
, sizeof(struct e8390_pkt_hdr
)>>1);
259 insb(nic_base
- NIC_OFFSET
+ HP_DATAPORT
, hdr
, sizeof(struct e8390_pkt_hdr
));
261 outb_p(saved_config
& (~HP_DATAON
), nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
264 /* Block input and output, similar to the Crynwr packet driver. If you are
265 porting to a new ethercard look at the packet driver source for hints.
266 The HP LAN doesn't use shared memory -- we put the packet
267 out through the "remote DMA" dataport. */
270 hp_block_input(struct net_device
*dev
, int count
, struct sk_buff
*skb
, int ring_offset
)
272 int nic_base
= dev
->base_addr
;
273 int saved_config
= inb_p(nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
274 int xfer_count
= count
;
275 char *buf
= skb
->data
;
277 outb_p(saved_config
| HP_DATAON
, nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
278 outb_p(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
);
279 outb_p(count
& 0xff, nic_base
+ EN0_RCNTLO
);
280 outb_p(count
>> 8, nic_base
+ EN0_RCNTHI
);
281 outb_p(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
282 outb_p(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
283 outb_p(E8390_RREAD
+E8390_START
, nic_base
);
284 if (ei_status
.word16
) {
285 insw(nic_base
- NIC_OFFSET
+ HP_DATAPORT
,buf
,count
>>1);
287 buf
[count
-1] = inb(nic_base
- NIC_OFFSET
+ HP_DATAPORT
), xfer_count
++;
289 insb(nic_base
- NIC_OFFSET
+ HP_DATAPORT
, buf
, count
);
291 /* This is for the ALPHA version only, remove for later releases. */
292 if (ei_debug
> 0) { /* DMA termination address check... */
293 int high
= inb_p(nic_base
+ EN0_RSARHI
);
294 int low
= inb_p(nic_base
+ EN0_RSARLO
);
295 int addr
= (high
<< 8) + low
;
296 /* Check only the lower 8 bits so we can ignore ring wrap. */
297 if (((ring_offset
+ xfer_count
) & 0xff) != (addr
& 0xff))
298 printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
299 dev
->name
, ring_offset
+ xfer_count
, addr
);
301 outb_p(saved_config
& (~HP_DATAON
), nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
305 hp_block_output(struct net_device
*dev
, int count
,
306 const unsigned char *buf
, int start_page
)
308 int nic_base
= dev
->base_addr
;
309 int saved_config
= inb_p(nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
311 outb_p(saved_config
| HP_DATAON
, nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
312 /* Round the count up for word writes. Do we need to do this?
313 What effect will an odd byte count have on the 8390?
314 I should check someday. */
315 if (ei_status
.word16
&& (count
& 0x01))
317 /* We should already be in page 0, but to be safe... */
318 outb_p(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
);
320 #ifdef NE8390_RW_BUGFIX
321 /* Handle the read-before-write bug the same way as the
322 Crynwr packet driver -- the NatSemi method doesn't work. */
323 outb_p(0x42, nic_base
+ EN0_RCNTLO
);
324 outb_p(0, nic_base
+ EN0_RCNTHI
);
325 outb_p(0xff, nic_base
+ EN0_RSARLO
);
326 outb_p(0x00, nic_base
+ EN0_RSARHI
);
328 outb_p(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
329 /* Make certain that the dummy read has occurred. */
334 outb_p(count
& 0xff, nic_base
+ EN0_RCNTLO
);
335 outb_p(count
>> 8, nic_base
+ EN0_RCNTHI
);
336 outb_p(0x00, nic_base
+ EN0_RSARLO
);
337 outb_p(start_page
, nic_base
+ EN0_RSARHI
);
339 outb_p(E8390_RWRITE
+E8390_START
, nic_base
);
340 if (ei_status
.word16
) {
341 /* Use the 'rep' sequence for 16 bit boards. */
342 outsw(nic_base
- NIC_OFFSET
+ HP_DATAPORT
, buf
, count
>>1);
344 outsb(nic_base
- NIC_OFFSET
+ HP_DATAPORT
, buf
, count
);
347 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here -- it's broken! */
349 /* This is for the ALPHA version only, remove for later releases. */
350 if (ei_debug
> 0) { /* DMA termination address check... */
351 int high
= inb_p(nic_base
+ EN0_RSARHI
);
352 int low
= inb_p(nic_base
+ EN0_RSARLO
);
353 int addr
= (high
<< 8) + low
;
354 if ((start_page
<< 8) + count
!= addr
)
355 printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
356 dev
->name
, (start_page
<< 8) + count
, addr
);
358 outb_p(saved_config
& (~HP_DATAON
), nic_base
- NIC_OFFSET
+ HP_CONFIGURE
);
362 /* This function resets the ethercard if something screws up. */
364 hp_init_card(struct net_device
*dev
)
368 outb_p(irqmap
[irq
&0x0f] | HP_RUN
,
369 dev
->base_addr
- NIC_OFFSET
+ HP_CONFIGURE
);
374 #define MAX_HP_CARDS 4 /* Max number of HP cards per module */
375 static struct net_device dev_hp
[MAX_HP_CARDS
];
376 static int io
[MAX_HP_CARDS
];
377 static int irq
[MAX_HP_CARDS
];
379 MODULE_PARM(io
, "1-" __MODULE_STRING(MAX_HP_CARDS
) "i");
380 MODULE_PARM(irq
, "1-" __MODULE_STRING(MAX_HP_CARDS
) "i");
381 MODULE_PARM_DESC(io
, "I/O base address(es)");
382 MODULE_PARM_DESC(irq
, "IRQ number(s) (assigned)");
383 MODULE_DESCRIPTION("HP PC-LAN ISA ethernet driver");
384 MODULE_LICENSE("GPL");
386 /* This is set up so that only a single autoprobe takes place per call.
387 ISA device autoprobes on a running machine are not recommended. */
391 int this_dev
, found
= 0;
393 for (this_dev
= 0; this_dev
< MAX_HP_CARDS
; this_dev
++) {
394 struct net_device
*dev
= &dev_hp
[this_dev
];
395 dev
->irq
= irq
[this_dev
];
396 dev
->base_addr
= io
[this_dev
];
397 dev
->init
= hp_probe
;
398 if (io
[this_dev
] == 0) {
399 if (this_dev
!= 0) break; /* only autoprobe 1st one */
400 printk(KERN_NOTICE
"hp.c: Presently autoprobing (not recommended) for a single card.\n");
402 if (register_netdev(dev
) != 0) {
403 printk(KERN_WARNING
"hp.c: No HP card found (i/o = 0x%x).\n", io
[this_dev
]);
404 if (found
!= 0) { /* Got at least one. */
419 for (this_dev
= 0; this_dev
< MAX_HP_CARDS
; this_dev
++) {
420 struct net_device
*dev
= &dev_hp
[this_dev
];
421 if (dev
->priv
!= NULL
) {
422 int ioaddr
= dev
->base_addr
- NIC_OFFSET
;
423 void *priv
= dev
->priv
;
424 free_irq(dev
->irq
, dev
);
425 release_region(ioaddr
, HP_IO_EXTENT
);
426 unregister_netdev(dev
);
436 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp.c"
438 * kept-new-versions: 5