drivers/net: request_irq - Remove unnecessary leading & from second arg
[deliverable/linux.git] / drivers / net / wan / sealevel.c
CommitLineData
1da177e4
LT
1/*
2 * Sealevel Systems 4021 driver.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * (c) Copyright 1999, 2001 Alan Cox
10 * (c) Copyright 2001 Red Hat Inc.
52e8a6a2 11 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
1da177e4
LT
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/mm.h>
18#include <linux/net.h>
19#include <linux/skbuff.h>
20#include <linux/netdevice.h>
21#include <linux/if_arp.h>
22#include <linux/delay.h>
52e8a6a2 23#include <linux/hdlc.h>
1da177e4
LT
24#include <linux/ioport.h>
25#include <linux/init.h>
26#include <net/arp.h>
27
82729971 28#include <asm/irq.h>
1da177e4
LT
29#include <asm/io.h>
30#include <asm/dma.h>
31#include <asm/byteorder.h>
1da177e4
LT
32#include "z85230.h"
33
34
35struct slvl_device
36{
1da177e4 37 struct z8530_channel *chan;
1da177e4
LT
38 int channel;
39};
40
41
42struct slvl_board
43{
52e8a6a2 44 struct slvl_device dev[2];
1da177e4
LT
45 struct z8530_dev board;
46 int iobase;
47};
48
49/*
50 * Network driver support routines
51 */
52
52e8a6a2
KH
53static inline struct slvl_device* dev_to_chan(struct net_device *dev)
54{
55 return (struct slvl_device *)dev_to_hdlc(dev)->priv;
56}
57
1da177e4 58/*
52e8a6a2 59 * Frame receive. Simple for our card as we do HDLC and there
1da177e4
LT
60 * is no funny garbage involved
61 */
52e8a6a2 62
1da177e4
LT
63static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
64{
65 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
52e8a6a2
KH
66 skb_trim(skb, skb->len - 2);
67 skb->protocol = hdlc_type_trans(skb, c->netdevice);
98e399f8 68 skb_reset_mac_header(skb);
52e8a6a2 69 skb->dev = c->netdevice;
1da177e4 70 netif_rx(skb);
1da177e4 71}
52e8a6a2 72
1da177e4
LT
73/*
74 * We've been placed in the UP state
52e8a6a2
KH
75 */
76
1da177e4
LT
77static int sealevel_open(struct net_device *d)
78{
52e8a6a2 79 struct slvl_device *slvl = dev_to_chan(d);
1da177e4
LT
80 int err = -1;
81 int unit = slvl->channel;
52e8a6a2 82
1da177e4 83 /*
52e8a6a2 84 * Link layer up.
1da177e4
LT
85 */
86
52e8a6a2 87 switch (unit)
1da177e4
LT
88 {
89 case 0:
52e8a6a2 90 err = z8530_sync_dma_open(d, slvl->chan);
1da177e4
LT
91 break;
92 case 1:
52e8a6a2 93 err = z8530_sync_open(d, slvl->chan);
1da177e4
LT
94 break;
95 }
52e8a6a2
KH
96
97 if (err)
1da177e4 98 return err;
52e8a6a2
KH
99
100 err = hdlc_open(d);
101 if (err) {
102 switch (unit) {
1da177e4
LT
103 case 0:
104 z8530_sync_dma_close(d, slvl->chan);
105 break;
106 case 1:
107 z8530_sync_close(d, slvl->chan);
108 break;
52e8a6a2 109 }
1da177e4
LT
110 return err;
111 }
52e8a6a2
KH
112
113 slvl->chan->rx_function = sealevel_input;
114
1da177e4
LT
115 /*
116 * Go go go
117 */
118 netif_start_queue(d);
119 return 0;
120}
121
122static int sealevel_close(struct net_device *d)
123{
52e8a6a2 124 struct slvl_device *slvl = dev_to_chan(d);
1da177e4 125 int unit = slvl->channel;
52e8a6a2 126
1da177e4
LT
127 /*
128 * Discard new frames
129 */
1da177e4 130
52e8a6a2
KH
131 slvl->chan->rx_function = z8530_null_rx;
132
133 hdlc_close(d);
1da177e4 134 netif_stop_queue(d);
52e8a6a2
KH
135
136 switch (unit)
1da177e4
LT
137 {
138 case 0:
139 z8530_sync_dma_close(d, slvl->chan);
140 break;
141 case 1:
142 z8530_sync_close(d, slvl->chan);
143 break;
144 }
145 return 0;
146}
147
148static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
149{
52e8a6a2 150 /* struct slvl_device *slvl=dev_to_chan(d);
1da177e4 151 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
52e8a6a2 152 return hdlc_ioctl(d, ifr, cmd);
1da177e4
LT
153}
154
155/*
52e8a6a2 156 * Passed network frames, fire them downwind.
1da177e4 157 */
52e8a6a2 158
d71a6749
SH
159static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb,
160 struct net_device *d)
1da177e4 161{
52e8a6a2 162 return z8530_queue_xmit(dev_to_chan(d)->chan, skb);
1da177e4
LT
163}
164
52e8a6a2
KH
165static int sealevel_attach(struct net_device *dev, unsigned short encoding,
166 unsigned short parity)
1da177e4 167{
52e8a6a2
KH
168 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
169 return 0;
170 return -EINVAL;
1da177e4
LT
171}
172
991990a1
KH
173static const struct net_device_ops sealevel_ops = {
174 .ndo_open = sealevel_open,
175 .ndo_stop = sealevel_close,
176 .ndo_change_mtu = hdlc_change_mtu,
177 .ndo_start_xmit = hdlc_start_xmit,
178 .ndo_do_ioctl = sealevel_ioctl,
179};
180
52e8a6a2 181static int slvl_setup(struct slvl_device *sv, int iobase, int irq)
1da177e4 182{
52e8a6a2
KH
183 struct net_device *dev = alloc_hdlcdev(sv);
184 if (!dev)
185 return -1;
186
187 dev_to_hdlc(dev)->attach = sealevel_attach;
188 dev_to_hdlc(dev)->xmit = sealevel_queue_xmit;
991990a1 189 dev->netdev_ops = &sealevel_ops;
52e8a6a2
KH
190 dev->base_addr = iobase;
191 dev->irq = irq;
192
193 if (register_hdlc_device(dev)) {
194 printk(KERN_ERR "sealevel: unable to register HDLC device\n");
195 free_netdev(dev);
196 return -1;
1da177e4 197 }
1da177e4 198
52e8a6a2 199 sv->chan->netdevice = dev;
1da177e4
LT
200 return 0;
201}
202
1da177e4
LT
203
204/*
205 * Allocate and setup Sealevel board.
206 */
52e8a6a2
KH
207
208static __init struct slvl_board *slvl_init(int iobase, int irq,
1da177e4
LT
209 int txdma, int rxdma, int slow)
210{
211 struct z8530_dev *dev;
212 struct slvl_board *b;
52e8a6a2 213
1da177e4
LT
214 /*
215 * Get the needed I/O space
216 */
217
52e8a6a2
KH
218 if (!request_region(iobase, 8, "Sealevel 4021")) {
219 printk(KERN_WARNING "sealevel: I/O 0x%X already in use.\n",
220 iobase);
1da177e4
LT
221 return NULL;
222 }
1da177e4 223
52e8a6a2
KH
224 b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
225 if (!b)
226 goto err_kzalloc;
1da177e4 227
52e8a6a2
KH
228 b->dev[0].chan = &b->board.chanA;
229 b->dev[0].channel = 0;
1da177e4 230
52e8a6a2
KH
231 b->dev[1].chan = &b->board.chanB;
232 b->dev[1].channel = 1;
1da177e4
LT
233
234 dev = &b->board;
52e8a6a2 235
1da177e4
LT
236 /*
237 * Stuff in the I/O addressing
238 */
52e8a6a2 239
1da177e4
LT
240 dev->active = 0;
241
242 b->iobase = iobase;
52e8a6a2 243
1da177e4
LT
244 /*
245 * Select 8530 delays for the old board
246 */
52e8a6a2
KH
247
248 if (slow)
1da177e4 249 iobase |= Z8530_PORT_SLEEP;
52e8a6a2
KH
250
251 dev->chanA.ctrlio = iobase + 1;
252 dev->chanA.dataio = iobase;
253 dev->chanB.ctrlio = iobase + 3;
254 dev->chanB.dataio = iobase + 2;
255
256 dev->chanA.irqs = &z8530_nop;
257 dev->chanB.irqs = &z8530_nop;
258
1da177e4
LT
259 /*
260 * Assert DTR enable DMA
261 */
52e8a6a2
KH
262
263 outb(3 | (1 << 7), b->iobase + 4);
264
1da177e4
LT
265
266 /* We want a fast IRQ for this device. Actually we'd like an even faster
267 IRQ ;) - This is one driver RtLinux is made for */
52e8a6a2 268
a0607fd3 269 if (request_irq(irq, z8530_interrupt, IRQF_DISABLED,
52e8a6a2 270 "SeaLevel", dev) < 0) {
1da177e4 271 printk(KERN_WARNING "sealevel: IRQ %d already in use.\n", irq);
52e8a6a2 272 goto err_request_irq;
1da177e4 273 }
52e8a6a2
KH
274
275 dev->irq = irq;
276 dev->chanA.private = &b->dev[0];
277 dev->chanB.private = &b->dev[1];
278 dev->chanA.dev = dev;
279 dev->chanB.dev = dev;
280
281 dev->chanA.txdma = 3;
282 dev->chanA.rxdma = 1;
283 if (request_dma(dev->chanA.txdma, "SeaLevel (TX)"))
284 goto err_dma_tx;
285
286 if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)"))
287 goto err_dma_rx;
288
1da177e4 289 disable_irq(irq);
52e8a6a2 290
1da177e4
LT
291 /*
292 * Begin normal initialise
293 */
52e8a6a2
KH
294
295 if (z8530_init(dev) != 0) {
1da177e4
LT
296 printk(KERN_ERR "Z8530 series device not found.\n");
297 enable_irq(irq);
52e8a6a2 298 goto free_hw;
1da177e4 299 }
52e8a6a2 300 if (dev->type == Z85C30) {
1da177e4
LT
301 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
302 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
52e8a6a2 303 } else {
1da177e4
LT
304 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
305 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
306 }
307
308 /*
309 * Now we can take the IRQ
310 */
52e8a6a2 311
1da177e4
LT
312 enable_irq(irq);
313
52e8a6a2
KH
314 if (slvl_setup(&b->dev[0], iobase, irq))
315 goto free_hw;
316 if (slvl_setup(&b->dev[1], iobase, irq))
317 goto free_netdev0;
1da177e4
LT
318
319 z8530_describe(dev, "I/O", iobase);
52e8a6a2 320 dev->active = 1;
1da177e4
LT
321 return b;
322
52e8a6a2
KH
323free_netdev0:
324 unregister_hdlc_device(b->dev[0].chan->netdevice);
325 free_netdev(b->dev[0].chan->netdevice);
326free_hw:
1da177e4 327 free_dma(dev->chanA.rxdma);
52e8a6a2 328err_dma_rx:
1da177e4 329 free_dma(dev->chanA.txdma);
52e8a6a2 330err_dma_tx:
1da177e4 331 free_irq(irq, dev);
52e8a6a2 332err_request_irq:
1da177e4 333 kfree(b);
52e8a6a2
KH
334err_kzalloc:
335 release_region(iobase, 8);
1da177e4
LT
336 return NULL;
337}
338
339static void __exit slvl_shutdown(struct slvl_board *b)
340{
341 int u;
342
343 z8530_shutdown(&b->board);
52e8a6a2
KH
344
345 for (u = 0; u < 2; u++)
1da177e4 346 {
52e8a6a2
KH
347 struct net_device *d = b->dev[u].chan->netdevice;
348 unregister_hdlc_device(d);
1da177e4
LT
349 free_netdev(d);
350 }
52e8a6a2 351
1da177e4
LT
352 free_irq(b->board.irq, &b->board);
353 free_dma(b->board.chanA.rxdma);
354 free_dma(b->board.chanA.txdma);
355 /* DMA off on the card, drop DTR */
356 outb(0, b->iobase);
357 release_region(b->iobase, 8);
358 kfree(b);
359}
360
361
362static int io=0x238;
363static int txdma=1;
364static int rxdma=3;
365static int irq=5;
366static int slow=0;
367
368module_param(io, int, 0);
369MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
370module_param(txdma, int, 0);
371MODULE_PARM_DESC(txdma, "Transmit DMA channel");
372module_param(rxdma, int, 0);
373MODULE_PARM_DESC(rxdma, "Receive DMA channel");
374module_param(irq, int, 0);
375MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
376module_param(slow, bool, 0);
377MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
378
379MODULE_AUTHOR("Alan Cox");
380MODULE_LICENSE("GPL");
381MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
382
383static struct slvl_board *slvl_unit;
384
385static int __init slvl_init_module(void)
386{
1da177e4
LT
387 slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
388
389 return slvl_unit ? 0 : -ENODEV;
390}
391
392static void __exit slvl_cleanup_module(void)
393{
394 if(slvl_unit)
395 slvl_shutdown(slvl_unit);
396}
397
398module_init(slvl_init_module);
399module_exit(slvl_cleanup_module);
This page took 0.742453 seconds and 5 git commands to generate.