blob: 6c9de117ffc68f2941d20f465161460f806f2d04 [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
Amos Kong78c8dbb2014-06-05 11:01:22 +080030/* We have 16392 bytes of RAM for the init block and buffers. This places
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
Amos Kong78c8dbb2014-06-05 11:01:22 +080032 * buffers and 2 Tx buffers, it takes (8 + 2) * 1544 bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 */
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 */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000049static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent);
50static void hplance_init(struct net_device *dev, struct dio_dev *d);
Bill Pemberton0cb05682012-12-03 09:23:54 -050051static void hplance_remove_one(struct dio_dev *d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052static void hplance_writerap(void *priv, unsigned short value);
53static void hplance_writerdp(void *priv, unsigned short value);
54static unsigned short hplance_readrdp(void *priv);
55static int hplance_open(struct net_device *dev);
56static int hplance_close(struct net_device *dev);
57
58static struct dio_device_id hplance_dio_tbl[] = {
59 { DIO_ID_LAN },
60 { 0 }
61};
62
63static struct dio_driver hplance_driver = {
64 .name = "hplance",
65 .id_table = hplance_dio_tbl,
66 .probe = hplance_init_one,
Bill Pemberton0cb05682012-12-03 09:23:54 -050067 .remove = hplance_remove_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068};
69
Alexander Beregalov2e303a92009-04-15 12:52:38 +000070static const struct net_device_ops hplance_netdev_ops = {
71 .ndo_open = hplance_open,
72 .ndo_stop = hplance_close,
73 .ndo_start_xmit = lance_start_xmit,
Jiri Pirkoafc4b132011-08-16 06:29:01 +000074 .ndo_set_rx_mode = lance_set_multicast,
Alexander Beregalov2e303a92009-04-15 12:52:38 +000075 .ndo_change_mtu = eth_change_mtu,
76 .ndo_validate_addr = eth_validate_addr,
77 .ndo_set_mac_address = eth_mac_addr,
78#ifdef CONFIG_NET_POLL_CONTROLLER
79 .ndo_poll_controller = lance_poll,
80#endif
81};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/* Find all the HP Lance boards and initialise them... */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000084static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 struct net_device *dev;
87 int err = -ENOMEM;
88
89 dev = alloc_etherdev(sizeof(struct hplance_private));
90 if (!dev)
91 goto out;
92
93 err = -EBUSY;
94 if (!request_mem_region(dio_resource_start(d),
95 dio_resource_len(d), d->name))
96 goto out_free_netdev;
97
98 hplance_init(dev, d);
99 err = register_netdev(dev);
100 if (err)
101 goto out_release_mem_region;
102
103 dio_set_drvdata(d, dev);
Kars de Jong8e8858e2006-12-09 10:29:58 +0100104
Danny Kukawkaf27fd492012-02-24 03:45:53 +0000105 printk(KERN_INFO "%s: %s; select code %d, addr %pM, irq %d\n",
106 dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
Kars de Jong8e8858e2006-12-09 10:29:58 +0100107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return 0;
109
110 out_release_mem_region:
111 release_mem_region(dio_resource_start(d), dio_resource_len(d));
112 out_free_netdev:
113 free_netdev(dev);
114 out:
115 return err;
116}
117
Bill Pemberton0cb05682012-12-03 09:23:54 -0500118static void hplance_remove_one(struct dio_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
120 struct net_device *dev = dio_get_drvdata(d);
121
122 unregister_netdev(dev);
123 release_mem_region(dio_resource_start(d), dio_resource_len(d));
124 free_netdev(dev);
125}
126
127/* Initialise a single lance board at the given DIO device */
Bill Pemberton0cb05682012-12-03 09:23:54 -0500128static void hplance_init(struct net_device *dev, struct dio_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100130 unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
131 struct hplance_private *lp;
132 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400133
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100134 /* reset the board */
135 out_8(va + DIO_IDOFF, 0xff);
136 udelay(100); /* ariba! ariba! udelay! udelay! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100138 /* Fill the dev fields */
139 dev->base_addr = va;
140 dev->netdev_ops = &hplance_netdev_ops;
141 dev->dma = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400142
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100143 for (i = 0; i < 6; i++) {
144 /* The NVRAM holds our ethernet address, one nibble per byte,
145 * at bytes NVRAMOFF+1,3,5,7,9...
146 */
147 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
148 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
149 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400150
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100151 lp = netdev_priv(dev);
Geert Uytterhoeven4ffa8fc2013-12-28 21:11:15 +0100152 lp->lance.name = d->name;
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100153 lp->lance.base = va;
154 lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
155 lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
156 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
157 lp->lance.irq = d->ipl;
158 lp->lance.writerap = hplance_writerap;
159 lp->lance.writerdp = hplance_writerdp;
160 lp->lance.readrdp = hplance_readrdp;
161 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
162 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
163 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
164 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
167/* This is disgusting. We have to check the DIO status register for ack every
168 * time we read or write the LANCE registers.
169 */
170static void hplance_writerap(void *priv, unsigned short value)
171{
172 struct lance_private *lp = (struct lance_private *)priv;
173 do {
174 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
175 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
176}
177
178static void hplance_writerdp(void *priv, unsigned short value)
179{
180 struct lance_private *lp = (struct lance_private *)priv;
181 do {
182 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
183 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
184}
185
186static unsigned short hplance_readrdp(void *priv)
187{
188 struct lance_private *lp = (struct lance_private *)priv;
189 __u16 value;
190 do {
191 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
192 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
193 return value;
194}
195
196static int hplance_open(struct net_device *dev)
197{
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100198 int status;
199 struct lance_private *lp = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400200
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100201 status = lance_open(dev); /* call generic lance open code */
202 if (status)
203 return status;
204 /* enable interrupts at board level. */
205 out_8(lp->base + HPLANCE_STATUS, LE_IE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100207 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
209
210static int hplance_close(struct net_device *dev)
211{
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100212 struct lance_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100214 out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
215 lance_close(dev);
216 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
Adrian Bunk0b114072008-06-10 01:23:32 +0300219static int __init hplance_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800221 return dio_register_driver(&hplance_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
Adrian Bunk0b114072008-06-10 01:23:32 +0300224static void __exit hplance_cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Geert Uytterhoevena8ab77a2013-12-28 21:11:14 +0100226 dio_unregister_driver(&hplance_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229module_init(hplance_init_module);
230module_exit(hplance_cleanup_module);
231
232MODULE_LICENSE("GPL");