1 // SPDX-License-Identifier: GPL-2.0-only
3 * Comtrol SV11 card driver
5 * This is a slightly odd Z85230 synchronous driver. All you need to
10 * It supports DMA using two DMA channels in SYNC mode. The driver doesn't
11 * use these facilities
13 * The control port is at io+1, the data at io+3 and turning off the DMA
14 * is done by writing 0 to io+4
16 * The hardware does the bus handling to avoid the need for delays between
17 * touching control registers.
19 * Port B isn't wired (why - beats me)
21 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #include <linux/net.h>
30 #include <linux/skbuff.h>
31 #include <linux/netdevice.h>
32 #include <linux/if_arp.h>
33 #include <linux/delay.h>
34 #include <linux/hdlc.h>
35 #include <linux/ioport.h>
36 #include <linux/slab.h>
42 #include <asm/byteorder.h>
48 * Network driver support routines
51 static inline struct z8530_dev
* dev_to_sv(struct net_device
*dev
)
53 return (struct z8530_dev
*)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 hostess_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
;
69 * Send it to the PPP layer. We don't have time to process
76 * We've been placed in the UP state
79 static int hostess_open(struct net_device
*d
)
81 struct z8530_dev
*sv11
= dev_to_sv(d
);
89 err
= z8530_sync_open(d
, &sv11
->chanA
);
92 err
= z8530_sync_dma_open(d
, &sv11
->chanA
);
95 err
= z8530_sync_txdma_open(d
, &sv11
->chanA
);
106 z8530_sync_close(d
, &sv11
->chanA
);
109 z8530_sync_dma_close(d
, &sv11
->chanA
);
112 z8530_sync_txdma_close(d
, &sv11
->chanA
);
117 sv11
->chanA
.rx_function
= hostess_input
;
123 netif_start_queue(d
);
127 static int hostess_close(struct net_device
*d
)
129 struct z8530_dev
*sv11
= dev_to_sv(d
);
133 sv11
->chanA
.rx_function
= z8530_null_rx
;
140 z8530_sync_close(d
, &sv11
->chanA
);
143 z8530_sync_dma_close(d
, &sv11
->chanA
);
146 z8530_sync_txdma_close(d
, &sv11
->chanA
);
152 static int hostess_ioctl(struct net_device
*d
, struct ifreq
*ifr
, int cmd
)
154 /* struct z8530_dev *sv11=dev_to_sv(d);
155 z8530_ioctl(d,&sv11->chanA,ifr,cmd) */
156 return hdlc_ioctl(d
, ifr
, cmd
);
160 * Passed network frames, fire them downwind.
163 static netdev_tx_t
hostess_queue_xmit(struct sk_buff
*skb
,
164 struct net_device
*d
)
166 return z8530_queue_xmit(&dev_to_sv(d
)->chanA
, skb
);
169 static int hostess_attach(struct net_device
*dev
, unsigned short encoding
,
170 unsigned short parity
)
172 if (encoding
== ENCODING_NRZ
&& parity
== PARITY_CRC16_PR1_CCITT
)
178 * Description block for a Comtrol Hostess SV11 card
181 static const struct net_device_ops hostess_ops
= {
182 .ndo_open
= hostess_open
,
183 .ndo_stop
= hostess_close
,
184 .ndo_start_xmit
= hdlc_start_xmit
,
185 .ndo_do_ioctl
= hostess_ioctl
,
188 static struct z8530_dev
*sv11_init(int iobase
, int irq
)
190 struct z8530_dev
*sv
;
191 struct net_device
*netdev
;
193 * Get the needed I/O space
196 if (!request_region(iobase
, 8, "Comtrol SV11")) {
197 pr_warn("I/O 0x%X already in use\n", iobase
);
201 sv
= kzalloc(sizeof(struct z8530_dev
), GFP_KERNEL
);
206 * Stuff in the I/O addressing
211 sv
->chanA
.ctrlio
= iobase
+ 1;
212 sv
->chanA
.dataio
= iobase
+ 3;
213 sv
->chanB
.ctrlio
= -1;
214 sv
->chanB
.dataio
= -1;
215 sv
->chanA
.irqs
= &z8530_nop
;
216 sv
->chanB
.irqs
= &z8530_nop
;
218 outb(0, iobase
+ 4); /* DMA off */
220 /* We want a fast IRQ for this device. Actually we'd like an even faster
221 IRQ ;) - This is one driver RtLinux is made for */
223 if (request_irq(irq
, z8530_interrupt
, 0,
224 "Hostess SV11", sv
) < 0) {
225 pr_warn("IRQ %d already in use\n", irq
);
230 sv
->chanA
.private = sv
;
236 * You can have DMA off or 1 and 3 thats the lot
241 outb(0x03 | 0x08, iobase
+ 4); /* DMA on */
242 if (request_dma(sv
->chanA
.txdma
, "Hostess SV/11 (TX)"))
246 if (request_dma(sv
->chanA
.rxdma
, "Hostess SV/11 (RX)"))
250 /* Kill our private IRQ line the hostess can end up chattering
251 until the configuration is set */
255 * Begin normal initialise
258 if (z8530_init(sv
)) {
259 pr_err("Z8530 series device not found\n");
263 z8530_channel_load(&sv
->chanB
, z8530_dead_port
);
264 if (sv
->type
== Z85C30
)
265 z8530_channel_load(&sv
->chanA
, z8530_hdlc_kilostream
);
267 z8530_channel_load(&sv
->chanA
, z8530_hdlc_kilostream_85230
);
272 * Now we can take the IRQ
275 sv
->chanA
.netdevice
= netdev
= alloc_hdlcdev(sv
);
279 dev_to_hdlc(netdev
)->attach
= hostess_attach
;
280 dev_to_hdlc(netdev
)->xmit
= hostess_queue_xmit
;
281 netdev
->netdev_ops
= &hostess_ops
;
282 netdev
->base_addr
= iobase
;
285 if (register_hdlc_device(netdev
)) {
286 pr_err("unable to register HDLC device\n");
291 z8530_describe(sv
, "I/O", iobase
);
297 free_dma(sv
->chanA
.rxdma
);
300 free_dma(sv
->chanA
.txdma
);
306 release_region(iobase
, 8);
310 static void sv11_shutdown(struct z8530_dev
*dev
)
312 unregister_hdlc_device(dev
->chanA
.netdevice
);
314 free_irq(dev
->irq
, dev
);
317 free_dma(dev
->chanA
.rxdma
);
318 free_dma(dev
->chanA
.txdma
);
320 release_region(dev
->chanA
.ctrlio
- 1, 8);
321 free_netdev(dev
->chanA
.netdevice
);
325 static int io
= 0x200;
328 module_param_hw(io
, int, ioport
, 0);
329 MODULE_PARM_DESC(io
, "The I/O base of the Comtrol Hostess SV11 card");
330 module_param_hw(dma
, int, dma
, 0);
331 MODULE_PARM_DESC(dma
, "Set this to 1 to use DMA1/DMA3 for TX/RX");
332 module_param_hw(irq
, int, irq
, 0);
333 MODULE_PARM_DESC(irq
, "The interrupt line setting for the Comtrol Hostess SV11 card");
335 MODULE_AUTHOR("Alan Cox");
336 MODULE_LICENSE("GPL");
337 MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
339 static struct z8530_dev
*sv11_unit
;
341 int init_module(void)
343 if ((sv11_unit
= sv11_init(io
, irq
)) == NULL
)
348 void cleanup_module(void)
351 sv11_shutdown(sv11_unit
);