net: convert print_mac to %pM
[deliverable/linux.git] / drivers / net / hp-plus.c
CommitLineData
1da177e4
LT
1/* hp-plus.c: A HP PCLAN/plus ethernet driver for linux. */
2/*
3 Written 1994 by Donald Becker.
4
5 This driver is for the Hewlett Packard PC LAN (27***) plus ethercards.
6 These cards are sold under several model numbers, usually 2724*.
7
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
10
11 The author may be reached as becker@scyld.com, or C/O
12 Scyld Computing Corporation
13 410 Severn Ave., Suite 210
14 Annapolis MD 21403
15
16 As is often the case, a great deal of credit is owed to Russ Nelson.
17 The Crynwr packet driver was my primary source of HP-specific
18 programming information.
19*/
20
21static const char version[] =
22"hp-plus.c:v1.10 9/24/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
23
24#include <linux/module.h>
25
26#include <linux/string.h> /* Important -- this inlines word moves. */
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>
34
35#include <asm/system.h>
36#include <asm/io.h>
37
38#include "8390.h"
39
40#define DRV_NAME "hp-plus"
41
42/* A zero-terminated list of I/O addresses to be probed. */
43static unsigned int hpplus_portlist[] __initdata =
44{0x200, 0x240, 0x280, 0x2C0, 0x300, 0x320, 0x340, 0};
45
46/*
47 The HP EtherTwist chip implementation is a fairly routine DP8390
48 implementation. It allows both shared memory and programmed-I/O buffer
49 access, using a custom interface for both. The programmed-I/O mode is
50 entirely implemented in the HP EtherTwist chip, bypassing the problem
51 ridden built-in 8390 facilities used on NE2000 designs. The shared
52 memory mode is likewise special, with an offset register used to make
53 packets appear at the shared memory base. Both modes use a base and bounds
54 page register to hide the Rx ring buffer wrap -- a packet that spans the
55 end of physical buffer memory appears continuous to the driver. (c.f. the
56 3c503 and Cabletron E2100)
57
58 A special note: the internal buffer of the board is only 8 bits wide.
59 This lays several nasty traps for the unaware:
60 - the 8390 must be programmed for byte-wide operations
61 - all I/O and memory operations must work on whole words (the access
62 latches are serially preloaded and have no byte-swapping ability).
63
64 This board is laid out in I/O space much like the earlier HP boards:
65 the first 16 locations are for the board registers, and the second 16 are
66 for the 8390. The board is easy to identify, with both a dedicated 16 bit
67 ID register and a constant 0x530* value in the upper bits of the paging
68 register.
69*/
70
71#define HP_ID 0x00 /* ID register, always 0x4850. */
72#define HP_PAGING 0x02 /* Registers visible @ 8-f, see PageName. */
73#define HPP_OPTION 0x04 /* Bitmapped options, see HP_Option. */
74#define HPP_OUT_ADDR 0x08 /* I/O output location in Perf_Page. */
75#define HPP_IN_ADDR 0x0A /* I/O input location in Perf_Page. */
76#define HP_DATAPORT 0x0c /* I/O data transfer in Perf_Page. */
77#define NIC_OFFSET 0x10 /* Offset to the 8390 registers. */
78#define HP_IO_EXTENT 32
79
80#define HP_START_PG 0x00 /* First page of TX buffer */
81#define HP_STOP_PG 0x80 /* Last page +1 of RX ring */
82
83/* The register set selected in HP_PAGING. */
84enum PageName {
85 Perf_Page = 0, /* Normal operation. */
86 MAC_Page = 1, /* The ethernet address (+checksum). */
87 HW_Page = 2, /* EEPROM-loaded hardware parameters. */
88 LAN_Page = 4, /* Transceiver selection, testing, etc. */
89 ID_Page = 6 };
90
91/* The bit definitions for the HPP_OPTION register. */
92enum HP_Option {
93 NICReset = 1, ChipReset = 2, /* Active low, really UNreset. */
94 EnableIRQ = 4, FakeIntr = 8, BootROMEnb = 0x10, IOEnb = 0x20,
95 MemEnable = 0x40, ZeroWait = 0x80, MemDisable = 0x1000, };
96
97static int hpp_probe1(struct net_device *dev, int ioaddr);
98
99static void hpp_reset_8390(struct net_device *dev);
100static int hpp_open(struct net_device *dev);
101static int hpp_close(struct net_device *dev);
102static void hpp_mem_block_input(struct net_device *dev, int count,
103 struct sk_buff *skb, int ring_offset);
104static void hpp_mem_block_output(struct net_device *dev, int count,
105 const unsigned char *buf, int start_page);
106static void hpp_mem_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
107 int ring_page);
108static void hpp_io_block_input(struct net_device *dev, int count,
109 struct sk_buff *skb, int ring_offset);
110static void hpp_io_block_output(struct net_device *dev, int count,
111 const unsigned char *buf, int start_page);
112static void hpp_io_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
113 int ring_page);
114
6aa20a22 115
1da177e4
LT
116/* Probe a list of addresses for an HP LAN+ adaptor.
117 This routine is almost boilerplate. */
118
119static int __init do_hpp_probe(struct net_device *dev)
120{
121 int i;
122 int base_addr = dev->base_addr;
123 int irq = dev->irq;
124
1da177e4
LT
125 if (base_addr > 0x1ff) /* Check a single specified location. */
126 return hpp_probe1(dev, base_addr);
127 else if (base_addr != 0) /* Don't probe at all. */
128 return -ENXIO;
129
130 for (i = 0; hpplus_portlist[i]; i++) {
131 if (hpp_probe1(dev, hpplus_portlist[i]) == 0)
132 return 0;
133 dev->irq = irq;
134 }
135
136 return -ENODEV;
137}
138
1da177e4
LT
139#ifndef MODULE
140struct net_device * __init hp_plus_probe(int unit)
141{
49f276be 142 struct net_device *dev = alloc_eip_netdev();
1da177e4
LT
143 int err;
144
145 if (!dev)
146 return ERR_PTR(-ENOMEM);
147
148 sprintf(dev->name, "eth%d", unit);
149 netdev_boot_setup_check(dev);
150
151 err = do_hpp_probe(dev);
152 if (err)
153 goto out;
1da177e4 154 return dev;
1da177e4
LT
155out:
156 free_netdev(dev);
157 return ERR_PTR(err);
158}
159#endif
160
161/* Do the interesting part of the probe at a single address. */
162static int __init hpp_probe1(struct net_device *dev, int ioaddr)
163{
164 int i, retval;
165 unsigned char checksum = 0;
166 const char name[] = "HP-PC-LAN+";
167 int mem_start;
168 static unsigned version_printed;
169
170 if (!request_region(ioaddr, HP_IO_EXTENT, DRV_NAME))
171 return -EBUSY;
172
173 /* Check for the HP+ signature, 50 48 0x 53. */
174 if (inw(ioaddr + HP_ID) != 0x4850
175 || (inw(ioaddr + HP_PAGING) & 0xfff0) != 0x5300) {
176 retval = -ENODEV;
177 goto out;
178 }
179
180 if (ei_debug && version_printed++ == 0)
181 printk(version);
182
0795af57 183 printk("%s: %s at %#3x, ", dev->name, name, ioaddr);
1da177e4
LT
184
185 /* Retrieve and checksum the station address. */
186 outw(MAC_Page, ioaddr + HP_PAGING);
187
188 for(i = 0; i < ETHER_ADDR_LEN; i++) {
189 unsigned char inval = inb(ioaddr + 8 + i);
190 dev->dev_addr[i] = inval;
191 checksum += inval;
1da177e4
LT
192 }
193 checksum += inb(ioaddr + 14);
194
e174961c 195 printk("%pM", dev->dev_addr);
0795af57 196
1da177e4
LT
197 if (checksum != 0xff) {
198 printk(" bad checksum %2.2x.\n", checksum);
199 retval = -ENODEV;
200 goto out;
201 } else {
202 /* Point at the Software Configuration Flags. */
203 outw(ID_Page, ioaddr + HP_PAGING);
204 printk(" ID %4.4x", inw(ioaddr + 12));
205 }
206
207 /* Read the IRQ line. */
208 outw(HW_Page, ioaddr + HP_PAGING);
209 {
210 int irq = inb(ioaddr + 13) & 0x0f;
211 int option = inw(ioaddr + HPP_OPTION);
212
213 dev->irq = irq;
214 if (option & MemEnable) {
215 mem_start = inw(ioaddr + 9) << 8;
216 printk(", IRQ %d, memory address %#x.\n", irq, mem_start);
217 } else {
218 mem_start = 0;
219 printk(", IRQ %d, programmed-I/O mode.\n", irq);
220 }
221 }
222
223 /* Set the wrap registers for string I/O reads. */
224 outw((HP_START_PG + TX_PAGES/2) | ((HP_STOP_PG - 1) << 8), ioaddr + 14);
225
226 /* Set the base address to point to the NIC, not the "real" base! */
227 dev->base_addr = ioaddr + NIC_OFFSET;
228
229 dev->open = &hpp_open;
230 dev->stop = &hpp_close;
231#ifdef CONFIG_NET_POLL_CONTROLLER
232 dev->poll_controller = ei_poll;
233#endif
234
235 ei_status.name = name;
236 ei_status.word16 = 0; /* Agggghhhhh! Debug time: 2 days! */
237 ei_status.tx_start_page = HP_START_PG;
238 ei_status.rx_start_page = HP_START_PG + TX_PAGES/2;
239 ei_status.stop_page = HP_STOP_PG;
240
241 ei_status.reset_8390 = &hpp_reset_8390;
242 ei_status.block_input = &hpp_io_block_input;
243 ei_status.block_output = &hpp_io_block_output;
244 ei_status.get_8390_hdr = &hpp_io_get_8390_hdr;
245
246 /* Check if the memory_enable flag is set in the option register. */
247 if (mem_start) {
248 ei_status.block_input = &hpp_mem_block_input;
249 ei_status.block_output = &hpp_mem_block_output;
250 ei_status.get_8390_hdr = &hpp_mem_get_8390_hdr;
251 dev->mem_start = mem_start;
b336cea3
AV
252 ei_status.mem = ioremap(mem_start,
253 (HP_STOP_PG - HP_START_PG)*256);
254 if (!ei_status.mem) {
255 retval = -ENOMEM;
256 goto out;
257 }
1da177e4
LT
258 ei_status.rmem_start = dev->mem_start + TX_PAGES/2*256;
259 dev->mem_end = ei_status.rmem_end
260 = dev->mem_start + (HP_STOP_PG - HP_START_PG)*256;
261 }
262
263 outw(Perf_Page, ioaddr + HP_PAGING);
f0084a36 264 NS8390p_init(dev, 0);
1da177e4
LT
265 /* Leave the 8390 and HP chip reset. */
266 outw(inw(ioaddr + HPP_OPTION) & ~EnableIRQ, ioaddr + HPP_OPTION);
267
b1fc5505 268 retval = register_netdev(dev);
269 if (retval)
b336cea3 270 goto out1;
1da177e4 271 return 0;
b336cea3
AV
272out1:
273 iounmap(ei_status.mem);
1da177e4
LT
274out:
275 release_region(ioaddr, HP_IO_EXTENT);
276 return retval;
277}
278
279static int
280hpp_open(struct net_device *dev)
281{
282 int ioaddr = dev->base_addr - NIC_OFFSET;
283 int option_reg;
284 int retval;
285
49f276be 286 if ((retval = request_irq(dev->irq, eip_interrupt, 0, dev->name, dev))) {
1da177e4
LT
287 return retval;
288 }
289
290 /* Reset the 8390 and HP chip. */
291 option_reg = inw(ioaddr + HPP_OPTION);
292 outw(option_reg & ~(NICReset + ChipReset), ioaddr + HPP_OPTION);
293 udelay(5);
294 /* Unreset the board and enable interrupts. */
295 outw(option_reg | (EnableIRQ + NICReset + ChipReset), ioaddr + HPP_OPTION);
296
297 /* Set the wrap registers for programmed-I/O operation. */
298 outw(HW_Page, ioaddr + HP_PAGING);
299 outw((HP_START_PG + TX_PAGES/2) | ((HP_STOP_PG - 1) << 8), ioaddr + 14);
300
301 /* Select the operational page. */
302 outw(Perf_Page, ioaddr + HP_PAGING);
303
49f276be 304 eip_open(dev);
1da177e4
LT
305 return 0;
306}
307
308static int
309hpp_close(struct net_device *dev)
310{
311 int ioaddr = dev->base_addr - NIC_OFFSET;
312 int option_reg = inw(ioaddr + HPP_OPTION);
313
314 free_irq(dev->irq, dev);
49f276be 315 eip_close(dev);
1da177e4
LT
316 outw((option_reg & ~EnableIRQ) | MemDisable | NICReset | ChipReset,
317 ioaddr + HPP_OPTION);
318
319 return 0;
320}
321
322static void
323hpp_reset_8390(struct net_device *dev)
324{
325 int ioaddr = dev->base_addr - NIC_OFFSET;
326 int option_reg = inw(ioaddr + HPP_OPTION);
327
328 if (ei_debug > 1) printk("resetting the 8390 time=%ld...", jiffies);
329
330 outw(option_reg & ~(NICReset + ChipReset), ioaddr + HPP_OPTION);
331 /* Pause a few cycles for the hardware reset to take place. */
332 udelay(5);
333 ei_status.txing = 0;
334 outw(option_reg | (EnableIRQ + NICReset + ChipReset), ioaddr + HPP_OPTION);
335
336 udelay(5);
337
338
339 if ((inb_p(ioaddr+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
340 printk("%s: hp_reset_8390() did not complete.\n", dev->name);
341
342 if (ei_debug > 1) printk("8390 reset done (%ld).", jiffies);
343 return;
344}
345
346/* The programmed-I/O version of reading the 4 byte 8390 specific header.
347 Note that transfer with the EtherTwist+ must be on word boundaries. */
348
349static void
350hpp_io_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
351{
352 int ioaddr = dev->base_addr - NIC_OFFSET;
353
354 outw((ring_page<<8), ioaddr + HPP_IN_ADDR);
355 insw(ioaddr + HP_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
356}
357
358/* Block input and output, similar to the Crynwr packet driver. */
359
360static void
361hpp_io_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
362{
363 int ioaddr = dev->base_addr - NIC_OFFSET;
364 char *buf = skb->data;
365
366 outw(ring_offset, ioaddr + HPP_IN_ADDR);
367 insw(ioaddr + HP_DATAPORT, buf, count>>1);
368 if (count & 0x01)
369 buf[count-1] = inw(ioaddr + HP_DATAPORT);
370}
371
372/* The corresponding shared memory versions of the above 2 functions. */
373
374static void
375hpp_mem_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
376{
377 int ioaddr = dev->base_addr - NIC_OFFSET;
378 int option_reg = inw(ioaddr + HPP_OPTION);
379
380 outw((ring_page<<8), ioaddr + HPP_IN_ADDR);
381 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
b336cea3 382 memcpy_fromio(hdr, ei_status.mem, sizeof(struct e8390_pkt_hdr));
1da177e4
LT
383 outw(option_reg, ioaddr + HPP_OPTION);
384 hdr->count = (le16_to_cpu(hdr->count) + 3) & ~3; /* Round up allocation. */
385}
386
387static void
388hpp_mem_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
389{
390 int ioaddr = dev->base_addr - NIC_OFFSET;
391 int option_reg = inw(ioaddr + HPP_OPTION);
392
393 outw(ring_offset, ioaddr + HPP_IN_ADDR);
394
395 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
396
397 /* Caution: this relies on get_8390_hdr() rounding up count!
398 Also note that we *can't* use eth_io_copy_and_sum() because
399 it will not always copy "count" bytes (e.g. padded IP). */
400
b336cea3 401 memcpy_fromio(skb->data, ei_status.mem, count);
1da177e4
LT
402 outw(option_reg, ioaddr + HPP_OPTION);
403}
404
405/* A special note: we *must* always transfer >=16 bit words.
406 It's always safe to round up, so we do. */
407static void
408hpp_io_block_output(struct net_device *dev, int count,
409 const unsigned char *buf, int start_page)
410{
411 int ioaddr = dev->base_addr - NIC_OFFSET;
412 outw(start_page << 8, ioaddr + HPP_OUT_ADDR);
413 outsl(ioaddr + HP_DATAPORT, buf, (count+3)>>2);
414 return;
415}
416
417static void
418hpp_mem_block_output(struct net_device *dev, int count,
419 const unsigned char *buf, int start_page)
420{
421 int ioaddr = dev->base_addr - NIC_OFFSET;
422 int option_reg = inw(ioaddr + HPP_OPTION);
423
424 outw(start_page << 8, ioaddr + HPP_OUT_ADDR);
425 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
b336cea3 426 memcpy_toio(ei_status.mem, buf, (count + 3) & ~3);
1da177e4
LT
427 outw(option_reg, ioaddr + HPP_OPTION);
428
429 return;
430}
431
6aa20a22 432
1da177e4
LT
433#ifdef MODULE
434#define MAX_HPP_CARDS 4 /* Max number of HPP cards per module */
435static struct net_device *dev_hpp[MAX_HPP_CARDS];
436static int io[MAX_HPP_CARDS];
437static int irq[MAX_HPP_CARDS];
438
439module_param_array(io, int, NULL, 0);
440module_param_array(irq, int, NULL, 0);
441MODULE_PARM_DESC(io, "I/O port address(es)");
442MODULE_PARM_DESC(irq, "IRQ number(s); ignored if properly detected");
443MODULE_DESCRIPTION("HP PC-LAN+ ISA ethernet driver");
444MODULE_LICENSE("GPL");
445
446/* This is set up so that only a single autoprobe takes place per call.
447ISA device autoprobes on a running machine are not recommended. */
29f9f6d2 448int __init
1da177e4
LT
449init_module(void)
450{
451 struct net_device *dev;
452 int this_dev, found = 0;
453
454 for (this_dev = 0; this_dev < MAX_HPP_CARDS; this_dev++) {
455 if (io[this_dev] == 0) {
456 if (this_dev != 0) break; /* only autoprobe 1st one */
457 printk(KERN_NOTICE "hp-plus.c: Presently autoprobing (not recommended) for a single card.\n");
458 }
459 dev = alloc_ei_netdev();
460 if (!dev)
461 break;
462 dev->irq = irq[this_dev];
463 dev->base_addr = io[this_dev];
464 if (do_hpp_probe(dev) == 0) {
b1fc5505 465 dev_hpp[found++] = dev;
466 continue;
1da177e4
LT
467 }
468 free_netdev(dev);
469 printk(KERN_WARNING "hp-plus.c: No HP-Plus card found (i/o = 0x%x).\n", io[this_dev]);
470 break;
471 }
472 if (found)
473 return 0;
474 return -ENXIO;
475}
476
64916f1e
DV
477static void cleanup_card(struct net_device *dev)
478{
479 /* NB: hpp_close() handles free_irq */
b336cea3 480 iounmap(ei_status.mem);
64916f1e
DV
481 release_region(dev->base_addr - NIC_OFFSET, HP_IO_EXTENT);
482}
483
afc8eb46 484void __exit
1da177e4
LT
485cleanup_module(void)
486{
487 int this_dev;
488
489 for (this_dev = 0; this_dev < MAX_HPP_CARDS; this_dev++) {
490 struct net_device *dev = dev_hpp[this_dev];
491 if (dev) {
492 unregister_netdev(dev);
493 cleanup_card(dev);
494 free_netdev(dev);
495 }
496 }
497}
498#endif /* MODULE */
This page took 0.456221 seconds and 5 git commands to generate.