1 /* $Id: lmc_media.c,v 1.13 2000/04/11 05:25:26 asj Exp $ */
3 #include <linux/config.h>
4 #include <linux/kernel.h>
5 #include <linux/string.h>
6 #include <linux/timer.h>
7 #include <linux/ptrace.h>
8 #include <linux/errno.h>
9 #include <linux/ioport.h>
10 #include <linux/slab.h>
11 #include <linux/interrupt.h>
12 #include <linux/pci.h>
14 #include <linux/if_arp.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/skbuff.h>
18 #include <linux/inet.h>
19 #include <linux/bitops.h>
21 #include <net/syncppp.h>
23 #include <asm/processor.h> /* Processor type for cache alignment. */
27 #include <asm/uaccess.h>
31 #include "lmc_ioctl.h"
32 #include "lmc_debug.h"
34 #define CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE 1
37 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
38 * All rights reserved. www.lanmedia.com
40 * This code is written by:
41 * Andrew Stanley-Jones (asj@cban.com)
42 * Rob Braun (bbraun@vix.com),
43 * Michael Graff (explorer@vix.com) and
44 * Matt Thomas (matt@3am-software.com).
46 * This software may be used and distributed according to the terms
47 * of the GNU General Public License version 2, incorporated herein by reference.
51 * protocol independent method.
53 static void lmc_set_protocol (lmc_softc_t * const, lmc_ctl_t *);
56 * media independent methods to check on media status, link, light LEDs,
59 static void lmc_ds3_init (lmc_softc_t * const);
60 static void lmc_ds3_default (lmc_softc_t * const);
61 static void lmc_ds3_set_status (lmc_softc_t * const, lmc_ctl_t *);
62 static void lmc_ds3_set_100ft (lmc_softc_t * const, int);
63 static int lmc_ds3_get_link_status (lmc_softc_t * const);
64 static void lmc_ds3_set_crc_length (lmc_softc_t * const, int);
65 static void lmc_ds3_set_scram (lmc_softc_t * const, int);
66 static void lmc_ds3_watchdog (lmc_softc_t * const);
68 static void lmc_hssi_init (lmc_softc_t * const);
69 static void lmc_hssi_default (lmc_softc_t * const);
70 static void lmc_hssi_set_status (lmc_softc_t * const, lmc_ctl_t *);
71 static void lmc_hssi_set_clock (lmc_softc_t * const, int);
72 static int lmc_hssi_get_link_status (lmc_softc_t * const);
73 static void lmc_hssi_set_link_status (lmc_softc_t * const, int);
74 static void lmc_hssi_set_crc_length (lmc_softc_t * const, int);
75 static void lmc_hssi_watchdog (lmc_softc_t * const);
77 static void lmc_ssi_init (lmc_softc_t * const);
78 static void lmc_ssi_default (lmc_softc_t * const);
79 static void lmc_ssi_set_status (lmc_softc_t * const, lmc_ctl_t *);
80 static void lmc_ssi_set_clock (lmc_softc_t * const, int);
81 static void lmc_ssi_set_speed (lmc_softc_t * const, lmc_ctl_t *);
82 static int lmc_ssi_get_link_status (lmc_softc_t * const);
83 static void lmc_ssi_set_link_status (lmc_softc_t * const, int);
84 static void lmc_ssi_set_crc_length (lmc_softc_t * const, int);
85 static void lmc_ssi_watchdog (lmc_softc_t * const);
87 static void lmc_t1_init (lmc_softc_t * const);
88 static void lmc_t1_default (lmc_softc_t * const);
89 static void lmc_t1_set_status (lmc_softc_t * const, lmc_ctl_t *);
90 static int lmc_t1_get_link_status (lmc_softc_t * const);
91 static void lmc_t1_set_circuit_type (lmc_softc_t * const, int);
92 static void lmc_t1_set_crc_length (lmc_softc_t * const, int);
93 static void lmc_t1_set_clock (lmc_softc_t * const, int);
94 static void lmc_t1_watchdog (lmc_softc_t * const);
96 static void lmc_dummy_set_1 (lmc_softc_t * const, int);
97 static void lmc_dummy_set2_1 (lmc_softc_t * const, lmc_ctl_t *);
99 static inline void write_av9110_bit (lmc_softc_t *, int);
100 static void write_av9110 (lmc_softc_t *, u_int32_t, u_int32_t, u_int32_t,
101 u_int32_t, u_int32_t);
103 lmc_media_t lmc_ds3_media = {
104 lmc_ds3_init, /* special media init stuff */
105 lmc_ds3_default, /* reset to default state */
106 lmc_ds3_set_status, /* reset status to state provided */
107 lmc_dummy_set_1, /* set clock source */
108 lmc_dummy_set2_1, /* set line speed */
109 lmc_ds3_set_100ft, /* set cable length */
110 lmc_ds3_set_scram, /* set scrambler */
111 lmc_ds3_get_link_status, /* get link status */
112 lmc_dummy_set_1, /* set link status */
113 lmc_ds3_set_crc_length, /* set CRC length */
114 lmc_dummy_set_1, /* set T1 or E1 circuit type */
118 lmc_media_t lmc_hssi_media = {
119 lmc_hssi_init, /* special media init stuff */
120 lmc_hssi_default, /* reset to default state */
121 lmc_hssi_set_status, /* reset status to state provided */
122 lmc_hssi_set_clock, /* set clock source */
123 lmc_dummy_set2_1, /* set line speed */
124 lmc_dummy_set_1, /* set cable length */
125 lmc_dummy_set_1, /* set scrambler */
126 lmc_hssi_get_link_status, /* get link status */
127 lmc_hssi_set_link_status, /* set link status */
128 lmc_hssi_set_crc_length, /* set CRC length */
129 lmc_dummy_set_1, /* set T1 or E1 circuit type */
133 lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
134 lmc_ssi_default, /* reset to default state */
135 lmc_ssi_set_status, /* reset status to state provided */
136 lmc_ssi_set_clock, /* set clock source */
137 lmc_ssi_set_speed, /* set line speed */
138 lmc_dummy_set_1, /* set cable length */
139 lmc_dummy_set_1, /* set scrambler */
140 lmc_ssi_get_link_status, /* get link status */
141 lmc_ssi_set_link_status, /* set link status */
142 lmc_ssi_set_crc_length, /* set CRC length */
143 lmc_dummy_set_1, /* set T1 or E1 circuit type */
147 lmc_media_t lmc_t1_media = {
148 lmc_t1_init, /* special media init stuff */
149 lmc_t1_default, /* reset to default state */
150 lmc_t1_set_status, /* reset status to state provided */
151 lmc_t1_set_clock, /* set clock source */
152 lmc_dummy_set2_1, /* set line speed */
153 lmc_dummy_set_1, /* set cable length */
154 lmc_dummy_set_1, /* set scrambler */
155 lmc_t1_get_link_status, /* get link status */
156 lmc_dummy_set_1, /* set link status */
157 lmc_t1_set_crc_length, /* set CRC length */
158 lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
163 lmc_dummy_set_1 (lmc_softc_t * const sc, int a)
168 lmc_dummy_set2_1 (lmc_softc_t * const sc, lmc_ctl_t * a)
177 lmc_hssi_init (lmc_softc_t * const sc)
179 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC5200;
181 lmc_gpio_mkoutput (sc, LMC_GEP_HSSI_CLOCK);
185 lmc_hssi_default (lmc_softc_t * const sc)
187 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
189 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
190 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
191 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
195 * Given a user provided state, set ourselves up to match it. This will
196 * always reset the card if needed.
199 lmc_hssi_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
203 sc->lmc_media->set_clock_source (sc, sc->ictl.clock_source);
204 lmc_set_protocol (sc, NULL);
210 * check for change in clock source
212 if (ctl->clock_source && !sc->ictl.clock_source)
214 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_INT);
215 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_INT;
217 else if (!ctl->clock_source && sc->ictl.clock_source)
219 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
220 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
223 lmc_set_protocol (sc, ctl);
227 * 1 == internal, 0 == external
230 lmc_hssi_set_clock (lmc_softc_t * const sc, int ie)
233 old = sc->ictl.clock_source;
234 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
236 sc->lmc_gpio |= LMC_GEP_HSSI_CLOCK;
237 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
238 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
240 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
244 sc->lmc_gpio &= ~(LMC_GEP_HSSI_CLOCK);
245 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
246 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
248 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
253 * return hardware link status.
254 * 0 == link is down, 1 == link is up.
257 lmc_hssi_get_link_status (lmc_softc_t * const sc)
260 * We're using the same code as SSI since
261 * they're practically the same
263 return lmc_ssi_get_link_status(sc);
267 lmc_hssi_set_link_status (lmc_softc_t * const sc, int state)
269 if (state == LMC_LINK_UP)
270 sc->lmc_miireg16 |= LMC_MII16_HSSI_TA;
272 sc->lmc_miireg16 &= ~LMC_MII16_HSSI_TA;
274 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
278 * 0 == 16bit, 1 == 32bit
281 lmc_hssi_set_crc_length (lmc_softc_t * const sc, int state)
283 if (state == LMC_CTL_CRC_LENGTH_32)
286 sc->lmc_miireg16 |= LMC_MII16_HSSI_CRC;
287 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
292 sc->lmc_miireg16 &= ~LMC_MII16_HSSI_CRC;
293 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
296 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
300 lmc_hssi_watchdog (lmc_softc_t * const sc)
313 lmc_ds3_set_100ft (lmc_softc_t * const sc, int ie)
315 if (ie == LMC_CTL_CABLE_LENGTH_GT_100FT)
317 sc->lmc_miireg16 &= ~LMC_MII16_DS3_ZERO;
318 sc->ictl.cable_length = LMC_CTL_CABLE_LENGTH_GT_100FT;
320 else if (ie == LMC_CTL_CABLE_LENGTH_LT_100FT)
322 sc->lmc_miireg16 |= LMC_MII16_DS3_ZERO;
323 sc->ictl.cable_length = LMC_CTL_CABLE_LENGTH_LT_100FT;
325 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
329 lmc_ds3_default (lmc_softc_t * const sc)
331 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
333 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
334 sc->lmc_media->set_cable_length (sc, LMC_CTL_CABLE_LENGTH_LT_100FT);
335 sc->lmc_media->set_scrambler (sc, LMC_CTL_OFF);
336 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
340 * Given a user provided state, set ourselves up to match it. This will
341 * always reset the card if needed.
344 lmc_ds3_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
348 sc->lmc_media->set_cable_length (sc, sc->ictl.cable_length);
349 sc->lmc_media->set_scrambler (sc, sc->ictl.scrambler_onoff);
350 lmc_set_protocol (sc, NULL);
356 * check for change in cable length setting
358 if (ctl->cable_length && !sc->ictl.cable_length)
359 lmc_ds3_set_100ft (sc, LMC_CTL_CABLE_LENGTH_GT_100FT);
360 else if (!ctl->cable_length && sc->ictl.cable_length)
361 lmc_ds3_set_100ft (sc, LMC_CTL_CABLE_LENGTH_LT_100FT);
364 * Check for change in scrambler setting (requires reset)
366 if (ctl->scrambler_onoff && !sc->ictl.scrambler_onoff)
367 lmc_ds3_set_scram (sc, LMC_CTL_ON);
368 else if (!ctl->scrambler_onoff && sc->ictl.scrambler_onoff)
369 lmc_ds3_set_scram (sc, LMC_CTL_OFF);
371 lmc_set_protocol (sc, ctl);
375 lmc_ds3_init (lmc_softc_t * const sc)
379 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC5245;
381 /* writes zeros everywhere */
382 for (i = 0; i < 21; i++)
384 lmc_mii_writereg (sc, 0, 17, i);
385 lmc_mii_writereg (sc, 0, 18, 0);
388 /* set some essential bits */
389 lmc_mii_writereg (sc, 0, 17, 1);
390 lmc_mii_writereg (sc, 0, 18, 0x25); /* ser, xtx */
392 lmc_mii_writereg (sc, 0, 17, 5);
393 lmc_mii_writereg (sc, 0, 18, 0x80); /* emode */
395 lmc_mii_writereg (sc, 0, 17, 14);
396 lmc_mii_writereg (sc, 0, 18, 0x30); /* rcgen, tcgen */
398 /* clear counters and latched bits */
399 for (i = 0; i < 21; i++)
401 lmc_mii_writereg (sc, 0, 17, i);
402 lmc_mii_readreg (sc, 0, 18);
407 * 1 == DS3 payload scrambled, 0 == not scrambled
410 lmc_ds3_set_scram (lmc_softc_t * const sc, int ie)
412 if (ie == LMC_CTL_ON)
414 sc->lmc_miireg16 |= LMC_MII16_DS3_SCRAM;
415 sc->ictl.scrambler_onoff = LMC_CTL_ON;
419 sc->lmc_miireg16 &= ~LMC_MII16_DS3_SCRAM;
420 sc->ictl.scrambler_onoff = LMC_CTL_OFF;
422 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
426 * return hardware link status.
427 * 0 == link is down, 1 == link is up.
430 lmc_ds3_get_link_status (lmc_softc_t * const sc)
432 u_int16_t link_status, link_status_11;
435 lmc_mii_writereg (sc, 0, 17, 7);
436 link_status = lmc_mii_readreg (sc, 0, 18);
438 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
439 * led0 yellow = far-end adapter is in Red alarm condition
440 * led1 blue = received an Alarm Indication signal
442 * led2 Green = power to adapter, Gate Array loaded & driver
444 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
445 * conditions detected on T3 receive signal
448 lmc_led_on(sc, LMC_DS3_LED2);
450 if ((link_status & LMC_FRAMER_REG0_DLOS) ||
451 (link_status & LMC_FRAMER_REG0_OOFS)){
453 if(sc->last_led_err[3] != 1){
455 lmc_mii_writereg (sc, 0, 17, 01); /* Turn on Xbit error as our cisco does */
456 r1 = lmc_mii_readreg (sc, 0, 18);
458 lmc_mii_writereg(sc, 0, 18, r1);
459 printk(KERN_WARNING "%s: Red Alarm - Loss of Signal or Loss of Framing\n", sc->name);
461 lmc_led_on(sc, LMC_DS3_LED3); /* turn on red LED */
462 sc->last_led_err[3] = 1;
465 lmc_led_off(sc, LMC_DS3_LED3); /* turn on red LED */
466 if(sc->last_led_err[3] == 1){
468 lmc_mii_writereg (sc, 0, 17, 01); /* Turn off Xbit error */
469 r1 = lmc_mii_readreg (sc, 0, 18);
471 lmc_mii_writereg(sc, 0, 18, r1);
473 sc->last_led_err[3] = 0;
476 lmc_mii_writereg(sc, 0, 17, 0x10);
477 link_status_11 = lmc_mii_readreg(sc, 0, 18);
478 if((link_status & LMC_FRAMER_REG0_AIS) ||
479 (link_status_11 & LMC_FRAMER_REG10_XBIT)) {
481 if(sc->last_led_err[0] != 1){
482 printk(KERN_WARNING "%s: AIS Alarm or XBit Error\n", sc->name);
483 printk(KERN_WARNING "%s: Remote end has loss of signal or framing\n", sc->name);
485 lmc_led_on(sc, LMC_DS3_LED0);
486 sc->last_led_err[0] = 1;
489 lmc_led_off(sc, LMC_DS3_LED0);
490 sc->last_led_err[0] = 0;
493 lmc_mii_writereg (sc, 0, 17, 9);
494 link_status = lmc_mii_readreg (sc, 0, 18);
496 if(link_status & LMC_FRAMER_REG9_RBLUE){
498 if(sc->last_led_err[1] != 1){
499 printk(KERN_WARNING "%s: Blue Alarm - Receiving all 1's\n", sc->name);
501 lmc_led_on(sc, LMC_DS3_LED1);
502 sc->last_led_err[1] = 1;
505 lmc_led_off(sc, LMC_DS3_LED1);
506 sc->last_led_err[1] = 0;
513 * 0 == 16bit, 1 == 32bit
516 lmc_ds3_set_crc_length (lmc_softc_t * const sc, int state)
518 if (state == LMC_CTL_CRC_LENGTH_32)
521 sc->lmc_miireg16 |= LMC_MII16_DS3_CRC;
522 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
527 sc->lmc_miireg16 &= ~LMC_MII16_DS3_CRC;
528 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
531 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
535 lmc_ds3_watchdog (lmc_softc_t * const sc)
546 lmc_ssi_init (lmc_softc_t * const sc)
551 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1000;
553 mii17 = lmc_mii_readreg (sc, 0, 17);
555 cable = (mii17 & LMC_MII17_SSI_CABLE_MASK) >> LMC_MII17_SSI_CABLE_SHIFT;
556 sc->ictl.cable_type = cable;
558 lmc_gpio_mkoutput (sc, LMC_GEP_SSI_TXCLOCK);
562 lmc_ssi_default (lmc_softc_t * const sc)
564 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
567 * make TXCLOCK always be an output
569 lmc_gpio_mkoutput (sc, LMC_GEP_SSI_TXCLOCK);
571 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
572 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
573 sc->lmc_media->set_speed (sc, NULL);
574 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
578 * Given a user provided state, set ourselves up to match it. This will
579 * always reset the card if needed.
582 lmc_ssi_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
586 sc->lmc_media->set_clock_source (sc, sc->ictl.clock_source);
587 sc->lmc_media->set_speed (sc, &sc->ictl);
588 lmc_set_protocol (sc, NULL);
594 * check for change in clock source
596 if (ctl->clock_source == LMC_CTL_CLOCK_SOURCE_INT
597 && sc->ictl.clock_source == LMC_CTL_CLOCK_SOURCE_EXT)
599 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_INT);
600 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_INT;
602 else if (ctl->clock_source == LMC_CTL_CLOCK_SOURCE_EXT
603 && sc->ictl.clock_source == LMC_CTL_CLOCK_SOURCE_INT)
605 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
606 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
609 if (ctl->clock_rate != sc->ictl.clock_rate)
610 sc->lmc_media->set_speed (sc, ctl);
612 lmc_set_protocol (sc, ctl);
616 * 1 == internal, 0 == external
619 lmc_ssi_set_clock (lmc_softc_t * const sc, int ie)
623 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
625 sc->lmc_gpio &= ~(LMC_GEP_SSI_TXCLOCK);
626 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
627 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
629 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
633 sc->lmc_gpio |= LMC_GEP_SSI_TXCLOCK;
634 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
635 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
637 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
642 lmc_ssi_set_speed (lmc_softc_t * const sc, lmc_ctl_t * ctl)
644 lmc_ctl_t *ictl = &sc->ictl;
647 /* original settings for clock rate of:
648 * 100 Khz (8,25,0,0,2) were incorrect
649 * they should have been 80,125,1,3,3
650 * There are 17 param combinations to produce this freq.
651 * For 1.5 Mhz use 120,100,1,1,2 (226 param. combinations)
655 av = &ictl->cardspec.ssi;
656 ictl->clock_rate = 1500000;
657 av->f = ictl->clock_rate;
664 write_av9110 (sc, av->n, av->m, av->v, av->x, av->r);
668 av = &ctl->cardspec.ssi;
673 ictl->clock_rate = av->f; /* really, this is the rate we are */
674 ictl->cardspec.ssi = *av;
676 write_av9110 (sc, av->n, av->m, av->v, av->x, av->r);
680 * return hardware link status.
681 * 0 == link is down, 1 == link is up.
684 lmc_ssi_get_link_status (lmc_softc_t * const sc)
686 u_int16_t link_status;
692 * missing CTS? Hmm. If we require CTS on, we may never get the
693 * link to come up, so omit it in this test.
695 * Also, it seems that with a loopback cable, DCD isn't asserted,
696 * so just check for things like this:
697 * DSR _must_ be asserted.
698 * One of DCD or CTS must be asserted.
701 /* LMC 1000 (SSI) LED definitions
702 * led0 Green = power to adapter, Gate Array loaded &
704 * led1 Green = DSR and DTR and RTS and CTS are set
705 * led2 Green = Cable detected
706 * led3 red = No timing is available from the
707 * cable or the on-board frequency
711 link_status = lmc_mii_readreg (sc, 0, 16);
713 /* Is the transmit clock still available */
714 ticks = LMC_CSR_READ (sc, csr_gp_timer);
715 ticks = 0x0000ffff - (ticks & 0x0000ffff);
717 lmc_led_on (sc, LMC_MII16_LED0);
719 /* ====== transmit clock determination ===== */
720 if (sc->lmc_timing == LMC_CTL_CLOCK_SOURCE_INT) {
721 lmc_led_off(sc, LMC_MII16_LED3);
723 else if (ticks == 0 ) { /* no clock found ? */
725 if(sc->last_led_err[3] != 1){
726 sc->stats.tx_lossOfClockCnt++;
727 printk(KERN_WARNING "%s: Lost Clock, Link Down\n", sc->name);
729 sc->last_led_err[3] = 1;
730 lmc_led_on (sc, LMC_MII16_LED3); /* turn ON red LED */
733 if(sc->last_led_err[3] == 1)
734 printk(KERN_WARNING "%s: Clock Returned\n", sc->name);
735 sc->last_led_err[3] = 0;
736 lmc_led_off (sc, LMC_MII16_LED3); /* turn OFF red LED */
739 if ((link_status & LMC_MII16_SSI_DSR) == 0) { /* Also HSSI CA */
744 #ifdef CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE
745 if ((link_status & (LMC_MII16_SSI_CTS | LMC_MII16_SSI_DCD)) == 0){
752 if(sc->last_led_err[1] != 1)
753 printk(KERN_WARNING "%s: DSR not asserted\n", sc->name);
754 sc->last_led_err[1] = 1;
755 lmc_led_off(sc, LMC_MII16_LED1);
758 if(sc->last_led_err[1] != 0)
759 printk(KERN_WARNING "%s: DSR now asserted\n", sc->name);
760 sc->last_led_err[1] = 0;
761 lmc_led_on(sc, LMC_MII16_LED1);
765 lmc_led_on(sc, LMC_MII16_LED2); /* Over all good status? */
772 lmc_ssi_set_link_status (lmc_softc_t * const sc, int state)
774 if (state == LMC_LINK_UP)
776 sc->lmc_miireg16 |= (LMC_MII16_SSI_DTR | LMC_MII16_SSI_RTS);
777 printk (LMC_PRINTF_FMT ": asserting DTR and RTS\n", LMC_PRINTF_ARGS);
781 sc->lmc_miireg16 &= ~(LMC_MII16_SSI_DTR | LMC_MII16_SSI_RTS);
782 printk (LMC_PRINTF_FMT ": deasserting DTR and RTS\n", LMC_PRINTF_ARGS);
785 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
790 * 0 == 16bit, 1 == 32bit
793 lmc_ssi_set_crc_length (lmc_softc_t * const sc, int state)
795 if (state == LMC_CTL_CRC_LENGTH_32)
798 sc->lmc_miireg16 |= LMC_MII16_SSI_CRC;
799 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
800 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_4;
806 sc->lmc_miireg16 &= ~LMC_MII16_SSI_CRC;
807 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
808 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_2;
811 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
815 * These are bits to program the ssi frequency generator
818 write_av9110_bit (lmc_softc_t * sc, int c)
821 * set the data bit as we need it.
823 sc->lmc_gpio &= ~(LMC_GEP_CLK);
825 sc->lmc_gpio |= LMC_GEP_DATA;
827 sc->lmc_gpio &= ~(LMC_GEP_DATA);
828 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
831 * set the clock to high
833 sc->lmc_gpio |= LMC_GEP_CLK;
834 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
837 * set the clock to low again.
839 sc->lmc_gpio &= ~(LMC_GEP_CLK);
840 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
844 write_av9110 (lmc_softc_t * sc, u_int32_t n, u_int32_t m, u_int32_t v,
845 u_int32_t x, u_int32_t r)
850 printk (LMC_PRINTF_FMT ": speed %u, %d %d %d %d %d\n",
851 LMC_PRINTF_ARGS, sc->ictl.clock_rate, n, m, v, x, r);
854 sc->lmc_gpio |= LMC_GEP_SSI_GENERATOR;
855 sc->lmc_gpio &= ~(LMC_GEP_DATA | LMC_GEP_CLK);
856 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
859 * Set the TXCLOCK, GENERATOR, SERIAL, and SERIALCLK
862 lmc_gpio_mkoutput (sc, (LMC_GEP_DATA | LMC_GEP_CLK
863 | LMC_GEP_SSI_GENERATOR));
865 sc->lmc_gpio &= ~(LMC_GEP_SSI_GENERATOR);
866 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
869 * a shifting we will go...
871 for (i = 0; i < 7; i++)
872 write_av9110_bit (sc, n >> i);
873 for (i = 0; i < 7; i++)
874 write_av9110_bit (sc, m >> i);
875 for (i = 0; i < 1; i++)
876 write_av9110_bit (sc, v >> i);
877 for (i = 0; i < 2; i++)
878 write_av9110_bit (sc, x >> i);
879 for (i = 0; i < 2; i++)
880 write_av9110_bit (sc, r >> i);
881 for (i = 0; i < 5; i++)
882 write_av9110_bit (sc, 0x17 >> i);
885 * stop driving serial-related signals
887 lmc_gpio_mkinput (sc,
888 (LMC_GEP_DATA | LMC_GEP_CLK
889 | LMC_GEP_SSI_GENERATOR));
893 lmc_ssi_watchdog (lmc_softc_t * const sc)
898 unsigned short dtr:1, dsr:1, rts:1, cable:3, crc:1, led0:1, led1:1,
899 led2:1, led3:1, fifo:1, ll:1, rl:1, tm:1, loop:1;
901 struct ssicsr2 *ssicsr;
902 mii17 = lmc_mii_readreg (sc, 0, 17);
903 ssicsr = (struct ssicsr2 *) &mii17;
904 if (ssicsr->cable == 7)
906 lmc_led_off (sc, LMC_MII16_LED2);
910 lmc_led_on (sc, LMC_MII16_LED2);
920 * The framer regs are multiplexed through MII regs 17 & 18
921 * write the register address to MII reg 17 and the * data to MII reg 18. */
923 lmc_t1_write (lmc_softc_t * const sc, int a, int d)
925 lmc_mii_writereg (sc, 0, 17, a);
926 lmc_mii_writereg (sc, 0, 18, d);
931 lmc_t1_read (lmc_softc_t * const sc, int a)
933 lmc_mii_writereg (sc, 0, 17, a);
934 return lmc_mii_readreg (sc, 0, 18);
940 lmc_t1_init (lmc_softc_t * const sc)
945 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1200;
946 mii16 = lmc_mii_readreg (sc, 0, 16);
949 mii16 &= ~LMC_MII16_T1_RST;
950 lmc_mii_writereg (sc, 0, 16, mii16 | LMC_MII16_T1_RST);
951 lmc_mii_writereg (sc, 0, 16, mii16);
953 /* set T1 or E1 line. Uses sc->lmcmii16 reg in function so update it */
954 sc->lmc_miireg16 = mii16;
955 lmc_t1_set_circuit_type(sc, LMC_CTL_CIRCUIT_TYPE_T1);
956 mii16 = sc->lmc_miireg16;
958 lmc_t1_write (sc, 0x01, 0x1B); /* CR0 - primary control */
959 lmc_t1_write (sc, 0x02, 0x42); /* JAT_CR - jitter atten config */
960 lmc_t1_write (sc, 0x14, 0x00); /* LOOP - loopback config */
961 lmc_t1_write (sc, 0x15, 0x00); /* DL3_TS - external data link timeslot */
962 lmc_t1_write (sc, 0x18, 0xFF); /* PIO - programmable I/O */
963 lmc_t1_write (sc, 0x19, 0x30); /* POE - programmable OE */
964 lmc_t1_write (sc, 0x1A, 0x0F); /* CMUX - clock input mux */
965 lmc_t1_write (sc, 0x20, 0x41); /* LIU_CR - RX LIU config */
966 lmc_t1_write (sc, 0x22, 0x76); /* RLIU_CR - RX LIU config */
967 lmc_t1_write (sc, 0x40, 0x03); /* RCR0 - RX config */
968 lmc_t1_write (sc, 0x45, 0x00); /* RALM - RX alarm config */
969 lmc_t1_write (sc, 0x46, 0x05); /* LATCH - RX alarm/err/cntr latch */
970 lmc_t1_write (sc, 0x68, 0x40); /* TLIU_CR - TX LIU config */
971 lmc_t1_write (sc, 0x70, 0x0D); /* TCR0 - TX framer config */
972 lmc_t1_write (sc, 0x71, 0x05); /* TCR1 - TX config */
973 lmc_t1_write (sc, 0x72, 0x0B); /* TFRM - TX frame format */
974 lmc_t1_write (sc, 0x73, 0x00); /* TERROR - TX error insert */
975 lmc_t1_write (sc, 0x74, 0x00); /* TMAN - TX manual Sa/FEBE config */
976 lmc_t1_write (sc, 0x75, 0x00); /* TALM - TX alarm signal config */
977 lmc_t1_write (sc, 0x76, 0x00); /* TPATT - TX test pattern config */
978 lmc_t1_write (sc, 0x77, 0x00); /* TLB - TX inband loopback config */
979 lmc_t1_write (sc, 0x90, 0x05); /* CLAD_CR - clock rate adapter config */
980 lmc_t1_write (sc, 0x91, 0x05); /* CSEL - clad freq sel */
981 lmc_t1_write (sc, 0xA6, 0x00); /* DL1_CTL - DL1 control */
982 lmc_t1_write (sc, 0xB1, 0x00); /* DL2_CTL - DL2 control */
983 lmc_t1_write (sc, 0xD0, 0x47); /* SBI_CR - sys bus iface config */
984 lmc_t1_write (sc, 0xD1, 0x70); /* RSB_CR - RX sys bus config */
985 lmc_t1_write (sc, 0xD4, 0x30); /* TSB_CR - TX sys bus config */
986 for (i = 0; i < 32; i++)
988 lmc_t1_write (sc, 0x0E0 + i, 0x00); /* SBCn - sys bus per-channel ctl */
989 lmc_t1_write (sc, 0x100 + i, 0x00); /* TPCn - TX per-channel ctl */
990 lmc_t1_write (sc, 0x180 + i, 0x00); /* RPCn - RX per-channel ctl */
992 for (i = 1; i < 25; i++)
994 lmc_t1_write (sc, 0x0E0 + i, 0x0D); /* SBCn - sys bus per-channel ctl */
997 mii16 |= LMC_MII16_T1_XOE;
998 lmc_mii_writereg (sc, 0, 16, mii16);
999 sc->lmc_miireg16 = mii16;
1003 lmc_t1_default (lmc_softc_t * const sc)
1005 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
1006 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
1007 sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1);
1008 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
1009 /* Right now we can only clock from out internal source */
1010 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
1012 /* * Given a user provided state, set ourselves up to match it. This will * always reset the card if needed.
1015 lmc_t1_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
1019 sc->lmc_media->set_circuit_type (sc, sc->ictl.circuit_type);
1020 lmc_set_protocol (sc, NULL);
1025 * check for change in circuit type */
1026 if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_T1
1027 && sc->ictl.circuit_type ==
1028 LMC_CTL_CIRCUIT_TYPE_E1) sc->lmc_media->set_circuit_type (sc,
1029 LMC_CTL_CIRCUIT_TYPE_E1);
1030 else if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_E1
1031 && sc->ictl.circuit_type == LMC_CTL_CIRCUIT_TYPE_T1)
1032 sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1);
1033 lmc_set_protocol (sc, ctl);
1036 * return hardware link status.
1037 * 0 == link is down, 1 == link is up.
1039 lmc_t1_get_link_status (lmc_softc_t * const sc)
1041 u_int16_t link_status;
1044 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
1045 * led0 yellow = far-end adapter is in Red alarm condition
1046 * led1 blue = received an Alarm Indication signal
1047 * (upstream failure)
1048 * led2 Green = power to adapter, Gate Array loaded & driver
1050 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
1051 * conditions detected on T3 receive signal
1053 lmc_trace(sc->lmc_device, "lmc_t1_get_link_status in");
1054 lmc_led_on(sc, LMC_DS3_LED2);
1056 lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM1_STATUS);
1057 link_status = lmc_mii_readreg (sc, 0, 18);
1060 if (link_status & T1F_RAIS) { /* turn on blue LED */
1062 if(sc->last_led_err[1] != 1){
1063 printk(KERN_WARNING "%s: Receive AIS/Blue Alarm. Far end in RED alarm\n", sc->name);
1065 lmc_led_on(sc, LMC_DS3_LED1);
1066 sc->last_led_err[1] = 1;
1069 if(sc->last_led_err[1] != 0){
1070 printk(KERN_WARNING "%s: End AIS/Blue Alarm\n", sc->name);
1072 lmc_led_off (sc, LMC_DS3_LED1);
1073 sc->last_led_err[1] = 0;
1077 * Yellow Alarm is nasty evil stuff, looks at data patterns
1078 * inside the channel and confuses it with HDLC framing
1079 * ignore all yellow alarms.
1081 * Do listen to MultiFrame Yellow alarm which while implemented
1082 * different ways isn't in the channel and hence somewhat
1086 if (link_status & T1F_RMYEL) {
1088 if(sc->last_led_err[0] != 1){
1089 printk(KERN_WARNING "%s: Receive Yellow AIS Alarm\n", sc->name);
1091 lmc_led_on(sc, LMC_DS3_LED0);
1092 sc->last_led_err[0] = 1;
1095 if(sc->last_led_err[0] != 0){
1096 printk(KERN_WARNING "%s: End of Yellow AIS Alarm\n", sc->name);
1098 lmc_led_off(sc, LMC_DS3_LED0);
1099 sc->last_led_err[0] = 0;
1103 * Loss of signal and los of frame
1104 * Use the green bit to identify which one lit the led
1106 if(link_status & T1F_RLOF){
1108 if(sc->last_led_err[3] != 1){
1109 printk(KERN_WARNING "%s: Local Red Alarm: Loss of Framing\n", sc->name);
1111 lmc_led_on(sc, LMC_DS3_LED3);
1112 sc->last_led_err[3] = 1;
1116 if(sc->last_led_err[3] != 0){
1117 printk(KERN_WARNING "%s: End Red Alarm (LOF)\n", sc->name);
1119 if( ! (link_status & T1F_RLOS))
1120 lmc_led_off(sc, LMC_DS3_LED3);
1121 sc->last_led_err[3] = 0;
1124 if(link_status & T1F_RLOS){
1126 if(sc->last_led_err[2] != 1){
1127 printk(KERN_WARNING "%s: Local Red Alarm: Loss of Signal\n", sc->name);
1129 lmc_led_on(sc, LMC_DS3_LED3);
1130 sc->last_led_err[2] = 1;
1134 if(sc->last_led_err[2] != 0){
1135 printk(KERN_WARNING "%s: End Red Alarm (LOS)\n", sc->name);
1137 if( ! (link_status & T1F_RLOF))
1138 lmc_led_off(sc, LMC_DS3_LED3);
1139 sc->last_led_err[2] = 0;
1142 sc->lmc_xinfo.t1_alarm1_status = link_status;
1144 lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM2_STATUS);
1145 sc->lmc_xinfo.t1_alarm2_status = lmc_mii_readreg (sc, 0, 18);
1148 lmc_trace(sc->lmc_device, "lmc_t1_get_link_status out");
1154 * 1 == T1 Circuit Type , 0 == E1 Circuit Type
1157 lmc_t1_set_circuit_type (lmc_softc_t * const sc, int ie)
1159 if (ie == LMC_CTL_CIRCUIT_TYPE_T1) {
1160 sc->lmc_miireg16 |= LMC_MII16_T1_Z;
1161 sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_T1;
1162 printk(KERN_INFO "%s: In T1 Mode\n", sc->name);
1165 sc->lmc_miireg16 &= ~LMC_MII16_T1_Z;
1166 sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_E1;
1167 printk(KERN_INFO "%s: In E1 Mode\n", sc->name);
1170 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
1175 * 0 == 16bit, 1 == 32bit */
1177 lmc_t1_set_crc_length (lmc_softc_t * const sc, int state)
1179 if (state == LMC_CTL_CRC_LENGTH_32)
1182 sc->lmc_miireg16 |= LMC_MII16_T1_CRC;
1183 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
1184 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_4;
1189 /* 16 bit */ sc->lmc_miireg16 &= ~LMC_MII16_T1_CRC;
1190 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
1191 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_2;
1195 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
1199 * 1 == internal, 0 == external
1202 lmc_t1_set_clock (lmc_softc_t * const sc, int ie)
1206 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
1208 sc->lmc_gpio &= ~(LMC_GEP_SSI_TXCLOCK);
1209 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
1210 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
1212 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
1216 sc->lmc_gpio |= LMC_GEP_SSI_TXCLOCK;
1217 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
1218 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
1220 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
1225 lmc_t1_watchdog (lmc_softc_t * const sc)
1230 lmc_set_protocol (lmc_softc_t * const sc, lmc_ctl_t * ctl)
1234 sc->ictl.keepalive_onoff = LMC_CTL_ON;