WAN: Port LMC driver to generic HDLC

Signed-off-by: Krzysztof Hałasa <khc@pm.waw.pl>
This commit is contained in:
Krzysztof Hałasa 2008-07-02 20:46:21 +02:00
parent 52e8a6a2d8
commit 64bef7630a
8 changed files with 364 additions and 652 deletions

View file

@ -61,7 +61,7 @@ config COSA
#
config LANMEDIA
tristate "LanMedia Corp. SSI/V.35, T1/E1, HSSI, T3 boards"
depends on PCI && VIRT_TO_BUS
depends on PCI && VIRT_TO_BUS && HDLC
---help---
Driver for the following Lan Media family of serial boards:
@ -78,9 +78,8 @@ config LANMEDIA
- LMC 5245 board connects directly to a T3 circuit saving the
additional external hardware.
To change setting such as syncPPP vs Cisco HDLC or clock source you
will need lmcctl. It is available at <ftp://ftp.lanmedia.com/>
(broken link).
To change setting such as clock source you will need lmcctl.
It is available at <ftp://ftp.lanmedia.com/> (broken link).
To compile this driver as a module, choose M here: the
module will be called lmc.

View file

@ -26,7 +26,6 @@ obj-$(CONFIG_SEALEVEL_4021) += z85230.o sealevel.o
obj-$(CONFIG_COSA) += cosa.o
obj-$(CONFIG_FARSYNC) += farsync.o
obj-$(CONFIG_DSCC4) += dscc4.o
obj-$(CONFIG_LANMEDIA) += syncppp.o
obj-$(CONFIG_X25_ASY) += x25_asy.o
obj-$(CONFIG_LANMEDIA) += lmc/

View file

@ -61,7 +61,7 @@
/*
* IFTYPE defines
*/
#define LMC_PPP 1 /* use sppp interface */
#define LMC_PPP 1 /* use generic HDLC interface */
#define LMC_NET 2 /* use direct net interface */
#define LMC_RAW 3 /* use direct net interface */

File diff suppressed because it is too large Load diff

View file

