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>
11 #include <linux/pci.h>
13 #include <linux/if_arp.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/skbuff.h>
17 #include <linux/inet.h>
18 #include <linux/bitops.h>
20 #include <net/syncppp.h>
22 #include <asm/processor.h> /* Processor type for cache alignment. */
26 #include <asm/uaccess.h>
30 #include "lmc_ioctl.h"
31 #include "lmc_debug.h"
33 #define CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE 1
36 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
37 * All rights reserved. www.lanmedia.com
39 * This code is written by:
40 * Andrew Stanley-Jones (asj@cban.com)
41 * Rob Braun (bbraun@vix.com),
42 * Michael Graff (explorer@vix.com) and
43 * Matt Thomas (matt@3am-software.com).
45 * This software may be used and distributed according to the terms
46 * of the GNU General Public License version 2, incorporated herein by reference.
50 * protocol independent method.
52 static void lmc_set_protocol (lmc_softc_t * const, lmc_ctl_t *);
55 * media independent methods to check on media status, link, light LEDs,
58 static void lmc_ds3_init (lmc_softc_t * const);
59 static void lmc_ds3_default (lmc_softc_t * const);
60 static void lmc_ds3_set_status (lmc_softc_t * const, lmc_ctl_t *);
61 static void lmc_ds3_set_100ft (lmc_softc_t * const, int);
62 static int lmc_ds3_get_link_status (lmc_softc_t * const);
63 static void lmc_ds3_set_crc_length (lmc_softc_t * const, int);
64 static void lmc_ds3_set_scram (lmc_softc_t * const, int);
65 static void lmc_ds3_watchdog (lmc_softc_t * const);
67 static void lmc_hssi_init (lmc_softc_t * const);
68 static void lmc_hssi_default (lmc_softc_t * const);
69 static void lmc_hssi_set_status (lmc_softc_t * const, lmc_ctl_t *);
70 static void lmc_hssi_set_clock (lmc_softc_t * const, int);
71 static int lmc_hssi_get_link_status (lmc_softc_t * const);
72 static void lmc_hssi_set_link_status (lmc_softc_t * const, int);
73 static void lmc_hssi_set_crc_length (lmc_softc_t * const, int);
74 static void lmc_hssi_watchdog (lmc_softc_t * const);
76 static void lmc_ssi_init (lmc_softc_t * const);
77 static void lmc_ssi_default (lmc_softc_t * const);
78 static void lmc_ssi_set_status (lmc_softc_t * const, lmc_ctl_t *);
79 static void lmc_ssi_set_clock (lmc_softc_t * const, int);
80 static void lmc_ssi_set_speed (lmc_softc_t * const, lmc_ctl_t *);
81 static int lmc_ssi_get_link_status (lmc_softc_t * const);
82 static void lmc_ssi_set_link_status (lmc_softc_t * const, int);
83 static void lmc_ssi_set_crc_length (lmc_softc_t * const, int);
84 static void lmc_ssi_watchdog (lmc_softc_t * const);
86 static void lmc_t1_init (lmc_softc_t * const);
87 static void lmc_t1_default (lmc_softc_t * const);
88 static void lmc_t1_set_status (lmc_softc_t * const, lmc_ctl_t *);
89 static int lmc_t1_get_link_status (lmc_softc_t * const);
90 static void lmc_t1_set_circuit_type (lmc_softc_t * const, int);
91 static void lmc_t1_set_crc_length (lmc_softc_t * const, int);
92 static void lmc_t1_set_clock (lmc_softc_t * const, int);
93 static void lmc_t1_watchdog (lmc_softc_t * const);
95 static void lmc_dummy_set_1 (lmc_softc_t * const, int);
96 static void lmc_dummy_set2_1 (lmc_softc_t * const, lmc_ctl_t *);
98 static inline void write_av9110_bit (lmc_softc_t *, int);
99 static void write_av9110 (lmc_softc_t *, u_int32_t, u_int32_t, u_int32_t,
100 u_int32_t, u_int32_t);
102 lmc_media_t lmc_ds3_media = {
103 lmc_ds3_init, /* special media init stuff */
104 lmc_ds3_default, /* reset to default state */
105 lmc_ds3_set_status, /* reset status to state provided */
106 lmc_dummy_set_1, /* set clock source */
107 lmc_dummy_set2_1, /* set line speed */
108 lmc_ds3_set_100ft, /* set cable length */
109 lmc_ds3_set_scram, /* set scrambler */
110 lmc_ds3_get_link_status, /* get link status */
111 lmc_dummy_set_1, /* set link status */
112 lmc_ds3_set_crc_length, /* set CRC length */
113 lmc_dummy_set_1, /* set T1 or E1 circuit type */
117 lmc_media_t lmc_hssi_media = {
118 lmc_hssi_init, /* special media init stuff */
119 lmc_hssi_default, /* reset to default state */
120 lmc_hssi_set_status, /* reset status to state provided */
121 lmc_hssi_set_clock, /* set clock source */
122 lmc_dummy_set2_1, /* set line speed */
123 lmc_dummy_set_1, /* set cable length */
124 lmc_dummy_set_1, /* set scrambler */
125 lmc_hssi_get_link_status, /* get link status */
126 lmc_hssi_set_link_status, /* set link status */
127 lmc_hssi_set_crc_length, /* set CRC length */
128 lmc_dummy_set_1, /* set T1 or E1 circuit type */
132 lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
133 lmc_ssi_default, /* reset to default state */
134 lmc_ssi_set_status, /* reset status to state provided */
135 lmc_ssi_set_clock, /* set clock source */
136 lmc_ssi_set_speed, /* set line speed */
137 lmc_dummy_set_1, /* set cable length */
138 lmc_dummy_set_1, /* set scrambler */
139 lmc_ssi_get_link_status, /* get link status */
140 lmc_ssi_set_link_status, /* set link status */
141 lmc_ssi_set_crc_length, /* set CRC length */
142 lmc_dummy_set_1, /* set T1 or E1 circuit type */
146 lmc_media_t lmc_t1_media = {
147 lmc_t1_init, /* special media init stuff */
148 lmc_t1_default, /* reset to default state */
149 lmc_t1_set_status, /* reset status to state provided */
150 lmc_t1_set_clock, /* set clock source */
151 lmc_dummy_set2_1, /* set line speed */
152 lmc_dummy_set_1, /* set cable length */
153 lmc_dummy_set_1, /* set scrambler */
154 lmc_t1_get_link_status, /* get link status */
155 lmc_dummy_set_1, /* set link status */
156 lmc_t1_set_crc_length, /* set CRC length */
157 lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
162 lmc_dummy_set_1 (lmc_softc_t * const sc, int a)
167 lmc_dummy_set2_1 (lmc_softc_t * const sc, lmc_ctl_t * a)
176 lmc_hssi_init (lmc_softc_t * const sc)
178 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC5200;
180 lmc_gpio_mkoutput (sc, LMC_GEP_HSSI_CLOCK);
184 lmc_hssi_default (lmc_softc_t * const sc)
186 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
188 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
189 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
190 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
194 * Given a user provided state, set ourselves up to match it. This will
195 * always reset the card if needed.
198 lmc_hssi_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
202 sc->lmc_media->set_clock_source (sc, sc->ictl.clock_source);
203 lmc_set_protocol (sc, NULL);
209 * check for change in clock source
211 if (ctl->clock_source && !sc->ictl.clock_source)
213 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_INT);
214 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_INT;
216 else if (!ctl->clock_source && sc->ictl.clock_source)
218 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
219 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
222 lmc_set_protocol (sc, ctl);
226 * 1 == internal, 0 == external
229 lmc_hssi_set_clock (lmc_softc_t * const sc, int ie)
232 old = sc->ictl.clock_source;
233 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
235 sc->lmc_gpio |= LMC_GEP_HSSI_CLOCK;
236 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
237 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
239 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
243 sc->lmc_gpio &= ~(LMC_GEP_HSSI_CLOCK);
244 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
245 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
247 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
252 * return hardware link status.
253 * 0 == link is down, 1 == link is up.
256 lmc_hssi_get_link_status (lmc_softc_t * const sc)
259 * We're using the same code as SSI since
260 * they're practically the same
262 return lmc_ssi_get_link_status(sc);
266 lmc_hssi_set_link_status (lmc_softc_t * const sc, int state)
268 if (state == LMC_LINK_UP)
269 sc->lmc_miireg16 |= LMC_MII16_HSSI_TA;
271 sc->lmc_miireg16 &= ~LMC_MII16_HSSI_TA;
273 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
277 * 0 == 16bit, 1 == 32bit
280 lmc_hssi_set_crc_length (lmc_softc_t * const sc, int state)
282 if (state == LMC_CTL_CRC_LENGTH_32)
285 sc->lmc_miireg16 |= LMC_MII16_HSSI_CRC;
286 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
291 sc->lmc_miireg16 &= ~LMC_MII16_HSSI_CRC;
292 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
295 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
299 lmc_hssi_watchdog (lmc_softc_t * const sc)
312 lmc_ds3_set_100ft (lmc_softc_t * const sc, int ie)
314 if (ie == LMC_CTL_CABLE_LENGTH_GT_100FT)
316 sc->lmc_miireg16 &= ~LMC_MII16_DS3_ZERO;
317 sc->ictl.cable_length = LMC_CTL_CABLE_LENGTH_GT_100FT;
319 else if (ie == LMC_CTL_CABLE_LENGTH_LT_100FT)
321 sc->lmc_miireg16 |= LMC_MII16_DS3_ZERO;
322 sc->ictl.cable_length = LMC_CTL_CABLE_LENGTH_LT_100FT;
324 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
328 lmc_ds3_default (lmc_softc_t * const sc)
330 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
332 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
333 sc->lmc_media->set_cable_length (sc, LMC_CTL_CABLE_LENGTH_LT_100FT);
334 sc->lmc_media->set_scrambler (sc, LMC_CTL_OFF);
335 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
339 * Given a user provided state, set ourselves up to match it. This will
340 * always reset the card if needed.
343 lmc_ds3_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
347 sc->lmc_media->set_cable_length (sc, sc->ictl.cable_length);
348 sc->lmc_media->set_scrambler (sc, sc->ictl.scrambler_onoff);
349 lmc_set_protocol (sc, NULL);
355 * check for change in cable length setting
357 if (ctl->cable_length && !sc->ictl.cable_length)
358 lmc_ds3_set_100ft (sc, LMC_CTL_CABLE_LENGTH_GT_100FT);
359 else if (!ctl->cable_length && sc->ictl.cable_length)
360 lmc_ds3_set_100ft (sc, LMC_CTL_CABLE_LENGTH_LT_100FT);
363 * Check for change in scrambler setting (requires reset)
365 if (ctl->scrambler_onoff && !sc->ictl.scrambler_onoff)
366 lmc_ds3_set_scram (sc, LMC_CTL_ON);
367 else if (!ctl->scrambler_onoff && sc->ictl.scrambler_onoff)
368 lmc_ds3_set_scram (sc, LMC_CTL_OFF);
370 lmc_set_protocol (sc, ctl);
374 lmc_ds3_init (lmc_softc_t * const sc)
378 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC5245;
380 /* writes zeros everywhere */
381 for (i = 0; i < 21; i++)
383 lmc_mii_writereg (sc, 0, 17, i);
384 lmc_mii_writereg (sc, 0, 18, 0);
387 /* set some essential bits */
388 lmc_mii_writereg (sc, 0, 17, 1);
389 lmc_mii_writereg (sc, 0, 18, 0x25); /* ser, xtx */
391 lmc_mii_writereg (sc, 0, 17, 5);
392 lmc_mii_writereg (sc, 0, 18, 0x80); /* emode */
394 lmc_mii_writereg (sc, 0, 17, 14);
395 lmc_mii_writereg (sc, 0, 18, 0x30); /* rcgen, tcgen */
397 /* clear counters and latched bits */
398 for (i = 0; i < 21; i++)
400 lmc_mii_writereg (sc, 0, 17, i);
401 lmc_mii_readreg (sc, 0, 18);
406 * 1 == DS3 payload scrambled, 0 == not scrambled
409 lmc_ds3_set_scram (lmc_softc_t * const sc, int ie)
411 if (ie == LMC_CTL_ON)
413 sc->lmc_miireg16 |= LMC_MII16_DS3_SCRAM;
414 sc->ictl.scrambler_onoff = LMC_CTL_ON;
418 sc->lmc_miireg16 &= ~LMC_MII16_DS3_SCRAM;
419 sc->ictl.scrambler_onoff = LMC_CTL_OFF;
421 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
425 * return hardware link status.
426 * 0 == link is down, 1 == link is up.
429 lmc_ds3_get_link_status (lmc_softc_t * const sc)
431 u_int16_t link_status, link_status_11;
434 lmc_mii_writereg (sc, 0, 17, 7);
435 link_status = lmc_mii_readreg (sc, 0, 18);
437 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
438 * led0 yellow = far-end adapter is in Red alarm condition
439 * led1 blue = received an Alarm Indication signal
441 * led2 Green = power to adapter, Gate Array loaded & driver
443 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
444 * conditions detected on T3 receive signal
447 lmc_led_on(sc, LMC_DS3_LED2);
449 if ((link_status & LMC_FRAMER_REG0_DLOS) ||
450 (link_status & LMC_FRAMER_REG0_OOFS)){
452 if(sc->last_led_err[3] != 1){
454 lmc_mii_writereg (sc, 0, 17, 01); /* Turn on Xbit error as our cisco does */
455 r1 = lmc_mii_readreg (sc, 0, 18);
457 lmc_mii_writereg(sc, 0, 18, r1);
458 printk(KERN_WARNING "%s: Red Alarm - Loss of Signal or Loss of Framing\n", sc->name);
460 lmc_led_on(sc, LMC_DS3_LED3); /* turn on red LED */
461 sc->last_led_err[3] = 1;
464 lmc_led_off(sc, LMC_DS3_LED3); /* turn on red LED */
465 if(sc->last_led_err[3] == 1){
467 lmc_mii_writereg (sc, 0, 17, 01); /* Turn off Xbit error */
468 r1 = lmc_mii_readreg (sc, 0, 18);
470 lmc_mii_writereg(sc, 0, 18, r1);
472 sc->last_led_err[3] = 0;
475 lmc_mii_writereg(sc, 0, 17, 0x10);
476 link_status_11 = lmc_mii_readreg(sc, 0, 18);
477 if((link_status & LMC_FRAMER_REG0_AIS) ||
478 (link_status_11 & LMC_FRAMER_REG10_XBIT)) {
480 if(sc->last_led_err[0] != 1){
481 printk(KERN_WARNING "%s: AIS Alarm or XBit Error\n", sc->name);
482 printk(KERN_WARNING "%s: Remote end has loss of signal or framing\n", sc->name);
484 lmc_led_on(sc, LMC_DS3_LED0);
485 sc->last_led_err[0] = 1;
488 lmc_led_off(sc, LMC_DS3_LED0);
489 sc->last_led_err[0] = 0;
492 lmc_mii_writereg (sc, 0, 17, 9);
493 link_status = lmc_mii_readreg (sc, 0, 18);
495 if(link_status & LMC_FRAMER_REG9_RBLUE){
497 if(sc->last_led_err[1] != 1){
498 printk(KERN_WARNING "%s: Blue Alarm - Receiving all 1's\n", sc->name);
500 lmc_led_on(sc, LMC_DS3_LED1);
501 sc->last_led_err[1] = 1;
504 lmc_led_off(sc, LMC_DS3_LED1);
505 sc->last_led_err[1] = 0;
512 * 0 == 16bit, 1 == 32bit
515 lmc_ds3_set_crc_length (lmc_softc_t * const sc, int state)
517 if (state == LMC_CTL_CRC_LENGTH_32)
520 sc->lmc_miireg16 |= LMC_MII16_DS3_CRC;
521 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
526 sc->lmc_miireg16 &= ~LMC_MII16_DS3_CRC;
527 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
530 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
534 lmc_ds3_watchdog (lmc_softc_t * const sc)
545 lmc_ssi_init (lmc_softc_t * const sc)
550 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1000;
552 mii17 = lmc_mii_readreg (sc, 0, 17);
554 cable = (mii17 & LMC_MII17_SSI_CABLE_MASK) >> LMC_MII17_SSI_CABLE_SHIFT;
555 sc->ictl.cable_type = cable;
557 lmc_gpio_mkoutput (sc, LMC_GEP_SSI_TXCLOCK);
561 lmc_ssi_default (lmc_softc_t * const sc)
563 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
566 * make TXCLOCK always be an output
568 lmc_gpio_mkoutput (sc, LMC_GEP_SSI_TXCLOCK);
570 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
571 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
572 sc->lmc_media->set_speed (sc, NULL);
573 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
577 * Given a user provided state, set ourselves up to match it. This will
578 * always reset the card if needed.
581 lmc_ssi_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
585 sc->lmc_media->set_clock_source (sc, sc->ictl.clock_source);
586 sc->lmc_media->set_speed (sc, &sc->ictl);
587 lmc_set_protocol (sc, NULL);
593 * check for change in clock source
595 if (ctl->clock_source == LMC_CTL_CLOCK_SOURCE_INT
596 && sc->ictl.clock_source == LMC_CTL_CLOCK_SOURCE_EXT)
598 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_INT);
599 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_INT;
601 else if (ctl->clock_source == LMC_CTL_CLOCK_SOURCE_EXT
602 && sc->ictl.clock_source == LMC_CTL_CLOCK_SOURCE_INT)
604 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
605 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
608 if (ctl->clock_rate != sc->ictl.clock_rate)
609 sc->lmc_media->set_speed (sc, ctl);
611 lmc_set_protocol (sc, ctl);
615 * 1 == internal, 0 == external
618 lmc_ssi_set_clock (lmc_softc_t * const sc, int ie)
622 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
624 sc->lmc_gpio &= ~(LMC_GEP_SSI_TXCLOCK);
625 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
626 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
628 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
632 sc->lmc_gpio |= LMC_GEP_SSI_TXCLOCK;
633 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
634 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
636 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
641 lmc_ssi_set_speed (lmc_softc_t * const sc, lmc_ctl_t * ctl)
643 lmc_ctl_t *ictl = &sc->ictl;
646 /* original settings for clock rate of:
647 * 100 Khz (8,25,0,0,2) were incorrect
648 * they should have been 80,125,1,3,3
649 * There are 17 param combinations to produce this freq.
650 * For 1.5 Mhz use 120,100,1,1,2 (226 param. combinations)
654 av = &ictl->cardspec.ssi;
655 ictl->clock_rate = 1500000;
656 av->f = ictl->clock_rate;
663 write_av9110 (sc, av->n, av->m, av->v, av->x, av->r);
667 av = &ctl->cardspec.ssi;
672 ictl->clock_rate = av->f; /* really, this is the rate we are */
673 ictl->cardspec.ssi = *av;
675 write_av9110 (sc, av->n, av->m, av->v, av->x, av->r);
679 * return hardware link status.
680 * 0 == link is down, 1 == link is up.
683 lmc_ssi_get_link_status (lmc_softc_t * const sc)
685 u_int16_t link_status;
691 * missing CTS? Hmm. If we require CTS on, we may never get the
692 * link to come up, so omit it in this test.
694 * Also, it seems that with a loopback cable, DCD isn't asserted,
695 * so just check for things like this:
696 * DSR _must_ be asserted.
697 * One of DCD or CTS must be asserted.
700 /* LMC 1000 (SSI) LED definitions
701 * led0 Green = power to adapter, Gate Array loaded &
703 * led1 Green = DSR and DTR and RTS and CTS are set
704 * led2 Green = Cable detected
705 * led3 red = No timing is available from the
706 * cable or the on-board frequency
710 link_status = lmc_mii_readreg (sc, 0, 16);
712 /* Is the transmit clock still available */
713 ticks = LMC_CSR_READ (sc, csr_gp_timer);
714 ticks = 0x0000ffff - (ticks & 0x0000ffff);
716 lmc_led_on (sc, LMC_MII16_LED0);
718 /* ====== transmit clock determination ===== */
719 if (sc->lmc_timing == LMC_CTL_CLOCK_SOURCE_INT) {
720 lmc_led_off(sc, LMC_MII16_LED3);
722 else if (ticks == 0 ) { /* no clock found ? */
724 if(sc->last_led_err[3] != 1){
725 sc->stats.tx_lossOfClockCnt++;
726 printk(KERN_WARNING "%s: Lost Clock, Link Down\n", sc->name);
728 sc->last_led_err[3] = 1;
729 lmc_led_on (sc, LMC_MII16_LED3); /* turn ON red LED */
732 if(sc->last_led_err[3] == 1)
733 printk(KERN_WARNING "%s: Clock Returned\n", sc->name);
734 sc->last_led_err[3] = 0;
735 lmc_led_off (sc, LMC_MII16_LED3); /* turn OFF red LED */
738 if ((link_status & LMC_MII16_SSI_DSR) == 0) { /* Also HSSI CA */
743 #ifdef CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE
744 if ((link_status & (LMC_MII16_SSI_CTS | LMC_MII16_SSI_DCD)) == 0){
751 if(sc->last_led_err[1] != 1)
752 printk(KERN_WARNING "%s: DSR not asserted\n", sc->name);
753 sc->last_led_err[1] = 1;
754 lmc_led_off(sc, LMC_MII16_LED1);
757 if(sc->last_led_err[1] != 0)
758 printk(KERN_WARNING "%s: DSR now asserted\n", sc->name);
759 sc->last_led_err[1] = 0;
760 lmc_led_on(sc, LMC_MII16_LED1);
764 lmc_led_on(sc, LMC_MII16_LED2); /* Over all good status? */
771 lmc_ssi_set_link_status (lmc_softc_t * const sc, int state)
773 if (state == LMC_LINK_UP)
775 sc->lmc_miireg16 |= (LMC_MII16_SSI_DTR | LMC_MII16_SSI_RTS);
776 printk (LMC_PRINTF_FMT ": asserting DTR and RTS\n", LMC_PRINTF_ARGS);
780 sc->lmc_miireg16 &= ~(LMC_MII16_SSI_DTR | LMC_MII16_SSI_RTS);
781 printk (LMC_PRINTF_FMT ": deasserting DTR and RTS\n", LMC_PRINTF_ARGS);
784 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
789 * 0 == 16bit, 1 == 32bit
792 lmc_ssi_set_crc_length (lmc_softc_t * const sc, int state)
794 if (state == LMC_CTL_CRC_LENGTH_32)
797 sc->lmc_miireg16 |= LMC_MII16_SSI_CRC;
798 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
799 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_4;
805 sc->lmc_miireg16 &= ~LMC_MII16_SSI_CRC;
806 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
807 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_2;
810 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
814 * These are bits to program the ssi frequency generator
817 write_av9110_bit (lmc_softc_t * sc, int c)
820 * set the data bit as we need it.
822 sc->lmc_gpio &= ~(LMC_GEP_CLK);
824 sc->lmc_gpio |= LMC_GEP_DATA;
826 sc->lmc_gpio &= ~(LMC_GEP_DATA);
827 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
830 * set the clock to high
832 sc->lmc_gpio |= LMC_GEP_CLK;
833 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
836 * set the clock to low again.
838 sc->lmc_gpio &= ~(LMC_GEP_CLK);
839 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
843 write_av9110 (lmc_softc_t * sc, u_int32_t n, u_int32_t m, u_int32_t v,
844 u_int32_t x, u_int32_t r)
849 printk (LMC_PRINTF_FMT ": speed %u, %d %d %d %d %d\n",
850 LMC_PRINTF_ARGS, sc->ictl.clock_rate, n, m, v, x, r);
853 sc->lmc_gpio |= LMC_GEP_SSI_GENERATOR;
854 sc->lmc_gpio &= ~(LMC_GEP_DATA | LMC_GEP_CLK);
855 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
858 * Set the TXCLOCK, GENERATOR, SERIAL, and SERIALCLK
861 lmc_gpio_mkoutput (sc, (LMC_GEP_DATA | LMC_GEP_CLK
862 | LMC_GEP_SSI_GENERATOR));
864 sc->lmc_gpio &= ~(LMC_GEP_SSI_GENERATOR);
865 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
868 * a shifting we will go...
870 for (i = 0; i < 7; i++)
871 write_av9110_bit (sc, n >> i);
872 for (i = 0; i < 7; i++)
873 write_av9110_bit (sc, m >> i);
874 for (i = 0; i < 1; i++)
875 write_av9110_bit (sc, v >> i);
876 for (i = 0; i < 2; i++)
877 write_av9110_bit (sc, x >> i);
878 for (i = 0; i < 2; i++)
879 write_av9110_bit (sc, r >> i);
880 for (i = 0; i < 5; i++)
881 write_av9110_bit (sc, 0x17 >> i);
884 * stop driving serial-related signals
886 lmc_gpio_mkinput (sc,
887 (LMC_GEP_DATA | LMC_GEP_CLK
888 | LMC_GEP_SSI_GENERATOR));
892 lmc_ssi_watchdog (lmc_softc_t * const sc)
897 unsigned short dtr:1, dsr:1, rts:1, cable:3, crc:1, led0:1, led1:1,
898 led2:1, led3:1, fifo:1, ll:1, rl:1, tm:1, loop:1;
900 struct ssicsr2 *ssicsr;
901 mii17 = lmc_mii_readreg (sc, 0, 17);
902 ssicsr = (struct ssicsr2 *) &mii17;
903 if (ssicsr->cable == 7)
905 lmc_led_off (sc, LMC_MII16_LED2);
909 lmc_led_on (sc, LMC_MII16_LED2);
919 * The framer regs are multiplexed through MII regs 17 & 18
920 * write the register address to MII reg 17 and the * data to MII reg 18. */
922 lmc_t1_write (lmc_softc_t * const sc, int a, int d)
924 lmc_mii_writereg (sc, 0, 17, a);
925 lmc_mii_writereg (sc, 0, 18, d);
930 lmc_t1_read (lmc_softc_t * const sc, int a)
932 lmc_mii_writereg (sc, 0, 17, a);
933 return lmc_mii_readreg (sc, 0, 18);
939 lmc_t1_init (lmc_softc_t * const sc)
944 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1200;
945 mii16 = lmc_mii_readreg (sc, 0, 16);
948 mii16 &= ~LMC_MII16_T1_RST;
949 lmc_mii_writereg (sc, 0, 16, mii16 | LMC_MII16_T1_RST);
950 lmc_mii_writereg (sc, 0, 16, mii16);
952 /* set T1 or E1 line. Uses sc->lmcmii16 reg in function so update it */
953 sc->lmc_miireg16 = mii16;
954 lmc_t1_set_circuit_type(sc, LMC_CTL_CIRCUIT_TYPE_T1);
955 mii16 = sc->lmc_miireg16;
957 lmc_t1_write (sc, 0x01, 0x1B); /* CR0 - primary control */
958 lmc_t1_write (sc, 0x02, 0x42); /* JAT_CR - jitter atten config */
959 lmc_t1_write (sc, 0x14, 0x00); /* LOOP - loopback config */
960 lmc_t1_write (sc, 0x15, 0x00); /* DL3_TS - external data link timeslot */
961 lmc_t1_write (sc, 0x18, 0xFF); /* PIO - programmable I/O */
962 lmc_t1_write (sc, 0x19, 0x30); /* POE - programmable OE */
963 lmc_t1_write (sc, 0x1A, 0x0F); /* CMUX - clock input mux */
964 lmc_t1_write (sc, 0x20, 0x41); /* LIU_CR - RX LIU config */
965 lmc_t1_write (sc, 0x22, 0x76); /* RLIU_CR - RX LIU config */
966 lmc_t1_write (sc, 0x40, 0x03); /* RCR0 - RX config */
967 lmc_t1_write (sc, 0x45, 0x00); /* RALM - RX alarm config */
968 lmc_t1_write (sc, 0x46, 0x05); /* LATCH - RX alarm/err/cntr latch */
969 lmc_t1_write (sc, 0x68, 0x40); /* TLIU_CR - TX LIU config */
970 lmc_t1_write (sc, 0x70, 0x0D); /* TCR0 - TX framer config */
971 lmc_t1_write (sc, 0x71, 0x05); /* TCR1 - TX config */
972 lmc_t1_write (sc, 0x72, 0x0B); /* TFRM - TX frame format */
973 lmc_t1_write (sc, 0x73, 0x00); /* TERROR - TX error insert */
974 lmc_t1_write (sc, 0x74, 0x00); /* TMAN - TX manual Sa/FEBE config */
975 lmc_t1_write (sc, 0x75, 0x00); /* TALM - TX alarm signal config */
976 lmc_t1_write (sc, 0x76, 0x00); /* TPATT - TX test pattern config */
977 lmc_t1_write (sc, 0x77, 0x00); /* TLB - TX inband loopback config */
978 lmc_t1_write (sc, 0x90, 0x05); /* CLAD_CR - clock rate adapter config */
979 lmc_t1_write (sc, 0x91, 0x05); /* CSEL - clad freq sel */
980 lmc_t1_write (sc, 0xA6, 0x00); /* DL1_CTL - DL1 control */
981 lmc_t1_write (sc, 0xB1, 0x00); /* DL2_CTL - DL2 control */
982 lmc_t1_write (sc, 0xD0, 0x47); /* SBI_CR - sys bus iface config */
983 lmc_t1_write (sc, 0xD1, 0x70); /* RSB_CR - RX sys bus config */
984 lmc_t1_write (sc, 0xD4, 0x30); /* TSB_CR - TX sys bus config */
985 for (i = 0; i < 32; i++)
987 lmc_t1_write (sc, 0x0E0 + i, 0x00); /* SBCn - sys bus per-channel ctl */
988 lmc_t1_write (sc, 0x100 + i, 0x00); /* TPCn - TX per-channel ctl */
989 lmc_t1_write (sc, 0x180 + i, 0x00); /* RPCn - RX per-channel ctl */
991 for (i = 1; i < 25; i++)
993 lmc_t1_write (sc, 0x0E0 + i, 0x0D); /* SBCn - sys bus per-channel ctl */
996 mii16 |= LMC_MII16_T1_XOE;
997 lmc_mii_writereg (sc, 0, 16, mii16);
998 sc->lmc_miireg16 = mii16;
1002 lmc_t1_default (lmc_softc_t * const sc)
1004 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
1005 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
1006 sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1);
1007 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
1008 /* Right now we can only clock from out internal source */
1009 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
1011 /* * Given a user provided state, set ourselves up to match it. This will * always reset the card if needed.
1014 lmc_t1_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
1018 sc->lmc_media->set_circuit_type (sc, sc->ictl.circuit_type);
1019 lmc_set_protocol (sc, NULL);
1024 * check for change in circuit type */
1025 if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_T1
1026 && sc->ictl.circuit_type ==
1027 LMC_CTL_CIRCUIT_TYPE_E1) sc->lmc_media->set_circuit_type (sc,
1028 LMC_CTL_CIRCUIT_TYPE_E1);
1029 else if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_E1
1030 && sc->ictl.circuit_type == LMC_CTL_CIRCUIT_TYPE_T1)
1031 sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1);
1032 lmc_set_protocol (sc, ctl);
1035 * return hardware link status.
1036 * 0 == link is down, 1 == link is up.
1038 lmc_t1_get_link_status (lmc_softc_t * const sc)
1040 u_int16_t link_status;
1043 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
1044 * led0 yellow = far-end adapter is in Red alarm condition
1045 * led1 blue = received an Alarm Indication signal
1046 * (upstream failure)
1047 * led2 Green = power to adapter, Gate Array loaded & driver
1049 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
1050 * conditions detected on T3 receive signal
1052 lmc_trace(sc->lmc_device, "lmc_t1_get_link_status in");
1053 lmc_led_on(sc, LMC_DS3_LED2);
1055 lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM1_STATUS);
1056 link_status = lmc_mii_readreg (sc, 0, 18);
1059 if (link_status & T1F_RAIS) { /* turn on blue LED */
1061 if(sc->last_led_err[1] != 1){
1062 printk(KERN_WARNING "%s: Receive AIS/Blue Alarm. Far end in RED alarm\n", sc->name);
1064 lmc_led_on(sc, LMC_DS3_LED1);
1065 sc->last_led_err[1] = 1;
1068 if(sc->last_led_err[1] != 0){
1069 printk(KERN_WARNING "%s: End AIS/Blue Alarm\n", sc->name);
1071 lmc_led_off (sc, LMC_DS3_LED1);
1072 sc->last_led_err[1] = 0;
1076 * Yellow Alarm is nasty evil stuff, looks at data patterns
1077 * inside the channel and confuses it with HDLC framing
1078 * ignore all yellow alarms.
1080 * Do listen to MultiFrame Yellow alarm which while implemented
1081 * different ways isn't in the channel and hence somewhat
1085 if (link_status & T1F_RMYEL) {
1087 if(sc->last_led_err[0] != 1){
1088 printk(KERN_WARNING "%s: Receive Yellow AIS Alarm\n", sc->name);
1090 lmc_led_on(sc, LMC_DS3_LED0);
1091 sc->last_led_err[0] = 1;
1094 if(sc->last_led_err[0] != 0){
1095 printk(KERN_WARNING "%s: End of Yellow AIS Alarm\n", sc->name);
1097 lmc_led_off(sc, LMC_DS3_LED0);
1098 sc->last_led_err[0] = 0;
1102 * Loss of signal and los of frame
1103 * Use the green bit to identify which one lit the led
1105 if(link_status & T1F_RLOF){
1107 if(sc->last_led_err[3] != 1){
1108 printk(KERN_WARNING "%s: Local Red Alarm: Loss of Framing\n", sc->name);
1110 lmc_led_on(sc, LMC_DS3_LED3);
1111 sc->last_led_err[3] = 1;
1115 if(sc->last_led_err[3] != 0){
1116 printk(KERN_WARNING "%s: End Red Alarm (LOF)\n", sc->name);
1118 if( ! (link_status & T1F_RLOS))
1119 lmc_led_off(sc, LMC_DS3_LED3);
1120 sc->last_led_err[3] = 0;
1123 if(link_status & T1F_RLOS){
1125 if(sc->last_led_err[2] != 1){
1126 printk(KERN_WARNING "%s: Local Red Alarm: Loss of Signal\n", sc->name);
1128 lmc_led_on(sc, LMC_DS3_LED3);
1129 sc->last_led_err[2] = 1;
1133 if(sc->last_led_err[2] != 0){
1134 printk(KERN_WARNING "%s: End Red Alarm (LOS)\n", sc->name);
1136 if( ! (link_status & T1F_RLOF))
1137 lmc_led_off(sc, LMC_DS3_LED3);
1138 sc->last_led_err[2] = 0;
1141 sc->lmc_xinfo.t1_alarm1_status = link_status;
1143 lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM2_STATUS);
1144 sc->lmc_xinfo.t1_alarm2_status = lmc_mii_readreg (sc, 0, 18);
1147 lmc_trace(sc->lmc_device, "lmc_t1_get_link_status out");
1153 * 1 == T1 Circuit Type , 0 == E1 Circuit Type
1156 lmc_t1_set_circuit_type (lmc_softc_t * const sc, int ie)
1158 if (ie == LMC_CTL_CIRCUIT_TYPE_T1) {
1159 sc->lmc_miireg16 |= LMC_MII16_T1_Z;
1160 sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_T1;
1161 printk(KERN_INFO "%s: In T1 Mode\n", sc->name);
1164 sc->lmc_miireg16 &= ~LMC_MII16_T1_Z;
1165 sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_E1;
1166 printk(KERN_INFO "%s: In E1 Mode\n", sc->name);
1169 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
1174 * 0 == 16bit, 1 == 32bit */
1176 lmc_t1_set_crc_length (lmc_softc_t * const sc, int state)
1178 if (state == LMC_CTL_CRC_LENGTH_32)
1181 sc->lmc_miireg16 |= LMC_MII16_T1_CRC;
1182 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
1183 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_4;
1188 /* 16 bit */ sc->lmc_miireg16 &= ~LMC_MII16_T1_CRC;
1189 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
1190 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_2;
1194 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
1198 * 1 == internal, 0 == external
1201 lmc_t1_set_clock (lmc_softc_t * const sc, int ie)
1205 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
1207 sc->lmc_gpio &= ~(LMC_GEP_SSI_TXCLOCK);
1208 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
1209 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
1211 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
1215 sc->lmc_gpio |= LMC_GEP_SSI_TXCLOCK;
1216 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
1217 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
1219 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
1224 lmc_t1_watchdog (lmc_softc_t * const sc)
1229 lmc_set_protocol (lmc_softc_t * const sc, lmc_ctl_t * ctl)
1233 sc->ictl.keepalive_onoff = LMC_CTL_ON;