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/slab.h>
10 #include <linux/interrupt.h>
12 #include <linux/if_arp.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <linux/skbuff.h>
16 #include <linux/inet.h>
17 #include <linux/bitops.h>
19 #include <net/syncppp.h>
21 #include <asm/processor.h> /* Processor type for cache alignment. */
25 #include <asm/uaccess.h>
29 #include "lmc_ioctl.h"
30 #include "lmc_debug.h"
32 #define CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE 1
35 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
36 * All rights reserved. www.lanmedia.com
38 * This code is written by:
39 * Andrew Stanley-Jones (asj@cban.com)
40 * Rob Braun (bbraun@vix.com),
41 * Michael Graff (explorer@vix.com) and
42 * Matt Thomas (matt@3am-software.com).
44 * This software may be used and distributed according to the terms
45 * of the GNU General Public License version 2, incorporated herein by reference.
49 * protocol independent method.
51 static void lmc_set_protocol (lmc_softc_t
* const, lmc_ctl_t
*);
54 * media independent methods to check on media status, link, light LEDs,
57 static void lmc_ds3_init (lmc_softc_t
* const);
58 static void lmc_ds3_default (lmc_softc_t
* const);
59 static void lmc_ds3_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
60 static void lmc_ds3_set_100ft (lmc_softc_t
* const, int);
61 static int lmc_ds3_get_link_status (lmc_softc_t
* const);
62 static void lmc_ds3_set_crc_length (lmc_softc_t
* const, int);
63 static void lmc_ds3_set_scram (lmc_softc_t
* const, int);
64 static void lmc_ds3_watchdog (lmc_softc_t
* const);
66 static void lmc_hssi_init (lmc_softc_t
* const);
67 static void lmc_hssi_default (lmc_softc_t
* const);
68 static void lmc_hssi_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
69 static void lmc_hssi_set_clock (lmc_softc_t
* const, int);
70 static int lmc_hssi_get_link_status (lmc_softc_t
* const);
71 static void lmc_hssi_set_link_status (lmc_softc_t
* const, int);
72 static void lmc_hssi_set_crc_length (lmc_softc_t
* const, int);
73 static void lmc_hssi_watchdog (lmc_softc_t
* const);
75 static void lmc_ssi_init (lmc_softc_t
* const);
76 static void lmc_ssi_default (lmc_softc_t
* const);
77 static void lmc_ssi_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
78 static void lmc_ssi_set_clock (lmc_softc_t
* const, int);
79 static void lmc_ssi_set_speed (lmc_softc_t
* const, lmc_ctl_t
*);
80 static int lmc_ssi_get_link_status (lmc_softc_t
* const);
81 static void lmc_ssi_set_link_status (lmc_softc_t
* const, int);
82 static void lmc_ssi_set_crc_length (lmc_softc_t
* const, int);
83 static void lmc_ssi_watchdog (lmc_softc_t
* const);
85 static void lmc_t1_init (lmc_softc_t
* const);
86 static void lmc_t1_default (lmc_softc_t
* const);
87 static void lmc_t1_set_status (lmc_softc_t
* const, lmc_ctl_t
*);
88 static int lmc_t1_get_link_status (lmc_softc_t
* const);
89 static void lmc_t1_set_circuit_type (lmc_softc_t
* const, int);
90 static void lmc_t1_set_crc_length (lmc_softc_t
* const, int);
91 static void lmc_t1_set_clock (lmc_softc_t
* const, int);
92 static void lmc_t1_watchdog (lmc_softc_t
* const);
94 static void lmc_dummy_set_1 (lmc_softc_t
* const, int);
95 static void lmc_dummy_set2_1 (lmc_softc_t
* const, lmc_ctl_t
*);
97 static inline void write_av9110_bit (lmc_softc_t
*, int);
98 static void write_av9110 (lmc_softc_t
*, u_int32_t
, u_int32_t
, u_int32_t
,
99 u_int32_t
, u_int32_t
);
101 lmc_media_t lmc_ds3_media
= {
102 lmc_ds3_init
, /* special media init stuff */
103 lmc_ds3_default
, /* reset to default state */
104 lmc_ds3_set_status
, /* reset status to state provided */
105 lmc_dummy_set_1
, /* set clock source */
106 lmc_dummy_set2_1
, /* set line speed */
107 lmc_ds3_set_100ft
, /* set cable length */
108 lmc_ds3_set_scram
, /* set scrambler */
109 lmc_ds3_get_link_status
, /* get link status */
110 lmc_dummy_set_1
, /* set link status */
111 lmc_ds3_set_crc_length
, /* set CRC length */
112 lmc_dummy_set_1
, /* set T1 or E1 circuit type */
116 lmc_media_t lmc_hssi_media
= {
117 lmc_hssi_init
, /* special media init stuff */
118 lmc_hssi_default
, /* reset to default state */
119 lmc_hssi_set_status
, /* reset status to state provided */
120 lmc_hssi_set_clock
, /* set clock source */
121 lmc_dummy_set2_1
, /* set line speed */
122 lmc_dummy_set_1
, /* set cable length */
123 lmc_dummy_set_1
, /* set scrambler */
124 lmc_hssi_get_link_status
, /* get link status */
125 lmc_hssi_set_link_status
, /* set link status */
126 lmc_hssi_set_crc_length
, /* set CRC length */
127 lmc_dummy_set_1
, /* set T1 or E1 circuit type */
131 lmc_media_t lmc_ssi_media
= { lmc_ssi_init
, /* special media init stuff */
132 lmc_ssi_default
, /* reset to default state */
133 lmc_ssi_set_status
, /* reset status to state provided */
134 lmc_ssi_set_clock
, /* set clock source */
135 lmc_ssi_set_speed
, /* set line speed */
136 lmc_dummy_set_1
, /* set cable length */
137 lmc_dummy_set_1
, /* set scrambler */
138 lmc_ssi_get_link_status
, /* get link status */
139 lmc_ssi_set_link_status
, /* set link status */
140 lmc_ssi_set_crc_length
, /* set CRC length */
141 lmc_dummy_set_1
, /* set T1 or E1 circuit type */
145 lmc_media_t lmc_t1_media
= {
146 lmc_t1_init
, /* special media init stuff */
147 lmc_t1_default
, /* reset to default state */
148 lmc_t1_set_status
, /* reset status to state provided */
149 lmc_t1_set_clock
, /* set clock source */
150 lmc_dummy_set2_1
, /* set line speed */
151 lmc_dummy_set_1
, /* set cable length */
152 lmc_dummy_set_1
, /* set scrambler */
153 lmc_t1_get_link_status
, /* get link status */
154 lmc_dummy_set_1
, /* set link status */
155 lmc_t1_set_crc_length
, /* set CRC length */
156 lmc_t1_set_circuit_type
, /* set T1 or E1 circuit type */
161 lmc_dummy_set_1 (lmc_softc_t
* const sc
, int a
)
166 lmc_dummy_set2_1 (lmc_softc_t
* const sc
, lmc_ctl_t
* a
)
175 lmc_hssi_init (lmc_softc_t
* const sc
)
177 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC5200
;
179 lmc_gpio_mkoutput (sc
, LMC_GEP_HSSI_CLOCK
);
183 lmc_hssi_default (lmc_softc_t
* const sc
)
185 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
187 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
188 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
189 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
193 * Given a user provided state, set ourselves up to match it. This will
194 * always reset the card if needed.
197 lmc_hssi_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
201 sc
->lmc_media
->set_clock_source (sc
, sc
->ictl
.clock_source
);
202 lmc_set_protocol (sc
, NULL
);
208 * check for change in clock source
210 if (ctl
->clock_source
&& !sc
->ictl
.clock_source
)
212 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_INT
);
213 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_INT
;
215 else if (!ctl
->clock_source
&& sc
->ictl
.clock_source
)
217 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_EXT
;
218 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
221 lmc_set_protocol (sc
, ctl
);
225 * 1 == internal, 0 == external
228 lmc_hssi_set_clock (lmc_softc_t
* const sc
, int ie
)
231 old
= sc
->ictl
.clock_source
;
232 if (ie
== LMC_CTL_CLOCK_SOURCE_EXT
)
234 sc
->lmc_gpio
|= LMC_GEP_HSSI_CLOCK
;
235 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
236 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_EXT
;
238 printk (LMC_PRINTF_FMT
": clock external\n", LMC_PRINTF_ARGS
);
242 sc
->lmc_gpio
&= ~(LMC_GEP_HSSI_CLOCK
);
243 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
244 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
246 printk (LMC_PRINTF_FMT
": clock internal\n", LMC_PRINTF_ARGS
);
251 * return hardware link status.
252 * 0 == link is down, 1 == link is up.
255 lmc_hssi_get_link_status (lmc_softc_t
* const sc
)
258 * We're using the same code as SSI since
259 * they're practically the same
261 return lmc_ssi_get_link_status(sc
);
265 lmc_hssi_set_link_status (lmc_softc_t
* const sc
, int state
)
267 if (state
== LMC_LINK_UP
)
268 sc
->lmc_miireg16
|= LMC_MII16_HSSI_TA
;
270 sc
->lmc_miireg16
&= ~LMC_MII16_HSSI_TA
;
272 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
276 * 0 == 16bit, 1 == 32bit
279 lmc_hssi_set_crc_length (lmc_softc_t
* const sc
, int state
)
281 if (state
== LMC_CTL_CRC_LENGTH_32
)
284 sc
->lmc_miireg16
|= LMC_MII16_HSSI_CRC
;
285 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
290 sc
->lmc_miireg16
&= ~LMC_MII16_HSSI_CRC
;
291 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
294 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
298 lmc_hssi_watchdog (lmc_softc_t
* const sc
)
311 lmc_ds3_set_100ft (lmc_softc_t
* const sc
, int ie
)
313 if (ie
== LMC_CTL_CABLE_LENGTH_GT_100FT
)
315 sc
->lmc_miireg16
&= ~LMC_MII16_DS3_ZERO
;
316 sc
->ictl
.cable_length
= LMC_CTL_CABLE_LENGTH_GT_100FT
;
318 else if (ie
== LMC_CTL_CABLE_LENGTH_LT_100FT
)
320 sc
->lmc_miireg16
|= LMC_MII16_DS3_ZERO
;
321 sc
->ictl
.cable_length
= LMC_CTL_CABLE_LENGTH_LT_100FT
;
323 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
327 lmc_ds3_default (lmc_softc_t
* const sc
)
329 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
331 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
332 sc
->lmc_media
->set_cable_length (sc
, LMC_CTL_CABLE_LENGTH_LT_100FT
);
333 sc
->lmc_media
->set_scrambler (sc
, LMC_CTL_OFF
);
334 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
338 * Given a user provided state, set ourselves up to match it. This will
339 * always reset the card if needed.
342 lmc_ds3_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
346 sc
->lmc_media
->set_cable_length (sc
, sc
->ictl
.cable_length
);
347 sc
->lmc_media
->set_scrambler (sc
, sc
->ictl
.scrambler_onoff
);
348 lmc_set_protocol (sc
, NULL
);
354 * check for change in cable length setting
356 if (ctl
->cable_length
&& !sc
->ictl
.cable_length
)
357 lmc_ds3_set_100ft (sc
, LMC_CTL_CABLE_LENGTH_GT_100FT
);
358 else if (!ctl
->cable_length
&& sc
->ictl
.cable_length
)
359 lmc_ds3_set_100ft (sc
, LMC_CTL_CABLE_LENGTH_LT_100FT
);
362 * Check for change in scrambler setting (requires reset)
364 if (ctl
->scrambler_onoff
&& !sc
->ictl
.scrambler_onoff
)
365 lmc_ds3_set_scram (sc
, LMC_CTL_ON
);
366 else if (!ctl
->scrambler_onoff
&& sc
->ictl
.scrambler_onoff
)
367 lmc_ds3_set_scram (sc
, LMC_CTL_OFF
);
369 lmc_set_protocol (sc
, ctl
);
373 lmc_ds3_init (lmc_softc_t
* const sc
)
377 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC5245
;
379 /* writes zeros everywhere */
380 for (i
= 0; i
< 21; i
++)
382 lmc_mii_writereg (sc
, 0, 17, i
);
383 lmc_mii_writereg (sc
, 0, 18, 0);
386 /* set some essential bits */
387 lmc_mii_writereg (sc
, 0, 17, 1);
388 lmc_mii_writereg (sc
, 0, 18, 0x25); /* ser, xtx */
390 lmc_mii_writereg (sc
, 0, 17, 5);
391 lmc_mii_writereg (sc
, 0, 18, 0x80); /* emode */
393 lmc_mii_writereg (sc
, 0, 17, 14);
394 lmc_mii_writereg (sc
, 0, 18, 0x30); /* rcgen, tcgen */
396 /* clear counters and latched bits */
397 for (i
= 0; i
< 21; i
++)
399 lmc_mii_writereg (sc
, 0, 17, i
);
400 lmc_mii_readreg (sc
, 0, 18);
405 * 1 == DS3 payload scrambled, 0 == not scrambled
408 lmc_ds3_set_scram (lmc_softc_t
* const sc
, int ie
)
410 if (ie
== LMC_CTL_ON
)
412 sc
->lmc_miireg16
|= LMC_MII16_DS3_SCRAM
;
413 sc
->ictl
.scrambler_onoff
= LMC_CTL_ON
;
417 sc
->lmc_miireg16
&= ~LMC_MII16_DS3_SCRAM
;
418 sc
->ictl
.scrambler_onoff
= LMC_CTL_OFF
;
420 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
424 * return hardware link status.
425 * 0 == link is down, 1 == link is up.
428 lmc_ds3_get_link_status (lmc_softc_t
* const sc
)
430 u_int16_t link_status
, link_status_11
;
433 lmc_mii_writereg (sc
, 0, 17, 7);
434 link_status
= lmc_mii_readreg (sc
, 0, 18);
436 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
437 * led0 yellow = far-end adapter is in Red alarm condition
438 * led1 blue = received an Alarm Indication signal
440 * led2 Green = power to adapter, Gate Array loaded & driver
442 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
443 * conditions detected on T3 receive signal
446 lmc_led_on(sc
, LMC_DS3_LED2
);
448 if ((link_status
& LMC_FRAMER_REG0_DLOS
) ||
449 (link_status
& LMC_FRAMER_REG0_OOFS
)){
451 if(sc
->last_led_err
[3] != 1){
453 lmc_mii_writereg (sc
, 0, 17, 01); /* Turn on Xbit error as our cisco does */
454 r1
= lmc_mii_readreg (sc
, 0, 18);
456 lmc_mii_writereg(sc
, 0, 18, r1
);
457 printk(KERN_WARNING
"%s: Red Alarm - Loss of Signal or Loss of Framing\n", sc
->name
);
459 lmc_led_on(sc
, LMC_DS3_LED3
); /* turn on red LED */
460 sc
->last_led_err
[3] = 1;
463 lmc_led_off(sc
, LMC_DS3_LED3
); /* turn on red LED */
464 if(sc
->last_led_err
[3] == 1){
466 lmc_mii_writereg (sc
, 0, 17, 01); /* Turn off Xbit error */
467 r1
= lmc_mii_readreg (sc
, 0, 18);
469 lmc_mii_writereg(sc
, 0, 18, r1
);
471 sc
->last_led_err
[3] = 0;
474 lmc_mii_writereg(sc
, 0, 17, 0x10);
475 link_status_11
= lmc_mii_readreg(sc
, 0, 18);
476 if((link_status
& LMC_FRAMER_REG0_AIS
) ||
477 (link_status_11
& LMC_FRAMER_REG10_XBIT
)) {
479 if(sc
->last_led_err
[0] != 1){
480 printk(KERN_WARNING
"%s: AIS Alarm or XBit Error\n", sc
->name
);
481 printk(KERN_WARNING
"%s: Remote end has loss of signal or framing\n", sc
->name
);
483 lmc_led_on(sc
, LMC_DS3_LED0
);
484 sc
->last_led_err
[0] = 1;
487 lmc_led_off(sc
, LMC_DS3_LED0
);
488 sc
->last_led_err
[0] = 0;
491 lmc_mii_writereg (sc
, 0, 17, 9);
492 link_status
= lmc_mii_readreg (sc
, 0, 18);
494 if(link_status
& LMC_FRAMER_REG9_RBLUE
){
496 if(sc
->last_led_err
[1] != 1){
497 printk(KERN_WARNING
"%s: Blue Alarm - Receiving all 1's\n", sc
->name
);
499 lmc_led_on(sc
, LMC_DS3_LED1
);
500 sc
->last_led_err
[1] = 1;
503 lmc_led_off(sc
, LMC_DS3_LED1
);
504 sc
->last_led_err
[1] = 0;
511 * 0 == 16bit, 1 == 32bit
514 lmc_ds3_set_crc_length (lmc_softc_t
* const sc
, int state
)
516 if (state
== LMC_CTL_CRC_LENGTH_32
)
519 sc
->lmc_miireg16
|= LMC_MII16_DS3_CRC
;
520 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
525 sc
->lmc_miireg16
&= ~LMC_MII16_DS3_CRC
;
526 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
529 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
533 lmc_ds3_watchdog (lmc_softc_t
* const sc
)
544 lmc_ssi_init (lmc_softc_t
* const sc
)
549 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC1000
;
551 mii17
= lmc_mii_readreg (sc
, 0, 17);
553 cable
= (mii17
& LMC_MII17_SSI_CABLE_MASK
) >> LMC_MII17_SSI_CABLE_SHIFT
;
554 sc
->ictl
.cable_type
= cable
;
556 lmc_gpio_mkoutput (sc
, LMC_GEP_SSI_TXCLOCK
);
560 lmc_ssi_default (lmc_softc_t
* const sc
)
562 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
565 * make TXCLOCK always be an output
567 lmc_gpio_mkoutput (sc
, LMC_GEP_SSI_TXCLOCK
);
569 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
570 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
571 sc
->lmc_media
->set_speed (sc
, NULL
);
572 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
576 * Given a user provided state, set ourselves up to match it. This will
577 * always reset the card if needed.
580 lmc_ssi_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
584 sc
->lmc_media
->set_clock_source (sc
, sc
->ictl
.clock_source
);
585 sc
->lmc_media
->set_speed (sc
, &sc
->ictl
);
586 lmc_set_protocol (sc
, NULL
);
592 * check for change in clock source
594 if (ctl
->clock_source
== LMC_CTL_CLOCK_SOURCE_INT
595 && sc
->ictl
.clock_source
== LMC_CTL_CLOCK_SOURCE_EXT
)
597 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_INT
);
598 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_INT
;
600 else if (ctl
->clock_source
== LMC_CTL_CLOCK_SOURCE_EXT
601 && sc
->ictl
.clock_source
== LMC_CTL_CLOCK_SOURCE_INT
)
603 sc
->lmc_media
->set_clock_source (sc
, LMC_CTL_CLOCK_SOURCE_EXT
);
604 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_EXT
;
607 if (ctl
->clock_rate
!= sc
->ictl
.clock_rate
)
608 sc
->lmc_media
->set_speed (sc
, ctl
);
610 lmc_set_protocol (sc
, ctl
);
614 * 1 == internal, 0 == external
617 lmc_ssi_set_clock (lmc_softc_t
* const sc
, int ie
)
621 if (ie
== LMC_CTL_CLOCK_SOURCE_EXT
)
623 sc
->lmc_gpio
&= ~(LMC_GEP_SSI_TXCLOCK
);
624 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
625 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_EXT
;
627 printk (LMC_PRINTF_FMT
": clock external\n", LMC_PRINTF_ARGS
);
631 sc
->lmc_gpio
|= LMC_GEP_SSI_TXCLOCK
;
632 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
633 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
635 printk (LMC_PRINTF_FMT
": clock internal\n", LMC_PRINTF_ARGS
);
640 lmc_ssi_set_speed (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
642 lmc_ctl_t
*ictl
= &sc
->ictl
;
645 /* original settings for clock rate of:
646 * 100 Khz (8,25,0,0,2) were incorrect
647 * they should have been 80,125,1,3,3
648 * There are 17 param combinations to produce this freq.
649 * For 1.5 Mhz use 120,100,1,1,2 (226 param. combinations)
653 av
= &ictl
->cardspec
.ssi
;
654 ictl
->clock_rate
= 1500000;
655 av
->f
= ictl
->clock_rate
;
662 write_av9110 (sc
, av
->n
, av
->m
, av
->v
, av
->x
, av
->r
);
666 av
= &ctl
->cardspec
.ssi
;
671 ictl
->clock_rate
= av
->f
; /* really, this is the rate we are */
672 ictl
->cardspec
.ssi
= *av
;
674 write_av9110 (sc
, av
->n
, av
->m
, av
->v
, av
->x
, av
->r
);
678 * return hardware link status.
679 * 0 == link is down, 1 == link is up.
682 lmc_ssi_get_link_status (lmc_softc_t
* const sc
)
684 u_int16_t link_status
;
690 * missing CTS? Hmm. If we require CTS on, we may never get the
691 * link to come up, so omit it in this test.
693 * Also, it seems that with a loopback cable, DCD isn't asserted,
694 * so just check for things like this:
695 * DSR _must_ be asserted.
696 * One of DCD or CTS must be asserted.
699 /* LMC 1000 (SSI) LED definitions
700 * led0 Green = power to adapter, Gate Array loaded &
702 * led1 Green = DSR and DTR and RTS and CTS are set
703 * led2 Green = Cable detected
704 * led3 red = No timing is available from the
705 * cable or the on-board frequency
709 link_status
= lmc_mii_readreg (sc
, 0, 16);
711 /* Is the transmit clock still available */
712 ticks
= LMC_CSR_READ (sc
, csr_gp_timer
);
713 ticks
= 0x0000ffff - (ticks
& 0x0000ffff);
715 lmc_led_on (sc
, LMC_MII16_LED0
);
717 /* ====== transmit clock determination ===== */
718 if (sc
->lmc_timing
== LMC_CTL_CLOCK_SOURCE_INT
) {
719 lmc_led_off(sc
, LMC_MII16_LED3
);
721 else if (ticks
== 0 ) { /* no clock found ? */
723 if(sc
->last_led_err
[3] != 1){
724 sc
->stats
.tx_lossOfClockCnt
++;
725 printk(KERN_WARNING
"%s: Lost Clock, Link Down\n", sc
->name
);
727 sc
->last_led_err
[3] = 1;
728 lmc_led_on (sc
, LMC_MII16_LED3
); /* turn ON red LED */
731 if(sc
->last_led_err
[3] == 1)
732 printk(KERN_WARNING
"%s: Clock Returned\n", sc
->name
);
733 sc
->last_led_err
[3] = 0;
734 lmc_led_off (sc
, LMC_MII16_LED3
); /* turn OFF red LED */
737 if ((link_status
& LMC_MII16_SSI_DSR
) == 0) { /* Also HSSI CA */
742 #ifdef CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE
743 if ((link_status
& (LMC_MII16_SSI_CTS
| LMC_MII16_SSI_DCD
)) == 0){
750 if(sc
->last_led_err
[1] != 1)
751 printk(KERN_WARNING
"%s: DSR not asserted\n", sc
->name
);
752 sc
->last_led_err
[1] = 1;
753 lmc_led_off(sc
, LMC_MII16_LED1
);
756 if(sc
->last_led_err
[1] != 0)
757 printk(KERN_WARNING
"%s: DSR now asserted\n", sc
->name
);
758 sc
->last_led_err
[1] = 0;
759 lmc_led_on(sc
, LMC_MII16_LED1
);
763 lmc_led_on(sc
, LMC_MII16_LED2
); /* Over all good status? */
770 lmc_ssi_set_link_status (lmc_softc_t
* const sc
, int state
)
772 if (state
== LMC_LINK_UP
)
774 sc
->lmc_miireg16
|= (LMC_MII16_SSI_DTR
| LMC_MII16_SSI_RTS
);
775 printk (LMC_PRINTF_FMT
": asserting DTR and RTS\n", LMC_PRINTF_ARGS
);
779 sc
->lmc_miireg16
&= ~(LMC_MII16_SSI_DTR
| LMC_MII16_SSI_RTS
);
780 printk (LMC_PRINTF_FMT
": deasserting DTR and RTS\n", LMC_PRINTF_ARGS
);
783 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
788 * 0 == 16bit, 1 == 32bit
791 lmc_ssi_set_crc_length (lmc_softc_t
* const sc
, int state
)
793 if (state
== LMC_CTL_CRC_LENGTH_32
)
796 sc
->lmc_miireg16
|= LMC_MII16_SSI_CRC
;
797 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
798 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_4
;
804 sc
->lmc_miireg16
&= ~LMC_MII16_SSI_CRC
;
805 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
806 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_2
;
809 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
813 * These are bits to program the ssi frequency generator
816 write_av9110_bit (lmc_softc_t
* sc
, int c
)
819 * set the data bit as we need it.
821 sc
->lmc_gpio
&= ~(LMC_GEP_CLK
);
823 sc
->lmc_gpio
|= LMC_GEP_DATA
;
825 sc
->lmc_gpio
&= ~(LMC_GEP_DATA
);
826 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
829 * set the clock to high
831 sc
->lmc_gpio
|= LMC_GEP_CLK
;
832 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
835 * set the clock to low again.
837 sc
->lmc_gpio
&= ~(LMC_GEP_CLK
);
838 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
842 write_av9110 (lmc_softc_t
* sc
, u_int32_t n
, u_int32_t m
, u_int32_t v
,
843 u_int32_t x
, u_int32_t r
)
848 printk (LMC_PRINTF_FMT
": speed %u, %d %d %d %d %d\n",
849 LMC_PRINTF_ARGS
, sc
->ictl
.clock_rate
, n
, m
, v
, x
, r
);
852 sc
->lmc_gpio
|= LMC_GEP_SSI_GENERATOR
;
853 sc
->lmc_gpio
&= ~(LMC_GEP_DATA
| LMC_GEP_CLK
);
854 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
857 * Set the TXCLOCK, GENERATOR, SERIAL, and SERIALCLK
860 lmc_gpio_mkoutput (sc
, (LMC_GEP_DATA
| LMC_GEP_CLK
861 | LMC_GEP_SSI_GENERATOR
));
863 sc
->lmc_gpio
&= ~(LMC_GEP_SSI_GENERATOR
);
864 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
867 * a shifting we will go...
869 for (i
= 0; i
< 7; i
++)
870 write_av9110_bit (sc
, n
>> i
);
871 for (i
= 0; i
< 7; i
++)
872 write_av9110_bit (sc
, m
>> i
);
873 for (i
= 0; i
< 1; i
++)
874 write_av9110_bit (sc
, v
>> i
);
875 for (i
= 0; i
< 2; i
++)
876 write_av9110_bit (sc
, x
>> i
);
877 for (i
= 0; i
< 2; i
++)
878 write_av9110_bit (sc
, r
>> i
);
879 for (i
= 0; i
< 5; i
++)
880 write_av9110_bit (sc
, 0x17 >> i
);
883 * stop driving serial-related signals
885 lmc_gpio_mkinput (sc
,
886 (LMC_GEP_DATA
| LMC_GEP_CLK
887 | LMC_GEP_SSI_GENERATOR
));
891 lmc_ssi_watchdog (lmc_softc_t
* const sc
)
893 u_int16_t mii17
= lmc_mii_readreg (sc
, 0, 17);
894 if (((mii17
>> 3) & 7) == 7)
896 lmc_led_off (sc
, LMC_MII16_LED2
);
900 lmc_led_on (sc
, LMC_MII16_LED2
);
910 * The framer regs are multiplexed through MII regs 17 & 18
911 * write the register address to MII reg 17 and the * data to MII reg 18. */
913 lmc_t1_write (lmc_softc_t
* const sc
, int a
, int d
)
915 lmc_mii_writereg (sc
, 0, 17, a
);
916 lmc_mii_writereg (sc
, 0, 18, d
);
921 lmc_t1_read (lmc_softc_t * const sc, int a)
923 lmc_mii_writereg (sc, 0, 17, a);
924 return lmc_mii_readreg (sc, 0, 18);
930 lmc_t1_init (lmc_softc_t
* const sc
)
935 sc
->ictl
.cardtype
= LMC_CTL_CARDTYPE_LMC1200
;
936 mii16
= lmc_mii_readreg (sc
, 0, 16);
939 mii16
&= ~LMC_MII16_T1_RST
;
940 lmc_mii_writereg (sc
, 0, 16, mii16
| LMC_MII16_T1_RST
);
941 lmc_mii_writereg (sc
, 0, 16, mii16
);
943 /* set T1 or E1 line. Uses sc->lmcmii16 reg in function so update it */
944 sc
->lmc_miireg16
= mii16
;
945 lmc_t1_set_circuit_type(sc
, LMC_CTL_CIRCUIT_TYPE_T1
);
946 mii16
= sc
->lmc_miireg16
;
948 lmc_t1_write (sc
, 0x01, 0x1B); /* CR0 - primary control */
949 lmc_t1_write (sc
, 0x02, 0x42); /* JAT_CR - jitter atten config */
950 lmc_t1_write (sc
, 0x14, 0x00); /* LOOP - loopback config */
951 lmc_t1_write (sc
, 0x15, 0x00); /* DL3_TS - external data link timeslot */
952 lmc_t1_write (sc
, 0x18, 0xFF); /* PIO - programmable I/O */
953 lmc_t1_write (sc
, 0x19, 0x30); /* POE - programmable OE */
954 lmc_t1_write (sc
, 0x1A, 0x0F); /* CMUX - clock input mux */
955 lmc_t1_write (sc
, 0x20, 0x41); /* LIU_CR - RX LIU config */
956 lmc_t1_write (sc
, 0x22, 0x76); /* RLIU_CR - RX LIU config */
957 lmc_t1_write (sc
, 0x40, 0x03); /* RCR0 - RX config */
958 lmc_t1_write (sc
, 0x45, 0x00); /* RALM - RX alarm config */
959 lmc_t1_write (sc
, 0x46, 0x05); /* LATCH - RX alarm/err/cntr latch */
960 lmc_t1_write (sc
, 0x68, 0x40); /* TLIU_CR - TX LIU config */
961 lmc_t1_write (sc
, 0x70, 0x0D); /* TCR0 - TX framer config */
962 lmc_t1_write (sc
, 0x71, 0x05); /* TCR1 - TX config */
963 lmc_t1_write (sc
, 0x72, 0x0B); /* TFRM - TX frame format */
964 lmc_t1_write (sc
, 0x73, 0x00); /* TERROR - TX error insert */
965 lmc_t1_write (sc
, 0x74, 0x00); /* TMAN - TX manual Sa/FEBE config */
966 lmc_t1_write (sc
, 0x75, 0x00); /* TALM - TX alarm signal config */
967 lmc_t1_write (sc
, 0x76, 0x00); /* TPATT - TX test pattern config */
968 lmc_t1_write (sc
, 0x77, 0x00); /* TLB - TX inband loopback config */
969 lmc_t1_write (sc
, 0x90, 0x05); /* CLAD_CR - clock rate adapter config */
970 lmc_t1_write (sc
, 0x91, 0x05); /* CSEL - clad freq sel */
971 lmc_t1_write (sc
, 0xA6, 0x00); /* DL1_CTL - DL1 control */
972 lmc_t1_write (sc
, 0xB1, 0x00); /* DL2_CTL - DL2 control */
973 lmc_t1_write (sc
, 0xD0, 0x47); /* SBI_CR - sys bus iface config */
974 lmc_t1_write (sc
, 0xD1, 0x70); /* RSB_CR - RX sys bus config */
975 lmc_t1_write (sc
, 0xD4, 0x30); /* TSB_CR - TX sys bus config */
976 for (i
= 0; i
< 32; i
++)
978 lmc_t1_write (sc
, 0x0E0 + i
, 0x00); /* SBCn - sys bus per-channel ctl */
979 lmc_t1_write (sc
, 0x100 + i
, 0x00); /* TPCn - TX per-channel ctl */
980 lmc_t1_write (sc
, 0x180 + i
, 0x00); /* RPCn - RX per-channel ctl */
982 for (i
= 1; i
< 25; i
++)
984 lmc_t1_write (sc
, 0x0E0 + i
, 0x0D); /* SBCn - sys bus per-channel ctl */
987 mii16
|= LMC_MII16_T1_XOE
;
988 lmc_mii_writereg (sc
, 0, 16, mii16
);
989 sc
->lmc_miireg16
= mii16
;
993 lmc_t1_default (lmc_softc_t
* const sc
)
995 sc
->lmc_miireg16
= LMC_MII16_LED_ALL
;
996 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_DOWN
);
997 sc
->lmc_media
->set_circuit_type (sc
, LMC_CTL_CIRCUIT_TYPE_T1
);
998 sc
->lmc_media
->set_crc_length (sc
, LMC_CTL_CRC_LENGTH_16
);
999 /* Right now we can only clock from out internal source */
1000 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
1002 /* * Given a user provided state, set ourselves up to match it. This will * always reset the card if needed.
1005 lmc_t1_set_status (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
1009 sc
->lmc_media
->set_circuit_type (sc
, sc
->ictl
.circuit_type
);
1010 lmc_set_protocol (sc
, NULL
);
1015 * check for change in circuit type */
1016 if (ctl
->circuit_type
== LMC_CTL_CIRCUIT_TYPE_T1
1017 && sc
->ictl
.circuit_type
==
1018 LMC_CTL_CIRCUIT_TYPE_E1
) sc
->lmc_media
->set_circuit_type (sc
,
1019 LMC_CTL_CIRCUIT_TYPE_E1
);
1020 else if (ctl
->circuit_type
== LMC_CTL_CIRCUIT_TYPE_E1
1021 && sc
->ictl
.circuit_type
== LMC_CTL_CIRCUIT_TYPE_T1
)
1022 sc
->lmc_media
->set_circuit_type (sc
, LMC_CTL_CIRCUIT_TYPE_T1
);
1023 lmc_set_protocol (sc
, ctl
);
1026 * return hardware link status.
1027 * 0 == link is down, 1 == link is up.
1029 lmc_t1_get_link_status (lmc_softc_t
* const sc
)
1031 u_int16_t link_status
;
1034 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
1035 * led0 yellow = far-end adapter is in Red alarm condition
1036 * led1 blue = received an Alarm Indication signal
1037 * (upstream failure)
1038 * led2 Green = power to adapter, Gate Array loaded & driver
1040 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
1041 * conditions detected on T3 receive signal
1043 lmc_trace(sc
->lmc_device
, "lmc_t1_get_link_status in");
1044 lmc_led_on(sc
, LMC_DS3_LED2
);
1046 lmc_mii_writereg (sc
, 0, 17, T1FRAMER_ALARM1_STATUS
);
1047 link_status
= lmc_mii_readreg (sc
, 0, 18);
1050 if (link_status
& T1F_RAIS
) { /* turn on blue LED */
1052 if(sc
->last_led_err
[1] != 1){
1053 printk(KERN_WARNING
"%s: Receive AIS/Blue Alarm. Far end in RED alarm\n", sc
->name
);
1055 lmc_led_on(sc
, LMC_DS3_LED1
);
1056 sc
->last_led_err
[1] = 1;
1059 if(sc
->last_led_err
[1] != 0){
1060 printk(KERN_WARNING
"%s: End AIS/Blue Alarm\n", sc
->name
);
1062 lmc_led_off (sc
, LMC_DS3_LED1
);
1063 sc
->last_led_err
[1] = 0;
1067 * Yellow Alarm is nasty evil stuff, looks at data patterns
1068 * inside the channel and confuses it with HDLC framing
1069 * ignore all yellow alarms.
1071 * Do listen to MultiFrame Yellow alarm which while implemented
1072 * different ways isn't in the channel and hence somewhat
1076 if (link_status
& T1F_RMYEL
) {
1078 if(sc
->last_led_err
[0] != 1){
1079 printk(KERN_WARNING
"%s: Receive Yellow AIS Alarm\n", sc
->name
);
1081 lmc_led_on(sc
, LMC_DS3_LED0
);
1082 sc
->last_led_err
[0] = 1;
1085 if(sc
->last_led_err
[0] != 0){
1086 printk(KERN_WARNING
"%s: End of Yellow AIS Alarm\n", sc
->name
);
1088 lmc_led_off(sc
, LMC_DS3_LED0
);
1089 sc
->last_led_err
[0] = 0;
1093 * Loss of signal and los of frame
1094 * Use the green bit to identify which one lit the led
1096 if(link_status
& T1F_RLOF
){
1098 if(sc
->last_led_err
[3] != 1){
1099 printk(KERN_WARNING
"%s: Local Red Alarm: Loss of Framing\n", sc
->name
);
1101 lmc_led_on(sc
, LMC_DS3_LED3
);
1102 sc
->last_led_err
[3] = 1;
1106 if(sc
->last_led_err
[3] != 0){
1107 printk(KERN_WARNING
"%s: End Red Alarm (LOF)\n", sc
->name
);
1109 if( ! (link_status
& T1F_RLOS
))
1110 lmc_led_off(sc
, LMC_DS3_LED3
);
1111 sc
->last_led_err
[3] = 0;
1114 if(link_status
& T1F_RLOS
){
1116 if(sc
->last_led_err
[2] != 1){
1117 printk(KERN_WARNING
"%s: Local Red Alarm: Loss of Signal\n", sc
->name
);
1119 lmc_led_on(sc
, LMC_DS3_LED3
);
1120 sc
->last_led_err
[2] = 1;
1124 if(sc
->last_led_err
[2] != 0){
1125 printk(KERN_WARNING
"%s: End Red Alarm (LOS)\n", sc
->name
);
1127 if( ! (link_status
& T1F_RLOF
))
1128 lmc_led_off(sc
, LMC_DS3_LED3
);
1129 sc
->last_led_err
[2] = 0;
1132 sc
->lmc_xinfo
.t1_alarm1_status
= link_status
;
1134 lmc_mii_writereg (sc
, 0, 17, T1FRAMER_ALARM2_STATUS
);
1135 sc
->lmc_xinfo
.t1_alarm2_status
= lmc_mii_readreg (sc
, 0, 18);
1138 lmc_trace(sc
->lmc_device
, "lmc_t1_get_link_status out");
1144 * 1 == T1 Circuit Type , 0 == E1 Circuit Type
1147 lmc_t1_set_circuit_type (lmc_softc_t
* const sc
, int ie
)
1149 if (ie
== LMC_CTL_CIRCUIT_TYPE_T1
) {
1150 sc
->lmc_miireg16
|= LMC_MII16_T1_Z
;
1151 sc
->ictl
.circuit_type
= LMC_CTL_CIRCUIT_TYPE_T1
;
1152 printk(KERN_INFO
"%s: In T1 Mode\n", sc
->name
);
1155 sc
->lmc_miireg16
&= ~LMC_MII16_T1_Z
;
1156 sc
->ictl
.circuit_type
= LMC_CTL_CIRCUIT_TYPE_E1
;
1157 printk(KERN_INFO
"%s: In E1 Mode\n", sc
->name
);
1160 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
1165 * 0 == 16bit, 1 == 32bit */
1167 lmc_t1_set_crc_length (lmc_softc_t
* const sc
, int state
)
1169 if (state
== LMC_CTL_CRC_LENGTH_32
)
1172 sc
->lmc_miireg16
|= LMC_MII16_T1_CRC
;
1173 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_32
;
1174 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_4
;
1179 /* 16 bit */ sc
->lmc_miireg16
&= ~LMC_MII16_T1_CRC
;
1180 sc
->ictl
.crc_length
= LMC_CTL_CRC_LENGTH_16
;
1181 sc
->lmc_crcSize
= LMC_CTL_CRC_BYTESIZE_2
;
1185 lmc_mii_writereg (sc
, 0, 16, sc
->lmc_miireg16
);
1189 * 1 == internal, 0 == external
1192 lmc_t1_set_clock (lmc_softc_t
* const sc
, int ie
)
1196 if (ie
== LMC_CTL_CLOCK_SOURCE_EXT
)
1198 sc
->lmc_gpio
&= ~(LMC_GEP_SSI_TXCLOCK
);
1199 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
1200 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_EXT
;
1202 printk (LMC_PRINTF_FMT
": clock external\n", LMC_PRINTF_ARGS
);
1206 sc
->lmc_gpio
|= LMC_GEP_SSI_TXCLOCK
;
1207 LMC_CSR_WRITE (sc
, csr_gp
, sc
->lmc_gpio
);
1208 sc
->ictl
.clock_source
= LMC_CTL_CLOCK_SOURCE_INT
;
1210 printk (LMC_PRINTF_FMT
": clock internal\n", LMC_PRINTF_ARGS
);
1215 lmc_t1_watchdog (lmc_softc_t
* const sc
)
1220 lmc_set_protocol (lmc_softc_t
* const sc
, lmc_ctl_t
* ctl
)
1223 sc
->ictl
.keepalive_onoff
= LMC_CTL_ON
;