1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Comtrol SV11 card driver
4 * This is a slightly odd Z85230 synchronous driver. All you need to
9 * It supports DMA using two DMA channels in SYNC mode. The driver doesn't
10 * use these facilities
12 * The control port is at io+1, the data at io+3 and turning off the DMA
13 * is done by writing 0 to io+4
15 * The hardware does the bus handling to avoid the need for delays between
16 * touching control registers.
18 * Port B isn't wired (why - beats me)
20 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/module.h>
26 #include <linux/kernel.h>
28 #include <linux/net.h>
29 #include <linux/skbuff.h>
30 #include <linux/netdevice.h>
31 #include <linux/if_arp.h>
32 #include <linux/delay.h>
33 #include <linux/hdlc.h>
34 #include <linux/ioport.h>
35 #include <linux/slab.h>
41 #include <asm/byteorder.h>
46 /* Network driver support routines
49 static inline struct z8530_dev *dev_to_sv(struct net_device *dev)
51 return (struct z8530_dev *)dev_to_hdlc(dev)->priv;
54 /* Frame receive. Simple for our card as we do HDLC and there
55 * is no funny garbage involved
58 static void hostess_input(struct z8530_channel *c, struct sk_buff *skb)
60 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
61 skb_trim(skb, skb->len - 2);
62 skb->protocol = hdlc_type_trans(skb, c->netdevice);
63 skb_reset_mac_header(skb);
64 skb->dev = c->netdevice;
65 /* Send it to the PPP layer. We don't have time to process
71 /* We've been placed in the UP state
74 static int hostess_open(struct net_device *d)
76 struct z8530_dev *sv11 = dev_to_sv(d);
83 err = z8530_sync_open(d, &sv11->chanA);
86 err = z8530_sync_dma_open(d, &sv11->chanA);
89 err = z8530_sync_txdma_open(d, &sv11->chanA);
100 z8530_sync_close(d, &sv11->chanA);
103 z8530_sync_dma_close(d, &sv11->chanA);
106 z8530_sync_txdma_close(d, &sv11->chanA);
111 sv11->chanA.rx_function = hostess_input;
117 netif_start_queue(d);
121 static int hostess_close(struct net_device *d)
123 struct z8530_dev *sv11 = dev_to_sv(d);
124 /* Discard new frames
126 sv11->chanA.rx_function = z8530_null_rx;
133 z8530_sync_close(d, &sv11->chanA);
136 z8530_sync_dma_close(d, &sv11->chanA);
139 z8530_sync_txdma_close(d, &sv11->chanA);
145 static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
147 return hdlc_ioctl(d, ifr, cmd);
150 /* Passed network frames, fire them downwind.
153 static netdev_tx_t hostess_queue_xmit(struct sk_buff *skb,
154 struct net_device *d)
156 return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb);
159 static int hostess_attach(struct net_device *dev, unsigned short encoding,
160 unsigned short parity)
162 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
167 /* Description block for a Comtrol Hostess SV11 card
170 static const struct net_device_ops hostess_ops = {
171 .ndo_open = hostess_open,
172 .ndo_stop = hostess_close,
173 .ndo_start_xmit = hdlc_start_xmit,
174 .ndo_do_ioctl = hostess_ioctl,
177 static struct z8530_dev *sv11_init(int iobase, int irq)
179 struct z8530_dev *sv;
180 struct net_device *netdev;
181 /* Get the needed I/O space
184 if (!request_region(iobase, 8, "Comtrol SV11")) {
185 pr_warn("I/O 0x%X already in use\n", iobase);
189 sv = kzalloc(sizeof(struct z8530_dev), GFP_KERNEL);
193 /* Stuff in the I/O addressing
198 sv->chanA.ctrlio = iobase + 1;
199 sv->chanA.dataio = iobase + 3;
200 sv->chanB.ctrlio = -1;
201 sv->chanB.dataio = -1;
202 sv->chanA.irqs = &z8530_nop;
203 sv->chanB.irqs = &z8530_nop;
205 outb(0, iobase + 4); /* DMA off */
207 /* We want a fast IRQ for this device. Actually we'd like an even faster
208 * IRQ ;) - This is one driver RtLinux is made for
211 if (request_irq(irq, z8530_interrupt, 0,
212 "Hostess SV11", sv) < 0) {
213 pr_warn("IRQ %d already in use\n", irq);
218 sv->chanA.private = sv;
223 /* You can have DMA off or 1 and 3 thats the lot
228 outb(0x03 | 0x08, iobase + 4); /* DMA on */
229 if (request_dma(sv->chanA.txdma, "Hostess SV/11 (TX)"))
233 if (request_dma(sv->chanA.rxdma, "Hostess SV/11 (RX)"))
237 /* Kill our private IRQ line the hostess can end up chattering
238 * until the configuration is set
242 /* Begin normal initialise
245 if (z8530_init(sv)) {
246 pr_err("Z8530 series device not found\n");
250 z8530_channel_load(&sv->chanB, z8530_dead_port);
251 if (sv->type == Z85C30)
252 z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream);
254 z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream_85230);
258 /* Now we can take the IRQ
261 sv->chanA.netdevice = netdev = alloc_hdlcdev(sv);
265 dev_to_hdlc(netdev)->attach = hostess_attach;
266 dev_to_hdlc(netdev)->xmit = hostess_queue_xmit;
267 netdev->netdev_ops = &hostess_ops;
268 netdev->base_addr = iobase;
271 if (register_hdlc_device(netdev)) {
272 pr_err("unable to register HDLC device\n");
277 z8530_describe(sv, "I/O", iobase);
283 free_dma(sv->chanA.rxdma);
286 free_dma(sv->chanA.txdma);
292 release_region(iobase, 8);
296 static void sv11_shutdown(struct z8530_dev *dev)
298 unregister_hdlc_device(dev->chanA.netdevice);
300 free_irq(dev->irq, dev);
303 free_dma(dev->chanA.rxdma);
304 free_dma(dev->chanA.txdma);
306 release_region(dev->chanA.ctrlio - 1, 8);
307 free_netdev(dev->chanA.netdevice);
311 static int io = 0x200;
314 module_param_hw(io, int, ioport, 0);
315 MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
316 module_param_hw(dma, int, dma, 0);
317 MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
318 module_param_hw(irq, int, irq, 0);
319 MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
321 MODULE_AUTHOR("Alan Cox");
322 MODULE_LICENSE("GPL");
323 MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
325 static struct z8530_dev *sv11_unit;
327 int init_module(void)
329 sv11_unit = sv11_init(io, irq);
335 void cleanup_module(void)
338 sv11_shutdown(sv11_unit);