12 #include <linux/module.h>
14 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/atmdev.h>
18 #include <linux/sonet.h>
22 #include <linux/capability.h>
24 #include <linux/slab.h>
25 #include <asm/param.h>
26 #include <asm/uaccess.h>
33 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
35 #define DPRINTK(format,args...)
38 #define PRIV(dev) ((struct suni_priv *) dev->phy_data)
40 #define PUT(val,reg) dev->ops->phy_put(dev,val,SUNI_##reg)
41 #define GET(reg) dev->ops->phy_get(dev,SUNI_##reg)
42 #define REG_CHANGE(mask,shift,value,reg) \
43 PUT((GET(reg) & ~(mask)) | ((value) << (shift)),reg)
47 static struct suni_priv *sunis =
NULL;
51 #define ADD_LIMITED(s,v) \
52 atomic_add((v),&stats->s); \
53 if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
56 static void suni_hz(
unsigned long from_timer)
58 struct suni_priv *walk;
62 for (walk = sunis; walk; walk = walk->next) {
64 stats = &walk->sonet_stats;
68 ((
GET(RSOP_SBM) & 0xff) << 8));
70 ((
GET(RLOP_LB) & 0xff) << 8) |
71 ((
GET(RLOP_LBM) & 0xf) << 16));
73 ((
GET(RPOP_PBM) & 0xff) << 8));
75 ((
GET(RLOP_LF) & 0xff) << 8) |
76 ((
GET(RLOP_LFM) & 0xf) << 16));
78 ((
GET(RPOP_PFM) & 0xff) << 8));
82 ((
GET(RACP_RCC) & 0xff) << 8) |
83 ((
GET(RACP_RCCM) & 7) << 16));
85 ((
GET(TACP_TCC) & 0xff) << 8) |
86 ((
GET(TACP_TCCM) & 7) << 16));
103 return error ? -
EFAULT : 0;
107 #define HANDLE_FLAG(flag,reg,bit) \
109 if (set) PUT(GET(reg) | bit,reg); \
110 else PUT(GET(reg) & ~bit,reg); \
115 static int change_diag(
struct atm_dev *dev,
void __user *arg,
int set)
135 static int get_diag(
struct atm_dev *dev,
void __user *arg)
152 static int set_loopback(
struct atm_dev *dev,
int mode)
167 control = dev->
ops->phy_get(dev, reg) & ~(dle | lle);
180 dev->
ops->phy_put(dev, control, reg);
195 static int set_sonet(
struct atm_dev *dev)
209 static int set_sdh(
struct atm_dev *dev)
224 static int get_framing(
struct atm_dev *dev,
void __user *arg)
239 static int set_framing(
struct atm_dev *dev,
void __user *arg)
243 if (
get_user(mode, (
int __user *) arg))
247 return set_sonet(dev);
255 static int suni_ioctl(
struct atm_dev *dev,
unsigned int cmd,
void __user *arg)
262 return change_diag(dev,arg,1);
264 return change_diag(dev,arg,0);
266 return get_diag(dev,arg);
270 return set_framing(dev, arg);
272 return get_framing(dev, arg);
278 return set_loopback(dev,(
int)(
unsigned long)arg);
280 return put_user(
PRIV(dev)->loop_mode,(
int __user *)arg) ?
284 (
int __user *) arg) ? -
EFAULT : 0;
291 static void poll_los(
struct atm_dev *dev)
299 static void suni_int(
struct atm_dev *dev)
307 static int suni_start(
struct atm_dev *dev)
314 PRIV(dev)->next = sunis;
316 spin_unlock_irqrestore(&sunis_lock,flags);
330 poll_timer.function = suni_hz;
333 printk(
KERN_DEBUG "[u] p=0x%lx,n=0x%lx\n",(
unsigned long) poll_timer.list.prev,
334 (
unsigned long) poll_timer.list.next);
342 static int suni_stop(
struct atm_dev *dev)
344 struct suni_priv **walk;
349 for (walk = &sunis; *walk !=
PRIV(dev);
350 walk = &
PRIV((*walk)->dev)->next);
351 *walk =
PRIV((*walk)->dev)->next;
353 spin_unlock_irqrestore(&sunis_lock,flags);
363 .interrupt = suni_int,
385 dev->
phy = &suni_ops;