udf: support files larger than 1G
[linux-2.6/mini2440.git] / drivers / net / hplance.c
blobc991cb82ff22bc8cf53c84dbf608c75af0ca83b5
1 /* hplance.c : the Linux/hp300/lance ethernet driver
3 * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
4 * Based on the Sun Lance driver and the NetBSD HP Lance driver
5 * Uses the generic 7990.c LANCE code.
6 */
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
12 #include <linux/ioport.h>
13 #include <linux/slab.h>
14 #include <linux/string.h>
15 #include <linux/delay.h>
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 /* Used for the temporal inet entries and routing */
19 #include <linux/socket.h>
20 #include <linux/route.h>
21 #include <linux/dio.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
26 #include <asm/system.h>
27 #include <asm/io.h>
28 #include <asm/pgtable.h>
30 #include "hplance.h"
32 /* We have 16834 bytes of RAM for the init block and buffers. This places
33 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
34 * buffers and 2 Tx buffers.
36 #define LANCE_LOG_TX_BUFFERS 1
37 #define LANCE_LOG_RX_BUFFERS 3
39 #include "7990.h" /* use generic LANCE code */
41 /* Our private data structure */
42 struct hplance_private {
43 struct lance_private lance;
46 /* function prototypes... This is easy because all the grot is in the
47 * generic LANCE support. All we have to support is probing for boards,
48 * plus board-specific init, open and close actions.
49 * Oh, and we need to tell the generic code how to read and write LANCE registers...
51 static int __devinit hplance_init_one(struct dio_dev *d,
52 const struct dio_device_id *ent);
53 static void __devinit hplance_init(struct net_device *dev,
54 struct dio_dev *d);
55 static void __devexit hplance_remove_one(struct dio_dev *d);
56 static void hplance_writerap(void *priv, unsigned short value);
57 static void hplance_writerdp(void *priv, unsigned short value);
58 static unsigned short hplance_readrdp(void *priv);
59 static int hplance_open(struct net_device *dev);
60 static int hplance_close(struct net_device *dev);
62 static struct dio_device_id hplance_dio_tbl[] = {
63 { DIO_ID_LAN },
64 { 0 }
67 static struct dio_driver hplance_driver = {
68 .name = "hplance",
69 .id_table = hplance_dio_tbl,
70 .probe = hplance_init_one,
71 .remove = __devexit_p(hplance_remove_one),
74 /* Find all the HP Lance boards and initialise them... */
75 static int __devinit hplance_init_one(struct dio_dev *d,
76 const struct dio_device_id *ent)
78 struct net_device *dev;
79 int err = -ENOMEM;
80 int i;
82 dev = alloc_etherdev(sizeof(struct hplance_private));
83 if (!dev)
84 goto out;
86 err = -EBUSY;
87 if (!request_mem_region(dio_resource_start(d),
88 dio_resource_len(d), d->name))
89 goto out_free_netdev;
91 hplance_init(dev, d);
92 err = register_netdev(dev);
93 if (err)
94 goto out_release_mem_region;
96 dio_set_drvdata(d, dev);
98 printk(KERN_INFO "%s: %s; select code %d, addr %2.2x", dev->name, d->name, d->scode, dev->dev_addr[0]);
100 for (i=1; i<6; i++) {
101 printk(":%2.2x", dev->dev_addr[i]);
104 printk(", irq %d\n", d->ipl);
106 return 0;
108 out_release_mem_region:
109 release_mem_region(dio_resource_start(d), dio_resource_len(d));
110 out_free_netdev:
111 free_netdev(dev);
112 out:
113 return err;
116 static void __devexit hplance_remove_one(struct dio_dev *d)
118 struct net_device *dev = dio_get_drvdata(d);
120 unregister_netdev(dev);
121 release_mem_region(dio_resource_start(d), dio_resource_len(d));
122 free_netdev(dev);
125 /* Initialise a single lance board at the given DIO device */
126 static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
128 unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
129 struct hplance_private *lp;
130 int i;
132 /* reset the board */
133 out_8(va+DIO_IDOFF, 0xff);
134 udelay(100); /* ariba! ariba! udelay! udelay! */
136 /* Fill the dev fields */
137 dev->base_addr = va;
138 dev->open = &hplance_open;
139 dev->stop = &hplance_close;
140 #ifdef CONFIG_NET_POLL_CONTROLLER
141 dev->poll_controller = lance_poll;
142 #endif
143 dev->hard_start_xmit = &lance_start_xmit;
144 dev->get_stats = &lance_get_stats;
145 dev->set_multicast_list = &lance_set_multicast;
146 dev->dma = 0;
148 for (i=0; i<6; i++) {
149 /* The NVRAM holds our ethernet address, one nibble per byte,
150 * at bytes NVRAMOFF+1,3,5,7,9...
152 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
153 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
156 lp = netdev_priv(dev);
157 lp->lance.name = (char*)d->name; /* discards const, shut up gcc */
158 lp->lance.base = va;
159 lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
160 lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
161 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
162 lp->lance.irq = d->ipl;
163 lp->lance.writerap = hplance_writerap;
164 lp->lance.writerdp = hplance_writerdp;
165 lp->lance.readrdp = hplance_readrdp;
166 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
167 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
168 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
169 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
172 /* This is disgusting. We have to check the DIO status register for ack every
173 * time we read or write the LANCE registers.
175 static void hplance_writerap(void *priv, unsigned short value)
177 struct lance_private *lp = (struct lance_private *)priv;
178 do {
179 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
180 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
183 static void hplance_writerdp(void *priv, unsigned short value)
185 struct lance_private *lp = (struct lance_private *)priv;
186 do {
187 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
188 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
191 static unsigned short hplance_readrdp(void *priv)
193 struct lance_private *lp = (struct lance_private *)priv;
194 __u16 value;
195 do {
196 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
197 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
198 return value;
201 static int hplance_open(struct net_device *dev)
203 int status;
204 struct lance_private *lp = netdev_priv(dev);
206 status = lance_open(dev); /* call generic lance open code */
207 if (status)
208 return status;
209 /* enable interrupts at board level. */
210 out_8(lp->base + HPLANCE_STATUS, LE_IE);
212 return 0;
215 static int hplance_close(struct net_device *dev)
217 struct lance_private *lp = netdev_priv(dev);
219 out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
220 lance_close(dev);
221 return 0;
224 int __init hplance_init_module(void)
226 return dio_register_driver(&hplance_driver);
229 void __exit hplance_cleanup_module(void)
231 dio_unregister_driver(&hplance_driver);
234 module_init(hplance_init_module);
235 module_exit(hplance_cleanup_module);
237 MODULE_LICENSE("GPL");