1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Sealevel Systems 4021 driver.
5 * (c) Copyright 1999, 2001 Alan Cox
6 * (c) Copyright 2001 Red Hat Inc.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/module.h>
13 #include <linux/kernel.h>
15 #include <linux/net.h>
16 #include <linux/skbuff.h>
17 #include <linux/netdevice.h>
18 #include <linux/if_arp.h>
19 #include <linux/delay.h>
20 #include <linux/hdlc.h>
21 #include <linux/ioport.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
29 #include <asm/byteorder.h>
35 struct z8530_channel *chan;
42 struct slvl_device dev[2];
43 struct z8530_dev board;
48 * Network driver support routines
51 static inline struct slvl_device* dev_to_chan(struct net_device *dev)
53 return (struct slvl_device *)dev_to_hdlc(dev)->priv;
57 * Frame receive. Simple for our card as we do HDLC and there
58 * is no funny garbage involved
61 static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
63 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
64 skb_trim(skb, skb->len - 2);
65 skb->protocol = hdlc_type_trans(skb, c->netdevice);
66 skb_reset_mac_header(skb);
67 skb->dev = c->netdevice;
72 * We've been placed in the UP state
75 static int sealevel_open(struct net_device *d)
77 struct slvl_device *slvl = dev_to_chan(d);
79 int unit = slvl->channel;
87 err = z8530_sync_dma_open(d, slvl->chan);
90 err = z8530_sync_open(d, slvl->chan);
101 z8530_sync_dma_close(d, slvl->chan);
104 z8530_sync_close(d, slvl->chan);
110 slvl->chan->rx_function = sealevel_input;
115 netif_start_queue(d);
119 static int sealevel_close(struct net_device *d)
121 struct slvl_device *slvl = dev_to_chan(d);
122 int unit = slvl->channel;
128 slvl->chan->rx_function = z8530_null_rx;
135 z8530_sync_dma_close(d, slvl->chan);
138 z8530_sync_close(d, slvl->chan);
144 static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
146 /* struct slvl_device *slvl=dev_to_chan(d);
147 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
148 return hdlc_ioctl(d, ifr, cmd);
152 * Passed network frames, fire them downwind.
155 static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb,
156 struct net_device *d)
158 return z8530_queue_xmit(dev_to_chan(d)->chan, skb);
161 static int sealevel_attach(struct net_device *dev, unsigned short encoding,
162 unsigned short parity)
164 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
169 static const struct net_device_ops sealevel_ops = {
170 .ndo_open = sealevel_open,
171 .ndo_stop = sealevel_close,
172 .ndo_start_xmit = hdlc_start_xmit,
173 .ndo_do_ioctl = sealevel_ioctl,
176 static int slvl_setup(struct slvl_device *sv, int iobase, int irq)
178 struct net_device *dev = alloc_hdlcdev(sv);
182 dev_to_hdlc(dev)->attach = sealevel_attach;
183 dev_to_hdlc(dev)->xmit = sealevel_queue_xmit;
184 dev->netdev_ops = &sealevel_ops;
185 dev->base_addr = iobase;
188 if (register_hdlc_device(dev)) {
189 pr_err("unable to register HDLC device\n");
194 sv->chan->netdevice = dev;
200 * Allocate and setup Sealevel board.
203 static __init struct slvl_board *slvl_init(int iobase, int irq,
204 int txdma, int rxdma, int slow)
206 struct z8530_dev *dev;
207 struct slvl_board *b;
210 * Get the needed I/O space
213 if (!request_region(iobase, 8, "Sealevel 4021")) {
214 pr_warn("I/O 0x%X already in use\n", iobase);
218 b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
222 b->dev[0].chan = &b->board.chanA;
223 b->dev[0].channel = 0;
225 b->dev[1].chan = &b->board.chanB;
226 b->dev[1].channel = 1;
231 * Stuff in the I/O addressing
239 * Select 8530 delays for the old board
243 iobase |= Z8530_PORT_SLEEP;
245 dev->chanA.ctrlio = iobase + 1;
246 dev->chanA.dataio = iobase;
247 dev->chanB.ctrlio = iobase + 3;
248 dev->chanB.dataio = iobase + 2;
250 dev->chanA.irqs = &z8530_nop;
251 dev->chanB.irqs = &z8530_nop;
254 * Assert DTR enable DMA
257 outb(3 | (1 << 7), b->iobase + 4);
260 /* We want a fast IRQ for this device. Actually we'd like an even faster
261 IRQ ;) - This is one driver RtLinux is made for */
263 if (request_irq(irq, z8530_interrupt, 0,
264 "SeaLevel", dev) < 0) {
265 pr_warn("IRQ %d already in use\n", irq);
266 goto err_request_irq;
270 dev->chanA.private = &b->dev[0];
271 dev->chanB.private = &b->dev[1];
272 dev->chanA.dev = dev;
273 dev->chanB.dev = dev;
275 dev->chanA.txdma = 3;
276 dev->chanA.rxdma = 1;
277 if (request_dma(dev->chanA.txdma, "SeaLevel (TX)"))
280 if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)"))
286 * Begin normal initialise
289 if (z8530_init(dev) != 0) {
290 pr_err("Z8530 series device not found\n");
294 if (dev->type == Z85C30) {
295 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
296 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
298 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
299 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
303 * Now we can take the IRQ
308 if (slvl_setup(&b->dev[0], iobase, irq))
310 if (slvl_setup(&b->dev[1], iobase, irq))
313 z8530_describe(dev, "I/O", iobase);
318 unregister_hdlc_device(b->dev[0].chan->netdevice);
319 free_netdev(b->dev[0].chan->netdevice);
321 free_dma(dev->chanA.rxdma);
323 free_dma(dev->chanA.txdma);
329 release_region(iobase, 8);
333 static void __exit slvl_shutdown(struct slvl_board *b)
337 z8530_shutdown(&b->board);
339 for (u = 0; u < 2; u++) {
340 struct net_device *d = b->dev[u].chan->netdevice;
341 unregister_hdlc_device(d);
345 free_irq(b->board.irq, &b->board);
346 free_dma(b->board.chanA.rxdma);
347 free_dma(b->board.chanA.txdma);
348 /* DMA off on the card, drop DTR */
350 release_region(b->iobase, 8);
359 static bool slow=false;
361 module_param_hw(io, int, ioport, 0);
362 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
363 module_param_hw(txdma, int, dma, 0);
364 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
365 module_param_hw(rxdma, int, dma, 0);
366 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
367 module_param_hw(irq, int, irq, 0);
368 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
369 module_param(slow, bool, 0);
370 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
372 MODULE_AUTHOR("Alan Cox");
373 MODULE_LICENSE("GPL");
374 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
376 static struct slvl_board *slvl_unit;
378 static int __init slvl_init_module(void)
380 slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
382 return slvl_unit ? 0 : -ENODEV;
385 static void __exit slvl_cleanup_module(void)
388 slvl_shutdown(slvl_unit);
391 module_init(slvl_init_module);
392 module_exit(slvl_cleanup_module);