@ -425,7 +425,7 @@ lmc_ds3_set_scram (lmc_softc_t * const sc, int ie)
static int
lmc_ds3_get_link_status (lmc_softc_t * const sc)
{
u_int16_t link_status, link_status_11;
u16 link_status, link_status_11;
int ret = 1;
lmc_mii_writereg (sc, 0, 17, 7);
@ -447,7 +447,7 @@ lmc_ds3_get_link_status (lmc_softc_t * const sc)
(link_status & LMC_FRAMER_REG0_OOFS)){
ret = 0;
if(sc->last_led_err[3] != 1){
u16 r1;
u16 r1;
lmc_mii_writereg (sc, 0, 17, 01); /* Turn on Xbit error as our cisco does */
r1 = lmc_mii_readreg (sc, 0, 18);
r1 &= 0xfe;
@ -460,7 +460,7 @@ lmc_ds3_get_link_status (lmc_softc_t * const sc)
else {
lmc_led_off(sc, LMC_DS3_LED3); /* turn on red LED */
if(sc->last_led_err[3] == 1){
u16 r1;
u16 r1;
lmc_mii_writereg (sc, 0, 17, 01); /* Turn off Xbit error */
r1 = lmc_mii_readreg (sc, 0, 18);
r1 |= 0x01;
@ -538,20 +538,19 @@ lmc_ds3_watchdog (lmc_softc_t * const sc)
* SSI methods
*/
static void
lmc_ssi_init (lmc_softc_t * const sc)
static void lmc_ssi_init(lmc_softc_t * const sc)
{
u_int16_t mii17;
int cable;
u16 mii17;
int cable;
sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1000;
sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1000;
mii17 = lmc_mii_readreg (sc, 0, 17);
mii17 = lmc_mii_readreg(sc, 0, 17);
cable = (mii17 & LMC_MII17_SSI_CABLE_MASK) >> LMC_MII17_SSI_CABLE_SHIFT;
sc->ictl.cable_type = cable;
cable = (mii17 & LMC_MII17_SSI_CABLE_MASK) >> LMC_MII17_SSI_CABLE_SHIFT;
sc->ictl.cable_type = cable;
lmc_gpio_mkoutput (sc, LMC_GEP_SSI_TXCLOCK);
lmc_gpio_mkoutput(sc, LMC_GEP_SSI_TXCLOCK);
}
static void
@ -679,11 +678,11 @@ lmc_ssi_set_speed (lmc_softc_t * const sc, lmc_ctl_t * ctl)
static int
lmc_ssi_get_link_status (lmc_softc_t * const sc)
{
u_int16_t link_status;
u16 link_status;
u_int32_t ticks;
int ret = 1;
int hw_hdsk = 1;
/*
* missing CTS? Hmm. If we require CTS on, we may never get the
* link to come up, so omit it in this test.
@ -718,9 +717,9 @@ lmc_ssi_get_link_status (lmc_softc_t * const sc)
}
else if (ticks == 0 ) { /* no clock found ? */
ret = 0;
if(sc->last_led_err[3] != 1){
sc->stats.tx_lossOfClockCnt++;
printk(KERN_WARNING "%s: Lost Clock, Link Down\n", sc->name);
if (sc->last_led_err[3] != 1) {
sc->extra_stats.tx_lossOfClockCnt++;
printk(KERN_WARNING "%s: Lost Clock, Link Down\n", sc->name);
}
sc->last_led_err[3] = 1;
lmc_led_on (sc, LMC_MII16_LED3); /* turn ON red LED */
@ -885,19 +884,13 @@ write_av9110 (lmc_softc_t * sc, u_int32_t n, u_int32_t m, u_int32_t v,
| LMC_GEP_SSI_GENERATOR));
}
static void
lmc_ssi_watchdog (lmc_softc_t * const sc)
static void lmc_ssi_watchdog(lmc_softc_t * const sc)
{
u_int16_t mii17 = lmc_mii_readreg (sc, 0, 17);
if (((mii17 >> 3) & 7) == 7)
{
lmc_led_off (sc, LMC_MII16_LED2);
}
else
{
lmc_led_on (sc, LMC_MII16_LED2);
}
u16 mii17 = lmc_mii_readreg(sc, 0, 17);
if (((mii17 >> 3) & 7) == 7)
lmc_led_off(sc, LMC_MII16_LED2);
else
lmc_led_on(sc, LMC_MII16_LED2);
}
/*
@ -927,7 +920,7 @@ lmc_t1_read (lmc_softc_t * const sc, int a)
static void
lmc_t1_init (lmc_softc_t * const sc)
{
u_int16_t mii16;
u16 mii16;
int i;
sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1200;
@ -1026,7 +1019,7 @@ lmc_t1_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
*/ static int
lmc_t1_get_link_status (lmc_softc_t * const sc)
{
u_int16_t link_status;
u16 link_status;
int ret = 1;
/* LMC5245 (DS3) & LMC1200 (DS1) LED definitions

View file

@ -36,9 +36,6 @@
#include <linux/workqueue.h>
#include <linux/proc_fs.h>
#include <linux/bitops.h>
#include <net/syncppp.h>
#include <asm/processor.h> /* Processor type for cache alignment. */
#include <asm/io.h>
#include <asm/dma.h>
@ -50,48 +47,6 @@
#include "lmc_ioctl.h"
#include "lmc_proto.h"
/*
* The compile-time variable SPPPSTUP causes the module to be
* compiled without referencing any of the sync ppp routines.
*/
#ifdef SPPPSTUB
#define SPPP_detach(d) (void)0
#define SPPP_open(d) 0
#define SPPP_reopen(d) (void)0
#define SPPP_close(d) (void)0
#define SPPP_attach(d) (void)0
#define SPPP_do_ioctl(d,i,c) -EOPNOTSUPP
#else
#define SPPP_attach(x) sppp_attach((x)->pd)
#define SPPP_detach(x) sppp_detach((x)->pd->dev)
#define SPPP_open(x) sppp_open((x)->pd->dev)
#define SPPP_reopen(x) sppp_reopen((x)->pd->dev)
#define SPPP_close(x) sppp_close((x)->pd->dev)
#define SPPP_do_ioctl(x, y, z) sppp_do_ioctl((x)->pd->dev, (y), (z))
#endif
// init
void lmc_proto_init(lmc_softc_t *sc) /*FOLD00*/
{
lmc_trace(sc->lmc_device, "lmc_proto_init in");
switch(sc->if_type){
case LMC_PPP:
sc->pd = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
if (!sc->pd) {
printk("lmc_proto_init(): kmalloc failure!\n");
return;
}
sc->pd->dev = sc->lmc_device;
sc->if_ptr = sc->pd;
break;
case LMC_RAW:
break;
default:
break;
}
lmc_trace(sc->lmc_device, "lmc_proto_init out");
}
// attach
void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
{
@ -100,7 +55,6 @@ void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
case LMC_PPP:
{
struct net_device *dev = sc->lmc_device;
SPPP_attach(sc);
dev->do_ioctl = lmc_ioctl;
}
break;
@ -108,7 +62,7 @@ void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
{
struct net_device *dev = sc->lmc_device;
/*
* They set a few basics because they don't use sync_ppp
* They set a few basics because they don't use HDLC
*/
dev->flags |= IFF_POINTOPOINT;
@ -124,88 +78,39 @@ void lmc_proto_attach(lmc_softc_t *sc) /*FOLD00*/
lmc_trace(sc->lmc_device, "lmc_proto_attach out");
}
// detach
void lmc_proto_detach(lmc_softc_t *sc) /*FOLD00*/
int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd)
{
switch(sc->if_type){
case LMC_PPP:
SPPP_detach(sc);
break;
case LMC_RAW: /* Tell someone we're detaching? */
break;
default:
break;
}
lmc_trace(sc->lmc_device, "lmc_proto_ioctl");
if (sc->if_type == LMC_PPP)
return hdlc_ioctl(sc->lmc_device, ifr, cmd);
return -EOPNOTSUPP;
}
// reopen
void lmc_proto_reopen(lmc_softc_t *sc) /*FOLD00*/
int lmc_proto_open(lmc_softc_t *sc)
{
lmc_trace(sc->lmc_device, "lmc_proto_reopen in");
switch(sc->if_type){
case LMC_PPP:
SPPP_reopen(sc);
break;
case LMC_RAW: /* Reset the interface after being down, prerape to receive packets again */
break;
default:
break;
}
lmc_trace(sc->lmc_device, "lmc_proto_reopen out");
int ret = 0;
lmc_trace(sc->lmc_device, "lmc_proto_open in");
if (sc->if_type == LMC_PPP) {
ret = hdlc_open(sc->lmc_device);
if (ret < 0)
printk(KERN_WARNING "%s: HDLC open failed: %d\n",
sc->name, ret);
}
lmc_trace(sc->lmc_device, "lmc_proto_open out");
return ret;
}
// ioctl
int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd) /*FOLD00*/
void lmc_proto_close(lmc_softc_t *sc)
{
lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
switch(sc->if_type){
case LMC_PPP:
return SPPP_do_ioctl (sc, ifr, cmd);
break;
default:
return -EOPNOTSUPP;
break;
}
lmc_trace(sc->lmc_device, "lmc_proto_ioctl out");
}
lmc_trace(sc->lmc_device, "lmc_proto_close in");
// open
void lmc_proto_open(lmc_softc_t *sc) /*FOLD00*/
{
int ret;
if (sc->if_type == LMC_PPP)
hdlc_close(sc->lmc_device);
lmc_trace(sc->lmc_device, "lmc_proto_open in");
switch(sc->if_type){
case LMC_PPP:
ret = SPPP_open(sc);
if(ret < 0)
printk("%s: syncPPP open failed: %d\n", sc->name, ret);
break;
case LMC_RAW: /* We're about to start getting packets! */
break;
default:
break;
}
lmc_trace(sc->lmc_device, "lmc_proto_open out");
}
// close
void lmc_proto_close(lmc_softc_t *sc) /*FOLD00*/
{
lmc_trace(sc->lmc_device, "lmc_proto_close in");
switch(sc->if_type){
case LMC_PPP:
SPPP_close(sc);
break;
case LMC_RAW: /* Interface going down */
break;
default:
break;
}
lmc_trace(sc->lmc_device, "lmc_proto_close out");
lmc_trace(sc->lmc_device, "lmc_proto_close out");
}
__be16 lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
@ -213,8 +118,8 @@ __be16 lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
lmc_trace(sc->lmc_device, "lmc_proto_type in");
switch(sc->if_type){
case LMC_PPP:
return htons(ETH_P_WAN_PPP);
break;
return hdlc_type_trans(skb, sc->lmc_device);
break;
case LMC_NET:
return htons(ETH_P_802_2);
break;
@ -245,4 +150,3 @@ void lmc_proto_netif(lmc_softc_t *sc, struct sk_buff *skb) /*FOLD00*/
}
lmc_trace(sc->lmc_device, "lmc_proto_netif out");
}

View file

@ -1,16 +1,18 @@
#ifndef _LMC_PROTO_H_
#define _LMC_PROTO_H_
void lmc_proto_init(lmc_softc_t *sc);
#include <linux/hdlc.h>
void lmc_proto_attach(lmc_softc_t *sc);
void lmc_proto_detach(lmc_softc_t *sc);
void lmc_proto_reopen(lmc_softc_t *sc);
int lmc_proto_ioctl(lmc_softc_t *sc, struct ifreq *ifr, int cmd);
void lmc_proto_open(lmc_softc_t *sc);
int lmc_proto_open(lmc_softc_t *sc);
void lmc_proto_close(lmc_softc_t *sc);
__be16 lmc_proto_type(lmc_softc_t *sc, struct sk_buff *skb);
void lmc_proto_netif(lmc_softc_t *sc, struct sk_buff *skb);
int lmc_skb_rawpackets(char *buf, char **start, off_t offset, int len, int unused);
static inline lmc_softc_t* dev_to_sc(struct net_device *dev)
{
return (lmc_softc_t *)dev_to_hdlc(dev)->priv;
}
#endif

View file

@ -1,8 +1,6 @@
#ifndef _LMC_VAR_H_
#define _LMC_VAR_H_
/* $Id: lmc_var.h,v 1.17 2000/04/06 12:16:47 asj Exp $ */
/*
* Copyright (c) 1997-2000 LAN Media Corporation (LMC)
* All rights reserved. www.lanmedia.com
@ -19,23 +17,6 @@
#include <linux/timer.h>
#ifndef __KERNEL__
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;
typedef signed long long s64;
typedef unsigned long long u64;
#define BITS_PER_LONG 32
#endif
/*
* basic definitions used in lmc include files
*/
@ -45,9 +26,6 @@ typedef struct lmc___media lmc_media_t;
typedef struct lmc___ctl lmc_ctl_t;
#define lmc_csrptr_t unsigned long
#define u_int16_t u16
#define u_int8_t u8
#define tulip_uint32_t u32
#define LMC_REG_RANGE 0x80
@ -244,46 +222,8 @@ struct lmc___media {
#define STATCHECK 0xBEEFCAFE
/* Included in this structure are first
* - standard net_device_stats
* - some other counters used for debug and driver performance
* evaluation -baz
*/
struct lmc_statistics
struct lmc_extra_statistics
{
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes;
unsigned long tx_bytes;
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long multicast; /* multicast packets received */
unsigned long collisions;
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
/* for cslip etc */
unsigned long rx_compressed;
unsigned long tx_compressed;
/* -------------------------------------
* Custom stats & counters follow -baz */
u_int32_t version_size;
u_int32_t lmc_cardtype;
@ -325,27 +265,26 @@ struct lmc_statistics
u_int32_t check;
};
typedef struct lmc_xinfo {
u_int32_t Magic0; /* BEEFCAFE */
u_int32_t Magic0; /* BEEFCAFE */
u_int32_t PciCardType;
u_int32_t PciSlotNumber; /* PCI slot number */
u_int32_t PciCardType;
u_int32_t PciSlotNumber; /* PCI slot number */
u_int16_t DriverMajorVersion;
u_int16_t DriverMinorVersion;
u_int16_t DriverSubVersion;
u16 DriverMajorVersion;
u16 DriverMinorVersion;
u16 DriverSubVersion;
u_int16_t XilinxRevisionNumber;
u_int16_t MaxFrameSize;
u16 XilinxRevisionNumber;
u16 MaxFrameSize;
u_int16_t t1_alarm1_status;
u_int16_t t1_alarm2_status;
u16 t1_alarm1_status;
u16 t1_alarm2_status;
int link_status;
u_int32_t mii_reg16;
int link_status;
u_int32_t mii_reg16;
u_int32_t Magic1; /* DEADBEEF */
u_int32_t Magic1; /* DEADBEEF */
} LMC_XINFO;
@ -353,11 +292,10 @@ typedef struct lmc_xinfo {
* forward decl
*/
struct lmc___softc {
void *if_ptr; /* General purpose pointer (used by SPPP) */
char *name;
u8 board_idx;
struct lmc_statistics stats;
struct net_device *lmc_device;
struct lmc_extra_statistics extra_stats;
struct net_device *lmc_device;
int hang, rxdesc, bad_packet, some_counter;
u_int32_t txgo;
@ -381,7 +319,7 @@ struct lmc___softc {
unsigned int lmc_taint_tx, lmc_taint_rx;
int lmc_tx_start, lmc_txfull;
int lmc_txbusy;
u_int16_t lmc_miireg16;
u16 lmc_miireg16;
int lmc_ok;
int last_link_status;
int lmc_cardtype;
@ -408,8 +346,7 @@ struct lmc___softc {
u32 num_int;
spinlock_t lmc_lock;
u_int16_t if_type; /* PPP or NET */
struct ppp_device *pd;
u16 if_type; /* HDLC/PPP or NET */
/* Failure cases */
u8 failed_ring;
@ -525,46 +462,9 @@ struct lmc___softc {
#define LMC_ADAP_SSI 4
#define LMC_ADAP_T1 5
#define HDLC_HDR_LEN 4
#define HDLC_ADDR_LEN 1
#define HDLC_SLARP 0x8035
#define LMC_MTU 1500
#define SLARP_LINECHECK 2
#define LMC_CRC_LEN_16 2 /* 16-bit CRC */
#define LMC_CRC_LEN_32 4
#ifdef LMC_HDLC
/* definition of an hdlc header. */
struct hdlc_hdr
{
u8 address;
u8 control;
u16 type;
};
/* definition of a slarp header. */
struct slarp
{
long code;
union sl
{
struct
{
ulong address;
ulong mask;
ushort unused;
} add;
struct
{
ulong mysequence;
ulong yoursequence;
ushort reliability;
ulong time;
} chk;
} t;
};
#endif /* LMC_HDLC */
#endif /* _LMC_VAR_H_ */