| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *	Comtrol SV11 card driver | 
 | 3 |  * | 
 | 4 |  *	This is a slightly odd Z85230 synchronous driver. All you need to | 
 | 5 |  *	know basically is | 
 | 6 |  * | 
 | 7 |  *	Its a genuine Z85230 | 
 | 8 |  * | 
 | 9 |  *	It supports DMA using two DMA channels in SYNC mode. The driver doesn't | 
 | 10 |  *	use these facilities | 
 | 11 |  *	 | 
 | 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 | 
 | 14 |  * | 
 | 15 |  *	The hardware does the bus handling to avoid the need for delays between | 
 | 16 |  *	touching control registers. | 
 | 17 |  * | 
 | 18 |  *	Port B isnt wired (why - beats me) | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 19 |  * | 
 | 20 |  *	Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 |  */ | 
 | 22 |  | 
 | 23 | #include <linux/module.h> | 
 | 24 | #include <linux/kernel.h> | 
 | 25 | #include <linux/mm.h> | 
 | 26 | #include <linux/net.h> | 
 | 27 | #include <linux/skbuff.h> | 
 | 28 | #include <linux/netdevice.h> | 
 | 29 | #include <linux/if_arp.h> | 
 | 30 | #include <linux/delay.h> | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 31 | #include <linux/hdlc.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/ioport.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <net/arp.h> | 
 | 35 |  | 
