Deleted Added
full compact
if_tl.c (93818) if_tl.c (102336)
1/*
2 * Copyright (c) 1997, 1998
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 1997, 1998
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: head/sys/pci/if_tl.c 93818 2002-04-04 21:03:38Z jhb $
32 * $FreeBSD: head/sys/pci/if_tl.c 102336 2002-08-24 00:02:03Z alfred $
33 */
34
35/*
36 * Texas Instruments ThunderLAN driver for FreeBSD 2.2.6 and 3.x.
37 * Supports many Compaq PCI NICs based on the ThunderLAN ethernet controller,
38 * the National Semiconductor DP83840A physical interface and the
39 * Microchip Technology 24Cxx series serial EEPROM.
40 *

--- 179 unchanged lines hidden (view full) ---

220
221MODULE_DEPEND(tl, miibus, 1, 1, 1);
222
223/* "controller miibus0" required. See GENERIC if you get errors here. */
224#include "miibus_if.h"
225
226#if !defined(lint)
227static const char rcsid[] =
33 */
34
35/*
36 * Texas Instruments ThunderLAN driver for FreeBSD 2.2.6 and 3.x.
37 * Supports many Compaq PCI NICs based on the ThunderLAN ethernet controller,
38 * the National Semiconductor DP83840A physical interface and the
39 * Microchip Technology 24Cxx series serial EEPROM.
40 *

--- 179 unchanged lines hidden (view full) ---

220
221MODULE_DEPEND(tl, miibus, 1, 1, 1);
222
223/* "controller miibus0" required. See GENERIC if you get errors here. */
224#include "miibus_if.h"
225
226#if !defined(lint)
227static const char rcsid[] =
228 "$FreeBSD: head/sys/pci/if_tl.c 93818 2002-04-04 21:03:38Z jhb $";
228 "$FreeBSD: head/sys/pci/if_tl.c 102336 2002-08-24 00:02:03Z alfred $";
229#endif
230
231/*
232 * Various supported device vendors/types and their names.
233 */
234
235static struct tl_type tl_devs[] = {
236 { TI_VENDORID, TI_DEVICEID_THUNDERLAN,

--- 171 unchanged lines hidden (view full) ---

408 int reg;
409 int val;
410{
411 CSR_WRITE_2(sc, TL_DIO_ADDR, reg);
412 CSR_WRITE_4(sc, TL_DIO_DATA + (reg & 3), val);
413 return;
414}
415
229#endif
230
231/*
232 * Various supported device vendors/types and their names.
233 */
234
235static struct tl_type tl_devs[] = {
236 { TI_VENDORID, TI_DEVICEID_THUNDERLAN,

--- 171 unchanged lines hidden (view full) ---

408 int reg;
409 int val;
410{
411 CSR_WRITE_2(sc, TL_DIO_ADDR, reg);
412 CSR_WRITE_4(sc, TL_DIO_DATA + (reg & 3), val);
413 return;
414}
415
416static void tl_dio_setbit(sc, reg, bit)
416static void
417tl_dio_setbit(sc, reg, bit)
417 struct tl_softc *sc;
418 int reg;
419 int bit;
420{
421 u_int8_t f;
422
423 CSR_WRITE_2(sc, TL_DIO_ADDR, reg);
424 f = CSR_READ_1(sc, TL_DIO_DATA + (reg & 3));
425 f |= bit;
426 CSR_WRITE_1(sc, TL_DIO_DATA + (reg & 3), f);
427
428 return;
429}
430
418 struct tl_softc *sc;
419 int reg;
420 int bit;
421{
422 u_int8_t f;
423
424 CSR_WRITE_2(sc, TL_DIO_ADDR, reg);
425 f = CSR_READ_1(sc, TL_DIO_DATA + (reg & 3));
426 f |= bit;
427 CSR_WRITE_1(sc, TL_DIO_DATA + (reg & 3), f);
428
429 return;
430}
431
431static void tl_dio_clrbit(sc, reg, bit)
432static void
433tl_dio_clrbit(sc, reg, bit)
432 struct tl_softc *sc;
433 int reg;
434 int bit;
435{
436 u_int8_t f;
437
438 CSR_WRITE_2(sc, TL_DIO_ADDR, reg);
439 f = CSR_READ_1(sc, TL_DIO_DATA + (reg & 3));

--- 143 unchanged lines hidden (view full) ---

583 *dest = byte;
584
585 return(0);
586}
587
588/*
589 * Read a sequence of bytes from the EEPROM.
590 */
434 struct tl_softc *sc;
435 int reg;
436 int bit;
437{
438 u_int8_t f;
439
440 CSR_WRITE_2(sc, TL_DIO_ADDR, reg);
441 f = CSR_READ_1(sc, TL_DIO_DATA + (reg & 3));

--- 143 unchanged lines hidden (view full) ---

585 *dest = byte;
586
587 return(0);
588}
589
590/*
591 * Read a sequence of bytes from the EEPROM.
592 */
591static int tl_read_eeprom(sc, dest, off, cnt)
593static int
594tl_read_eeprom(sc, dest, off, cnt)
592 struct tl_softc *sc;
593 caddr_t dest;
594 int off;
595 int cnt;
596{
597 int err = 0, i;
598 u_int8_t byte = 0;
599
600 for (i = 0; i < cnt; i++) {
601 err = tl_eeprom_getbyte(sc, off + i, &byte);
602 if (err)
603 break;
604 *(dest + i) = byte;
605 }
606
607 return(err ? 1 : 0);
608}
609
595 struct tl_softc *sc;
596 caddr_t dest;
597 int off;
598 int cnt;
599{
600 int err = 0, i;
601 u_int8_t byte = 0;
602
603 for (i = 0; i < cnt; i++) {
604 err = tl_eeprom_getbyte(sc, off + i, &byte);
605 if (err)
606 break;
607 *(dest + i) = byte;
608 }
609
610 return(err ? 1 : 0);
611}
612
610static void tl_mii_sync(sc)
613static void
614tl_mii_sync(sc)
611 struct tl_softc *sc;
612{
613 register int i;
614
615 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MTXEN);
616
617 for (i = 0; i < 32; i++) {
618 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MCLK);
619 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MCLK);
620 }
621
622 return;
623}
624
615 struct tl_softc *sc;
616{
617 register int i;
618
619 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MTXEN);
620
621 for (i = 0; i < 32; i++) {
622 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MCLK);
623 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MCLK);
624 }
625
626 return;
627}
628
625static void tl_mii_send(sc, bits, cnt)
629static void
630tl_mii_send(sc, bits, cnt)
626 struct tl_softc *sc;
627 u_int32_t bits;
628 int cnt;
629{
630 int i;
631
632 for (i = (0x1 << (cnt - 1)); i; i >>= 1) {
633 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MCLK);
634 if (bits & i) {
635 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MDATA);
636 } else {
637 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MDATA);
638 }
639 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MCLK);
640 }
641}
642
631 struct tl_softc *sc;
632 u_int32_t bits;
633 int cnt;
634{
635 int i;
636
637 for (i = (0x1 << (cnt - 1)); i; i >>= 1) {
638 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MCLK);
639 if (bits & i) {
640 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MDATA);
641 } else {
642 tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_MDATA);
643 }
644 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MCLK);
645 }
646}
647
643static int tl_mii_readreg(sc, frame)
648static int
649tl_mii_readreg(sc, frame)
644 struct tl_softc *sc;
645 struct tl_mii_frame *frame;
646
647{
648 int i, ack;
649 int minten = 0;
650
651 TL_LOCK(sc);

--- 78 unchanged lines hidden (view full) ---

730
731 TL_UNLOCK(sc);
732
733 if (ack)
734 return(1);
735 return(0);
736}
737
650 struct tl_softc *sc;
651 struct tl_mii_frame *frame;
652
653{
654 int i, ack;
655 int minten = 0;
656
657 TL_LOCK(sc);

--- 78 unchanged lines hidden (view full) ---

736
737 TL_UNLOCK(sc);
738
739 if (ack)
740 return(1);
741 return(0);
742}
743
738static int tl_mii_writereg(sc, frame)
744static int
745tl_mii_writereg(sc, frame)
739 struct tl_softc *sc;
740 struct tl_mii_frame *frame;
741
742{
743 int minten;
744
745 TL_LOCK(sc);
746

--- 39 unchanged lines hidden (view full) ---

786 if (minten)
787 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MINTEN);
788
789 TL_UNLOCK(sc);
790
791 return(0);
792}
793
746 struct tl_softc *sc;
747 struct tl_mii_frame *frame;
748
749{
750 int minten;
751
752 TL_LOCK(sc);
753

--- 39 unchanged lines hidden (view full) ---

793 if (minten)
794 tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MINTEN);
795
796 TL_UNLOCK(sc);
797
798 return(0);
799}
800
794static int tl_miibus_readreg(dev, phy, reg)
801static int
802tl_miibus_readreg(dev, phy, reg)
795 device_t dev;
796 int phy, reg;
797{
798 struct tl_softc *sc;
799 struct tl_mii_frame frame;
800
801 sc = device_get_softc(dev);
802 bzero((char *)&frame, sizeof(frame));
803
804 frame.mii_phyaddr = phy;
805 frame.mii_regaddr = reg;
806 tl_mii_readreg(sc, &frame);
807
808 return(frame.mii_data);
809}
810
803 device_t dev;
804 int phy, reg;
805{
806 struct tl_softc *sc;
807 struct tl_mii_frame frame;
808
809 sc = device_get_softc(dev);
810 bzero((char *)&frame, sizeof(frame));
811
812 frame.mii_phyaddr = phy;
813 frame.mii_regaddr = reg;
814 tl_mii_readreg(sc, &frame);
815
816 return(frame.mii_data);
817}
818
811static int tl_miibus_writereg(dev, phy, reg, data)
819static int
820tl_miibus_writereg(dev, phy, reg, data)
812 device_t dev;
813 int phy, reg, data;
814{
815 struct tl_softc *sc;
816 struct tl_mii_frame frame;
817
818 sc = device_get_softc(dev);
819 bzero((char *)&frame, sizeof(frame));
820
821 frame.mii_phyaddr = phy;
822 frame.mii_regaddr = reg;
823 frame.mii_data = data;
824
825 tl_mii_writereg(sc, &frame);
826
827 return(0);
828}
829
821 device_t dev;
822 int phy, reg, data;
823{
824 struct tl_softc *sc;
825 struct tl_mii_frame frame;
826
827 sc = device_get_softc(dev);
828 bzero((char *)&frame, sizeof(frame));
829
830 frame.mii_phyaddr = phy;
831 frame.mii_regaddr = reg;
832 frame.mii_data = data;
833
834 tl_mii_writereg(sc, &frame);
835
836 return(0);
837}
838
830static void tl_miibus_statchg(dev)
839static void
840tl_miibus_statchg(dev)
831 device_t dev;
832{
833 struct tl_softc *sc;
834 struct mii_data *mii;
835
836 sc = device_get_softc(dev);
837 TL_LOCK(sc);
838 mii = device_get_softc(sc->tl_miibus);

--- 6 unchanged lines hidden (view full) ---

845 TL_UNLOCK(sc);
846
847 return;
848}
849
850/*
851 * Set modes for bitrate devices.
852 */
841 device_t dev;
842{
843 struct tl_softc *sc;
844 struct mii_data *mii;
845
846 sc = device_get_softc(dev);
847 TL_LOCK(sc);
848 mii = device_get_softc(sc->tl_miibus);

--- 6 unchanged lines hidden (view full) ---

855 TL_UNLOCK(sc);
856
857 return;
858}
859
860/*
861 * Set modes for bitrate devices.
862 */
853static void tl_setmode(sc, media)
863static void
864tl_setmode(sc, media)
854 struct tl_softc *sc;
855 int media;
856{
857 if (IFM_SUBTYPE(media) == IFM_10_5)
858 tl_dio_setbit(sc, TL_ACOMMIT, TL_AC_MTXD1);
859 if (IFM_SUBTYPE(media) == IFM_10_T) {
860 tl_dio_clrbit(sc, TL_ACOMMIT, TL_AC_MTXD1);
861 if ((media & IFM_GMASK) == IFM_FDX) {

--- 12 unchanged lines hidden (view full) ---

874 * Calculate the hash of a MAC address for programming the multicast hash
875 * table. This hash is simply the address split into 6-bit chunks
876 * XOR'd, e.g.
877 * byte: 000000|00 1111|1111 22|222222|333333|33 4444|4444 55|555555
878 * bit: 765432|10 7654|3210 76|543210|765432|10 7654|3210 76|543210
879 * Bytes 0-2 and 3-5 are symmetrical, so are folded together. Then
880 * the folded 24-bit value is split into 6-bit portions and XOR'd.
881 */
865 struct tl_softc *sc;
866 int media;
867{
868 if (IFM_SUBTYPE(media) == IFM_10_5)
869 tl_dio_setbit(sc, TL_ACOMMIT, TL_AC_MTXD1);
870 if (IFM_SUBTYPE(media) == IFM_10_T) {
871 tl_dio_clrbit(sc, TL_ACOMMIT, TL_AC_MTXD1);
872 if ((media & IFM_GMASK) == IFM_FDX) {

--- 12 unchanged lines hidden (view full) ---

885 * Calculate the hash of a MAC address for programming the multicast hash
886 * table. This hash is simply the address split into 6-bit chunks
887 * XOR'd, e.g.
888 * byte: 000000|00 1111|1111 22|222222|333333|33 4444|4444 55|555555
889 * bit: 765432|10 7654|3210 76|543210|765432|10 7654|3210 76|543210
890 * Bytes 0-2 and 3-5 are symmetrical, so are folded together. Then
891 * the folded 24-bit value is split into 6-bit portions and XOR'd.
892 */
882static int tl_calchash(addr)
893static int
894tl_calchash(addr)
883 caddr_t addr;
884{
885 int t;
886
887 t = (addr[0] ^ addr[3]) << 16 | (addr[1] ^ addr[4]) << 8 |
888 (addr[2] ^ addr[5]);
889 return ((t >> 18) ^ (t >> 12) ^ (t >> 6) ^ t) & 0x3f;
890}
891
892/*
893 * The ThunderLAN has a perfect MAC address filter in addition to
894 * the multicast hash filter. The perfect filter can be programmed
895 * with up to four MAC addresses. The first one is always used to
896 * hold the station address, which leaves us free to use the other
897 * three for multicast addresses.
898 */
895 caddr_t addr;
896{
897 int t;
898
899 t = (addr[0] ^ addr[3]) << 16 | (addr[1] ^ addr[4]) << 8 |
900 (addr[2] ^ addr[5]);
901 return ((t >> 18) ^ (t >> 12) ^ (t >> 6) ^ t) & 0x3f;
902}
903
904/*
905 * The ThunderLAN has a perfect MAC address filter in addition to
906 * the multicast hash filter. The perfect filter can be programmed
907 * with up to four MAC addresses. The first one is always used to
908 * hold the station address, which leaves us free to use the other
909 * three for multicast addresses.
910 */
899static void tl_setfilt(sc, addr, slot)
911static void
912tl_setfilt(sc, addr, slot)
900 struct tl_softc *sc;
901 caddr_t addr;
902 int slot;
903{
904 int i;
905 u_int16_t regaddr;
906
907 regaddr = TL_AREG0_B5 + (slot * ETHER_ADDR_LEN);

--- 15 unchanged lines hidden (view full) ---

923 * and into the hash table.
924 *
925 * Because the multicast list is a doubly-linked list as opposed to a
926 * circular queue, we don't have the ability to just grab the tail of
927 * the list and traverse it backwards. Instead, we have to traverse
928 * the list once to find the tail, then traverse it again backwards to
929 * update the multicast filter.
930 */
913 struct tl_softc *sc;
914 caddr_t addr;
915 int slot;
916{
917 int i;
918 u_int16_t regaddr;
919
920 regaddr = TL_AREG0_B5 + (slot * ETHER_ADDR_LEN);

--- 15 unchanged lines hidden (view full) ---

936 * and into the hash table.
937 *
938 * Because the multicast list is a doubly-linked list as opposed to a
939 * circular queue, we don't have the ability to just grab the tail of
940 * the list and traverse it backwards. Instead, we have to traverse
941 * the list once to find the tail, then traverse it again backwards to
942 * update the multicast filter.
943 */
931static void tl_setmulti(sc)
944static void
945tl_setmulti(sc)
932 struct tl_softc *sc;
933{
934 struct ifnet *ifp;
935 u_int32_t hashes[2] = { 0, 0 };
936 int h, i;
937 struct ifmultiaddr *ifma;
938 u_int8_t dummy[] = { 0, 0, 0, 0, 0 ,0 };
939 ifp = &sc->arpcom.ac_if;

--- 41 unchanged lines hidden (view full) ---

981}
982
983/*
984 * This routine is recommended by the ThunderLAN manual to insure that
985 * the internal PHY is powered up correctly. It also recommends a one
986 * second pause at the end to 'wait for the clocks to start' but in my
987 * experience this isn't necessary.
988 */
946 struct tl_softc *sc;
947{
948 struct ifnet *ifp;
949 u_int32_t hashes[2] = { 0, 0 };
950 int h, i;
951 struct ifmultiaddr *ifma;
952 u_int8_t dummy[] = { 0, 0, 0, 0, 0 ,0 };
953 ifp = &sc->arpcom.ac_if;

--- 41 unchanged lines hidden (view full) ---

995}
996
997/*
998 * This routine is recommended by the ThunderLAN manual to insure that
999 * the internal PHY is powered up correctly. It also recommends a one
1000 * second pause at the end to 'wait for the clocks to start' but in my
1001 * experience this isn't necessary.
1002 */
989static void tl_hardreset(dev)
1003static void
1004tl_hardreset(dev)
990 device_t dev;
991{
992 struct tl_softc *sc;
993 int i;
994 u_int16_t flags;
995
996 sc = device_get_softc(dev);
997

--- 9 unchanged lines hidden (view full) ---

1007 tl_miibus_writereg(dev, 31, MII_BMCR, BMCR_LOOP|BMCR_ISO);
1008 tl_mii_sync(sc);
1009 while(tl_miibus_readreg(dev, 31, MII_BMCR) & BMCR_RESET);
1010
1011 DELAY(50000);
1012 return;
1013}
1014
1005 device_t dev;
1006{
1007 struct tl_softc *sc;
1008 int i;
1009 u_int16_t flags;
1010
1011 sc = device_get_softc(dev);
1012

--- 9 unchanged lines hidden (view full) ---

1022 tl_miibus_writereg(dev, 31, MII_BMCR, BMCR_LOOP|BMCR_ISO);
1023 tl_mii_sync(sc);
1024 while(tl_miibus_readreg(dev, 31, MII_BMCR) & BMCR_RESET);
1025
1026 DELAY(50000);
1027 return;
1028}
1029
1015static void tl_softreset(sc, internal)
1030static void
1031tl_softreset(sc, internal)
1016 struct tl_softc *sc;
1017 int internal;
1018{
1019 u_int32_t cmd, dummy, i;
1020
1021 /* Assert the adapter reset bit. */
1022 CMD_SET(sc, TL_CMD_ADRST);
1023

--- 45 unchanged lines hidden (view full) ---

1069
1070 return;
1071}
1072
1073/*
1074 * Probe for a ThunderLAN chip. Check the PCI vendor and device IDs
1075 * against our list and return its name if we find a match.
1076 */
1032 struct tl_softc *sc;
1033 int internal;
1034{
1035 u_int32_t cmd, dummy, i;
1036
1037 /* Assert the adapter reset bit. */
1038 CMD_SET(sc, TL_CMD_ADRST);
1039

--- 45 unchanged lines hidden (view full) ---

1085
1086 return;
1087}
1088
1089/*
1090 * Probe for a ThunderLAN chip. Check the PCI vendor and device IDs
1091 * against our list and return its name if we find a match.
1092 */
1077static int tl_probe(dev)
1093static int
1094tl_probe(dev)
1078 device_t dev;
1079{
1080 struct tl_type *t;
1081
1082 t = tl_devs;
1083
1084 while(t->tl_name != NULL) {
1085 if ((pci_get_vendor(dev) == t->tl_vid) &&
1086 (pci_get_device(dev) == t->tl_did)) {
1087 device_set_desc(dev, t->tl_name);
1088 return(0);
1089 }
1090 t++;
1091 }
1092
1093 return(ENXIO);
1094}
1095
1095 device_t dev;
1096{
1097 struct tl_type *t;
1098
1099 t = tl_devs;
1100
1101 while(t->tl_name != NULL) {
1102 if ((pci_get_vendor(dev) == t->tl_vid) &&
1103 (pci_get_device(dev) == t->tl_did)) {
1104 device_set_desc(dev, t->tl_name);
1105 return(0);
1106 }
1107 t++;
1108 }
1109
1110 return(ENXIO);
1111}
1112
1096static int tl_attach(dev)
1113static int
1114tl_attach(dev)
1097 device_t dev;
1098{
1099 int i;
1100 u_int32_t command;
1101 u_int16_t did, vid;
1102 struct tl_type *t;
1103 struct ifnet *ifp;
1104 struct tl_softc *sc;

--- 230 unchanged lines hidden (view full) ---

1335 return(0);
1336
1337fail:
1338 TL_UNLOCK(sc);
1339 mtx_destroy(&sc->tl_mtx);
1340 return(error);
1341}
1342
1115 device_t dev;
1116{
1117 int i;
1118 u_int32_t command;
1119 u_int16_t did, vid;
1120 struct tl_type *t;
1121 struct ifnet *ifp;
1122 struct tl_softc *sc;

--- 230 unchanged lines hidden (view full) ---

1353 return(0);
1354
1355fail:
1356 TL_UNLOCK(sc);
1357 mtx_destroy(&sc->tl_mtx);
1358 return(error);
1359}
1360
1343static int tl_detach(dev)
1361static int
1362tl_detach(dev)
1344 device_t dev;
1345{
1346 struct tl_softc *sc;
1347 struct ifnet *ifp;
1348
1349 sc = device_get_softc(dev);
1350 TL_LOCK(sc);
1351 ifp = &sc->arpcom.ac_if;

--- 16 unchanged lines hidden (view full) ---

1368 mtx_destroy(&sc->tl_mtx);
1369
1370 return(0);
1371}
1372
1373/*
1374 * Initialize the transmit lists.
1375 */
1363 device_t dev;
1364{
1365 struct tl_softc *sc;
1366 struct ifnet *ifp;
1367
1368 sc = device_get_softc(dev);
1369 TL_LOCK(sc);
1370 ifp = &sc->arpcom.ac_if;

--- 16 unchanged lines hidden (view full) ---

1387 mtx_destroy(&sc->tl_mtx);
1388
1389 return(0);
1390}
1391
1392/*
1393 * Initialize the transmit lists.
1394 */
1376static int tl_list_tx_init(sc)
1395static int
1396tl_list_tx_init(sc)
1377 struct tl_softc *sc;
1378{
1379 struct tl_chain_data *cd;
1380 struct tl_list_data *ld;
1381 int i;
1382
1383 cd = &sc->tl_cdata;
1384 ld = sc->tl_ldata;

--- 10 unchanged lines hidden (view full) ---

1395 sc->tl_txeoc = 1;
1396
1397 return(0);
1398}
1399
1400/*
1401 * Initialize the RX lists and allocate mbufs for them.
1402 */
1397 struct tl_softc *sc;
1398{
1399 struct tl_chain_data *cd;
1400 struct tl_list_data *ld;
1401 int i;
1402
1403 cd = &sc->tl_cdata;
1404 ld = sc->tl_ldata;

--- 10 unchanged lines hidden (view full) ---

1415 sc->tl_txeoc = 1;
1416
1417 return(0);
1418}
1419
1420/*
1421 * Initialize the RX lists and allocate mbufs for them.
1422 */
1403static int tl_list_rx_init(sc)
1423static int
1424tl_list_rx_init(sc)
1404 struct tl_softc *sc;
1405{
1406 struct tl_chain_data *cd;
1407 struct tl_list_data *ld;
1408 int i;
1409
1410 cd = &sc->tl_cdata;
1411 ld = sc->tl_ldata;

--- 14 unchanged lines hidden (view full) ---

1426 }
1427
1428 cd->tl_rx_head = &cd->tl_rx_chain[0];
1429 cd->tl_rx_tail = &cd->tl_rx_chain[TL_RX_LIST_CNT - 1];
1430
1431 return(0);
1432}
1433
1425 struct tl_softc *sc;
1426{
1427 struct tl_chain_data *cd;
1428 struct tl_list_data *ld;
1429 int i;
1430
1431 cd = &sc->tl_cdata;
1432 ld = sc->tl_ldata;

--- 14 unchanged lines hidden (view full) ---

1447 }
1448
1449 cd->tl_rx_head = &cd->tl_rx_chain[0];
1450 cd->tl_rx_tail = &cd->tl_rx_chain[TL_RX_LIST_CNT - 1];
1451
1452 return(0);
1453}
1454
1434static int tl_newbuf(sc, c)
1455static int
1456tl_newbuf(sc, c)
1435 struct tl_softc *sc;
1436 struct tl_chain_onefrag *c;
1437{
1438 struct mbuf *m_new = NULL;
1439
1440 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
1441 if (m_new == NULL)
1442 return(ENOBUFS);

--- 36 unchanged lines hidden (view full) ---

1479 * been sent on its way, the 'list' structure is assigned a new buffer
1480 * and moved to the end of the RX chain. As long we we stay ahead of
1481 * the chip, it will always think it has an endless receive channel.
1482 *
1483 * If we happen to fall behind and the chip manages to fill up all of
1484 * the buffers, it will generate an end of channel interrupt and wait
1485 * for us to empty the chain and restart the receiver.
1486 */
1457 struct tl_softc *sc;
1458 struct tl_chain_onefrag *c;
1459{
1460 struct mbuf *m_new = NULL;
1461
1462 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
1463 if (m_new == NULL)
1464 return(ENOBUFS);

--- 36 unchanged lines hidden (view full) ---

1501 * been sent on its way, the 'list' structure is assigned a new buffer
1502 * and moved to the end of the RX chain. As long we we stay ahead of
1503 * the chip, it will always think it has an endless receive channel.
1504 *
1505 * If we happen to fall behind and the chip manages to fill up all of
1506 * the buffers, it will generate an end of channel interrupt and wait
1507 * for us to empty the chain and restart the receiver.
1508 */
1487static int tl_intvec_rxeof(xsc, type)
1509static int
1510tl_intvec_rxeof(xsc, type)
1488 void *xsc;
1489 u_int32_t type;
1490{
1491 struct tl_softc *sc;
1492 int r = 0, total_len = 0;
1493 struct ether_header *eh;
1494 struct mbuf *m;
1495 struct ifnet *ifp;

--- 52 unchanged lines hidden (view full) ---

1548
1549/*
1550 * The RX-EOC condition hits when the ch_parm address hasn't been
1551 * initialized or the adapter reached a list with a forward pointer
1552 * of 0 (which indicates the end of the chain). In our case, this means
1553 * the card has hit the end of the receive buffer chain and we need to
1554 * empty out the buffers and shift the pointer back to the beginning again.
1555 */
1511 void *xsc;
1512 u_int32_t type;
1513{
1514 struct tl_softc *sc;
1515 int r = 0, total_len = 0;
1516 struct ether_header *eh;
1517 struct mbuf *m;
1518 struct ifnet *ifp;

--- 52 unchanged lines hidden (view full) ---

1571
1572/*
1573 * The RX-EOC condition hits when the ch_parm address hasn't been
1574 * initialized or the adapter reached a list with a forward pointer
1575 * of 0 (which indicates the end of the chain). In our case, this means
1576 * the card has hit the end of the receive buffer chain and we need to
1577 * empty out the buffers and shift the pointer back to the beginning again.
1578 */
1556static int tl_intvec_rxeoc(xsc, type)
1579static int
1580tl_intvec_rxeoc(xsc, type)
1557 void *xsc;
1558 u_int32_t type;
1559{
1560 struct tl_softc *sc;
1561 int r;
1562 struct tl_chain_data *cd;
1563
1564

--- 6 unchanged lines hidden (view full) ---

1571 r = 1;
1572 cd->tl_rx_head = &cd->tl_rx_chain[0];
1573 cd->tl_rx_tail = &cd->tl_rx_chain[TL_RX_LIST_CNT - 1];
1574 CSR_WRITE_4(sc, TL_CH_PARM, vtophys(sc->tl_cdata.tl_rx_head->tl_ptr));
1575 r |= (TL_CMD_GO|TL_CMD_RT);
1576 return(r);
1577}
1578
1581 void *xsc;
1582 u_int32_t type;
1583{
1584 struct tl_softc *sc;
1585 int r;
1586 struct tl_chain_data *cd;
1587
1588

--- 6 unchanged lines hidden (view full) ---

1595 r = 1;
1596 cd->tl_rx_head = &cd->tl_rx_chain[0];
1597 cd->tl_rx_tail = &cd->tl_rx_chain[TL_RX_LIST_CNT - 1];
1598 CSR_WRITE_4(sc, TL_CH_PARM, vtophys(sc->tl_cdata.tl_rx_head->tl_ptr));
1599 r |= (TL_CMD_GO|TL_CMD_RT);
1600 return(r);
1601}
1602
1579static int tl_intvec_txeof(xsc, type)
1603static int
1604tl_intvec_txeof(xsc, type)
1580 void *xsc;
1581 u_int32_t type;
1582{
1583 struct tl_softc *sc;
1584 int r = 0;
1585 struct tl_chain *cur_tx;
1586
1587 sc = xsc;

--- 35 unchanged lines hidden (view full) ---

1623 * are queued for transmission. If tl_statrt() is called after TXEOF
1624 * resets the tx_head pointer but _before_ the TXEOC interrupt arrives,
1625 * it could attempt to issue a transmit command prematurely.
1626 *
1627 * To guard against this, tl_start() will only issue transmit commands
1628 * if the tl_txeoc flag is set, and only the TXEOC interrupt handler
1629 * can set this flag once tl_start() has cleared it.
1630 */
1605 void *xsc;
1606 u_int32_t type;
1607{
1608 struct tl_softc *sc;
1609 int r = 0;
1610 struct tl_chain *cur_tx;
1611
1612 sc = xsc;

--- 35 unchanged lines hidden (view full) ---

1648 * are queued for transmission. If tl_statrt() is called after TXEOF
1649 * resets the tx_head pointer but _before_ the TXEOC interrupt arrives,
1650 * it could attempt to issue a transmit command prematurely.
1651 *
1652 * To guard against this, tl_start() will only issue transmit commands
1653 * if the tl_txeoc flag is set, and only the TXEOC interrupt handler
1654 * can set this flag once tl_start() has cleared it.
1655 */
1631static int tl_intvec_txeoc(xsc, type)
1656static int
1657tl_intvec_txeoc(xsc, type)
1632 void *xsc;
1633 u_int32_t type;
1634{
1635 struct tl_softc *sc;
1636 struct ifnet *ifp;
1637 u_int32_t cmd;
1638
1639 sc = xsc;

--- 19 unchanged lines hidden (view full) ---

1659 cmd |= TL_CMD_GO|TL_CMD_INTSON;
1660 CMD_PUT(sc, cmd);
1661 return(0);
1662 }
1663
1664 return(1);
1665}
1666
1658 void *xsc;
1659 u_int32_t type;
1660{
1661 struct tl_softc *sc;
1662 struct ifnet *ifp;
1663 u_int32_t cmd;
1664
1665 sc = xsc;

--- 19 unchanged lines hidden (view full) ---

1685 cmd |= TL_CMD_GO|TL_CMD_INTSON;
1686 CMD_PUT(sc, cmd);
1687 return(0);
1688 }
1689
1690 return(1);
1691}
1692
1667static int tl_intvec_adchk(xsc, type)
1693static int
1694tl_intvec_adchk(xsc, type)
1668 void *xsc;
1669 u_int32_t type;
1670{
1671 struct tl_softc *sc;
1672
1673 sc = xsc;
1674
1675 if (type)
1676 printf("tl%d: adapter check: %x\n", sc->tl_unit,
1677 (unsigned int)CSR_READ_4(sc, TL_CH_PARM));
1678
1679 tl_softreset(sc, 1);
1680 tl_stop(sc);
1681 tl_init(sc);
1682 CMD_SET(sc, TL_CMD_INTSON);
1683
1684 return(0);
1685}
1686
1695 void *xsc;
1696 u_int32_t type;
1697{
1698 struct tl_softc *sc;
1699
1700 sc = xsc;
1701
1702 if (type)
1703 printf("tl%d: adapter check: %x\n", sc->tl_unit,
1704 (unsigned int)CSR_READ_4(sc, TL_CH_PARM));
1705
1706 tl_softreset(sc, 1);
1707 tl_stop(sc);
1708 tl_init(sc);
1709 CMD_SET(sc, TL_CMD_INTSON);
1710
1711 return(0);
1712}
1713
1687static int tl_intvec_netsts(xsc, type)
1714static int
1715tl_intvec_netsts(xsc, type)
1688 void *xsc;
1689 u_int32_t type;
1690{
1691 struct tl_softc *sc;
1692 u_int16_t netsts;
1693
1694 sc = xsc;
1695
1696 netsts = tl_dio_read16(sc, TL_NETSTS);
1697 tl_dio_write16(sc, TL_NETSTS, netsts);
1698
1699 printf("tl%d: network status: %x\n", sc->tl_unit, netsts);
1700
1701 return(1);
1702}
1703
1716 void *xsc;
1717 u_int32_t type;
1718{
1719 struct tl_softc *sc;
1720 u_int16_t netsts;
1721
1722 sc = xsc;
1723
1724 netsts = tl_dio_read16(sc, TL_NETSTS);
1725 tl_dio_write16(sc, TL_NETSTS, netsts);
1726
1727 printf("tl%d: network status: %x\n", sc->tl_unit, netsts);
1728
1729 return(1);
1730}
1731
1704static void tl_intr(xsc)
1732static void
1733tl_intr(xsc)
1705 void *xsc;
1706{
1707 struct tl_softc *sc;
1708 struct ifnet *ifp;
1709 int r = 0;
1710 u_int32_t type = 0;
1711 u_int16_t ints = 0;
1712 u_int8_t ivec = 0;

--- 58 unchanged lines hidden (view full) ---

1771 if (ifp->if_snd.ifq_head != NULL)
1772 tl_start(ifp);
1773
1774 TL_UNLOCK(sc);
1775
1776 return;
1777}
1778
1734 void *xsc;
1735{
1736 struct tl_softc *sc;
1737 struct ifnet *ifp;
1738 int r = 0;
1739 u_int32_t type = 0;
1740 u_int16_t ints = 0;
1741 u_int8_t ivec = 0;

--- 58 unchanged lines hidden (view full) ---

1800 if (ifp->if_snd.ifq_head != NULL)
1801 tl_start(ifp);
1802
1803 TL_UNLOCK(sc);
1804
1805 return;
1806}
1807
1779static void tl_stats_update(xsc)
1808static void
1809tl_stats_update(xsc)
1780 void *xsc;
1781{
1782 struct tl_softc *sc;
1783 struct ifnet *ifp;
1784 struct tl_stats tl_stats;
1785 struct mii_data *mii;
1786 u_int32_t *p;
1787

--- 45 unchanged lines hidden (view full) ---

1833
1834 return;
1835}
1836
1837/*
1838 * Encapsulate an mbuf chain in a list by coupling the mbuf data
1839 * pointers to the fragment pointers.
1840 */
1810 void *xsc;
1811{
1812 struct tl_softc *sc;
1813 struct ifnet *ifp;
1814 struct tl_stats tl_stats;
1815 struct mii_data *mii;
1816 u_int32_t *p;
1817

--- 45 unchanged lines hidden (view full) ---

1863
1864 return;
1865}
1866
1867/*
1868 * Encapsulate an mbuf chain in a list by coupling the mbuf data
1869 * pointers to the fragment pointers.
1870 */
1841static int tl_encap(sc, c, m_head)
1871static int
1872tl_encap(sc, c, m_head)
1842 struct tl_softc *sc;
1843 struct tl_chain *c;
1844 struct mbuf *m_head;
1845{
1846 int frag = 0;
1847 struct tl_frag *f = NULL;
1848 int total_len;
1849 struct mbuf *m;

--- 80 unchanged lines hidden (view full) ---

1930}
1931
1932/*
1933 * Main transmit routine. To avoid having to do mbuf copies, we put pointers
1934 * to the mbuf data regions directly in the transmit lists. We also save a
1935 * copy of the pointers since the transmit list fragment pointers are
1936 * physical addresses.
1937 */
1873 struct tl_softc *sc;
1874 struct tl_chain *c;
1875 struct mbuf *m_head;
1876{
1877 int frag = 0;
1878 struct tl_frag *f = NULL;
1879 int total_len;
1880 struct mbuf *m;

--- 80 unchanged lines hidden (view full) ---

1961}
1962
1963/*
1964 * Main transmit routine. To avoid having to do mbuf copies, we put pointers
1965 * to the mbuf data regions directly in the transmit lists. We also save a
1966 * copy of the pointers since the transmit list fragment pointers are
1967 * physical addresses.
1968 */
1938static void tl_start(ifp)
1969static void
1970tl_start(ifp)
1939 struct ifnet *ifp;
1940{
1941 struct tl_softc *sc;
1942 struct mbuf *m_head = NULL;
1943 u_int32_t cmd;
1944 struct tl_chain *prev = NULL, *cur_tx = NULL, *start_tx;
1945
1946 sc = ifp->if_softc;

--- 76 unchanged lines hidden (view full) ---

2023 * Set a timeout in case the chip goes out to lunch.
2024 */
2025 ifp->if_timer = 5;
2026 TL_UNLOCK(sc);
2027
2028 return;
2029}
2030
1971 struct ifnet *ifp;
1972{
1973 struct tl_softc *sc;
1974 struct mbuf *m_head = NULL;
1975 u_int32_t cmd;
1976 struct tl_chain *prev = NULL, *cur_tx = NULL, *start_tx;
1977
1978 sc = ifp->if_softc;

--- 76 unchanged lines hidden (view full) ---

2055 * Set a timeout in case the chip goes out to lunch.
2056 */
2057 ifp->if_timer = 5;
2058 TL_UNLOCK(sc);
2059
2060 return;
2061}
2062
2031static void tl_init(xsc)
2063static void
2064tl_init(xsc)
2032 void *xsc;
2033{
2034 struct tl_softc *sc = xsc;
2035 struct ifnet *ifp = &sc->arpcom.ac_if;
2036 struct mii_data *mii;
2037
2038 TL_LOCK(sc);
2039

--- 72 unchanged lines hidden (view full) ---

2112 TL_UNLOCK(sc);
2113
2114 return;
2115}
2116
2117/*
2118 * Set media options.
2119 */
2065 void *xsc;
2066{
2067 struct tl_softc *sc = xsc;
2068 struct ifnet *ifp = &sc->arpcom.ac_if;
2069 struct mii_data *mii;
2070
2071 TL_LOCK(sc);
2072

--- 72 unchanged lines hidden (view full) ---

2145 TL_UNLOCK(sc);
2146
2147 return;
2148}
2149
2150/*
2151 * Set media options.
2152 */
2120static int tl_ifmedia_upd(ifp)
2153static int
2154tl_ifmedia_upd(ifp)
2121 struct ifnet *ifp;
2122{
2123 struct tl_softc *sc;
2124 struct mii_data *mii = NULL;
2125
2126 sc = ifp->if_softc;
2127
2128 if (sc->tl_bitrate)

--- 4 unchanged lines hidden (view full) ---

2133 }
2134
2135 return(0);
2136}
2137
2138/*
2139 * Report current media status.
2140 */
2155 struct ifnet *ifp;
2156{
2157 struct tl_softc *sc;
2158 struct mii_data *mii = NULL;
2159
2160 sc = ifp->if_softc;
2161
2162 if (sc->tl_bitrate)

--- 4 unchanged lines hidden (view full) ---

2167 }
2168
2169 return(0);
2170}
2171
2172/*
2173 * Report current media status.
2174 */
2141static void tl_ifmedia_sts(ifp, ifmr)
2175static void
2176tl_ifmedia_sts(ifp, ifmr)
2142 struct ifnet *ifp;
2143 struct ifmediareq *ifmr;
2144{
2145 struct tl_softc *sc;
2146 struct mii_data *mii;
2147
2148 sc = ifp->if_softc;
2149

--- 14 unchanged lines hidden (view full) ---

2164 mii_pollstat(mii);
2165 ifmr->ifm_active = mii->mii_media_active;
2166 ifmr->ifm_status = mii->mii_media_status;
2167 }
2168
2169 return;
2170}
2171
2177 struct ifnet *ifp;
2178 struct ifmediareq *ifmr;
2179{
2180 struct tl_softc *sc;
2181 struct mii_data *mii;
2182
2183 sc = ifp->if_softc;
2184

--- 14 unchanged lines hidden (view full) ---

2199 mii_pollstat(mii);
2200 ifmr->ifm_active = mii->mii_media_active;
2201 ifmr->ifm_status = mii->mii_media_status;
2202 }
2203
2204 return;
2205}
2206
2172static int tl_ioctl(ifp, command, data)
2207static int
2208tl_ioctl(ifp, command, data)
2173 struct ifnet *ifp;
2174 u_long command;
2175 caddr_t data;
2176{
2177 struct tl_softc *sc = ifp->if_softc;
2178 struct ifreq *ifr = (struct ifreq *) data;
2179 int s, error = 0;
2180

--- 48 unchanged lines hidden (view full) ---

2229 break;
2230 }
2231
2232 (void)splx(s);
2233
2234 return(error);
2235}
2236
2209 struct ifnet *ifp;
2210 u_long command;
2211 caddr_t data;
2212{
2213 struct tl_softc *sc = ifp->if_softc;
2214 struct ifreq *ifr = (struct ifreq *) data;
2215 int s, error = 0;
2216

--- 48 unchanged lines hidden (view full) ---

2265 break;
2266 }
2267
2268 (void)splx(s);
2269
2270 return(error);
2271}
2272
2237static void tl_watchdog(ifp)
2273static void
2274tl_watchdog(ifp)
2238 struct ifnet *ifp;
2239{
2240 struct tl_softc *sc;
2241
2242 sc = ifp->if_softc;
2243
2244 printf("tl%d: device timeout\n", sc->tl_unit);
2245

--- 4 unchanged lines hidden (view full) ---

2250
2251 return;
2252}
2253
2254/*
2255 * Stop the adapter and free any mbufs allocated to the
2256 * RX and TX lists.
2257 */
2275 struct ifnet *ifp;
2276{
2277 struct tl_softc *sc;
2278
2279 sc = ifp->if_softc;
2280
2281 printf("tl%d: device timeout\n", sc->tl_unit);
2282

--- 4 unchanged lines hidden (view full) ---

2287
2288 return;
2289}
2290
2291/*
2292 * Stop the adapter and free any mbufs allocated to the
2293 * RX and TX lists.
2294 */
2258static void tl_stop(sc)
2295static void
2296tl_stop(sc)
2259 struct tl_softc *sc;
2260{
2261 register int i;
2262 struct ifnet *ifp;
2263
2264 TL_LOCK(sc);
2265
2266 ifp = &sc->arpcom.ac_if;

--- 50 unchanged lines hidden (view full) ---

2317
2318 return;
2319}
2320
2321/*
2322 * Stop all chip I/O so that the kernel's probe routines don't
2323 * get confused by errant DMAs when rebooting.
2324 */
2297 struct tl_softc *sc;
2298{
2299 register int i;
2300 struct ifnet *ifp;
2301
2302 TL_LOCK(sc);
2303
2304 ifp = &sc->arpcom.ac_if;

--- 50 unchanged lines hidden (view full) ---

2355
2356 return;
2357}
2358
2359/*
2360 * Stop all chip I/O so that the kernel's probe routines don't
2361 * get confused by errant DMAs when rebooting.
2362 */
2325static void tl_shutdown(dev)
2363static void
2364tl_shutdown(dev)
2326 device_t dev;
2327{
2328 struct tl_softc *sc;
2329
2330 sc = device_get_softc(dev);
2331
2332 tl_stop(sc);
2333
2334 return;
2335}
2365 device_t dev;
2366{
2367 struct tl_softc *sc;
2368
2369 sc = device_get_softc(dev);
2370
2371 tl_stop(sc);
2372
2373 return;
2374}