Deleted Added
full compact
if_txp.c (189687) if_txp.c (189688)
1/* $OpenBSD: if_txp.c,v 1.48 2001/06/27 06:34:50 kjc Exp $ */
2
3/*-
4 * Copyright (c) 2001
5 * Jason L. Wright <jason@thought.net>, Theo de Raadt, and
6 * Aaron Campbell <aaron@monkey.org>. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include <sys/cdefs.h>
1/* $OpenBSD: if_txp.c,v 1.48 2001/06/27 06:34:50 kjc Exp $ */
2
3/*-
4 * Copyright (c) 2001
5 * Jason L. Wright <jason@thought.net>, Theo de Raadt, and
6 * Aaron Campbell <aaron@monkey.org>. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/dev/txp/if_txp.c 189687 2009-03-11 08:41:57Z yongari $");
38__FBSDID("$FreeBSD: head/sys/dev/txp/if_txp.c 189688 2009-03-11 08:49:17Z yongari $");
39
40/*
41 * Driver for 3c990 (Typhoon) Ethernet ASIC
42 */
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/sockio.h>
46#include <sys/mbuf.h>

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

82#define TXP_USEIOSPACE
83#define __STRICT_ALIGNMENT
84
85#include <dev/txp/if_txpreg.h>
86#include <dev/txp/3c990img.h>
87
88#ifndef lint
89static const char rcsid[] =
39
40/*
41 * Driver for 3c990 (Typhoon) Ethernet ASIC
42 */
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/sockio.h>
46#include <sys/mbuf.h>

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

82#define TXP_USEIOSPACE
83#define __STRICT_ALIGNMENT
84
85#include <dev/txp/if_txpreg.h>
86#include <dev/txp/3c990img.h>
87
88#ifndef lint
89static const char rcsid[] =
90 "$FreeBSD: head/sys/dev/txp/if_txp.c 189687 2009-03-11 08:41:57Z yongari $";
90 "$FreeBSD: head/sys/dev/txp/if_txp.c 189688 2009-03-11 08:49:17Z yongari $";
91#endif
92
93/*
94 * Various supported device vendors/types and their names.
95 */
96static struct txp_type txp_devs[] = {
97 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990_TX_95,
98 "3Com 3cR990-TX-95 Etherlink with 3XP Processor" },

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

