hostess_sv11.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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->mac.raw=skb->data;
  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=(struct sv11_device *)kmalloc(sizeof(struct sv11_device), GFP_KERNEL);
  208. if(!sv)
  209. goto fail3;
  210. memset(sv, 0, sizeof(*sv));
  211. sv->if_ptr=&sv->netdev;
  212. sv->netdev.dev = alloc_netdev(0, "hdlc%d", sv11_setup);
  213. if(!sv->netdev.dev)
  214. goto fail2;
  215. SET_MODULE_OWNER(sv->netdev.dev);
  216. dev=&sv->sync;
  217. /*
  218. * Stuff in the I/O addressing
  219. */
  220. dev->active = 0;
  221. dev->chanA.ctrlio=iobase+1;
  222. dev->chanA.dataio=iobase+3;
  223. dev->chanB.ctrlio=-1;
  224. dev->chanB.dataio=-1;
  225. dev->chanA.irqs=&z8530_nop;
  226. dev->chanB.irqs=&z8530_nop;
  227. outb(0, iobase+4); /* DMA off */
  228. /* We want a fast IRQ for this device. Actually we'd like an even faster
  229. IRQ ;) - This is one driver RtLinux is made for */
  230. if(request_irq(irq, &z8530_interrupt, SA_INTERRUPT, "Hostess SV11", dev)<0)
  231. {
  232. printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq);
  233. goto fail1;
  234. }
  235. dev->irq=irq;
  236. dev->chanA.private=sv;
  237. dev->chanA.netdevice=sv->netdev.dev;
  238. dev->chanA.dev=dev;
  239. dev->chanB.dev=dev;
  240. if(dma)
  241. {
  242. /*
  243. * You can have DMA off or 1 and 3 thats the lot
  244. * on the Comtrol.
  245. */
  246. dev->chanA.txdma=3;
  247. dev->chanA.rxdma=1;
  248. outb(0x03|0x08, iobase+4); /* DMA on */
  249. if(request_dma(dev->chanA.txdma, "Hostess SV/11 (TX)")!=0)
  250. goto fail;
  251. if(dma==1)
  252. {
  253. if(request_dma(dev->chanA.rxdma, "Hostess SV/11 (RX)")!=0)
  254. goto dmafail;
  255. }
  256. }
  257. /* Kill our private IRQ line the hostess can end up chattering
  258. until the configuration is set */
  259. disable_irq(irq);
  260. /*
  261. * Begin normal initialise
  262. */
  263. if(z8530_init(dev)!=0)
  264. {
  265. printk(KERN_ERR "Z8530 series device not found.\n");
  266. enable_irq(irq);
  267. goto dmafail2;
  268. }
  269. z8530_channel_load(&dev->chanB, z8530_dead_port);
  270. if(dev->type==Z85C30)
  271. z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
  272. else
  273. z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
  274. enable_irq(irq);
  275. /*
  276. * Now we can take the IRQ
  277. */
  278. if(dev_alloc_name(dev->chanA.netdevice,"hdlc%d")>=0)
  279. {
  280. struct net_device *d=dev->chanA.netdevice;
  281. /*
  282. * Initialise the PPP components
  283. */
  284. sppp_attach(&sv->netdev);
  285. /*
  286. * Local fields
  287. */
  288. d->base_addr = iobase;
  289. d->irq = irq;
  290. d->priv = sv;
  291. if(register_netdev(d))
  292. {
  293. printk(KERN_ERR "%s: unable to register device.\n",
  294. d->name);
  295. sppp_detach(d);
  296. goto dmafail2;
  297. }
  298. z8530_describe(dev, "I/O", iobase);
  299. dev->active=1;
  300. return sv;
  301. }
  302. dmafail2:
  303. if(dma==1)
  304. free_dma(dev->chanA.rxdma);
  305. dmafail:
  306. if(dma)
  307. free_dma(dev->chanA.txdma);
  308. fail:
  309. free_irq(irq, dev);
  310. fail1:
  311. free_netdev(sv->netdev.dev);
  312. fail2:
  313. kfree(sv);
  314. fail3:
  315. release_region(iobase,8);
  316. return NULL;
  317. }
  318. static void sv11_shutdown(struct sv11_device *dev)
  319. {
  320. sppp_detach(dev->netdev.dev);
  321. unregister_netdev(dev->netdev.dev);
  322. z8530_shutdown(&dev->sync);
  323. free_irq(dev->sync.irq, dev);
  324. if(dma)
  325. {
  326. if(dma==1)
  327. free_dma(dev->sync.chanA.rxdma);
  328. free_dma(dev->sync.chanA.txdma);
  329. }
  330. release_region(dev->sync.chanA.ctrlio-1, 8);
  331. free_netdev(dev->netdev.dev);
  332. kfree(dev);
  333. }
  334. #ifdef MODULE
  335. static int io=0x200;
  336. static int irq=9;
  337. module_param(io, int, 0);
  338. MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
  339. module_param(dma, int, 0);
  340. MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
  341. module_param(irq, int, 0);
  342. MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
  343. MODULE_AUTHOR("Alan Cox");
  344. MODULE_LICENSE("GPL");
  345. MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
  346. static struct sv11_device *sv11_unit;
  347. int init_module(void)
  348. {
  349. printk(KERN_INFO "SV-11 Z85230 Synchronous Driver v 0.03.\n");
  350. printk(KERN_INFO "(c) Copyright 2001, Red Hat Inc.\n");
  351. if((sv11_unit=sv11_init(io,irq))==NULL)
  352. return -ENODEV;
  353. return 0;
  354. }
  355. void cleanup_module(void)
  356. {
  357. if(sv11_unit)
  358. sv11_shutdown(sv11_unit);
  359. }
  360. #endif