hostess_sv11.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/mm.h>
  23. #include <linux/net.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/if_arp.h>
  27. #include <linux/delay.h>
  28. #include <linux/ioport.h>
  29. #include <net/arp.h>
  30. #include <asm/irq.h>
  31. #include <asm/io.h>
  32. #include <asm/dma.h>
  33. #include <asm/byteorder.h>
  34. #include <net/syncppp.h>
  35. #include "z85230.h"
  36. static int dma;
  37. struct sv11_device
  38. {
  39. void *if_ptr; /* General purpose pointer (used by SPPP) */
  40. struct z8530_dev sync;
  41. struct ppp_device netdev;
  42. };
  43. /*
  44. * Network driver support routines
  45. */
  46. /*
  47. * Frame receive. Simple for our card as we do sync ppp 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=__constant_htons(ETH_P_WAN_PPP);
  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. c->netdevice->last_rx = jiffies;
  63. }
  64. /*
  65. * We've been placed in the UP state
  66. */
  67. static int hostess_open(struct net_device *d)
  68. {
  69. struct sv11_device *sv11=d->priv;
  70. int err = -1;
  71. /*
  72. * Link layer up
  73. */
  74. switch(dma)
  75. {
  76. case 0:
  77. err=z8530_sync_open(d, &sv11->sync.chanA);
  78. break;
  79. case 1:
  80. err=z8530_sync_dma_open(d, &sv11->sync.chanA);
  81. break;
  82. case 2:
  83. err=z8530_sync_txdma_open(d, &sv11->sync.chanA);
  84. break;
  85. }
  86. if(err)
  87. return err;
  88. /*
  89. * Begin PPP
  90. */
  91. err=sppp_open(d);
  92. if(err)
  93. {
  94. switch(dma)
  95. {
  96. case 0:
  97. z8530_sync_close(d, &sv11->sync.chanA);
  98. break;
  99. case 1:
  100. z8530_sync_dma_close(d, &sv11->sync.chanA);
  101. break;
  102. case 2:
  103. z8530_sync_txdma_close(d, &sv11->sync.chanA);
  104. break;
  105. }
  106. return err;
  107. }
  108. sv11->sync.chanA.rx_function=hostess_input;
  109. /*
  110. * Go go go
  111. */
  112. netif_start_queue(d);
  113. return 0;
  114. }
  115. static int hostess_close(struct net_device *d)
  116. {
  117. struct sv11_device *sv11=d->priv;
  118. /*
  119. * Discard new frames
  120. */
  121. sv11->sync.chanA.rx_function=z8530_null_rx;
  122. /*
  123. * PPP off
  124. */
  125. sppp_close(d);
  126. /*
  127. * Link layer down
  128. */
  129. netif_stop_queue(d);
  130. switch(dma)
  131. {
  132. case 0:
  133. z8530_sync_close(d, &sv11->sync.chanA);
  134. break;
  135. case 1:
  136. z8530_sync_dma_close(d, &sv11->sync.chanA);
  137. break;
  138. case 2:
  139. z8530_sync_txdma_close(d, &sv11->sync.chanA);
  140. break;
  141. }
  142. return 0;
  143. }
  144. static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
  145. {
  146. /* struct sv11_device *sv11=d->priv;
  147. z8530_ioctl(d,&sv11->sync.chanA,ifr,cmd) */
  148. return sppp_do_ioctl(d, ifr,cmd);
  149. }
  150. static struct net_device_stats *hostess_get_stats(struct net_device *d)
  151. {
  152. struct sv11_device *sv11=d->priv;
  153. if(sv11)
  154. return z8530_get_stats(&sv11->sync.chanA);
  155. else
  156. return NULL;
  157. }
  158. /*
  159. * Passed PPP frames, fire them downwind.
  160. */
  161. static int hostess_queue_xmit(struct sk_buff *skb, struct net_device *d)
  162. {
  163. struct sv11_device *sv11=d->priv;
  164. return z8530_queue_xmit(&sv11->sync.chanA, skb);
  165. }
  166. static int hostess_neigh_setup(struct neighbour *n)
  167. {
  168. if (n->nud_state == NUD_NONE) {
  169. n->ops = &arp_broken_ops;
  170. n->output = n->ops->output;
  171. }
  172. return 0;
  173. }
  174. static int hostess_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
  175. {
  176. if (p->tbl->family == AF_INET) {
  177. p->neigh_setup = hostess_neigh_setup;
  178. p->ucast_probes = 0;
  179. p->mcast_probes = 0;
  180. }
  181. return 0;
  182. }
  183. static void sv11_setup(struct net_device *dev)
  184. {
  185. dev->open = hostess_open;
  186. dev->stop = hostess_close;
  187. dev->hard_start_xmit = hostess_queue_xmit;
  188. dev->get_stats = hostess_get_stats;
  189. dev->do_ioctl = hostess_ioctl;
  190. dev->neigh_setup = hostess_neigh_setup_dev;
  191. }
  192. /*
  193. * Description block for a Comtrol Hostess SV11 card
  194. */
  195. static struct sv11_device *sv11_init(int iobase, int irq)
  196. {
  197. struct z8530_dev *dev;
  198. struct sv11_device *sv;
  199. /*
  200. * Get the needed I/O space
  201. */
  202. if(!request_region(iobase, 8, "Comtrol SV11"))
  203. {
  204. printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n", iobase);
  205. return NULL;
  206. }
  207. sv = kzalloc(sizeof(struct sv11_device), GFP_KERNEL);
  208. if(!sv)
  209. goto fail3;
  210. sv->if_ptr=&sv->netdev;
  211. sv->netdev.dev = alloc_netdev(0, "hdlc%d", sv11_setup);
  212. if(!sv->netdev.dev)
  213. goto fail2;
  214. dev=&sv->sync;
  215. /*
  216. * Stuff in the I/O addressing
  217. */
  218. dev->active = 0;
  219. dev->chanA.ctrlio=iobase+1;
  220. dev->chanA.dataio=iobase+3;
  221. dev->chanB.ctrlio=-1;
  222. dev->chanB.dataio=-1;
  223. dev->chanA.irqs=&z8530_nop;
  224. dev->chanB.irqs=&z8530_nop;
  225. outb(0, iobase+4); /* DMA off */
  226. /* We want a fast IRQ for this device. Actually we'd like an even faster
  227. IRQ ;) - This is one driver RtLinux is made for */
  228. if(request_irq(irq, &z8530_interrupt, IRQF_DISABLED, "Hostess SV11", dev)<0)
  229. {
  230. printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq);
  231. goto fail1;
  232. }
  233. dev->irq=irq;
  234. dev->chanA.private=sv;
  235. dev->chanA.netdevice=sv->netdev.dev;
  236. dev->chanA.dev=dev;
  237. dev->chanB.dev=dev;
  238. if(dma)
  239. {
  240. /*
  241. * You can have DMA off or 1 and 3 thats the lot
  242. * on the Comtrol.
  243. */
  244. dev->chanA.txdma=3;
  245. dev->chanA.rxdma=1;
  246. outb(0x03|0x08, iobase+4); /* DMA on */
  247. if(request_dma(dev->chanA.txdma, "Hostess SV/11 (TX)")!=0)
  248. goto fail;
  249. if(dma==1)
  250. {
  251. if(request_dma(dev->chanA.rxdma, "Hostess SV/11 (RX)")!=0)
  252. goto dmafail;
  253. }
  254. }
  255. /* Kill our private IRQ line the hostess can end up chattering
  256. until the configuration is set */
  257. disable_irq(irq);
  258. /*
  259. * Begin normal initialise
  260. */
  261. if(z8530_init(dev)!=0)
  262. {
  263. printk(KERN_ERR "Z8530 series device not found.\n");
  264. enable_irq(irq);
  265. goto dmafail2;
  266. }
  267. z8530_channel_load(&dev->chanB, z8530_dead_port);
  268. if(dev->type==Z85C30)
  269. z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
  270. else
  271. z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
  272. enable_irq(irq);
  273. /*
  274. * Now we can take the IRQ
  275. */
  276. if(dev_alloc_name(dev->chanA.netdevice,"hdlc%d")>=0)
  277. {
  278. struct net_device *d=dev->chanA.netdevice;
  279. /*
  280. * Initialise the PPP components
  281. */
  282. sppp_attach(&sv->netdev);
  283. /*
  284. * Local fields
  285. */
  286. d->base_addr = iobase;
  287. d->irq = irq;
  288. d->priv = sv;
  289. if(register_netdev(d))
  290. {
  291. printk(KERN_ERR "%s: unable to register device.\n",
  292. d->name);
  293. sppp_detach(d);
  294. goto dmafail2;
  295. }
  296. z8530_describe(dev, "I/O", iobase);
  297. dev->active=1;
  298. return sv;
  299. }
  300. dmafail2:
  301. if(dma==1)
  302. free_dma(dev->chanA.rxdma);
  303. dmafail:
  304. if(dma)
  305. free_dma(dev->chanA.txdma);
  306. fail:
  307. free_irq(irq, dev);
  308. fail1:
  309. free_netdev(sv->netdev.dev);
  310. fail2:
  311. kfree(sv);
  312. fail3:
  313. release_region(iobase,8);
  314. return NULL;
  315. }
  316. static void sv11_shutdown(struct sv11_device *dev)
  317. {
  318. sppp_detach(dev->netdev.dev);
  319. unregister_netdev(dev->netdev.dev);
  320. z8530_shutdown(&dev->sync);
  321. free_irq(dev->sync.irq, dev);
  322. if(dma)
  323. {
  324. if(dma==1)
  325. free_dma(dev->sync.chanA.rxdma);
  326. free_dma(dev->sync.chanA.txdma);
  327. }
  328. release_region(dev->sync.chanA.ctrlio-1, 8);
  329. free_netdev(dev->netdev.dev);
  330. kfree(dev);
  331. }
  332. #ifdef MODULE
  333. static int io=0x200;
  334. static int irq=9;
  335. module_param(io, int, 0);
  336. MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
  337. module_param(dma, int, 0);
  338. MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
  339. module_param(irq, int, 0);
  340. MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
  341. MODULE_AUTHOR("Alan Cox");
  342. MODULE_LICENSE("GPL");
  343. MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
  344. static struct sv11_device *sv11_unit;
  345. int init_module(void)
  346. {
  347. printk(KERN_INFO "SV-11 Z85230 Synchronous Driver v 0.03.\n");
  348. printk(KERN_INFO "(c) Copyright 2001, Red Hat Inc.\n");
  349. if((sv11_unit=sv11_init(io,irq))==NULL)
  350. return -ENODEV;
  351. return 0;
  352. }
  353. void cleanup_module(void)
  354. {
  355. if(sv11_unit)
  356. sv11_shutdown(sv11_unit);
  357. }
  358. #endif