Initial commit
[wrt350n-kernel.git] / drivers / net / wan / lmc / lmc_proto.c
blob85315758198d901d9e2fdb02bbd185f5d878c156
1 /*
2 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
3 * All rights reserved. www.lanmedia.com
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).
11 * With Help By:
12 * David Boggs
13 * Ron Crane
14 * Allan Cox
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.
19 * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
22 #include <linux/kernel.h>
23 #include <linux/string.h>
24 #include <linux/timer.h>
25 #include <linux/ptrace.h>
26 #include <linux/errno.h>
27 #include <linux/ioport.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.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>
40 #include <net/syncppp.h>
42 #include <asm/processor.h> /* Processor type for cache alignment. */
43 #include <asm/io.h>
44 #include <asm/dma.h>
45 #include <linux/smp.h>
47 #include "lmc.h"
48 #include "lmc_var.h"
49 #include "lmc_debug.h"
50 #include "lmc_ioctl.h"
51 #include "lmc_proto.h"
54 * The compile-time variable SPPPSTUP causes the module to be
55 * compiled without referencing any of the sync ppp routines.
57 #ifdef SPPPSTUB
58 #define SPPP_detach(d) (void)0
59 #define SPPP_open(d) 0
60 #define SPPP_reopen(d) (void)0
61 #define SPPP_close(d) (void)0
62 #define SPPP_attach(d) (void)0
63 #define SPPP_do_ioctl(d,i,c) -EOPNOTSUPP
64 #else
65 #define SPPP_attach(x) sppp_attach((x)->pd)
66 #define SPPP_detach(x) sppp_detach((x)->pd->dev)
67 #define SPPP_open(x) sppp_open((x)->pd->dev)
68 #define SPPP_reopen(x) sppp_reopen((x)->pd->dev)
69 #define SPPP_close(x) sppp_close((x)->pd->dev)
70 #define SPPP_do_ioctl(x, y, z) sppp_do_ioctl((x)->pd->dev, (y), (z))
71 #endif
73 // init
74 void lmc_proto_init(lmc_softc_t *sc) /*FOLD00*/
76 lmc_trace(sc->lmc_device, "lmc_proto_init in");
77 switch(sc->if_type){
78 case LMC_PPP:
79 sc->pd = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
80 if (!sc->pd) {
81 printk("lmc_proto_init(): kmalloc failure!\n");
82 return;
84 sc->pd->dev = sc->lmc_device;
85 sc->if_ptr = sc->pd;
86 break;
87 case LMC_RAW:
88 break;
89 default:
90 break;
92 lmc_trace(sc->lmc_device, "lmc_proto_init out");
95 // attach
96 void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
98 lmc_trace(sc->lmc_device, "lmc_proto_attach in");
99 switch(sc->if_type){
100 case LMC_PPP:
102 struct net_device *dev = sc->lmc_device;
103 SPPP_attach(sc);
104 dev->do_ioctl = lmc_ioctl;
106 break;
107 case LMC_NET:
109 struct net_device *dev = sc->lmc_device;
111 * They set a few basics because they don't use sync_ppp
113 dev->flags |= IFF_POINTOPOINT;
115 dev->hard_header_len = 0;
116 dev->addr_len = 0;
118 case LMC_RAW: /* Setup the task queue, maybe we should notify someone? */
121 default:
122 break;
124 lmc_trace(sc->lmc_device, "lmc_proto_attach out");
127 // detach
128 void lmc_proto_detach(lmc_softc_t *sc) /*FOLD00*/
130 switch(sc->if_type){
131 case LMC_PPP:
132 SPPP_detach(sc);
133 break;
134 case LMC_RAW: /* Tell someone we're detaching? */
135 break;
136 default:
137 break;
142 // reopen
143 void lmc_proto_reopen(lmc_softc_t *sc) /*FOLD00*/
145 lmc_trace(sc->lmc_device, "lmc_proto_reopen in");
146 switch(sc->if_type){
147 case LMC_PPP:
148 SPPP_reopen(sc);
149 break;
150 case LMC_RAW: /* Reset the interface after being down, prerape to receive packets again */
151 break;
152 default:
153 break;
155 lmc_trace(sc->lmc_device, "lmc_proto_reopen out");
159 // ioctl
160 int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd) /*FOLD00*/
162 lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
163 switch(sc->if_type){
164 case LMC_PPP:
165 return SPPP_do_ioctl (sc, ifr, cmd);
166 break;
167 default:
168 return -EOPNOTSUPP;
169 break;
171 lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
174 // open
175 void lmc_proto_open(lmc_softc_t *sc) /*FOLD00*/
177 int ret;
179 lmc_trace(sc->lmc_device, "lmc_proto_open in");
180 switch(sc->if_type){
181 case LMC_PPP:
182 ret = SPPP_open(sc);
183 if(ret < 0)
184 printk("%s: syncPPP open failed: %d\n", sc->name, ret);
185 break;
186 case LMC_RAW: /* We're about to start getting packets! */
187 break;
188 default:
189 break;
191 lmc_trace(sc->lmc_device, "lmc_proto_open out");
194 // close
196 void lmc_proto_close(lmc_softc_t *sc) /*FOLD00*/
198 lmc_trace(sc->lmc_device, "lmc_proto_close in");
199 switch(sc->if_type){
200 case LMC_PPP:
201 SPPP_close(sc);
202 break;
203 case LMC_RAW: /* Interface going down */
204 break;
205 default:
206 break;
208 lmc_trace(sc->lmc_device, "lmc_proto_close out");
211 __be16 lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
213 lmc_trace(sc->lmc_device, "lmc_proto_type in");
214 switch(sc->if_type){
215 case LMC_PPP:
216 return htons(ETH_P_WAN_PPP);
217 break;
218 case LMC_NET:
219 return htons(ETH_P_802_2);
220 break;
221 case LMC_RAW: /* Packet type for skbuff kind of useless */
222 return htons(ETH_P_802_2);
223 break;
224 default:
225 printk(KERN_WARNING "%s: No protocol set for this interface, assuming 802.2 (which is wrong!!)\n", sc->name);
226 return htons(ETH_P_802_2);
227 break;
229 lmc_trace(sc->lmc_device, "lmc_proto_tye out");
233 void lmc_proto_netif(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
235 lmc_trace(sc->lmc_device, "lmc_proto_netif in");
236 switch(sc->if_type){
237 case LMC_PPP:
238 case LMC_NET:
239 default:
240 skb->dev->last_rx = jiffies;
241 netif_rx(skb);
242 break;
243 case LMC_RAW:
244 break;
246 lmc_trace(sc->lmc_device, "lmc_proto_netif out");