blob: 3e3528ade259d73f072d614f2181fe04c2083940 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* hplance.c : the Linux/hp300/lance ethernet driver
2 *
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 */
7
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>
25
26#include <asm/system.h>
27#include <asm/io.h>
28#include <asm/pgtable.h>
29
30#include "hplance.h"
31
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.
35 */
36#define LANCE_LOG_TX_BUFFERS 1
37#define LANCE_LOG_RX_BUFFERS 3
38
39#include "7990.h" /* use generic LANCE code */
40
41/* Our private data structure */
42struct hplance_private {
43 struct lance_private lance;
44};
45
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,
Jeff Garzik6aa20a22006-09-13 13:24:59 -040048 * plus board-specific init, open and close actions.
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * Oh, and we need to tell the generic code how to read and write LANCE registers...
50 */
51static int __devinit hplance_init_one(struct dio_dev *d,
52 const struct dio_device_id *ent);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040053static void __devinit hplance_init(struct net_device *dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 struct dio_dev *d);
55static void __devexit hplance_remove_one(struct dio_dev *d);
56static void hplance_writerap(void *priv, unsigned short value);
57static void hplance_writerdp(void *priv, unsigned short value);
58static unsigned short hplance_readrdp(void *priv);
59static int hplance_open(struct net_device *dev);
60static int hplance_close(struct net_device *dev);
61
62static struct dio_device_id hplance_dio_tbl[] = {
63 { DIO_ID_LAN },
64 { 0 }
65};
66
67static 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),
72};
73
Alexander Beregalov2e303a92009-04-15 12:52:38 +000074static const struct net_device_ops hplance_netdev_ops = {
75 .ndo_open = hplance_open,
76 .ndo_stop = hplance_close,
77 .ndo_start_xmit = lance_start_xmit,
78 .ndo_set_multicast_list = lance_set_multicast,
79 .ndo_change_mtu = eth_change_mtu,
80 .ndo_validate_addr = eth_validate_addr,
81 .ndo_set_mac_address = eth_mac_addr,
82#ifdef CONFIG_NET_POLL_CONTROLLER
83 .ndo_poll_controller = lance_poll,
84#endif
85};
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/* Find all the HP Lance boards and initialise them... */
88static int __devinit hplance_init_one(struct dio_dev *d,
89 const struct dio_device_id *ent)
90{
91 struct net_device *dev;
92 int err = -ENOMEM;
Kars de Jong8e8858e2006-12-09 10:29:58 +010093 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 dev = alloc_etherdev(sizeof(struct hplance_private));
96 if (!dev)
97 goto out;
98
99 err = -EBUSY;
100 if (!request_mem_region(dio_resource_start(d),
101 dio_resource_len(d), d->name))
102 goto out_free_netdev;
103
104 hplance_init(dev, d);
105 err = register_netdev(dev);
106 if (err)
107 goto out_release_mem_region;
108
109 dio_set_drvdata(d, dev);
Kars de Jong8e8858e2006-12-09 10:29:58 +0100110
111 printk(KERN_INFO "%s: %s; select code %d, addr %2.2x", dev->name, d->name, d->scode, dev->dev_addr[0]);
112
113 for (i=1; i<6; i++) {
114 printk(":%2.2x", dev->dev_addr[i]);
115 }
116
117 printk(", irq %d\n", d->ipl);
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return 0;
120
121 out_release_mem_region:
122 release_mem_region(dio_resource_start(d), dio_resource_len(d));
123 out_free_netdev:
124 free_netdev(dev);
125 out:
126 return err;
127}
128
129static void __devexit hplance_remove_one(struct dio_dev *d)
130{
131 struct net_device *dev = dio_get_drvdata(d);
132
133 unregister_netdev(dev);
134 release_mem_region(dio_resource_start(d), dio_resource_len(d));
135 free_netdev(dev);
136}
137
138/* Initialise a single lance board at the given DIO device */
139static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
140{
141 unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
142 struct hplance_private *lp;
143 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 /* reset the board */
146 out_8(va+DIO_IDOFF, 0xff);
147 udelay(100); /* ariba! ariba! udelay! udelay! */
148
149 /* Fill the dev fields */
150 dev->base_addr = va;
Alexander Beregalov2e303a92009-04-15 12:52:38 +0000151 dev->netdev_ops = &hplance_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 dev->dma = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 for (i=0; i<6; i++) {
155 /* The NVRAM holds our ethernet address, one nibble per byte,
156 * at bytes NVRAMOFF+1,3,5,7,9...
157 */
158 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
159 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 lp = netdev_priv(dev);
163 lp->lance.name = (char*)d->name; /* discards const, shut up gcc */
164 lp->lance.base = va;
165 lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
Al Viroa5d361f2006-01-12 01:06:34 -0800166 lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
168 lp->lance.irq = d->ipl;
169 lp->lance.writerap = hplance_writerap;
170 lp->lance.writerdp = hplance_writerdp;
171 lp->lance.readrdp = hplance_readrdp;
172 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
173 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
174 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
175 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
178/* This is disgusting. We have to check the DIO status register for ack every
179 * time we read or write the LANCE registers.
180 */
181static void hplance_writerap(void *priv, unsigned short value)
182{
183 struct lance_private *lp = (struct lance_private *)priv;
184 do {
185 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
186 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
187}
188
189static void hplance_writerdp(void *priv, unsigned short value)
190{
191 struct lance_private *lp = (struct lance_private *)priv;
192 do {
193 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
194 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
195}
196
197static unsigned short hplance_readrdp(void *priv)
198{
199 struct lance_private *lp = (struct lance_private *)priv;
200 __u16 value;
201 do {
202 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
203 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
204 return value;
205}
206
207static int hplance_open(struct net_device *dev)
208{
209 int status;
210 struct lance_private *lp = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 status = lance_open(dev); /* call generic lance open code */
213 if (status)
214 return status;
215 /* enable interrupts at board level. */
216 out_8(lp->base + HPLANCE_STATUS, LE_IE);
217
218 return 0;
219}
220
221static int hplance_close(struct net_device *dev)
222{
223 struct lance_private *lp = netdev_priv(dev);
224
225 out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
226 lance_close(dev);
227 return 0;
228}
229
Adrian Bunk0b114072008-06-10 01:23:32 +0300230static int __init hplance_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800232 return dio_register_driver(&hplance_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
Adrian Bunk0b114072008-06-10 01:23:32 +0300235static void __exit hplance_cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 dio_unregister_driver(&hplance_driver);
238}
239
240module_init(hplance_init_module);
241module_exit(hplance_cleanup_module);
242
243MODULE_LICENSE("GPL");