blob: 8baff4e5d964ed6f172f0cd1f44a3ac2c3a5ce0e [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/io.h>
26#include <asm/pgtable.h>
27
28#include "hplance.h"
29
30/* We have 16834 bytes of RAM for the init block and buffers. This places
31 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
32 * buffers and 2 Tx buffers.
33 */
34#define LANCE_LOG_TX_BUFFERS 1
35#define LANCE_LOG_RX_BUFFERS 3
36
37#include "7990.h" /* use generic LANCE code */
38
39/* Our private data structure */
40struct hplance_private {
41 struct lance_private lance;
42};
43
44/* function prototypes... This is easy because all the grot is in the
45 * generic LANCE support. All we have to support is probing for boards,
Jeff Garzik6aa20a22006-09-13 13:24:59 -040046 * plus board-specific init, open and close actions.
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 * Oh, and we need to tell the generic code how to read and write LANCE registers...
48 */
49static int __devinit hplance_init_one(struct dio_dev *d,
50 const struct dio_device_id *ent);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040051static void __devinit hplance_init(struct net_device *dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 struct dio_dev *d);
53static void __devexit hplance_remove_one(struct dio_dev *d);
54static void hplance_writerap(void *priv, unsigned short value);
55static void hplance_writerdp(void *priv, unsigned short value);
56static unsigned short hplance_readrdp(void *priv);
57static int hplance_open(struct net_device *dev);
58static int hplance_close(struct net_device *dev);
59
60static struct dio_device_id hplance_dio_tbl[] = {
61 { DIO_ID_LAN },
62 { 0 }
63};
64
65static struct dio_driver hplance_driver = {
66 .name = "hplance",
67 .id_table = hplance_dio_tbl,
68 .probe = hplance_init_one,
69 .remove = __devexit_p(hplance_remove_one),
70};
71
Alexander Beregalov2e303a92009-04-15 12:52:38 +000072static const struct net_device_ops hplance_netdev_ops = {
73 .ndo_open = hplance_open,
74 .ndo_stop = hplance_close,
75 .ndo_start_xmit = lance_start_xmit,
Jiri Pirkoafc4b132011-08-16 06:29:01 +000076 .ndo_set_rx_mode = lance_set_multicast,
Alexander Beregalov2e303a92009-04-15 12:52:38 +000077 .ndo_change_mtu = eth_change_mtu,
78 .ndo_validate_addr = eth_validate_addr,
79 .ndo_set_mac_address = eth_mac_addr,
80#ifdef CONFIG_NET_POLL_CONTROLLER
81 .ndo_poll_controller = lance_poll,
82#endif
83};
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* Find all the HP Lance boards and initialise them... */
86static int __devinit hplance_init_one(struct dio_dev *d,
87 const struct dio_device_id *ent)
88{
89 struct net_device *dev;
90 int err = -ENOMEM;
91
92 dev = alloc_etherdev(sizeof(struct hplance_private));
93 if (!dev)
94 goto out;
95
96 err = -EBUSY;
97 if (!request_mem_region(dio_resource_start(d),
98 dio_resource_len(d), d->name))
99 goto out_free_netdev;
100
101 hplance_init(dev, d);
102 err = register_netdev(dev);
103 if (err)
104 goto out_release_mem_region;
105
106 dio_set_drvdata(d, dev);
Kars de Jong8e8858e2006-12-09 10:29:58 +0100107
Danny Kukawkaf27fd492012-02-24 03:45:53 +0000108 printk(KERN_INFO "%s: %s; select code %d, addr %pM, irq %d\n",
109 dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
Kars de Jong8e8858e2006-12-09 10:29:58 +0100110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return 0;
112
113 out_release_mem_region:
114 release_mem_region(dio_resource_start(d), dio_resource_len(d));
115 out_free_netdev:
116 free_netdev(dev);
117 out:
118 return err;
119}
120
121static void __devexit hplance_remove_one(struct dio_dev *d)
122{
123 struct net_device *dev = dio_get_drvdata(d);
124
125 unregister_netdev(dev);
126 release_mem_region(dio_resource_start(d), dio_resource_len(d));
127 free_netdev(dev);
128}
129
130/* Initialise a single lance board at the given DIO device */
Geert Uytterhoeven9281b2a2011-06-13 08:17:36 +0000131static void __devinit hplance_init(struct net_device *dev, struct dio_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
134 struct hplance_private *lp;
135 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 /* reset the board */
138 out_8(va+DIO_IDOFF, 0xff);
139 udelay(100); /* ariba! ariba! udelay! udelay! */
140
141 /* Fill the dev fields */
142 dev->base_addr = va;
Alexander Beregalov2e303a92009-04-15 12:52:38 +0000143 dev->netdev_ops = &hplance_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 dev->dma = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 for (i=0; i<6; i++) {
147 /* The NVRAM holds our ethernet address, one nibble per byte,
148 * at bytes NVRAMOFF+1,3,5,7,9...
149 */
150 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
151 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 lp = netdev_priv(dev);
155 lp->lance.name = (char*)d->name; /* discards const, shut up gcc */
156 lp->lance.base = va;
157 lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
Al Viroa5d361f2006-01-12 01:06:34 -0800158 lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
160 lp->lance.irq = d->ipl;
161 lp->lance.writerap = hplance_writerap;
162 lp->lance.writerdp = hplance_writerdp;
163 lp->lance.readrdp = hplance_readrdp;
164 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
165 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
166 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
167 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
170/* This is disgusting. We have to check the DIO status register for ack every
171 * time we read or write the LANCE registers.
172 */
173static void hplance_writerap(void *priv, unsigned short value)
174{
175 struct lance_private *lp = (struct lance_private *)priv;
176 do {
177 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
178 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
179}
180
181static void hplance_writerdp(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_RDP, value);
186 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
187}
188
189static unsigned short hplance_readrdp(void *priv)
190{
191 struct lance_private *lp = (struct lance_private *)priv;
192 __u16 value;
193 do {
194 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
195 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
196 return value;
197}
198
199static int hplance_open(struct net_device *dev)
200{
201 int status;
202 struct lance_private *lp = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 status = lance_open(dev); /* call generic lance open code */
205 if (status)
206 return status;
207 /* enable interrupts at board level. */
208 out_8(lp->base + HPLANCE_STATUS, LE_IE);
209
210 return 0;
211}
212
213static int hplance_close(struct net_device *dev)
214{
215 struct lance_private *lp = netdev_priv(dev);
216
217 out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
218 lance_close(dev);
219 return 0;
220}
221
Adrian Bunk0b114072008-06-10 01:23:32 +0300222static int __init hplance_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800224 return dio_register_driver(&hplance_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
Adrian Bunk0b114072008-06-10 01:23:32 +0300227static void __exit hplance_cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
229 dio_unregister_driver(&hplance_driver);
230}
231
232module_init(hplance_init_module);
233module_exit(hplance_cleanup_module);
234
235MODULE_LICENSE("GPL");