sealevel.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * Sealevel Systems 4021 driver.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * (c) Copyright 1999, 2001 Alan Cox
  10. * (c) Copyright 2001 Red Hat Inc.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/net.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/delay.h>
  21. #include <linux/ioport.h>
  22. #include <linux/init.h>
  23. #include <net/arp.h>
  24. #include <asm/irq.h>
  25. #include <asm/io.h>
  26. #include <asm/dma.h>
  27. #include <asm/byteorder.h>
  28. #include <net/syncppp.h>
  29. #include "z85230.h"
  30. struct slvl_device
  31. {
  32. void *if_ptr; /* General purpose pointer (used by SPPP) */
  33. struct z8530_channel *chan;
  34. struct ppp_device pppdev;
  35. int channel;
  36. };
  37. struct slvl_board
  38. {
  39. struct slvl_device *dev[2];
  40. struct z8530_dev board;
  41. int iobase;
  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 sealevel_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=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 sealevel_open(struct net_device *d)
  68. {
  69. struct slvl_device *slvl=d->priv;
  70. int err = -1;
  71. int unit = slvl->channel;
  72. /*
  73. * Link layer up.
  74. */
  75. switch(unit)
  76. {
  77. case 0:
  78. err=z8530_sync_dma_open(d, slvl->chan);
  79. break;
  80. case 1:
  81. err=z8530_sync_open(d, slvl->chan);
  82. break;
  83. }
  84. if(err)
  85. return err;
  86. /*
  87. * Begin PPP
  88. */
  89. err=sppp_open(d);
  90. if(err)
  91. {
  92. switch(unit)
  93. {
  94. case 0:
  95. z8530_sync_dma_close(d, slvl->chan);
  96. break;
  97. case 1:
  98. z8530_sync_close(d, slvl->chan);
  99. break;
  100. }
  101. return err;
  102. }
  103. slvl->chan->rx_function=sealevel_input;
  104. /*
  105. * Go go go
  106. */
  107. netif_start_queue(d);
  108. return 0;
  109. }
  110. static int sealevel_close(struct net_device *d)
  111. {
  112. struct slvl_device *slvl=d->priv;
  113. int unit = slvl->channel;
  114. /*
  115. * Discard new frames
  116. */
  117. slvl->chan->rx_function=z8530_null_rx;
  118. /*
  119. * PPP off
  120. */
  121. sppp_close(d);
  122. /*
  123. * Link layer down
  124. */
  125. netif_stop_queue(d);
  126. switch(unit)
  127. {
  128. case 0:
  129. z8530_sync_dma_close(d, slvl->chan);
  130. break;
  131. case 1:
  132. z8530_sync_close(d, slvl->chan);
  133. break;
  134. }
  135. return 0;
  136. }
  137. static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
  138. {
  139. /* struct slvl_device *slvl=d->priv;
  140. z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
  141. return sppp_do_ioctl(d, ifr,cmd);
  142. }
  143. static struct net_device_stats *sealevel_get_stats(struct net_device *d)
  144. {
  145. struct slvl_device *slvl=d->priv;
  146. if(slvl)
  147. return z8530_get_stats(slvl->chan);
  148. else
  149. return NULL;
  150. }
  151. /*
  152. * Passed PPP frames, fire them downwind.
  153. */
  154. static int sealevel_queue_xmit(struct sk_buff *skb, struct net_device *d)
  155. {
  156. struct slvl_device *slvl=d->priv;
  157. return z8530_queue_xmit(slvl->chan, skb);
  158. }
  159. static int sealevel_neigh_setup(struct neighbour *n)
  160. {
  161. if (n->nud_state == NUD_NONE) {
  162. n->ops = &arp_broken_ops;
  163. n->output = n->ops->output;
  164. }
  165. return 0;
  166. }
  167. static int sealevel_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
  168. {
  169. if (p->tbl->family == AF_INET) {
  170. p->neigh_setup = sealevel_neigh_setup;
  171. p->ucast_probes = 0;
  172. p->mcast_probes = 0;
  173. }
  174. return 0;
  175. }
  176. static int sealevel_attach(struct net_device *dev)
  177. {
  178. struct slvl_device *sv = dev->priv;
  179. sppp_attach(&sv->pppdev);
  180. return 0;
  181. }
  182. static void sealevel_detach(struct net_device *dev)
  183. {
  184. sppp_detach(dev);
  185. }
  186. static void slvl_setup(struct net_device *d)
  187. {
  188. d->open = sealevel_open;
  189. d->stop = sealevel_close;
  190. d->init = sealevel_attach;
  191. d->uninit = sealevel_detach;
  192. d->hard_start_xmit = sealevel_queue_xmit;
  193. d->get_stats = sealevel_get_stats;
  194. d->set_multicast_list = NULL;
  195. d->do_ioctl = sealevel_ioctl;
  196. d->neigh_setup = sealevel_neigh_setup_dev;
  197. d->set_mac_address = NULL;
  198. }
  199. static inline struct slvl_device *slvl_alloc(int iobase, int irq)
  200. {
  201. struct net_device *d;
  202. struct slvl_device *sv;
  203. d = alloc_netdev(sizeof(struct slvl_device), "hdlc%d",
  204. slvl_setup);
  205. if (!d)
  206. return NULL;
  207. sv = d->priv;
  208. sv->if_ptr = &sv->pppdev;
  209. sv->pppdev.dev = d;
  210. d->base_addr = iobase;
  211. d->irq = irq;
  212. return sv;
  213. }
  214. /*
  215. * Allocate and setup Sealevel board.
  216. */
  217. static __init struct slvl_board *slvl_init(int iobase, int irq,
  218. int txdma, int rxdma, int slow)
  219. {
  220. struct z8530_dev *dev;
  221. struct slvl_board *b;
  222. /*
  223. * Get the needed I/O space
  224. */
  225. if(!request_region(iobase, 8, "Sealevel 4021"))
  226. {
  227. printk(KERN_WARNING "sealevel: I/O 0x%X already in use.\n", iobase);
  228. return NULL;
  229. }
  230. b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
  231. if(!b)
  232. goto fail3;
  233. if (!(b->dev[0]= slvl_alloc(iobase, irq)))
  234. goto fail2;
  235. b->dev[0]->chan = &b->board.chanA;
  236. b->dev[0]->channel = 0;
  237. if (!(b->dev[1] = slvl_alloc(iobase, irq)))
  238. goto fail1_0;
  239. b->dev[1]->chan = &b->board.chanB;
  240. b->dev[1]->channel = 1;
  241. dev = &b->board;
  242. /*
  243. * Stuff in the I/O addressing
  244. */
  245. dev->active = 0;
  246. b->iobase = iobase;
  247. /*
  248. * Select 8530 delays for the old board
  249. */
  250. if(slow)
  251. iobase |= Z8530_PORT_SLEEP;
  252. dev->chanA.ctrlio=iobase+1;
  253. dev->chanA.dataio=iobase;
  254. dev->chanB.ctrlio=iobase+3;
  255. dev->chanB.dataio=iobase+2;
  256. dev->chanA.irqs=&z8530_nop;
  257. dev->chanB.irqs=&z8530_nop;
  258. /*
  259. * Assert DTR enable DMA
  260. */
  261. outb(3|(1<<7), b->iobase+4);
  262. /* We want a fast IRQ for this device. Actually we'd like an even faster
  263. IRQ ;) - This is one driver RtLinux is made for */
  264. if(request_irq(irq, &z8530_interrupt, IRQF_DISABLED, "SeaLevel", dev)<0)
  265. {
  266. printk(KERN_WARNING "sealevel: IRQ %d already in use.\n", irq);
  267. goto fail1_1;
  268. }
  269. dev->irq=irq;
  270. dev->chanA.private=&b->dev[0];
  271. dev->chanB.private=&b->dev[1];
  272. dev->chanA.netdevice=b->dev[0]->pppdev.dev;
  273. dev->chanB.netdevice=b->dev[1]->pppdev.dev;
  274. dev->chanA.dev=dev;
  275. dev->chanB.dev=dev;
  276. dev->chanA.txdma=3;
  277. dev->chanA.rxdma=1;
  278. if(request_dma(dev->chanA.txdma, "SeaLevel (TX)")!=0)
  279. goto fail;
  280. if(request_dma(dev->chanA.rxdma, "SeaLevel (RX)")!=0)
  281. goto dmafail;
  282. disable_irq(irq);
  283. /*
  284. * Begin normal initialise
  285. */
  286. if(z8530_init(dev)!=0)
  287. {
  288. printk(KERN_ERR "Z8530 series device not found.\n");
  289. enable_irq(irq);
  290. goto dmafail2;
  291. }
  292. if(dev->type==Z85C30)
  293. {
  294. z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
  295. z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
  296. }
  297. else
  298. {
  299. z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
  300. z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
  301. }
  302. /*
  303. * Now we can take the IRQ
  304. */
  305. enable_irq(irq);
  306. if (register_netdev(b->dev[0]->pppdev.dev))
  307. goto dmafail2;
  308. if (register_netdev(b->dev[1]->pppdev.dev))
  309. goto fail_unit;
  310. z8530_describe(dev, "I/O", iobase);
  311. dev->active=1;
  312. return b;
  313. fail_unit:
  314. unregister_netdev(b->dev[0]->pppdev.dev);
  315. dmafail2:
  316. free_dma(dev->chanA.rxdma);
  317. dmafail:
  318. free_dma(dev->chanA.txdma);
  319. fail:
  320. free_irq(irq, dev);
  321. fail1_1:
  322. free_netdev(b->dev[1]->pppdev.dev);
  323. fail1_0:
  324. free_netdev(b->dev[0]->pppdev.dev);
  325. fail2:
  326. kfree(b);
  327. fail3:
  328. release_region(iobase,8);
  329. return NULL;
  330. }
  331. static void __exit slvl_shutdown(struct slvl_board *b)
  332. {
  333. int u;
  334. z8530_shutdown(&b->board);
  335. for(u=0; u<2; u++)
  336. {
  337. struct net_device *d = b->dev[u]->pppdev.dev;
  338. unregister_netdev(d);
  339. free_netdev(d);
  340. }
  341. free_irq(b->board.irq, &b->board);
  342. free_dma(b->board.chanA.rxdma);
  343. free_dma(b->board.chanA.txdma);
  344. /* DMA off on the card, drop DTR */
  345. outb(0, b->iobase);
  346. release_region(b->iobase, 8);
  347. kfree(b);
  348. }
  349. static int io=0x238;
  350. static int txdma=1;
  351. static int rxdma=3;
  352. static int irq=5;
  353. static int slow=0;
  354. module_param(io, int, 0);
  355. MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
  356. module_param(txdma, int, 0);
  357. MODULE_PARM_DESC(txdma, "Transmit DMA channel");
  358. module_param(rxdma, int, 0);
  359. MODULE_PARM_DESC(rxdma, "Receive DMA channel");
  360. module_param(irq, int, 0);
  361. MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
  362. module_param(slow, bool, 0);
  363. MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
  364. MODULE_AUTHOR("Alan Cox");
  365. MODULE_LICENSE("GPL");
  366. MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
  367. static struct slvl_board *slvl_unit;
  368. static int __init slvl_init_module(void)
  369. {
  370. #ifdef MODULE
  371. printk(KERN_INFO "SeaLevel Z85230 Synchronous Driver v 0.02.\n");
  372. printk(KERN_INFO "(c) Copyright 1998, Building Number Three Ltd.\n");
  373. #endif
  374. slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
  375. return slvl_unit ? 0 : -ENODEV;
  376. }
  377. static void __exit slvl_cleanup_module(void)
  378. {
  379. if(slvl_unit)
  380. slvl_shutdown(slvl_unit);
  381. }
  382. module_init(slvl_init_module);
  383. module_exit(slvl_cleanup_module);