| Al Viro | 8272997 | 2005-12-06 05:53:04 -0500 | [diff] [blame] | 36 | #include <asm/irq.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/io.h> | 
 | 38 | #include <asm/dma.h> | 
 | 39 | #include <asm/byteorder.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include "z85230.h" | 
 | 41 |  | 
 | 42 | static int dma; | 
 | 43 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* | 
 | 45 |  *	Network driver support routines | 
 | 46 |  */ | 
 | 47 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 48 | static inline struct z8530_dev* dev_to_sv(struct net_device *dev) | 
 | 49 | { | 
 | 50 | 	return (struct z8530_dev *)dev_to_hdlc(dev)->priv; | 
 | 51 | } | 
 | 52 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 54 |  *	Frame receive. Simple for our card as we do HDLC and there | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 |  *	is no funny garbage involved | 
 | 56 |  */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 57 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static void hostess_input(struct z8530_channel *c, struct sk_buff *skb) | 
 | 59 | { | 
 | 60 | 	/* Drop the CRC - it's not a good idea to try and negotiate it ;) */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 61 | 	skb_trim(skb, skb->len - 2); | 
 | 62 | 	skb->protocol = hdlc_type_trans(skb, c->netdevice); | 
| Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 63 | 	skb_reset_mac_header(skb); | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 64 | 	skb->dev = c->netdevice; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | 	/* | 
 | 66 | 	 *	Send it to the PPP layer. We don't have time to process | 
 | 67 | 	 *	it right now. | 
 | 68 | 	 */ | 
 | 69 | 	netif_rx(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 71 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* | 
 | 73 |  *	We've been placed in the UP state | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 74 |  */ | 
 | 75 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | static int hostess_open(struct net_device *d) | 
 | 77 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 78 | 	struct z8530_dev *sv11 = dev_to_sv(d); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | 	int err = -1; | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 80 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | 	/* | 
 | 82 | 	 *	Link layer up | 
 | 83 | 	 */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 84 | 	switch (dma) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 		case 0: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 86 | 			err = z8530_sync_open(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | 			break; | 
 | 88 | 		case 1: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 89 | 			err = z8530_sync_dma_open(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | 			break; | 
 | 91 | 		case 2: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 92 | 			err = z8530_sync_txdma_open(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | 			break; | 
 | 94 | 	} | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 95 |  | 
 | 96 | 	if (err) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | 		return err; | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 98 |  | 
 | 99 | 	err = hdlc_open(d); | 
 | 100 | 	if (err) { | 
 | 101 | 		switch (dma) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | 			case 0: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 103 | 				z8530_sync_close(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | 				break; | 
 | 105 | 			case 1: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 106 | 				z8530_sync_dma_close(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | 				break; | 
 | 108 | 			case 2: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 109 | 				z8530_sync_txdma_close(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | 				break; | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 111 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | 		return err; | 
 | 113 | 	} | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 114 | 	sv11->chanA.rx_function = hostess_input; | 
 | 115 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | 	/* | 
 | 117 | 	 *	Go go go | 
 | 118 | 	 */ | 
 | 119 |  | 
 | 120 | 	netif_start_queue(d); | 
 | 121 | 	return 0; | 
 | 122 | } | 
 | 123 |  | 
 | 124 | static int hostess_close(struct net_device *d) | 
 | 125 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 126 | 	struct z8530_dev *sv11 = dev_to_sv(d); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | 	/* | 
 | 128 | 	 *	Discard new frames | 
 | 129 | 	 */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 130 | 	sv11->chanA.rx_function = z8530_null_rx; | 
 | 131 |  | 
 | 132 | 	hdlc_close(d); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | 	netif_stop_queue(d); | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 134 |  | 
 | 135 | 	switch (dma) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | 		case 0: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 137 | 			z8530_sync_close(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | 			break; | 
 | 139 | 		case 1: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 140 | 			z8530_sync_dma_close(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | 			break; | 
 | 142 | 		case 2: | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 143 | 			z8530_sync_txdma_close(d, &sv11->chanA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | 			break; | 
 | 145 | 	} | 
 | 146 | 	return 0; | 
 | 147 | } | 
 | 148 |  | 
 | 149 | static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd) | 
 | 150 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 151 | 	/* struct z8530_dev *sv11=dev_to_sv(d); | 
 | 152 | 	   z8530_ioctl(d,&sv11->chanA,ifr,cmd) */ | 
 | 153 | 	return hdlc_ioctl(d, ifr, cmd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } | 
 | 155 |  | 
 | 156 | /* | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 157 |  *	Passed network frames, fire them downwind. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 |  */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 159 |  | 
| Stephen Hemminger | d71a674 | 2009-08-31 19:50:47 +0000 | [diff] [blame] | 160 | static netdev_tx_t hostess_queue_xmit(struct sk_buff *skb, | 
 | 161 | 					    struct net_device *d) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 163 | 	return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } | 
 | 165 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 166 | static int hostess_attach(struct net_device *dev, unsigned short encoding, | 
 | 167 | 			  unsigned short parity) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 169 | 	if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT) | 
 | 170 | 		return 0; | 
 | 171 | 	return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } | 
 | 173 |  | 
 | 174 | /* | 
 | 175 |  *	Description block for a Comtrol Hostess SV11 card | 
 | 176 |  */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 177 |  | 
| Krzysztof Hałasa | 991990a | 2009-01-08 22:52:11 +0100 | [diff] [blame] | 178 | static const struct net_device_ops hostess_ops = { | 
 | 179 | 	.ndo_open       = hostess_open, | 
 | 180 | 	.ndo_stop       = hostess_close, | 
 | 181 | 	.ndo_change_mtu = hdlc_change_mtu, | 
 | 182 | 	.ndo_start_xmit = hdlc_start_xmit, | 
 | 183 | 	.ndo_do_ioctl   = hostess_ioctl, | 
 | 184 | }; | 
 | 185 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 186 | static struct z8530_dev *sv11_init(int iobase, int irq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 188 | 	struct z8530_dev *sv; | 
 | 189 | 	struct net_device *netdev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | 	/* | 
 | 191 | 	 *	Get the needed I/O space | 
 | 192 | 	 */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 193 |  | 
 | 194 | 	if (!request_region(iobase, 8, "Comtrol SV11")) { | 
 | 195 | 		printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n", | 
 | 196 | 		       iobase); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | 		return NULL; | 
 | 198 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 200 | 	sv = kzalloc(sizeof(struct z8530_dev), GFP_KERNEL); | 
 | 201 | 	if (!sv) | 
 | 202 | 		goto err_kzalloc; | 
 | 203 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | 	/* | 
 | 205 | 	 *	Stuff in the I/O addressing | 
 | 206 | 	 */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 207 |  | 
 | 208 | 	sv->active = 0; | 
 | 209 |  | 
 | 210 | 	sv->chanA.ctrlio = iobase + 1; | 
 | 211 | 	sv->chanA.dataio = iobase + 3; | 
 | 212 | 	sv->chanB.ctrlio = -1; | 
 | 213 | 	sv->chanB.dataio = -1; | 
 | 214 | 	sv->chanA.irqs = &z8530_nop; | 
 | 215 | 	sv->chanB.irqs = &z8530_nop; | 
 | 216 |  | 
 | 217 | 	outb(0, iobase + 4);		/* DMA off */ | 
 | 218 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | 	/* We want a fast IRQ for this device. Actually we'd like an even faster | 
 | 220 | 	   IRQ ;) - This is one driver RtLinux is made for */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 221 |  | 
| Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 222 | 	if (request_irq(irq, z8530_interrupt, IRQF_DISABLED, | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 223 | 			"Hostess SV11", sv) < 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | 		printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq); | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 225 | 		goto err_irq; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | 	} | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 227 |  | 
 | 228 | 	sv->irq = irq; | 
 | 229 | 	sv->chanA.private = sv; | 
 | 230 | 	sv->chanA.dev = sv; | 
 | 231 | 	sv->chanB.dev = sv; | 
 | 232 |  | 
 | 233 | 	if (dma) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | 		/* | 
 | 235 | 		 *	You can have DMA off or 1 and 3 thats the lot | 
 | 236 | 		 *	on the Comtrol. | 
 | 237 | 		 */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 238 | 		sv->chanA.txdma = 3; | 
 | 239 | 		sv->chanA.rxdma = 1; | 
 | 240 | 		outb(0x03 | 0x08, iobase + 4);		/* DMA on */ | 
 | 241 | 		if (request_dma(sv->chanA.txdma, "Hostess SV/11 (TX)")) | 
 | 242 | 			goto err_txdma; | 
 | 243 |  | 
 | 244 | 		if (dma == 1) | 
 | 245 | 			if (request_dma(sv->chanA.rxdma, "Hostess SV/11 (RX)")) | 
 | 246 | 				goto err_rxdma; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | 	} | 
 | 248 |  | 
 | 249 | 	/* Kill our private IRQ line the hostess can end up chattering | 
 | 250 | 	   until the configuration is set */ | 
 | 251 | 	disable_irq(irq); | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 252 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | 	/* | 
 | 254 | 	 *	Begin normal initialise | 
 | 255 | 	 */ | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 256 |  | 
 | 257 | 	if (z8530_init(sv)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | 		printk(KERN_ERR "Z8530 series device not found.\n"); | 
 | 259 | 		enable_irq(irq); | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 260 | 		goto free_dma; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | 	} | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 262 | 	z8530_channel_load(&sv->chanB, z8530_dead_port); | 
 | 263 | 	if (sv->type == Z85C30) | 
 | 264 | 		z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | 	else | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 266 | 		z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream_85230); | 
 | 267 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | 	enable_irq(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 |  | 
 | 270 | 	/* | 
 | 271 | 	 *	Now we can take the IRQ | 
 | 272 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 274 | 	sv->chanA.netdevice = netdev = alloc_hdlcdev(sv); | 
 | 275 | 	if (!netdev) | 
 | 276 | 		goto free_dma; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 278 | 	dev_to_hdlc(netdev)->attach = hostess_attach; | 
 | 279 | 	dev_to_hdlc(netdev)->xmit = hostess_queue_xmit; | 
| Krzysztof Hałasa | 991990a | 2009-01-08 22:52:11 +0100 | [diff] [blame] | 280 | 	netdev->netdev_ops = &hostess_ops; | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 281 | 	netdev->base_addr = iobase; | 
 | 282 | 	netdev->irq = irq; | 
 | 283 |  | 
 | 284 | 	if (register_hdlc_device(netdev)) { | 
 | 285 | 		printk(KERN_ERR "hostess: unable to register HDLC device.\n"); | 
 | 286 | 		free_netdev(netdev); | 
 | 287 | 		goto free_dma; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | 	} | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 289 |  | 
 | 290 | 	z8530_describe(sv, "I/O", iobase); | 
 | 291 | 	sv->active = 1; | 
 | 292 | 	return sv; | 
 | 293 |  | 
 | 294 | free_dma: | 
 | 295 | 	if (dma == 1) | 
 | 296 | 		free_dma(sv->chanA.rxdma); | 
 | 297 | err_rxdma: | 
 | 298 | 	if (dma) | 
 | 299 | 		free_dma(sv->chanA.txdma); | 
 | 300 | err_txdma: | 
 | 301 | 	free_irq(irq, sv); | 
 | 302 | err_irq: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | 	kfree(sv); | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 304 | err_kzalloc: | 
 | 305 | 	release_region(iobase, 8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | 	return NULL; | 
 | 307 | } | 
 | 308 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 309 | static void sv11_shutdown(struct z8530_dev *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 311 | 	unregister_hdlc_device(dev->chanA.netdevice); | 
 | 312 | 	z8530_shutdown(dev); | 
 | 313 | 	free_irq(dev->irq, dev); | 
 | 314 | 	if (dma) { | 
 | 315 | 		if (dma == 1) | 
 | 316 | 			free_dma(dev->chanA.rxdma); | 
 | 317 | 		free_dma(dev->chanA.txdma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | 	} | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 319 | 	release_region(dev->chanA.ctrlio - 1, 8); | 
 | 320 | 	free_netdev(dev->chanA.netdevice); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | 	kfree(dev); | 
 | 322 | } | 
 | 323 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 324 | static int io = 0x200; | 
 | 325 | static int irq = 9; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 |  | 
 | 327 | module_param(io, int, 0); | 
 | 328 | MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card"); | 
 | 329 | module_param(dma, int, 0); | 
 | 330 | MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX"); | 
 | 331 | module_param(irq, int, 0); | 
 | 332 | MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card"); | 
 | 333 |  | 
 | 334 | MODULE_AUTHOR("Alan Cox"); | 
 | 335 | MODULE_LICENSE("GPL"); | 
 | 336 | MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11"); | 
 | 337 |  | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 338 | static struct z8530_dev *sv11_unit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 |  | 
 | 340 | int init_module(void) | 
 | 341 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 342 | 	if ((sv11_unit = sv11_init(io, irq)) == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 		return -ENODEV; | 
 | 344 | 	return 0; | 
 | 345 | } | 
 | 346 |  | 
 | 347 | void cleanup_module(void) | 
 | 348 | { | 
| Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 349 | 	if (sv11_unit) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | 		sv11_shutdown(sv11_unit); | 
 | 351 | } |