1 /* $Id: lmc_media.c,v 1.13 2000/04/11 05:25:26 asj Exp $ */
3 #include <linux/kernel.h>
4 #include <linux/string.h>
5 #include <linux/timer.h>
6 #include <linux/ptrace.h>
7 #include <linux/errno.h>
8 #include <linux/ioport.h>
9 #include <linux/interrupt.h>
11 #include <linux/if_arp.h>
12 #include <linux/netdevice.h>
13 #include <linux/etherdevice.h>
14 #include <linux/skbuff.h>
15 #include <linux/inet.h>
16 #include <linux/bitops.h>
18 #include <asm/processor.h> /* Processor type for cache alignment. */
22 #include <asm/uaccess.h>
26 #include "lmc_ioctl.h"
27 #include "lmc_debug.h"
29 #define CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE 1
32 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
33 * All rights reserved. www.lanmedia.com
35 * This code is written by:
36 * Andrew Stanley-Jones (asj@cban.com)
37 * Rob Braun (bbraun@vix.com),
38 * Michael Graff (explorer@vix.com) and
39 * Matt Thomas (matt@3am-software.com).
41 * This software may be used and distributed according to the terms
42 * of the GNU General Public License version 2, incorporated herein by reference.
46 * protocol independent method.
48 static void lmc_set_protocol (lmc_softc_t
* const, lmc_ctl_t
*);
51 * media independent methods to check on media status, link, light LEDs,
54 static void lmc_ds3_init (lmc_softc_t
* const);
55 static void lmc_ds3_default (lmc_softc_t
* const);
56 static void lmc_ds3_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
57 static void lmc_ds3_set_100ft (lmc_softc_t
* const, int);
58 static int lmc_ds3_get_link_status (lmc_softc_t
* const);
59 static void lmc_ds3_set_crc_length (lmc_softc_t
* const, int);
60 static void lmc_ds3_set_scram (lmc_softc_t
* const, int);
61 static void lmc_ds3_watchdog (lmc_softc_t
* const);
63 static void lmc_hssi_init (lmc_softc_t
* const);
64 static void lmc_hssi_default (lmc_softc_t
* const);
65 static void lmc_hssi_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
66 static void lmc_hssi_set_clock (lmc_softc_t
* const, int);
67 static int lmc_hssi_get_link_status (lmc_softc_t
* const);
68 static void lmc_hssi_set_link_status (lmc_softc_t
* const, int);
69 static void lmc_hssi_set_crc_length (lmc_softc_t
* const, int);
70 static void lmc_hssi_watchdog (lmc_softc_t
* const);
72 static void lmc_ssi_init (lmc_softc_t
* const);
73 static void lmc_ssi_default (lmc_softc_t
* const);
74 static void lmc_ssi_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
75 static void lmc_ssi_set_clock (lmc_softc_t
* const, int);
76 static void lmc_ssi_set_speed (lmc_softc_t
* const, lmc_ctl_t
*);
77 static int lmc_ssi_get_link_status (lmc_softc_t
* const);
78 static void lmc_ssi_set_link_status (lmc_softc_t
* const, int);
79 static void lmc_ssi_set_crc_length (lmc_softc_t
* const, int);
80 static void lmc_ssi_watchdog (lmc_softc_t
* const);
82 static void lmc_t1_init (lmc_softc_t
* const);
83 static void lmc_t1_default (lmc_softc_t
* const);
84 static void lmc_t1_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
85 static int lmc_t1_get_link_status (lmc_softc_t
* const);
86 static void lmc_t1_set_circuit_type (lmc_softc_t
* const, int);
87 static void lmc_t1_set_crc_length (lmc_softc_t
* const, int);
88 static void lmc_t1_set_clock (lmc_softc_t
* const, int);
89 static void lmc_t1_watchdog (lmc_softc_t
* const);
91 static void lmc_dummy_set_1 (lmc_softc_t
* const, int);
92 static void lmc_dummy_set2_1 (lmc_softc_t
* const, lmc_ctl_t
*);
94 static inline void write_av9110_bit (lmc_softc_t
*, int);
95 static void write_av9110(lmc_softc_t
*, u32
, u32
, u32
, u32
, u32
);
97 lmc_media_t lmc_ds3_media
= {
98 lmc_ds3_init
, /* special media init stuff */
99 lmc_ds3_default
, /* reset to default state */
100 lmc_ds3_set_status
, /* reset status to state provided */
101 lmc_dummy_set_1
, /* set clock source */
102 lmc_dummy_set2_1
, /* set line speed */
103 lmc_ds3_set_100ft
, /* set cable length */
104 lmc_ds3_set_scram
, /* set scrambler */
105 lmc_ds3_get_link_status
, /* get link status */
106 lmc_dummy_set_1
, /* set link status */
107 lmc_ds3_set_crc_length
, /* set CRC length */
108 lmc_dummy_set_1
, /* set T1 or E1 circuit type */
112 lmc_media_t lmc_hssi_media
= {
113 lmc_hssi_init
, /* special media init stuff */
114 lmc_hssi_default
, /* reset to default state */
115 lmc_hssi_set_status
, /* reset status to state provided */
116 lmc_hssi_set_clock
, /* set clock source */
117 lmc_dummy_set2_1
, /* set line speed */
118 lmc_dummy_set_1
, /* set cable length */
119 lmc_dummy_set_1
, /* set scrambler */
120 lmc_hssi_get_link_status
, /* get link status */
121 lmc_hssi_set_link_status
, /* set link status */
122 lmc_hssi_set_crc_length
, /* set CRC length */
123 lmc_dummy_set_1
, /* set T1 or E1 circuit type */
127 lmc_media_t lmc_ssi_media
= { lmc_ssi_init
, /* special media init stuff */
128 lmc_ssi_default
, /* reset to default state */
129 lmc_ssi_set_status
, /* reset status to state provided */
130 lmc_ssi_set_clock
, /* set clock source */
131 lmc_ssi_set_speed
, /* set line speed */
132 lmc_dummy_set_1
, /* set cable length */
133 lmc_dummy_set_1
, /* set scrambler */
134 lmc_ssi_get_link_status
, /* get link status */
135 lmc_ssi_set_link_status
, /* set link status */
136 lmc_ssi_set_crc_length
, /* set CRC length */
137 lmc_dummy_set_1
, /* set T1 or E1 circuit type */
141 lmc_media_t lmc_t1_media
= {
142 lmc_t1_init
, /* special media init stuff */
143 lmc_t1_default
, /* reset to default state */
144 lmc_t1_set_status
, /* reset status to state provided */
145 lmc_t1_set_clock
, /* set clock source */
146 lmc_dummy_set2_1
, /* set line speed */
147 lmc_dummy_set_1
, /* set cable length */
148 lmc_dummy_set_1
, /* set scrambler */
149 lmc_t1_get_link_status
, /* get link status */
150 lmc_dummy_set_1
, /* set link status */
151 lmc_t1_set_crc_length
, /* set CRC length */
152 lmc_t1_set_circuit_type
, /* set T1 or E1 circuit type */
157 lmc_dummy_set_1 (lmc_softc_t
* const sc
, int a
)
162 lmc_dummy_set2_1 (lmc_softc_t
* const sc
, lmc_ctl_t
* a
)
171 lmc_hssi_init (lmc_softc_t
* const sc
)
173 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC5200
;
175 lmc_gpio_mkoutput (sc
, LMC_GEP_HSSI_CLOCK
);
179 lmc_hssi_default (lmc_softc_t
* const sc
)
181 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
183 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
184 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
185 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
189 * Given a user provided state, set ourselves up to match it. This will
190 * always reset the card if needed.
193 lmc_hssi_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
197 sc
->lmc_media
->set_clock_source (sc
, sc
->ictl
.clock_source
);
198 lmc_set_protocol (sc
, NULL
);
204 * check for change in clock source
206 if (ctl
->clock_source
&& !sc
->ictl
.clock_source
)
208 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_INT
);
209 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_INT
;
211 else if (!ctl
->clock_source
&& sc
->ictl
.clock_source
)
213 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_EXT
;
214 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
217 lmc_set_protocol (sc
, ctl
);
221 * 1 == internal, 0 == external
224 lmc_hssi_set_clock (lmc_softc_t
* const sc
, int ie
)
227 old
= sc
->ictl
.clock_source
;
228 if (ie
== LMC_CTL_CLOCK_SOURCE_EXT
)
230 sc
->lmc_gpio
|= LMC_GEP_HSSI_CLOCK
;
231 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
232 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_EXT
;
234 printk (LMC_PRINTF_FMT
": clock external\n", LMC_PRINTF_ARGS
);
238 sc
->lmc_gpio
&= ~(LMC_GEP_HSSI_CLOCK
);
239 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
240 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
242 printk (LMC_PRINTF_FMT
": clock internal\n", LMC_PRINTF_ARGS
);
247 * return hardware link status.
248 * 0 == link is down, 1 == link is up.
251 lmc_hssi_get_link_status (lmc_softc_t
* const sc
)
254 * We're using the same code as SSI since
255 * they're practically the same
257 return lmc_ssi_get_link_status(sc
);
261 lmc_hssi_set_link_status (lmc_softc_t
* const sc
, int state
)
263 if (state
== LMC_LINK_UP
)
264 sc
->lmc_miireg16
|= LMC_MII16_HSSI_TA
;
266 sc
->lmc_miireg16
&= ~LMC_MII16_HSSI_TA
;
268 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
272 * 0 == 16bit, 1 == 32bit
275 lmc_hssi_set_crc_length (lmc_softc_t
* const sc
, int state
)
277 if (state
== LMC_CTL_CRC_LENGTH_32
)
280 sc
->lmc_miireg16
|= LMC_MII16_HSSI_CRC
;
281 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
286 sc
->lmc_miireg16
&= ~LMC_MII16_HSSI_CRC
;
287 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
290 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
294 lmc_hssi_watchdog (lmc_softc_t
* const sc
)
307 lmc_ds3_set_100ft (lmc_softc_t
* const sc
, int ie
)
309 if (ie
== LMC_CTL_CABLE_LENGTH_GT_100FT
)
311 sc
->lmc_miireg16
&= ~LMC_MII16_DS3_ZERO
;
312 sc
->ictl
.cable_length
= LMC_CTL_CABLE_LENGTH_GT_100FT
;
314 else if (ie
== LMC_CTL_CABLE_LENGTH_LT_100FT
)
316 sc
->lmc_miireg16
|= LMC_MII16_DS3_ZERO
;
317 sc
->ictl
.cable_length
= LMC_CTL_CABLE_LENGTH_LT_100FT
;
319 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
323 lmc_ds3_default (lmc_softc_t
* const sc
)
325 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
327 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
328 sc
->lmc_media
->set_cable_length (sc
, LMC_CTL_CABLE_LENGTH_LT_100FT
);
329 sc
->lmc_media
->set_scrambler (sc
, LMC_CTL_OFF
);
330 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
334 * Given a user provided state, set ourselves up to match it. This will
335 * always reset the card if needed.
338 lmc_ds3_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
342 sc
->lmc_media
->set_cable_length (sc
, sc
->ictl
.cable_length
);
343 sc
->lmc_media
->set_scrambler (sc
, sc
->ictl
.scrambler_onoff
);
344 lmc_set_protocol (sc
, NULL
);
350 * check for change in cable length setting
352 if (ctl
->cable_length
&& !sc
->ictl
.cable_length
)
353 lmc_ds3_set_100ft (sc
, LMC_CTL_CABLE_LENGTH_GT_100FT
);
354 else if (!ctl
->cable_length
&& sc
->ictl
.cable_length
)
355 lmc_ds3_set_100ft (sc
, LMC_CTL_CABLE_LENGTH_LT_100FT
);
358 * Check for change in scrambler setting (requires reset)
360 if (ctl
->scrambler_onoff
&& !sc
->ictl
.scrambler_onoff
)
361 lmc_ds3_set_scram (sc
, LMC_CTL_ON
);
362 else if (!ctl
->scrambler_onoff
&& sc
->ictl
.scrambler_onoff
)
363 lmc_ds3_set_scram (sc
, LMC_CTL_OFF
);
365 lmc_set_protocol (sc
, ctl
);
369 lmc_ds3_init (lmc_softc_t
* const sc
)
373 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC5245
;
375 /* writes zeros everywhere */
376 for (i
= 0; i
< 21; i
++)
378 lmc_mii_writereg (sc
, 0, 17, i
);
379 lmc_mii_writereg (sc
, 0, 18, 0);
382 /* set some essential bits */
383 lmc_mii_writereg (sc
, 0, 17, 1);
384 lmc_mii_writereg (sc
, 0, 18, 0x25); /* ser, xtx */
386 lmc_mii_writereg (sc
, 0, 17, 5);
387 lmc_mii_writereg (sc
, 0, 18, 0x80); /* emode */
389 lmc_mii_writereg (sc
, 0, 17, 14);
390 lmc_mii_writereg (sc
, 0, 18, 0x30); /* rcgen, tcgen */
392 /* clear counters and latched bits */
393 for (i
= 0; i
< 21; i
++)
395 lmc_mii_writereg (sc
, 0, 17, i
);
396 lmc_mii_readreg (sc
, 0, 18);
401 * 1 == DS3 payload scrambled, 0 == not scrambled
404 lmc_ds3_set_scram (lmc_softc_t
* const sc
, int ie
)
406 if (ie
== LMC_CTL_ON
)
408 sc
->lmc_miireg16
|= LMC_MII16_DS3_SCRAM
;
409 sc
->ictl
.scrambler_onoff
= LMC_CTL_ON
;
413 sc
->lmc_miireg16
&= ~LMC_MII16_DS3_SCRAM
;
414 sc
->ictl
.scrambler_onoff
= LMC_CTL_OFF
;
416 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
420 * return hardware link status.
421 * 0 == link is down, 1 == link is up.
424 lmc_ds3_get_link_status (lmc_softc_t
* const sc
)
426 u16 link_status
, link_status_11
;
429 lmc_mii_writereg (sc
, 0, 17, 7);
430 link_status
= lmc_mii_readreg (sc
, 0, 18);
432 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
433 * led0 yellow = far-end adapter is in Red alarm condition
434 * led1 blue = received an Alarm Indication signal
436 * led2 Green = power to adapter, Gate Array loaded & driver
438 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
439 * conditions detected on T3 receive signal
442 lmc_led_on(sc
, LMC_DS3_LED2
);
444 if ((link_status
& LMC_FRAMER_REG0_DLOS
) ||
445 (link_status
& LMC_FRAMER_REG0_OOFS
)){
447 if(sc
->last_led_err
[3] != 1){
449 lmc_mii_writereg (sc
, 0, 17, 01); /* Turn on Xbit error as our cisco does */
450 r1
= lmc_mii_readreg (sc
, 0, 18);
452 lmc_mii_writereg(sc
, 0, 18, r1
);
453 printk(KERN_WARNING
"%s: Red Alarm - Loss of Signal or Loss of Framing\n", sc
->name
);
455 lmc_led_on(sc
, LMC_DS3_LED3
); /* turn on red LED */
456 sc
->last_led_err
[3] = 1;
459 lmc_led_off(sc
, LMC_DS3_LED3
); /* turn on red LED */
460 if(sc
->last_led_err
[3] == 1){
462 lmc_mii_writereg (sc
, 0, 17, 01); /* Turn off Xbit error */
463 r1
= lmc_mii_readreg (sc
, 0, 18);
465 lmc_mii_writereg(sc
, 0, 18, r1
);
467 sc
->last_led_err
[3] = 0;
470 lmc_mii_writereg(sc
, 0, 17, 0x10);
471 link_status_11
= lmc_mii_readreg(sc
, 0, 18);
472 if((link_status
& LMC_FRAMER_REG0_AIS
) ||
473 (link_status_11
& LMC_FRAMER_REG10_XBIT
)) {
475 if(sc
->last_led_err
[0] != 1){
476 printk(KERN_WARNING
"%s: AIS Alarm or XBit Error\n", sc
->name
);
477 printk(KERN_WARNING
"%s: Remote end has loss of signal or framing\n", sc
->name
);
479 lmc_led_on(sc
, LMC_DS3_LED0
);
480 sc
->last_led_err
[0] = 1;
483 lmc_led_off(sc
, LMC_DS3_LED0
);
484 sc
->last_led_err
[0] = 0;
487 lmc_mii_writereg (sc
, 0, 17, 9);
488 link_status
= lmc_mii_readreg (sc
, 0, 18);
490 if(link_status
& LMC_FRAMER_REG9_RBLUE
){
492 if(sc
->last_led_err
[1] != 1){
493 printk(KERN_WARNING
"%s: Blue Alarm - Receiving all 1's\n", sc
->name
);
495 lmc_led_on(sc
, LMC_DS3_LED1
);
496 sc
->last_led_err
[1] = 1;
499 lmc_led_off(sc
, LMC_DS3_LED1
);
500 sc
->last_led_err
[1] = 0;
507 * 0 == 16bit, 1 == 32bit
510 lmc_ds3_set_crc_length (lmc_softc_t
* const sc
, int state
)
512 if (state
== LMC_CTL_CRC_LENGTH_32
)
515 sc
->lmc_miireg16
|= LMC_MII16_DS3_CRC
;
516 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
521 sc
->lmc_miireg16
&= ~LMC_MII16_DS3_CRC
;
522 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
525 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
529 lmc_ds3_watchdog (lmc_softc_t
* const sc
)
539 static void lmc_ssi_init(lmc_softc_t
* const sc
)
544 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC1000
;
546 mii17
= lmc_mii_readreg(sc
, 0, 17);
548 cable
= (mii17
& LMC_MII17_SSI_CABLE_MASK
) >> LMC_MII17_SSI_CABLE_SHIFT
;
549 sc
->ictl
.cable_type
= cable
;
551 lmc_gpio_mkoutput(sc
, LMC_GEP_SSI_TXCLOCK
);
555 lmc_ssi_default (lmc_softc_t
* const sc
)
557 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
560 * make TXCLOCK always be an output
562 lmc_gpio_mkoutput (sc
, LMC_GEP_SSI_TXCLOCK
);
564 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
565 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
566 sc
->lmc_media
->set_speed (sc
, NULL
);
567 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
571 * Given a user provided state, set ourselves up to match it. This will
572 * always reset the card if needed.
575 lmc_ssi_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
579 sc
->lmc_media
->set_clock_source (sc
, sc
->ictl
.clock_source
);
580 sc
->lmc_media
->set_speed (sc
, &sc
->ictl
);
581 lmc_set_protocol (sc
, NULL
);
587 * check for change in clock source
589 if (ctl
->clock_source
== LMC_CTL_CLOCK_SOURCE_INT
590 && sc
->ictl
.clock_source
== LMC_CTL_CLOCK_SOURCE_EXT
)
592 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_INT
);
593 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_INT
;
595 else if (ctl
->clock_source
== LMC_CTL_CLOCK_SOURCE_EXT
596 && sc
->ictl
.clock_source
== LMC_CTL_CLOCK_SOURCE_INT
)
598 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
599 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_EXT
;
602 if (ctl
->clock_rate
!= sc
->ictl
.clock_rate
)
603 sc
->lmc_media
->set_speed (sc
, ctl
);
605 lmc_set_protocol (sc
, ctl
);
609 * 1 == internal, 0 == external
612 lmc_ssi_set_clock (lmc_softc_t
* const sc
, int ie
)
616 if (ie
== LMC_CTL_CLOCK_SOURCE_EXT
)
618 sc
->lmc_gpio
&= ~(LMC_GEP_SSI_TXCLOCK
);
619 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
620 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_EXT
;
622 printk (LMC_PRINTF_FMT
": clock external\n", LMC_PRINTF_ARGS
);
626 sc
->lmc_gpio
|= LMC_GEP_SSI_TXCLOCK
;
627 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
628 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
630 printk (LMC_PRINTF_FMT
": clock internal\n", LMC_PRINTF_ARGS
);
635 lmc_ssi_set_speed (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
637 lmc_ctl_t
*ictl
= &sc
->ictl
;
640 /* original settings for clock rate of:
641 * 100 Khz (8,25,0,0,2) were incorrect
642 * they should have been 80,125,1,3,3
643 * There are 17 param combinations to produce this freq.
644 * For 1.5 Mhz use 120,100,1,1,2 (226 param. combinations)
648 av
= &ictl
->cardspec
.ssi
;
649 ictl
->clock_rate
= 1500000;
650 av
->f
= ictl
->clock_rate
;
657 write_av9110 (sc
, av
->n
, av
->m
, av
->v
, av
->x
, av
->r
);
661 av
= &ctl
->cardspec
.ssi
;
666 ictl
->clock_rate
= av
->f
; /* really, this is the rate we are */
667 ictl
->cardspec
.ssi
= *av
;
669 write_av9110 (sc
, av
->n
, av
->m
, av
->v
, av
->x
, av
->r
);
673 * return hardware link status.
674 * 0 == link is down, 1 == link is up.
677 lmc_ssi_get_link_status (lmc_softc_t
* const sc
)
685 * missing CTS? Hmm. If we require CTS on, we may never get the
686 * link to come up, so omit it in this test.
688 * Also, it seems that with a loopback cable, DCD isn't asserted,
689 * so just check for things like this:
690 * DSR _must_ be asserted.
691 * One of DCD or CTS must be asserted.
694 /* LMC 1000 (SSI) LED definitions
695 * led0 Green = power to adapter, Gate Array loaded &
697 * led1 Green = DSR and DTR and RTS and CTS are set
698 * led2 Green = Cable detected
699 * led3 red = No timing is available from the
700 * cable or the on-board frequency
704 link_status
= lmc_mii_readreg (sc
, 0, 16);
706 /* Is the transmit clock still available */
707 ticks
= LMC_CSR_READ (sc
, csr_gp_timer
);
708 ticks
= 0x0000ffff - (ticks
& 0x0000ffff);
710 lmc_led_on (sc
, LMC_MII16_LED0
);
712 /* ====== transmit clock determination ===== */
713 if (sc
->lmc_timing
== LMC_CTL_CLOCK_SOURCE_INT
) {
714 lmc_led_off(sc
, LMC_MII16_LED3
);
716 else if (ticks
== 0 ) { /* no clock found ? */
718 if (sc
->last_led_err
[3] != 1) {
719 sc
->extra_stats
.tx_lossOfClockCnt
++;
720 printk(KERN_WARNING
"%s: Lost Clock, Link Down\n", sc
->name
);
722 sc
->last_led_err
[3] = 1;
723 lmc_led_on (sc
, LMC_MII16_LED3
); /* turn ON red LED */
726 if(sc
->last_led_err
[3] == 1)
727 printk(KERN_WARNING
"%s: Clock Returned\n", sc
->name
);
728 sc
->last_led_err
[3] = 0;
729 lmc_led_off (sc
, LMC_MII16_LED3
); /* turn OFF red LED */
732 if ((link_status
& LMC_MII16_SSI_DSR
) == 0) { /* Also HSSI CA */
737 #ifdef CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE
738 if ((link_status
& (LMC_MII16_SSI_CTS
| LMC_MII16_SSI_DCD
)) == 0){
745 if(sc
->last_led_err
[1] != 1)
746 printk(KERN_WARNING
"%s: DSR not asserted\n", sc
->name
);
747 sc
->last_led_err
[1] = 1;
748 lmc_led_off(sc
, LMC_MII16_LED1
);
751 if(sc
->last_led_err
[1] != 0)
752 printk(KERN_WARNING
"%s: DSR now asserted\n", sc
->name
);
753 sc
->last_led_err
[1] = 0;
754 lmc_led_on(sc
, LMC_MII16_LED1
);
758 lmc_led_on(sc
, LMC_MII16_LED2
); /* Over all good status? */
765 lmc_ssi_set_link_status (lmc_softc_t
* const sc
, int state
)
767 if (state
== LMC_LINK_UP
)
769 sc
->lmc_miireg16
|= (LMC_MII16_SSI_DTR
| LMC_MII16_SSI_RTS
);
770 printk (LMC_PRINTF_FMT
": asserting DTR and RTS\n", LMC_PRINTF_ARGS
);
774 sc
->lmc_miireg16
&= ~(LMC_MII16_SSI_DTR
| LMC_MII16_SSI_RTS
);
775 printk (LMC_PRINTF_FMT
": deasserting DTR and RTS\n", LMC_PRINTF_ARGS
);
778 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
783 * 0 == 16bit, 1 == 32bit
786 lmc_ssi_set_crc_length (lmc_softc_t
* const sc
, int state
)
788 if (state
== LMC_CTL_CRC_LENGTH_32
)
791 sc
->lmc_miireg16
|= LMC_MII16_SSI_CRC
;
792 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
793 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_4
;
799 sc
->lmc_miireg16
&= ~LMC_MII16_SSI_CRC
;
800 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
801 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_2
;
804 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
808 * These are bits to program the ssi frequency generator
811 write_av9110_bit (lmc_softc_t
* sc
, int c
)
814 * set the data bit as we need it.
816 sc
->lmc_gpio
&= ~(LMC_GEP_CLK
);
818 sc
->lmc_gpio
|= LMC_GEP_DATA
;
820 sc
->lmc_gpio
&= ~(LMC_GEP_DATA
);
821 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
824 * set the clock to high
826 sc
->lmc_gpio
|= LMC_GEP_CLK
;
827 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
830 * set the clock to low again.
832 sc
->lmc_gpio
&= ~(LMC_GEP_CLK
);
833 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
836 static void write_av9110(lmc_softc_t
*sc
, u32 n
, u32 m
, u32 v
, u32 x
, u32 r
)
841 printk (LMC_PRINTF_FMT
": speed %u, %d %d %d %d %d\n",
842 LMC_PRINTF_ARGS
, sc
->ictl
.clock_rate
, n
, m
, v
, x
, r
);
845 sc
->lmc_gpio
|= LMC_GEP_SSI_GENERATOR
;
846 sc
->lmc_gpio
&= ~(LMC_GEP_DATA
| LMC_GEP_CLK
);
847 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
850 * Set the TXCLOCK, GENERATOR, SERIAL, and SERIALCLK
853 lmc_gpio_mkoutput (sc
, (LMC_GEP_DATA
| LMC_GEP_CLK
854 | LMC_GEP_SSI_GENERATOR
));
856 sc
->lmc_gpio
&= ~(LMC_GEP_SSI_GENERATOR
);
857 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
860 * a shifting we will go...
862 for (i
= 0; i
< 7; i
++)
863 write_av9110_bit (sc
, n
>> i
);
864 for (i
= 0; i
< 7; i
++)
865 write_av9110_bit (sc
, m
>> i
);
866 for (i
= 0; i
< 1; i
++)
867 write_av9110_bit (sc
, v
>> i
);
868 for (i
= 0; i
< 2; i
++)
869 write_av9110_bit (sc
, x
>> i
);
870 for (i
= 0; i
< 2; i
++)
871 write_av9110_bit (sc
, r
>> i
);
872 for (i
= 0; i
< 5; i
++)
873 write_av9110_bit (sc
, 0x17 >> i
);
876 * stop driving serial-related signals
878 lmc_gpio_mkinput (sc
,
879 (LMC_GEP_DATA
| LMC_GEP_CLK
880 | LMC_GEP_SSI_GENERATOR
));
883 static void lmc_ssi_watchdog(lmc_softc_t
* const sc
)
885 u16 mii17
= lmc_mii_readreg(sc
, 0, 17);
886 if (((mii17
>> 3) & 7) == 7)
887 lmc_led_off(sc
, LMC_MII16_LED2
);
889 lmc_led_on(sc
, LMC_MII16_LED2
);
897 * The framer regs are multiplexed through MII regs 17 & 18
898 * write the register address to MII reg 17 and the * data to MII reg 18. */
900 lmc_t1_write (lmc_softc_t
* const sc
, int a
, int d
)
902 lmc_mii_writereg (sc
, 0, 17, a
);
903 lmc_mii_writereg (sc
, 0, 18, d
);
908 lmc_t1_read (lmc_softc_t * const sc, int a)
910 lmc_mii_writereg (sc, 0, 17, a);
911 return lmc_mii_readreg (sc, 0, 18);
917 lmc_t1_init (lmc_softc_t
* const sc
)
922 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC1200
;
923 mii16
= lmc_mii_readreg (sc
, 0, 16);
926 mii16
&= ~LMC_MII16_T1_RST
;
927 lmc_mii_writereg (sc
, 0, 16, mii16
| LMC_MII16_T1_RST
);
928 lmc_mii_writereg (sc
, 0, 16, mii16
);
930 /* set T1 or E1 line. Uses sc->lmcmii16 reg in function so update it */
931 sc
->lmc_miireg16
= mii16
;
932 lmc_t1_set_circuit_type(sc
, LMC_CTL_CIRCUIT_TYPE_T1
);
933 mii16
= sc
->lmc_miireg16
;
935 lmc_t1_write (sc
, 0x01, 0x1B); /* CR0 - primary control */
936 lmc_t1_write (sc
, 0x02, 0x42); /* JAT_CR - jitter atten config */
937 lmc_t1_write (sc
, 0x14, 0x00); /* LOOP - loopback config */
938 lmc_t1_write (sc
, 0x15, 0x00); /* DL3_TS - external data link timeslot */
939 lmc_t1_write (sc
, 0x18, 0xFF); /* PIO - programmable I/O */
940 lmc_t1_write (sc
, 0x19, 0x30); /* POE - programmable OE */
941 lmc_t1_write (sc
, 0x1A, 0x0F); /* CMUX - clock input mux */
942 lmc_t1_write (sc
, 0x20, 0x41); /* LIU_CR - RX LIU config */
943 lmc_t1_write (sc
, 0x22, 0x76); /* RLIU_CR - RX LIU config */
944 lmc_t1_write (sc
, 0x40, 0x03); /* RCR0 - RX config */
945 lmc_t1_write (sc
, 0x45, 0x00); /* RALM - RX alarm config */
946 lmc_t1_write (sc
, 0x46, 0x05); /* LATCH - RX alarm/err/cntr latch */
947 lmc_t1_write (sc
, 0x68, 0x40); /* TLIU_CR - TX LIU config */
948 lmc_t1_write (sc
, 0x70, 0x0D); /* TCR0 - TX framer config */
949 lmc_t1_write (sc
, 0x71, 0x05); /* TCR1 - TX config */
950 lmc_t1_write (sc
, 0x72, 0x0B); /* TFRM - TX frame format */
951 lmc_t1_write (sc
, 0x73, 0x00); /* TERROR - TX error insert */
952 lmc_t1_write (sc
, 0x74, 0x00); /* TMAN - TX manual Sa/FEBE config */
953 lmc_t1_write (sc
, 0x75, 0x00); /* TALM - TX alarm signal config */
954 lmc_t1_write (sc
, 0x76, 0x00); /* TPATT - TX test pattern config */
955 lmc_t1_write (sc
, 0x77, 0x00); /* TLB - TX inband loopback config */
956 lmc_t1_write (sc
, 0x90, 0x05); /* CLAD_CR - clock rate adapter config */
957 lmc_t1_write (sc
, 0x91, 0x05); /* CSEL - clad freq sel */
958 lmc_t1_write (sc
, 0xA6, 0x00); /* DL1_CTL - DL1 control */
959 lmc_t1_write (sc
, 0xB1, 0x00); /* DL2_CTL - DL2 control */
960 lmc_t1_write (sc
, 0xD0, 0x47); /* SBI_CR - sys bus iface config */
961 lmc_t1_write (sc
, 0xD1, 0x70); /* RSB_CR - RX sys bus config */
962 lmc_t1_write (sc
, 0xD4, 0x30); /* TSB_CR - TX sys bus config */
963 for (i
= 0; i
< 32; i
++)
965 lmc_t1_write (sc
, 0x0E0 + i
, 0x00); /* SBCn - sys bus per-channel ctl */
966 lmc_t1_write (sc
, 0x100 + i
, 0x00); /* TPCn - TX per-channel ctl */
967 lmc_t1_write (sc
, 0x180 + i
, 0x00); /* RPCn - RX per-channel ctl */
969 for (i
= 1; i
< 25; i
++)
971 lmc_t1_write (sc
, 0x0E0 + i
, 0x0D); /* SBCn - sys bus per-channel ctl */
974 mii16
|= LMC_MII16_T1_XOE
;
975 lmc_mii_writereg (sc
, 0, 16, mii16
);
976 sc
->lmc_miireg16
= mii16
;
980 lmc_t1_default (lmc_softc_t
* const sc
)
982 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
983 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
984 sc
->lmc_media
->set_circuit_type (sc
, LMC_CTL_CIRCUIT_TYPE_T1
);
985 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
986 /* Right now we can only clock from out internal source */
987 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
989 /* * Given a user provided state, set ourselves up to match it. This will * always reset the card if needed.
992 lmc_t1_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
996 sc
->lmc_media
->set_circuit_type (sc
, sc
->ictl
.circuit_type
);
997 lmc_set_protocol (sc
, NULL
);
1002 * check for change in circuit type */
1003 if (ctl
->circuit_type
== LMC_CTL_CIRCUIT_TYPE_T1
1004 && sc
->ictl
.circuit_type
==
1005 LMC_CTL_CIRCUIT_TYPE_E1
) sc
->lmc_media
->set_circuit_type (sc
,
1006 LMC_CTL_CIRCUIT_TYPE_E1
);
1007 else if (ctl
->circuit_type
== LMC_CTL_CIRCUIT_TYPE_E1
1008 && sc
->ictl
.circuit_type
== LMC_CTL_CIRCUIT_TYPE_T1
)
1009 sc
->lmc_media
->set_circuit_type (sc
, LMC_CTL_CIRCUIT_TYPE_T1
);
1010 lmc_set_protocol (sc
, ctl
);
1013 * return hardware link status.
1014 * 0 == link is down, 1 == link is up.
1016 lmc_t1_get_link_status (lmc_softc_t
* const sc
)
1021 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
1022 * led0 yellow = far-end adapter is in Red alarm condition
1023 * led1 blue = received an Alarm Indication signal
1024 * (upstream failure)
1025 * led2 Green = power to adapter, Gate Array loaded & driver
1027 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
1028 * conditions detected on T3 receive signal
1030 lmc_trace(sc
->lmc_device
, "lmc_t1_get_link_status in");
1031 lmc_led_on(sc
, LMC_DS3_LED2
);
1033 lmc_mii_writereg (sc
, 0, 17, T1FRAMER_ALARM1_STATUS
);
1034 link_status
= lmc_mii_readreg (sc
, 0, 18);
1037 if (link_status
& T1F_RAIS
) { /* turn on blue LED */
1039 if(sc
->last_led_err
[1] != 1){
1040 printk(KERN_WARNING
"%s: Receive AIS/Blue Alarm. Far end in RED alarm\n", sc
->name
);
1042 lmc_led_on(sc
, LMC_DS3_LED1
);
1043 sc
->last_led_err
[1] = 1;
1046 if(sc
->last_led_err
[1] != 0){
1047 printk(KERN_WARNING
"%s: End AIS/Blue Alarm\n", sc
->name
);
1049 lmc_led_off (sc
, LMC_DS3_LED1
);
1050 sc
->last_led_err
[1] = 0;
1054 * Yellow Alarm is nasty evil stuff, looks at data patterns
1055 * inside the channel and confuses it with HDLC framing
1056 * ignore all yellow alarms.
1058 * Do listen to MultiFrame Yellow alarm which while implemented
1059 * different ways isn't in the channel and hence somewhat
1063 if (link_status
& T1F_RMYEL
) {
1065 if(sc
->last_led_err
[0] != 1){
1066 printk(KERN_WARNING
"%s: Receive Yellow AIS Alarm\n", sc
->name
);
1068 lmc_led_on(sc
, LMC_DS3_LED0
);
1069 sc
->last_led_err
[0] = 1;
1072 if(sc
->last_led_err
[0] != 0){
1073 printk(KERN_WARNING
"%s: End of Yellow AIS Alarm\n", sc
->name
);
1075 lmc_led_off(sc
, LMC_DS3_LED0
);
1076 sc
->last_led_err
[0] = 0;
1080 * Loss of signal and los of frame
1081 * Use the green bit to identify which one lit the led
1083 if(link_status
& T1F_RLOF
){
1085 if(sc
->last_led_err
[3] != 1){
1086 printk(KERN_WARNING
"%s: Local Red Alarm: Loss of Framing\n", sc
->name
);
1088 lmc_led_on(sc
, LMC_DS3_LED3
);
1089 sc
->last_led_err
[3] = 1;
1093 if(sc
->last_led_err
[3] != 0){
1094 printk(KERN_WARNING
"%s: End Red Alarm (LOF)\n", sc
->name
);
1096 if( ! (link_status
& T1F_RLOS
))
1097 lmc_led_off(sc
, LMC_DS3_LED3
);
1098 sc
->last_led_err
[3] = 0;
1101 if(link_status
& T1F_RLOS
){
1103 if(sc
->last_led_err
[2] != 1){
1104 printk(KERN_WARNING
"%s: Local Red Alarm: Loss of Signal\n", sc
->name
);
1106 lmc_led_on(sc
, LMC_DS3_LED3
);
1107 sc
->last_led_err
[2] = 1;
1111 if(sc
->last_led_err
[2] != 0){
1112 printk(KERN_WARNING
"%s: End Red Alarm (LOS)\n", sc
->name
);
1114 if( ! (link_status
& T1F_RLOF
))
1115 lmc_led_off(sc
, LMC_DS3_LED3
);
1116 sc
->last_led_err
[2] = 0;
1119 sc
->lmc_xinfo
.t1_alarm1_status
= link_status
;
1121 lmc_mii_writereg (sc
, 0, 17, T1FRAMER_ALARM2_STATUS
);
1122 sc
->lmc_xinfo
.t1_alarm2_status
= lmc_mii_readreg (sc
, 0, 18);
1125 lmc_trace(sc
->lmc_device
, "lmc_t1_get_link_status out");
1131 * 1 == T1 Circuit Type , 0 == E1 Circuit Type
1134 lmc_t1_set_circuit_type (lmc_softc_t
* const sc
, int ie
)
1136 if (ie
== LMC_CTL_CIRCUIT_TYPE_T1
) {
1137 sc
->lmc_miireg16
|= LMC_MII16_T1_Z
;
1138 sc
->ictl
.circuit_type
= LMC_CTL_CIRCUIT_TYPE_T1
;
1139 printk(KERN_INFO
"%s: In T1 Mode\n", sc
->name
);
1142 sc
->lmc_miireg16
&= ~LMC_MII16_T1_Z
;
1143 sc
->ictl
.circuit_type
= LMC_CTL_CIRCUIT_TYPE_E1
;
1144 printk(KERN_INFO
"%s: In E1 Mode\n", sc
->name
);
1147 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
1152 * 0 == 16bit, 1 == 32bit */
1154 lmc_t1_set_crc_length (lmc_softc_t
* const sc
, int state
)
1156 if (state
== LMC_CTL_CRC_LENGTH_32
)
1159 sc
->lmc_miireg16
|= LMC_MII16_T1_CRC
;
1160 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
1161 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_4
;
1166 /* 16 bit */ sc
->lmc_miireg16
&= ~LMC_MII16_T1_CRC
;
1167 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
1168 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_2
;
1172 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
1176 * 1 == internal, 0 == external
1179 lmc_t1_set_clock (lmc_softc_t
* const sc
, int ie
)
1183 if (ie
== LMC_CTL_CLOCK_SOURCE_EXT
)
1185 sc
->lmc_gpio
&= ~(LMC_GEP_SSI_TXCLOCK
);
1186 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
1187 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_EXT
;
1189 printk (LMC_PRINTF_FMT
": clock external\n", LMC_PRINTF_ARGS
);
1193 sc
->lmc_gpio
|= LMC_GEP_SSI_TXCLOCK
;
1194 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
1195 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
1197 printk (LMC_PRINTF_FMT
": clock internal\n", LMC_PRINTF_ARGS
);
1202 lmc_t1_watchdog (lmc_softc_t
* const sc
)
1207 lmc_set_protocol (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
1210 sc
->ictl
.keepalive_onoff
= LMC_CTL_ON
;