lmc_proto.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
  3. * All rights reserved. www.lanmedia.com
  4. *
  5. * This code is written by:
  6. * Andrew Stanley-Jones (asj@cban.com)
  7. * Rob Braun (bbraun@vix.com),
  8. * Michael Graff (explorer@vix.com) and
  9. * Matt Thomas (matt@3am-software.com).
  10. *
  11. * With Help By:
  12. * David Boggs
  13. * Ron Crane
  14. * Allan Cox
  15. *
  16. * This software may be used and distributed according to the terms
  17. * of the GNU General Public License version 2, incorporated herein by reference.
  18. *
  19. * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/string.h>
  23. #include <linux/timer.h>
  24. #include <linux/ptrace.h>
  25. #include <linux/errno.h>
  26. #include <linux/ioport.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/in.h>
  30. #include <linux/if_arp.h>
  31. #include <linux/netdevice.h>
  32. #include <linux/etherdevice.h>
  33. #include <linux/skbuff.h>
  34. #include <linux/inet.h>
  35. #include <linux/workqueue.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/bitops.h>
  38. #include <net/syncppp.h>
  39. #include <asm/processor.h> /* Processor type for cache alignment. */
  40. #include <asm/io.h>
  41. #include <asm/dma.h>
  42. #include <linux/smp.h>
  43. #include "lmc.h"
  44. #include "lmc_var.h"
  45. #include "lmc_debug.h"
  46. #include "lmc_ioctl.h"
  47. #include "lmc_proto.h"
  48. /*
  49. * The compile-time variable SPPPSTUP causes the module to be
  50. * compiled without referencing any of the sync ppp routines.
  51. */
  52. #ifdef SPPPSTUB
  53. #define SPPP_detach(d) (void)0
  54. #define SPPP_open(d) 0
  55. #define SPPP_reopen(d) (void)0
  56. #define SPPP_close(d) (void)0
  57. #define SPPP_attach(d) (void)0
  58. #define SPPP_do_ioctl(d,i,c) -EOPNOTSUPP
  59. #else
  60. #define SPPP_attach(x) sppp_attach((x)->pd)
  61. #define SPPP_detach(x) sppp_detach((x)->pd->dev)
  62. #define SPPP_open(x) sppp_open((x)->pd->dev)
  63. #define SPPP_reopen(x) sppp_reopen((x)->pd->dev)
  64. #define SPPP_close(x) sppp_close((x)->pd->dev)
  65. #define SPPP_do_ioctl(x, y, z) sppp_do_ioctl((x)->pd->dev, (y), (z))
  66. #endif
  67. // init
  68. void lmc_proto_init(lmc_softc_t *sc) /*FOLD00*/
  69. {
  70. lmc_trace(sc->lmc_device, "lmc_proto_init in");
  71. switch(sc->if_type){
  72. case LMC_PPP:
  73. sc->pd = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
  74. if (!sc->pd) {
  75. printk("lmc_proto_init(): kmalloc failure!\n");
  76. return;
  77. }
  78. sc->pd->dev = sc->lmc_device;
  79. sc->if_ptr = sc->pd;
  80. break;
  81. case LMC_RAW:
  82. break;
  83. default:
  84. break;
  85. }
  86. lmc_trace(sc->lmc_device, "lmc_proto_init out");
  87. }
  88. // attach
  89. void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
  90. {
  91. lmc_trace(sc->lmc_device, "lmc_proto_attach in");
  92. switch(sc->if_type){
  93. case LMC_PPP:
  94. {
  95. struct net_device *dev = sc->lmc_device;
  96. SPPP_attach(sc);
  97. dev->do_ioctl = lmc_ioctl;
  98. }
  99. break;
  100. case LMC_NET:
  101. {
  102. struct net_device *dev = sc->lmc_device;
  103. /*
  104. * They set a few basics because they don't use sync_ppp
  105. */
  106. dev->flags |= IFF_POINTOPOINT;
  107. dev->hard_header = NULL;
  108. dev->hard_header_len = 0;
  109. dev->addr_len = 0;
  110. }
  111. case LMC_RAW: /* Setup the task queue, maybe we should notify someone? */
  112. {
  113. }
  114. default:
  115. break;
  116. }
  117. lmc_trace(sc->lmc_device, "lmc_proto_attach out");
  118. }
  119. // detach
  120. void lmc_proto_detach(lmc_softc_t *sc) /*FOLD00*/
  121. {
  122. switch(sc->if_type){
  123. case LMC_PPP:
  124. SPPP_detach(sc);
  125. break;
  126. case LMC_RAW: /* Tell someone we're detaching? */
  127. break;
  128. default:
  129. break;
  130. }
  131. }
  132. // reopen
  133. void lmc_proto_reopen(lmc_softc_t *sc) /*FOLD00*/
  134. {
  135. lmc_trace(sc->lmc_device, "lmc_proto_reopen in");
  136. switch(sc->if_type){
  137. case LMC_PPP:
  138. SPPP_reopen(sc);
  139. break;
  140. case LMC_RAW: /* Reset the interface after being down, prerape to receive packets again */
  141. break;
  142. default:
  143. break;
  144. }
  145. lmc_trace(sc->lmc_device, "lmc_proto_reopen out");
  146. }
  147. // ioctl
  148. int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd) /*FOLD00*/
  149. {
  150. lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
  151. switch(sc->if_type){
  152. case LMC_PPP:
  153. return SPPP_do_ioctl (sc, ifr, cmd);
  154. break;
  155. default:
  156. return -EOPNOTSUPP;
  157. break;
  158. }
  159. lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
  160. }
  161. // open
  162. void lmc_proto_open(lmc_softc_t *sc) /*FOLD00*/
  163. {
  164. int ret;
  165. lmc_trace(sc->lmc_device, "lmc_proto_open in");
  166. switch(sc->if_type){
  167. case LMC_PPP:
  168. ret = SPPP_open(sc);
  169. if(ret < 0)
  170. printk("%s: syncPPP open failed: %d\n", sc->name, ret);
  171. break;
  172. case LMC_RAW: /* We're about to start getting packets! */
  173. break;
  174. default:
  175. break;
  176. }
  177. lmc_trace(sc->lmc_device, "lmc_proto_open out");
  178. }
  179. // close
  180. void lmc_proto_close(lmc_softc_t *sc) /*FOLD00*/
  181. {
  182. lmc_trace(sc->lmc_device, "lmc_proto_close in");
  183. switch(sc->if_type){
  184. case LMC_PPP:
  185. SPPP_close(sc);
  186. break;
  187. case LMC_RAW: /* Interface going down */
  188. break;
  189. default:
  190. break;
  191. }
  192. lmc_trace(sc->lmc_device, "lmc_proto_close out");
  193. }
  194. unsigned short lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
  195. {
  196. lmc_trace(sc->lmc_device, "lmc_proto_type in");
  197. switch(sc->if_type){
  198. case LMC_PPP:
  199. return htons(ETH_P_WAN_PPP);
  200. break;
  201. case LMC_NET:
  202. return htons(ETH_P_802_2);
  203. break;
  204. case LMC_RAW: /* Packet type for skbuff kind of useless */
  205. return htons(ETH_P_802_2);
  206. break;
  207. default:
  208. printk(KERN_WARNING "%s: No protocol set for this interface, assuming 802.2 (which is wrong!!)\n", sc->name);
  209. return htons(ETH_P_802_2);
  210. break;
  211. }
  212. lmc_trace(sc->lmc_device, "lmc_proto_tye out");
  213. }
  214. void lmc_proto_netif(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
  215. {
  216. lmc_trace(sc->lmc_device, "lmc_proto_netif in");
  217. switch(sc->if_type){
  218. case LMC_PPP:
  219. case LMC_NET:
  220. default:
  221. skb->dev->last_rx = jiffies;
  222. netif_rx(skb);
  223. break;
  224. case LMC_RAW:
  225. break;
  226. }
  227. lmc_trace(sc->lmc_device, "lmc_proto_netif out");
  228. }