hostess_sv11.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 netdev_tx_t hostess_queue_xmit(struct sk_buff *skb,
  140. struct net_device *d)
  141. {
  142. return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb);
  143. }
  144. static int hostess_attach(struct net_device *dev, unsigned short encoding,
  145. unsigned short parity)
  146. {
  147. if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
  148. return 0;
  149. return -EINVAL;
  150. }
  151. /*
  152. * Description block for a Comtrol Hostess SV11 card
  153. */
  154. static const struct net_device_ops hostess_ops = {
  155. .ndo_open = hostess_open,
  156. .ndo_stop = hostess_close,
  157. .ndo_change_mtu = hdlc_change_mtu,
  158. .ndo_start_xmit = hdlc_start_xmit,
  159. .ndo_do_ioctl = hostess_ioctl,
  160. };
  161. static struct z8530_dev *sv11_init(int iobase, int irq)
  162. {
  163. struct z8530_dev *sv;
  164. struct net_device *netdev;
  165. /*
  166. * Get the needed I/O space
  167. */
  168. if (!request_region(iobase, 8, "Comtrol SV11")) {
  169. printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n",
  170. iobase);
  171. return NULL;
  172. }
  173. sv = kzalloc(sizeof(struct z8530_dev), GFP_KERNEL);
  174. if (!sv)
  175. goto err_kzalloc;
  176. /*
  177. * Stuff in the I/O addressing
  178. */
  179. sv->active = 0;
  180. sv->chanA.ctrlio = iobase + 1;
  181. sv->chanA.dataio = iobase + 3;
  182. sv->chanB.ctrlio = -1;
  183. sv->chanB.dataio = -1;
  184. sv->chanA.irqs = &z8530_nop;
  185. sv->chanB.irqs = &z8530_nop;
  186. outb(0, iobase + 4); /* DMA off */
  187. /* We want a fast IRQ for this device. Actually we'd like an even faster
  188. IRQ ;) - This is one driver RtLinux is made for */
  189. if (request_irq(irq, &z8530_interrupt, IRQF_DISABLED,
  190. "Hostess SV11", sv) < 0) {
  191. printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq);
  192. goto err_irq;
  193. }
  194. sv->irq = irq;
  195. sv->chanA.private = sv;
  196. sv->chanA.dev = sv;
  197. sv->chanB.dev = sv;
  198. if (dma) {
  199. /*
  200. * You can have DMA off or 1 and 3 thats the lot
  201. * on the Comtrol.
  202. */
  203. sv->chanA.txdma = 3;
  204. sv->chanA.rxdma = 1;
  205. outb(0x03 | 0x08, iobase + 4); /* DMA on */
  206. if (request_dma(sv->chanA.txdma, "Hostess SV/11 (TX)"))
  207. goto err_txdma;
  208. if (dma == 1)
  209. if (request_dma(sv->chanA.rxdma, "Hostess SV/11 (RX)"))
  210. goto err_rxdma;
  211. }
  212. /* Kill our private IRQ line the hostess can end up chattering
  213. until the configuration is set */
  214. disable_irq(irq);
  215. /*
  216. * Begin normal initialise
  217. */
  218. if (z8530_init(sv)) {
  219. printk(KERN_ERR "Z8530 series device not found.\n");
  220. enable_irq(irq);
  221. goto free_dma;
  222. }
  223. z8530_channel_load(&sv->chanB, z8530_dead_port);
  224. if (sv->type == Z85C30)
  225. z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream);
  226. else
  227. z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream_85230);
  228. enable_irq(irq);
  229. /*
  230. * Now we can take the IRQ
  231. */
  232. sv->chanA.netdevice = netdev = alloc_hdlcdev(sv);
  233. if (!netdev)
  234. goto free_dma;
  235. dev_to_hdlc(netdev)->attach = hostess_attach;
  236. dev_to_hdlc(netdev)->xmit = hostess_queue_xmit;
  237. netdev->netdev_ops = &hostess_ops;
  238. netdev->base_addr = iobase;
  239. netdev->irq = irq;
  240. if (register_hdlc_device(netdev)) {
  241. printk(KERN_ERR "hostess: unable to register HDLC device.\n");
  242. free_netdev(netdev);
  243. goto free_dma;
  244. }
  245. z8530_describe(sv, "I/O", iobase);
  246. sv->active = 1;
  247. return sv;
  248. free_dma:
  249. if (dma == 1)
  250. free_dma(sv->chanA.rxdma);
  251. err_rxdma:
  252. if (dma)
  253. free_dma(sv->chanA.txdma);
  254. err_txdma:
  255. free_irq(irq, sv);
  256. err_irq:
  257. kfree(sv);
  258. err_kzalloc:
  259. release_region(iobase, 8);
  260. return NULL;
  261. }
  262. static void sv11_shutdown(struct z8530_dev *dev)
  263. {
  264. unregister_hdlc_device(dev->chanA.netdevice);
  265. z8530_shutdown(dev);
  266. free_irq(dev->irq, dev);
  267. if (dma) {
  268. if (dma == 1)
  269. free_dma(dev->chanA.rxdma);
  270. free_dma(dev->chanA.txdma);
  271. }
  272. release_region(dev->chanA.ctrlio - 1, 8);
  273. free_netdev(dev->chanA.netdevice);
  274. kfree(dev);
  275. }
  276. static int io = 0x200;
  277. static int irq = 9;
  278. module_param(io, int, 0);
  279. MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
  280. module_param(dma, int, 0);
  281. MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
  282. module_param(irq, int, 0);
  283. MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
  284. MODULE_AUTHOR("Alan Cox");
  285. MODULE_LICENSE("GPL");
  286. MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
  287. static struct z8530_dev *sv11_unit;
  288. int init_module(void)
  289. {
  290. if ((sv11_unit = sv11_init(io, irq)) == NULL)
  291. return -ENODEV;
  292. return 0;
  293. }
  294. void cleanup_module(void)
  295. {
  296. if (sv11_unit)
  297. sv11_shutdown(sv11_unit);
  298. }