]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/ethernet/amd/hplance.c
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / drivers / net / ethernet / amd / hplance.c
1 /* 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/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/io.h>
26 #include <asm/pgtable.h>
27
28 #include "hplance.h"
29
30 /* We have 16392 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, it takes (8 + 2) * 1544 bytes.
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 */
40 struct 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,
46 * plus board-specific init, open and close actions.
47 * Oh, and we need to tell the generic code how to read and write LANCE registers...
48 */
49 static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent);
50 static void hplance_init(struct net_device *dev, struct dio_dev *d);
51 static void hplance_remove_one(struct dio_dev *d);
52 static void hplance_writerap(void *priv, unsigned short value);
53 static void hplance_writerdp(void *priv, unsigned short value);
54 static unsigned short hplance_readrdp(void *priv);
55 static int hplance_open(struct net_device *dev);
56 static int hplance_close(struct net_device *dev);
57
58 static struct dio_device_id hplance_dio_tbl[] = {
59 { DIO_ID_LAN },
60 { 0 }
61 };
62
63 static struct dio_driver hplance_driver = {
64 .name = "hplance",
65 .id_table = hplance_dio_tbl,
66 .probe = hplance_init_one,
67 .remove = hplance_remove_one,
68 };
69
70 static 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,
74 .ndo_set_rx_mode = lance_set_multicast,
75 .ndo_validate_addr = eth_validate_addr,
76 .ndo_set_mac_address = eth_mac_addr,
77 #ifdef CONFIG_NET_POLL_CONTROLLER
78 .ndo_poll_controller = lance_poll,
79 #endif
80 };
81
82 /* Find all the HP Lance boards and initialise them... */
83 static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent)
84 {
85 struct net_device *dev;
86 int err = -ENOMEM;
87
88 dev = alloc_etherdev(sizeof(struct hplance_private));
89 if (!dev)
90 goto out;
91
92 err = -EBUSY;
93 if (!request_mem_region(dio_resource_start(d),
94 dio_resource_len(d), d->name))
95 goto out_free_netdev;
96
97 hplance_init(dev, d);
98 err = register_netdev(dev);
99 if (err)
100 goto out_release_mem_region;
101
102 dio_set_drvdata(d, dev);
103
104 printk(KERN_INFO "%s: %s; select code %d, addr %pM, irq %d\n",
105 dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
106
107 return 0;
108
109 out_release_mem_region:
110 release_mem_region(dio_resource_start(d), dio_resource_len(d));
111 out_free_netdev:
112 free_netdev(dev);
113 out:
114 return err;
115 }
116
117 static void hplance_remove_one(struct dio_dev *d)
118 {
119 struct net_device *dev = dio_get_drvdata(d);
120
121 unregister_netdev(dev);
122 release_mem_region(dio_resource_start(d), dio_resource_len(d));
123 free_netdev(dev);
124 }
125
126 /* Initialise a single lance board at the given DIO device */
127 static void hplance_init(struct net_device *dev, struct dio_dev *d)
128 {
129 unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
130 struct hplance_private *lp;
131 int i;
132
133 /* reset the board */
134 out_8(va + DIO_IDOFF, 0xff);
135 udelay(100); /* ariba! ariba! udelay! udelay! */
136
137 /* Fill the dev fields */
138 dev->base_addr = va;
139 dev->netdev_ops = &hplance_netdev_ops;
140 dev->dma = 0;
141
142 for (i = 0; i < 6; i++) {
143 /* The NVRAM holds our ethernet address, one nibble per byte,
144 * at bytes NVRAMOFF+1,3,5,7,9...
145 */
146 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
147 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
148 }
149
150 lp = netdev_priv(dev);
151 lp->lance.name = d->name;
152 lp->lance.base = va;
153 lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
154 lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
155 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
156 lp->lance.irq = d->ipl;
157 lp->lance.writerap = hplance_writerap;
158 lp->lance.writerdp = hplance_writerdp;
159 lp->lance.readrdp = hplance_readrdp;
160 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
161 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
162 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
163 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
164 }
165
166 /* This is disgusting. We have to check the DIO status register for ack every
167 * time we read or write the LANCE registers.
168 */
169 static void hplance_writerap(void *priv, unsigned short value)
170 {
171 struct lance_private *lp = (struct lance_private *)priv;
172 do {
173 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
174 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
175 }
176
177 static void hplance_writerdp(void *priv, unsigned short value)
178 {
179 struct lance_private *lp = (struct lance_private *)priv;
180 do {
181 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
182 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
183 }
184
185 static unsigned short hplance_readrdp(void *priv)
186 {
187 struct lance_private *lp = (struct lance_private *)priv;
188 __u16 value;
189 do {
190 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
191 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
192 return value;
193 }
194
195 static int hplance_open(struct net_device *dev)
196 {
197 int status;
198 struct lance_private *lp = netdev_priv(dev);
199
200 status = lance_open(dev); /* call generic lance open code */
201 if (status)
202 return status;
203 /* enable interrupts at board level. */
204 out_8(lp->base + HPLANCE_STATUS, LE_IE);
205
206 return 0;
207 }
208
209 static int hplance_close(struct net_device *dev)
210 {
211 struct lance_private *lp = netdev_priv(dev);
212
213 out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
214 lance_close(dev);
215 return 0;
216 }
217
218 static int __init hplance_init_module(void)
219 {
220 return dio_register_driver(&hplance_driver);
221 }
222
223 static void __exit hplance_cleanup_module(void)
224 {
225 dio_unregister_driver(&hplance_driver);
226 }
227
228 module_init(hplance_init_module);
229 module_exit(hplance_cleanup_module);
230
231 MODULE_LICENSE("GPL");