Skip to content

Commit df3bc8b

Browse files
Chas Williamsdavem330
authored andcommitted
atm: [suni] add support for setting loopback and framing modes
Signed-off-by: Chas Williams <chas@cmf.nrl.navy.mil> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2be63b8 commit df3bc8b

3 files changed

Lines changed: 133 additions & 21 deletions

File tree

‎drivers/atm/suni.c‎

Lines changed: 105 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
/* drivers/atm/suni.c - PMC PM5346 SUNI (PHY) driver */
1+
/*
2+
* drivers/atm/suni.c - S/UNI PHY driver
3+
*
4+
* Supports the following:
5+
* PMC PM5346 S/UNI LITE
6+
* PMC PM5350 S/UNI 155 ULTRA
7+
* PMC PM5355 S/UNI 622
8+
*/
29

310
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
411

5-
612
#include <linux/module.h>
713
#include <linux/jiffies.h>
814
#include <linux/kernel.h>
@@ -146,25 +152,105 @@ static int get_diag(struct atm_dev *dev,void __user *arg)
146152
static int set_loopback(struct atm_dev *dev,int mode)
147153
{
148154
unsigned char control;
155+
int reg, dle, lle;
156+
157+
if (PRIV(dev)->type == SUNI_MRI_TYPE_PM5355) {
158+
reg = SUNI_MCM;
159+
dle = SUNI_MCM_DLE;
160+
lle = SUNI_MCM_LLE;
161+
} else {
162+
reg = SUNI_MCT;
163+
dle = SUNI_MCT_DLE;
164+
lle = SUNI_MCT_LLE;
165+
}
149166

150-
control = GET(MCT) & ~(SUNI_MCT_DLE | SUNI_MCT_LLE);
167+
control = dev->ops->phy_get(dev, reg) & ~(dle | lle);
151168
switch (mode) {
152169
case ATM_LM_NONE:
153170
break;
154171
case ATM_LM_LOC_PHY:
155-
control |= SUNI_MCT_DLE;
172+
control |= dle;
156173
break;
157174
case ATM_LM_RMT_PHY:
158-
control |= SUNI_MCT_LLE;
175+
control |= lle;
159176
break;
160177
default:
161178
return -EINVAL;
162179
}
163-
PUT(control,MCT);
180+
dev->ops->phy_put(dev, control, reg);
164181
PRIV(dev)->loop_mode = mode;
165182
return 0;
166183
}
167184

185+
/*
186+
* SONET vs. SDH Configuration
187+
*
188+
* Z0INS (register 0x06): 0 for SONET, 1 for SDH
189+
* ENSS (register 0x3D): 0 for SONET, 1 for SDH
190+
* LEN16 (register 0x28): 0 for SONET, 1 for SDH (n/a for S/UNI 155 QUAD)
191+
* LEN16 (register 0x50): 0 for SONET, 1 for SDH (n/a for S/UNI 155 QUAD)
192+
* S[1:0] (register 0x46): 00 for SONET, 10 for SDH
193+
*/
194+
195+
static int set_sonet(struct atm_dev *dev)
196+
{
197+
if (PRIV(dev)->type == SUNI_MRI_TYPE_PM5355) {
198+
PUT(GET(RPOP_RC) & ~SUNI_RPOP_RC_ENSS, RPOP_RC);
199+
PUT(GET(SSTB_CTRL) & ~SUNI_SSTB_CTRL_LEN16, SSTB_CTRL);
200+
PUT(GET(SPTB_CTRL) & ~SUNI_SPTB_CTRL_LEN16, SPTB_CTRL);
201+
}
202+
203+
REG_CHANGE(SUNI_TPOP_APM_S, SUNI_TPOP_APM_S_SHIFT,
204+
SUNI_TPOP_S_SONET, TPOP_APM);
205+
206+
return 0;
207+
}
208+
209+
static int set_sdh(struct atm_dev *dev)
210+
{
211+
if (PRIV(dev)->type == SUNI_MRI_TYPE_PM5355) {
212+
PUT(GET(RPOP_RC) | SUNI_RPOP_RC_ENSS, RPOP_RC);
213+
PUT(GET(SSTB_CTRL) | SUNI_SSTB_CTRL_LEN16, SSTB_CTRL);
214+
PUT(GET(SPTB_CTRL) | SUNI_SPTB_CTRL_LEN16, SPTB_CTRL);
215+
}
216+
217+
REG_CHANGE(SUNI_TPOP_APM_S, SUNI_TPOP_APM_S_SHIFT,
218+
SUNI_TPOP_S_SDH, TPOP_APM);
219+
220+
return 0;
221+
}
222+
223+
224+
static int get_framing(struct atm_dev *dev, void __user *arg)
225+
{
226+
int framing;
227+
unsigned char s;
228+
229+
230+
s = (GET(TPOP_APM) & SUNI_TPOP_APM_S) >> SUNI_TPOP_APM_S_SHIFT;
231+
if (s == SUNI_TPOP_S_SONET)
232+
framing = SONET_FRAME_SONET;
233+
else
234+
framing = SONET_FRAME_SDH;
235+
236+
return put_user(framing, (int __user *) arg) ? -EFAULT : 0;
237+
}
238+
239+
static int set_framing(struct atm_dev *dev, void __user *arg)
240+
{
241+
int mode;
242+
243+
if (get_user(mode, (int __user *) arg))
244+
return -EFAULT;
245+
246+
if (mode == SONET_FRAME_SONET)
247+
return set_sonet(dev);
248+
else if (mode == SONET_FRAME_SDH)
249+
return set_sdh(dev);
250+
251+
return -EINVAL;
252+
}
253+
168254

