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