Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | /* hplance.c : the Linux/hp300/lance ethernet driver |
3 | * | |
4 | * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk> | |
5 | * Based on the Sun Lance driver and the NetBSD HP Lance driver | |
6 | * Uses the generic 7990.c LANCE code. | |
7 | */ | |
8 | ||
9 | #include <linux/module.h> | |
10 | #include <linux/kernel.h> | |
11 | #include <linux/types.h> | |
12 | #include <linux/interrupt.h> | |
13 | #include <linux/ioport.h> | |
1da177e4 LT |
14 | #include <linux/string.h> |
15 | #include <linux/delay.h> | |
16 | #include <linux/init.h> | |
17 | #include <linux/errno.h> | |
65fddcfc | 18 | #include <linux/pgtable.h> |
1da177e4 LT |
19 | /* Used for the temporal inet entries and routing */ |
20 | #include <linux/socket.h> | |
21 | #include <linux/route.h> | |
22 | #include <linux/dio.h> | |
23 | #include <linux/netdevice.h> | |
24 | #include <linux/etherdevice.h> | |
25 | #include <linux/skbuff.h> | |
26 | ||
1da177e4 | 27 | #include <asm/io.h> |
1da177e4 LT |
28 | |
29 | #include "hplance.h" | |
30 | ||
78c8dbb6 | 31 | /* We have 16392 bytes of RAM for the init block and buffers. This places |
1da177e4 | 32 | * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx |
78c8dbb6 | 33 | * buffers and 2 Tx buffers, it takes (8 + 2) * 1544 bytes. |
1da177e4 LT |
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 */ | |
41 | struct 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, | |
6aa20a22 | 47 | * plus board-specific init, open and close actions. |
1da177e4 LT |
48 | * Oh, and we need to tell the generic code how to read and write LANCE registers... |
49 | */ | |
1dd06ae8 GKH |
50 | static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent); |
51 | static void hplance_init(struct net_device *dev, struct dio_dev *d); | |
0cb0568d | 52 | static void hplance_remove_one(struct dio_dev *d); |
1da177e4 LT |
53 | static void hplance_writerap(void *priv, unsigned short value); |
54 | static void hplance_writerdp(void *priv, unsigned short value); | |
55 | static unsigned short hplance_readrdp(void *priv); | |
56 | static int hplance_open(struct net_device *dev); | |
57 | static int hplance_close(struct net_device *dev); | |
58 | ||
59 | static struct dio_device_id hplance_dio_tbl[] = { | |
60 | { DIO_ID_LAN }, | |
61 | { 0 } | |
62 | }; | |
63 | ||
64 | static struct dio_driver hplance_driver = { | |
65 | .name = "hplance", | |
66 | .id_table = hplance_dio_tbl, | |
67 | .probe = hplance_init_one, | |
0cb0568d | 68 | .remove = hplance_remove_one, |
1da177e4 LT |
69 | }; |
70 | ||
2e303a92 AB |
71 | static const struct net_device_ops hplance_netdev_ops = { |
72 | .ndo_open = hplance_open, | |
73 | .ndo_stop = hplance_close, | |
74 | .ndo_start_xmit = lance_start_xmit, | |
afc4b13d | 75 | .ndo_set_rx_mode = lance_set_multicast, |
2e303a92 AB |
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 | ||
1da177e4 | 83 | /* Find all the HP Lance boards and initialise them... */ |
1dd06ae8 | 84 | static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent) |
1da177e4 LT |
85 | { |
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); | |
8e8858e9 | 104 | |
f27fd499 DK |
105 | 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); | |
8e8858e9 | 107 | |
1da177e4 LT |
108 | 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 | ||
0cb0568d | 118 | static void hplance_remove_one(struct dio_dev *d) |
1da177e4 LT |
119 | { |
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 */ | |
0cb0568d | 128 | static void hplance_init(struct net_device *dev, struct dio_dev *d) |
1da177e4 | 129 | { |
a8ab77a8 GU |
130 | unsigned long va = (d->resource.start + DIO_VIRADDRBASE); |
131 | struct hplance_private *lp; | |
21942eef | 132 | u8 addr[ETH_ALEN]; |
a8ab77a8 GU |
133 | int i; |
134 | ||
135 | /* reset the board */ | |
136 | out_8(va + DIO_IDOFF, 0xff); | |
137 | udelay(100); /* ariba! ariba! udelay! udelay! */ | |
138 | ||
139 | /* Fill the dev fields */ | |
140 | dev->base_addr = va; | |
141 | dev->netdev_ops = &hplance_netdev_ops; | |
142 | dev->dma = 0; | |
143 | ||
144 | for (i = 0; i < 6; i++) { | |
145 | /* The NVRAM holds our ethernet address, one nibble per byte, | |
146 | * at bytes NVRAMOFF+1,3,5,7,9... | |
147 | */ | |
21942eef | 148 | addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4) |
a8ab77a8 GU |
149 | | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF); |
150 | } | |
21942eef | 151 | eth_hw_addr_set(dev, addr); |
a8ab77a8 GU |
152 | |
153 | lp = netdev_priv(dev); | |
4ffa8fcd | 154 | lp->lance.name = d->name; |
a8ab77a8 GU |
155 | lp->lance.base = va; |
156 | lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */ | |
157 | lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */ | |
158 | lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */ | |
159 | lp->lance.irq = d->ipl; | |
160 | lp->lance.writerap = hplance_writerap; | |
161 | lp->lance.writerdp = hplance_writerdp; | |
162 | lp->lance.readrdp = hplance_readrdp; | |
163 | lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS; | |
164 | lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; | |
165 | lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK; | |
166 | lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK; | |
1da177e4 LT |
167 | } |
168 | ||
169 | /* This is disgusting. We have to check the DIO status register for ack every | |
170 | * time we read or write the LANCE registers. | |
171 | */ | |
172 | static void hplance_writerap(void *priv, unsigned short value) | |
173 | { | |
174 | struct lance_private *lp = (struct lance_private *)priv; | |
3f6ebcff | 175 | |
1da177e4 LT |
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 | ||
181 | static void hplance_writerdp(void *priv, unsigned short value) | |
182 | { | |
183 | struct lance_private *lp = (struct lance_private *)priv; | |
3f6ebcff | 184 | |
1da177e4 LT |
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 | ||
190 | static unsigned short hplance_readrdp(void *priv) | |
191 | { | |
192 | struct lance_private *lp = (struct lance_private *)priv; | |
193 | __u16 value; | |
3f6ebcff | 194 | |
1da177e4 LT |
195 | do { |
196 | value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP); | |
197 | } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0); | |
198 | return value; | |
199 | } | |
200 | ||
201 | static int hplance_open(struct net_device *dev) | |
202 | { | |
a8ab77a8 GU |
203 | int status; |
204 | struct lance_private *lp = netdev_priv(dev); | |
6aa20a22 | 205 | |
a8ab77a8 GU |
206 | status = lance_open(dev); /* call generic lance open code */ |
207 | if (status) | |
208 | return status; | |
209 | /* enable interrupts at board level. */ | |
210 | out_8(lp->base + HPLANCE_STATUS, LE_IE); | |
1da177e4 | 211 | |
a8ab77a8 | 212 | return 0; |
1da177e4 LT |
213 | } |
214 | ||
215 | static int hplance_close(struct net_device *dev) | |
216 | { | |
a8ab77a8 | 217 | struct lance_private *lp = netdev_priv(dev); |
1da177e4 | 218 | |
a8ab77a8 GU |
219 | out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */ |
220 | lance_close(dev); | |
221 | return 0; | |
1da177e4 LT |
222 | } |
223 | ||
0b114078 | 224 | static int __init hplance_init_module(void) |
1da177e4 | 225 | { |
e51c01b0 | 226 | return dio_register_driver(&hplance_driver); |
1da177e4 LT |
227 | } |
228 | ||
0b114078 | 229 | static void __exit hplance_cleanup_module(void) |
1da177e4 | 230 | { |
a8ab77a8 | 231 | dio_unregister_driver(&hplance_driver); |
1da177e4 LT |
232 | } |
233 | ||
234 | module_init(hplance_init_module); | |
235 | module_exit(hplance_cleanup_module); | |
236 | ||
deb9d576 | 237 | MODULE_DESCRIPTION("HP300 on-board LANCE Ethernet driver"); |
1da177e4 | 238 | MODULE_LICENSE("GPL"); |