169255
static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
170256
{
@@ -179,14 +265,16 @@ static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
179265
case SONET_GETDIAG:
180266
return get_diag(dev,arg);
181267
case SONET_SETFRAMING:
182-
if ((int)(unsigned long)arg != SONET_FRAME_SONET) return -EINVAL;
183-
return 0;
268+
if (!capable(CAP_NET_ADMIN))
269+
return -EPERM;
270+
return set_framing(dev, arg);
184271
case SONET_GETFRAMING:
185-
return put_user(SONET_FRAME_SONET,(int __user *)arg) ?
186-
-EFAULT : 0;
272+
return get_framing(dev, arg);
187273
case SONET_GETFRSENSE:
188274
return -EINVAL;
189275
case ATM_SETLOOP:
276+
if (!capable(CAP_NET_ADMIN))
277+
return -EPERM;
190278
return set_loopback(dev,(int)(unsigned long)arg);
191279
case ATM_GETLOOP:
192280
return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ?
@@ -220,10 +308,6 @@ static int suni_start(struct atm_dev *dev)
220308
unsigned long flags;
221309
int first;
222310

223-
if (!(dev->phy_data = kmalloc(sizeof(struct suni_priv),GFP_KERNEL)))
224-
return -ENOMEM;
225-
226-
PRIV(dev)->dev = dev;
227311
spin_lock_irqsave(&sunis_lock,flags);
228312
first = !sunis;
229313
PRIV(dev)->next = sunis;
@@ -284,16 +368,21 @@ int suni_init(struct atm_dev *dev)
284368
{
285369
unsigned char mri;
286370

371+
if (!(dev->phy_data = kmalloc(sizeof(struct suni_priv),GFP_KERNEL)))
372+
return -ENOMEM;
373+
PRIV(dev)->dev = dev;
374+
287375
mri = GET(MRI); /* reset SUNI */
376+
PRIV(dev)->type = (mri & SUNI_MRI_TYPE) >> SUNI_MRI_TYPE_SHIFT;
288377
PUT(mri | SUNI_MRI_RESET,MRI);
289378
PUT(mri,MRI);
290379
PUT((GET(MT) & SUNI_MT_DS27_53),MT); /* disable all tests */
291-
REG_CHANGE(SUNI_TPOP_APM_S,SUNI_TPOP_APM_S_SHIFT,SUNI_TPOP_S_SONET,
292-
TPOP_APM); /* use SONET */
380+
set_sonet(dev);
293381
REG_CHANGE(SUNI_TACP_IUCHP_CLP,0,SUNI_TACP_IUCHP_CLP,
294382
TACP_IUCHP); /* idle cells */
295383
PUT(SUNI_IDLE_PATTERN,TACP_IUCPOP);
296384
dev->phy = &suni_ops;
385+
297386
return 0;
298387
}
299388

‎drivers/atm/suni.h‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/* drivers/atm/suni.h - PMC PM5346 SUNI (PHY) declarations */
1+
/*
2+
* drivers/atm/suni.h - S/UNI PHY driver
3+
*/
24

35
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4-
56

67
#ifndef DRIVER_ATM_SUNI_H
78
#define DRIVER_ATM_SUNI_H
@@ -39,7 +40,8 @@
3940
#define SUNI_RLOP_LFM 0x1F /* RLOP Line FEBE MSB */
4041
#define SUNI_TLOP_CTRL 0x20 /* TLOP Control */
4142
#define SUNI_TLOP_DIAG 0x21 /* TLOP Diagnostic */
42-
/* 0x22-0x2F reserved */
43+
/* 0x22-0x27 reserved */
44+
#define SUNI_SSTB_CTRL 0x28
4345
#define SUNI_RPOP_SC 0x30 /* RPOP Status/Control */
4446
#define SUNI_RPOP_IS 0x31 /* RPOP Interrupt Status */
4547
/* 0x32 reserved */
@@ -52,6 +54,7 @@
5254
#define SUNI_RPOP_PFM 0x3B /* RPOP Path FEBE MSB */
5355
/* 0x3C reserved */
5456
#define SUNI_RPOP_PBC 0x3D /* RPOP Path BIP-8 Configuration */
57+
#define SUNI_RPOP_RC 0x3D /* RPOP Ring Control (PM5355) */
5558
/* 0x3E-0x3F reserved */
5659
#define SUNI_TPOP_CD 0x40 /* TPOP Control/Diagnostic */
5760
#define SUNI_TPOP_PC 0x41 /* TPOP Pointer Control */
@@ -82,7 +85,8 @@
8285
#define SUNI_TACP_TCC 0x65 /* TACP Transmit Cell Counter */
8386
#define SUNI_TACP_TCCM 0x66 /* TACP Transmit Cell Counter MSB */
8487
#define SUNI_TACP_CFG 0x67 /* TACP Configuration */
85-
/* 0x68-0x7F reserved */
88+
#define SUNI_SPTB_CTRL 0x68 /* SPTB Control */
89+
/* 0x69-0x7F reserved */
8690
#define SUNI_MT 0x80 /* Master Test */
8791
/* 0x81-0xFF reserved */
8892

@@ -94,9 +98,18 @@
9498
#define SUNI_MRI_ID_SHIFT 0
9599
#define SUNI_MRI_TYPE 0x70 /* R, SUNI type (lite is 011) */
96100
#define SUNI_MRI_TYPE_SHIFT 4
101+
#define SUNI_MRI_TYPE_PM5346 0x3 /* S/UNI 155 LITE */
102+
#define SUNI_MRI_TYPE_PM5347 0x4 /* S/UNI 155 PLUS */
103+
#define SUNI_MRI_TYPE_PM5350 0x7 /* S/UNI 155 ULTRA */
104+
#define SUNI_MRI_TYPE_PM5355 0x1 /* S/UNI 622 */
97105
#define SUNI_MRI_RESET 0x80 /* RW, reset & power down chip
98106
0: normal operation
99107
1: reset & low power */
108+
109+
/* MCM is reg 0x4 */
110+
#define SUNI_MCM_LLE 0x20 /* line loopback (PM5355) */
111+
#define SUNI_MCM_DLE 0x10 /* diagnostic loopback (PM5355) */
112+
100113
/* MCT is reg 5 */
101114
#define SUNI_MCT_LOOPT 0x01 /* RW, timing source, 0: from
102115
TRCLK+/- */
@@ -144,6 +157,12 @@
144157
/* TLOP_DIAG is reg 0x21 */
145158
#define SUNI_TLOP_DIAG_DBIP 0x01 /* insert line BIP err (continuously) */
146159

160+
/* SSTB_CTRL is reg 0x28 */
161+
#define SUNI_SSTB_CTRL_LEN16 0x01 /* path trace message length bit */
162+
163+
/* RPOP_RC is reg 0x3D (PM5355) */
164+
#define SUNI_RPOP_RC_ENSS 0x40 /* enable size bit */
165+
147166
/* TPOP_DIAG is reg 0x40 */
148167
#define SUNI_TPOP_DIAG_PAIS 0x01 /* insert STS path alarm ind (cont) */
149168
#define SUNI_TPOP_DIAG_DB3 0x02 /* insert path BIP err (continuously) */
@@ -191,6 +210,9 @@
191210
pattern */
192211
#define SUNI_TACP_IUCHP_GFC_SHIFT 4
193212

213+
/* SPTB_CTRL is reg 0x68 */
214+
#define SUNI_SPTB_CTRL_LEN16 0x01 /* path trace message length */
215+
194216
/* MT is reg 0x80 */
195217
#define SUNI_MT_HIZIO 0x01 /* RW, all but data bus & MP interface
196218
tri-state */
@@ -208,6 +230,7 @@
208230
struct suni_priv {
209231
struct k_sonet_stats sonet_stats; /* link diagnostics */
210232
int loop_mode; /* loopback mode */
233+
int type; /* phy type */
211234
struct atm_dev *dev; /* device back-pointer */
212235
struct suni_priv *next; /* next SUNI */
213236
};

‎include/linux/sonet.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct sonet_stats {
3434
/* clear error insertion */
3535
#define SONET_GETDIAG _IOR('a',ATMIOC_PHYTYP+4,int)
3636
/* query error insertion */
37-
#define SONET_SETFRAMING _IO('a',ATMIOC_PHYTYP+5)
37+
#define SONET_SETFRAMING _IOW('a',ATMIOC_PHYTYP+5,int)
3838
/* set framing mode (SONET/SDH) */
3939
#define SONET_GETFRAMING _IOR('a',ATMIOC_PHYTYP+6,int)
4040
/* get framing mode */

0 commit comments

Comments
 (0)