lmc_proto.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/pci.h>
  30. #include <linux/in.h>
  31. #include <linux/if_arp.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/inet.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/proc_fs.h>
  38. #include <linux/bitops.h>
  39. #include <net/syncppp.h>
  40. #include <asm/processor.h> /* Processor type for cache alignment. */
  41. #include <asm/io.h>
  42. #include <asm/dma.h>
  43. #include <linux/smp.h>
  44. #include "lmc.h"
  45. #include "lmc_var.h"
  46. #include "lmc_debug.h"
  47. #include "lmc_ioctl.h"
  48. #include "lmc_proto.h"
  49. /*
  50. * The compile-time variable SPPPSTUP causes the module to be
  51. * compiled without referencing any of the sync ppp routines.
  52. */
  53. #ifdef SPPPSTUB
  54. #define SPPP_detach(d) (void)0
  55. #define SPPP_open(d) 0
  56. #define SPPP_reopen(d) (void)0
  57. #define SPPP_close(d) (void)0
  58. #define SPPP_attach(d) (void)0
  59. #define SPPP_do_ioctl(d,i,c) -EOPNOTSUPP
  60. #else
  61. #define SPPP_attach(x) sppp_attach((x)->pd)
  62. #define SPPP_detach(x) sppp_detach((x)->pd->dev)
  63. #define SPPP_open(x) sppp_open((x)->pd->dev)
  64. #define SPPP_reopen(x) sppp_reopen((x)->pd->dev)
  65. #define SPPP_close(x) sppp_close((x)->pd->dev)
  66. #define SPPP_do_ioctl(x, y, z) sppp_do_ioctl((x)->pd->dev, (y), (z))
  67. #endif
  68. // init
  69. void lmc_proto_init(lmc_softc_t *sc) /*FOLD00*/
  70. {
  71. lmc_trace(sc->lmc_device, "lmc_proto_init in");
  72. switch(sc->if_type){
  73. case LMC_PPP:
  74. sc->pd = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
  75. if (!sc->pd) {
  76. printk("lmc_proto_init(): kmalloc failure!\n");
  77. return;
  78. }
  79. sc->pd->dev = sc->lmc_device;
  80. sc->if_ptr = sc->pd;
  81. break;
  82. case LMC_RAW:
  83. break;
  84. default:
  85. break;
  86. }
  87. lmc_trace(sc->lmc_device, "lmc_proto_init out");
  88. }
  89. // attach
  90. void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
  91. {
  92. lmc_trace(sc->lmc_device, "lmc_proto_attach in");
  93. switch(sc->if_type){
  94. case LMC_PPP:
  95. {
  96. struct net_device *dev = sc->lmc_device;
  97. SPPP_attach(sc);
  98. dev->do_ioctl = lmc_ioctl;
  99. }
  100. break;
  101. case LMC_NET:
  102. {
  103. struct net_device *dev = sc->lmc_device;
  104. /*
  105. * They set a few basics because they don't use sync_ppp
  106. */
  107. dev->flags |= IFF_POINTOPOINT;
  108. dev->hard_header = NULL;
  109. dev->hard_header_len = 0;
  110. dev->addr_len = 0;
  111. }
  112. case LMC_RAW: /* Setup the task queue, maybe we should notify someone? */
  113. {
  114. }
  115. default:
  116. break;
  117. }
  118. lmc_trace(sc->lmc_device, "lmc_proto_attach out");
  119. }
  120. // detach
  121. void lmc_proto_detach(lmc_softc_t *sc) /*FOLD00*/
  122. {
  123. switch(sc->if_type){
  124. case LMC_PPP:
  125. SPPP_detach(sc);
  126. break;
  127. case LMC_RAW: /* Tell someone we're detaching? */
  128. break;
  129. default:
  130. break;
  131. }
  132. }
  133. // reopen
  134. void lmc_proto_reopen(lmc_softc_t *sc) /*FOLD00*/
  135. {
  136. lmc_trace(sc->lmc_device, "lmc_proto_reopen in");
  137. switch(sc->if_type){
  138. case LMC_PPP:
  139. SPPP_reopen(sc);
  140. break;
  141. case LMC_RAW: /* Reset the interface after being down, prerape to receive packets again */
  142. break;
  143. default:
  144. break;
  145. }
  146. lmc_trace(sc->lmc_device, "lmc_proto_reopen out");
  147. }
  148. // ioctl
  149. int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd) /*FOLD00*/
  150. {
  151. lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
  152. switch(sc->if_type){
  153. case LMC_PPP:
  154. return SPPP_do_ioctl (sc, ifr, cmd);
  155. break;
  156. default:
  157. return -EOPNOTSUPP;
  158. break;
  159. }
  160. lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
  161. }
  162. // open
  163. void lmc_proto_open(lmc_softc_t *sc) /*FOLD00*/
  164. {
  165. int ret;
  166. lmc_trace(sc->lmc_device, "lmc_proto_open in");
  167. switch(sc->if_type){
  168. case LMC_PPP:
  169. ret = SPPP_open(sc);
  170. if(ret < 0)
  171. printk("%s: syncPPP open failed: %d\n", sc->name, ret);
  172. break;
  173. case LMC_RAW: /* We're about to start getting packets! */
  174. break;
  175. default:
  176. break;
  177. }
  178. lmc_trace(sc->lmc_device, "lmc_proto_open out");
  179. }
  180. // close
  181. void lmc_proto_close(lmc_softc_t *sc) /*FOLD00*/
  182. {
  183. lmc_trace(sc->lmc_device, "lmc_proto_close in");
  184. switch(sc->if_type){
  185. case LMC_PPP:
  186. SPPP_close(sc);
  187. break;
  188. case LMC_RAW: /* Interface going down */
  189. break;
  190. default:
  191. break;
  192. }
  193. lmc_trace(sc->lmc_device, "lmc_proto_close out");
  194. }
  195. unsigned short lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
  196. {
  197. lmc_trace(sc->lmc_device, "lmc_proto_type in");
  198. switch(sc->if_type){
  199. case LMC_PPP:
  200. return htons(ETH_P_WAN_PPP);
  201. break;
  202. case LMC_NET:
  203. return htons(ETH_P_802_2);
  204. break;
  205. case LMC_RAW: /* Packet type for skbuff kind of useless */
  206. return htons(ETH_P_802_2);
  207. break;
  208. default:
  209. printk(KERN_WARNING "%s: No protocol set for this interface, assuming 802.2 (which is wrong!!)\n", sc->name);
  210. return htons(ETH_P_802_2);
  211. break;
  212. }
  213. lmc_trace(sc->lmc_device, "lmc_proto_tye out");
  214. }
  215. void lmc_proto_netif(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
  216. {
  217. lmc_trace(sc->lmc_device, "lmc_proto_netif in");
  218. switch(sc->if_type){
  219. case LMC_PPP:
  220. case LMC_NET:
  221. default:
  222. skb->dev->last_rx = jiffies;
  223. netif_rx(skb);
  224. break;
  225. case LMC_RAW:
  226. break;
  227. }
  228. lmc_trace(sc->lmc_device, "lmc_proto_netif out");
  229. }