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.
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 static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
129 /* struct slvl_device *slvl=dev_to_chan(d);
130 * z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd)
132 return hdlc_ioctl(d, ifr, cmd);
135 /* Passed network frames, fire them downwind. */
137 static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb,
138 struct net_device *d)
140 return z8530_queue_xmit(dev_to_chan(d)->chan, skb);
143 static int sealevel_attach(struct net_device *dev, unsigned short encoding,
144 unsigned short parity)
146 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
151 static const struct net_device_ops sealevel_ops = {
152 .ndo_open = sealevel_open,
153 .ndo_stop = sealevel_close,
154 .ndo_start_xmit = hdlc_start_xmit,
155 .ndo_do_ioctl = sealevel_ioctl,
158 static int slvl_setup(struct slvl_device *sv, int iobase, int irq)
160 struct net_device *dev = alloc_hdlcdev(sv);
165 dev_to_hdlc(dev)->attach = sealevel_attach;
166 dev_to_hdlc(dev)->xmit = sealevel_queue_xmit;
167 dev->netdev_ops = &sealevel_ops;
168 dev->base_addr = iobase;
171 if (register_hdlc_device(dev)) {
172 pr_err("unable to register HDLC device\n");
177 sv->chan->netdevice = dev;
181 /* Allocate and setup Sealevel board. */
183 static __init struct slvl_board *slvl_init(int iobase, int irq,
184 int txdma, int rxdma, int slow)
186 struct z8530_dev *dev;
187 struct slvl_board *b;
189 /* Get the needed I/O space */
191 if (!request_region(iobase, 8, "Sealevel 4021")) {
192 pr_warn("I/O 0x%X already in use\n", iobase);
196 b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
200 b->dev[0].chan = &b->board.chanA;
201 b->dev[0].channel = 0;
203 b->dev[1].chan = &b->board.chanB;
204 b->dev[1].channel = 1;
208 /* Stuff in the I/O addressing */
214 /* Select 8530 delays for the old board */
217 iobase |= Z8530_PORT_SLEEP;
219 dev->chanA.ctrlio = iobase + 1;
220 dev->chanA.dataio = iobase;
221 dev->chanB.ctrlio = iobase + 3;
222 dev->chanB.dataio = iobase + 2;
224 dev->chanA.irqs = &z8530_nop;
225 dev->chanB.irqs = &z8530_nop;
227 /* Assert DTR enable DMA */
229 outb(3 | (1 << 7), b->iobase + 4);
231 /* We want a fast IRQ for this device. Actually we'd like an even faster
232 * IRQ ;) - This is one driver RtLinux is made for
235 if (request_irq(irq, z8530_interrupt, 0,
236 "SeaLevel", dev) < 0) {
237 pr_warn("IRQ %d already in use\n", irq);
238 goto err_request_irq;
242 dev->chanA.private = &b->dev[0];
243 dev->chanB.private = &b->dev[1];
244 dev->chanA.dev = dev;
245 dev->chanB.dev = dev;
247 dev->chanA.txdma = 3;
248 dev->chanA.rxdma = 1;
249 if (request_dma(dev->chanA.txdma, "SeaLevel (TX)"))
252 if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)"))
257 /* Begin normal initialise */
259 if (z8530_init(dev) != 0) {
260 pr_err("Z8530 series device not found\n");
264 if (dev->type == Z85C30) {
265 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
266 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
268 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
269 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
272 /* Now we can take the IRQ */
276 if (slvl_setup(&b->dev[0], iobase, irq))
278 if (slvl_setup(&b->dev[1], iobase, irq))
281 z8530_describe(dev, "I/O", iobase);
286 unregister_hdlc_device(b->dev[0].chan->netdevice);
287 free_netdev(b->dev[0].chan->netdevice);
289 free_dma(dev->chanA.rxdma);
291 free_dma(dev->chanA.txdma);
297 release_region(iobase, 8);
301 static void __exit slvl_shutdown(struct slvl_board *b)
305 z8530_shutdown(&b->board);
307 for (u = 0; u < 2; u++) {
308 struct net_device *d = b->dev[u].chan->netdevice;
310 unregister_hdlc_device(d);
314 free_irq(b->board.irq, &b->board);
315 free_dma(b->board.chanA.rxdma);
316 free_dma(b->board.chanA.txdma);
317 /* DMA off on the card, drop DTR */
319 release_region(b->iobase, 8);
323 static int io = 0x238;
324 static int txdma = 1;
325 static int rxdma = 3;
329 module_param_hw(io, int, ioport, 0);
330 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
331 module_param_hw(txdma, int, dma, 0);
332 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
333 module_param_hw(rxdma, int, dma, 0);
334 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
335 module_param_hw(irq, int, irq, 0);
336 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
337 module_param(slow, bool, 0);
338 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
340 MODULE_AUTHOR("Alan Cox");
341 MODULE_LICENSE("GPL");
342 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
344 static struct slvl_board *slvl_unit;
346 static int __init slvl_init_module(void)
348 slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
350 return slvl_unit ? 0 : -ENODEV;
353 static void __exit slvl_cleanup_module(void)
356 slvl_shutdown(slvl_unit);
359 module_init(slvl_init_module);
360 module_exit(slvl_cleanup_module);