Commit 6fcdf4fa authored by Paul Gortmaker's avatar Paul Gortmaker

wanrouter: delete now orphaned header content, files/drivers

The wanrouter support was identified earlier as unused for years,
and so the previous commit totally decoupled it from the kernel,
leaving the related wanrouter files present, but totally inert.

Here we take the final step in that cleanup, by doing a wholesale
removal of these files.  The two step process is used so that the
large deletion is decoupled from the git history of files that we
still care about.

The drivers deleted here all were dependent on the Kconfig setting
CONFIG_WAN_ROUTER_DRIVERS.

A stub wanrouter.h header (kernel & uapi) are left behind so that
drivers/isdn/i4l/isdn_x25iface.c continues to compile, and so that
we don't accidentally break userspace that expected these defines.

Cc: Joe Perches <joe@perches.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
parent a786a7c0
This diff is collapsed.
/*
* cycx_main.c Cyclades Cyclom 2X WAN Link Driver. Main module.
*
* Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
*
* Copyright: (c) 1998-2003 Arnaldo Carvalho de Melo
*
* Based on sdlamain.c by Gene Kozin <genek@compuserve.com> &
* Jaspreet Singh <jaspreet@sangoma.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
* Please look at the bitkeeper changelog (or any other scm tool that ends up
* importing bitkeeper changelog or that replaces bitkeeper in the future as
* main tool for linux development).
*
* 2001/05/09 acme Fix MODULE_DESC for debug, .bss nitpicks,
* some cleanups
* 2000/07/13 acme remove useless #ifdef MODULE and crap
* #if KERNEL_VERSION > blah
* 2000/07/06 acme __exit at cyclomx_cleanup
* 2000/04/02 acme dprintk and cycx_debug
* module_init/module_exit
* 2000/01/21 acme rename cyclomx_open to cyclomx_mod_inc_use_count
* and cyclomx_close to cyclomx_mod_dec_use_count
* 2000/01/08 acme cleanup
* 1999/11/06 acme cycx_down back to life (it needs to be
* called to iounmap the dpmbase)
* 1999/08/09 acme removed references to enable_tx_int
* use spinlocks instead of cli/sti in
* cyclomx_set_state
* 1999/05/19 acme works directly linked into the kernel
* init_waitqueue_head for 2.3.* kernel
* 1999/05/18 acme major cleanup (polling not needed), etc
* 1998/08/28 acme minor cleanup (ioctls for firmware deleted)
* queue_task activated
* 1998/08/08 acme Initial version.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/stddef.h> /* offsetof(), etc. */
#include <linux/errno.h> /* return codes */
#include <linux/string.h> /* inline memset(), etc. */
#include <linux/slab.h> /* kmalloc(), kfree() */
#include <linux/kernel.h> /* printk(), and other useful stuff */
#include <linux/module.h> /* support for loadable modules */
#include <linux/ioport.h> /* request_region(), release_region() */
#include <linux/wanrouter.h> /* WAN router definitions */
#include <linux/cyclomx.h> /* cyclomx common user API definitions */
#include <linux/init.h> /* __init (when not using as a module) */
#include <linux/interrupt.h>
unsigned int cycx_debug;
MODULE_AUTHOR("Arnaldo Carvalho de Melo");
MODULE_DESCRIPTION("Cyclom 2X Sync Card Driver.");
MODULE_LICENSE("GPL");
module_param(cycx_debug, int, 0);
MODULE_PARM_DESC(cycx_debug, "cyclomx debug level");
/* Defines & Macros */
#define CYCX_DRV_VERSION 0 /* version number */
#define CYCX_DRV_RELEASE 11 /* release (minor version) number */
#define CYCX_MAX_CARDS 1 /* max number of adapters */
#define CONFIG_CYCX_CARDS 1
/* Function Prototypes */
/* WAN link driver entry points */
static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf);
static int cycx_wan_shutdown(struct wan_device *wandev);
/* Miscellaneous functions */
static irqreturn_t cycx_isr(int irq, void *dev_id);
/* Global Data
* Note: All data must be explicitly initialized!!!
*/
/* private data */
static const char cycx_drvname[] = "cyclomx";
static const char cycx_fullname[] = "CYCLOM 2X(tm) Sync Card Driver";
static const char cycx_copyright[] = "(c) 1998-2003 Arnaldo Carvalho de Melo "
"<acme@conectiva.com.br>";
static int cycx_ncards = CONFIG_CYCX_CARDS;
static struct cycx_device *cycx_card_array; /* adapter data space */
/* Kernel Loadable Module Entry Points */
/*
* Module 'insert' entry point.
* o print announcement
* o allocate adapter data space
* o initialize static data
* o register all cards with WAN router
* o calibrate Cyclom 2X shared memory access delay.
*
* Return: 0 Ok
* < 0 error.
* Context: process
*/
static int __init cycx_init(void)
{
int cnt, err = -ENOMEM;
pr_info("%s v%u.%u %s\n",
cycx_fullname, CYCX_DRV_VERSION, CYCX_DRV_RELEASE,
cycx_copyright);
/* Verify number of cards and allocate adapter data space */
cycx_ncards = min_t(int, cycx_ncards, CYCX_MAX_CARDS);
cycx_ncards = max_t(int, cycx_ncards, 1);
cycx_card_array = kcalloc(cycx_ncards, sizeof(struct cycx_device), GFP_KERNEL);
if (!cycx_card_array)
goto out;
/* Register adapters with WAN router */
for (cnt = 0; cnt < cycx_ncards; ++cnt) {
struct cycx_device *card = &cycx_card_array[cnt];
struct wan_device *wandev = &card->wandev;
sprintf(card->devname, "%s%d", cycx_drvname, cnt + 1);
wandev->magic = ROUTER_MAGIC;
wandev->name = card->devname;
wandev->private = card;
wandev->setup = cycx_wan_setup;
wandev->shutdown = cycx_wan_shutdown;
err = register_wan_device(wandev);
if (err) {
pr_err("%s registration failed with error %d!\n",
card->devname, err);
break;
}
}
err = -ENODEV;
if (!cnt) {
kfree(cycx_card_array);
goto out;
}
err = 0;
cycx_ncards = cnt; /* adjust actual number of cards */
out: return err;
}
/*
* Module 'remove' entry point.
* o unregister all adapters from the WAN router
* o release all remaining system resources
*/
static void __exit cycx_exit(void)
{
int i = 0;
for (; i < cycx_ncards; ++i) {
struct cycx_device *card = &cycx_card_array[i];
unregister_wan_device(card->devname);
}
kfree(cycx_card_array);
}
/* WAN Device Driver Entry Points */
/*
* Setup/configure WAN link driver.
* o check adapter state
* o make sure firmware is present in configuration
* o allocate interrupt vector
* o setup Cyclom 2X hardware
* o call appropriate routine to perform protocol-specific initialization
*
* This function is called when router handles ROUTER_SETUP IOCTL. The
* configuration structure is in kernel memory (including extended data, if
* any).
*/
static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf)
{
int rc = -EFAULT;
struct cycx_device *card;
int irq;
/* Sanity checks */
if (!wandev || !wandev->private || !conf)
goto out;
card = wandev->private;
rc = -EBUSY;
if (wandev->state != WAN_UNCONFIGURED)
goto out;
rc = -EINVAL;
if (!conf->data_size || !conf->data) {
pr_err("%s: firmware not found in configuration data!\n",
wandev->name);
goto out;
}
if (conf->irq <= 0) {
pr_err("%s: can't configure without IRQ!\n", wandev->name);
goto out;
}
/* Allocate IRQ */
irq = conf->irq == 2 ? 9 : conf->irq; /* IRQ2 -> IRQ9 */
if (request_irq(irq, cycx_isr, 0, wandev->name, card)) {
pr_err("%s: can't reserve IRQ %d!\n", wandev->name, irq);
goto out;
}
/* Configure hardware, load firmware, etc. */
memset(&card->hw, 0, sizeof(card->hw));
card->hw.irq = irq;
card->hw.dpmsize = CYCX_WINDOWSIZE;
card->hw.fwid = CFID_X25_2X;
spin_lock_init(&card->lock);
init_waitqueue_head(&card->wait_stats);
rc = cycx_setup(&card->hw, conf->data, conf->data_size, conf->maddr);
if (rc)
goto out_irq;
/* Initialize WAN device data space */
wandev->irq = irq;
wandev->dma = wandev->ioport = 0;
wandev->maddr = (unsigned long)card->hw.dpmbase;
wandev->msize = card->hw.dpmsize;
wandev->hw_opt[2] = 0;
wandev->hw_opt[3] = card->hw.fwid;
/* Protocol-specific initialization */
switch (card->hw.fwid) {
#ifdef CONFIG_CYCLOMX_X25
case CFID_X25_2X:
rc = cycx_x25_wan_init(card, conf);
break;
#endif
default:
pr_err("%s: this firmware is not supported!\n", wandev->name);
rc = -EINVAL;
}
if (rc) {
cycx_down(&card->hw);
goto out_irq;
}
rc = 0;
out:
return rc;
out_irq:
free_irq(irq, card);
goto out;
}
/*
* Shut down WAN link driver.
* o shut down adapter hardware
* o release system resources.
*
* This function is called by the router when device is being unregistered or
* when it handles ROUTER_DOWN IOCTL.
*/
static int cycx_wan_shutdown(struct wan_device *wandev)
{
int ret = -EFAULT;
struct cycx_device *card;
/* sanity checks */
if (!wandev || !wandev->private)
goto out;
ret = 0;
if (wandev->state == WAN_UNCONFIGURED)
goto out;
card = wandev->private;
wandev->state = WAN_UNCONFIGURED;
cycx_down(&card->hw);
pr_info("%s: irq %d being freed!\n", wandev->name, wandev->irq);
free_irq(wandev->irq, card);
out: return ret;
}
/* Miscellaneous */
/*
* Cyclom 2X Interrupt Service Routine.
* o acknowledge Cyclom 2X hardware interrupt.
* o call protocol-specific interrupt service routine, if any.
*/
static irqreturn_t cycx_isr(int irq, void *dev_id)
{
struct cycx_device *card = dev_id;
if (card->wandev.state == WAN_UNCONFIGURED)
goto out;
if (card->in_isr) {
pr_warn("%s: interrupt re-entrancy on IRQ %d!\n",
card->devname, card->wandev.irq);
goto out;
}
if (card->isr)
card->isr(card);
return IRQ_HANDLED;
out:
return IRQ_NONE;
}
/* Set WAN device state. */
void cycx_set_state(struct cycx_device *card, int state)
{
unsigned long flags;
char *string_state = NULL;
spin_lock_irqsave(&card->lock, flags);
if (card->wandev.state != state) {
switch (state) {
case WAN_CONNECTED:
string_state = "connected!";
break;
case WAN_DISCONNECTED:
string_state = "disconnected!";
break;
}
pr_info("%s: link %s\n", card->devname, string_state);
card->wandev.state = state;
}
card->state_tick = jiffies;
spin_unlock_irqrestore(&card->lock, flags);
}
module_init(cycx_init);
module_exit(cycx_exit);
This diff is collapsed.
#ifndef _CYCLOMX_H
#define _CYCLOMX_H
/*
* cyclomx.h Cyclom 2X WAN Link Driver.
* User-level API definitions.
*
* Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
*
* Copyright: (c) 1998-2003 Arnaldo Carvalho de Melo
*
* Based on wanpipe.h by Gene Kozin <genek@compuserve.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
* 2000/07/13 acme remove crap #if KERNEL_VERSION > blah
* 2000/01/21 acme rename cyclomx_open to cyclomx_mod_inc_use_count
* and cyclomx_close to cyclomx_mod_dec_use_count
* 1999/05/19 acme wait_queue_head_t wait_stats(support for 2.3.*)
* 1999/01/03 acme judicious use of data types
* 1998/12/27 acme cleanup: PACKED not needed
* 1998/08/08 acme Version 0.0.1
*/
#include <linux/wanrouter.h>
#include <linux/spinlock.h>
#ifdef __KERNEL__
/* Kernel Interface */
#include <linux/cycx_drv.h> /* Cyclom 2X support module API definitions */
#include <linux/cycx_cfm.h> /* Cyclom 2X firmware module definitions */
#ifdef CONFIG_CYCLOMX_X25
#include <linux/cycx_x25.h>
#endif
/* Adapter Data Space.
* This structure is needed because we handle multiple cards, otherwise
* static data would do it.
*/
struct cycx_device {
char devname[WAN_DRVNAME_SZ + 1];/* card name */
struct cycx_hw hw; /* hardware configuration */
struct wan_device wandev; /* WAN device data space */
u32 state_tick; /* link state timestamp */
spinlock_t lock;
char in_isr; /* interrupt-in-service flag */
char buff_int_mode_unbusy; /* flag for carrying out dev_tint */
wait_queue_head_t wait_stats; /* to wait for the STATS indication */
void __iomem *mbox; /* -> mailbox */
void (*isr)(struct cycx_device* card); /* interrupt service routine */
int (*exec)(struct cycx_device* card, void* u_cmd, void* u_data);
union {
#ifdef CONFIG_CYCLOMX_X25
struct { /* X.25 specific data */
u32 lo_pvc;
u32 hi_pvc;
u32 lo_svc;
u32 hi_svc;
struct cycx_x25_stats stats;
spinlock_t lock;
u32 connection_keys;
} x;
#endif
} u;
};
/* Public Functions */
void cycx_set_state(struct cycx_device *card, int state);
#ifdef CONFIG_CYCLOMX_X25
int cycx_x25_wan_init(struct cycx_device *card, wandev_conf_t *conf);
#endif
#endif /* __KERNEL__ */
#endif /* _CYCLOMX_H */
/*
* cycx_drv.h CYCX Support Module. Kernel API Definitions.
*
* Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
*
* Copyright: (c) 1998-2003 Arnaldo Carvalho de Melo
*
* Based on sdladrv.h by Gene Kozin <genek@compuserve.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
* 1999/10/23 acme cycxhw_t cleanup
* 1999/01/03 acme more judicious use of data types...
* uclong, ucchar, etc deleted, the u8, u16, u32
* types are the portable way to go.
* 1999/01/03 acme judicious use of data types... u16, u32, etc
* 1998/12/26 acme FIXED_BUFFERS, CONF_OFFSET,
* removal of cy_read{bwl}
* 1998/08/08 acme Initial version.
*/
#ifndef _CYCX_DRV_H
#define _CYCX_DRV_H
#define CYCX_WINDOWSIZE 0x4000 /* default dual-port memory window size */
#define GEN_CYCX_INTR 0x02
#define RST_ENABLE 0x04
#define START_CPU 0x06
#define RST_DISABLE 0x08
#define FIXED_BUFFERS 0x08
#define TEST_PATTERN 0xaa55
#define CMD_OFFSET 0x20
#define CONF_OFFSET 0x0380
#define RESET_OFFSET 0x3c00 /* For reset file load */
#define DATA_OFFSET 0x0100 /* For code and data files load */
#define START_OFFSET 0x3ff0 /* 80186 starts here */
/**
* struct cycx_hw - Adapter hardware configuration
* @fwid - firmware ID
* @irq - interrupt request level
* @dpmbase - dual-port memory base
* @dpmsize - dual-port memory size
* @reserved - reserved for future use
*/
struct cycx_hw {
u32 fwid;
int irq;
void __iomem *dpmbase;
u32 dpmsize;
u32 reserved[5];
};
/* Function Prototypes */
extern int cycx_setup(struct cycx_hw *hw, void *sfm, u32 len, unsigned long base);
extern int cycx_down(struct cycx_hw *hw);
extern int cycx_peek(struct cycx_hw *hw, u32 addr, void *buf, u32 len);
extern int cycx_poke(struct cycx_hw *hw, u32 addr, void *buf, u32 len);
extern int cycx_exec(void __iomem *addr);
extern void cycx_intr(struct cycx_hw *hw);
#endif /* _CYCX_DRV_H */
/***************************************************************************** /*
* wanrouter.h Definitions for the WAN Multiprotocol Router Module. * wanrouter.h Legacy declarations kept around until X25 is removed
* This module provides API and common services for WAN Link */
* Drivers and is completely hardware-independent.
*
* Author: Nenad Corbic <ncorbic@sangoma.com>
* Gideon Hack
* Additions: Arnaldo Melo
*
* Copyright: (c) 1995-2000 Sangoma Technologies Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
* Jul 21, 2000 Nenad Corbic Added WAN_FT1_READY State
* Feb 24, 2000 Nenad Corbic Added support for socket based x25api
* Jan 28, 2000 Nenad Corbic Added support for the ASYNC protocol.
* Oct 04, 1999 Nenad Corbic Updated for 2.1.0 release
* Jun 02, 1999 Gideon Hack Added support for the S514 adapter.
* May 23, 1999 Arnaldo Melo Added local_addr to wanif_conf_t
* WAN_DISCONNECTING state added
* Jul 20, 1998 David Fong Added Inverse ARP options to 'wanif_conf_t'
* Jun 12, 1998 David Fong Added Cisco HDLC support.
* Dec 16, 1997 Jaspreet Singh Moved 'enable_IPX' and 'network_number' to
* 'wanif_conf_t'
* Dec 05, 1997 Jaspreet Singh Added 'pap', 'chap' to 'wanif_conf_t'
* Added 'authenticator' to 'wan_ppp_conf_t'
* Nov 06, 1997 Jaspreet Singh Changed Router Driver version to 1.1 from 1.0
* Oct 20, 1997 Jaspreet Singh Added 'cir','bc','be' and 'mc' to 'wanif_conf_t'
* Added 'enable_IPX' and 'network_number' to
* 'wan_device_t'. Also added defines for
* UDP PACKET TYPE, Interrupt test, critical values
* for RACE conditions.
* Oct 05, 1997 Jaspreet Singh Added 'dlci_num' and 'dlci[100]' to
* 'wan_fr_conf_t' to configure a list of dlci(s)
* for a NODE
* Jul 07, 1997 Jaspreet Singh Added 'ttl' to 'wandev_conf_t' & 'wan_device_t'
* May 29, 1997 Jaspreet Singh Added 'tx_int_enabled' to 'wan_device_t'
* May 21, 1997 Jaspreet Singh Added 'udp_port' to 'wan_device_t'
* Apr 25, 1997 Farhan Thawar Added 'udp_port' to 'wandev_conf_t'
* Jan 16, 1997 Gene Kozin router_devlist made public
* Jan 02, 1997 Gene Kozin Initial version (based on wanpipe.h).
*****************************************************************************/
#ifndef _ROUTER_H #ifndef _ROUTER_H
#define _ROUTER_H #define _ROUTER_H
#include <uapi/linux/wanrouter.h> #include <uapi/linux/wanrouter.h>
/****** Kernel Interface ****************************************************/
#include <linux/fs.h> /* support for device drivers */
#include <linux/proc_fs.h> /* proc filesystem pragmatics */
#include <linux/netdevice.h> /* support for network drivers */
#include <linux/spinlock.h> /* Support for SMP Locking */
/*----------------------------------------------------------------------------
* WAN device data space.
*/
struct wan_device {
unsigned magic; /* magic number */
char* name; /* -> WAN device name (ASCIIZ) */
void* private; /* -> driver private data */
unsigned config_id; /* Configuration ID */
/****** hardware configuration ******/
unsigned ioport; /* adapter I/O port base #1 */
char S514_cpu_no[1]; /* PCI CPU Number */
unsigned char S514_slot_no; /* PCI Slot Number */
unsigned long maddr; /* dual-port memory address */
unsigned msize; /* dual-port memory size */
int irq; /* interrupt request level */
int dma; /* DMA request level */
unsigned bps; /* data transfer rate */
unsigned mtu; /* max physical transmit unit size */
unsigned udp_port; /* UDP port for management */
unsigned char ttl; /* Time To Live for UDP security */
unsigned enable_tx_int; /* Transmit Interrupt enabled or not */
char interface; /* RS-232/V.35, etc. */
char clocking; /* external/internal */
char line_coding; /* NRZ/NRZI/FM0/FM1, etc. */
char station; /* DTE/DCE, primary/secondary, etc. */
char connection; /* permanent/switched/on-demand */
char signalling; /* Signalling RS232 or V35 */
char read_mode; /* read mode: Polling or interrupt */
char new_if_cnt; /* Number of interfaces per wanpipe */
char del_if_cnt; /* Number of times del_if() gets called */
unsigned char piggyback; /* Piggibacking a port */
unsigned hw_opt[4]; /* other hardware options */
/****** status and statistics *******/
char state; /* device state */
char api_status; /* device api status */
struct net_device_stats stats; /* interface statistics */
unsigned reserved[16]; /* reserved for future use */
unsigned long critical; /* critical section flag */
spinlock_t lock; /* Support for SMP Locking */
/****** device management methods ***/
int (*setup) (struct wan_device *wandev, wandev_conf_t *conf);
int (*shutdown) (struct wan_device *wandev);
int (*update) (struct wan_device *wandev);
int (*ioctl) (struct wan_device *wandev, unsigned cmd,
unsigned long arg);
int (*new_if)(struct wan_device *wandev, struct net_device *dev,
wanif_conf_t *conf);
int (*del_if)(struct wan_device *wandev, struct net_device *dev);
/****** maintained by the router ****/
struct wan_device* next; /* -> next device */
struct net_device* dev; /* list of network interfaces */
unsigned ndev; /* number of interfaces */
struct proc_dir_entry *dent; /* proc filesystem entry */
};
/* Public functions available for device drivers */
extern int register_wan_device(struct wan_device *wandev);
extern int unregister_wan_device(char *name);
/* Proc interface functions. These must not be called by the drivers! */
extern int wanrouter_proc_init(void);
extern void wanrouter_proc_cleanup(void);
extern int wanrouter_proc_add(struct wan_device *wandev);
extern int wanrouter_proc_delete(struct wan_device *wandev);
extern long wanrouter_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
/* Public Data */
/* list of registered devices */
extern struct wan_device *wanrouter_router_devlist;
#endif /* _ROUTER_H */ #endif /* _ROUTER_H */
This diff is collapsed.
#
# Configuration for WAN router
#
config WAN_ROUTER
tristate "WAN router (DEPRECATED)"
depends on EXPERIMENTAL
---help---
Wide Area Networks (WANs), such as X.25, frame relay and leased
lines, are used to interconnect Local Area Networks (LANs) over vast
distances with data transfer rates significantly higher than those
achievable with commonly used asynchronous modem connections.
Usually, a quite expensive external device called a `WAN router' is
needed to connect to a WAN.
As an alternative, WAN routing can be built into the Linux kernel.
With relatively inexpensive WAN interface cards available on the
market, a perfectly usable router can be built for less than half
the price of an external router. If you have one of those cards and
wish to use your Linux box as a WAN router, say Y here and also to
the WAN driver for your card, below. You will then need the
wan-tools package which is available from <ftp://ftp.sangoma.com/>.
To compile WAN routing support as a module, choose M here: the
module will be called wanrouter.
If unsure, say N.
#
# Makefile for the Linux WAN router layer.
#
obj-$(CONFIG_WAN_ROUTER) += wanrouter.o
wanrouter-y := wanproc.o wanmain.o
This diff is collapsed.
/*****************************************************************************
* wanproc.c WAN Router Module. /proc filesystem interface.
*
* This module is completely hardware-independent and provides
* access to the router using Linux /proc filesystem.
*
* Author: Gideon Hack
*
* Copyright: (c) 1995-1999 Sangoma Technologies Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
* Jun 02, 1999 Gideon Hack Updates for Linux 2.2.X kernels.
* Jun 29, 1997 Alan Cox Merged with 1.0.3 vendor code
* Jan 29, 1997 Gene Kozin v1.0.1. Implemented /proc read routines
* Jan 30, 1997 Alan Cox Hacked around for 2.1
* Dec 13, 1996 Gene Kozin Initial version (based on Sangoma's WANPIPE)
*****************************************************************************/
#include <linux/init.h> /* __initfunc et al. */
#include <linux/stddef.h> /* offsetof(), etc. */
#include <linux/errno.h> /* return codes */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/wanrouter.h> /* WAN router API definitions */
#include <linux/seq_file.h>
#include <linux/mutex.h>
#include <net/net_namespace.h>
#include <asm/io.h>
#define PROC_STATS_FORMAT "%30s: %12lu\n"
/****** Defines and Macros **************************************************/
#define PROT_DECODE(prot) ((prot == WANCONFIG_FR) ? " FR" :\
(prot == WANCONFIG_X25) ? " X25" : \
(prot == WANCONFIG_PPP) ? " PPP" : \
(prot == WANCONFIG_CHDLC) ? " CHDLC": \
(prot == WANCONFIG_MPPP) ? " MPPP" : \
" Unknown" )
/****** Function Prototypes *************************************************/
#ifdef CONFIG_PROC_FS
/* Miscellaneous */
/*
* Structures for interfacing with the /proc filesystem.
* Router creates its own directory /proc/net/router with the following
* entries:
* config device configuration
* status global device statistics
* <device> entry for each WAN device
*/
/*
* Generic /proc/net/router/<file> file and inode operations
*/
/*
* /proc/net/router
*/
static DEFINE_MUTEX(config_mutex);
static struct proc_dir_entry *proc_router;
/* Strings */
/*
* Interface functions
*/
/****** Proc filesystem entry points ****************************************/
/*
* Iterator
*/
static void *r_start(struct seq_file *m, loff_t *pos)
{
struct wan_device *wandev;
loff_t l = *pos;
mutex_lock(&config_mutex);
if (!l--)
return SEQ_START_TOKEN;
for (wandev = wanrouter_router_devlist; l-- && wandev;
wandev = wandev->next)
;
return wandev;
}
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
{
struct wan_device *wandev = v;
(*pos)++;
return (v == SEQ_START_TOKEN) ? wanrouter_router_devlist : wandev->next;
}
static void r_stop(struct seq_file *m, void *v)
{
mutex_unlock(&config_mutex);
}
static int config_show(struct seq_file *m, void *v)
{
struct wan_device *p = v;
if (v == SEQ_START_TOKEN) {
seq_puts(m, "Device name | port |IRQ|DMA| mem.addr |"
"mem.size|option1|option2|option3|option4\n");
return 0;
}
if (!p->state)
return 0;
seq_printf(m, "%-15s|0x%-4X|%3u|%3u| 0x%-8lX |0x%-6X|%7u|%7u|%7u|%7u\n",
p->name, p->ioport, p->irq, p->dma, p->maddr, p->msize,
p->hw_opt[0], p->hw_opt[1], p->hw_opt[2], p->hw_opt[3]);
return 0;
}
static int status_show(struct seq_file *m, void *v)
{
struct wan_device *p = v;
if (v == SEQ_START_TOKEN) {
seq_puts(m, "Device name |protocol|station|interface|"
"clocking|baud rate| MTU |ndev|link state\n");
return 0;
}
if (!p->state)
return 0;
seq_printf(m, "%-15s|%-8s| %-7s| %-9s|%-8s|%9u|%5u|%3u |",
p->name,
PROT_DECODE(p->config_id),
p->config_id == WANCONFIG_FR ?
(p->station ? "Node" : "CPE") :
(p->config_id == WANCONFIG_X25 ?
(p->station ? "DCE" : "DTE") :
("N/A")),
p->interface ? "V.35" : "RS-232",
p->clocking ? "internal" : "external",
p->bps,
p->mtu,
p->ndev);
switch (p->state) {
case WAN_UNCONFIGURED:
seq_printf(m, "%-12s\n", "unconfigured");
break;
case WAN_DISCONNECTED:
seq_printf(m, "%-12s\n", "disconnected");
break;
case WAN_CONNECTING:
seq_printf(m, "%-12s\n", "connecting");
break;
case WAN_CONNECTED:
seq_printf(m, "%-12s\n", "connected");
break;
default:
seq_printf(m, "%-12s\n", "invalid");
break;
}
return 0;
}
static const struct seq_operations config_op = {
.start = r_start,
.next = r_next,
.stop = r_stop,
.show = config_show,
};
static const struct seq_operations status_op = {
.start = r_start,
.next = r_next,
.stop = r_stop,
.show = status_show,
};
static int config_open(struct inode *inode, struct file *file)
{
return seq_open(file, &config_op);
}
static int status_open(struct inode *inode, struct file *file)
{
return seq_open(file, &status_op);
}
static const struct file_operations config_fops = {
.owner = THIS_MODULE,
.open = config_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static const struct file_operations status_fops = {
.owner = THIS_MODULE,
.open = status_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static int wandev_show(struct seq_file *m, void *v)
{
struct wan_device *wandev = m->private;
if (wandev->magic != ROUTER_MAGIC)
return 0;
if (!wandev->state) {
seq_puts(m, "device is not configured!\n");
return 0;
}
/* Update device statistics */
if (wandev->update) {
int err = wandev->update(wandev);
if (err == -EAGAIN) {
seq_puts(m, "Device is busy!\n");
return 0;
}
if (err) {
seq_puts(m, "Device is not configured!\n");
return 0;
}
}
seq_printf(m, PROC_STATS_FORMAT,
"total packets received", wandev->stats.rx_packets);
seq_printf(m, PROC_STATS_FORMAT,
"total packets transmitted", wandev->stats.tx_packets);
seq_printf(m, PROC_STATS_FORMAT,
"total bytes received", wandev->stats.rx_bytes);
seq_printf(m, PROC_STATS_FORMAT,
"total bytes transmitted", wandev->stats.tx_bytes);
seq_printf(m, PROC_STATS_FORMAT,
"bad packets received", wandev->stats.rx_errors);
seq_printf(m, PROC_STATS_FORMAT,
"packet transmit problems", wandev->stats.tx_errors);
seq_printf(m, PROC_STATS_FORMAT,
"received frames dropped", wandev->stats.rx_dropped);
seq_printf(m, PROC_STATS_FORMAT,
"transmit frames dropped", wandev->stats.tx_dropped);
seq_printf(m, PROC_STATS_FORMAT,
"multicast packets received", wandev->stats.multicast);
seq_printf(m, PROC_STATS_FORMAT,
"transmit collisions", wandev->stats.collisions);
seq_printf(m, PROC_STATS_FORMAT,
"receive length errors", wandev->stats.rx_length_errors);
seq_printf(m, PROC_STATS_FORMAT,
"receiver overrun errors", wandev->stats.rx_over_errors);
seq_printf(m, PROC_STATS_FORMAT,
"CRC errors", wandev->stats.rx_crc_errors);
seq_printf(m, PROC_STATS_FORMAT,
"frame format errors (aborts)", wandev->stats.rx_frame_errors);
seq_printf(m, PROC_STATS_FORMAT,
"receiver fifo overrun", wandev->stats.rx_fifo_errors);
seq_printf(m, PROC_STATS_FORMAT,
"receiver missed packet", wandev->stats.rx_missed_errors);
seq_printf(m, PROC_STATS_FORMAT,
"aborted frames transmitted", wandev->stats.tx_aborted_errors);
return 0;
}
static int wandev_open(struct inode *inode, struct file *file)
{
return single_open(file, wandev_show, PDE(inode)->data);
}
static const struct file_operations wandev_fops = {
.owner = THIS_MODULE,
.open = wandev_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.unlocked_ioctl = wanrouter_ioctl,
};
/*
* Initialize router proc interface.
*/
int __init wanrouter_proc_init(void)
{
struct proc_dir_entry *p;
proc_router = proc_mkdir(ROUTER_NAME, init_net.proc_net);
if (!proc_router)
goto fail;
p = proc_create("config", S_IRUGO, proc_router, &config_fops);
if (!p)
goto fail_config;
p = proc_create("status", S_IRUGO, proc_router, &status_fops);
if (!p)
goto fail_stat;
return 0;
fail_stat:
remove_proc_entry("config", proc_router);
fail_config:
remove_proc_entry(ROUTER_NAME, init_net.proc_net);
fail:
return -ENOMEM;
}
/*
* Clean up router proc interface.
*/
void wanrouter_proc_cleanup(void)
{
remove_proc_entry("config", proc_router);
remove_proc_entry("status", proc_router);
remove_proc_entry(ROUTER_NAME, init_net.proc_net);
}
/*
* Add directory entry for WAN device.
*/
int wanrouter_proc_add(struct wan_device* wandev)
{
if (wandev->magic != ROUTER_MAGIC)
return -EINVAL;
wandev->dent = proc_create(wandev->name, S_IRUGO,
proc_router, &wandev_fops);
if (!wandev->dent)
return -ENOMEM;
wandev->dent->data = wandev;
return 0;
}
/*
* Delete directory entry for WAN device.
*/
int wanrouter_proc_delete(struct wan_device* wandev)
{
if (wandev->magic != ROUTER_MAGIC)
return -EINVAL;
remove_proc_entry(wandev->name, proc_router);
return 0;
}
#else
/*
* No /proc - output stubs
*/
int __init wanrouter_proc_init(void)
{
return 0;
}
void wanrouter_proc_cleanup(void)
{
}
int wanrouter_proc_add(struct wan_device *wandev)
{
return 0;
}
int wanrouter_proc_delete(struct wan_device *wandev)
{
return 0;
}
#endif
/*
* End
*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment