Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Comtrol SV11 card driver | |
3 | * | |
4 | * This is a slightly odd Z85230 synchronous driver. All you need to | |
5 | * know basically is | |
6 | * | |
7 | * Its a genuine Z85230 | |
8 | * | |
9 | * It supports DMA using two DMA channels in SYNC mode. The driver doesn't | |
10 | * use these facilities | |
11 | * | |
12 | * The control port is at io+1, the data at io+3 and turning off the DMA | |
13 | * is done by writing 0 to io+4 | |
14 | * | |
15 | * The hardware does the bus handling to avoid the need for delays between | |
16 | * touching control registers. | |
17 | * | |
18 | * Port B isnt wired (why - beats me) | |
52e8a6a2 KH |
19 | * |
20 | * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl> | |
1da177e4 LT |
21 | */ |
22 | ||
23 | #include <linux/module.h> | |
24 | #include <linux/kernel.h> | |
25 | #include <linux/mm.h> | |
26 | #include <linux/net.h> | |
27 | #include <linux/skbuff.h> | |
28 | #include <linux/netdevice.h> | |
29 | #include <linux/if_arp.h> | |
30 | #include <linux/delay.h> | |
52e8a6a2 | 31 | #include <linux/hdlc.h> |
1da177e4 LT |
32 | #include <linux/ioport.h> |
33 | #include <net/arp.h> | |
34 | ||
82729971 | 35 | #include <asm/irq.h> |
1da177e4 LT |
36 | #include <asm/io.h> |
37 | #include <asm/dma.h> | |
38 | #include <asm/byteorder.h> | |
1da177e4 LT |
39 | #include "z85230.h" |
40 | ||
41 | static int dma; | |
42 | ||
1da177e4 LT |
43 | /* |
44 | * Network driver support routines | |
45 | */ | |
46 | ||
52e8a6a2 KH |
47 | static inline struct z8530_dev* dev_to_sv(struct net_device *dev) |
48 | { | |
49 | return (struct z8530_dev *)dev_to_hdlc(dev)->priv; | |
50 | } | |
51 | ||
1da177e4 | 52 | /* |
52e8a6a2 | 53 | * Frame receive. Simple for our card as we do HDLC and there |
1da177e4 LT |
54 | * is no funny garbage involved |
55 | */ | |
52e8a6a2 | 56 | |
1da177e4 LT |
57 | static void hostess_input(struct z8530_channel *c, struct sk_buff *skb) |
58 | { | |
59 | /* Drop the CRC - it's not a good idea to try and negotiate it ;) */ | |
52e8a6a2 KH |
60 | skb_trim(skb, skb->len - 2); |
61 | skb->protocol = hdlc_type_trans(skb, c->netdevice); | |
98e399f8 | 62 | skb_reset_mac_header(skb); |
52e8a6a2 | 63 | skb->dev = c->netdevice; |
1da177e4 LT |
64 | /* |
65 | * Send it to the PPP layer. We don't have time to process | |
66 | * it right now. | |
67 | */ | |
68 | netif_rx(skb); | |
1da177e4 | 69 | } |
52e8a6a2 | 70 | |
1da177e4 LT |
71 | /* |
72 | * We've been placed in the UP state | |
52e8a6a2 KH |
73 | */ |
74 | ||
1da177e4 LT |
75 | static int hostess_open(struct net_device *d) |
76 | { | |
52e8a6a2 | 77 | struct z8530_dev *sv11 = dev_to_sv(d); |
1da177e4 | 78 | int err = -1; |
52e8a6a2 | 79 | |
1da177e4 LT |
80 | /* |
81 | * Link layer up | |
82 | */ | |
52e8a6a2 | 83 | switch (dma) { |
1da177e4 | 84 | case 0: |
52e8a6a2 | 85 | err = z8530_sync_open(d, &sv11->chanA); |
1da177e4 LT |
86 | break; |
87 | case 1: | |
52e8a6a2 | 88 | err = z8530_sync_dma_open(d, &sv11->chanA); |
1da177e4 LT |
89 | break; |
90 | case 2: | |
52e8a6a2 | 91 | err = z8530_sync_txdma_open(d, &sv11->chanA); |
1da177e4 LT |
92 | break; |
93 | } | |
52e8a6a2 KH |
94 | |
95 | if (err) | |
1da177e4 | 96 | return err; |
52e8a6a2 KH |
97 | |
98 | err = hdlc_open(d); | |
99 | if (err) { | |
100 | switch (dma) { | |
1da177e4 | 101 | case 0: |
52e8a6a2 | 102 | z8530_sync_close(d, &sv11->chanA); |
1da177e4 LT |
103 | break; |
104 | case 1: | |
52e8a6a2 | 105 | z8530_sync_dma_close(d, &sv11->chanA); |
1da177e4 LT |
106 | break; |
107 | case 2: | |
52e8a6a2 | 108 | z8530_sync_txdma_close(d, &sv11->chanA); |
1da177e4 | 109 | break; |
52e8a6a2 | 110 | } |
1da177e4 LT |
111 | return err; |
112 | } | |
52e8a6a2 KH |
113 | sv11->chanA.rx_function = hostess_input; |
114 | ||
1da177e4 LT |
115 | /* |
116 | * Go go go | |
117 | */ | |
118 | ||
119 | netif_start_queue(d); | |
120 | return 0; | |
121 | } | |
122 | ||
123 | static int hostess_close(struct net_device *d) | |
124 | { | |
52e8a6a2 | 125 | struct z8530_dev *sv11 = dev_to_sv(d); |
1da177e4 LT |
126 | /* |
127 | * Discard new frames | |
128 | */ | |
52e8a6a2 KH |
129 | sv11->chanA.rx_function = z8530_null_rx; |
130 | ||
131 | hdlc_close(d); | |
1da177e4 | 132 | netif_stop_queue(d); |
52e8a6a2 KH |
133 | |
134 | switch (dma) { | |
1da177e4 | 135 | case 0: |
52e8a6a2 | 136 | z8530_sync_close(d, &sv11->chanA); |
1da177e4 LT |
137 | break; |
138 | case 1: | |
52e8a6a2 | 139 | z8530_sync_dma_close(d, &sv11->chanA); |
1da177e4 LT |
140 | break; |
141 | case 2: | |
52e8a6a2 | 142 | z8530_sync_txdma_close(d, &sv11->chanA); |
1da177e4 LT |
143 | break; |
144 | } | |
145 | return 0; | |
146 | } | |
147 | ||
148 | static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd) | |
149 | { | |
52e8a6a2 KH |
150 | /* struct z8530_dev *sv11=dev_to_sv(d); |
151 | z8530_ioctl(d,&sv11->chanA,ifr,cmd) */ | |
152 | return hdlc_ioctl(d, ifr, cmd); | |
1da177e4 LT |
153 | } |
154 | ||
155 | /* | |
52e8a6a2 | 156 | * Passed network frames, fire them downwind. |
1da177e4 | 157 | */ |
52e8a6a2 | 158 | |
1da177e4 LT |
159 | static int hostess_queue_xmit(struct sk_buff *skb, struct net_device *d) |
160 | { | |
52e8a6a2 | 161 | return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb); |
1da177e4 LT |
162 | } |
163 | ||
52e8a6a2 KH |
164 | static int hostess_attach(struct net_device *dev, unsigned short encoding, |
165 | unsigned short parity) | |
1da177e4 | 166 | { |
52e8a6a2 KH |
167 | if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT) |
168 | return 0; | |
169 | return -EINVAL; | |
1da177e4 LT |
170 | } |
171 | ||
172 | /* | |
173 | * Description block for a Comtrol Hostess SV11 card | |
174 | */ | |
52e8a6a2 KH |
175 | |
176 | static struct z8530_dev *sv11_init(int iobase, int irq) | |
1da177e4 | 177 | { |
52e8a6a2 KH |
178 | struct z8530_dev *sv; |
179 | struct net_device *netdev; | |
1da177e4 LT |
180 | /* |
181 | * Get the needed I/O space | |
182 | */ | |
52e8a6a2 KH |
183 | |
184 | if (!request_region(iobase, 8, "Comtrol SV11")) { | |
185 | printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n", | |
186 | iobase); | |
1da177e4 LT |
187 | return NULL; |
188 | } | |
52e8a6a2 KH |
189 | |
190 | sv = kzalloc(sizeof(struct z8530_dev), GFP_KERNEL); | |
191 | if (!sv) | |
192 | goto err_kzalloc; | |
193 | ||
1da177e4 LT |
194 | /* |
195 | * Stuff in the I/O addressing | |
196 | */ | |
52e8a6a2 KH |
197 | |
198 | sv->active = 0; | |
199 | ||
200 | sv->chanA.ctrlio = iobase + 1; | |
201 | sv->chanA.dataio = iobase + 3; | |
202 | sv->chanB.ctrlio = -1; | |
203 | sv->chanB.dataio = -1; | |
204 | sv->chanA.irqs = &z8530_nop; | |
205 | sv->chanB.irqs = &z8530_nop; | |
206 | ||
207 | outb(0, iobase + 4); /* DMA off */ | |
208 | ||
1da177e4 LT |
209 | /* We want a fast IRQ for this device. Actually we'd like an even faster |
210 | IRQ ;) - This is one driver RtLinux is made for */ | |
52e8a6a2 KH |
211 | |
212 | if (request_irq(irq, &z8530_interrupt, IRQF_DISABLED, | |
213 | "Hostess SV11", sv) < 0) { | |
1da177e4 | 214 | printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq); |
52e8a6a2 | 215 | goto err_irq; |
1da177e4 | 216 | } |
52e8a6a2 KH |
217 | |
218 | sv->irq = irq; | |
219 | sv->chanA.private = sv; | |
220 | sv->chanA.dev = sv; | |
221 | sv->chanB.dev = sv; | |
222 | ||
223 | if (dma) { | |
1da177e4 LT |
224 | /* |
225 | * You can have DMA off or 1 and 3 thats the lot | |
226 | * on the Comtrol. | |
227 | */ | |
52e8a6a2 KH |
228 | sv->chanA.txdma = 3; |
229 | sv->chanA.rxdma = 1; | |
230 | outb(0x03 | 0x08, iobase + 4); /* DMA on */ | |
231 | if (request_dma(sv->chanA.txdma, "Hostess SV/11 (TX)")) | |
232 | goto err_txdma; | |
233 | ||
234 | if (dma == 1) | |
235 | if (request_dma(sv->chanA.rxdma, "Hostess SV/11 (RX)")) | |
236 | goto err_rxdma; | |
1da177e4 LT |
237 | } |
238 | ||
239 | /* Kill our private IRQ line the hostess can end up chattering | |
240 | until the configuration is set */ | |
241 | disable_irq(irq); | |
52e8a6a2 | 242 | |
1da177e4 LT |
243 | /* |
244 | * Begin normal initialise | |
245 | */ | |
52e8a6a2 KH |
246 | |
247 | if (z8530_init(sv)) { | |
1da177e4 LT |
248 | printk(KERN_ERR "Z8530 series device not found.\n"); |
249 | enable_irq(irq); | |
52e8a6a2 | 250 | goto free_dma; |
1da177e4 | 251 | } |
52e8a6a2 KH |
252 | z8530_channel_load(&sv->chanB, z8530_dead_port); |
253 | if (sv->type == Z85C30) | |
254 | z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream); | |
1da177e4 | 255 | else |
52e8a6a2 KH |
256 | z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream_85230); |
257 | ||
1da177e4 | 258 | enable_irq(irq); |
1da177e4 LT |
259 | |
260 | /* | |
261 | * Now we can take the IRQ | |
262 | */ | |
1da177e4 | 263 | |
52e8a6a2 KH |
264 | sv->chanA.netdevice = netdev = alloc_hdlcdev(sv); |
265 | if (!netdev) | |
266 | goto free_dma; | |
1da177e4 | 267 | |
52e8a6a2 KH |
268 | dev_to_hdlc(netdev)->attach = hostess_attach; |
269 | dev_to_hdlc(netdev)->xmit = hostess_queue_xmit; | |
270 | netdev->open = hostess_open; | |
271 | netdev->stop = hostess_close; | |
272 | netdev->do_ioctl = hostess_ioctl; | |
273 | netdev->base_addr = iobase; | |
274 | netdev->irq = irq; | |
275 | ||
276 | if (register_hdlc_device(netdev)) { | |
277 | printk(KERN_ERR "hostess: unable to register HDLC device.\n"); | |
278 | free_netdev(netdev); | |
279 | goto free_dma; | |
1da177e4 | 280 | } |
52e8a6a2 KH |
281 | |
282 | z8530_describe(sv, "I/O", iobase); | |
283 | sv->active = 1; | |
284 | return sv; | |
285 | ||
286 | free_dma: | |
287 | if (dma == 1) | |
288 | free_dma(sv->chanA.rxdma); | |
289 | err_rxdma: | |
290 | if (dma) | |
291 | free_dma(sv->chanA.txdma); | |
292 | err_txdma: | |
293 | free_irq(irq, sv); | |
294 | err_irq: | |
1da177e4 | 295 | kfree(sv); |
52e8a6a2 KH |
296 | err_kzalloc: |
297 | release_region(iobase, 8); | |
1da177e4 LT |
298 | return NULL; |
299 | } | |
300 | ||
52e8a6a2 | 301 | static void sv11_shutdown(struct z8530_dev *dev) |
1da177e4 | 302 | { |
52e8a6a2 KH |
303 | unregister_hdlc_device(dev->chanA.netdevice); |
304 | z8530_shutdown(dev); | |
305 | free_irq(dev->irq, dev); | |
306 | if (dma) { | |
307 | if (dma == 1) | |
308 | free_dma(dev->chanA.rxdma); | |
309 | free_dma(dev->chanA.txdma); | |
1da177e4 | 310 | } |
52e8a6a2 KH |
311 | release_region(dev->chanA.ctrlio - 1, 8); |
312 | free_netdev(dev->chanA.netdevice); | |
1da177e4 LT |
313 | kfree(dev); |
314 | } | |
315 | ||
52e8a6a2 KH |
316 | static int io = 0x200; |
317 | static int irq = 9; | |
1da177e4 LT |
318 | |
319 | module_param(io, int, 0); | |
320 | MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card"); | |
321 | module_param(dma, int, 0); | |
322 | MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX"); | |
323 | module_param(irq, int, 0); | |
324 | MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card"); | |
325 | ||
326 | MODULE_AUTHOR("Alan Cox"); | |
327 | MODULE_LICENSE("GPL"); | |
328 | MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11"); | |
329 | ||
52e8a6a2 | 330 | static struct z8530_dev *sv11_unit; |
1da177e4 LT |
331 | |
332 | int init_module(void) | |
333 | { | |
52e8a6a2 | 334 | if ((sv11_unit = sv11_init(io, irq)) == NULL) |
1da177e4 LT |
335 | return -ENODEV; |
336 | return 0; | |
337 | } | |
338 | ||
339 | void cleanup_module(void) | |
340 | { | |
52e8a6a2 | 341 | if (sv11_unit) |
1da177e4 LT |
342 | sv11_shutdown(sv11_unit); |
343 | } |