hostess_sv11.c 8.1 KB

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