patch-2.3.99-pre3 linux/drivers/atm/uPD98402.c
Next file: linux/drivers/atm/zatm.c
Previous file: linux/drivers/atm/suni.h
Back to the patch index
Back to the overall index
- Lines: 204
- Date:
Tue Mar 21 23:38:26 2000
- Orig file:
v2.3.99-pre2/linux/drivers/atm/uPD98402.c
- Orig date:
Thu Feb 10 17:11:06 2000
diff -u --recursive --new-file v2.3.99-pre2/linux/drivers/atm/uPD98402.c linux/drivers/atm/uPD98402.c
@@ -11,6 +11,7 @@
#include <linux/sonet.h>
#include <linux/init.h>
#include <asm/uaccess.h>
+#include <asm/atomic.h>
#include "uPD98402.h"
@@ -23,8 +24,9 @@
struct uPD98402_priv {
- struct sonet_stats sonet_stats; /* link diagnostics */
+ struct k_sonet_stats sonet_stats;/* link diagnostics */
unsigned char framing; /* SONET/SDH framing */
+ int loop_mode; /* loopback mode */
};
@@ -36,23 +38,18 @@
static int fetch_stats(struct atm_dev *dev,struct sonet_stats *arg,int zero)
{
- unsigned long flags;
- int error;
+ struct sonet_stats tmp;
+ int error = 0;
- error = 0;
- save_flags(flags);
- cli();
- PRIV(dev)->sonet_stats.uncorr_hcs += GET(HECCT);
- if (arg)
- error = copy_to_user(arg,&PRIV(dev)->sonet_stats,
- sizeof(struct sonet_stats));
+ atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
+ sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
+ if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
if (zero && !error) {
- memset(&PRIV(dev)->sonet_stats,0,sizeof(struct sonet_stats));
- PRIV(dev)->sonet_stats.corr_hcs = -1;
- PRIV(dev)->sonet_stats.tx_cells = -1;
- PRIV(dev)->sonet_stats.rx_cells = -1;
+ /* unused fields are reported as -1, but we must not "adjust"
+ them */
+ tmp.corr_hcs = tmp.tx_cells = tmp.rx_cells = 0;
+ sonet_subtract_stats(&PRIV(dev)->sonet_stats,&tmp);
}
- restore_flags(flags);
return error ? -EFAULT : 0;
}
@@ -102,6 +99,39 @@
}
+static int set_loopback(struct atm_dev *dev,int mode)
+{
+ unsigned char mode_reg;
+
+ mode_reg = GET(MDR) & ~(uPD98402_MDR_TPLP | uPD98402_MDR_ALP |
+ uPD98402_MDR_RPLP);
+ switch (__ATM_LM_XTLOC(mode)) {
+ case __ATM_LM_NONE:
+ break;
+ case __ATM_LM_PHY:
+ mode_reg |= uPD98402_MDR_TPLP;
+ break;
+ case __ATM_LM_ATM:
+ mode_reg |= uPD98402_MDR_ALP;
+ break;
+ default:
+ return -EINVAL;
+ }
+ switch (__ATM_LM_XTRMT(mode)) {
+ case __ATM_LM_NONE:
+ break;
+ case __ATM_LM_PHY:
+ mode_reg |= uPD98402_MDR_RPLP;
+ break;
+ default:
+ return -EINVAL;
+ }
+ PUT(mode_reg,MDR);
+ PRIV(dev)->loop_mode = mode;
+ return 0;
+}
+
+
static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg)
{
switch (cmd) {
@@ -117,35 +147,42 @@
-EFAULT : 0;
case SONET_GETFRSENSE:
return get_sense(dev,arg);
+ case ATM_SETLOOP:
+ return set_loopback(dev,(int) (long) arg);
+ case ATM_GETLOOP:
+ return put_user(PRIV(dev)->loop_mode,(int *) arg) ?
+ -EFAULT : 0;
+ case ATM_QUERYLOOP:
+ return put_user(ATM_LM_LOC_PHY | ATM_LM_LOC_ATM |
+ ATM_LM_RMT_PHY,(int *) arg) ? -EFAULT : 0;
default:
- return -ENOIOCTLCMD;
+ return -ENOIOCTLCMD;
}
}
+#define ADD_LIMITED(s,v) \
+ { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
+ if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
+ atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
+
+
static void stat_event(struct atm_dev *dev)
{
unsigned char events;
events = GET(PCR);
- if (events & uPD98402_PFM_PFEB)
- if ((PRIV(dev)->sonet_stats.path_febe += GET(PFECB)) < 0)
- PRIV(dev)->sonet_stats.path_febe = LONG_MAX;
- if (events & uPD98402_PFM_LFEB)
- if ((PRIV(dev)->sonet_stats.line_febe += GET(LECCT)) < 0)
- PRIV(dev)->sonet_stats.line_febe = LONG_MAX;
- if (events & uPD98402_PFM_B3E)
- if ((PRIV(dev)->sonet_stats.path_bip += GET(B3ECT)) < 0)
- PRIV(dev)->sonet_stats.path_bip = LONG_MAX;
- if (events & uPD98402_PFM_B2E)
- if ((PRIV(dev)->sonet_stats.line_bip += GET(B2ECT)) < 0)
- PRIV(dev)->sonet_stats.line_bip = LONG_MAX;
- if (events & uPD98402_PFM_B1E)
- if ((PRIV(dev)->sonet_stats.section_bip += GET(B1ECT)) < 0)
- PRIV(dev)->sonet_stats.section_bip = LONG_MAX;
+ if (events & uPD98402_PFM_PFEB) ADD_LIMITED(path_febe,PFECB);
+ if (events & uPD98402_PFM_LFEB) ADD_LIMITED(line_febe,LECCT);
+ if (events & uPD98402_PFM_B3E) ADD_LIMITED(path_bip,B3ECT);
+ if (events & uPD98402_PFM_B2E) ADD_LIMITED(line_bip,B2ECT);
+ if (events & uPD98402_PFM_B1E) ADD_LIMITED(section_bip,B1ECT);
}
+#undef ADD_LIMITED
+
+
static void uPD98402_int(struct atm_dev *dev)
{
static unsigned long silence = 0;
@@ -158,7 +195,8 @@
if (reason & uPD98402_INT_PFM) stat_event(dev);
if (reason & uPD98402_INT_PCO) {
(void) GET(PCOCR); /* clear interrupt cause */
- PRIV(dev)->sonet_stats.uncorr_hcs += GET(HECCT);
+ atomic_add(GET(HECCT),
+ &PRIV(dev)->sonet_stats.uncorr_hcs);
}
if ((reason & uPD98402_INT_RFO) &&
(time_after(jiffies, silence) || silence == 0)) {
@@ -172,10 +210,10 @@
static int uPD98402_start(struct atm_dev *dev)
{
-DPRINTK("phy_start\n");
+ DPRINTK("phy_start\n");
if (!(PRIV(dev) = kmalloc(sizeof(struct uPD98402_priv),GFP_KERNEL)))
return -ENOMEM;
- memset(&PRIV(dev)->sonet_stats,0,sizeof(struct sonet_stats));
+ memset(&PRIV(dev)->sonet_stats,0,sizeof(struct k_sonet_stats));
(void) GET(PCR); /* clear performance events */
PUT(uPD98402_PFM_FJ,PCMR); /* ignore frequency adj */
(void) GET(PCOCR); /* clear overflows */
@@ -184,15 +222,26 @@
PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
uPD98402_INT_LOS),PIMR); /* enable them */
(void) fetch_stats(dev,NULL,1); /* clear kernel counters */
+ atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
+ atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
+ atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
return 0;
}
+static int uPD98402_stop(struct atm_dev *dev)
+{
+ /* let SAR driver worry about stopping interrupts */
+ kfree(PRIV(dev));
+ return 0;
+}
+
static const struct atmphy_ops uPD98402_ops = {
- uPD98402_start,
- uPD98402_ioctl, /* no ioctl yet */
- uPD98402_int
+ start: uPD98402_start,
+ ioctl: uPD98402_ioctl,
+ interrupt: uPD98402_int,
+ stop: uPD98402_stop,
};
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)