aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/atm/suni.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/atm/suni.c')
-rw-r--r--drivers/atm/suni.c130
1 files changed, 105 insertions, 25 deletions
diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
index b1d063cc4fbe..6dd3f5919968 100644
--- a/drivers/atm/suni.c
+++ b/drivers/atm/suni.c
@@ -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 */
2 9
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 10/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4 11
5
6#include <linux/module.h> 12#include <linux/module.h>
7#include <linux/jiffies.h> 13#include <linux/jiffies.h>
8#include <linux/kernel.h> 14#include <linux/kernel.h>
@@ -29,15 +35,6 @@
29#define DPRINTK(format,args...) 35#define DPRINTK(format,args...)
30#endif 36#endif
31 37
32
33struct suni_priv {
34 struct k_sonet_stats sonet_stats; /* link diagnostics */
35 int loop_mode; /* loopback mode */
36 struct atm_dev *dev; /* device back-pointer */
37 struct suni_priv *next; /* next SUNI */
38};
39
40
41#define PRIV(dev) ((struct suni_priv *) dev->phy_data) 38#define PRIV(dev) ((struct suni_priv *) dev->phy_data)
42 39
43#define PUT(val,reg) dev->ops->phy_put(dev,val,SUNI_##reg) 40#define PUT(val,reg) dev->ops->phy_put(dev,val,SUNI_##reg)
@@ -155,25 +152,105 @@ static int get_diag(struct atm_dev *dev,void __user *arg)
155static int set_loopback(struct atm_dev *dev,int mode) 152static int set_loopback(struct atm_dev *dev,int mode)
156{ 153{
157 unsigned char control; 154 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 }
158 166
159 control = GET(MCT) & ~(SUNI_MCT_DLE | SUNI_MCT_LLE); 167 control = dev->ops->phy_get(dev, reg) & ~(dle | lle);
160 switch (mode) { 168 switch (mode) {
161 case ATM_LM_NONE: 169 case ATM_LM_NONE:
162 break; 170 break;
163 case ATM_LM_LOC_PHY: 171 case ATM_LM_LOC_PHY:
164 control |= SUNI_MCT_DLE; 172 control |= dle;
165 break; 173 break;
166 case ATM_LM_RMT_PHY: 174 case ATM_LM_RMT_PHY:
167 control |= SUNI_MCT_LLE; 175 control |= lle;
168 break; 176 break;
169 default: 177 default:
170 return -EINVAL; 178 return -EINVAL;
171 } 179 }
172 PUT(control,MCT); 180 dev->ops->phy_put(dev, control, reg);
173 PRIV(dev)->loop_mode = mode; 181 PRIV(dev)->loop_mode = mode;
174 return 0; 182 return 0;
175} 183}
176 184
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
195static 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
209static 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
224static 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
239static 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
177 254
178static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) 255static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
179{ 256{
@@ -188,14 +265,16 @@ static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
188 case SONET_GETDIAG: 265 case SONET_GETDIAG:
189 return get_diag(dev,arg); 266 return get_diag(dev,arg);
190 case SONET_SETFRAMING: 267 case SONET_SETFRAMING:
191 if ((int)(unsigned long)arg != SONET_FRAME_SONET) return -EINVAL; 268 if (!capable(CAP_NET_ADMIN))
192 return 0; 269 return -EPERM;
270 return set_framing(dev, arg);
193 case SONET_GETFRAMING: 271 case SONET_GETFRAMING:
194 return put_user(SONET_FRAME_SONET,(int __user *)arg) ? 272 return get_framing(dev, arg);
195 -EFAULT : 0;
196 case SONET_GETFRSENSE: 273 case SONET_GETFRSENSE:
197 return -EINVAL; 274 return -EINVAL;
198 case ATM_SETLOOP: 275 case ATM_SETLOOP:
276 if (!capable(CAP_NET_ADMIN))
277 return -EPERM;
199 return set_loopback(dev,(int)(unsigned long)arg); 278 return set_loopback(dev,(int)(unsigned long)arg);
200 case ATM_GETLOOP: 279 case ATM_GETLOOP:
201 return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ? 280 return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ?
@@ -229,10 +308,6 @@ static int suni_start(struct atm_dev *dev)
229 unsigned long flags; 308 unsigned long flags;
230 int first; 309 int first;
231 310
232 if (!(dev->phy_data = kmalloc(sizeof(struct suni_priv),GFP_KERNEL)))
233 return -ENOMEM;
234
235 PRIV(dev)->dev = dev;
236 spin_lock_irqsave(&sunis_lock,flags); 311 spin_lock_irqsave(&sunis_lock,flags);
237 first = !sunis; 312 first = !sunis;
238 PRIV(dev)->next = sunis; 313 PRIV(dev)->next = sunis;
@@ -293,16 +368,21 @@ int suni_init(struct atm_dev *dev)
293{ 368{
294 unsigned char mri; 369 unsigned char mri;
295 370
371 if (!(dev->phy_data = kmalloc(sizeof(struct suni_priv),GFP_KERNEL)))
372 return -ENOMEM;
373 PRIV(dev)->dev = dev;
374
296 mri = GET(MRI); /* reset SUNI */ 375 mri = GET(MRI); /* reset SUNI */
376 PRIV(dev)->type = (mri & SUNI_MRI_TYPE) >> SUNI_MRI_TYPE_SHIFT;
297 PUT(mri | SUNI_MRI_RESET,MRI); 377 PUT(mri | SUNI_MRI_RESET,MRI);
298 PUT(mri,MRI); 378 PUT(mri,MRI);
299 PUT((GET(MT) & SUNI_MT_DS27_53),MT); /* disable all tests */ 379 PUT((GET(MT) & SUNI_MT_DS27_53),MT); /* disable all tests */
300 REG_CHANGE(SUNI_TPOP_APM_S,SUNI_TPOP_APM_S_SHIFT,SUNI_TPOP_S_SONET, 380 set_sonet(dev);
301 TPOP_APM); /* use SONET */
302 REG_CHANGE(SUNI_TACP_IUCHP_CLP,0,SUNI_TACP_IUCHP_CLP, 381 REG_CHANGE(SUNI_TACP_IUCHP_CLP,0,SUNI_TACP_IUCHP_CLP,
303 TACP_IUCHP); /* idle cells */ 382 TACP_IUCHP); /* idle cells */
304 PUT(SUNI_IDLE_PATTERN,TACP_IUCPOP); 383 PUT(SUNI_IDLE_PATTERN,TACP_IUCPOP);
305 dev->phy = &suni_ops; 384 dev->phy = &suni_ops;
385
306 return 0; 386 return 0;
307} 387}
308 388