4 * Copyright (c) 2002-2004 David Boggs. <boggs@boggs.palo-alto.ca.us>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * GNU General Public License:
32 * This program is free software; you can redistribute it and/or modify it
33 * under the terms of the GNU General Public License as published by the Free
34 * Software Foundation; either version 2 of the License, or (at your option)
37 * This program is distributed in the hope that it will be useful, but WITHOUT
38 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
42 * You should have received a copy of the GNU General Public License along with
43 * this program; if not, write to the Free Software Foundation, Inc., 59
44 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
48 * This is an open-source Unix device driver for PCI-bus WAN interface cards.
49 * It sends and receives packets in HDLC frames over synchronous links.
50 * A generic PC plus Unix plus some SBE/LMC cards makes an OPEN router.
51 * This driver works with FreeBSD, NetBSD, OpenBSD, BSD/OS and Linux.
52 * It has been tested on i386 (32-bit little-end), Sparc (64-bit big-end),
53 * and Alpha (64-bit little-end) architectures.
55 * History and Authors:
57 * Ron Crane had the neat idea to use a Fast Ethernet chip as a PCI
58 * interface and add an Ethernet-to-HDLC gate array to make a WAN card.
59 * David Boggs designed the Ethernet-to-HDLC gate arrays and PC cards.
60 * We did this at our company, LAN Media Corporation (LMC).
61 * SBE Corp acquired LMC and continues to make the cards.
63 * Since the cards use Tulip Ethernet chips, we started with Matt Thomas'
64 * ubiquitous "de" driver. Michael Graff stripped out the Ethernet stuff
65 * and added HSSI stuff. Basil Gunn ported it to Solaris (lost) and
66 * Rob Braun ported it to Linux. Andrew Stanley-Jones added support
67 * for three more cards and wrote the first version of lmcconfig.
68 * During 2002-5 David Boggs rewrote it and now feels responsible for it.
70 * Responsible Individual:
72 * Send bug reports and improvements to <boggs@boggs.palo-alto.ca.us>.
74 # include <sys/param.h> /* OS version */
76 # include "opt_inet.h" /* INET */
77 # include "opt_inet6.h" /* INET6 */
78 # include "opt_netgraph.h" /* NETGRAPH */
79 # ifdef HAVE_KERNEL_OPTION_HEADERS
80 # include "opt_device_polling.h" /* DEVICE_POLLING */
91 # define P2P 0 /* not in FreeBSD */
92 # define NSPPP 1 /* No count devices in FreeBSD 5 */
93 # include "opt_bpf.h" /* DEV_BPF */
94 # define NBPFILTER DEV_BPF
95 # define GEN_HDLC 0 /* not in FreeBSD */
97 # include <sys/systm.h>
98 # include <sys/kernel.h>
99 # include <sys/malloc.h>
100 # include <sys/mbuf.h>
101 # include <sys/socket.h>
102 # include <sys/sockio.h>
103 # include <sys/module.h>
104 # include <sys/bus.h>
105 # include <sys/lock.h>
107 # include <net/if_var.h>
108 # include <net/if_types.h>
109 # include <net/if_media.h>
110 # include <net/netisr.h>
111 # include <net/route.h>
112 # include <machine/bus.h>
113 # include <machine/resource.h>
114 # include <sys/rman.h>
116 # include <vm/pmap.h>
117 # include <sys/priv.h>
118 # include <sys/mutex.h>
119 # include <dev/pci/pcivar.h>
121 # include <netgraph/ng_message.h>
122 # include <netgraph/netgraph.h>
125 # include <netinet/in.h>
126 # include <netinet/in_var.h>
129 # include <net/if_sppp.h>
132 # include <net/bpf.h>
135 # include <dev/lmc/if_lmc.h>
141 /* The SROM is a generic 93C46 serial EEPROM (64 words by 16 bits). */
142 /* Data is set up before the RISING edge of CLK; CLK is parked low. */
144 shift_srom_bits(softc_t *sc, u_int32_t data, u_int32_t len)
146 u_int32_t csr = READ_CSR(TLP_SROM_MII);
149 if (data & (1<<(len-1)))
150 csr |= TLP_SROM_DIN; /* DIN setup */
152 csr &= ~TLP_SROM_DIN; /* DIN setup */
153 WRITE_CSR(TLP_SROM_MII, csr);
154 csr |= TLP_SROM_CLK; /* CLK rising edge */
155 WRITE_CSR(TLP_SROM_MII, csr);
156 csr &= ~TLP_SROM_CLK; /* CLK falling edge */
157 WRITE_CSR(TLP_SROM_MII, csr);
161 /* Data is sampled on the RISING edge of CLK; CLK is parked low. */
163 read_srom(softc_t *sc, u_int8_t addr)
169 /* Enable SROM access. */
170 csr = (TLP_SROM_SEL | TLP_SROM_RD | TLP_MII_MDOE);
171 WRITE_CSR(TLP_SROM_MII, csr);
172 /* CS rising edge prepares SROM for a new cycle. */
174 WRITE_CSR(TLP_SROM_MII, csr); /* assert CS */
175 shift_srom_bits(sc, 6, 4); /* issue read cmd */
176 shift_srom_bits(sc, addr, 6); /* issue address */
177 for (data=0, i=16; i>=0; i--) /* read ->17<- bits of data */
179 csr = READ_CSR(TLP_SROM_MII); /* DOUT sampled */
180 data = (data<<1) | ((csr & TLP_SROM_DOUT) ? 1:0);
181 csr |= TLP_SROM_CLK; /* CLK rising edge */
182 WRITE_CSR(TLP_SROM_MII, csr);
183 csr &= ~TLP_SROM_CLK; /* CLK falling edge */
184 WRITE_CSR(TLP_SROM_MII, csr);
186 /* Disable SROM access. */
187 WRITE_CSR(TLP_SROM_MII, TLP_MII_MDOE);
192 /* The SROM is formatted by the mfgr and should NOT be written! */
193 /* But lmcconfig can rewrite it in case it gets overwritten somehow. */
194 /* IOCTL SYSCALL: can sleep. */
196 write_srom(softc_t *sc, u_int8_t addr, u_int16_t data)
201 /* Enable SROM access. */
202 csr = (TLP_SROM_SEL | TLP_SROM_RD | TLP_MII_MDOE);
203 WRITE_CSR(TLP_SROM_MII, csr);
205 /* Issue write-enable command. */
207 WRITE_CSR(TLP_SROM_MII, csr); /* assert CS */
208 shift_srom_bits(sc, 4, 4); /* issue write enable cmd */
209 shift_srom_bits(sc, 63, 6); /* issue address */
211 WRITE_CSR(TLP_SROM_MII, csr); /* deassert CS */
213 /* Issue erase command. */
215 WRITE_CSR(TLP_SROM_MII, csr); /* assert CS */
216 shift_srom_bits(sc, 7, 4); /* issue erase cmd */
217 shift_srom_bits(sc, addr, 6); /* issue address */
219 WRITE_CSR(TLP_SROM_MII, csr); /* deassert CS */
221 /* Issue write command. */
223 WRITE_CSR(TLP_SROM_MII, csr); /* assert CS */
224 for (i=0; i<10; i++) /* 100 ms max wait */
225 if ((READ_CSR(TLP_SROM_MII) & TLP_SROM_DOUT)==0) SLEEP(10000);
226 shift_srom_bits(sc, 5, 4); /* issue write cmd */
227 shift_srom_bits(sc, addr, 6); /* issue address */
228 shift_srom_bits(sc, data, 16); /* issue data */
230 WRITE_CSR(TLP_SROM_MII, csr); /* deassert CS */
232 /* Issue write-disable command. */
234 WRITE_CSR(TLP_SROM_MII, csr); /* assert CS */
235 for (i=0; i<10; i++) /* 100 ms max wait */
236 if ((READ_CSR(TLP_SROM_MII) & TLP_SROM_DOUT)==0) SLEEP(10000);
237 shift_srom_bits(sc, 4, 4); /* issue write disable cmd */
238 shift_srom_bits(sc, 0, 6); /* issue address */
240 WRITE_CSR(TLP_SROM_MII, csr); /* deassert CS */
242 /* Disable SROM access. */
243 WRITE_CSR(TLP_SROM_MII, TLP_MII_MDOE);
246 /* Not all boards have BIOS roms. */
247 /* The BIOS ROM is an AMD 29F010 1Mbit (128K by 8) EEPROM. */
249 read_bios(softc_t *sc, u_int32_t addr)
253 /* Load the BIOS rom address register. */
254 WRITE_CSR(TLP_BIOS_ROM, addr);
256 /* Enable the BIOS rom. */
257 srom_mii = TLP_BIOS_SEL | TLP_BIOS_RD | TLP_MII_MDOE;
258 WRITE_CSR(TLP_SROM_MII, srom_mii);
260 /* Wait at least 20 PCI cycles. */
263 /* Read the BIOS rom data. */
264 srom_mii = READ_CSR(TLP_SROM_MII);
266 /* Disable the BIOS rom. */
267 WRITE_CSR(TLP_SROM_MII, TLP_MII_MDOE);
269 return (u_int8_t)srom_mii & 0xFF;
273 write_bios_phys(softc_t *sc, u_int32_t addr, u_int8_t data)
277 /* Load the BIOS rom address register. */
278 WRITE_CSR(TLP_BIOS_ROM, addr);
280 /* Enable the BIOS rom. */
281 srom_mii = TLP_BIOS_SEL | TLP_BIOS_WR | TLP_MII_MDOE;
283 /* Load the data into the data register. */
284 srom_mii = (srom_mii & 0xFFFFFF00) | (data & 0xFF);
285 WRITE_CSR(TLP_SROM_MII, srom_mii);
287 /* Wait at least 20 PCI cycles. */
290 /* Disable the BIOS rom. */
291 WRITE_CSR(TLP_SROM_MII, TLP_MII_MDOE);
294 /* IOCTL SYSCALL: can sleep. */
296 write_bios(softc_t *sc, u_int32_t addr, u_int8_t data)
300 /* this sequence enables writing */
301 write_bios_phys(sc, 0x5555, 0xAA);
302 write_bios_phys(sc, 0x2AAA, 0x55);
303 write_bios_phys(sc, 0x5555, 0xA0);
304 write_bios_phys(sc, addr, data);
306 /* Wait for the write operation to complete. */
307 for (;;) /* interruptable syscall */
311 read_data = read_bios(sc, addr);
312 if ((read_data & 0x80) == (data & 0x80)) break;
313 if (read_data & 0x20)
314 { /* Data sheet says read it again. */
315 read_data = read_bios(sc, addr);
316 if ((read_data & 0x80) == (data & 0x80)) break;
318 printf("%s: write_bios() failed; rom addr=0x%x\n",
323 read_data = read_bios(sc, addr);
324 if (read_data == data) break;
328 /* IOCTL SYSCALL: can sleep. */
330 erase_bios(softc_t *sc)
332 unsigned char read_data;
334 /* This sequence enables erasing: */
335 write_bios_phys(sc, 0x5555, 0xAA);
336 write_bios_phys(sc, 0x2AAA, 0x55);
337 write_bios_phys(sc, 0x5555, 0x80);
338 write_bios_phys(sc, 0x5555, 0xAA);
339 write_bios_phys(sc, 0x2AAA, 0x55);
340 write_bios_phys(sc, 0x5555, 0x10);
342 /* Wait for the erase operation to complete. */
343 for (;;) /* interruptable syscall */
347 read_data = read_bios(sc, 0);
348 if (read_data & 0x80) break;
349 if (read_data & 0x20)
350 { /* Data sheet says read it again. */
351 read_data = read_bios(sc, 0);
352 if (read_data & 0x80) break;
354 printf("%s: erase_bios() failed\n", NAME_UNIT);
358 read_data = read_bios(sc, 0);
359 if (read_data == 0xFF) break;
363 /* MDIO is 3-stated between tranactions. */
364 /* MDIO is set up before the RISING edge of MDC; MDC is parked low. */
366 shift_mii_bits(softc_t *sc, u_int32_t data, u_int32_t len)
368 u_int32_t csr = READ_CSR(TLP_SROM_MII);
371 if (data & (1<<(len-1)))
372 csr |= TLP_MII_MDOUT; /* MDOUT setup */
374 csr &= ~TLP_MII_MDOUT; /* MDOUT setup */
375 WRITE_CSR(TLP_SROM_MII, csr);
376 csr |= TLP_MII_MDC; /* MDC rising edge */
377 WRITE_CSR(TLP_SROM_MII, csr);
378 csr &= ~TLP_MII_MDC; /* MDC falling edge */
379 WRITE_CSR(TLP_SROM_MII, csr);
383 /* The specification for the MII is IEEE Std 802.3 clause 22. */
384 /* MDIO is sampled on the RISING edge of MDC; MDC is parked low. */
386 read_mii(softc_t *sc, u_int8_t regad)
392 WRITE_CSR(TLP_SROM_MII, TLP_MII_MDOUT);
394 shift_mii_bits(sc, 0xFFFFF, 20); /* preamble */
395 shift_mii_bits(sc, 0xFFFFF, 20); /* preamble */
396 shift_mii_bits(sc, 1, 2); /* start symbol */
397 shift_mii_bits(sc, 2, 2); /* read op */
398 shift_mii_bits(sc, 0, 5); /* phyad=0 */
399 shift_mii_bits(sc, regad, 5); /* regad */
400 csr = READ_CSR(TLP_SROM_MII);
402 WRITE_CSR(TLP_SROM_MII, csr);
403 shift_mii_bits(sc, 0, 2); /* turn-around */
404 for (i=15; i>=0; i--) /* data */
406 csr = READ_CSR(TLP_SROM_MII); /* MDIN sampled */
407 data = (data<<1) | ((csr & TLP_MII_MDIN) ? 1:0);
408 csr |= TLP_MII_MDC; /* MDC rising edge */
409 WRITE_CSR(TLP_SROM_MII, csr);
410 csr &= ~TLP_MII_MDC; /* MDC falling edge */
411 WRITE_CSR(TLP_SROM_MII, csr);
417 write_mii(softc_t *sc, u_int8_t regad, u_int16_t data)
419 WRITE_CSR(TLP_SROM_MII, TLP_MII_MDOUT);
420 shift_mii_bits(sc, 0xFFFFF, 20); /* preamble */
421 shift_mii_bits(sc, 0xFFFFF, 20); /* preamble */
422 shift_mii_bits(sc, 1, 2); /* start symbol */
423 shift_mii_bits(sc, 1, 2); /* write op */
424 shift_mii_bits(sc, 0, 5); /* phyad=0 */
425 shift_mii_bits(sc, regad, 5); /* regad */
426 shift_mii_bits(sc, 2, 2); /* turn-around */
427 shift_mii_bits(sc, data, 16); /* data */
428 WRITE_CSR(TLP_SROM_MII, TLP_MII_MDOE);
429 if (regad == 16) sc->led_state = data; /* a small optimization */
433 set_mii16_bits(softc_t *sc, u_int16_t bits)
435 u_int16_t mii16 = read_mii(sc, 16);
437 write_mii(sc, 16, mii16);
441 clr_mii16_bits(softc_t *sc, u_int16_t bits)
443 u_int16_t mii16 = read_mii(sc, 16);
445 write_mii(sc, 16, mii16);
449 set_mii17_bits(softc_t *sc, u_int16_t bits)
451 u_int16_t mii17 = read_mii(sc, 17);
453 write_mii(sc, 17, mii17);
457 clr_mii17_bits(softc_t *sc, u_int16_t bits)
459 u_int16_t mii17 = read_mii(sc, 17);
461 write_mii(sc, 17, mii17);
465 * Watchdog code is more readable if it refreshes LEDs
466 * once a second whether they need it or not.
467 * But MII refs take 150 uSecs each, so remember the last value
468 * written to MII16 and avoid LED writes that do nothing.
472 led_off(softc_t *sc, u_int16_t led)
474 if ((led & sc->led_state) == led) return;
475 set_mii16_bits(sc, led);
479 led_on(softc_t *sc, u_int16_t led)
481 if ((led & sc->led_state) == 0) return;
482 clr_mii16_bits(sc, led);
486 led_inv(softc_t *sc, u_int16_t led)
488 u_int16_t mii16 = read_mii(sc, 16);
490 write_mii(sc, 16, mii16);
494 * T1 & T3 framer registers are accessed through MII regs 17 & 18.
495 * Write the address to MII reg 17 then R/W data through MII reg 18.
496 * The hardware interface is an Intel-style 8-bit muxed A/D bus.
499 write_framer(softc_t *sc, u_int16_t addr, u_int8_t data)
501 write_mii(sc, 17, addr);
502 write_mii(sc, 18, data);
506 read_framer(softc_t *sc, u_int16_t addr)
508 write_mii(sc, 17, addr);
509 return (u_int8_t)read_mii(sc, 18);
512 /* Tulip's hardware implementation of General Purpose IO
513 * (GPIO) pins makes life difficult for software.
514 * Bits 7-0 in the Tulip GPIO CSR are used for two purposes
515 * depending on the state of bit 8.
516 * If bit 8 is 0 then bits 7-0 are "data" bits.
517 * If bit 8 is 1 then bits 7-0 are "direction" bits.
518 * If a direction bit is one, the data bit is an output.
519 * The problem is that the direction bits are WRITE-ONLY.
520 * Software must remember the direction bits in a shadow copy.
521 * (sc->gpio_dir) in order to change some but not all of the bits.
522 * All accesses to the Tulip GPIO register use these five procedures.
526 make_gpio_input(softc_t *sc, u_int32_t bits)
528 sc->gpio_dir &= ~bits;
529 WRITE_CSR(TLP_GPIO, TLP_GPIO_DIR | (sc->gpio_dir));
533 make_gpio_output(softc_t *sc, u_int32_t bits)
535 sc->gpio_dir |= bits;
536 WRITE_CSR(TLP_GPIO, TLP_GPIO_DIR | (sc->gpio_dir));
540 read_gpio(softc_t *sc)
542 return READ_CSR(TLP_GPIO);
546 set_gpio_bits(softc_t *sc, u_int32_t bits)
548 WRITE_CSR(TLP_GPIO, (read_gpio(sc) | bits) & 0xFF);
552 clr_gpio_bits(softc_t *sc, u_int32_t bits)
554 WRITE_CSR(TLP_GPIO, (read_gpio(sc) & ~bits) & 0xFF);
557 /* Reset ALL of the flip-flops in the gate array to zero. */
558 /* This does NOT change the gate array programming. */
559 /* Called during initialization so it must not sleep. */
561 reset_xilinx(softc_t *sc)
563 /* Drive RESET low to force initialization. */
564 clr_gpio_bits(sc, GPIO_RESET);
565 make_gpio_output(sc, GPIO_RESET);
567 /* Hold RESET low for more than 10 uSec. */
570 /* Done with RESET; make it an input. */
571 make_gpio_input(sc, GPIO_RESET);
574 /* Load Xilinx gate array program from on-board rom. */
575 /* This changes the gate array programming. */
576 /* IOCTL SYSCALL: can sleep. */
578 load_xilinx_from_rom(softc_t *sc)
582 /* Drive MODE low to load from ROM rather than GPIO. */
583 clr_gpio_bits(sc, GPIO_MODE);
584 make_gpio_output(sc, GPIO_MODE);
586 /* Drive DP & RESET low to force configuration. */
587 clr_gpio_bits(sc, GPIO_RESET | GPIO_DP);
588 make_gpio_output(sc, GPIO_RESET | GPIO_DP);
590 /* Hold RESET & DP low for more than 10 uSec. */
593 /* Done with RESET & DP; make them inputs. */
594 make_gpio_input(sc, GPIO_DP | GPIO_RESET);
596 /* BUSY-WAIT for Xilinx chip to configure itself from ROM bits. */
597 for (i=0; i<100; i++) /* 1 sec max delay */
598 if ((read_gpio(sc) & GPIO_DP) == 0) SLEEP(10000);
600 /* Done with MODE; make it an input. */
601 make_gpio_input(sc, GPIO_MODE);
604 /* Load the Xilinx gate array program from userland bits. */
605 /* This changes the gate array programming. */
606 /* IOCTL SYSCALL: can sleep. */
608 load_xilinx_from_file(softc_t *sc, char *addr, u_int32_t len)
613 /* Get some pages to hold the Xilinx bits; biggest file is < 6 KB. */
614 if (len > 8192) return EFBIG; /* too big */
615 data = malloc(len, M_DEVBUF, M_WAITOK);
616 if (data == NULL) return ENOMEM;
618 /* Copy the Xilinx bits from userland. */
619 if ((error = copyin(addr, data, len)))
621 free(data, M_DEVBUF);
625 /* Drive MODE high to load from GPIO rather than ROM. */
626 set_gpio_bits(sc, GPIO_MODE);
627 make_gpio_output(sc, GPIO_MODE);
629 /* Drive DP & RESET low to force configuration. */
630 clr_gpio_bits(sc, GPIO_RESET | GPIO_DP);
631 make_gpio_output(sc, GPIO_RESET | GPIO_DP);
633 /* Hold RESET & DP low for more than 10 uSec. */
636 /* Done with RESET & DP; make them inputs. */
637 make_gpio_input(sc, GPIO_RESET | GPIO_DP);
639 /* BUSY-WAIT for Xilinx chip to clear its config memory. */
640 make_gpio_input(sc, GPIO_INIT);
641 for (i=0; i<10000; i++) /* 1 sec max delay */
642 if ((read_gpio(sc) & GPIO_INIT)==0) SLEEP(10000);
644 /* Configure CLK and DATA as outputs. */
645 set_gpio_bits(sc, GPIO_CLK); /* park CLK high */
646 make_gpio_output(sc, GPIO_CLK | GPIO_DATA);
648 /* Write bits to Xilinx; CLK is parked HIGH. */
649 /* DATA is set up before the RISING edge of CLK. */
650 for (i=0; i<len; i++)
653 if ((data[i] & (1<<j)) != 0)
654 set_gpio_bits(sc, GPIO_DATA); /* DATA setup */
656 clr_gpio_bits(sc, GPIO_DATA); /* DATA setup */
657 clr_gpio_bits(sc, GPIO_CLK); /* CLK falling edge */
658 set_gpio_bits(sc, GPIO_CLK); /* CLK rising edge */
661 /* Stop driving all Xilinx-related signals. */
662 /* Pullup and pulldown resistors take over. */
663 make_gpio_input(sc, GPIO_CLK | GPIO_DATA | GPIO_MODE);
665 free(data, M_DEVBUF);
669 /* Write fragments of a command into the synthesized oscillator. */
670 /* DATA is set up before the RISING edge of CLK. CLK is parked low. */
672 shift_synth_bits(softc_t *sc, u_int32_t data, u_int32_t len)
676 for (i=0; i<len; i++)
678 if ((data & (1<<i)) != 0)
679 set_gpio_bits(sc, GPIO_DATA); /* DATA setup */
681 clr_gpio_bits(sc, GPIO_DATA); /* DATA setup */
682 set_gpio_bits(sc, GPIO_CLK); /* CLK rising edge */
683 clr_gpio_bits(sc, GPIO_CLK); /* CLK falling edge */
687 /* Write a command to the synthesized oscillator on SSI and HSSIc. */
689 write_synth(softc_t *sc, struct synth *synth)
691 /* SSI cards have a programmable prescaler */
692 if (sc->status.card_type == TLP_CSID_SSI)
694 if (synth->prescale == 9) /* divide by 512 */
695 set_mii17_bits(sc, MII17_SSI_PRESCALE);
696 else /* divide by 32 */
697 clr_mii17_bits(sc, MII17_SSI_PRESCALE);
700 clr_gpio_bits(sc, GPIO_DATA | GPIO_CLK);
701 make_gpio_output(sc, GPIO_DATA | GPIO_CLK);
703 /* SYNTH is a low-true chip enable for the AV9110 chip. */
704 set_gpio_bits(sc, GPIO_SSI_SYNTH);
705 make_gpio_output(sc, GPIO_SSI_SYNTH);
706 clr_gpio_bits(sc, GPIO_SSI_SYNTH);
708 /* Serially shift the command into the AV9110 chip. */
709 shift_synth_bits(sc, synth->n, 7);
710 shift_synth_bits(sc, synth->m, 7);
711 shift_synth_bits(sc, synth->v, 1);
712 shift_synth_bits(sc, synth->x, 2);
713 shift_synth_bits(sc, synth->r, 2);
714 shift_synth_bits(sc, 0x16, 5); /* enable clk/x output */
716 /* SYNTH (chip enable) going high ends the command. */
717 set_gpio_bits(sc, GPIO_SSI_SYNTH);
718 make_gpio_input(sc, GPIO_SSI_SYNTH);
720 /* Stop driving serial-related signals; pullups/pulldowns take over. */
721 make_gpio_input(sc, GPIO_DATA | GPIO_CLK);
723 /* remember the new synthesizer parameters */
724 if (&sc->config.synth != synth) sc->config.synth = *synth;
727 /* Write a command to the DAC controlling the VCXO on some T3 adapters. */
728 /* The DAC is a TI-TLV5636: 12-bit resolution and a serial interface. */
729 /* DATA is set up before the FALLING edge of CLK. CLK is parked HIGH. */
731 write_dac(softc_t *sc, u_int16_t data)
735 /* Prepare to use DATA and CLK. */
736 set_gpio_bits(sc, GPIO_DATA | GPIO_CLK);
737 make_gpio_output(sc, GPIO_DATA | GPIO_CLK);
739 /* High-to-low transition prepares DAC for new value. */
740 set_gpio_bits(sc, GPIO_T3_DAC);
741 make_gpio_output(sc, GPIO_T3_DAC);
742 clr_gpio_bits(sc, GPIO_T3_DAC);
744 /* Serially shift command bits into DAC. */
747 if ((data & (1<<(15-i))) != 0)
748 set_gpio_bits(sc, GPIO_DATA); /* DATA setup */
750 clr_gpio_bits(sc, GPIO_DATA); /* DATA setup */
751 clr_gpio_bits(sc, GPIO_CLK); /* CLK falling edge */
752 set_gpio_bits(sc, GPIO_CLK); /* CLK rising edge */
755 /* Done with DAC; make it an input; loads new value into DAC. */
756 set_gpio_bits(sc, GPIO_T3_DAC);
757 make_gpio_input(sc, GPIO_T3_DAC);
759 /* Stop driving serial-related signals; pullups/pulldowns take over. */
760 make_gpio_input(sc, GPIO_DATA | GPIO_CLK);
763 /* begin HSSI card code */
765 /* Must not sleep. */
767 hssi_config(softc_t *sc)
769 if (sc->status.card_type == 0)
771 sc->status.card_type = READ_PCI_CFG(sc, TLP_CSID);
772 sc->config.crc_len = CFG_CRC_16;
773 sc->config.loop_back = CFG_LOOP_NONE;
774 sc->config.tx_clk_src = CFG_CLKMUX_ST;
775 sc->config.dte_dce = CFG_DTE;
776 sc->config.synth.n = 52; /* 52.000 Mbs */
777 sc->config.synth.m = 5;
778 sc->config.synth.v = 0;
779 sc->config.synth.x = 0;
780 sc->config.synth.r = 0;
781 sc->config.synth.prescale = 2;
785 if (sc->config.crc_len == CFG_CRC_32)
786 set_mii16_bits(sc, MII16_HSSI_CRC32);
788 clr_mii16_bits(sc, MII16_HSSI_CRC32);
790 /* Assert pin LA in HSSI conn: ask modem for local loop. */
791 if (sc->config.loop_back == CFG_LOOP_LL)
792 set_mii16_bits(sc, MII16_HSSI_LA);
794 clr_mii16_bits(sc, MII16_HSSI_LA);
796 /* Assert pin LB in HSSI conn: ask modem for remote loop. */
797 if (sc->config.loop_back == CFG_LOOP_RL)
798 set_mii16_bits(sc, MII16_HSSI_LB);
800 clr_mii16_bits(sc, MII16_HSSI_LB);
802 if (sc->status.card_type == TLP_CSID_HSSI)
805 if (sc->config.tx_clk_src == CFG_CLKMUX_ST)
806 set_gpio_bits(sc, GPIO_HSSI_TXCLK);
808 clr_gpio_bits(sc, GPIO_HSSI_TXCLK);
809 make_gpio_output(sc, GPIO_HSSI_TXCLK);
811 else if (sc->status.card_type == TLP_CSID_HSSIc)
812 { /* cPCI HSSI rev C has extra features */
813 /* Set TXCLK source. */
814 u_int16_t mii16 = read_mii(sc, 16);
815 mii16 &= ~MII16_HSSI_CLKMUX;
816 mii16 |= (sc->config.tx_clk_src&3)<<13;
817 write_mii(sc, 16, mii16);
819 /* cPCI HSSI implements loopback towards the net. */
820 if (sc->config.loop_back == CFG_LOOP_LINE)
821 set_mii16_bits(sc, MII16_HSSI_LOOP);
823 clr_mii16_bits(sc, MII16_HSSI_LOOP);
825 /* Set DTE/DCE mode. */
826 if (sc->config.dte_dce == CFG_DCE)
827 set_gpio_bits(sc, GPIO_HSSI_DCE);
829 clr_gpio_bits(sc, GPIO_HSSI_DCE);
830 make_gpio_output(sc, GPIO_HSSI_DCE);
832 /* Program the synthesized oscillator. */
833 write_synth(sc, &sc->config.synth);
838 hssi_ident(softc_t *sc)
842 /* Called once a second; must not sleep. */
844 hssi_watchdog(softc_t *sc)
846 u_int16_t mii16 = read_mii(sc, 16) & MII16_HSSI_MODEM;
847 int link_status = STATUS_UP;
849 led_inv(sc, MII16_HSSI_LED_UL); /* Software is alive. */
850 led_on(sc, MII16_HSSI_LED_LL); /* always on (SSI cable) */
852 /* Check the transmit clock. */
853 if (sc->status.tx_speed == 0)
855 led_on(sc, MII16_HSSI_LED_UR);
856 link_status = STATUS_DOWN;
859 led_off(sc, MII16_HSSI_LED_UR);
861 /* Is the modem ready? */
862 if ((mii16 & MII16_HSSI_CA) == 0)
864 led_off(sc, MII16_HSSI_LED_LR);
865 link_status = STATUS_DOWN;
868 led_on(sc, MII16_HSSI_LED_LR);
870 /* Print the modem control signals if they changed. */
871 if ((DRIVER_DEBUG) && (mii16 != sc->last_mii16))
873 char *on = "ON ", *off = "OFF";
874 printf("%s: TA=%s CA=%s LA=%s LB=%s LC=%s TM=%s\n", NAME_UNIT,
875 (mii16 & MII16_HSSI_TA) ? on : off,
876 (mii16 & MII16_HSSI_CA) ? on : off,
877 (mii16 & MII16_HSSI_LA) ? on : off,
878 (mii16 & MII16_HSSI_LB) ? on : off,
879 (mii16 & MII16_HSSI_LC) ? on : off,
880 (mii16 & MII16_HSSI_TM) ? on : off);
883 /* SNMP one-second-report */
884 sc->status.snmp.hssi.sigs = mii16 & MII16_HSSI_MODEM;
886 /* Remember this state until next time. */
887 sc->last_mii16 = mii16;
889 /* If a loop back is in effect, link status is UP */
890 if (sc->config.loop_back != CFG_LOOP_NONE)
891 link_status = STATUS_UP;
896 /* IOCTL SYSCALL: can sleep (but doesn't). */
898 hssi_ioctl(softc_t *sc, struct ioctl *ioctl)
902 if (ioctl->cmd == IOCTL_SNMP_SIGS)
904 u_int16_t mii16 = read_mii(sc, 16);
905 mii16 &= ~MII16_HSSI_MODEM;
906 mii16 |= (MII16_HSSI_MODEM & ioctl->data);
907 write_mii(sc, 16, mii16);
909 else if (ioctl->cmd == IOCTL_SET_STATUS)
911 if (ioctl->data != 0)
912 set_mii16_bits(sc, MII16_HSSI_TA);
914 clr_mii16_bits(sc, MII16_HSSI_TA);
922 /* begin DS3 card code */
924 /* Must not sleep. */
926 t3_config(softc_t *sc)
931 if (sc->status.card_type == 0)
933 sc->status.card_type = TLP_CSID_T3;
934 sc->config.crc_len = CFG_CRC_16;
935 sc->config.loop_back = CFG_LOOP_NONE;
936 sc->config.format = CFG_FORMAT_T3CPAR;
937 sc->config.cable_len = 10; /* meters */
938 sc->config.scrambler = CFG_SCRAM_DL_KEN;
939 sc->config.tx_clk_src = CFG_CLKMUX_INT;
941 /* Center the VCXO -- get within 20 PPM of 44736000. */
942 write_dac(sc, 0x9002); /* set Vref = 2.048 volts */
943 write_dac(sc, 2048); /* range is 0..4095 */
946 /* Set cable length. */
947 if (sc->config.cable_len > 30)
948 clr_mii16_bits(sc, MII16_DS3_ZERO);
950 set_mii16_bits(sc, MII16_DS3_ZERO);
952 /* Set payload scrambler polynomial. */
953 if (sc->config.scrambler == CFG_SCRAM_LARS)
954 set_mii16_bits(sc, MII16_DS3_POLY);
956 clr_mii16_bits(sc, MII16_DS3_POLY);
958 /* Set payload scrambler on/off. */
959 if (sc->config.scrambler == CFG_SCRAM_OFF)
960 clr_mii16_bits(sc, MII16_DS3_SCRAM);
962 set_mii16_bits(sc, MII16_DS3_SCRAM);
964 /* Set CRC length. */
965 if (sc->config.crc_len == CFG_CRC_32)
966 set_mii16_bits(sc, MII16_DS3_CRC32);
968 clr_mii16_bits(sc, MII16_DS3_CRC32);
970 /* Loopback towards host thru the line interface. */
971 if (sc->config.loop_back == CFG_LOOP_OTHER)
972 set_mii16_bits(sc, MII16_DS3_TRLBK);
974 clr_mii16_bits(sc, MII16_DS3_TRLBK);
976 /* Loopback towards network thru the line interface. */
977 if (sc->config.loop_back == CFG_LOOP_LINE)
978 set_mii16_bits(sc, MII16_DS3_LNLBK);
979 else if (sc->config.loop_back == CFG_LOOP_DUAL)
980 set_mii16_bits(sc, MII16_DS3_LNLBK);
982 clr_mii16_bits(sc, MII16_DS3_LNLBK);
984 /* Configure T3 framer chip; write EVERY writeable register. */
985 ctl1 = CTL1_SER | CTL1_XTX;
986 if (sc->config.loop_back == CFG_LOOP_INWARD) ctl1 |= CTL1_3LOOP;
987 if (sc->config.loop_back == CFG_LOOP_DUAL) ctl1 |= CTL1_3LOOP;
988 if (sc->config.format == CFG_FORMAT_T3M13) ctl1 |= CTL1_M13MODE;
989 write_framer(sc, T3CSR_CTL1, ctl1);
990 write_framer(sc, T3CSR_TX_FEAC, CTL5_EMODE);
991 write_framer(sc, T3CSR_CTL8, CTL8_FBEC);
992 write_framer(sc, T3CSR_CTL12, CTL12_DLCB1 | CTL12_C21 | CTL12_MCB1);
993 write_framer(sc, T3CSR_DBL_FEAC, 0);
994 write_framer(sc, T3CSR_CTL14, CTL14_RGCEN | CTL14_TGCEN);
995 write_framer(sc, T3CSR_INTEN, 0);
996 write_framer(sc, T3CSR_CTL20, CTL20_CVEN);
998 /* Clear error counters and latched error bits */
999 /* that may have happened while initializing. */
1000 for (i=0; i<21; i++) read_framer(sc, i);
1004 t3_ident(softc_t *sc)
1006 printf(", TXC03401 rev B");
1009 /* Called once a second; must not sleep. */
1011 t3_watchdog(softc_t *sc)
1014 u_int8_t CERR, PERR, MERR, FERR, FEBE;
1015 u_int8_t ctl1, stat16, feac;
1016 int link_status = STATUS_UP;
1019 /* Read the alarm registers. */
1020 ctl1 = read_framer(sc, T3CSR_CTL1);
1021 stat16 = read_framer(sc, T3CSR_STAT16);
1022 mii16 = read_mii(sc, 16);
1024 /* Always ignore the RTLOC alarm bit. */
1025 stat16 &= ~STAT16_RTLOC;
1027 /* Software is alive. */
1028 led_inv(sc, MII16_DS3_LED_GRN);
1030 /* Receiving Alarm Indication Signal (AIS). */
1031 if ((stat16 & STAT16_RAIS) != 0) /* receiving ais */
1032 led_on(sc, MII16_DS3_LED_BLU);
1033 else if (ctl1 & CTL1_TXAIS) /* sending ais */
1034 led_inv(sc, MII16_DS3_LED_BLU);
1036 led_off(sc, MII16_DS3_LED_BLU);
1038 /* Receiving Remote Alarm Indication (RAI). */
1039 if ((stat16 & STAT16_XERR) != 0) /* receiving rai */
1040 led_on(sc, MII16_DS3_LED_YEL);
1041 else if ((ctl1 & CTL1_XTX) == 0) /* sending rai */
1042 led_inv(sc, MII16_DS3_LED_YEL);
1044 led_off(sc, MII16_DS3_LED_YEL);
1046 /* If certain status bits are set then the link is 'down'. */
1047 /* The bad bits are: rxlos rxoof rxais rxidl xerr. */
1048 if ((stat16 & ~(STAT16_FEAC | STAT16_SEF)) != 0)
1049 link_status = STATUS_DOWN;
1051 /* Declare local Red Alarm if the link is down. */
1052 if (link_status == STATUS_DOWN)
1053 led_on(sc, MII16_DS3_LED_RED);
1054 else if (sc->loop_timer != 0) /* loopback is active */
1055 led_inv(sc, MII16_DS3_LED_RED);
1057 led_off(sc, MII16_DS3_LED_RED);
1059 /* Print latched error bits if they changed. */
1060 if ((DRIVER_DEBUG) && ((stat16 & ~STAT16_FEAC) != sc->last_stat16))
1062 char *on = "ON ", *off = "OFF";
1063 printf("%s: RLOS=%s ROOF=%s RAIS=%s RIDL=%s SEF=%s XERR=%s\n",
1065 (stat16 & STAT16_RLOS) ? on : off,
1066 (stat16 & STAT16_ROOF) ? on : off,
1067 (stat16 & STAT16_RAIS) ? on : off,
1068 (stat16 & STAT16_RIDL) ? on : off,
1069 (stat16 & STAT16_SEF) ? on : off,
1070 (stat16 & STAT16_XERR) ? on : off);
1073 /* Check and print error counters if non-zero. */
1074 CV = read_framer(sc, T3CSR_CVHI)<<8;
1075 CV += read_framer(sc, T3CSR_CVLO);
1076 PERR = read_framer(sc, T3CSR_PERR);
1077 CERR = read_framer(sc, T3CSR_CERR);
1078 FERR = read_framer(sc, T3CSR_FERR);
1079 MERR = read_framer(sc, T3CSR_MERR);
1080 FEBE = read_framer(sc, T3CSR_FEBE);
1082 /* CV is invalid during LOS. */
1083 if ((stat16 & STAT16_RLOS)!=0) CV = 0;
1084 /* CERR & FEBE are invalid in M13 mode */
1085 if (sc->config.format == CFG_FORMAT_T3M13) CERR = FEBE = 0;
1086 /* FEBE is invalid during AIS. */
1087 if ((stat16 & STAT16_RAIS)!=0) FEBE = 0;
1088 if (DRIVER_DEBUG && (CV || PERR || CERR || FERR || MERR || FEBE))
1089 printf("%s: CV=%u PERR=%u CERR=%u FERR=%u MERR=%u FEBE=%u\n",
1090 NAME_UNIT, CV, PERR, CERR, FERR, MERR, FEBE);
1092 /* Driver keeps crude link-level error counters (SNMP is better). */
1093 sc->status.cntrs.lcv_errs += CV;
1094 sc->status.cntrs.par_errs += PERR;
1095 sc->status.cntrs.cpar_errs += CERR;
1096 sc->status.cntrs.frm_errs += FERR;
1097 sc->status.cntrs.mfrm_errs += MERR;
1098 sc->status.cntrs.febe_errs += FEBE;
1100 /* Check for FEAC messages (FEAC not defined in M13 mode). */
1101 if (FORMAT_T3CPAR && (stat16 & STAT16_FEAC)) do
1103 feac = read_framer(sc, T3CSR_FEAC_STK);
1104 if ((feac & FEAC_STK_VALID)==0) break;
1105 /* Ignore RxFEACs while a far end loopback has been requested. */
1106 if ((sc->status.snmp.t3.line & TLOOP_FAR_LINE)!=0) continue;
1107 switch (feac & FEAC_STK_FEAC)
1109 case T3BOP_LINE_UP: break;
1110 case T3BOP_LINE_DOWN: break;
1111 case T3BOP_LOOP_DS3:
1113 if (sc->last_FEAC == T3BOP_LINE_DOWN)
1116 printf("%s: Received a 'line loopback deactivate' FEAC msg\n", NAME_UNIT);
1117 clr_mii16_bits(sc, MII16_DS3_LNLBK);
1120 if (sc->last_FEAC == T3BOP_LINE_UP)
1123 printf("%s: Received a 'line loopback activate' FEAC msg\n", NAME_UNIT);
1124 set_mii16_bits(sc, MII16_DS3_LNLBK);
1125 sc->loop_timer = 300;
1132 printf("%s: Received a 'far end LOF' FEAC msg\n", NAME_UNIT);
1138 printf("%s: Received a 'far end IDL' FEAC msg\n", NAME_UNIT);
1144 printf("%s: Received a 'far end AIS' FEAC msg\n", NAME_UNIT);
1150 printf("%s: Received a 'far end LOS' FEAC msg\n", NAME_UNIT);
1156 printf("%s: Received a 'type 0x%02X' FEAC msg\n", NAME_UNIT, feac & FEAC_STK_FEAC);
1160 sc->last_FEAC = feac & FEAC_STK_FEAC;
1161 } while ((feac & FEAC_STK_MORE) != 0);
1162 stat16 &= ~STAT16_FEAC;
1164 /* Send Service-Affecting priority FEAC messages */
1165 if (((sc->last_stat16 ^ stat16) & 0xF0) && (FORMAT_T3CPAR))
1167 /* Transmit continuous FEACs */
1168 write_framer(sc, T3CSR_CTL14,
1169 read_framer(sc, T3CSR_CTL14) & ~CTL14_FEAC10);
1170 if ((stat16 & STAT16_RLOS)!=0)
1171 write_framer(sc, T3CSR_TX_FEAC, 0xC0 + T3BOP_LOS);
1172 else if ((stat16 & STAT16_ROOF)!=0)
1173 write_framer(sc, T3CSR_TX_FEAC, 0xC0 + T3BOP_OOF);
1174 else if ((stat16 & STAT16_RAIS)!=0)
1175 write_framer(sc, T3CSR_TX_FEAC, 0xC0 + T3BOP_AIS);
1176 else if ((stat16 & STAT16_RIDL)!=0)
1177 write_framer(sc, T3CSR_TX_FEAC, 0xC0 + T3BOP_IDLE);
1179 write_framer(sc, T3CSR_TX_FEAC, CTL5_EMODE);
1182 /* Start sending RAI, Remote Alarm Indication. */
1183 if (((stat16 & STAT16_ROOF)!=0) && ((stat16 & STAT16_RLOS)==0) &&
1184 ((sc->last_stat16 & STAT16_ROOF)==0))
1185 write_framer(sc, T3CSR_CTL1, ctl1 &= ~CTL1_XTX);
1186 /* Stop sending RAI, Remote Alarm Indication. */
1187 else if (((stat16 & STAT16_ROOF)==0) && ((sc->last_stat16 & STAT16_ROOF)!=0))
1188 write_framer(sc, T3CSR_CTL1, ctl1 |= CTL1_XTX);
1190 /* Start sending AIS, Alarm Indication Signal */
1191 if (((stat16 & STAT16_RLOS)!=0) && ((sc->last_stat16 & STAT16_RLOS)==0))
1193 set_mii16_bits(sc, MII16_DS3_FRAME);
1194 write_framer(sc, T3CSR_CTL1, ctl1 | CTL1_TXAIS);
1196 /* Stop sending AIS, Alarm Indication Signal */
1197 else if (((stat16 & STAT16_RLOS)==0) && ((sc->last_stat16 & STAT16_RLOS)!=0))
1199 clr_mii16_bits(sc, MII16_DS3_FRAME);
1200 write_framer(sc, T3CSR_CTL1, ctl1 & ~CTL1_TXAIS);
1203 /* Time out loopback requests. */
1204 if (sc->loop_timer != 0)
1205 if (--sc->loop_timer == 0)
1206 if ((mii16 & MII16_DS3_LNLBK)!=0)
1209 printf("%s: Timeout: Loop Down after 300 seconds\n", NAME_UNIT);
1210 clr_mii16_bits(sc, MII16_DS3_LNLBK); /* line loopback off */
1213 /* SNMP error counters */
1214 sc->status.snmp.t3.lcv = CV;
1215 sc->status.snmp.t3.pcv = PERR;
1216 sc->status.snmp.t3.ccv = CERR;
1217 sc->status.snmp.t3.febe = FEBE;
1219 /* SNMP Line Status */
1220 sc->status.snmp.t3.line = 0;
1221 if ((ctl1 & CTL1_XTX)==0) sc->status.snmp.t3.line |= TLINE_TX_RAI;
1222 if (stat16 & STAT16_XERR) sc->status.snmp.t3.line |= TLINE_RX_RAI;
1223 if (ctl1 & CTL1_TXAIS) sc->status.snmp.t3.line |= TLINE_TX_AIS;
1224 if (stat16 & STAT16_RAIS) sc->status.snmp.t3.line |= TLINE_RX_AIS;
1225 if (stat16 & STAT16_ROOF) sc->status.snmp.t3.line |= TLINE_LOF;
1226 if (stat16 & STAT16_RLOS) sc->status.snmp.t3.line |= TLINE_LOS;
1227 if (stat16 & STAT16_SEF) sc->status.snmp.t3.line |= T3LINE_SEF;
1229 /* SNMP Loopback Status */
1230 sc->status.snmp.t3.loop &= ~TLOOP_FAR_LINE;
1231 if (sc->config.loop_back == CFG_LOOP_TULIP)
1232 sc->status.snmp.t3.loop |= TLOOP_NEAR_OTHER;
1233 if (ctl1 & CTL1_3LOOP) sc->status.snmp.t3.loop |= TLOOP_NEAR_INWARD;
1234 if (mii16 & MII16_DS3_TRLBK) sc->status.snmp.t3.loop |= TLOOP_NEAR_OTHER;
1235 if (mii16 & MII16_DS3_LNLBK) sc->status.snmp.t3.loop |= TLOOP_NEAR_LINE;
1236 /*if (ctl12 & CTL12_RTPLOOP) sc->status.snmp.t3.loop |= TLOOP_NEAR_PAYLOAD; */
1238 /* Remember this state until next time. */
1239 sc->last_stat16 = stat16;
1241 /* If an INWARD loopback is in effect, link status is UP */
1242 if (sc->config.loop_back != CFG_LOOP_NONE) /* XXX INWARD ONLY */
1243 link_status = STATUS_UP;
1248 /* IOCTL SYSCALL: can sleep. */
1250 t3_send_dbl_feac(softc_t *sc, int feac1, int feac2)
1255 /* The FEAC transmitter could be sending a continuous */
1256 /* FEAC msg when told to send a double FEAC message. */
1257 /* So save the current state of the FEAC transmitter. */
1258 tx_feac = read_framer(sc, T3CSR_TX_FEAC);
1259 /* Load second FEAC code and stop FEAC transmitter. */
1260 write_framer(sc, T3CSR_TX_FEAC, CTL5_EMODE + feac2);
1261 /* FEAC transmitter sends 10 more FEACs and then stops. */
1262 SLEEP(20000); /* sending one FEAC takes 1700 uSecs */
1263 /* Load first FEAC code and start FEAC transmitter. */
1264 write_framer(sc, T3CSR_DBL_FEAC, CTL13_DFEXEC + feac1);
1265 /* Wait for double FEAC sequence to complete -- about 70 ms. */
1266 for (i=0; i<10; i++) /* max delay 100 ms */
1267 if (read_framer(sc, T3CSR_DBL_FEAC) & CTL13_DFEXEC) SLEEP(10000);
1268 /* Flush received FEACS; don't respond to our own loop cmd! */
1269 while (read_framer(sc, T3CSR_FEAC_STK) & FEAC_STK_VALID) DELAY(1); /* XXX HANG */
1270 /* Restore previous state of the FEAC transmitter. */
1271 /* If it was sending a continous FEAC, it will resume. */
1272 write_framer(sc, T3CSR_TX_FEAC, tx_feac);
1275 /* IOCTL SYSCALL: can sleep. */
1277 t3_ioctl(softc_t *sc, struct ioctl *ioctl)
1283 case IOCTL_SNMP_SEND: /* set opstatus? */
1285 if (sc->config.format != CFG_FORMAT_T3CPAR)
1287 else if (ioctl->data == TSEND_LINE)
1289 sc->status.snmp.t3.loop |= TLOOP_FAR_LINE;
1290 t3_send_dbl_feac(sc, T3BOP_LINE_UP, T3BOP_LOOP_DS3);
1292 else if (ioctl->data == TSEND_RESET)
1294 t3_send_dbl_feac(sc, T3BOP_LINE_DOWN, T3BOP_LOOP_DS3);
1295 sc->status.snmp.t3.loop &= ~TLOOP_FAR_LINE;
1301 case IOCTL_SNMP_LOOP: /* set opstatus = test? */
1303 if (ioctl->data == CFG_LOOP_NONE)
1305 clr_mii16_bits(sc, MII16_DS3_FRAME);
1306 clr_mii16_bits(sc, MII16_DS3_TRLBK);
1307 clr_mii16_bits(sc, MII16_DS3_LNLBK);
1308 write_framer(sc, T3CSR_CTL1,
1309 read_framer(sc, T3CSR_CTL1) & ~CTL1_3LOOP);
1310 write_framer(sc, T3CSR_CTL12,
1311 read_framer(sc, T3CSR_CTL12) & ~(CTL12_RTPLOOP | CTL12_RTPLLEN));
1313 else if (ioctl->data == CFG_LOOP_LINE)
1314 set_mii16_bits(sc, MII16_DS3_LNLBK);
1315 else if (ioctl->data == CFG_LOOP_OTHER)
1316 set_mii16_bits(sc, MII16_DS3_TRLBK);
1317 else if (ioctl->data == CFG_LOOP_INWARD)
1318 write_framer(sc, T3CSR_CTL1,
1319 read_framer(sc, T3CSR_CTL1) | CTL1_3LOOP);
1320 else if (ioctl->data == CFG_LOOP_DUAL)
1322 set_mii16_bits(sc, MII16_DS3_LNLBK);
1323 write_framer(sc, T3CSR_CTL1,
1324 read_framer(sc, T3CSR_CTL1) | CTL1_3LOOP);
1326 else if (ioctl->data == CFG_LOOP_PAYLOAD)
1328 set_mii16_bits(sc, MII16_DS3_FRAME);
1329 write_framer(sc, T3CSR_CTL12,
1330 read_framer(sc, T3CSR_CTL12) | CTL12_RTPLOOP);
1331 write_framer(sc, T3CSR_CTL12,
1332 read_framer(sc, T3CSR_CTL12) | CTL12_RTPLLEN);
1333 DELAY(25); /* at least two frames (22 uS) */
1334 write_framer(sc, T3CSR_CTL12,
1335 read_framer(sc, T3CSR_CTL12) & ~CTL12_RTPLLEN);
1349 /* begin SSI card code */
1351 /* Must not sleep. */
1353 ssi_config(softc_t *sc)
1355 if (sc->status.card_type == 0)
1357 sc->status.card_type = TLP_CSID_SSI;
1358 sc->config.crc_len = CFG_CRC_16;
1359 sc->config.loop_back = CFG_LOOP_NONE;
1360 sc->config.tx_clk_src = CFG_CLKMUX_ST;
1361 sc->config.dte_dce = CFG_DTE;
1362 sc->config.synth.n = 51; /* 1.536 MHz */
1363 sc->config.synth.m = 83;
1364 sc->config.synth.v = 1;
1365 sc->config.synth.x = 1;
1366 sc->config.synth.r = 1;
1367 sc->config.synth.prescale = 4;
1370 /* Disable the TX clock driver while programming the oscillator. */
1371 clr_gpio_bits(sc, GPIO_SSI_DCE);
1372 make_gpio_output(sc, GPIO_SSI_DCE);
1374 /* Program the synthesized oscillator. */
1375 write_synth(sc, &sc->config.synth);
1377 /* Set DTE/DCE mode. */
1378 /* If DTE mode then DCD & TXC are received. */
1379 /* If DCE mode then DCD & TXC are driven. */
1380 /* Boards with MII rev=4.0 don't drive DCD. */
1381 if (sc->config.dte_dce == CFG_DCE)
1382 set_gpio_bits(sc, GPIO_SSI_DCE);
1384 clr_gpio_bits(sc, GPIO_SSI_DCE);
1385 make_gpio_output(sc, GPIO_SSI_DCE);
1387 /* Set CRC length. */
1388 if (sc->config.crc_len == CFG_CRC_32)
1389 set_mii16_bits(sc, MII16_SSI_CRC32);
1391 clr_mii16_bits(sc, MII16_SSI_CRC32);
1393 /* Loop towards host thru cable drivers and receivers. */
1394 /* Asserts DCD at the far end of a null modem cable. */
1395 if (sc->config.loop_back == CFG_LOOP_PINS)
1396 set_mii16_bits(sc, MII16_SSI_LOOP);
1398 clr_mii16_bits(sc, MII16_SSI_LOOP);
1400 /* Assert pin LL in modem conn: ask modem for local loop. */
1401 /* Asserts TM at the far end of a null modem cable. */
1402 if (sc->config.loop_back == CFG_LOOP_LL)
1403 set_mii16_bits(sc, MII16_SSI_LL);
1405 clr_mii16_bits(sc, MII16_SSI_LL);
1407 /* Assert pin RL in modem conn: ask modem for remote loop. */
1408 if (sc->config.loop_back == CFG_LOOP_RL)
1409 set_mii16_bits(sc, MII16_SSI_RL);
1411 clr_mii16_bits(sc, MII16_SSI_RL);
1415 ssi_ident(softc_t *sc)
1417 printf(", LTC1343/44");
1420 /* Called once a second; must not sleep. */
1422 ssi_watchdog(softc_t *sc)
1425 u_int16_t mii16 = read_mii(sc, 16) & MII16_SSI_MODEM;
1426 int link_status = STATUS_UP;
1428 /* Software is alive. */
1429 led_inv(sc, MII16_SSI_LED_UL);
1431 /* Check the transmit clock. */
1432 if (sc->status.tx_speed == 0)
1434 led_on(sc, MII16_SSI_LED_UR);
1435 link_status = STATUS_DOWN;
1438 led_off(sc, MII16_SSI_LED_UR);
1440 /* Check the external cable. */
1441 cable = read_mii(sc, 17);
1442 cable = cable & MII17_SSI_CABLE_MASK;
1443 cable = cable >> MII17_SSI_CABLE_SHIFT;
1446 led_off(sc, MII16_SSI_LED_LL); /* no cable */
1447 link_status = STATUS_DOWN;
1450 led_on(sc, MII16_SSI_LED_LL);
1452 /* The unit at the other end of the cable is ready if: */
1453 /* DTE mode and DCD pin is asserted */
1454 /* DCE mode and DSR pin is asserted */
1455 if (((sc->config.dte_dce == CFG_DTE) && ((mii16 & MII16_SSI_DCD)==0)) ||
1456 ((sc->config.dte_dce == CFG_DCE) && ((mii16 & MII16_SSI_DSR)==0)))
1458 led_off(sc, MII16_SSI_LED_LR);
1459 link_status = STATUS_DOWN;
1462 led_on(sc, MII16_SSI_LED_LR);
1464 if (DRIVER_DEBUG && (cable != sc->status.cable_type))
1465 printf("%s: SSI cable type changed to '%s'\n",
1466 NAME_UNIT, ssi_cables[cable]);
1467 sc->status.cable_type = cable;
1469 /* Print the modem control signals if they changed. */
1470 if ((DRIVER_DEBUG) && (mii16 != sc->last_mii16))
1472 char *on = "ON ", *off = "OFF";
1473 printf("%s: DTR=%s DSR=%s RTS=%s CTS=%s DCD=%s RI=%s LL=%s RL=%s TM=%s\n",
1475 (mii16 & MII16_SSI_DTR) ? on : off,
1476 (mii16 & MII16_SSI_DSR) ? on : off,
1477 (mii16 & MII16_SSI_RTS) ? on : off,
1478 (mii16 & MII16_SSI_CTS) ? on : off,
1479 (mii16 & MII16_SSI_DCD) ? on : off,
1480 (mii16 & MII16_SSI_RI) ? on : off,
1481 (mii16 & MII16_SSI_LL) ? on : off,
1482 (mii16 & MII16_SSI_RL) ? on : off,
1483 (mii16 & MII16_SSI_TM) ? on : off);
1486 /* SNMP one-second report */
1487 sc->status.snmp.ssi.sigs = mii16 & MII16_SSI_MODEM;
1489 /* Remember this state until next time. */
1490 sc->last_mii16 = mii16;
1492 /* If a loop back is in effect, link status is UP */
1493 if (sc->config.loop_back != CFG_LOOP_NONE)
1494 link_status = STATUS_UP;
1499 /* IOCTL SYSCALL: can sleep (but doesn't). */
1501 ssi_ioctl(softc_t *sc, struct ioctl *ioctl)
1505 if (ioctl->cmd == IOCTL_SNMP_SIGS)
1507 u_int16_t mii16 = read_mii(sc, 16);
1508 mii16 &= ~MII16_SSI_MODEM;
1509 mii16 |= (MII16_SSI_MODEM & ioctl->data);
1510 write_mii(sc, 16, mii16);
1512 else if (ioctl->cmd == IOCTL_SET_STATUS)
1514 if (ioctl->data != 0)
1515 set_mii16_bits(sc, (MII16_SSI_DTR | MII16_SSI_RTS | MII16_SSI_DCD));
1517 clr_mii16_bits(sc, (MII16_SSI_DTR | MII16_SSI_RTS | MII16_SSI_DCD));
1525 /* begin T1E1 card code */
1527 /* Must not sleep. */
1529 t1_config(softc_t *sc)
1532 u_int8_t pulse, lbo, gain;
1534 if (sc->status.card_type == 0)
1536 sc->status.card_type = TLP_CSID_T1E1;
1537 sc->config.crc_len = CFG_CRC_16;
1538 sc->config.loop_back = CFG_LOOP_NONE;
1539 sc->config.tx_clk_src = CFG_CLKMUX_INT;
1540 sc->config.format = CFG_FORMAT_T1ESF;
1541 sc->config.cable_len = 10;
1542 sc->config.time_slots = 0x01FFFFFE;
1543 sc->config.tx_pulse = CFG_PULSE_AUTO;
1544 sc->config.rx_gain = CFG_GAIN_AUTO;
1545 sc->config.tx_lbo = CFG_LBO_AUTO;
1547 /* Bt8370 occasionally powers up in a loopback mode. */
1548 /* Data sheet says zero LOOP reg and do a s/w reset. */
1549 write_framer(sc, Bt8370_LOOP, 0x00); /* no loopback */
1550 write_framer(sc, Bt8370_CR0, 0x80); /* s/w reset */
1551 for (i=0; i<10; i++) /* max delay 10 ms */
1552 if (read_framer(sc, Bt8370_CR0) & 0x80) DELAY(1000);
1555 /* Set CRC length. */
1556 if (sc->config.crc_len == CFG_CRC_32)
1557 set_mii16_bits(sc, MII16_T1_CRC32);
1559 clr_mii16_bits(sc, MII16_T1_CRC32);
1561 /* Invert HDLC payload data in SF/AMI mode. */
1562 /* HDLC stuff bits satisfy T1 pulse density. */
1564 set_mii16_bits(sc, MII16_T1_INVERT);
1566 clr_mii16_bits(sc, MII16_T1_INVERT);
1568 /* Set the transmitter output impedance. */
1569 if (FORMAT_E1ANY) set_mii16_bits(sc, MII16_T1_Z);
1571 /* 001:CR0 -- Control Register 0 - T1/E1 and frame format */
1572 write_framer(sc, Bt8370_CR0, sc->config.format);
1574 /* 002:JAT_CR -- Jitter Attenuator Control Register */
1575 if (sc->config.tx_clk_src == CFG_CLKMUX_RT) /* loop timing */
1576 write_framer(sc, Bt8370_JAT_CR, 0xA3); /* JAT in RX path */
1578 { /* 64-bit elastic store; free-running JCLK and CLADO */
1579 write_framer(sc, Bt8370_JAT_CR, 0x4B); /* assert jcenter */
1580 write_framer(sc, Bt8370_JAT_CR, 0x43); /* release jcenter */
1583 /* 00C-013:IERn -- Interrupt Enable Registers */
1584 for (i=Bt8370_IER7; i<=Bt8370_IER0; i++)
1585 write_framer(sc, i, 0); /* no interrupts; polled */
1587 /* 014:LOOP -- loopbacks */
1588 if (sc->config.loop_back == CFG_LOOP_PAYLOAD)
1589 write_framer(sc, Bt8370_LOOP, LOOP_PAYLOAD);
1590 else if (sc->config.loop_back == CFG_LOOP_LINE)
1591 write_framer(sc, Bt8370_LOOP, LOOP_LINE);
1592 else if (sc->config.loop_back == CFG_LOOP_OTHER)
1593 write_framer(sc, Bt8370_LOOP, LOOP_ANALOG);
1594 else if (sc->config.loop_back == CFG_LOOP_INWARD)
1595 write_framer(sc, Bt8370_LOOP, LOOP_FRAMER);
1596 else if (sc->config.loop_back == CFG_LOOP_DUAL)
1597 write_framer(sc, Bt8370_LOOP, LOOP_DUAL);
1599 write_framer(sc, Bt8370_LOOP, 0x00); /* no loopback */
1601 /* 015:DL3_TS -- Data Link 3 */
1602 write_framer(sc, Bt8370_DL3_TS, 0x00); /* disabled */
1604 /* 018:PIO -- Programmable I/O */
1605 write_framer(sc, Bt8370_PIO, 0xFF); /* all pins are outputs */
1607 /* 019:POE -- Programmable Output Enable */
1608 write_framer(sc, Bt8370_POE, 0x00); /* all outputs are enabled */
1610 /* 01A;CMUX -- Clock Input Mux */
1611 if (sc->config.tx_clk_src == CFG_CLKMUX_EXT)
1612 write_framer(sc, Bt8370_CMUX, 0x0C); /* external timing */
1614 write_framer(sc, Bt8370_CMUX, 0x0F); /* internal timing */
1616 /* 020:LIU_CR -- Line Interface Unit Config Register */
1617 write_framer(sc, Bt8370_LIU_CR, 0xC1); /* reset LIU, squelch */
1619 /* 022:RLIU_CR -- RX Line Interface Unit Config Reg */
1620 /* Errata sheet says don't use freeze-short, but we do anyway! */
1621 write_framer(sc, Bt8370_RLIU_CR, 0xB1); /* AGC=2048, Long Eye */
1623 /* Select Rx sensitivity based on cable length. */
1624 if ((gain = sc->config.rx_gain) == CFG_GAIN_AUTO)
1626 if (sc->config.cable_len > 2000)
1627 gain = CFG_GAIN_EXTEND;
1628 else if (sc->config.cable_len > 1000)
1629 gain = CFG_GAIN_LONG;
1630 else if (sc->config.cable_len > 100)
1631 gain = CFG_GAIN_MEDIUM;
1633 gain = CFG_GAIN_SHORT;
1636 /* 024:VGA_MAX -- Variable Gain Amplifier Max gain */
1637 write_framer(sc, Bt8370_VGA_MAX, gain);
1639 /* 028:PRE_EQ -- Pre Equalizer */
1640 if (gain == CFG_GAIN_EXTEND)
1641 write_framer(sc, Bt8370_PRE_EQ, 0xE6); /* ON; thresh 6 */
1643 write_framer(sc, Bt8370_PRE_EQ, 0xA6); /* OFF; thresh 6 */
1645 /* 038-03C:GAINn -- RX Equalizer gain thresholds */
1646 write_framer(sc, Bt8370_GAIN0, 0x24);
1647 write_framer(sc, Bt8370_GAIN1, 0x28);
1648 write_framer(sc, Bt8370_GAIN2, 0x2C);
1649 write_framer(sc, Bt8370_GAIN3, 0x30);
1650 write_framer(sc, Bt8370_GAIN4, 0x34);
1652 /* 040:RCR0 -- Receiver Control Register 0 */
1654 write_framer(sc, Bt8370_RCR0, 0x05); /* B8ZS, 2/5 FErrs */
1655 else if (FORMAT_T1SF)
1656 write_framer(sc, Bt8370_RCR0, 0x84); /* AMI, 2/5 FErrs */
1657 else if (FORMAT_E1NONE)
1658 write_framer(sc, Bt8370_RCR0, 0x41); /* HDB3, rabort */
1659 else if (FORMAT_E1CRC)
1660 write_framer(sc, Bt8370_RCR0, 0x09); /* HDB3, 3 FErrs or 915 CErrs */
1661 else /* E1 no CRC */
1662 write_framer(sc, Bt8370_RCR0, 0x19); /* HDB3, 3 FErrs */
1664 /* 041:RPATT -- Receive Test Pattern configuration */
1665 write_framer(sc, Bt8370_RPATT, 0x3E); /* looking for framed QRSS */
1667 /* 042:RLB -- Receive Loop Back code detector config */
1668 write_framer(sc, Bt8370_RLB, 0x09); /* 6 bits down; 5 bits up */
1670 /* 043:LBA -- Loop Back Activate code */
1671 write_framer(sc, Bt8370_LBA, 0x08); /* 10000 10000 10000 ... */
1673 /* 044:LBD -- Loop Back Deactivate code */
1674 write_framer(sc, Bt8370_LBD, 0x24); /* 100100 100100 100100 ... */
1676 /* 045:RALM -- Receive Alarm signal configuration */
1677 write_framer(sc, Bt8370_RALM, 0x0C); /* yel_intg rlof_intg */
1679 /* 046:LATCH -- Alarm/Error/Counter Latch register */
1680 write_framer(sc, Bt8370_LATCH, 0x1F); /* stop_cnt latch_{cnt,err,alm} */
1682 /* Select Pulse Shape based on cable length (T1 only). */
1683 if ((pulse = sc->config.tx_pulse) == CFG_PULSE_AUTO)
1687 if (sc->config.cable_len > 200)
1688 pulse = CFG_PULSE_T1CSU;
1689 else if (sc->config.cable_len > 160)
1690 pulse = CFG_PULSE_T1DSX4;
1691 else if (sc->config.cable_len > 120)
1692 pulse = CFG_PULSE_T1DSX3;
1693 else if (sc->config.cable_len > 80)
1694 pulse = CFG_PULSE_T1DSX2;
1695 else if (sc->config.cable_len > 40)
1696 pulse = CFG_PULSE_T1DSX1;
1698 pulse = CFG_PULSE_T1DSX0;
1701 pulse = CFG_PULSE_E1TWIST;
1704 /* Select Line Build Out based on cable length (T1CSU only). */
1705 if ((lbo = sc->config.tx_lbo) == CFG_LBO_AUTO)
1707 if (pulse == CFG_PULSE_T1CSU)
1709 if (sc->config.cable_len > 1500)
1711 else if (sc->config.cable_len > 1000)
1713 else if (sc->config.cable_len > 500)
1722 /* 068:TLIU_CR -- Transmit LIU Control Register */
1723 write_framer(sc, Bt8370_TLIU_CR, (0x40 | (lbo & 0x30) | (pulse & 0x0E)));
1725 /* 070:TCR0 -- Transmit Framer Configuration */
1726 write_framer(sc, Bt8370_TCR0, sc->config.format>>1);
1728 /* 071:TCR1 -- Transmitter Configuration */
1730 write_framer(sc, Bt8370_TCR1, 0x43); /* tabort, AMI PDV enforced */
1732 write_framer(sc, Bt8370_TCR1, 0x41); /* tabort, B8ZS or HDB3 */
1734 /* 072:TFRM -- Transmit Frame format MYEL YEL MF FE CRC FBIT */
1735 if (sc->config.format == CFG_FORMAT_T1ESF)
1736 write_framer(sc, Bt8370_TFRM, 0x0B); /* - YEL MF - CRC FBIT */
1737 else if (sc->config.format == CFG_FORMAT_T1SF)
1738 write_framer(sc, Bt8370_TFRM, 0x19); /* - YEL MF - - FBIT */
1739 else if (sc->config.format == CFG_FORMAT_E1FAS)
1740 write_framer(sc, Bt8370_TFRM, 0x11); /* - YEL - - - FBIT */
1741 else if (sc->config.format == CFG_FORMAT_E1FASCRC)
1742 write_framer(sc, Bt8370_TFRM, 0x1F); /* - YEL MF FE CRC FBIT */
1743 else if (sc->config.format == CFG_FORMAT_E1FASCAS)
1744 write_framer(sc, Bt8370_TFRM, 0x31); /* MYEL YEL - - - FBIT */
1745 else if (sc->config.format == CFG_FORMAT_E1FASCRCCAS)
1746 write_framer(sc, Bt8370_TFRM, 0x3F); /* MYEL YEL MF FE CRC FBIT */
1747 else if (sc->config.format == CFG_FORMAT_E1NONE)
1748 write_framer(sc, Bt8370_TFRM, 0x00); /* NO FRAMING BITS AT ALL! */
1750 /* 073:TERROR -- Transmit Error Insert */
1751 write_framer(sc, Bt8370_TERROR, 0x00); /* no errors, please! */
1753 /* 074:TMAN -- Transmit Manual Sa-byte/FEBE configuration */
1754 write_framer(sc, Bt8370_TMAN, 0x00); /* none */
1756 /* 075:TALM -- Transmit Alarm Signal Configuration */
1758 write_framer(sc, Bt8370_TALM, 0x38); /* auto_myel auto_yel auto_ais */
1759 else if (FORMAT_T1ANY)
1760 write_framer(sc, Bt8370_TALM, 0x18); /* auto_yel auto_ais */
1762 /* 076:TPATT -- Transmit Test Pattern Configuration */
1763 write_framer(sc, Bt8370_TPATT, 0x00); /* disabled */
1765 /* 077:TLB -- Transmit Inband Loopback Code Configuration */
1766 write_framer(sc, Bt8370_TLB, 0x00); /* disabled */
1768 /* 090:CLAD_CR -- Clack Rate Adapter Configuration */
1770 write_framer(sc, Bt8370_CLAD_CR, 0x06); /* loop filter gain 1/2^6 */
1772 write_framer(sc, Bt8370_CLAD_CR, 0x08); /* loop filter gain 1/2^8 */
1774 /* 091:CSEL -- CLAD frequency Select */
1776 write_framer(sc, Bt8370_CSEL, 0x55); /* 1544 kHz */
1778 write_framer(sc, Bt8370_CSEL, 0x11); /* 2048 kHz */
1780 /* 092:CPHASE -- CLAD Phase detector */
1782 write_framer(sc, Bt8370_CPHASE, 0x22); /* phase compare @ 386 kHz */
1784 write_framer(sc, Bt8370_CPHASE, 0x00); /* phase compare @ 2048 kHz */
1786 if (FORMAT_T1ESF) /* BOP & PRM are enabled in T1ESF mode only. */
1788 /* 0A0:BOP -- Bit Oriented Protocol messages */
1789 write_framer(sc, Bt8370_BOP, RBOP_25 | TBOP_OFF);
1790 /* 0A4:DL1_TS -- Data Link 1 Time Slot Enable */
1791 write_framer(sc, Bt8370_DL1_TS, 0x40); /* FDL bits in odd frames */
1792 /* 0A6:DL1_CTL -- Data Link 1 Control */
1793 write_framer(sc, Bt8370_DL1_CTL, 0x03); /* FCS mode, TX on, RX on */
1794 /* 0A7:RDL1_FFC -- Rx Data Link 1 Fifo Fill Control */
1795 write_framer(sc, Bt8370_RDL1_FFC, 0x30); /* assert "near full" at 48 */
1796 /* 0AA:PRM -- Performance Report Messages */
1797 write_framer(sc, Bt8370_PRM, 0x80);
1800 /* 0D0:SBI_CR -- System Bus Interface Configuration Register */
1802 write_framer(sc, Bt8370_SBI_CR, 0x47); /* 1.544 with 24 TS +Fbits */
1804 write_framer(sc, Bt8370_SBI_CR, 0x46); /* 2.048 with 32 TS */
1806 /* 0D1:RSB_CR -- Receive System Bus Configuration Register */
1807 /* Change RINDO & RFSYNC on falling edge of RSBCLKI. */
1808 write_framer(sc, Bt8370_RSB_CR, 0x70);
1810 /* 0D2,0D3:RSYNC_{TS,BIT} -- Receive frame Sync offset */
1811 write_framer(sc, Bt8370_RSYNC_BIT, 0x00);
1812 write_framer(sc, Bt8370_RSYNC_TS, 0x00);
1814 /* 0D4:TSB_CR -- Transmit System Bus Configuration Register */
1815 /* Change TINDO & TFSYNC on falling edge of TSBCLKI. */
1816 write_framer(sc, Bt8370_TSB_CR, 0x30);
1818 /* 0D5,0D6:TSYNC_{TS,BIT} -- Transmit frame Sync offset */
1819 write_framer(sc, Bt8370_TSYNC_BIT, 0x00);
1820 write_framer(sc, Bt8370_TSYNC_TS, 0x00);
1822 /* 0D7:RSIG_CR -- Receive SIGnalling Configuratin Register */
1823 write_framer(sc, Bt8370_RSIG_CR, 0x00);
1825 /* Assign and configure 64Kb TIME SLOTS. */
1826 /* TS24..TS1 must be assigned for T1, TS31..TS0 for E1. */
1827 /* Timeslots with no user data have RINDO and TINDO off. */
1828 for (i=0; i<32; i++)
1830 /* 0E0-0FF:SBCn -- System Bus Per-Channel Control */
1831 if (FORMAT_T1ANY && (i==0 || i>24))
1832 write_framer(sc, Bt8370_SBCn +i, 0x00); /* not assigned in T1 mode */
1833 else if (FORMAT_E1ANY && (i==0) && !FORMAT_E1NONE)
1834 write_framer(sc, Bt8370_SBCn +i, 0x01); /* assigned, TS0 o/h bits */
1835 else if (FORMAT_E1CAS && (i==16) && !FORMAT_E1NONE)
1836 write_framer(sc, Bt8370_SBCn +i, 0x01); /* assigned, TS16 o/h bits */
1837 else if ((sc->config.time_slots & (1<<i)) != 0)
1838 write_framer(sc, Bt8370_SBCn +i, 0x0D); /* assigned, RINDO, TINDO */
1840 write_framer(sc, Bt8370_SBCn +i, 0x01); /* assigned, idle */
1842 /* 100-11F:TPCn -- Transmit Per-Channel Control */
1843 if (FORMAT_E1CAS && (i==0))
1844 write_framer(sc, Bt8370_TPCn +i, 0x30); /* tidle, sig=0000 (MAS) */
1845 else if (FORMAT_E1CAS && (i==16))
1846 write_framer(sc, Bt8370_TPCn +i, 0x3B); /* tidle, sig=1011 (XYXX) */
1847 else if ((sc->config.time_slots & (1<<i)) == 0)
1848 write_framer(sc, Bt8370_TPCn +i, 0x20); /* tidle: use TSLIP_LOn */
1850 write_framer(sc, Bt8370_TPCn +i, 0x00); /* nothing special */
1852 /* 140-15F:TSLIP_LOn -- Transmit PCM Slip Buffer */
1853 write_framer(sc, Bt8370_TSLIP_LOn +i, 0x7F); /* idle chan data */
1854 /* 180-19F:RPCn -- Receive Per-Channel Control */
1855 write_framer(sc, Bt8370_RPCn +i, 0x00); /* nothing special */
1858 /* Enable transmitter output drivers. */
1859 set_mii16_bits(sc, MII16_T1_XOE);
1863 t1_ident(softc_t *sc)
1865 printf(", Bt837%x rev %x",
1866 read_framer(sc, Bt8370_DID)>>4,
1867 read_framer(sc, Bt8370_DID)&0x0F);
1870 /* Called once a second; must not sleep. */
1872 t1_watchdog(softc_t *sc)
1874 u_int16_t LCV = 0, FERR = 0, CRC = 0, FEBE = 0;
1875 u_int8_t alm1, alm3, loop, isr0;
1876 int link_status = STATUS_UP;
1879 /* Read the alarm registers */
1880 alm1 = read_framer(sc, Bt8370_ALM1);
1881 alm3 = read_framer(sc, Bt8370_ALM3);
1882 loop = read_framer(sc, Bt8370_LOOP);
1883 isr0 = read_framer(sc, Bt8370_ISR0);
1885 /* Always ignore the SIGFRZ alarm bit, */
1886 alm1 &= ~ALM1_SIGFRZ;
1887 if (FORMAT_T1ANY) /* ignore RYEL in T1 modes */
1889 else if (FORMAT_E1NONE) /* ignore all alarms except LOS */
1892 /* Software is alive. */
1893 led_inv(sc, MII16_T1_LED_GRN);
1895 /* Receiving Alarm Indication Signal (AIS). */
1896 if ((alm1 & ALM1_RAIS)!=0) /* receiving ais */
1897 led_on(sc, MII16_T1_LED_BLU);
1898 else if ((alm1 & ALM1_RLOS)!=0) /* sending ais */
1899 led_inv(sc, MII16_T1_LED_BLU);
1901 led_off(sc, MII16_T1_LED_BLU);
1903 /* Receiving Remote Alarm Indication (RAI). */
1904 if ((alm1 & (ALM1_RMYEL | ALM1_RYEL))!=0) /* receiving rai */
1905 led_on(sc, MII16_T1_LED_YEL);
1906 else if ((alm1 & ALM1_RLOF)!=0) /* sending rai */
1907 led_inv(sc, MII16_T1_LED_YEL);
1909 led_off(sc, MII16_T1_LED_YEL);
1911 /* If any alarm bits are set then the link is 'down'. */
1912 /* The bad bits are: rmyel ryel rais ralos rlos rlof. */
1913 /* Some alarm bits have been masked by this point. */
1914 if (alm1 != 0) link_status = STATUS_DOWN;
1916 /* Declare local Red Alarm if the link is down. */
1917 if (link_status == STATUS_DOWN)
1918 led_on(sc, MII16_T1_LED_RED);
1919 else if (sc->loop_timer != 0) /* loopback is active */
1920 led_inv(sc, MII16_T1_LED_RED);
1922 led_off(sc, MII16_T1_LED_RED);
1924 /* Print latched error bits if they changed. */
1925 if ((DRIVER_DEBUG) && (alm1 != sc->last_alm1))
1927 char *on = "ON ", *off = "OFF";
1928 printf("%s: RLOF=%s RLOS=%s RALOS=%s RAIS=%s RYEL=%s RMYEL=%s\n",
1930 (alm1 & ALM1_RLOF) ? on : off,
1931 (alm1 & ALM1_RLOS) ? on : off,
1932 (alm1 & ALM1_RALOS) ? on : off,
1933 (alm1 & ALM1_RAIS) ? on : off,
1934 (alm1 & ALM1_RYEL) ? on : off,
1935 (alm1 & ALM1_RMYEL) ? on : off);
1938 /* Check and print error counters if non-zero. */
1939 LCV = read_framer(sc, Bt8370_LCV_LO) +
1940 (read_framer(sc, Bt8370_LCV_HI)<<8);
1942 FERR = read_framer(sc, Bt8370_FERR_LO) +
1943 (read_framer(sc, Bt8370_FERR_HI)<<8);
1944 if (FORMAT_E1CRC || FORMAT_T1ESF)
1945 CRC = read_framer(sc, Bt8370_CRC_LO) +
1946 (read_framer(sc, Bt8370_CRC_HI)<<8);
1948 FEBE = read_framer(sc, Bt8370_FEBE_LO) +
1949 (read_framer(sc, Bt8370_FEBE_HI)<<8);
1950 /* Only LCV is valid if Out-Of-Frame */
1951 if (FORMAT_E1NONE) FERR = CRC = FEBE = 0;
1952 if ((DRIVER_DEBUG) && (LCV || FERR || CRC || FEBE))
1953 printf("%s: LCV=%u FERR=%u CRC=%u FEBE=%u\n",
1954 NAME_UNIT, LCV, FERR, CRC, FEBE);
1956 /* Driver keeps crude link-level error counters (SNMP is better). */
1957 sc->status.cntrs.lcv_errs += LCV;
1958 sc->status.cntrs.frm_errs += FERR;
1959 sc->status.cntrs.crc_errs += CRC;
1960 sc->status.cntrs.febe_errs += FEBE;
1962 /* Check for BOP messages in the ESF Facility Data Link. */
1963 if ((FORMAT_T1ESF) && (read_framer(sc, Bt8370_ISR1) & 0x80))
1965 u_int8_t bop_code = read_framer(sc, Bt8370_RBOP) & 0x3F;
1971 if ((DRIVER_DEBUG) && ((sc->last_alm1 & ALM1_RMYEL)==0))
1972 printf("%s: Receiving a 'yellow alarm' BOP msg\n", NAME_UNIT);
1978 printf("%s: Received a 'line loopback activate' BOP msg\n", NAME_UNIT);
1979 write_framer(sc, Bt8370_LOOP, LOOP_LINE);
1980 sc->loop_timer = 305;
1983 case T1BOP_LINE_DOWN:
1986 printf("%s: Received a 'line loopback deactivate' BOP msg\n", NAME_UNIT);
1987 write_framer(sc, Bt8370_LOOP,
1988 read_framer(sc, Bt8370_LOOP) & ~LOOP_LINE);
1995 printf("%s: Received a 'payload loopback activate' BOP msg\n", NAME_UNIT);
1996 write_framer(sc, Bt8370_LOOP, LOOP_PAYLOAD);
1997 sc->loop_timer = 305;
2000 case T1BOP_PAY_DOWN:
2003 printf("%s: Received a 'payload loopback deactivate' BOP msg\n", NAME_UNIT);
2004 write_framer(sc, Bt8370_LOOP,
2005 read_framer(sc, Bt8370_LOOP) & ~LOOP_PAYLOAD);
2012 printf("%s: Received a type 0x%02X BOP msg\n", NAME_UNIT, bop_code);
2018 /* Check for HDLC pkts in the ESF Facility Data Link. */
2019 if ((FORMAT_T1ESF) && (read_framer(sc, Bt8370_ISR2) & 0x70))
2021 /* while (not fifo-empty && not start-of-msg) flush fifo */
2022 while ((read_framer(sc, Bt8370_RDL1_STAT) & 0x0C) == 0)
2023 read_framer(sc, Bt8370_RDL1);
2024 /* If (not fifo-empty), then begin processing fifo contents. */
2025 if ((read_framer(sc, Bt8370_RDL1_STAT) & 0x0C) == 0x08)
2028 u_int8_t stat = read_framer(sc, Bt8370_RDL1);
2029 sc->status.cntrs.fdl_pkts++;
2030 for (i=0; i<(stat & 0x3F); i++)
2031 msg[i] = read_framer(sc, Bt8370_RDL1);
2032 /* Is this FDL message a T1.403 performance report? */
2033 if (((stat & 0x3F)==11) &&
2034 ((msg[0]==0x38) || (msg[0]==0x3A)) &&
2035 (msg[1]==1) && (msg[2]==3))
2036 /* Copy 4 PRs from FDL pkt to SNMP struct. */
2037 memcpy(sc->status.snmp.t1.prm, msg+3, 8);
2041 /* Check for inband loop up/down commands. */
2044 u_int8_t isr6 = read_framer(sc, Bt8370_ISR6);
2045 u_int8_t alarm2 = read_framer(sc, Bt8370_ALM2);
2046 u_int8_t tlb = read_framer(sc, Bt8370_TLB);
2048 /* Inband Code == Loop Up && On Transition && Inband Tx Inactive */
2049 if ((isr6 & 0x40) && (alarm2 & 0x40) && ((tlb & 1)==0))
2050 { /* CSU loop up is 10000 10000 ... */
2052 printf("%s: Received a 'CSU Loop Up' inband msg\n", NAME_UNIT);
2053 write_framer(sc, Bt8370_LOOP, LOOP_LINE); /* Loop up */
2054 sc->loop_timer = 305;
2056 /* Inband Code == Loop Down && On Transition && Inband Tx Inactive */
2057 if ((isr6 & 0x80) && (alarm2 & 0x80) && ((tlb & 1)==0))
2058 { /* CSU loop down is 100 100 100 ... */
2060 printf("%s: Received a 'CSU Loop Down' inband msg\n", NAME_UNIT);
2061 write_framer(sc, Bt8370_LOOP,
2062 read_framer(sc, Bt8370_LOOP) & ~LOOP_LINE); /* loop down */
2067 /* Manually send Yellow Alarm BOP msgs. */
2070 u_int8_t isr7 = read_framer(sc, Bt8370_ISR7);
2072 if ((isr7 & 0x02) && (alm1 & 0x02)) /* RLOF on-transition */
2073 { /* Start sending continuous Yellow Alarm BOP messages. */
2074 write_framer(sc, Bt8370_BOP, RBOP_25 | TBOP_CONT);
2075 write_framer(sc, Bt8370_TBOP, 0x00); /* send BOP; order matters */
2077 else if ((isr7 & 0x02) && ((alm1 & 0x02)==0)) /* RLOF off-transition */
2078 { /* Stop sending continuous Yellow Alarm BOP messages. */
2079 write_framer(sc, Bt8370_BOP, RBOP_25 | TBOP_OFF);
2083 /* Time out loopback requests. */
2084 if (sc->loop_timer != 0)
2085 if (--sc->loop_timer == 0)
2089 printf("%s: Timeout: Loop Down after 300 seconds\n", NAME_UNIT);
2090 write_framer(sc, Bt8370_LOOP, loop & ~(LOOP_PAYLOAD | LOOP_LINE));
2093 /* RX Test Pattern status */
2094 if ((DRIVER_DEBUG) && (isr0 & 0x10))
2095 printf("%s: RX Test Pattern Sync\n", NAME_UNIT);
2097 /* SNMP Error Counters */
2098 sc->status.snmp.t1.lcv = LCV;
2099 sc->status.snmp.t1.fe = FERR;
2100 sc->status.snmp.t1.crc = CRC;
2101 sc->status.snmp.t1.febe = FEBE;
2103 /* SNMP Line Status */
2104 sc->status.snmp.t1.line = 0;
2105 if (alm1 & ALM1_RMYEL) sc->status.snmp.t1.line |= TLINE_RX_RAI;
2106 if (alm1 & ALM1_RYEL) sc->status.snmp.t1.line |= TLINE_RX_RAI;
2107 if (alm1 & ALM1_RLOF) sc->status.snmp.t1.line |= TLINE_TX_RAI;
2108 if (alm1 & ALM1_RAIS) sc->status.snmp.t1.line |= TLINE_RX_AIS;
2109 if (alm1 & ALM1_RLOS) sc->status.snmp.t1.line |= TLINE_TX_AIS;
2110 if (alm1 & ALM1_RLOF) sc->status.snmp.t1.line |= TLINE_LOF;
2111 if (alm1 & ALM1_RLOS) sc->status.snmp.t1.line |= TLINE_LOS;
2112 if (alm3 & ALM3_RMAIS) sc->status.snmp.t1.line |= T1LINE_RX_TS16_AIS;
2113 if (alm3 & ALM3_SRED) sc->status.snmp.t1.line |= T1LINE_TX_TS16_LOMF;
2114 if (alm3 & ALM3_SEF) sc->status.snmp.t1.line |= T1LINE_SEF;
2115 if (isr0 & 0x10) sc->status.snmp.t1.line |= T1LINE_RX_TEST;
2116 if ((alm1 & ALM1_RMYEL) && (FORMAT_E1CAS))
2117 sc->status.snmp.t1.line |= T1LINE_RX_TS16_LOMF;
2119 /* SNMP Loopback Status */
2120 sc->status.snmp.t1.loop &= ~(TLOOP_FAR_LINE | TLOOP_FAR_PAYLOAD);
2121 if (sc->config.loop_back == CFG_LOOP_TULIP)
2122 sc->status.snmp.t1.loop |= TLOOP_NEAR_OTHER;
2123 if (loop & LOOP_PAYLOAD) sc->status.snmp.t1.loop |= TLOOP_NEAR_PAYLOAD;
2124 if (loop & LOOP_LINE) sc->status.snmp.t1.loop |= TLOOP_NEAR_LINE;
2125 if (loop & LOOP_ANALOG) sc->status.snmp.t1.loop |= TLOOP_NEAR_OTHER;
2126 if (loop & LOOP_FRAMER) sc->status.snmp.t1.loop |= TLOOP_NEAR_INWARD;
2128 /* Remember this state until next time. */
2129 sc->last_alm1 = alm1;
2131 /* If an INWARD loopback is in effect, link status is UP */
2132 if (sc->config.loop_back != CFG_LOOP_NONE) /* XXX INWARD ONLY */
2133 link_status = STATUS_UP;
2138 /* IOCTL SYSCALL: can sleep. */
2140 t1_send_bop(softc_t *sc, int bop_code)
2145 /* The BOP transmitter could be sending a continuous */
2146 /* BOP msg when told to send this BOP_25 message. */
2147 /* So save and restore the state of the BOP machine. */
2148 bop = read_framer(sc, Bt8370_BOP);
2149 write_framer(sc, Bt8370_BOP, RBOP_OFF | TBOP_OFF);
2150 for (i=0; i<40; i++) /* max delay 400 ms. */
2151 if (read_framer(sc, Bt8370_BOP_STAT) & 0x80) SLEEP(10000);
2152 /* send 25 repetitions of bop_code */
2153 write_framer(sc, Bt8370_BOP, RBOP_OFF | TBOP_25);
2154 write_framer(sc, Bt8370_TBOP, bop_code); /* order matters */
2155 /* wait for tx to stop */
2156 for (i=0; i<40; i++) /* max delay 400 ms. */
2157 if (read_framer(sc, Bt8370_BOP_STAT) & 0x80) SLEEP(10000);
2158 /* Restore previous state of the BOP machine. */
2159 write_framer(sc, Bt8370_BOP, bop);
2162 /* IOCTL SYSCALL: can sleep. */
2164 t1_ioctl(softc_t *sc, struct ioctl *ioctl)
2170 case IOCTL_SNMP_SEND: /* set opstatus? */
2172 switch (ioctl->data)
2176 write_framer(sc, Bt8370_TPATT, 0x00); /* tx pattern generator off */
2177 write_framer(sc, Bt8370_RPATT, 0x00); /* rx pattern detector off */
2178 write_framer(sc, Bt8370_TLB, 0x00); /* tx inband generator off */
2184 t1_send_bop(sc, T1BOP_LINE_UP);
2185 else if (FORMAT_T1SF)
2187 write_framer(sc, Bt8370_LBP, 0x08); /* 10000 10000 ... */
2188 write_framer(sc, Bt8370_TLB, 0x05); /* 5 bits, framed, start */
2190 sc->status.snmp.t1.loop |= TLOOP_FAR_LINE;
2195 t1_send_bop(sc, T1BOP_PAY_UP);
2196 sc->status.snmp.t1.loop |= TLOOP_FAR_PAYLOAD;
2201 if (sc->status.snmp.t1.loop == TLOOP_FAR_LINE)
2204 t1_send_bop(sc, T1BOP_LINE_DOWN);
2205 else if (FORMAT_T1SF)
2207 write_framer(sc, Bt8370_LBP, 0x24); /* 100100 100100 ... */
2208 write_framer(sc, Bt8370_TLB, 0x09); /* 6 bits, framed, start */
2210 sc->status.snmp.t1.loop &= ~TLOOP_FAR_LINE;
2212 if (sc->status.snmp.t1.loop == TLOOP_FAR_PAYLOAD)
2214 t1_send_bop(sc, T1BOP_PAY_DOWN);
2215 sc->status.snmp.t1.loop &= ~TLOOP_FAR_PAYLOAD;
2221 write_framer(sc, Bt8370_TPATT, 0x1E); /* framed QRSS */
2232 case IOCTL_SNMP_LOOP: /* set opstatus = test? */
2234 u_int8_t new_loop = 0;
2236 if (ioctl->data == CFG_LOOP_NONE)
2238 else if (ioctl->data == CFG_LOOP_PAYLOAD)
2239 new_loop = LOOP_PAYLOAD;
2240 else if (ioctl->data == CFG_LOOP_LINE)
2241 new_loop = LOOP_LINE;
2242 else if (ioctl->data == CFG_LOOP_OTHER)
2243 new_loop = LOOP_ANALOG;
2244 else if (ioctl->data == CFG_LOOP_INWARD)
2245 new_loop = LOOP_FRAMER;
2246 else if (ioctl->data == CFG_LOOP_DUAL)
2247 new_loop = LOOP_DUAL;
2252 write_framer(sc, Bt8370_LOOP, new_loop);
2253 sc->config.loop_back = ioctl->data;
2266 struct card hssi_card =
2268 .config = hssi_config,
2269 .ident = hssi_ident,
2270 .watchdog = hssi_watchdog,
2271 .ioctl = hssi_ioctl,
2275 struct card t3_card =
2277 .config = t3_config,
2279 .watchdog = t3_watchdog,
2284 struct card ssi_card =
2286 .config = ssi_config,
2288 .watchdog = ssi_watchdog,
2293 struct card t1_card =
2295 .config = t1_config,
2297 .watchdog = t1_watchdog,
2301 /* RAWIP is raw IP packets (v4 or v6) in HDLC frames with NO HEADERS. */
2302 /* No HDLC Address/Control fields! No line control protocol at all! */
2304 /* rxintr_cleanup calls this to give a newly arrived pkt to higher levels. */
2306 lmc_raw_input(struct ifnet *ifp, struct mbuf *mbuf)
2308 softc_t *sc = IFP2SC(ifp);
2310 M_SETFIB(mbuf, ifp->if_fib);
2312 if (mbuf->m_data[0]>>4 == 4)
2313 netisr_dispatch(NETISR_IP, mbuf);
2317 if (mbuf->m_data[0]>>4 == 6)
2318 netisr_dispatch(NETISR_IPV6, mbuf);
2323 sc->status.cntrs.idiscards++;
2325 printf("%s: lmc_raw_input: rx pkt discarded: not IPv4 or IPv6\n",
2331 * We are "standing on the head of a pin" in these routines.
2332 * Tulip CSRs can be accessed, but nothing else is interrupt-safe!
2333 * Do NOT access: MII, GPIO, SROM, BIOSROM, XILINX, SYNTH, or DAC.
2337 /* Singly-linked tail-queues hold mbufs with active DMA.
2338 * For RX, single mbuf clusters; for TX, mbuf chains are queued.
2339 * NB: mbufs are linked through their m_nextpkt field.
2340 * Callers must hold sc->bottom_lock; not otherwise locked.
2343 /* Put an mbuf (chain) on the tail of the descriptor ring queue. */
2344 static void /* BSD version */
2345 mbuf_enqueue(struct desc_ring *ring, struct mbuf *m)
2347 m->m_nextpkt = NULL;
2348 if (ring->tail == NULL)
2351 ring->tail->m_nextpkt = m;
2355 /* Get an mbuf (chain) from the head of the descriptor ring queue. */
2356 static struct mbuf* /* BSD version */
2357 mbuf_dequeue(struct desc_ring *ring)
2359 struct mbuf *m = ring->head;
2361 if ((ring->head = m->m_nextpkt) == NULL)
2366 static void /* *** FreeBSD ONLY *** Callout from bus_dmamap_load() */
2367 fbsd_dmamap_load(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
2369 struct desc_ring *ring = arg;
2370 ring->nsegs = error ? 0 : nsegs;
2371 ring->segs[0] = segs[0];
2372 ring->segs[1] = segs[1];
2375 /* Initialize a DMA descriptor ring. */
2376 static int /* BSD version */
2377 create_ring(softc_t *sc, struct desc_ring *ring, int num_descs)
2379 struct dma_desc *descs;
2380 int size_descs = sizeof(struct dma_desc)*num_descs;
2383 /* The DMA descriptor array must not cross a page boundary. */
2384 if (size_descs > PAGE_SIZE)
2386 printf("%s: DMA descriptor array > PAGE_SIZE (%d)\n", NAME_UNIT,
2392 /* Create a DMA tag for descriptors and buffers. */
2393 if ((error = bus_dma_tag_create(bus_get_dma_tag(sc->dev),
2394 4, 0, BUS_SPACE_MAXADDR_32BIT,
2395 BUS_SPACE_MAXADDR, NULL, NULL, PAGE_SIZE, 2, PAGE_SIZE, BUS_DMA_ALLOCNOW,
2399 printf("%s: bus_dma_tag_create() failed: error %d\n", NAME_UNIT, error);
2403 /* Allocate wired physical memory for DMA descriptor array */
2404 /* and map physical address to kernel virtual address. */
2405 if ((error = bus_dmamem_alloc(ring->tag, (void**)&ring->first,
2406 BUS_DMA_NOWAIT | BUS_DMA_COHERENT | BUS_DMA_ZERO, &ring->map)))
2408 printf("%s: bus_dmamem_alloc() failed; error %d\n", NAME_UNIT, error);
2411 descs = ring->first;
2413 /* Map kernel virtual address to PCI address for DMA descriptor array. */
2414 if ((error = bus_dmamap_load(ring->tag, ring->map, descs, size_descs,
2415 fbsd_dmamap_load, ring, 0)))
2417 printf("%s: bus_dmamap_load() failed; error %d\n", NAME_UNIT, error);
2420 ring->dma_addr = ring->segs[0].ds_addr;
2422 /* Allocate dmamaps for each DMA descriptor. */
2423 for (i=0; i<num_descs; i++)
2424 if ((error = bus_dmamap_create(ring->tag, 0, &descs[i].map)))
2426 printf("%s: bus_dmamap_create() failed; error %d\n", NAME_UNIT, error);
2432 ring->write = descs;
2433 ring->first = descs;
2434 ring->last = descs + num_descs -1;
2435 ring->last->control = TLP_DCTL_END_RING;
2436 ring->num_descs = num_descs;
2437 ring->size_descs = size_descs;
2444 /* Destroy a DMA descriptor ring */
2445 static void /* BSD version */
2446 destroy_ring(softc_t *sc, struct desc_ring *ring)
2448 struct dma_desc *desc;
2451 /* Free queued mbufs. */
2452 while ((m = mbuf_dequeue(ring)) != NULL)
2455 /* TX may have one pkt that is not on any queue. */
2456 if (sc->tx_mbuf != NULL)
2458 m_freem(sc->tx_mbuf);
2462 /* Unmap active DMA descriptors. */
2463 while (ring->read != ring->write)
2465 bus_dmamap_unload(ring->tag, ring->read->map);
2466 if (ring->read++ == ring->last) ring->read = ring->first;
2470 /* Free the dmamaps of all DMA descriptors. */
2471 for (desc=ring->first; desc!=ring->last+1; desc++)
2472 if (desc->map != NULL)
2473 bus_dmamap_destroy(ring->tag, desc->map);
2475 /* Unmap PCI address for DMA descriptor array. */
2476 if (ring->dma_addr != 0)
2477 bus_dmamap_unload(ring->tag, ring->map);
2478 /* Free kernel memory for DMA descriptor array. */
2479 if (ring->first != NULL)
2480 bus_dmamem_free(ring->tag, ring->first, ring->map);
2481 /* Free the DMA tag created for this ring. */
2482 if (ring->tag != NULL)
2483 bus_dma_tag_destroy(ring->tag);
2487 /* Clean up after a packet has been received. */
2488 static int /* BSD version */
2489 rxintr_cleanup(softc_t *sc)
2491 struct desc_ring *ring = &sc->rxring;
2492 struct dma_desc *first_desc, *last_desc;
2493 struct mbuf *first_mbuf=NULL, *last_mbuf=NULL;
2494 struct mbuf *new_mbuf;
2495 int pkt_len, desc_len;
2497 #if defined(DEVICE_POLLING)
2498 /* Input packet flow control (livelock prevention): */
2499 /* Give pkts to higher levels only if quota is > 0. */
2500 if (sc->quota <= 0) return 0;
2503 /* This looks complicated, but remember: typically packets up */
2504 /* to 2048 bytes long fit in one mbuf and use one descriptor. */
2506 first_desc = last_desc = ring->read;
2508 /* ASSERTION: If there is a descriptor in the ring and the hardware has */
2509 /* finished with it, then that descriptor will have RX_FIRST_DESC set. */
2510 if ((ring->read != ring->write) && /* descriptor ring not empty */
2511 ((ring->read->status & TLP_DSTS_OWNER) == 0) && /* hardware done */
2512 ((ring->read->status & TLP_DSTS_RX_FIRST_DESC) == 0)) /* should be set */
2513 panic("%s: rxintr_cleanup: rx-first-descriptor not set.\n", NAME_UNIT);
2515 /* First decide if a complete packet has arrived. */
2516 /* Run down DMA descriptors looking for one marked "last". */
2517 /* Bail out if an active descriptor is encountered. */
2518 /* Accumulate most significant bits of packet length. */
2522 if (last_desc == ring->write) return 0; /* no more descs */
2523 if (last_desc->status & TLP_DSTS_OWNER) return 0; /* still active */
2524 if (last_desc->status & TLP_DSTS_RX_LAST_DESC) break; /* end of packet */
2525 pkt_len += last_desc->length1 + last_desc->length2; /* entire desc filled */
2526 if (last_desc++->control & TLP_DCTL_END_RING) last_desc = ring->first; /* ring wrap */
2529 /* A complete packet has arrived; how long is it? */
2530 /* H/w ref man shows RX pkt length as a 14-bit field. */
2531 /* An experiment found that only the 12 LSBs work. */
2532 if (((last_desc->status>>16)&0xFFF) == 0) pkt_len += 4096; /* carry-bit */
2533 pkt_len = (pkt_len & 0xF000) + ((last_desc->status>>16) & 0x0FFF);
2534 /* Subtract the CRC length unless doing so would underflow. */
2535 if (pkt_len >= sc->config.crc_len) pkt_len -= sc->config.crc_len;
2537 /* Run down DMA descriptors again doing the following:
2538 * 1) put pkt info in pkthdr of first mbuf,
2540 * 3) set mbuf lengths.
2542 first_desc = ring->read;
2545 /* Read a DMA descriptor from the ring. */
2546 last_desc = ring->read;
2547 /* Advance the ring read pointer. */
2548 if (ring->read++ == ring->last) ring->read = ring->first;
2550 /* Dequeue the corresponding cluster mbuf. */
2551 new_mbuf = mbuf_dequeue(ring);
2552 if (new_mbuf == NULL)
2553 panic("%s: rxintr_cleanup: expected an mbuf\n", NAME_UNIT);
2555 desc_len = last_desc->length1 + last_desc->length2;
2556 /* If bouncing, copy bounce buf to mbuf. */
2557 DMA_SYNC(last_desc->map, desc_len, BUS_DMASYNC_POSTREAD);
2558 /* Unmap kernel virtual address to PCI address. */
2559 bus_dmamap_unload(ring->tag, last_desc->map);
2561 /* 1) Put pkt info in pkthdr of first mbuf. */
2562 if (last_desc == first_desc)
2564 first_mbuf = new_mbuf;
2565 first_mbuf->m_pkthdr.len = pkt_len; /* total pkt length */
2566 first_mbuf->m_pkthdr.rcvif = sc->ifp; /* how it got here */
2568 else /* 2) link mbufs. */
2570 last_mbuf->m_next = new_mbuf;
2571 /* M_PKTHDR should be set in the first mbuf only. */
2572 new_mbuf->m_flags &= ~M_PKTHDR;
2574 last_mbuf = new_mbuf;
2576 /* 3) Set mbuf lengths. */
2577 new_mbuf->m_len = (pkt_len >= desc_len) ? desc_len : pkt_len;
2578 pkt_len -= new_mbuf->m_len;
2579 } while ((last_desc->status & TLP_DSTS_RX_LAST_DESC) == 0);
2581 /* Decide whether to accept or to discard this packet. */
2582 /* RxHDLC sets MIIERR for bad CRC, abort and partial byte at pkt end. */
2583 if (((last_desc->status & TLP_DSTS_RX_BAD) == 0) &&
2584 (sc->status.oper_status == STATUS_UP) &&
2585 (first_mbuf->m_pkthdr.len > 0))
2587 /* Optimization: copy a small pkt into a small mbuf. */
2588 if (first_mbuf->m_pkthdr.len <= COPY_BREAK)
2590 MGETHDR(new_mbuf, M_NOWAIT, MT_DATA);
2591 if (new_mbuf != NULL)
2593 new_mbuf->m_pkthdr.rcvif = first_mbuf->m_pkthdr.rcvif;
2594 new_mbuf->m_pkthdr.len = first_mbuf->m_pkthdr.len;
2595 new_mbuf->m_len = first_mbuf->m_len;
2596 memcpy(new_mbuf->m_data, first_mbuf->m_data,
2597 first_mbuf->m_pkthdr.len);
2598 m_freem(first_mbuf);
2599 first_mbuf = new_mbuf;
2602 /* Include CRC and one flag byte in input byte count. */
2603 sc->status.cntrs.ibytes += first_mbuf->m_pkthdr.len + sc->config.crc_len +1;
2604 sc->status.cntrs.ipackets++;
2605 if_inc_counter(sc->ifp, IFCOUNTER_IPACKETS, 1);
2606 LMC_BPF_MTAP(first_mbuf);
2607 #if defined(DEVICE_POLLING)
2611 /* Give this good packet to the network stacks. */
2613 if (sc->ng_hook != NULL) /* is hook connected? */
2615 int error; /* ignore error */
2616 NG_SEND_DATA_ONLY(error, sc->ng_hook, first_mbuf);
2617 return 1; /* did something */
2619 #endif /* NETGRAPH */
2620 if (sc->config.line_pkg == PKG_RAWIP)
2621 lmc_raw_input(sc->ifp, first_mbuf);
2625 sppp_input(sc->ifp, first_mbuf);
2627 new_mbuf = first_mbuf;
2628 while (new_mbuf != NULL)
2630 sc->p2p->p2p_hdrinput(sc->p2p, new_mbuf->m_data, new_mbuf->m_len);
2631 new_mbuf = new_mbuf->m_next;
2633 sc->p2p->p2p_input(sc->p2p, NULL);
2634 m_freem(first_mbuf);
2636 m_freem(first_mbuf);
2637 sc->status.cntrs.idiscards++;
2641 else if (sc->status.oper_status != STATUS_UP)
2643 /* If the link is down, this packet is probably noise. */
2644 m_freem(first_mbuf);
2645 sc->status.cntrs.idiscards++;
2647 printf("%s: rxintr_cleanup: rx pkt discarded: link down\n", NAME_UNIT);
2649 else /* Log and discard this bad packet. */
2652 printf("%s: RX bad pkt; len=%d %s%s%s%s\n",
2653 NAME_UNIT, first_mbuf->m_pkthdr.len,
2654 (last_desc->status & TLP_DSTS_RX_MII_ERR) ? " miierr" : "",
2655 (last_desc->status & TLP_DSTS_RX_DRIBBLE) ? " dribble" : "",
2656 (last_desc->status & TLP_DSTS_RX_DESC_ERR) ? " descerr" : "",
2657 (last_desc->status & TLP_DSTS_RX_OVERRUN) ? " overrun" : "");
2658 if (last_desc->status & TLP_DSTS_RX_OVERRUN)
2659 sc->status.cntrs.fifo_over++;
2661 sc->status.cntrs.ierrors++;
2662 m_freem(first_mbuf);
2665 return 1; /* did something */
2668 /* Setup (prepare) to receive a packet. */
2669 /* Try to keep the RX descriptor ring full of empty buffers. */
2670 static int /* BSD version */
2671 rxintr_setup(softc_t *sc)
2673 struct desc_ring *ring = &sc->rxring;
2674 struct dma_desc *desc;
2679 /* Ring is full if (wrap(write+1)==read) */
2680 if (((ring->write == ring->last) ? ring->first : ring->write+1) == ring->read)
2681 return 0; /* ring is full; nothing to do */
2683 /* Allocate a small mbuf and attach an mbuf cluster. */
2684 MGETHDR(m, M_NOWAIT, MT_DATA);
2687 sc->status.cntrs.rxdma++;
2689 printf("%s: rxintr_setup: MGETHDR() failed\n", NAME_UNIT);
2692 if (!(MCLGET(m, M_NOWAIT)))
2695 sc->status.cntrs.rxdma++;
2697 printf("%s: rxintr_setup: MCLGET() failed\n", NAME_UNIT);
2701 /* Queue the mbuf for later processing by rxintr_cleanup. */
2702 mbuf_enqueue(ring, m);
2704 /* Write a DMA descriptor into the ring. */
2705 /* Hardware won't see it until the OWNER bit is set. */
2707 /* Advance the ring write pointer. */
2708 if (ring->write++ == ring->last) ring->write = ring->first;
2710 desc_len = (MCLBYTES < MAX_DESC_LEN) ? MCLBYTES : MAX_DESC_LEN;
2711 /* Map kernel virtual address to PCI address. */
2712 if ((error = DMA_LOAD(desc->map, m->m_data, desc_len)))
2713 printf("%s: bus_dmamap_load(rx) failed; error %d\n", NAME_UNIT, error);
2714 /* Invalidate the cache for this mbuf. */
2715 DMA_SYNC(desc->map, desc_len, BUS_DMASYNC_PREREAD);
2717 /* Set up the DMA descriptor. */
2718 desc->address1 = ring->segs[0].ds_addr;
2719 desc->length1 = desc_len>>1;
2720 desc->address2 = desc->address1 + desc->length1;
2721 desc->length2 = desc_len>>1;
2723 /* Before setting the OWNER bit, flush the cache (memory barrier). */
2724 DMA_SYNC(ring->map, ring->size_descs, BUS_DMASYNC_PREWRITE);
2726 /* Commit the DMA descriptor to the hardware. */
2727 desc->status = TLP_DSTS_OWNER;
2729 /* Notify the receiver that there is another buffer available. */
2730 WRITE_CSR(TLP_RX_POLL, 1);
2732 return 1; /* did something */
2735 /* Clean up after a packet has been transmitted. */
2736 /* Free the mbuf chain and update the DMA descriptor ring. */
2737 static int /* BSD version */
2738 txintr_cleanup(softc_t *sc)
2740 struct desc_ring *ring = &sc->txring;
2741 struct dma_desc *desc;
2743 while ((ring->read != ring->write) && /* while ring is not empty */
2744 ((ring->read->status & TLP_DSTS_OWNER) == 0))
2746 /* Read a DMA descriptor from the ring. */
2748 /* Advance the ring read pointer. */
2749 if (ring->read++ == ring->last) ring->read = ring->first;
2751 /* This is a no-op on most architectures. */
2752 DMA_SYNC(desc->map, desc->length1 + desc->length2, BUS_DMASYNC_POSTWRITE);
2753 /* Unmap kernel virtual address to PCI address. */
2754 bus_dmamap_unload(ring->tag, desc->map);
2756 /* If this descriptor is the last segment of a packet, */
2757 /* then dequeue and free the corresponding mbuf chain. */
2758 if ((desc->control & TLP_DCTL_TX_LAST_SEG) != 0)
2761 if ((m = mbuf_dequeue(ring)) == NULL)
2762 panic("%s: txintr_cleanup: expected an mbuf\n", NAME_UNIT);
2764 /* Include CRC and one flag byte in output byte count. */
2765 sc->status.cntrs.obytes += m->m_pkthdr.len + sc->config.crc_len +1;
2766 sc->status.cntrs.opackets++;
2767 if_inc_counter(sc->ifp, IFCOUNTER_OPACKETS, 1);
2769 /* The only bad TX status is fifo underrun. */
2770 if ((desc->status & TLP_DSTS_TX_UNDERRUN) != 0)
2771 sc->status.cntrs.fifo_under++;
2774 return 1; /* did something */
2781 /* Build DMA descriptors for a transmit packet mbuf chain. */
2782 static int /* 0=success; 1=error */ /* BSD version */
2783 txintr_setup_mbuf(softc_t *sc, struct mbuf *m)
2785 struct desc_ring *ring = &sc->txring;
2786 struct dma_desc *desc;
2787 unsigned int desc_len;
2789 /* build DMA descriptors for a chain of mbufs. */
2792 char *data = m->m_data;
2793 int length = m->m_len; /* zero length mbufs happen! */
2795 /* Build DMA descriptors for one mbuf. */
2800 /* Ring is full if (wrap(write+1)==read) */
2801 if (((ring->temp==ring->last) ? ring->first : ring->temp+1) == ring->read)
2802 { /* Not enough DMA descriptors; try later. */
2803 for (; ring->temp!=ring->write;
2804 ring->temp = (ring->temp==ring->first)? ring->last : ring->temp-1)
2805 bus_dmamap_unload(ring->tag, ring->temp->map);
2806 sc->status.cntrs.txdma++;
2810 /* Provisionally, write a descriptor into the ring. */
2811 /* But don't change the REAL ring write pointer. */
2812 /* Hardware won't see it until the OWNER bit is set. */
2814 /* Advance the temporary ring write pointer. */
2815 if (ring->temp++ == ring->last) ring->temp = ring->first;
2817 /* Clear all control bits except the END_RING bit. */
2818 desc->control &= TLP_DCTL_END_RING;
2819 /* Don't pad short packets up to 64 bytes. */
2820 desc->control |= TLP_DCTL_TX_NO_PAD;
2821 /* Use Tulip's CRC-32 generator, if appropriate. */
2822 if (sc->config.crc_len != CFG_CRC_32)
2823 desc->control |= TLP_DCTL_TX_NO_CRC;
2824 /* Set the OWNER bit, except in the first descriptor. */
2825 if (desc != ring->write)
2826 desc->status = TLP_DSTS_OWNER;
2828 desc_len = (length > MAX_CHUNK_LEN) ? MAX_CHUNK_LEN : length;
2829 /* Map kernel virtual address to PCI address. */
2830 if ((error = DMA_LOAD(desc->map, data, desc_len)))
2831 printf("%s: bus_dmamap_load(tx) failed; error %d\n", NAME_UNIT, error);
2832 /* Flush the cache and if bouncing, copy mbuf to bounce buf. */
2833 DMA_SYNC(desc->map, desc_len, BUS_DMASYNC_PREWRITE);
2835 /* Prevent wild fetches if mapping fails (nsegs==0). */
2836 desc->length1 = desc->length2 = 0;
2837 desc->address1 = desc->address2 = 0;
2839 bus_dma_segment_t *segs = ring->segs;
2840 int nsegs = ring->nsegs;
2843 desc->address1 = segs[0].ds_addr;
2844 desc->length1 = segs[0].ds_len;
2848 desc->address2 = segs[1].ds_addr;
2849 desc->length2 = segs[1].ds_len;
2855 } /* while (length > 0) */
2858 } /* while (m != NULL) */
2860 return 0; /* success */
2863 /* Setup (prepare) to transmit a packet. */
2864 /* Select a packet, build DMA descriptors and give packet to hardware. */
2865 /* If DMA descriptors run out, abandon the attempt and return 0. */
2866 static int /* BSD version */
2867 txintr_setup(softc_t *sc)
2869 struct desc_ring *ring = &sc->txring;
2870 struct dma_desc *first_desc, *last_desc;
2872 /* Protect against half-up links: Don't transmit */
2873 /* if the receiver can't hear the far end. */
2874 if (sc->status.oper_status != STATUS_UP) return 0;
2876 /* Pick a packet to transmit. */
2878 if ((sc->ng_hook != NULL) && (sc->tx_mbuf == NULL))
2880 if (!IFQ_IS_EMPTY(&sc->ng_fastq))
2881 IFQ_DEQUEUE(&sc->ng_fastq, sc->tx_mbuf);
2883 IFQ_DEQUEUE(&sc->ng_sndq, sc->tx_mbuf);
2887 if (sc->tx_mbuf == NULL)
2889 if (sc->config.line_pkg == PKG_RAWIP)
2890 IFQ_DEQUEUE(&sc->ifp->if_snd, sc->tx_mbuf);
2894 sc->tx_mbuf = sppp_dequeue(sc->ifp);
2896 if (!IFQ_IS_EMPTY(&sc->p2p->p2p_isnd))
2897 IFQ_DEQUEUE(&sc->p2p->p2p_isnd, sc->tx_mbuf);
2899 IFQ_DEQUEUE(&sc->ifp->if_snd, sc->tx_mbuf);
2903 if (sc->tx_mbuf == NULL) return 0; /* no pkt to transmit */
2905 /* Build DMA descriptors for an outgoing mbuf chain. */
2906 ring->temp = ring->write; /* temporary ring write pointer */
2907 if (txintr_setup_mbuf(sc, sc->tx_mbuf) != 0) return 0;
2909 /* Enqueue the mbuf; txintr_cleanup will free it. */
2910 mbuf_enqueue(ring, sc->tx_mbuf);
2912 /* The transmitter has room for another packet. */
2915 /* Set first & last segment bits. */
2916 /* last_desc is the desc BEFORE the one pointed to by ring->temp. */
2917 first_desc = ring->write;
2918 first_desc->control |= TLP_DCTL_TX_FIRST_SEG;
2919 last_desc = (ring->temp==ring->first)? ring->last : ring->temp-1;
2920 last_desc->control |= TLP_DCTL_TX_LAST_SEG;
2921 /* Interrupt at end-of-transmission? Why bother the poor computer! */
2922 /* last_desc->control |= TLP_DCTL_TX_INTERRUPT; */
2924 /* Make sure the OWNER bit is not set in the next descriptor. */
2925 /* The OWNER bit may have been set if a previous call aborted. */
2926 ring->temp->status = 0;
2928 /* Commit the DMA descriptors to the software. */
2929 ring->write = ring->temp;
2931 /* Before setting the OWNER bit, flush the cache (memory barrier). */
2932 DMA_SYNC(ring->map, ring->size_descs, BUS_DMASYNC_PREWRITE);
2934 /* Commit the DMA descriptors to the hardware. */
2935 first_desc->status = TLP_DSTS_OWNER;
2937 /* Notify the transmitter that there is another packet to send. */
2938 WRITE_CSR(TLP_TX_POLL, 1);
2940 return 1; /* did something */
2946 check_intr_status(softc_t *sc)
2948 u_int32_t status, cfcs, op_mode;
2949 u_int32_t missed, overruns;
2951 /* Check for four unusual events:
2952 * 1) fatal PCI bus errors - some are recoverable
2953 * 2) transmitter FIFO underruns - increase fifo threshold
2954 * 3) receiver FIFO overruns - clear potential hangup
2955 * 4) no receive descs or bufs - count missed packets
2958 /* 1) A fatal bus error causes a Tulip to stop initiating bus cycles. */
2959 /* Module unload/load or boot are the only fixes for Parity Errors. */
2960 /* Master and Target Aborts can be cleared and life may continue. */
2961 status = READ_CSR(TLP_STATUS);
2962 if ((status & TLP_STAT_FATAL_ERROR) != 0)
2964 u_int32_t fatal = (status & TLP_STAT_FATAL_BITS)>>TLP_STAT_FATAL_SHIFT;
2965 printf("%s: FATAL PCI BUS ERROR: %s%s%s%s\n", NAME_UNIT,
2966 (fatal == 0) ? "PARITY ERROR" : "",
2967 (fatal == 1) ? "MASTER ABORT" : "",
2968 (fatal == 2) ? "TARGET ABORT" : "",
2969 (fatal >= 3) ? "RESERVED (?)" : "");
2970 cfcs = READ_PCI_CFG(sc, TLP_CFCS); /* try to clear it */
2971 cfcs &= ~(TLP_CFCS_MSTR_ABORT | TLP_CFCS_TARG_ABORT);
2972 WRITE_PCI_CFG(sc, TLP_CFCS, cfcs);
2975 /* 2) If the transmitter fifo underruns, increase the transmit fifo */
2976 /* threshold: the number of bytes required to be in the fifo */
2977 /* before starting the transmitter (cost: increased tx delay). */
2978 /* The TX_FSM must be stopped to change this parameter. */
2979 if ((status & TLP_STAT_TX_UNDERRUN) != 0)
2981 op_mode = READ_CSR(TLP_OP_MODE);
2982 /* enable store-and-forward mode if tx_threshold tops out? */
2983 if ((op_mode & TLP_OP_TX_THRESH) < TLP_OP_TX_THRESH)
2985 op_mode += 0x4000; /* increment TX_THRESH field; can't overflow */
2986 WRITE_CSR(TLP_OP_MODE, op_mode & ~TLP_OP_TX_RUN);
2987 /* Wait for the TX FSM to stop; it might be processing a pkt. */
2988 while (READ_CSR(TLP_STATUS) & TLP_STAT_TX_FSM); /* XXX HANG */
2989 WRITE_CSR(TLP_OP_MODE, op_mode); /* restart tx */
2991 printf("%s: tx underrun; tx fifo threshold now %d bytes\n",
2992 NAME_UNIT, 128<<((op_mode>>TLP_OP_TR_SHIFT)&3));
2996 /* 3) Errata memo from Digital Equipment Corp warns that 21140A */
2997 /* receivers through rev 2.2 can hang if the fifo overruns. */
2998 /* Recommended fix: stop and start the RX FSM after an overrun. */
2999 missed = READ_CSR(TLP_MISSED);
3000 if ((overruns = ((missed & TLP_MISS_OVERRUN)>>TLP_OVERRUN_SHIFT)) != 0)
3003 printf("%s: rx overrun cntr=%d\n", NAME_UNIT, overruns);
3004 sc->status.cntrs.overruns += overruns;
3005 if ((READ_PCI_CFG(sc, TLP_CFRV) & 0xFF) <= 0x22)
3007 op_mode = READ_CSR(TLP_OP_MODE);
3008 WRITE_CSR(TLP_OP_MODE, op_mode & ~TLP_OP_RX_RUN);
3009 /* Wait for the RX FSM to stop; it might be processing a pkt. */
3010 while (READ_CSR(TLP_STATUS) & TLP_STAT_RX_FSM); /* XXX HANG */
3011 WRITE_CSR(TLP_OP_MODE, op_mode); /* restart rx */
3015 /* 4) When the receiver is enabled and a packet arrives, but no DMA */
3016 /* descriptor is available, the packet is counted as 'missed'. */
3017 /* The receiver should never miss packets; warn if it happens. */
3018 if ((missed = (missed & TLP_MISS_MISSED)) != 0)
3021 printf("%s: rx missed %d pkts\n", NAME_UNIT, missed);
3022 sc->status.cntrs.missed += missed;
3026 static void /* This is where the work gets done. */
3027 core_interrupt(void *arg, int check_status)
3032 /* If any CPU is inside this critical section, then */
3033 /* other CPUs should go away without doing anything. */
3034 if (BOTTOM_TRYLOCK == 0)
3036 sc->status.cntrs.lck_intr++;
3040 /* Clear pending card interrupts. */
3041 WRITE_CSR(TLP_STATUS, READ_CSR(TLP_STATUS));
3043 /* In Linux, pci_alloc_consistent() means DMA descriptors */
3044 /* don't need explicit syncing. */
3046 struct desc_ring *ring = &sc->txring;
3047 DMA_SYNC(sc->txring.map, sc->txring.size_descs,
3048 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
3050 DMA_SYNC(sc->rxring.map, sc->rxring.size_descs,
3051 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
3054 do /* This is the main loop for interrupt processing. */
3056 activity = txintr_cleanup(sc);
3057 activity += txintr_setup(sc);
3058 activity += rxintr_cleanup(sc);
3059 activity += rxintr_setup(sc);
3063 struct desc_ring *ring = &sc->txring;
3064 DMA_SYNC(sc->txring.map, sc->txring.size_descs,
3065 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3067 DMA_SYNC(sc->rxring.map, sc->rxring.size_descs,
3068 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3071 /* As the interrupt is dismissed, check for four unusual events. */
3072 if (check_status) check_intr_status(sc);
3077 /* user_interrupt() may be called from a syscall or a softirq */
3079 user_interrupt(softc_t *sc, int check_status)
3081 DISABLE_INTR; /* noop on FreeBSD-5 and Linux */
3082 core_interrupt(sc, check_status);
3083 ENABLE_INTR; /* noop on FreeBSD-5 and Linux */
3087 # if defined(DEVICE_POLLING)
3089 /* Service the card from the kernel idle loop without interrupts. */
3091 fbsd_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
3093 softc_t *sc = IFP2SC(ifp);
3097 core_interrupt(sc, (cmd==POLL_AND_CHECK_STATUS));
3101 # endif /* DEVICE_POLLING */
3103 /* BSD kernels call this procedure when an interrupt happens. */
3104 static intr_return_t
3105 bsd_interrupt(void *arg)
3109 /* Cut losses early if this is not our interrupt. */
3110 if ((READ_CSR(TLP_STATUS) & TLP_INT_TXRX) == 0)
3113 # if defined(DEVICE_POLLING)
3114 if (sc->ifp->if_capenable & IFCAP_POLLING)
3117 if ((sc->ifp->if_capabilities & IFCAP_POLLING) &&
3118 (ether_poll_register(fbsd_poll, sc->ifp)))
3120 WRITE_CSR(TLP_INT_ENBL, TLP_INT_DISABLE);
3124 sc->quota = sc->rxring.num_descs; /* input flow control */
3125 # endif /* DEVICE_POLLING */
3127 /* Disable card interrupts. */
3128 WRITE_CSR(TLP_INT_ENBL, TLP_INT_DISABLE);
3130 core_interrupt(sc, 0);
3132 /* Enable card interrupts. */
3133 WRITE_CSR(TLP_INT_ENBL, TLP_INT_TXRX);
3139 /* Administrative status of the driver (UP or DOWN) has changed. */
3140 /* A card-specific action may be required: T1 and T3 cards: no-op. */
3141 /* HSSI and SSI cards change the state of modem ready signals. */
3143 set_status(softc_t *sc, int status)
3147 ioctl.cmd = IOCTL_SET_STATUS;
3148 ioctl.data = status;
3150 sc->card->ioctl(sc, &ioctl);
3155 /* Callout from P2P: */
3156 /* Get the state of DCD (Data Carrier Detect). */
3158 p2p_getmdm(struct p2pcom *p2p, caddr_t result)
3160 softc_t *sc = IFP2SC(&p2p->p2p_if);
3162 /* Non-zero isn't good enough; TIOCM_CAR is 0x40. */
3163 *(int *)result = (sc->status.oper_status==STATUS_UP) ? TIOCM_CAR : 0;
3168 /* Callout from P2P: */
3169 /* Set the state of DTR (Data Terminal Ready). */
3171 p2p_mdmctl(struct p2pcom *p2p, int flag)
3173 softc_t *sc = IFP2SC(&p2p->p2p_if);
3175 set_status(sc, flag);
3188 /* Callout from SPPP: */
3190 sppp_tls(struct sppp *sppp)
3192 if (!(sppp->pp_mode & IFF_LINK2) &&
3193 !(sppp->pp_flags & PP_FR))
3197 /* Callout from SPPP: */
3199 sppp_tlf(struct sppp *sppp)
3201 if (!(sppp->pp_mode & IFF_LINK2) &&
3202 !(sppp->pp_flags & PP_FR))
3203 sppp->pp_down(sppp);
3208 /* Configure line protocol stuff.
3209 * Called by attach_card() during module init.
3210 * Called by core_ioctl() when lmcconfig writes sc->config.
3211 * Called by detach_card() during module shutdown.
3214 config_proto(softc_t *sc, struct config *config)
3216 /* Use line protocol stack instead of RAWIP mode. */
3217 if ((sc->config.line_pkg == PKG_RAWIP) &&
3218 (config->line_pkg != PKG_RAWIP))
3222 sppp_attach(sc->ifp);
3223 LMC_BPF_ATTACH(DLT_PPP, 4);
3224 sc->sppp->pp_tls = sppp_tls;
3225 sc->sppp->pp_tlf = sppp_tlf;
3226 /* Force reconfiguration of SPPP params. */
3227 sc->config.line_prot = 0;
3228 sc->config.keep_alive = config->keep_alive ? 0:1;
3231 sc->p2p->p2p_proto = 0; /* force p2p_attach */
3232 if ((error = p2p_attach(sc->p2p))) /* calls bpfattach() */
3234 printf("%s: p2p_attach() failed; error %d\n", NAME_UNIT, error);
3235 config->line_pkg = PKG_RAWIP; /* still in RAWIP mode */
3239 sc->p2p->p2p_mdmctl = p2p_mdmctl; /* set DTR */
3240 sc->p2p->p2p_getmdm = p2p_getmdm; /* get DCD */
3244 sc->net_dev->mtu = HDLC_MAX_MTU;
3245 if ((error = hdlc_open(sc->net_dev)))
3247 printf("%s: hdlc_open() failed; error %d\n", NAME_UNIT, error);
3248 printf("%s: Try 'sethdlc %s ppp'\n", NAME_UNIT, NAME_UNIT);
3249 config->line_pkg = PKG_RAWIP; /* still in RAWIP mode */
3251 #else /* no line protocol stack was configured */
3252 config->line_pkg = PKG_RAWIP; /* still in RAWIP mode */
3256 /* Bypass line protocol stack and return to RAWIP mode. */
3257 if ((sc->config.line_pkg != PKG_RAWIP) &&
3258 (config->line_pkg == PKG_RAWIP))
3262 sppp_flush(sc->ifp);
3263 sppp_detach(sc->ifp);
3264 setup_ifnet(sc->ifp);
3265 LMC_BPF_ATTACH(DLT_RAW, 0);
3268 if_qflush(&sc->p2p->p2p_isnd);
3269 if ((error = p2p_detach(sc->p2p)))
3271 printf("%s: p2p_detach() failed; error %d\n", NAME_UNIT, error);
3272 printf("%s: Try 'ifconfig %s down -remove'\n", NAME_UNIT, NAME_UNIT);
3273 config->line_pkg = PKG_P2P; /* not in RAWIP mode; still attached to P2P */
3277 setup_ifnet(sc->ifp);
3278 LMC_BPF_ATTACH(DLT_RAW, 0);
3281 hdlc_proto_detach(sc->hdlc_dev);
3282 hdlc_close(sc->net_dev);
3283 setup_netdev(sc->net_dev);
3289 if (config->line_pkg != PKG_RAWIP)
3291 /* Check for change to PPP protocol. */
3292 if ((sc->config.line_prot != PROT_PPP) &&
3293 (config->line_prot == PROT_PPP))
3296 sc->ifp->if_flags &= ~IFF_LINK2;
3297 sc->sppp->pp_flags &= ~PP_FR;
3298 LMC_BPF_ATTACH(DLT_PPP, 4);
3299 sppp_ioctl(sc->ifp, SIOCSIFFLAGS, NULL);
3303 # define DLT_C_HDLC DLT_PPP
3306 /* Check for change to C_HDLC protocol. */
3307 if ((sc->config.line_prot != PROT_C_HDLC) &&
3308 (config->line_prot == PROT_C_HDLC))
3311 sc->ifp->if_flags |= IFF_LINK2;
3312 sc->sppp->pp_flags &= ~PP_FR;
3313 LMC_BPF_ATTACH(DLT_C_HDLC, 4);
3314 sppp_ioctl(sc->ifp, SIOCSIFFLAGS, NULL);
3317 /* Check for change to Frame Relay protocol. */
3318 if ((sc->config.line_prot != PROT_FRM_RLY) &&
3319 (config->line_prot == PROT_FRM_RLY))
3322 sc->ifp->if_flags &= ~IFF_LINK2;
3323 sc->sppp->pp_flags |= PP_FR;
3324 LMC_BPF_ATTACH(DLT_FRELAY, 4);
3325 sppp_ioctl(sc->ifp, SIOCSIFFLAGS, NULL);
3328 /* Check for disabling keep-alives. */
3329 if ((sc->config.keep_alive != 0) &&
3330 (config->keep_alive == 0))
3331 sc->sppp->pp_flags &= ~PP_KEEPALIVE;
3333 /* Check for enabling keep-alives. */
3334 if ((sc->config.keep_alive == 0) &&
3335 (config->keep_alive != 0))
3336 sc->sppp->pp_flags |= PP_KEEPALIVE;
3341 /* Loop back through the TULIP Ethernet chip; (no CRC). */
3342 /* Data sheet says stop DMA before changing OPMODE register. */
3343 /* But that's not as simple as it sounds; works anyway. */
3344 /* Check for enabling loopback thru Tulip chip. */
3345 if ((sc->config.loop_back != CFG_LOOP_TULIP) &&
3346 (config->loop_back == CFG_LOOP_TULIP))
3348 u_int32_t op_mode = READ_CSR(TLP_OP_MODE);
3349 op_mode |= TLP_OP_INT_LOOP;
3350 WRITE_CSR(TLP_OP_MODE, op_mode);
3351 config->crc_len = CFG_CRC_0;
3354 /* Check for disabling loopback thru Tulip chip. */
3355 if ((sc->config.loop_back == CFG_LOOP_TULIP) &&
3356 (config->loop_back != CFG_LOOP_TULIP))
3358 u_int32_t op_mode = READ_CSR(TLP_OP_MODE);
3359 op_mode &= ~TLP_OP_LOOP_MODE;
3360 WRITE_CSR(TLP_OP_MODE, op_mode);
3361 config->crc_len = CFG_CRC_16;
3365 /* This is the core ioctl procedure. */
3366 /* It handles IOCTLs from lmcconfig(8). */
3367 /* It must not run when card watchdogs run. */
3368 /* Called from a syscall (user context; no spinlocks). */
3369 /* This procedure can SLEEP. */
3371 core_ioctl(softc_t *sc, u_long cmd, caddr_t data)
3373 struct iohdr *iohdr = (struct iohdr *) data;
3374 struct ioctl *ioctl = (struct ioctl *) data;
3375 struct status *status = (struct status *) data;
3376 struct config *config = (struct config *) data;
3379 /* All structs start with a string and a cookie. */
3380 if (((struct iohdr *)data)->cookie != NGM_LMC_COOKIE)
3383 while (TOP_TRYLOCK == 0)
3385 sc->status.cntrs.lck_ioctl++;
3386 SLEEP(10000); /* yield? */
3392 *status = sc->status;
3393 iohdr->cookie = NGM_LMC_COOKIE;
3398 *config = sc->config;
3399 iohdr->cookie = NGM_LMC_COOKIE;
3404 if ((error = CHECK_CAP)) break;
3405 config_proto(sc, config);
3406 sc->config = *config;
3407 sc->card->config(sc);
3412 if (ioctl->cmd == IOCTL_RW_PCI)
3414 if (ioctl->address > 252) { error = EFAULT; break; }
3415 ioctl->data = READ_PCI_CFG(sc, ioctl->address);
3417 else if (ioctl->cmd == IOCTL_RW_CSR)
3419 if (ioctl->address > 15) { error = EFAULT; break; }
3420 ioctl->data = READ_CSR(ioctl->address*TLP_CSR_STRIDE);
3422 else if (ioctl->cmd == IOCTL_RW_SROM)
3424 if (ioctl->address > 63) { error = EFAULT; break; }
3425 ioctl->data = read_srom(sc, ioctl->address);
3427 else if (ioctl->cmd == IOCTL_RW_BIOS)
3428 ioctl->data = read_bios(sc, ioctl->address);
3429 else if (ioctl->cmd == IOCTL_RW_MII)
3430 ioctl->data = read_mii(sc, ioctl->address);
3431 else if (ioctl->cmd == IOCTL_RW_FRAME)
3432 ioctl->data = read_framer(sc, ioctl->address);
3439 if ((error = CHECK_CAP)) break;
3440 if (ioctl->cmd == IOCTL_RW_PCI)
3442 if (ioctl->address > 252) { error = EFAULT; break; }
3443 WRITE_PCI_CFG(sc, ioctl->address, ioctl->data);
3445 else if (ioctl->cmd == IOCTL_RW_CSR)
3447 if (ioctl->address > 15) { error = EFAULT; break; }
3448 WRITE_CSR(ioctl->address*TLP_CSR_STRIDE, ioctl->data);
3450 else if (ioctl->cmd == IOCTL_RW_SROM)
3452 if (ioctl->address > 63) { error = EFAULT; break; }
3453 write_srom(sc, ioctl->address, ioctl->data); /* can sleep */
3455 else if (ioctl->cmd == IOCTL_RW_BIOS)
3457 if (ioctl->address == 0) erase_bios(sc);
3458 write_bios(sc, ioctl->address, ioctl->data); /* can sleep */
3460 else if (ioctl->cmd == IOCTL_RW_MII)
3461 write_mii(sc, ioctl->address, ioctl->data);
3462 else if (ioctl->cmd == IOCTL_RW_FRAME)
3463 write_framer(sc, ioctl->address, ioctl->data);
3464 else if (ioctl->cmd == IOCTL_WO_SYNTH)
3465 write_synth(sc, (struct synth *)&ioctl->data);
3466 else if (ioctl->cmd == IOCTL_WO_DAC)
3468 write_dac(sc, 0x9002); /* set Vref = 2.048 volts */
3469 write_dac(sc, ioctl->data & 0xFFF);
3477 if ((error = CHECK_CAP)) break;
3478 if (ioctl->cmd == IOCTL_XILINX_RESET)
3481 sc->card->config(sc);
3483 else if (ioctl->cmd == IOCTL_XILINX_ROM)
3485 load_xilinx_from_rom(sc); /* can sleep */
3486 sc->card->config(sc);
3488 else if (ioctl->cmd == IOCTL_XILINX_FILE)
3490 /* load_xilinx_from_file() can sleep. */
3491 error = load_xilinx_from_file(sc, ioctl->ucode, ioctl->data);
3492 if (error != 0) load_xilinx_from_rom(sc); /* try the rom */
3493 sc->card->config(sc);
3494 set_status(sc, (error==0)); /* XXX */
3496 else if (ioctl->cmd == IOCTL_RESET_CNTRS)
3498 memset(&sc->status.cntrs, 0, sizeof(struct event_cntrs));
3499 microtime(&sc->status.cntrs.reset_time);
3502 error = sc->card->ioctl(sc, ioctl); /* can sleep */
3514 /* This is the core watchdog procedure. */
3515 /* It calculates link speed, and calls the card-specific watchdog code. */
3516 /* Calls interrupt() in case one got lost; also kick-starts the device. */
3517 /* ioctl syscalls and card watchdog routines must be interlocked. */
3518 /* This procedure must not sleep. */
3520 core_watchdog(softc_t *sc)
3522 /* Read and restart the Tulip timer. */
3523 u_int32_t tx_speed = READ_CSR(TLP_TIMER);
3524 WRITE_CSR(TLP_TIMER, 0xFFFF);
3526 /* Measure MII clock using a timer in the Tulip chip.
3527 * This timer counts transmitter bits divided by 4096.
3528 * Since this is called once a second the math is easy.
3529 * This is only correct when the link is NOT sending pkts.
3530 * On a fully-loaded link, answer will be HALF actual rate.
3531 * Clock rate during pkt is HALF clk rate between pkts.
3532 * Measuring clock rate really measures link utilization!
3534 sc->status.tx_speed = (0xFFFF - (tx_speed & 0xFFFF)) << 12;
3536 /* The first status reset time is when the calendar clock is set. */
3537 if (sc->status.cntrs.reset_time.tv_sec < 1000)
3538 microtime(&sc->status.cntrs.reset_time);
3540 /* Update hardware (operational) status. */
3541 /* Call the card-specific watchdog routines. */
3542 if (TOP_TRYLOCK != 0)
3544 sc->status.oper_status = sc->card->watchdog(sc);
3546 /* Increment a counter which tells user-land */
3547 /* observers that SNMP state has been updated. */
3553 sc->status.cntrs.lck_watch++;
3555 /* In case an interrupt gets lost... */
3556 user_interrupt(sc, 1);
3560 /* Called from a syscall (user context; no spinlocks). */
3562 lmc_raw_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
3564 struct ifreq *ifr = (struct ifreq *) data;
3572 ifp->if_flags |= IFF_UP; /* a Unix tradition */
3575 ifp->if_mtu = ifr->ifr_mtu;
3584 /* Called from a syscall (user context; no spinlocks). */
3586 lmc_ifnet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
3588 softc_t *sc = IFP2SC(ifp);
3593 /* Catch the IOCTLs used by lmcconfig. */
3600 error = core_ioctl(sc, cmd, data);
3602 /* Pass the rest to the line protocol. */
3604 if (sc->config.line_pkg == PKG_RAWIP)
3605 error = lmc_raw_ioctl(ifp, cmd, data);
3608 error = sppp_ioctl(ifp, cmd, data);
3610 error = p2p_ioctl(ifp, cmd, data);
3617 if (DRIVER_DEBUG && (error!=0))
3618 printf("%s: lmc_ifnet_ioctl; cmd=0x%08lx error=%d\n",
3619 NAME_UNIT, cmd, error);
3624 /* Called from a syscall (user context; no spinlocks). */
3626 lmc_ifnet_start(struct ifnet *ifp)
3628 softc_t *sc = IFP2SC(ifp);
3630 /* Start the transmitter; incoming pkts are NOT processed. */
3631 user_interrupt(sc, 0);
3634 /* sppp and p2p replace this with their own proc. */
3635 /* RAWIP mode is the only time this is used. */
3636 /* Called from a syscall (user context; no spinlocks). */
3638 lmc_raw_output(struct ifnet *ifp, struct mbuf *m,
3639 const struct sockaddr *dst, struct route *ro)
3641 softc_t *sc = IFP2SC(ifp);
3644 /* Fail if the link is down. */
3645 if (sc->status.oper_status != STATUS_UP)
3648 sc->status.cntrs.odiscards++;
3650 printf("%s: lmc_raw_output: tx pkt discarded: link down\n", NAME_UNIT);
3655 /* Netgraph has priority over the ifnet kernel interface. */
3656 if (sc->ng_hook != NULL)
3659 sc->status.cntrs.odiscards++;
3661 printf("%s: lmc_raw_output: tx pkt discarded: netgraph active\n",
3667 /* lmc_raw_output() ENQUEUEs in a syscall or softirq. */
3668 /* txintr_setup() DEQUEUEs in a hard interrupt. */
3669 /* Some BSD QUEUE routines are not interrupt-safe. */
3672 IFQ_ENQUEUE(&ifp->if_snd, m, error);
3677 user_interrupt(sc, 0); /* start the transmitter */
3681 sc->status.cntrs.odiscards++;
3682 if_inc_counter(ifp, IFCOUNTER_OQDROPS, 1);
3684 printf("%s: lmc_raw_output: IFQ_ENQUEUE() failed; error %d\n",
3691 /* Called from a softirq once a second. */
3693 lmc_watchdog(void *arg)
3695 struct ifnet *ifp = arg;
3696 softc_t *sc = IFP2SC(ifp);
3697 u_int8_t old_oper_status = sc->status.oper_status;
3699 core_watchdog(sc); /* updates oper_status */
3702 if (sc->ng_hook != NULL)
3704 sc->status.line_pkg = PKG_NG;
3705 sc->status.line_prot = 0;
3709 if (sc->config.line_pkg == PKG_RAWIP)
3711 sc->status.line_pkg = PKG_RAWIP;
3712 sc->status.line_prot = PROT_IP_HDLC;
3717 /* Notice change in link status. */
3718 if ((old_oper_status != sc->status.oper_status) && (sc->p2p->p2p_modem))
3719 (*sc->p2p->p2p_modem)(sc->p2p, sc->status.oper_status==STATUS_UP);
3721 /* Notice change in line protocol. */
3722 sc->status.line_pkg = PKG_P2P;
3723 switch (sc->ifp->if_type)
3726 sc->status.line_prot = PROT_PPP;
3729 sc->status.line_prot = PROT_C_HDLC;
3732 sc->status.line_prot = PROT_FRM_RLY;
3735 sc->status.line_prot = 0;
3740 /* Notice change in link status. */
3741 if ((old_oper_status != STATUS_UP) &&
3742 (sc->status.oper_status == STATUS_UP)) /* link came up */
3744 if ((old_oper_status == STATUS_UP) &&
3745 (sc->status.oper_status != STATUS_UP)) /* link went down */
3748 /* Notice change in line protocol. */
3749 sc->status.line_pkg = PKG_SPPP;
3750 if (sc->sppp->pp_flags & PP_FR)
3751 sc->status.line_prot = PROT_FRM_RLY;
3752 else if (sc->ifp->if_flags & IFF_LINK2)
3753 sc->status.line_prot = PROT_C_HDLC;
3755 sc->status.line_prot = PROT_PPP;
3758 /* Suppress compiler warning. */
3759 if (old_oper_status == STATUS_UP);
3763 ifp->if_baudrate = sc->status.tx_speed;
3764 if (sc->status.oper_status == STATUS_UP)
3765 ifp->if_link_state = LINK_STATE_UP;
3767 ifp->if_link_state = LINK_STATE_DOWN;
3769 /* Call this procedure again after one second. */
3770 callout_reset(&sc->callout, hz, lmc_watchdog, ifp);
3774 lmc_get_counter(struct ifnet *ifp, ift_counter cnt)
3777 struct event_cntrs *cntrs;
3779 sc = if_getsoftc(ifp);
3780 cntrs = &sc->status.cntrs;
3783 case IFCOUNTER_IPACKETS:
3784 return (cntrs->ipackets);
3785 case IFCOUNTER_OPACKETS:
3786 return (cntrs->opackets);
3787 case IFCOUNTER_IBYTES:
3788 return (cntrs->ibytes);
3789 case IFCOUNTER_OBYTES:
3790 return (cntrs->obytes);
3791 case IFCOUNTER_IERRORS:
3792 return (cntrs->ierrors);
3793 case IFCOUNTER_OERRORS:
3794 return (cntrs->oerrors);
3795 case IFCOUNTER_IQDROPS:
3796 return (cntrs->idiscards);
3798 return (if_get_counter_default(ifp, cnt));
3803 setup_ifnet(struct ifnet *ifp)
3805 softc_t *sc = ifp->if_softc;
3807 /* Initialize the generic network interface. */
3808 ifp->if_flags = IFF_POINTOPOINT;
3809 ifp->if_flags |= IFF_RUNNING;
3810 ifp->if_ioctl = lmc_ifnet_ioctl;
3811 ifp->if_start = lmc_ifnet_start; /* sppp changes this */
3812 ifp->if_output = lmc_raw_output; /* sppp & p2p change this */
3813 ifp->if_input = lmc_raw_input;
3814 ifp->if_get_counter = lmc_get_counter;
3815 ifp->if_mtu = MAX_DESC_LEN; /* sppp & p2p change this */
3816 ifp->if_type = IFT_PTPSERIAL; /* p2p changes this */
3818 # if defined(DEVICE_POLLING)
3819 ifp->if_capabilities |= IFCAP_POLLING;
3820 ifp->if_capenable |= IFCAP_POLLING_NOCOUNT;
3823 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
3827 lmc_ifnet_attach(softc_t *sc)
3829 sc->ifp = if_alloc(NSPPP ? IFT_PPP : IFT_OTHER);
3830 if (sc->ifp == NULL) return ENOMEM;
3832 sc->sppp = sc->ifp->if_l2com;
3834 sc->ifp = &sc->p2pcom.p2p_if;
3835 sc->p2p = &sc->p2pcom;
3838 /* Initialize the network interface struct. */
3839 sc->ifp->if_softc = sc;
3840 setup_ifnet(sc->ifp);
3842 /* ALTQ output queue initialization. */
3843 IFQ_SET_MAXLEN(&sc->ifp->if_snd, SNDQ_MAXLEN);
3844 IFQ_SET_READY(&sc->ifp->if_snd);
3846 /* Attach to the ifnet kernel interface. */
3849 /* Attach Berkeley Packet Filter. */
3850 LMC_BPF_ATTACH(DLT_RAW, 0);
3852 callout_reset(&sc->callout, hz, lmc_watchdog, sc);
3858 lmc_ifnet_detach(softc_t *sc)
3861 # if defined(DEVICE_POLLING)
3862 if (sc->ifp->if_capenable & IFCAP_POLLING)
3863 ether_poll_deregister(sc->ifp);
3866 /* Detach Berkeley Packet Filter. */
3869 /* Detach from the ifnet kernel interface. */
3878 /* These next two macros should be added to netgraph */
3879 # define NG_TYPE_REF(type) atomic_add_int(&(type)->refs, 1)
3880 # define NG_TYPE_UNREF(type) \
3882 if ((type)->refs == 1) \
3885 atomic_subtract_int(&(type)->refs, 1); \
3888 /* It is an error to construct new copies of this Netgraph node. */
3889 /* All instances are constructed by ng_attach and are persistent. */
3890 static int ng_constructor(node_p node) { return EINVAL; }
3892 /* Incoming Netgraph control message. */
3894 ng_rcvmsg(node_p node, item_p item, hook_p lasthook)
3896 struct ng_mesg *msg;
3897 struct ng_mesg *resp = NULL;
3898 softc_t *sc = NG_NODE_PRIVATE(node);
3901 NGI_GET_MSG(item, msg);
3902 if (msg->header.typecookie == NGM_LMC_COOKIE)
3904 switch (msg->header.cmd)
3913 /* Call the core ioctl procedure. */
3914 error = core_ioctl(sc, msg->header.cmd, msg->data);
3915 if ((msg->header.cmd & IOC_OUT) != 0)
3916 { /* synchronous response */
3917 NG_MKRESPONSE(resp, msg, sizeof(struct ng_mesg) +
3918 IOCPARM_LEN(msg->header.cmd), M_NOWAIT);
3922 memcpy(resp->data, msg->data, IOCPARM_LEN(msg->header.cmd));
3931 else if ((msg->header.typecookie == NGM_GENERIC_COOKIE) &&
3932 (msg->header.cmd == NGM_TEXT_STATUS))
3933 { /* synchronous response */
3934 NG_MKRESPONSE(resp, msg, sizeof(struct ng_mesg) +
3935 NG_TEXTRESPONSE, M_NOWAIT);
3940 char *s = resp->data;
3941 sprintf(s, "Card type = <%s>\n"
3942 "This driver considers the link to be %s.\n"
3943 "Use lmcconfig to configure this interface.\n",
3944 sc->dev_desc, (sc->status.oper_status==STATUS_UP) ? "UP" : "DOWN");
3945 resp->header.arglen = strlen(s) +1;
3949 /* Netgraph should be able to read and write these
3950 * parameters with text-format control messages:
3953 * loop loop loop loop
3955 * dte dte format format
3956 * synth synth cablen cablen
3957 * cable timeslot scram
3961 * Someday I'll implement this...
3965 /* Handle synchronous response. */
3966 NG_RESPOND_MSG(error, node, item, resp);
3972 /* This is a persistent netgraph node. */
3974 ng_shutdown(node_p node)
3976 /* unless told to really die, bounce back to life */
3977 if ((node->nd_flags & NG_REALLY_DIE)==0)
3978 node->nd_flags &= ~NG_INVALID; /* bounce back to life */
3983 /* ng_disconnect is the opposite of this procedure. */
3985 ng_newhook(node_p node, hook_p hook, const char *name)
3987 softc_t *sc = NG_NODE_PRIVATE(node);
3989 /* Hook name must be 'rawdata'. */
3990 if (strncmp(name, "rawdata", 7) != 0) return EINVAL;
3992 /* Is our hook connected? */
3993 if (sc->ng_hook != NULL) return EBUSY;
3995 /* Accept the hook. */
4001 /* Both ends have accepted their hooks and the links have been made. */
4002 /* This is the last chance to reject the connection request. */
4004 ng_connect(hook_p hook)
4006 /* Probably not at splnet, force outward queueing. (huh?) */
4007 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
4008 return 0; /* always accept */
4011 /* Receive data in mbufs from another Netgraph node. */
4012 /* Transmit an mbuf-chain on the communication link. */
4013 /* This procedure is very similar to lmc_raw_output(). */
4014 /* Called from a syscall (user context; no spinlocks). */
4016 ng_rcvdata(hook_p hook, item_p item)
4018 softc_t *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
4024 NGI_GET_META(item, meta);
4027 /* This macro must not store into meta! */
4030 /* Fail if the link is down. */
4031 if (sc->status.oper_status != STATUS_UP)
4034 sc->status.cntrs.odiscards++;
4036 printf("%s: ng_rcvdata: tx pkt discarded: link down\n", NAME_UNIT);
4040 /* ng_rcvdata() ENQUEUEs in a syscall or softirq. */
4041 /* txintr_setup() DEQUEUEs in a hard interrupt. */
4042 /* Some BSD QUEUE routines are not interrupt-safe. */
4046 IFQ_ENQUEUE(&sc->ng_sndq, m, error);
4048 IFQ_ENQUEUE(&sc->ng_fastq, m, error);
4053 user_interrupt(sc, 0); /* start the transmitter */
4057 sc->status.cntrs.odiscards++;
4059 printf("%s: ng_rcvdata: IFQ_ENQUEUE() failed; error %d\n",
4066 /* ng_newhook is the opposite of this procedure, not */
4067 /* ng_connect, as you might expect from the names. */
4069 ng_disconnect(hook_p hook)
4071 softc_t *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
4073 /* Disconnect the hook. */
4080 struct ng_type ng_type =
4082 .version = NG_ABI_VERSION,
4083 .name = NG_LMC_NODE_TYPE,
4085 .constructor = ng_constructor,
4086 .rcvmsg = ng_rcvmsg,
4088 .shutdown = ng_shutdown,
4089 .newhook = ng_newhook,
4091 .connect = ng_connect,
4092 .rcvdata = ng_rcvdata,
4093 .disconnect = ng_disconnect,
4097 /* Attach to the Netgraph kernel interface (/sys/netgraph).
4098 * It is called once for each physical card during device attach.
4099 * This is effectively ng_constructor.
4102 ng_attach(softc_t *sc)
4106 /* If this node type is not known to Netgraph then register it. */
4107 if (ng_type.refs == 0) /* or: if (ng_findtype(&ng_type) == NULL) */
4109 if ((error = ng_newtype(&ng_type)))
4111 printf("%s: ng_newtype() failed; error %d\n", NAME_UNIT, error);
4116 NG_TYPE_REF(&ng_type);
4118 /* Call the superclass node constructor. */
4119 if ((error = ng_make_node_common(&ng_type, &sc->ng_node)))
4121 NG_TYPE_UNREF(&ng_type);
4122 printf("%s: ng_make_node_common() failed; error %d\n", NAME_UNIT, error);
4126 /* Associate a name with this netgraph node. */
4127 if ((error = ng_name_node(sc->ng_node, NAME_UNIT)))
4129 NG_NODE_UNREF(sc->ng_node);
4130 NG_TYPE_UNREF(&ng_type);
4131 printf("%s: ng_name_node() failed; error %d\n", NAME_UNIT, error);
4135 /* Initialize the send queue mutexes. */
4136 mtx_init(&sc->ng_sndq.ifq_mtx, NAME_UNIT, "sndq", MTX_DEF);
4137 mtx_init(&sc->ng_fastq.ifq_mtx, NAME_UNIT, "fastq", MTX_DEF);
4139 /* Put a backpointer to the softc in the netgraph node. */
4140 NG_NODE_SET_PRIVATE(sc->ng_node, sc);
4142 /* ALTQ output queue initialization. */
4143 IFQ_SET_MAXLEN(&sc->ng_fastq, SNDQ_MAXLEN);
4144 IFQ_SET_READY(&sc->ng_fastq);
4145 IFQ_SET_MAXLEN(&sc->ng_sndq, SNDQ_MAXLEN);
4146 IFQ_SET_READY(&sc->ng_sndq);
4153 ng_detach(softc_t *sc)
4155 callout_drain(&sc->callout);
4156 mtx_destroy(&sc->ng_sndq.ifq_mtx);
4157 mtx_destroy(&sc->ng_fastq.ifq_mtx);
4158 ng_rmnode_self(sc->ng_node); /* free hook */
4159 NG_NODE_UNREF(sc->ng_node); /* free node */
4160 NG_TYPE_UNREF(&ng_type);
4163 #endif /* NETGRAPH */
4165 /* The next few procedures initialize the card. */
4167 /* Returns 0 on success; error code on failure. */
4169 startup_card(softc_t *sc)
4171 int num_rx_descs, error = 0;
4172 u_int32_t tlp_bus_pbl, tlp_bus_cal, tlp_op_tr;
4173 u_int32_t tlp_cfdd, tlp_cfcs;
4174 u_int32_t tlp_cflt, tlp_csid, tlp_cfit;
4176 /* Make sure the COMMAND bits are reasonable. */
4177 tlp_cfcs = READ_PCI_CFG(sc, TLP_CFCS);
4178 tlp_cfcs &= ~TLP_CFCS_MWI_ENABLE;
4179 tlp_cfcs |= TLP_CFCS_BUS_MASTER;
4180 tlp_cfcs |= TLP_CFCS_MEM_ENABLE;
4181 tlp_cfcs |= TLP_CFCS_IO_ENABLE;
4182 tlp_cfcs |= TLP_CFCS_PAR_ERROR;
4183 tlp_cfcs |= TLP_CFCS_SYS_ERROR;
4184 WRITE_PCI_CFG(sc, TLP_CFCS, tlp_cfcs);
4186 /* Set the LATENCY TIMER to the recommended value, */
4187 /* and make sure the CACHE LINE SIZE is reasonable. */
4188 tlp_cfit = READ_PCI_CFG(sc, TLP_CFIT);
4189 tlp_cflt = READ_PCI_CFG(sc, TLP_CFLT);
4190 tlp_cflt &= ~TLP_CFLT_LATENCY;
4191 tlp_cflt |= (tlp_cfit & TLP_CFIT_MAX_LAT)>>16;
4192 /* "prgmbl burst length" and "cache alignment" used below. */
4193 switch(tlp_cflt & TLP_CFLT_CACHE)
4195 case 8: /* 8 bytes per cache line */
4196 { tlp_bus_pbl = 32; tlp_bus_cal = 1; break; }
4198 { tlp_bus_pbl = 32; tlp_bus_cal = 2; break; }
4200 { tlp_bus_pbl = 32; tlp_bus_cal = 3; break; }
4203 tlp_bus_pbl = 32; tlp_bus_cal = 1;
4204 tlp_cflt &= ~TLP_CFLT_CACHE;
4209 WRITE_PCI_CFG(sc, TLP_CFLT, tlp_cflt);
4211 /* Make sure SNOOZE and SLEEP modes are disabled. */
4212 tlp_cfdd = READ_PCI_CFG(sc, TLP_CFDD);
4213 tlp_cfdd &= ~TLP_CFDD_SLEEP;
4214 tlp_cfdd &= ~TLP_CFDD_SNOOZE;
4215 WRITE_PCI_CFG(sc, TLP_CFDD, tlp_cfdd);
4216 DELAY(11*1000); /* Tulip wakes up in 10 ms max */
4218 /* Software Reset the Tulip chip; stops DMA and Interrupts. */
4219 /* This does not change the PCI config regs just set above. */
4220 WRITE_CSR(TLP_BUS_MODE, TLP_BUS_RESET); /* self-clearing */
4221 DELAY(5); /* Tulip is dead for 50 PCI cycles after reset. */
4223 /* Reset the Xilinx Field Programmable Gate Array. */
4224 reset_xilinx(sc); /* side effect: turns on all four LEDs */
4226 /* Configure card-specific stuff (framers, line interfaces, etc.). */
4227 sc->card->config(sc);
4229 /* Initializing cards can glitch clocks and upset fifos. */
4230 /* Reset the FIFOs between the Tulip and Xilinx chips. */
4231 set_mii16_bits(sc, MII16_FIFO);
4232 clr_mii16_bits(sc, MII16_FIFO);
4234 /* Initialize the PCI busmode register. */
4235 /* The PCI bus cycle type "Memory Write and Invalidate" does NOT */
4236 /* work cleanly in any version of the 21140A, so don't enable it! */
4237 WRITE_CSR(TLP_BUS_MODE,
4238 (tlp_bus_cal ? TLP_BUS_READ_LINE : 0) |
4239 (tlp_bus_cal ? TLP_BUS_READ_MULT : 0) |
4240 (tlp_bus_pbl<<TLP_BUS_PBL_SHIFT) |
4241 (tlp_bus_cal<<TLP_BUS_CAL_SHIFT) |
4242 ((BYTE_ORDER == BIG_ENDIAN) ? TLP_BUS_DESC_BIGEND : 0) |
4243 ((BYTE_ORDER == BIG_ENDIAN) ? TLP_BUS_DATA_BIGEND : 0) |
4247 /* Pick number of RX descriptors and TX fifo threshold. */
4248 /* tx_threshold in bytes: 0=128, 1=256, 2=512, 3=1024 */
4249 tlp_csid = READ_PCI_CFG(sc, TLP_CSID);
4252 case TLP_CSID_HSSI: /* 52 Mb/s */
4253 case TLP_CSID_HSSIc: /* 52 Mb/s */
4254 case TLP_CSID_T3: /* 45 Mb/s */
4255 { num_rx_descs = 48; tlp_op_tr = 2; break; }
4256 case TLP_CSID_SSI: /* 10 Mb/s */
4257 { num_rx_descs = 32; tlp_op_tr = 1; break; }
4258 case TLP_CSID_T1E1: /* 2 Mb/s */
4259 { num_rx_descs = 16; tlp_op_tr = 0; break; }
4261 { num_rx_descs = 16; tlp_op_tr = 0; break; }
4264 /* Create DMA descriptors and initialize list head registers. */
4265 if ((error = create_ring(sc, &sc->txring, NUM_TX_DESCS))) return error;
4266 WRITE_CSR(TLP_TX_LIST, sc->txring.dma_addr);
4267 if ((error = create_ring(sc, &sc->rxring, num_rx_descs))) return error;
4268 WRITE_CSR(TLP_RX_LIST, sc->rxring.dma_addr);
4270 /* Initialize the operating mode register. */
4271 WRITE_CSR(TLP_OP_MODE, TLP_OP_INIT | (tlp_op_tr<<TLP_OP_TR_SHIFT));
4273 /* Read the missed frame register (result ignored) to zero it. */
4274 error = READ_CSR( TLP_MISSED); /* error is used as a bit-dump */
4276 /* Disable rx watchdog and tx jabber features. */
4277 WRITE_CSR(TLP_WDOG, TLP_WDOG_INIT);
4279 /* Enable card interrupts. */
4280 WRITE_CSR(TLP_INT_ENBL, TLP_INT_TXRX);
4285 /* Stop DMA and Interrupts; free descriptors and buffers. */
4287 shutdown_card(void *arg)
4291 /* Leave the LEDs in the state they were in after power-on. */
4292 led_on(sc, MII16_LED_ALL);
4294 /* Software reset the Tulip chip; stops DMA and Interrupts */
4295 WRITE_CSR(TLP_BUS_MODE, TLP_BUS_RESET); /* self-clearing */
4296 DELAY(5); /* Tulip is dead for 50 PCI cycles after reset. */
4298 /* Disconnect from the PCI bus except for config cycles. */
4299 /* Hmmm; Linux syslogs a warning that IO and MEM are disabled. */
4300 WRITE_PCI_CFG(sc, TLP_CFCS, TLP_CFCS_MEM_ENABLE | TLP_CFCS_IO_ENABLE);
4302 /* Free the DMA descriptor rings. */
4303 destroy_ring(sc, &sc->txring);
4304 destroy_ring(sc, &sc->rxring);
4307 /* Start the card and attach a kernel interface and line protocol. */
4309 attach_card(softc_t *sc, const char *intrstr)
4311 struct config config;
4317 /* Start the card. */
4318 if ((error = startup_card(sc))) return error;
4320 callout_init(&sc->callout, 0);
4322 /* Attach a kernel interface. */
4324 if ((error = ng_attach(sc))) return error;
4325 sc->flags |= FLAG_NETGRAPH;
4327 if ((error = lmc_ifnet_attach(sc))) return error;
4328 sc->flags |= FLAG_IFNET;
4330 /* Attach a line protocol stack. */
4331 sc->config.line_pkg = PKG_RAWIP;
4332 config = sc->config; /* get current config */
4333 config.line_pkg = 0; /* select external stack */
4334 config.line_prot = PROT_C_HDLC;
4335 config.keep_alive = 1;
4336 config_proto(sc, &config); /* reconfigure */
4337 sc->config = config; /* save new configuration */
4339 /* Print interesting hardware-related things. */
4340 mii3 = read_mii(sc, 3);
4341 tlp_cfrv = READ_PCI_CFG(sc, TLP_CFRV);
4342 printf("%s: PCI rev %d.%d, MII rev %d.%d", NAME_UNIT,
4343 (tlp_cfrv>>4) & 0xF, tlp_cfrv & 0xF, (mii3>>4) & 0xF, mii3 & 0xF);
4344 ieee = (u_int8_t *)sc->status.ieee;
4345 for (i=0; i<3; i++) sc->status.ieee[i] = read_srom(sc, 10+i);
4346 printf(", IEEE addr %02x:%02x:%02x:%02x:%02x:%02x",
4347 ieee[0], ieee[1], ieee[2], ieee[3], ieee[4], ieee[5]);
4348 sc->card->ident(sc);
4349 printf(" %s\n", intrstr);
4351 /* Print interesting software-related things. */
4352 printf("%s: Driver rev %d.%d.%d", NAME_UNIT,
4353 DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION, DRIVER_SUB_VERSION);
4354 printf(", Options %s%s%s%s%s%s%s%s%s\n",
4355 NETGRAPH ? "NETGRAPH " : "", GEN_HDLC ? "GEN_HDLC " : "",
4356 NSPPP ? "SPPP " : "", P2P ? "P2P " : "",
4357 ALTQ_PRESENT ? "ALTQ " : "", NBPFILTER ? "BPF " : "",
4358 DEV_POLL ? "POLL " : "", IOREF_CSR ? "IO_CSR " : "MEM_CSR ",
4359 (BYTE_ORDER == BIG_ENDIAN) ? "BIG_END " : "LITTLE_END ");
4361 /* Make the local hardware ready. */
4367 /* Detach from the kernel in all ways. */
4369 detach_card(softc_t *sc)
4371 struct config config;
4373 /* Make the local hardware NOT ready. */
4376 /* Detach external line protocol stack. */
4377 if (sc->config.line_pkg != PKG_RAWIP)
4379 config = sc->config;
4380 config.line_pkg = PKG_RAWIP;
4381 config_proto(sc, &config);
4382 sc->config = config;
4385 /* Detach kernel interfaces. */
4387 if (sc->flags & FLAG_NETGRAPH)
4389 IFQ_PURGE(&sc->ng_fastq);
4390 IFQ_PURGE(&sc->ng_sndq);
4392 sc->flags &= ~FLAG_NETGRAPH;
4395 if (sc->flags & FLAG_IFNET)
4397 IFQ_PURGE(&sc->ifp->if_snd);
4398 lmc_ifnet_detach(sc);
4399 sc->flags &= ~FLAG_IFNET;
4402 /* Reset the Tulip chip; stops DMA and Interrupts. */
4406 /* This is the I/O configuration interface for FreeBSD */
4410 fbsd_probe(device_t dev)
4412 u_int32_t cfid = pci_read_config(dev, TLP_CFID, 4);
4413 u_int32_t csid = pci_read_config(dev, TLP_CSID, 4);
4415 /* Looking for a DEC 21140A chip on any Lan Media Corp card. */
4416 if (cfid != TLP_CFID_TULIP) return ENXIO;
4420 case TLP_CSID_HSSIc:
4421 device_set_desc(dev, HSSI_DESC);
4424 device_set_desc(dev, T3_DESC);
4427 device_set_desc(dev, SSI_DESC);
4430 device_set_desc(dev, T1E1_DESC);
4439 fbsd_detach(device_t dev)
4441 softc_t *sc = device_get_softc(dev);
4443 /* Stop the card and detach from the kernel. */
4446 /* Release resources. */
4447 if (sc->irq_cookie != NULL)
4449 bus_teardown_intr(dev, sc->irq_res, sc->irq_cookie);
4450 sc->irq_cookie = NULL;
4452 if (sc->irq_res != NULL)
4454 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_res_id, sc->irq_res);
4457 if (sc->csr_res != NULL)
4459 bus_release_resource(dev, sc->csr_res_type, sc->csr_res_id, sc->csr_res);
4463 mtx_destroy(&sc->top_mtx);
4464 mtx_destroy(&sc->bottom_mtx);
4465 return 0; /* no error */
4469 fbsd_shutdown(device_t dev)
4471 shutdown_card(device_get_softc(dev));
4476 fbsd_attach(device_t dev)
4478 softc_t *sc = device_get_softc(dev);
4481 /* READ/WRITE_PCI_CFG need this. */
4484 /* What kind of card are we driving? */
4485 switch (READ_PCI_CFG(sc, TLP_CSID))
4488 case TLP_CSID_HSSIc:
4489 sc->card = &hssi_card;
4492 sc->card = &t3_card;
4495 sc->card = &ssi_card;
4498 sc->card = &t1_card;
4503 sc->dev_desc = device_get_desc(dev);
4505 /* Allocate PCI memory or IO resources to access the Tulip chip CSRs. */
4507 sc->csr_res_id = TLP_CBIO;
4508 sc->csr_res_type = SYS_RES_IOPORT;
4510 sc->csr_res_id = TLP_CBMA;
4511 sc->csr_res_type = SYS_RES_MEMORY;
4513 sc->csr_res = bus_alloc_resource(dev, sc->csr_res_type, &sc->csr_res_id,
4514 0, ~0, 1, RF_ACTIVE);
4515 if (sc->csr_res == NULL)
4517 printf("%s: bus_alloc_resource(csr) failed.\n", NAME_UNIT);
4520 sc->csr_tag = rman_get_bustag(sc->csr_res);
4521 sc->csr_handle = rman_get_bushandle(sc->csr_res);
4523 /* Allocate PCI interrupt resources for the card. */
4525 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_res_id,
4526 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
4527 if (sc->irq_res == NULL)
4529 printf("%s: bus_alloc_resource(irq) failed.\n", NAME_UNIT);
4533 if ((error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
4534 NULL, bsd_interrupt, sc, &sc->irq_cookie)))
4536 printf("%s: bus_setup_intr() failed; error %d\n", NAME_UNIT, error);
4541 /* Initialize the top-half and bottom-half locks. */
4542 mtx_init(&sc->top_mtx, NAME_UNIT, "top half lock", MTX_DEF);
4543 mtx_init(&sc->bottom_mtx, NAME_UNIT, "bottom half lock", MTX_DEF);
4545 /* Start the card and attach a kernel interface and line protocol. */
4546 if ((error = attach_card(sc, ""))) detach_card(sc);
4550 static device_method_t methods[] =
4552 DEVMETHOD(device_probe, fbsd_probe),
4553 DEVMETHOD(device_attach, fbsd_attach),
4554 DEVMETHOD(device_detach, fbsd_detach),
4555 DEVMETHOD(device_shutdown, fbsd_shutdown),
4556 /* This driver does not suspend and resume. */
4560 static driver_t driver =
4562 .name = DEVICE_NAME,
4564 .size = sizeof(softc_t),
4567 static devclass_t devclass;
4569 DRIVER_MODULE(lmc, pci, driver, devclass, 0, 0);
4570 MODULE_VERSION(lmc, 2);
4571 MODULE_DEPEND(lmc, pci, 1, 1, 1);
4573 MODULE_DEPEND(lmc, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION);
4576 MODULE_DEPEND(lmc, sppp, 1, 1, 1);
4580 /* This is the I/O configuration interface for NetBSD. */
4583 /* This is the I/O configuration interface for OpenBSD. */
4586 /* This is the I/O configuration interface for BSD/OS. */