lmc_proto.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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