hostess_sv11.c 7.2 KB

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