1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
4*4882a593Smuzhiyun * All rights reserved. www.lanmedia.com
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * This code is written by:
7*4882a593Smuzhiyun * Andrew Stanley-Jones (asj@cban.com)
8*4882a593Smuzhiyun * Rob Braun (bbraun@vix.com),
9*4882a593Smuzhiyun * Michael Graff (explorer@vix.com) and
10*4882a593Smuzhiyun * Matt Thomas (matt@3am-software.com).
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * With Help By:
13*4882a593Smuzhiyun * David Boggs
14*4882a593Smuzhiyun * Ron Crane
15*4882a593Smuzhiyun * Allan Cox
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
18*4882a593Smuzhiyun */
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include <linux/kernel.h>
21*4882a593Smuzhiyun #include <linux/string.h>
22*4882a593Smuzhiyun #include <linux/timer.h>
23*4882a593Smuzhiyun #include <linux/ptrace.h>
24*4882a593Smuzhiyun #include <linux/errno.h>
25*4882a593Smuzhiyun #include <linux/ioport.h>
26*4882a593Smuzhiyun #include <linux/interrupt.h>
27*4882a593Smuzhiyun #include <linux/in.h>
28*4882a593Smuzhiyun #include <linux/if_arp.h>
29*4882a593Smuzhiyun #include <linux/netdevice.h>
30*4882a593Smuzhiyun #include <linux/etherdevice.h>
31*4882a593Smuzhiyun #include <linux/skbuff.h>
32*4882a593Smuzhiyun #include <linux/inet.h>
33*4882a593Smuzhiyun #include <linux/workqueue.h>
34*4882a593Smuzhiyun #include <linux/proc_fs.h>
35*4882a593Smuzhiyun #include <linux/bitops.h>
36*4882a593Smuzhiyun #include <asm/processor.h> /* Processor type for cache alignment. */
37*4882a593Smuzhiyun #include <asm/io.h>
38*4882a593Smuzhiyun #include <asm/dma.h>
39*4882a593Smuzhiyun #include <linux/smp.h>
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #include "lmc.h"
42*4882a593Smuzhiyun #include "lmc_var.h"
43*4882a593Smuzhiyun #include "lmc_debug.h"
44*4882a593Smuzhiyun #include "lmc_ioctl.h"
45*4882a593Smuzhiyun #include "lmc_proto.h"
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun // attach
lmc_proto_attach(lmc_softc_t * sc)48*4882a593Smuzhiyun void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun if (sc->if_type == LMC_NET) {
51*4882a593Smuzhiyun struct net_device *dev = sc->lmc_device;
52*4882a593Smuzhiyun /*
53*4882a593Smuzhiyun * They set a few basics because they don't use HDLC
54*4882a593Smuzhiyun */
55*4882a593Smuzhiyun dev->flags |= IFF_POINTOPOINT;
56*4882a593Smuzhiyun dev->hard_header_len = 0;
57*4882a593Smuzhiyun dev->addr_len = 0;
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
lmc_proto_ioctl(lmc_softc_t * sc,struct ifreq * ifr,int cmd)61*4882a593Smuzhiyun int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun if (sc->if_type == LMC_PPP)
64*4882a593Smuzhiyun return hdlc_ioctl(sc->lmc_device, ifr, cmd);
65*4882a593Smuzhiyun return -EOPNOTSUPP;
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun
lmc_proto_open(lmc_softc_t * sc)68*4882a593Smuzhiyun int lmc_proto_open(lmc_softc_t *sc)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun int ret = 0;
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun if (sc->if_type == LMC_PPP) {
73*4882a593Smuzhiyun ret = hdlc_open(sc->lmc_device);
74*4882a593Smuzhiyun if (ret < 0)
75*4882a593Smuzhiyun printk(KERN_WARNING "%s: HDLC open failed: %d\n",
76*4882a593Smuzhiyun sc->name, ret);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun return ret;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun
lmc_proto_close(lmc_softc_t * sc)81*4882a593Smuzhiyun void lmc_proto_close(lmc_softc_t *sc)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun if (sc->if_type == LMC_PPP)
84*4882a593Smuzhiyun hdlc_close(sc->lmc_device);
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
lmc_proto_type(lmc_softc_t * sc,struct sk_buff * skb)87*4882a593Smuzhiyun __be16 lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun switch(sc->if_type){
90*4882a593Smuzhiyun case LMC_PPP:
91*4882a593Smuzhiyun return hdlc_type_trans(skb, sc->lmc_device);
92*4882a593Smuzhiyun case LMC_NET:
93*4882a593Smuzhiyun return htons(ETH_P_802_2);
94*4882a593Smuzhiyun case LMC_RAW: /* Packet type for skbuff kind of useless */
95*4882a593Smuzhiyun return htons(ETH_P_802_2);
96*4882a593Smuzhiyun default:
97*4882a593Smuzhiyun printk(KERN_WARNING "%s: No protocol set for this interface, assuming 802.2 (which is wrong!!)\n", sc->name);
98*4882a593Smuzhiyun return htons(ETH_P_802_2);
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
lmc_proto_netif(lmc_softc_t * sc,struct sk_buff * skb)102*4882a593Smuzhiyun void lmc_proto_netif(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun switch(sc->if_type){
105*4882a593Smuzhiyun case LMC_PPP:
106*4882a593Smuzhiyun case LMC_NET:
107*4882a593Smuzhiyun default:
108*4882a593Smuzhiyun netif_rx(skb);
109*4882a593Smuzhiyun break;
110*4882a593Smuzhiyun case LMC_RAW:
111*4882a593Smuzhiyun break;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun }
114