diff options
author | Chas Williams <chas@cmf.nrl.navy.mil> | 2008-06-17 19:19:24 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-06-17 19:19:24 -0400 |
commit | df3bc8bd8f8fd17e9b22859d82af38fa702e75b7 (patch) | |
tree | ff3172a18511fb244e8f8216dd6b344150b5c4f3 /drivers/atm/suni.c | |
parent | 2be63b878f2a1e6d939b05f4f5cb733cb39bcd22 (diff) |
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>
Diffstat (limited to 'drivers/atm/suni.c')
-rw-r--r-- | drivers/atm/suni.c | 121 |
1 files changed, 105 insertions, 16 deletions
diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c index 6097f6877a4..6dd3f591996 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> |
@@ -146,25 +152,105 @@ static int get_diag(struct atm_dev *dev,void __user *arg) | |||
146 | static int set_loopback(struct atm_dev *dev,int mode) | 152 | static int set_loopback(struct atm_dev *dev,int mode) |
147 | { | 153 | { |
148 | 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 | } | ||
149 | 166 | ||
150 | control = GET(MCT) & ~(SUNI_MCT_DLE | SUNI_MCT_LLE); | 167 | control = dev->ops->phy_get(dev, reg) & ~(dle | lle); |
151 | switch (mode) { | 168 | switch (mode) { |
152 | case ATM_LM_NONE: | 169 | case ATM_LM_NONE: |
153 | break; | 170 | break; |
154 | case ATM_LM_LOC_PHY: | 171 | case ATM_LM_LOC_PHY: |
155 | control |= SUNI_MCT_DLE; | 172 | control |= dle; |
156 | break; | 173 | break; |
157 | case ATM_LM_RMT_PHY: | 174 | case ATM_LM_RMT_PHY: |
158 | control |= SUNI_MCT_LLE; | 175 | control |= lle; |
159 | break; | 176 | break; |
160 | default: | 177 | default: |
161 | return -EINVAL; | 178 | return -EINVAL; |
162 | } | 179 | } |
163 | PUT(control,MCT); | 180 | dev->ops->phy_put(dev, control, reg); |
164 | PRIV(dev)->loop_mode = mode; | 181 | PRIV(dev)->loop_mode = mode; |
165 | return 0; | 182 | return 0; |
166 | } | 183 | } |
167 | 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 | |||
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 | |||
168 | 254 | ||
169 | static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) | 255 | static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) |
170 | { | 256 | { |
@@ -179,14 +265,16 @@ static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) | |||
179 | case SONET_GETDIAG: | 265 | case SONET_GETDIAG: |
180 | return get_diag(dev,arg); | 266 | return get_diag(dev,arg); |
181 | case SONET_SETFRAMING: | 267 | case SONET_SETFRAMING: |
182 | if ((int)(unsigned long)arg != SONET_FRAME_SONET) return -EINVAL; | 268 | if (!capable(CAP_NET_ADMIN)) |
183 | return 0; | 269 | return -EPERM; |
270 | return set_framing(dev, arg); | ||
184 | case SONET_GETFRAMING: | 271 | case SONET_GETFRAMING: |
185 | return put_user(SONET_FRAME_SONET,(int __user *)arg) ? | 272 | return get_framing(dev, arg); |
186 | -EFAULT : 0; | ||
187 | case SONET_GETFRSENSE: | 273 | case SONET_GETFRSENSE: |
188 | return -EINVAL; | 274 | return -EINVAL; |
189 | case ATM_SETLOOP: | 275 | case ATM_SETLOOP: |
276 | if (!capable(CAP_NET_ADMIN)) | ||
277 | return -EPERM; | ||
190 | return set_loopback(dev,(int)(unsigned long)arg); | 278 | return set_loopback(dev,(int)(unsigned long)arg); |
191 | case ATM_GETLOOP: | 279 | case ATM_GETLOOP: |
192 | return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ? | 280 | return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ? |
@@ -220,10 +308,6 @@ static int suni_start(struct atm_dev *dev) | |||
220 | unsigned long flags; | 308 | unsigned long flags; |
221 | int first; | 309 | int first; |
222 | 310 | ||
223 | if (!(dev->phy_data = kmalloc(sizeof(struct suni_priv),GFP_KERNEL))) | ||
224 | return -ENOMEM; | ||
225 | |||
226 | PRIV(dev)->dev = dev; | ||
227 | spin_lock_irqsave(&sunis_lock,flags); | 311 | spin_lock_irqsave(&sunis_lock,flags); |
228 | first = !sunis; | 312 | first = !sunis; |
229 | PRIV(dev)->next = sunis; | 313 | PRIV(dev)->next = sunis; |
@@ -284,16 +368,21 @@ int suni_init(struct atm_dev *dev) | |||
284 | { | 368 | { |
285 | unsigned char mri; | 369 | unsigned char mri; |
286 | 370 | ||
371 | if (!(dev->phy_data = kmalloc(sizeof(struct suni_priv),GFP_KERNEL))) | ||
372 | return -ENOMEM; | ||
373 | PRIV(dev)->dev = dev; | ||
374 | |||
287 | mri = GET(MRI); /* reset SUNI */ | 375 | mri = GET(MRI); /* reset SUNI */ |
376 | PRIV(dev)->type = (mri & SUNI_MRI_TYPE) >> SUNI_MRI_TYPE_SHIFT; | ||
288 | PUT(mri | SUNI_MRI_RESET,MRI); | 377 | PUT(mri | SUNI_MRI_RESET,MRI); |
289 | PUT(mri,MRI); | 378 | PUT(mri,MRI); |
290 | PUT((GET(MT) & SUNI_MT_DS27_53),MT); /* disable all tests */ | 379 | 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, | 380 | set_sonet(dev); |
292 | TPOP_APM); /* use SONET */ | ||
293 | REG_CHANGE(SUNI_TACP_IUCHP_CLP,0,SUNI_TACP_IUCHP_CLP, | 381 | REG_CHANGE(SUNI_TACP_IUCHP_CLP,0,SUNI_TACP_IUCHP_CLP, |
294 | TACP_IUCHP); /* idle cells */ | 382 | TACP_IUCHP); /* idle cells */ |
295 | PUT(SUNI_IDLE_PATTERN,TACP_IUCPOP); | 383 | PUT(SUNI_IDLE_PATTERN,TACP_IUCPOP); |
296 | dev->phy = &suni_ops; | 384 | dev->phy = &suni_ops; |
385 | |||
297 | return 0; | 386 | return 0; |
298 | } | 387 | } |
299 | 388 | ||