Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/processor.h> /* Processor type for cache alignment. */ |
| 40 | #include <asm/io.h> |
| 41 | #include <asm/dma.h> |
| 42 | #include <linux/smp.h> |
| 43 | |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | // attach |
| 51 | void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/ |
| 52 | { |
| 53 | lmc_trace(sc->lmc_device, "lmc_proto_attach in"); |
| 54 | switch(sc->if_type){ |
| 55 | case LMC_PPP: |
| 56 | { |
| 57 | struct net_device *dev = sc->lmc_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | dev->do_ioctl = lmc_ioctl; |
| 59 | } |
| 60 | break; |
| 61 | case LMC_NET: |
| 62 | { |
| 63 | struct net_device *dev = sc->lmc_device; |
| 64 | /* |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 65 | * They set a few basics because they don't use HDLC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | */ |
| 67 | dev->flags |= IFF_POINTOPOINT; |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | dev->hard_header_len = 0; |
| 70 | dev->addr_len = 0; |
| 71 | } |
| 72 | case LMC_RAW: /* Setup the task queue, maybe we should notify someone? */ |
| 73 | { |
| 74 | } |
| 75 | default: |
| 76 | break; |
| 77 | } |
| 78 | lmc_trace(sc->lmc_device, "lmc_proto_attach out"); |
| 79 | } |
| 80 | |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 81 | int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 83 | lmc_trace(sc->lmc_device, "lmc_proto_ioctl"); |
| 84 | if (sc->if_type == LMC_PPP) |
| 85 | return hdlc_ioctl(sc->lmc_device, ifr, cmd); |
| 86 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 89 | int lmc_proto_open(lmc_softc_t *sc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 91 | int ret = 0; |
| 92 | |
| 93 | lmc_trace(sc->lmc_device, "lmc_proto_open in"); |
| 94 | |
| 95 | if (sc->if_type == LMC_PPP) { |
| 96 | ret = hdlc_open(sc->lmc_device); |
| 97 | if (ret < 0) |
| 98 | printk(KERN_WARNING "%s: HDLC open failed: %d\n", |
| 99 | sc->name, ret); |
| 100 | } |
| 101 | |
| 102 | lmc_trace(sc->lmc_device, "lmc_proto_open out"); |
| 103 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 106 | void lmc_proto_close(lmc_softc_t *sc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 108 | lmc_trace(sc->lmc_device, "lmc_proto_close in"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 110 | if (sc->if_type == LMC_PPP) |
| 111 | hdlc_close(sc->lmc_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 113 | lmc_trace(sc->lmc_device, "lmc_proto_close out"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Al Viro | 90458401 | 2007-12-22 17:52:52 +0000 | [diff] [blame] | 116 | __be16 lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
| 118 | lmc_trace(sc->lmc_device, "lmc_proto_type in"); |
| 119 | switch(sc->if_type){ |
| 120 | case LMC_PPP: |
Krzysztof Hałasa | 64bef76 | 2008-07-02 20:46:21 +0200 | [diff] [blame] | 121 | return hdlc_type_trans(skb, sc->lmc_device); |
| 122 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | case LMC_NET: |
| 124 | return htons(ETH_P_802_2); |
| 125 | break; |
| 126 | case LMC_RAW: /* Packet type for skbuff kind of useless */ |
| 127 | return htons(ETH_P_802_2); |
| 128 | break; |
| 129 | default: |
| 130 | printk(KERN_WARNING "%s: No protocol set for this interface, assuming 802.2 (which is wrong!!)\n", sc->name); |
| 131 | return htons(ETH_P_802_2); |
| 132 | break; |
| 133 | } |
| 134 | lmc_trace(sc->lmc_device, "lmc_proto_tye out"); |
| 135 | |
| 136 | } |
| 137 | |
| 138 | void lmc_proto_netif(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/ |
| 139 | { |
| 140 | lmc_trace(sc->lmc_device, "lmc_proto_netif in"); |
| 141 | switch(sc->if_type){ |
| 142 | case LMC_PPP: |
| 143 | case LMC_NET: |
| 144 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | netif_rx(skb); |
| 146 | break; |
| 147 | case LMC_RAW: |
| 148 | break; |
| 149 | } |
| 150 | lmc_trace(sc->lmc_device, "lmc_proto_netif out"); |
| 151 | } |