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.
7 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
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>
34 struct z8530_channel *chan;
40 struct slvl_device dev[2];
41 struct z8530_dev board;
46 * Network driver support routines
49 static inline struct slvl_device* dev_to_chan(struct net_device *dev)
51 return (struct slvl_device *)dev_to_hdlc(dev)->priv;
55 * Frame receive. Simple for our card as we do HDLC and there
56 * is no funny garbage involved
59 static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
61 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
62 skb_trim(skb, skb->len - 2);
63 skb->protocol = hdlc_type_trans(skb, c->netdevice);
64 skb_reset_mac_header(skb);
65 skb->dev = c->netdevice;
70 * We've been placed in the UP state
73 static int sealevel_open(struct net_device *d)
75 struct slvl_device *slvl = dev_to_chan(d);
77 int unit = slvl->channel;
85 err = z8530_sync_dma_open(d, slvl->chan);
88 err = z8530_sync_open(d, slvl->chan);
99 z8530_sync_dma_close(d, slvl->chan);
102 z8530_sync_close(d, slvl->chan);
108 slvl->chan->rx_function = sealevel_input;
113 netif_start_queue(d);
117 static int sealevel_close(struct net_device *d)
119 struct slvl_device *slvl = dev_to_chan(d);
120 int unit = slvl->channel;
126 slvl->chan->rx_function = z8530_null_rx;
133 z8530_sync_dma_close(d, slvl->chan);
136 z8530_sync_close(d, slvl->chan);
142 static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
144 /* struct slvl_device *slvl=dev_to_chan(d);
145 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
146 return hdlc_ioctl(d, ifr, cmd);
150 * Passed network frames, fire them downwind.
153 static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb,
154 struct net_device *d)
156 return z8530_queue_xmit(dev_to_chan(d)->chan, skb);
159 static int sealevel_attach(struct net_device *dev, unsigned short encoding,
160 unsigned short parity)
162 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
167 static const struct net_device_ops sealevel_ops = {
168 .ndo_open = sealevel_open,
169 .ndo_stop = sealevel_close,
170 .ndo_start_xmit = hdlc_start_xmit,
171 .ndo_do_ioctl = sealevel_ioctl,
174 static int slvl_setup(struct slvl_device *sv, int iobase, int irq)
176 struct net_device *dev = alloc_hdlcdev(sv);
180 dev_to_hdlc(dev)->attach = sealevel_attach;
181 dev_to_hdlc(dev)->xmit = sealevel_queue_xmit;
182 dev->netdev_ops = &sealevel_ops;
183 dev->base_addr = iobase;
186 if (register_hdlc_device(dev)) {
187 pr_err("unable to register HDLC device\n");
192 sv->chan->netdevice = dev;
197 * Allocate and setup Sealevel board.
200 static __init struct slvl_board *slvl_init(int iobase, int irq,
201 int txdma, int rxdma, int slow)
203 struct z8530_dev *dev;
204 struct slvl_board *b;
207 * Get the needed I/O space
210 if (!request_region(iobase, 8, "Sealevel 4021")) {
211 pr_warn("I/O 0x%X already in use\n", iobase);
215 b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
219 b->dev[0].chan = &b->board.chanA;
220 b->dev[0].channel = 0;
222 b->dev[1].chan = &b->board.chanB;
223 b->dev[1].channel = 1;
228 * Stuff in the I/O addressing
236 * Select 8530 delays for the old board
240 iobase |= Z8530_PORT_SLEEP;
242 dev->chanA.ctrlio = iobase + 1;
243 dev->chanA.dataio = iobase;
244 dev->chanB.ctrlio = iobase + 3;
245 dev->chanB.dataio = iobase + 2;
247 dev->chanA.irqs = &z8530_nop;
248 dev->chanB.irqs = &z8530_nop;
251 * Assert DTR enable DMA
254 outb(3 | (1 << 7), b->iobase + 4);
256 /* We want a fast IRQ for this device. Actually we'd like an even faster
257 IRQ ;) - This is one driver RtLinux is made for */
259 if (request_irq(irq, z8530_interrupt, 0,
260 "SeaLevel", dev) < 0) {
261 pr_warn("IRQ %d already in use\n", irq);
262 goto err_request_irq;
266 dev->chanA.private = &b->dev[0];
267 dev->chanB.private = &b->dev[1];
268 dev->chanA.dev = dev;
269 dev->chanB.dev = dev;
271 dev->chanA.txdma = 3;
272 dev->chanA.rxdma = 1;
273 if (request_dma(dev->chanA.txdma, "SeaLevel (TX)"))
276 if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)"))
282 * Begin normal initialise
285 if (z8530_init(dev) != 0) {
286 pr_err("Z8530 series device not found\n");
290 if (dev->type == Z85C30) {
291 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
292 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
294 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
295 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
299 * Now we can take the IRQ
304 if (slvl_setup(&b->dev[0], iobase, irq))
306 if (slvl_setup(&b->dev[1], iobase, irq))
309 z8530_describe(dev, "I/O", iobase);
314 unregister_hdlc_device(b->dev[0].chan->netdevice);
315 free_netdev(b->dev[0].chan->netdevice);
317 free_dma(dev->chanA.rxdma);
319 free_dma(dev->chanA.txdma);
325 release_region(iobase, 8);
329 static void __exit slvl_shutdown(struct slvl_board *b)
333 z8530_shutdown(&b->board);
335 for (u = 0; u < 2; u++) {
336 struct net_device *d = b->dev[u].chan->netdevice;
337 unregister_hdlc_device(d);
341 free_irq(b->board.irq, &b->board);
342 free_dma(b->board.chanA.rxdma);
343 free_dma(b->board.chanA.txdma);
344 /* DMA off on the card, drop DTR */
346 release_region(b->iobase, 8);
354 static bool slow=false;
356 module_param_hw(io, int, ioport, 0);
357 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
358 module_param_hw(txdma, int, dma, 0);
359 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
360 module_param_hw(rxdma, int, dma, 0);
361 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
362 module_param_hw(irq, int, irq, 0);
363 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
364 module_param(slow, bool, 0);
365 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
367 MODULE_AUTHOR("Alan Cox");
368 MODULE_LICENSE("GPL");
369 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
371 static struct slvl_board *slvl_unit;
373 static int __init slvl_init_module(void)
375 slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
377 return slvl_unit ? 0 : -ENODEV;
380 static void __exit slvl_cleanup_module(void)
383 slvl_shutdown(slvl_unit);
386 module_init(slvl_init_module);
387 module_exit(slvl_cleanup_module);