1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Sealevel Systems 4021 driver.
4 * (c) Copyright 1999, 2001 Alan Cox
5 * (c) Copyright 2001 Red Hat Inc.
6 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/module.h>
12 #include <linux/kernel.h>
14 #include <linux/net.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/if_arp.h>
18 #include <linux/delay.h>
19 #include <linux/hdlc.h>
20 #include <linux/ioport.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
28 #include <asm/byteorder.h>
32 struct z8530_channel *chan;
37 struct slvl_device dev[2];
38 struct z8530_dev board;
42 /* Network driver support routines */
44 static inline struct slvl_device *dev_to_chan(struct net_device *dev)
46 return (struct slvl_device *)dev_to_hdlc(dev)->priv;
49 /* Frame receive. Simple for our card as we do HDLC and there
50 * is no funny garbage involved
53 static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
55 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
56 skb_trim(skb, skb->len - 2);
57 skb->protocol = hdlc_type_trans(skb, c->netdevice);
58 skb_reset_mac_header(skb);
59 skb->dev = c->netdevice;
63 /* We've been placed in the UP state */
65 static int sealevel_open(struct net_device *d)
67 struct slvl_device *slvl = dev_to_chan(d);
69 int unit = slvl->channel;
75 err = z8530_sync_dma_open(d, slvl->chan);
78 err = z8530_sync_open(d, slvl->chan);
89 z8530_sync_dma_close(d, slvl->chan);
92 z8530_sync_close(d, slvl->chan);
98 slvl->chan->rx_function = sealevel_input;
100 netif_start_queue(d);
104 static int sealevel_close(struct net_device *d)
106 struct slvl_device *slvl = dev_to_chan(d);
107 int unit = slvl->channel;
109 /* Discard new frames */
111 slvl->chan->rx_function = z8530_null_rx;
118 z8530_sync_dma_close(d, slvl->chan);
121 z8530_sync_close(d, slvl->chan);
127 /* Passed network frames, fire them downwind. */
129 static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb,
130 struct net_device *d)
132 return z8530_queue_xmit(dev_to_chan(d)->chan, skb);
135 static int sealevel_attach(struct net_device *dev, unsigned short encoding,
136 unsigned short parity)
138 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
143 static const struct net_device_ops sealevel_ops = {
144 .ndo_open = sealevel_open,
145 .ndo_stop = sealevel_close,
146 .ndo_start_xmit = hdlc_start_xmit,
147 .ndo_siocwandev = hdlc_ioctl,
150 static int slvl_setup(struct slvl_device *sv, int iobase, int irq)
152 struct net_device *dev = alloc_hdlcdev(sv);
157 dev_to_hdlc(dev)->attach = sealevel_attach;
158 dev_to_hdlc(dev)->xmit = sealevel_queue_xmit;
159 dev->netdev_ops = &sealevel_ops;
160 dev->base_addr = iobase;
163 if (register_hdlc_device(dev)) {
164 pr_err("unable to register HDLC device\n");
169 sv->chan->netdevice = dev;
173 /* Allocate and setup Sealevel board. */
175 static __init struct slvl_board *slvl_init(int iobase, int irq,
176 int txdma, int rxdma, int slow)
178 struct z8530_dev *dev;
179 struct slvl_board *b;
181 /* Get the needed I/O space */
183 if (!request_region(iobase, 8, "Sealevel 4021")) {
184 pr_warn("I/O 0x%X already in use\n", iobase);
188 b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
192 b->dev[0].chan = &b->board.chanA;
193 b->dev[0].channel = 0;
195 b->dev[1].chan = &b->board.chanB;
196 b->dev[1].channel = 1;
200 /* Stuff in the I/O addressing */
206 /* Select 8530 delays for the old board */
209 iobase |= Z8530_PORT_SLEEP;
211 dev->chanA.ctrlio = iobase + 1;
212 dev->chanA.dataio = iobase;
213 dev->chanB.ctrlio = iobase + 3;
214 dev->chanB.dataio = iobase + 2;
216 dev->chanA.irqs = &z8530_nop;
217 dev->chanB.irqs = &z8530_nop;
219 /* Assert DTR enable DMA */
221 outb(3 | (1 << 7), b->iobase + 4);
223 /* We want a fast IRQ for this device. Actually we'd like an even faster
224 * IRQ ;) - This is one driver RtLinux is made for
227 if (request_irq(irq, z8530_interrupt, 0,
228 "SeaLevel", dev) < 0) {
229 pr_warn("IRQ %d already in use\n", irq);
230 goto err_request_irq;
234 dev->chanA.private = &b->dev[0];
235 dev->chanB.private = &b->dev[1];
236 dev->chanA.dev = dev;
237 dev->chanB.dev = dev;
239 dev->chanA.txdma = 3;
240 dev->chanA.rxdma = 1;
241 if (request_dma(dev->chanA.txdma, "SeaLevel (TX)"))
244 if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)"))
249 /* Begin normal initialise */
251 if (z8530_init(dev) != 0) {
252 pr_err("Z8530 series device not found\n");
256 if (dev->type == Z85C30) {
257 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
258 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
260 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
261 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
264 /* Now we can take the IRQ */
268 if (slvl_setup(&b->dev[0], iobase, irq))
270 if (slvl_setup(&b->dev[1], iobase, irq))
273 z8530_describe(dev, "I/O", iobase);
278 unregister_hdlc_device(b->dev[0].chan->netdevice);
279 free_netdev(b->dev[0].chan->netdevice);
281 free_dma(dev->chanA.rxdma);
283 free_dma(dev->chanA.txdma);
289 release_region(iobase, 8);
293 static void __exit slvl_shutdown(struct slvl_board *b)
297 z8530_shutdown(&b->board);
299 for (u = 0; u < 2; u++) {
300 struct net_device *d = b->dev[u].chan->netdevice;
302 unregister_hdlc_device(d);
306 free_irq(b->board.irq, &b->board);
307 free_dma(b->board.chanA.rxdma);
308 free_dma(b->board.chanA.txdma);
309 /* DMA off on the card, drop DTR */
311 release_region(b->iobase, 8);
315 static int io = 0x238;
316 static int txdma = 1;
317 static int rxdma = 3;
321 module_param_hw(io, int, ioport, 0);
322 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
323 module_param_hw(txdma, int, dma, 0);
324 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
325 module_param_hw(rxdma, int, dma, 0);
326 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
327 module_param_hw(irq, int, irq, 0);
328 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
329 module_param(slow, bool, 0);
330 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
332 MODULE_AUTHOR("Alan Cox");
333 MODULE_LICENSE("GPL");
334 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
336 static struct slvl_board *slvl_unit;
338 static int __init slvl_init_module(void)
340 slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
342 return slvl_unit ? 0 : -ENODEV;
345 static void __exit slvl_cleanup_module(void)
348 slvl_shutdown(slvl_unit);
351 module_init(slvl_init_module);
352 module_exit(slvl_cleanup_module);