2 * Sealevel Systems 4021 driver.
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.
9 * (c) Copyright 1999, 2001 Alan Cox
10 * (c) Copyright 2001 Red Hat Inc.
11 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
15 #include <linux/module.h>
16 #include <linux/kernel.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>
23 #include <linux/hdlc.h>
24 #include <linux/ioport.h>
25 #include <linux/init.h>
31 #include <asm/byteorder.h>
37 struct z8530_channel
*chan
;
44 struct slvl_device dev
[2];
45 struct z8530_dev board
;
50 * Network driver support routines
53 static inline struct slvl_device
* dev_to_chan(struct net_device
*dev
)
55 return (struct slvl_device
*)dev_to_hdlc(dev
)->priv
;
59 * Frame receive. Simple for our card as we do HDLC and there
60 * is no funny garbage involved
63 static void sealevel_input(struct z8530_channel
*c
, struct sk_buff
*skb
)
65 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
66 skb_trim(skb
, skb
->len
- 2);
67 skb
->protocol
= hdlc_type_trans(skb
, c
->netdevice
);
68 skb_reset_mac_header(skb
);
69 skb
->dev
= c
->netdevice
;
74 * We've been placed in the UP state
77 static int sealevel_open(struct net_device
*d
)
79 struct slvl_device
*slvl
= dev_to_chan(d
);
81 int unit
= slvl
->channel
;
90 err
= z8530_sync_dma_open(d
, slvl
->chan
);
93 err
= z8530_sync_open(d
, slvl
->chan
);
104 z8530_sync_dma_close(d
, slvl
->chan
);
107 z8530_sync_close(d
, slvl
->chan
);
113 slvl
->chan
->rx_function
= sealevel_input
;
118 netif_start_queue(d
);
122 static int sealevel_close(struct net_device
*d
)
124 struct slvl_device
*slvl
= dev_to_chan(d
);
125 int unit
= slvl
->channel
;
131 slvl
->chan
->rx_function
= z8530_null_rx
;
139 z8530_sync_dma_close(d
, slvl
->chan
);
142 z8530_sync_close(d
, slvl
->chan
);
148 static int sealevel_ioctl(struct net_device
*d
, struct ifreq
*ifr
, int cmd
)
150 /* struct slvl_device *slvl=dev_to_chan(d);
151 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
152 return hdlc_ioctl(d
, ifr
, cmd
);
156 * Passed network frames, fire them downwind.
159 static netdev_tx_t
sealevel_queue_xmit(struct sk_buff
*skb
,
160 struct net_device
*d
)
162 return z8530_queue_xmit(dev_to_chan(d
)->chan
, skb
);
165 static int sealevel_attach(struct net_device
*dev
, unsigned short encoding
,
166 unsigned short parity
)
168 if (encoding
== ENCODING_NRZ
&& parity
== PARITY_CRC16_PR1_CCITT
)
173 static 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
,
181 static int slvl_setup(struct slvl_device
*sv
, int iobase
, int irq
)
183 struct net_device
*dev
= alloc_hdlcdev(sv
);
187 dev_to_hdlc(dev
)->attach
= sealevel_attach
;
188 dev_to_hdlc(dev
)->xmit
= sealevel_queue_xmit
;
189 dev
->netdev_ops
= &sealevel_ops
;
190 dev
->base_addr
= iobase
;
193 if (register_hdlc_device(dev
)) {
194 printk(KERN_ERR
"sealevel: unable to register HDLC device\n");
199 sv
->chan
->netdevice
= dev
;
205 * Allocate and setup Sealevel board.
208 static __init
struct slvl_board
*slvl_init(int iobase
, int irq
,
209 int txdma
, int rxdma
, int slow
)
211 struct z8530_dev
*dev
;
212 struct slvl_board
*b
;
215 * Get the needed I/O space
218 if (!request_region(iobase
, 8, "Sealevel 4021")) {
219 printk(KERN_WARNING
"sealevel: I/O 0x%X already in use.\n",
224 b
= kzalloc(sizeof(struct slvl_board
), GFP_KERNEL
);
228 b
->dev
[0].chan
= &b
->board
.chanA
;
229 b
->dev
[0].channel
= 0;
231 b
->dev
[1].chan
= &b
->board
.chanB
;
232 b
->dev
[1].channel
= 1;
237 * Stuff in the I/O addressing
245 * Select 8530 delays for the old board
249 iobase
|= Z8530_PORT_SLEEP
;
251 dev
->chanA
.ctrlio
= iobase
+ 1;
252 dev
->chanA
.dataio
= iobase
;
253 dev
->chanB
.ctrlio
= iobase
+ 3;
254 dev
->chanB
.dataio
= iobase
+ 2;
256 dev
->chanA
.irqs
= &z8530_nop
;
257 dev
->chanB
.irqs
= &z8530_nop
;
260 * Assert DTR enable DMA
263 outb(3 | (1 << 7), b
->iobase
+ 4);
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 */
269 if (request_irq(irq
, &z8530_interrupt
, IRQF_DISABLED
,
270 "SeaLevel", dev
) < 0) {
271 printk(KERN_WARNING
"sealevel: IRQ %d already in use.\n", irq
);
272 goto err_request_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
;
281 dev
->chanA
.txdma
= 3;
282 dev
->chanA
.rxdma
= 1;
283 if (request_dma(dev
->chanA
.txdma
, "SeaLevel (TX)"))
286 if (request_dma(dev
->chanA
.rxdma
, "SeaLevel (RX)"))
292 * Begin normal initialise
295 if (z8530_init(dev
) != 0) {
296 printk(KERN_ERR
"Z8530 series device not found.\n");
300 if (dev
->type
== Z85C30
) {
301 z8530_channel_load(&dev
->chanA
, z8530_hdlc_kilostream
);
302 z8530_channel_load(&dev
->chanB
, z8530_hdlc_kilostream
);
304 z8530_channel_load(&dev
->chanA
, z8530_hdlc_kilostream_85230
);
305 z8530_channel_load(&dev
->chanB
, z8530_hdlc_kilostream_85230
);
309 * Now we can take the IRQ
314 if (slvl_setup(&b
->dev
[0], iobase
, irq
))
316 if (slvl_setup(&b
->dev
[1], iobase
, irq
))
319 z8530_describe(dev
, "I/O", iobase
);
324 unregister_hdlc_device(b
->dev
[0].chan
->netdevice
);
325 free_netdev(b
->dev
[0].chan
->netdevice
);
327 free_dma(dev
->chanA
.rxdma
);
329 free_dma(dev
->chanA
.txdma
);
335 release_region(iobase
, 8);
339 static void __exit
slvl_shutdown(struct slvl_board
*b
)
343 z8530_shutdown(&b
->board
);
345 for (u
= 0; u
< 2; u
++)
347 struct net_device
*d
= b
->dev
[u
].chan
->netdevice
;
348 unregister_hdlc_device(d
);
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 */
357 release_region(b
->iobase
, 8);
368 module_param(io
, int, 0);
369 MODULE_PARM_DESC(io
, "The I/O base of the Sealevel card");
370 module_param(txdma
, int, 0);
371 MODULE_PARM_DESC(txdma
, "Transmit DMA channel");
372 module_param(rxdma
, int, 0);
373 MODULE_PARM_DESC(rxdma
, "Receive DMA channel");
374 module_param(irq
, int, 0);
375 MODULE_PARM_DESC(irq
, "The interrupt line setting for the SeaLevel card");
376 module_param(slow
, bool, 0);
377 MODULE_PARM_DESC(slow
, "Set this for an older Sealevel card such as the 4012");
379 MODULE_AUTHOR("Alan Cox");
380 MODULE_LICENSE("GPL");
381 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
383 static struct slvl_board
*slvl_unit
;
385 static int __init
slvl_init_module(void)
387 slvl_unit
= slvl_init(io
, irq
, txdma
, rxdma
, slow
);
389 return slvl_unit
? 0 : -ENODEV
;
392 static void __exit
slvl_cleanup_module(void)
395 slvl_shutdown(slvl_unit
);
398 module_init(slvl_init_module
);
399 module_exit(slvl_cleanup_module
);