blob: 4e2d68a4de8aae7fb9404067d18508cbf8be4d19 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/string.h>
14#include <linux/delay.h>
15#include <linux/init.h>
16#include <linux/errno.h>
17/* Used for the temporal inet entries and routing */
18#include <linux/socket.h>
19#include <linux/route.h>
20#include <linux/dio.h>
21#include <linux/netdevice.h>
22#include <linux/etherdevice.h>
23#include <linux/skbuff.h>
24
25#include <asm/system.h>
26#include <asm/io.h>
27#include <asm/pgtable.h>
28
29#include "hplance.h"
30
31/* We have 16834 bytes of RAM for the init block and buffers. This places
32 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
33 * buffers and 2 Tx buffers.
34 */
35#define LANCE_LOG_TX_BUFFERS 1
36#define LANCE_LOG_RX_BUFFERS 3
37
38#include "7990.h" /* use generic LANCE code */
39
40/* Our private data structure */
41struct hplance_private {
42 struct lance_private lance;
43};
44
45/* function prototypes... This is easy because all the grot is in the
46 * generic LANCE support. All we have to support is probing for boards,
Jeff Garzik6aa20a22006-09-13 13:24:59 -040047 * plus board-specific init, open and close actions.
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 * Oh, and we need to tell the generic code how to read and write LANCE registers...
49 */
50static int __devinit hplance_init_one(struct dio_dev *d,
51 const struct dio_device_id *ent);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040052static void __devinit hplance_init(struct net_device *dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 struct dio_dev *d);
54static void __devexit hplance_remove_one(struct dio_dev *d);
55static void hplance_writerap(void *priv, unsigned short value);
56static void hplance_writerdp(void *priv, unsigned short value);
57static unsigned short hplance_readrdp(void *priv);
58static int hplance_open(struct net_device *dev);
59static int hplance_close(struct net_device *dev);
60
61static struct dio_device_id hplance_dio_tbl[] = {
62 { DIO_ID_LAN },
63 { 0 }
64};
65
66static struct dio_driver hplance_driver = {
67 .name = "hplance",
68 .id_table = hplance_dio_tbl,
69 .probe = hplance_init_one,
70 .remove = __devexit_p(hplance_remove_one),
71};
72
Alexander Beregalov2e303a92009-04-15 12:52:38 +000073static const struct net_device_ops hplance_netdev_ops = {
74 .ndo_open = hplance_open,
75 .ndo_stop = hplance_close,
76 .ndo_start_xmit = lance_start_xmit,
Jiri Pirkoafc4b132011-08-16 06:29:01 +000077 .ndo_set_rx_mode = lance_set_multicast,
Alexander Beregalov2e303a92009-04-15 12:52:38 +000078 .ndo_change_mtu = eth_change_mtu,
79 .ndo_validate_addr = eth_validate_addr,
80 .ndo_set_mac_address = eth_mac_addr,
81#ifdef CONFIG_NET_POLL_CONTROLLER
82 .ndo_poll_controller = lance_poll,
83#endif
84};
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086/* Find all the HP Lance boards and initialise them... */
87static int __devinit hplance_init_one(struct dio_dev *d,
88 const struct dio_device_id *ent)
89{
90 struct net_device *dev;
91 int err = -ENOMEM;
92
93 dev = alloc_etherdev(sizeof(struct hplance_private));
94 if (!dev)
95 goto out;
96
97 err = -EBUSY;
98 if (!request_mem_region(dio_resource_start(d),
99 dio_resource_len(d), d->name))
100 goto out_free_netdev;
101
102 hplance_init(dev, d);
103 err = register_netdev(dev);
104 if (err)
105 goto out_release_mem_region;
106
107 dio_set_drvdata(d, dev);
Kars de Jong8e8858e2006-12-09 10:29:58 +0100108
Danny Kukawkaf27fd492012-02-24 03:45:53 +0000109 printk(KERN_INFO "%s: %s; select code %d, addr %pM, irq %d\n",
110 dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
Kars de Jong8e8858e2006-12-09 10:29:58 +0100111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return 0;
113
114 out_release_mem_region:
115 release_mem_region(dio_resource_start(d), dio_resource_len(d));
116 out_free_netdev:
117 free_netdev(dev);
118 out:
119 return err;
120}
121
122static void __devexit hplance_remove_one(struct dio_dev *d)
123{
124 struct net_device *dev = dio_get_drvdata(d);
125
126 unregister_netdev(dev);
127 release_mem_region(dio_resource_start(d), dio_resource_len(d));
128 free_netdev(dev);
129}
130
131/* Initialise a single lance board at the given DIO device */
Geert Uytterhoeven9281b2a2011-06-13 08:17:36 +0000132static void __devinit hplance_init(struct net_device *dev, struct dio_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
135 struct hplance_private *lp;
136 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 /* reset the board */
139 out_8(va+DIO_IDOFF, 0xff);
140 udelay(100); /* ariba! ariba! udelay! udelay! */
141
142 /* Fill the dev fields */
143 dev->base_addr = va;
Alexander Beregalov2e303a92009-04-15 12:52:38 +0000144 dev->netdev_ops = &hplance_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 dev->dma = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 for (i=0; i<6; i++) {
148 /* The NVRAM holds our ethernet address, one nibble per byte,
149 * at bytes NVRAMOFF+1,3,5,7,9...
150 */
151 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
152 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 lp = netdev_priv(dev);
156 lp->lance.name = (char*)d->name; /* discards const, shut up gcc */
157 lp->lance.base = va;
158 lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
Al Viroa5d361f2006-01-12 01:06:34 -0800159 lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
161 lp->lance.irq = d->ipl;
162 lp->lance.writerap = hplance_writerap;
163 lp->lance.writerdp = hplance_writerdp;
164 lp->lance.readrdp = hplance_readrdp;
165 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
166 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
167 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
168 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
171/* This is disgusting. We have to check the DIO status register for ack every
172 * time we read or write the LANCE registers.
173 */
174static void hplance_writerap(void *priv, unsigned short value)
175{
176 struct lance_private *lp = (struct lance_private *)priv;
177 do {
178 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
179 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
180}
181
182static void hplance_writerdp(void *priv, unsigned short value)
183{
184 struct lance_private *lp = (struct lance_private *)priv;
185 do {
186 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
187 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
188}
189
190static unsigned short hplance_readrdp(void *priv)
191{
192 struct lance_private *lp = (struct lance_private *)priv;
193 __u16 value;
194 do {
195 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
196 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
197 return value;
198}
199
200static int hplance_open(struct net_device *dev)
201{
202 int status;
203 struct lance_private *lp = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 status = lance_open(dev); /* call generic lance open code */
206 if (status)
207 return status;
208 /* enable interrupts at board level. */
209 out_8(lp->base + HPLANCE_STATUS, LE_IE);
210
211 return 0;
212}
213
214static int hplance_close(struct net_device *dev)
215{
216 struct lance_private *lp = netdev_priv(dev);
217
218 out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
219 lance_close(dev);
220 return 0;
221}
222
Adrian Bunk0b114072008-06-10 01:23:32 +0300223static int __init hplance_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800225 return dio_register_driver(&hplance_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Adrian Bunk0b114072008-06-10 01:23:32 +0300228static void __exit hplance_cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 dio_unregister_driver(&hplance_driver);
231}
232
233module_init(hplance_init_module);
234module_exit(hplance_cleanup_module);
235
236MODULE_LICENSE("GPL");