187
188static int
189txp_probe(device_t dev)
190{
191 struct txp_type *t;
192
193 t = txp_devs;
194
91#endif
92
93/*
94 * Various supported device vendors/types and their names.
95 */
96static struct txp_type txp_devs[] = {
97 { TXP_VENDORID_3COM, TXP_DEVICEID_3CR990_TX_95,
98 "3Com 3cR990-TX-95 Etherlink with 3XP Processor" },

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

187
188static int
189txp_probe(device_t dev)
190{
191 struct txp_type *t;
192
193 t = txp_devs;
194
195 while(t->txp_name != NULL) {
195 while (t->txp_name != NULL) {
196 if ((pci_get_vendor(dev) == t->txp_vid) &&
197 (pci_get_device(dev) == t->txp_did)) {
198 device_set_desc(dev, t->txp_name);
196 if ((pci_get_vendor(dev) == t->txp_vid) &&
197 (pci_get_device(dev) == t->txp_did)) {
198 device_set_desc(dev, t->txp_name);
199 return(BUS_PROBE_DEFAULT);
199 return (BUS_PROBE_DEFAULT);
200 }
201 t++;
202 }
203
200 }
201 t++;
202 }
203
204 return(ENXIO);
204 return (ENXIO);
205}
206
207static int
208txp_attach(device_t dev)
209{
210 struct txp_softc *sc;
211 struct ifnet *ifp;
212 u_int16_t p1;

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

347 NULL, txp_intr, sc, &sc->sc_intrhand);
348
349 if (error) {
350 ether_ifdetach(ifp);
351 device_printf(dev, "couldn't set up irq\n");
352 goto fail;
353 }
354
205}
206
207static int
208txp_attach(device_t dev)
209{
210 struct txp_softc *sc;
211 struct ifnet *ifp;
212 u_int16_t p1;

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

347 NULL, txp_intr, sc, &sc->sc_intrhand);
348
349 if (error) {
350 ether_ifdetach(ifp);
351 device_printf(dev, "couldn't set up irq\n");
352 goto fail;
353 }
354
355 return(0);
355 return (0);
356
357fail:
358 txp_release_resources(sc);
359 mtx_destroy(&sc->sc_mtx);
356
357fail:
358 txp_release_resources(sc);
359 mtx_destroy(&sc->sc_mtx);
360 return(error);
360 return (error);
361}
362
363static int
364txp_detach(device_t dev)
365{
366 struct txp_softc *sc;
367 struct ifnet *ifp;
368 int i;

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

380 ether_ifdetach(ifp);
381
382 for (i = 0; i < RXBUF_ENTRIES; i++)
383 free(sc->sc_rxbufs[i].rb_sd, M_DEVBUF);
384
385 txp_release_resources(sc);
386
387 mtx_destroy(&sc->sc_mtx);
361}
362
363static int
364txp_detach(device_t dev)
365{
366 struct txp_softc *sc;
367 struct ifnet *ifp;
368 int i;

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

380 ether_ifdetach(ifp);
381
382 for (i = 0; i < RXBUF_ENTRIES; i++)
383 free(sc->sc_rxbufs[i].rb_sd, M_DEVBUF);
384
385 txp_release_resources(sc);
386
387 mtx_destroy(&sc->sc_mtx);
388 return(0);
388 return (0);
389}
390
391static void
392txp_release_resources(struct txp_softc *sc)
393{
394 device_t dev;
395
396 dev = sc->sc_dev;

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

896 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
897 TXP_INT_LATCH);
898
899 txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
900 txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
901 txp_command(sc, TXP_CMD_HALT, 0, 0, 0, NULL, NULL, NULL, 0);
902 TXP_UNLOCK(sc);
903
389}
390
391static void
392txp_release_resources(struct txp_softc *sc)
393{
394 device_t dev;
395
396 dev = sc->sc_dev;

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

896 TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
897 TXP_INT_LATCH);
898
899 txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
900 txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
901 txp_command(sc, TXP_CMD_HALT, 0, 0, 0, NULL, NULL, NULL, 0);
902 TXP_UNLOCK(sc);
903
904 return(0);
904 return (0);
905}
906
907static int
908txp_alloc_rings(struct txp_softc *sc)
909{
910 struct txp_boot_record *boot;
911 struct txp_ldata *ld;
912 u_int32_t r;

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

985
986 for (i = 0; i < RXBUF_ENTRIES; i++) {
987 struct txp_swdesc *sd;
988 if (sc->sc_rxbufs[i].rb_sd != NULL)
989 continue;
990 sc->sc_rxbufs[i].rb_sd = malloc(sizeof(struct txp_swdesc),
991 M_DEVBUF, M_NOWAIT);
992 if (sc->sc_rxbufs[i].rb_sd == NULL)
905}
906
907static int
908txp_alloc_rings(struct txp_softc *sc)
909{
910 struct txp_boot_record *boot;
911 struct txp_ldata *ld;
912 u_int32_t r;

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

985
986 for (i = 0; i < RXBUF_ENTRIES; i++) {
987 struct txp_swdesc *sd;
988 if (sc->sc_rxbufs[i].rb_sd != NULL)
989 continue;
990 sc->sc_rxbufs[i].rb_sd = malloc(sizeof(struct txp_swdesc),
991 M_DEVBUF, M_NOWAIT);
992 if (sc->sc_rxbufs[i].rb_sd == NULL)
993 return(ENOBUFS);
993 return (ENOBUFS);
994 sd = sc->sc_rxbufs[i].rb_sd;
995 sd->sd_mbuf = NULL;
996 }
997 sc->sc_rxbufprod = 0;
998
999 /* zero dma */
1000 bzero(&ld->txp_zero, sizeof(u_int32_t));
1001 boot->br_zero_lo = vtophys(&ld->txp_zero);

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

1006 r = READ_REG(sc, TXP_A2H_0);
1007 if (r == STAT_WAITING_FOR_BOOT)
1008 break;
1009 DELAY(50);
1010 }
1011
1012 if (r != STAT_WAITING_FOR_BOOT) {
1013 device_printf(sc->sc_dev, "not waiting for boot\n");
994 sd = sc->sc_rxbufs[i].rb_sd;
995 sd->sd_mbuf = NULL;
996 }
997 sc->sc_rxbufprod = 0;
998
999 /* zero dma */
1000 bzero(&ld->txp_zero, sizeof(u_int32_t));
1001 boot->br_zero_lo = vtophys(&ld->txp_zero);

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

1006 r = READ_REG(sc, TXP_A2H_0);
1007 if (r == STAT_WAITING_FOR_BOOT)
1008 break;
1009 DELAY(50);
1010 }
1011
1012 if (r != STAT_WAITING_FOR_BOOT) {
1013 device_printf(sc->sc_dev, "not waiting for boot\n");
1014 return(ENXIO);
1014 return (ENXIO);
1015 }
1016
1017 WRITE_REG(sc, TXP_H2A_2, 0);
1018 WRITE_REG(sc, TXP_H2A_1, vtophys(sc->sc_boot));
1019 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_REGISTER_BOOT_RECORD);
1020
1021 /* See if it booted */
1022 for (i = 0; i < 10000; i++) {
1023 r = READ_REG(sc, TXP_A2H_0);
1024 if (r == STAT_RUNNING)
1025 break;
1026 DELAY(50);
1027 }
1028 if (r != STAT_RUNNING) {
1029 device_printf(sc->sc_dev, "fw not running\n");
1015 }
1016
1017 WRITE_REG(sc, TXP_H2A_2, 0);
1018 WRITE_REG(sc, TXP_H2A_1, vtophys(sc->sc_boot));
1019 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_REGISTER_BOOT_RECORD);
1020
1021 /* See if it booted */
1022 for (i = 0; i < 10000; i++) {
1023 r = READ_REG(sc, TXP_A2H_0);
1024 if (r == STAT_RUNNING)
1025 break;
1026 DELAY(50);
1027 }
1028 if (r != STAT_RUNNING) {
1029 device_printf(sc->sc_dev, "fw not running\n");
1030 return(ENXIO);
1030 return (ENXIO);
1031 }
1032
1033 /* Clear TX and CMD ring write registers */
1034 WRITE_REG(sc, TXP_H2A_1, TXP_BOOTCMD_NULL);
1035 WRITE_REG(sc, TXP_H2A_2, TXP_BOOTCMD_NULL);
1036 WRITE_REG(sc, TXP_H2A_3, TXP_BOOTCMD_NULL);
1037 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_NULL);
1038
1039 return (0);
1040}
1041
1042static int
1043txp_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1044{
1045 struct txp_softc *sc = ifp->if_softc;
1046 struct ifreq *ifr = (struct ifreq *)data;
1047 int error = 0;
1048
1031 }
1032
1033 /* Clear TX and CMD ring write registers */
1034 WRITE_REG(sc, TXP_H2A_1, TXP_BOOTCMD_NULL);
1035 WRITE_REG(sc, TXP_H2A_2, TXP_BOOTCMD_NULL);
1036 WRITE_REG(sc, TXP_H2A_3, TXP_BOOTCMD_NULL);
1037 WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_NULL);
1038
1039 return (0);
1040}
1041
1042static int
1043txp_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1044{
1045 struct txp_softc *sc = ifp->if_softc;
1046 struct ifreq *ifr = (struct ifreq *)data;
1047 int error = 0;
1048
1049 switch(command) {
1049 switch (command) {
1050 case SIOCSIFFLAGS:
1051 TXP_LOCK(sc);
1052 if (ifp->if_flags & IFF_UP) {
1053 txp_init_locked(sc);
1054 } else {
1055 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1056 txp_stop(sc);
1057 }

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

1072 case SIOCSIFMEDIA:
1073 error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, command);
1074 break;
1075 default:
1076 error = ether_ioctl(ifp, command, data);
1077 break;
1078 }
1079
1050 case SIOCSIFFLAGS:
1051 TXP_LOCK(sc);
1052 if (ifp->if_flags & IFF_UP) {
1053 txp_init_locked(sc);
1054 } else {
1055 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1056 txp_stop(sc);
1057 }

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

1072 case SIOCSIFMEDIA:
1073 error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, command);
1074 break;
1075 default:
1076 error = ether_ioctl(ifp, command, data);
1077 break;
1078 }
1079
1080 return(error);
1080 return (error);
1081}
1082
1083static int
1084txp_rxring_fill(struct txp_softc *sc)
1085{
1086 int i;
1087 struct ifnet *ifp;
1088 struct txp_swdesc *sd;
1089
1090 TXP_LOCK_ASSERT(sc);
1091 ifp = sc->sc_ifp;
1092
1093 for (i = 0; i < RXBUF_ENTRIES; i++) {
1094 sd = sc->sc_rxbufs[i].rb_sd;
1095 sd->sd_mbuf = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1096 if (sd->sd_mbuf == NULL)
1081}
1082
1083static int
1084txp_rxring_fill(struct txp_softc *sc)
1085{
1086 int i;
1087 struct ifnet *ifp;
1088 struct txp_swdesc *sd;
1089
1090 TXP_LOCK_ASSERT(sc);
1091 ifp = sc->sc_ifp;
1092
1093 for (i = 0; i < RXBUF_ENTRIES; i++) {
1094 sd = sc->sc_rxbufs[i].rb_sd;
1095 sd->sd_mbuf = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1096 if (sd->sd_mbuf == NULL)
1097 return(ENOBUFS);
1097 return (ENOBUFS);
1098
1099 sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
1100 sd->sd_mbuf->m_pkthdr.rcvif = ifp;
1101
1102 sc->sc_rxbufs[i].rb_paddrlo =
1103 vtophys(mtod(sd->sd_mbuf, vm_offset_t));
1104 sc->sc_rxbufs[i].rb_paddrhi = 0;
1105 }
1106
1107 sc->sc_hostvar->hv_rx_buf_write_idx = (RXBUF_ENTRIES - 1) *
1108 sizeof(struct txp_rxbuf_desc);
1109
1098
1099 sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
1100 sd->sd_mbuf->m_pkthdr.rcvif = ifp;
1101
1102 sc->sc_rxbufs[i].rb_paddrlo =
1103 vtophys(mtod(sd->sd_mbuf, vm_offset_t));
1104 sc->sc_rxbufs[i].rb_paddrhi = 0;
1105 }
1106
1107 sc->sc_hostvar->hv_rx_buf_write_idx = (RXBUF_ENTRIES - 1) *
1108 sizeof(struct txp_rxbuf_desc);
1109
1110 return(0);
1110 return (0);
1111}
1112
1113static void
1114txp_rxring_empty(struct txp_softc *sc)
1115{
1116 int i;
1117 struct txp_swdesc *sd;
1118

--- 732 unchanged lines hidden ---
1111}
1112
1113static void
1114txp_rxring_empty(struct txp_softc *sc)
1115{
1116 int i;
1117 struct txp_swdesc *sd;
1118

--- 732 unchanged lines hidden ---