hostess_sv11.c 7.2 KB

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