if_gem.c (148368) | if_gem.c (148369) |
---|---|
1/*- 2 * Copyright (C) 2001 Eduardo Horvath. 3 * Copyright (c) 2001-2003 Thomas Moestl 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * from: NetBSD: gem.c,v 1.21 2002/06/01 23:50:58 lukem Exp 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 2001 Eduardo Horvath. 3 * Copyright (c) 2001-2003 Thomas Moestl 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * from: NetBSD: gem.c,v 1.21 2002/06/01 23:50:58 lukem Exp 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem.c 148368 2005-07-24 18:12:31Z marius $"); | 31__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem.c 148369 2005-07-24 18:45:15Z marius $"); |
32 33/* 34 * Driver for Sun GEM ethernet controllers. 35 */ 36 37#if 0 38#define GEM_DEBUG 39#endif --- 5 unchanged lines hidden (view full) --- 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/bus.h> 48#include <sys/callout.h> 49#include <sys/endian.h> 50#include <sys/mbuf.h> 51#include <sys/malloc.h> 52#include <sys/kernel.h> | 32 33/* 34 * Driver for Sun GEM ethernet controllers. 35 */ 36 37#if 0 38#define GEM_DEBUG 39#endif --- 5 unchanged lines hidden (view full) --- 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/bus.h> 48#include <sys/callout.h> 49#include <sys/endian.h> 50#include <sys/mbuf.h> 51#include <sys/malloc.h> 52#include <sys/kernel.h> |
53#include <sys/lock.h> |
|
53#include <sys/module.h> | 54#include <sys/module.h> |
55#include <sys/mutex.h> |
|
54#include <sys/socket.h> 55#include <sys/sockio.h> 56 57#include <net/bpf.h> 58#include <net/ethernet.h> 59#include <net/if.h> 60#include <net/if_arp.h> 61#include <net/if_dl.h> --- 6 unchanged lines hidden (view full) --- 68#include <dev/mii/miivar.h> 69 70#include <dev/gem/if_gemreg.h> 71#include <dev/gem/if_gemvar.h> 72 73#define TRIES 10000 74 75static void gem_start(struct ifnet *); | 56#include <sys/socket.h> 57#include <sys/sockio.h> 58 59#include <net/bpf.h> 60#include <net/ethernet.h> 61#include <net/if.h> 62#include <net/if_arp.h> 63#include <net/if_dl.h> --- 6 unchanged lines hidden (view full) --- 70#include <dev/mii/miivar.h> 71 72#include <dev/gem/if_gemreg.h> 73#include <dev/gem/if_gemvar.h> 74 75#define TRIES 10000 76 77static void gem_start(struct ifnet *); |
78static void gem_start_locked(struct ifnet *); |
|
76static void gem_stop(struct ifnet *, int); 77static int gem_ioctl(struct ifnet *, u_long, caddr_t); 78static void gem_cddma_callback(void *, bus_dma_segment_t *, int, int); 79static void gem_txdma_callback(void *, bus_dma_segment_t *, int, 80 bus_size_t, int); 81static void gem_tick(void *); 82static void gem_watchdog(struct ifnet *); 83static void gem_init(void *); | 79static void gem_stop(struct ifnet *, int); 80static int gem_ioctl(struct ifnet *, u_long, caddr_t); 81static void gem_cddma_callback(void *, bus_dma_segment_t *, int, int); 82static void gem_txdma_callback(void *, bus_dma_segment_t *, int, 83 bus_size_t, int); 84static void gem_tick(void *); 85static void gem_watchdog(struct ifnet *); 86static void gem_init(void *); |
87static void gem_init_locked(struct gem_softc *sc); |
|
84static void gem_init_regs(struct gem_softc *sc); 85static int gem_ringsize(int sz); 86static int gem_meminit(struct gem_softc *); 87static int gem_load_txmbuf(struct gem_softc *, struct mbuf *); 88static void gem_mifinit(struct gem_softc *); 89static int gem_bitwait(struct gem_softc *sc, bus_addr_t r, 90 u_int32_t clr, u_int32_t set); 91static int gem_reset_rx(struct gem_softc *); --- 35 unchanged lines hidden (view full) --- 127gem_attach(sc) 128 struct gem_softc *sc; 129{ 130 struct ifnet *ifp; 131 struct mii_softc *child; 132 int i, error; 133 u_int32_t v; 134 | 88static void gem_init_regs(struct gem_softc *sc); 89static int gem_ringsize(int sz); 90static int gem_meminit(struct gem_softc *); 91static int gem_load_txmbuf(struct gem_softc *, struct mbuf *); 92static void gem_mifinit(struct gem_softc *); 93static int gem_bitwait(struct gem_softc *sc, bus_addr_t r, 94 u_int32_t clr, u_int32_t set); 95static int gem_reset_rx(struct gem_softc *); --- 35 unchanged lines hidden (view full) --- 131gem_attach(sc) 132 struct gem_softc *sc; 133{ 134 struct ifnet *ifp; 135 struct mii_softc *child; 136 int i, error; 137 u_int32_t v; 138 |
139 GEM_LOCK_ASSERT(sc, MA_NOTOWNED); 140 |
|
135 ifp = sc->sc_ifp = if_alloc(IFT_ETHER); 136 if (ifp == NULL) 137 return (ENOSPC); 138 139 /* Make sure the chip is stopped. */ 140 ifp->if_softc = sc; | 141 ifp = sc->sc_ifp = if_alloc(IFT_ETHER); 142 if (ifp == NULL) 143 return (ENOSPC); 144 145 /* Make sure the chip is stopped. */ 146 ifp->if_softc = sc; |
147 GEM_LOCK(sc); |
|
141 gem_reset(sc); | 148 gem_reset(sc); |
149 GEM_UNLOCK(sc); |
|
142 143 error = bus_dma_tag_create(NULL, 1, 0, BUS_SPACE_MAXADDR_32BIT, 144 BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES, GEM_NSEGS, 145 BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL, &sc->sc_pdmatag); 146 if (error) 147 goto fail_ifnet; 148 149 error = bus_dma_tag_create(sc->sc_pdmatag, 1, 0, --- 71 unchanged lines hidden (view full) --- 221 &sc->sc_rxsoft[i].rxs_dmamap)) != 0) { 222 device_printf(sc->sc_dev, "unable to create rx DMA map " 223 "%d, error = %d\n", i, error); 224 goto fail_rxd; 225 } 226 sc->sc_rxsoft[i].rxs_mbuf = NULL; 227 } 228 | 150 151 error = bus_dma_tag_create(NULL, 1, 0, BUS_SPACE_MAXADDR_32BIT, 152 BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES, GEM_NSEGS, 153 BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL, &sc->sc_pdmatag); 154 if (error) 155 goto fail_ifnet; 156 157 error = bus_dma_tag_create(sc->sc_pdmatag, 1, 0, --- 71 unchanged lines hidden (view full) --- 229 &sc->sc_rxsoft[i].rxs_dmamap)) != 0) { 230 device_printf(sc->sc_dev, "unable to create rx DMA map " 231 "%d, error = %d\n", i, error); 232 goto fail_rxd; 233 } 234 sc->sc_rxsoft[i].rxs_mbuf = NULL; 235 } 236 |
237 GEM_LOCK(sc); |
|
229 gem_mifinit(sc); | 238 gem_mifinit(sc); |
239 GEM_UNLOCK(sc); |
|
230 231 if ((error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, gem_mediachange, 232 gem_mediastatus)) != 0) { 233 device_printf(sc->sc_dev, "phy probe failed: %d\n", error); 234 goto fail_rxd; 235 } 236 sc->sc_mii = device_get_softc(sc->sc_miibus); 237 --- 12 unchanged lines hidden (view full) --- 250 device_printf(sc->sc_dev, "%ukB RX FIFO, %ukB TX FIFO\n", 251 sc->sc_rxfifosize / 1024, v / 16); 252 253 /* Initialize ifnet structure. */ 254 ifp->if_softc = sc; 255 if_initname(ifp, device_get_name(sc->sc_dev), 256 device_get_unit(sc->sc_dev)); 257 ifp->if_mtu = ETHERMTU; | 240 241 if ((error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, gem_mediachange, 242 gem_mediastatus)) != 0) { 243 device_printf(sc->sc_dev, "phy probe failed: %d\n", error); 244 goto fail_rxd; 245 } 246 sc->sc_mii = device_get_softc(sc->sc_miibus); 247 --- 12 unchanged lines hidden (view full) --- 260 device_printf(sc->sc_dev, "%ukB RX FIFO, %ukB TX FIFO\n", 261 sc->sc_rxfifosize / 1024, v / 16); 262 263 /* Initialize ifnet structure. */ 264 ifp->if_softc = sc; 265 if_initname(ifp, device_get_name(sc->sc_dev), 266 device_get_unit(sc->sc_dev)); 267 ifp->if_mtu = ETHERMTU; |
258 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST | 259 IFF_NEEDSGIANT; | 268 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; |
260 ifp->if_start = gem_start; 261 ifp->if_ioctl = gem_ioctl; 262 ifp->if_watchdog = gem_watchdog; 263 ifp->if_init = gem_init; 264 ifp->if_snd.ifq_maxlen = GEM_TXQUEUELEN; 265 /* 266 * Walk along the list of attached MII devices and 267 * establish an `MII instance' to `phy number' --- 47 unchanged lines hidden (view full) --- 315 * resume. 316 */ 317 sc->sc_powerhook = powerhook_establish(gem_power, sc); 318 if (sc->sc_powerhook == NULL) 319 device_printf(sc->sc_dev, "WARNING: unable to establish power " 320 "hook\n"); 321#endif 322 | 269 ifp->if_start = gem_start; 270 ifp->if_ioctl = gem_ioctl; 271 ifp->if_watchdog = gem_watchdog; 272 ifp->if_init = gem_init; 273 ifp->if_snd.ifq_maxlen = GEM_TXQUEUELEN; 274 /* 275 * Walk along the list of attached MII devices and 276 * establish an `MII instance' to `phy number' --- 47 unchanged lines hidden (view full) --- 324 * resume. 325 */ 326 sc->sc_powerhook = powerhook_establish(gem_power, sc); 327 if (sc->sc_powerhook == NULL) 328 device_printf(sc->sc_dev, "WARNING: unable to establish power " 329 "hook\n"); 330#endif 331 |
323 callout_init(&sc->sc_tick_ch, 0); | 332 callout_init(&sc->sc_tick_ch, CALLOUT_MPSAFE); |
324#ifdef GEM_RINT_TIMEOUT | 333#ifdef GEM_RINT_TIMEOUT |
325 callout_init(&sc->sc_rx_ch, 0); | 334 callout_init(&sc->sc_rx_ch, CALLOUT_MPSAFE); |
326#endif 327 return (0); 328 329 /* 330 * Free any resources we've allocated during the failed attach 331 * attempt. Do this in reverse order and fall through. 332 */ 333fail_rxd: --- 27 unchanged lines hidden (view full) --- 361 362void 363gem_detach(sc) 364 struct gem_softc *sc; 365{ 366 struct ifnet *ifp = sc->sc_ifp; 367 int i; 368 | 335#endif 336 return (0); 337 338 /* 339 * Free any resources we've allocated during the failed attach 340 * attempt. Do this in reverse order and fall through. 341 */ 342fail_rxd: --- 27 unchanged lines hidden (view full) --- 370 371void 372gem_detach(sc) 373 struct gem_softc *sc; 374{ 375 struct ifnet *ifp = sc->sc_ifp; 376 int i; 377 |
378 GEM_LOCK_ASSERT(sc, MA_NOTOWNED); 379 380 GEM_LOCK(sc); |
|
369 gem_stop(ifp, 1); | 381 gem_stop(ifp, 1); |
382 GEM_UNLOCK(sc); |
|
370 ether_ifdetach(ifp); 371 if_free(ifp); 372 device_delete_child(sc->sc_dev, sc->sc_miibus); 373 374 for (i = 0; i < GEM_NRXDESC; i++) { 375 if (sc->sc_rxsoft[i].rxs_dmamap != NULL) 376 bus_dmamap_destroy(sc->sc_rdmatag, 377 sc->sc_rxsoft[i].rxs_dmamap); --- 15 unchanged lines hidden (view full) --- 393} 394 395void 396gem_suspend(sc) 397 struct gem_softc *sc; 398{ 399 struct ifnet *ifp = sc->sc_ifp; 400 | 383 ether_ifdetach(ifp); 384 if_free(ifp); 385 device_delete_child(sc->sc_dev, sc->sc_miibus); 386 387 for (i = 0; i < GEM_NRXDESC; i++) { 388 if (sc->sc_rxsoft[i].rxs_dmamap != NULL) 389 bus_dmamap_destroy(sc->sc_rdmatag, 390 sc->sc_rxsoft[i].rxs_dmamap); --- 15 unchanged lines hidden (view full) --- 406} 407 408void 409gem_suspend(sc) 410 struct gem_softc *sc; 411{ 412 struct ifnet *ifp = sc->sc_ifp; 413 |
414 GEM_LOCK(sc); |
|
401 gem_stop(ifp, 0); | 415 gem_stop(ifp, 0); |
416 GEM_UNLOCK(sc); |
|
402} 403 404void 405gem_resume(sc) 406 struct gem_softc *sc; 407{ 408 struct ifnet *ifp = sc->sc_ifp; 409 | 417} 418 419void 420gem_resume(sc) 421 struct gem_softc *sc; 422{ 423 struct ifnet *ifp = sc->sc_ifp; 424 |
425 GEM_LOCK(sc); |
|
410 if (ifp->if_flags & IFF_UP) | 426 if (ifp->if_flags & IFF_UP) |
411 gem_init(ifp); | 427 gem_init_locked(sc); 428 GEM_UNLOCK(sc); |
412} 413 414static void 415gem_cddma_callback(xsc, segs, nsegs, error) 416 void *xsc; 417 bus_dma_segment_t *segs; 418 int nsegs; 419 int error; --- 84 unchanged lines hidden (view full) --- 504 ("gem_txdma_callback: missed end of packet!")); 505} 506 507static void 508gem_tick(arg) 509 void *arg; 510{ 511 struct gem_softc *sc = arg; | 429} 430 431static void 432gem_cddma_callback(xsc, segs, nsegs, error) 433 void *xsc; 434 bus_dma_segment_t *segs; 435 int nsegs; 436 int error; --- 84 unchanged lines hidden (view full) --- 521 ("gem_txdma_callback: missed end of packet!")); 522} 523 524static void 525gem_tick(arg) 526 void *arg; 527{ 528 struct gem_softc *sc = arg; |
512 int s; | |
513 | 529 |
514 s = splnet(); | |
515 mii_tick(sc->sc_mii); | 530 mii_tick(sc->sc_mii); |
516 splx(s); | |
517 518 callout_reset(&sc->sc_tick_ch, hz, gem_tick, sc); 519} 520 521static int 522gem_bitwait(sc, r, clr, set) 523 struct gem_softc *sc; 524 bus_addr_t r; --- 12 unchanged lines hidden (view full) --- 537} 538 539void 540gem_reset(sc) 541 struct gem_softc *sc; 542{ 543 bus_space_tag_t t = sc->sc_bustag; 544 bus_space_handle_t h = sc->sc_h; | 531 532 callout_reset(&sc->sc_tick_ch, hz, gem_tick, sc); 533} 534 535static int 536gem_bitwait(sc, r, clr, set) 537 struct gem_softc *sc; 538 bus_addr_t r; --- 12 unchanged lines hidden (view full) --- 551} 552 553void 554gem_reset(sc) 555 struct gem_softc *sc; 556{ 557 bus_space_tag_t t = sc->sc_bustag; 558 bus_space_handle_t h = sc->sc_h; |
545 int s; | |
546 | 559 |
547 s = splnet(); | |
548#ifdef GEM_DEBUG 549 CTR1(KTR_GEM, "%s: gem_reset", device_get_name(sc->sc_dev)); 550#endif 551 gem_reset_rx(sc); 552 gem_reset_tx(sc); 553 554 /* Do a full reset */ 555 bus_space_write_4(t, h, GEM_RESET, GEM_RESET_RX | GEM_RESET_TX); 556 if (!gem_bitwait(sc, GEM_RESET, GEM_RESET_RX | GEM_RESET_TX, 0)) 557 device_printf(sc->sc_dev, "cannot reset device\n"); | 560#ifdef GEM_DEBUG 561 CTR1(KTR_GEM, "%s: gem_reset", device_get_name(sc->sc_dev)); 562#endif 563 gem_reset_rx(sc); 564 gem_reset_tx(sc); 565 566 /* Do a full reset */ 567 bus_space_write_4(t, h, GEM_RESET, GEM_RESET_RX | GEM_RESET_TX); 568 if (!gem_bitwait(sc, GEM_RESET, GEM_RESET_RX | GEM_RESET_TX, 0)) 569 device_printf(sc->sc_dev, "cannot reset device\n"); |
558 splx(s); | |
559} 560 561 562/* 563 * gem_rxdrain: 564 * 565 * Drain the receive queue. 566 */ --- 261 unchanged lines hidden (view full) --- 828 break; 829 default: 830 printf("gem: invalid Receive Descriptor ring size\n"); 831 break; 832 } 833 return (v); 834} 835 | 570} 571 572 573/* 574 * gem_rxdrain: 575 * 576 * Drain the receive queue. 577 */ --- 261 unchanged lines hidden (view full) --- 839 break; 840 default: 841 printf("gem: invalid Receive Descriptor ring size\n"); 842 break; 843 } 844 return (v); 845} 846 |
847static void 848gem_init(xsc) 849 void *xsc; 850{ 851 struct gem_softc *sc = (struct gem_softc *)xsc; 852 853 GEM_LOCK(sc); 854 gem_init_locked(sc); 855 GEM_UNLOCK(sc); 856} 857 |
|
836/* 837 * Initialization of interface; set up initialization block 838 * and transmit/receive descriptor rings. 839 */ 840static void | 858/* 859 * Initialization of interface; set up initialization block 860 * and transmit/receive descriptor rings. 861 */ 862static void |
841gem_init(xsc) 842 void *xsc; | 863gem_init_locked(sc) 864 struct gem_softc *sc; |
843{ | 865{ |
844 struct gem_softc *sc = (struct gem_softc *)xsc; | |
845 struct ifnet *ifp = sc->sc_ifp; 846 bus_space_tag_t t = sc->sc_bustag; 847 bus_space_handle_t h = sc->sc_h; | 866 struct ifnet *ifp = sc->sc_ifp; 867 bus_space_tag_t t = sc->sc_bustag; 868 bus_space_handle_t h = sc->sc_h; |
848 int s; | |
849 u_int32_t v; 850 | 869 u_int32_t v; 870 |
851 s = splnet(); | 871 GEM_LOCK_ASSERT(sc, MA_OWNED); |
852 853#ifdef GEM_DEBUG 854 CTR1(KTR_GEM, "%s: gem_init: calling stop", device_get_name(sc->sc_dev)); 855#endif 856 /* 857 * Initialization sequence. The numbered steps below correspond 858 * to the sequence outlined in section 6.3.5.1 in the Ethernet 859 * Channel Engine manual (part of the PCIO manual). --- 70 unchanged lines hidden (view full) --- 930 * and an ON Threshold of 1/4 full. 931 */ 932 bus_space_write_4(t, h, GEM_RX_PAUSE_THRESH, 933 (3 * sc->sc_rxfifosize / 256) | 934 ( (sc->sc_rxfifosize / 256) << 12)); 935 bus_space_write_4(t, h, GEM_RX_BLANKING, (6<<12)|6); 936 937 /* step 11. Configure Media */ | 872 873#ifdef GEM_DEBUG 874 CTR1(KTR_GEM, "%s: gem_init: calling stop", device_get_name(sc->sc_dev)); 875#endif 876 /* 877 * Initialization sequence. The numbered steps below correspond 878 * to the sequence outlined in section 6.3.5.1 in the Ethernet 879 * Channel Engine manual (part of the PCIO manual). --- 70 unchanged lines hidden (view full) --- 950 * and an ON Threshold of 1/4 full. 951 */ 952 bus_space_write_4(t, h, GEM_RX_PAUSE_THRESH, 953 (3 * sc->sc_rxfifosize / 256) | 954 ( (sc->sc_rxfifosize / 256) << 12)); 955 bus_space_write_4(t, h, GEM_RX_BLANKING, (6<<12)|6); 956 957 /* step 11. Configure Media */ |
958 GEM_UNLOCK(sc); |
|
938 mii_mediachg(sc->sc_mii); | 959 mii_mediachg(sc->sc_mii); |
960 GEM_LOCK(sc); |
|
939 940 /* step 12. RX_MAC Configuration Register */ 941 v = bus_space_read_4(t, h, GEM_MAC_RX_CONFIG); 942 v |= GEM_MAC_RX_ENABLE; 943 bus_space_write_4(t, h, GEM_MAC_RX_CONFIG, v); 944 945 /* step 14. Issue Transmit Pending command */ 946 947 /* step 15. Give the reciever a swift kick */ 948 bus_space_write_4(t, h, GEM_RX_KICK, GEM_NRXDESC-4); 949 950 /* Start the one second timer. */ 951 callout_reset(&sc->sc_tick_ch, hz, gem_tick, sc); 952 953 ifp->if_flags |= IFF_RUNNING; 954 ifp->if_flags &= ~IFF_OACTIVE; 955 ifp->if_timer = 0; 956 sc->sc_ifflags = ifp->if_flags; | 961 962 /* step 12. RX_MAC Configuration Register */ 963 v = bus_space_read_4(t, h, GEM_MAC_RX_CONFIG); 964 v |= GEM_MAC_RX_ENABLE; 965 bus_space_write_4(t, h, GEM_MAC_RX_CONFIG, v); 966 967 /* step 14. Issue Transmit Pending command */ 968 969 /* step 15. Give the reciever a swift kick */ 970 bus_space_write_4(t, h, GEM_RX_KICK, GEM_NRXDESC-4); 971 972 /* Start the one second timer. */ 973 callout_reset(&sc->sc_tick_ch, hz, gem_tick, sc); 974 975 ifp->if_flags |= IFF_RUNNING; 976 ifp->if_flags &= ~IFF_OACTIVE; 977 ifp->if_timer = 0; 978 sc->sc_ifflags = ifp->if_flags; |
957 splx(s); | |
958} 959 960static int 961gem_load_txmbuf(sc, m0) 962 struct gem_softc *sc; 963 struct mbuf *m0; 964{ 965 struct gem_txdma txd; --- 133 unchanged lines hidden (view full) --- 1099 bus_space_write_4(t, h, GEM_MAC_XIF_CONFIG, v); 1100} 1101 1102static void 1103gem_start(ifp) 1104 struct ifnet *ifp; 1105{ 1106 struct gem_softc *sc = (struct gem_softc *)ifp->if_softc; | 979} 980 981static int 982gem_load_txmbuf(sc, m0) 983 struct gem_softc *sc; 984 struct mbuf *m0; 985{ 986 struct gem_txdma txd; --- 133 unchanged lines hidden (view full) --- 1120 bus_space_write_4(t, h, GEM_MAC_XIF_CONFIG, v); 1121} 1122 1123static void 1124gem_start(ifp) 1125 struct ifnet *ifp; 1126{ 1127 struct gem_softc *sc = (struct gem_softc *)ifp->if_softc; |
1128 1129 GEM_LOCK(sc); 1130 gem_start_locked(ifp); 1131 GEM_UNLOCK(sc); 1132} 1133 1134static void 1135gem_start_locked(ifp) 1136 struct ifnet *ifp; 1137{ 1138 struct gem_softc *sc = (struct gem_softc *)ifp->if_softc; |
|
1107 struct mbuf *m0 = NULL; 1108 int firsttx, ntx = 0, ofree, txmfail; 1109 1110 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) 1111 return; 1112 1113 /* 1114 * Remember the previous number of free descriptors and --- 188 unchanged lines hidden (view full) --- 1303#endif 1304 1305 if (progress) { 1306 if (sc->sc_txfree == GEM_NTXDESC - 1) 1307 sc->sc_txwin = 0; 1308 1309 /* Freed some descriptors, so reset IFF_OACTIVE and restart. */ 1310 ifp->if_flags &= ~IFF_OACTIVE; | 1139 struct mbuf *m0 = NULL; 1140 int firsttx, ntx = 0, ofree, txmfail; 1141 1142 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) 1143 return; 1144 1145 /* 1146 * Remember the previous number of free descriptors and --- 188 unchanged lines hidden (view full) --- 1335#endif 1336 1337 if (progress) { 1338 if (sc->sc_txfree == GEM_NTXDESC - 1) 1339 sc->sc_txwin = 0; 1340 1341 /* Freed some descriptors, so reset IFF_OACTIVE and restart. */ 1342 ifp->if_flags &= ~IFF_OACTIVE; |
1311 gem_start(ifp); | 1343 gem_start_locked(ifp); |
1312 1313 if (STAILQ_EMPTY(&sc->sc_txdirtyq)) 1314 ifp->if_timer = 0; 1315 } 1316 1317#ifdef GEM_DEBUG 1318 CTR2(KTR_GEM, "%s: gem_tint: watchdog %d", 1319 device_get_name(sc->sc_dev), ifp->if_timer); 1320#endif 1321} 1322 1323#ifdef GEM_RINT_TIMEOUT 1324static void 1325gem_rint_timeout(arg) 1326 void *arg; 1327{ | 1344 1345 if (STAILQ_EMPTY(&sc->sc_txdirtyq)) 1346 ifp->if_timer = 0; 1347 } 1348 1349#ifdef GEM_DEBUG 1350 CTR2(KTR_GEM, "%s: gem_tint: watchdog %d", 1351 device_get_name(sc->sc_dev), ifp->if_timer); 1352#endif 1353} 1354 1355#ifdef GEM_RINT_TIMEOUT 1356static void 1357gem_rint_timeout(arg) 1358 void *arg; 1359{ |
1360 struct gem_softc *sc = (struct gem_softc *)arg; |
|
1328 | 1361 |
1329 gem_rint((struct gem_softc *)arg); | 1362 GEM_LOCK(sc); 1363 gem_rint(sc); 1364 GEM_UNLOCK(sc); |
1330} 1331#endif 1332 1333/* 1334 * Receive interrupt. 1335 */ 1336static void 1337gem_rint(sc) --- 86 unchanged lines hidden (view full) --- 1424 continue; 1425 } 1426 m->m_data += 2; /* We're already off by two */ 1427 1428 m->m_pkthdr.rcvif = ifp; 1429 m->m_pkthdr.len = m->m_len = len - ETHER_CRC_LEN; 1430 1431 /* Pass it on. */ | 1365} 1366#endif 1367 1368/* 1369 * Receive interrupt. 1370 */ 1371static void 1372gem_rint(sc) --- 86 unchanged lines hidden (view full) --- 1459 continue; 1460 } 1461 m->m_data += 2; /* We're already off by two */ 1462 1463 m->m_pkthdr.rcvif = ifp; 1464 m->m_pkthdr.len = m->m_len = len - ETHER_CRC_LEN; 1465 1466 /* Pass it on. */ |
1467 GEM_UNLOCK(sc); |
|
1432 (*ifp->if_input)(ifp, m); | 1468 (*ifp->if_input)(ifp, m); |
1469 GEM_LOCK(sc); |
|
1433 } 1434 1435 if (progress) { 1436 GEM_CDSYNC(sc, BUS_DMASYNC_PREWRITE); 1437 /* Update the receive pointer. */ 1438 if (i == sc->sc_rxptr) { 1439 device_printf(sc->sc_dev, "rint: ring wrap\n"); 1440 } --- 80 unchanged lines hidden (view full) --- 1521gem_intr(v) 1522 void *v; 1523{ 1524 struct gem_softc *sc = (struct gem_softc *)v; 1525 bus_space_tag_t t = sc->sc_bustag; 1526 bus_space_handle_t seb = sc->sc_h; 1527 u_int32_t status; 1528 | 1470 } 1471 1472 if (progress) { 1473 GEM_CDSYNC(sc, BUS_DMASYNC_PREWRITE); 1474 /* Update the receive pointer. */ 1475 if (i == sc->sc_rxptr) { 1476 device_printf(sc->sc_dev, "rint: ring wrap\n"); 1477 } --- 80 unchanged lines hidden (view full) --- 1558gem_intr(v) 1559 void *v; 1560{ 1561 struct gem_softc *sc = (struct gem_softc *)v; 1562 bus_space_tag_t t = sc->sc_bustag; 1563 bus_space_handle_t seb = sc->sc_h; 1564 u_int32_t status; 1565 |
1566 GEM_LOCK(sc); |
|
1529 status = bus_space_read_4(t, seb, GEM_STATUS); 1530#ifdef GEM_DEBUG 1531 CTR3(KTR_GEM, "%s: gem_intr: cplt %x, status %x", 1532 device_get_name(sc->sc_dev), (status>>19), 1533 (u_int)status); 1534#endif 1535 1536 if ((status & (GEM_INTR_RX_TAG_ERR | GEM_INTR_BERR)) != 0) --- 7 unchanged lines hidden (view full) --- 1544 1545 /* We should eventually do more than just print out error stats. */ 1546 if (status & GEM_INTR_TX_MAC) { 1547 int txstat = bus_space_read_4(t, seb, GEM_MAC_TX_STATUS); 1548 if (txstat & ~GEM_MAC_TX_XMIT_DONE) 1549 device_printf(sc->sc_dev, "MAC tx fault, status %x\n", 1550 txstat); 1551 if (txstat & (GEM_MAC_TX_UNDERRUN | GEM_MAC_TX_PKT_TOO_LONG)) | 1567 status = bus_space_read_4(t, seb, GEM_STATUS); 1568#ifdef GEM_DEBUG 1569 CTR3(KTR_GEM, "%s: gem_intr: cplt %x, status %x", 1570 device_get_name(sc->sc_dev), (status>>19), 1571 (u_int)status); 1572#endif 1573 1574 if ((status & (GEM_INTR_RX_TAG_ERR | GEM_INTR_BERR)) != 0) --- 7 unchanged lines hidden (view full) --- 1582 1583 /* We should eventually do more than just print out error stats. */ 1584 if (status & GEM_INTR_TX_MAC) { 1585 int txstat = bus_space_read_4(t, seb, GEM_MAC_TX_STATUS); 1586 if (txstat & ~GEM_MAC_TX_XMIT_DONE) 1587 device_printf(sc->sc_dev, "MAC tx fault, status %x\n", 1588 txstat); 1589 if (txstat & (GEM_MAC_TX_UNDERRUN | GEM_MAC_TX_PKT_TOO_LONG)) |
1552 gem_init(sc); | 1590 gem_init_locked(sc); |
1553 } 1554 if (status & GEM_INTR_RX_MAC) { 1555 int rxstat = bus_space_read_4(t, seb, GEM_MAC_RX_STATUS); 1556 if (rxstat & ~(GEM_MAC_RX_DONE | GEM_MAC_RX_FRAME_CNT)) 1557 device_printf(sc->sc_dev, "MAC rx fault, status %x\n", 1558 rxstat); 1559 if ((rxstat & GEM_MAC_RX_OVERFLOW) != 0) | 1591 } 1592 if (status & GEM_INTR_RX_MAC) { 1593 int rxstat = bus_space_read_4(t, seb, GEM_MAC_RX_STATUS); 1594 if (rxstat & ~(GEM_MAC_RX_DONE | GEM_MAC_RX_FRAME_CNT)) 1595 device_printf(sc->sc_dev, "MAC rx fault, status %x\n", 1596 rxstat); 1597 if ((rxstat & GEM_MAC_RX_OVERFLOW) != 0) |
1560 gem_init(sc); | 1598 gem_init_locked(sc); |
1561 } | 1599 } |
1600 GEM_UNLOCK(sc); |
|
1562} 1563 1564 1565static void 1566gem_watchdog(ifp) 1567 struct ifnet *ifp; 1568{ 1569 struct gem_softc *sc = ifp->if_softc; 1570 | 1601} 1602 1603 1604static void 1605gem_watchdog(ifp) 1606 struct ifnet *ifp; 1607{ 1608 struct gem_softc *sc = ifp->if_softc; 1609 |
1610 GEM_LOCK(sc); |
|
1571#ifdef GEM_DEBUG 1572 CTR3(KTR_GEM, "gem_watchdog: GEM_RX_CONFIG %x GEM_MAC_RX_STATUS %x " 1573 "GEM_MAC_RX_CONFIG %x", 1574 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_RX_CONFIG), 1575 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_RX_STATUS), 1576 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_RX_CONFIG)); 1577 CTR3(KTR_GEM, "gem_watchdog: GEM_TX_CONFIG %x GEM_MAC_TX_STATUS %x " 1578 "GEM_MAC_TX_CONFIG %x", 1579 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_TX_CONFIG), 1580 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_TX_STATUS), 1581 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_TX_CONFIG)); 1582#endif 1583 1584 device_printf(sc->sc_dev, "device timeout\n"); 1585 ++ifp->if_oerrors; 1586 1587 /* Try to get more packets going. */ | 1611#ifdef GEM_DEBUG 1612 CTR3(KTR_GEM, "gem_watchdog: GEM_RX_CONFIG %x GEM_MAC_RX_STATUS %x " 1613 "GEM_MAC_RX_CONFIG %x", 1614 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_RX_CONFIG), 1615 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_RX_STATUS), 1616 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_RX_CONFIG)); 1617 CTR3(KTR_GEM, "gem_watchdog: GEM_TX_CONFIG %x GEM_MAC_TX_STATUS %x " 1618 "GEM_MAC_TX_CONFIG %x", 1619 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_TX_CONFIG), 1620 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_TX_STATUS), 1621 bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_MAC_TX_CONFIG)); 1622#endif 1623 1624 device_printf(sc->sc_dev, "device timeout\n"); 1625 ++ifp->if_oerrors; 1626 1627 /* Try to get more packets going. */ |
1588 gem_init(ifp); | 1628 gem_init_locked(sc); 1629 GEM_UNLOCK(sc); |
1589} 1590 1591/* 1592 * Initialize the MII Management Interface 1593 */ 1594static void 1595gem_mifinit(sc) 1596 struct gem_softc *sc; 1597{ 1598 bus_space_tag_t t = sc->sc_bustag; 1599 bus_space_handle_t mif = sc->sc_h; 1600 | 1630} 1631 1632/* 1633 * Initialize the MII Management Interface 1634 */ 1635static void 1636gem_mifinit(sc) 1637 struct gem_softc *sc; 1638{ 1639 bus_space_tag_t t = sc->sc_bustag; 1640 bus_space_handle_t mif = sc->sc_h; 1641 |
1642 GEM_LOCK_ASSERT(sc, MA_OWNED); 1643 |
|
1601 /* Configure the MIF in frame mode */ 1602 sc->sc_mif_config = bus_space_read_4(t, mif, GEM_MIF_CONFIG); 1603 sc->sc_mif_config &= ~GEM_MIF_CONFIG_BB_ENA; 1604 bus_space_write_4(t, mif, GEM_MIF_CONFIG, sc->sc_mif_config); 1605} 1606 1607/* 1608 * MII interface --- 15 unchanged lines hidden (view full) --- 1624 int phy, reg; 1625{ 1626 struct gem_softc *sc = device_get_softc(dev); 1627 bus_space_tag_t t = sc->sc_bustag; 1628 bus_space_handle_t mif = sc->sc_h; 1629 int n; 1630 u_int32_t v; 1631 | 1644 /* Configure the MIF in frame mode */ 1645 sc->sc_mif_config = bus_space_read_4(t, mif, GEM_MIF_CONFIG); 1646 sc->sc_mif_config &= ~GEM_MIF_CONFIG_BB_ENA; 1647 bus_space_write_4(t, mif, GEM_MIF_CONFIG, sc->sc_mif_config); 1648} 1649 1650/* 1651 * MII interface --- 15 unchanged lines hidden (view full) --- 1667 int phy, reg; 1668{ 1669 struct gem_softc *sc = device_get_softc(dev); 1670 bus_space_tag_t t = sc->sc_bustag; 1671 bus_space_handle_t mif = sc->sc_h; 1672 int n; 1673 u_int32_t v; 1674 |
1675 GEM_LOCK(sc); |
|
1632#ifdef GEM_DEBUG_PHY 1633 printf("gem_mii_readreg: phy %d reg %d\n", phy, reg); 1634#endif 1635 1636#if 0 1637 /* Select the desired PHY in the MIF configuration register */ 1638 v = bus_space_read_4(t, mif, GEM_MIF_CONFIG); 1639 /* Clear PHY select bit */ --- 7 unchanged lines hidden (view full) --- 1647 /* Construct the frame command */ 1648 v = (reg << GEM_MIF_REG_SHIFT) | (phy << GEM_MIF_PHY_SHIFT) | 1649 GEM_MIF_FRAME_READ; 1650 1651 bus_space_write_4(t, mif, GEM_MIF_FRAME, v); 1652 for (n = 0; n < 100; n++) { 1653 DELAY(1); 1654 v = bus_space_read_4(t, mif, GEM_MIF_FRAME); | 1676#ifdef GEM_DEBUG_PHY 1677 printf("gem_mii_readreg: phy %d reg %d\n", phy, reg); 1678#endif 1679 1680#if 0 1681 /* Select the desired PHY in the MIF configuration register */ 1682 v = bus_space_read_4(t, mif, GEM_MIF_CONFIG); 1683 /* Clear PHY select bit */ --- 7 unchanged lines hidden (view full) --- 1691 /* Construct the frame command */ 1692 v = (reg << GEM_MIF_REG_SHIFT) | (phy << GEM_MIF_PHY_SHIFT) | 1693 GEM_MIF_FRAME_READ; 1694 1695 bus_space_write_4(t, mif, GEM_MIF_FRAME, v); 1696 for (n = 0; n < 100; n++) { 1697 DELAY(1); 1698 v = bus_space_read_4(t, mif, GEM_MIF_FRAME); |
1655 if (v & GEM_MIF_FRAME_TA0) | 1699 if (v & GEM_MIF_FRAME_TA0) { 1700 GEM_UNLOCK(sc); |
1656 return (v & GEM_MIF_FRAME_DATA); | 1701 return (v & GEM_MIF_FRAME_DATA); |
1702 } |
|
1657 } 1658 1659 device_printf(sc->sc_dev, "mii_read timeout\n"); | 1703 } 1704 1705 device_printf(sc->sc_dev, "mii_read timeout\n"); |
1706 GEM_UNLOCK(sc); |
|
1660 return (0); 1661} 1662 1663int 1664gem_mii_writereg(dev, phy, reg, val) 1665 device_t dev; 1666 int phy, reg, val; 1667{ 1668 struct gem_softc *sc = device_get_softc(dev); 1669 bus_space_tag_t t = sc->sc_bustag; 1670 bus_space_handle_t mif = sc->sc_h; 1671 int n; 1672 u_int32_t v; 1673 | 1707 return (0); 1708} 1709 1710int 1711gem_mii_writereg(dev, phy, reg, val) 1712 device_t dev; 1713 int phy, reg, val; 1714{ 1715 struct gem_softc *sc = device_get_softc(dev); 1716 bus_space_tag_t t = sc->sc_bustag; 1717 bus_space_handle_t mif = sc->sc_h; 1718 int n; 1719 u_int32_t v; 1720 |
1721 GEM_LOCK(sc); |
|
1674#ifdef GEM_DEBUG_PHY 1675 printf("gem_mii_writereg: phy %d reg %d val %x\n", phy, reg, val); 1676#endif 1677 1678#if 0 1679 /* Select the desired PHY in the MIF configuration register */ 1680 v = bus_space_read_4(t, mif, GEM_MIF_CONFIG); 1681 /* Clear PHY select bit */ --- 8 unchanged lines hidden (view full) --- 1690 (phy << GEM_MIF_PHY_SHIFT) | 1691 (reg << GEM_MIF_REG_SHIFT) | 1692 (val & GEM_MIF_FRAME_DATA); 1693 1694 bus_space_write_4(t, mif, GEM_MIF_FRAME, v); 1695 for (n = 0; n < 100; n++) { 1696 DELAY(1); 1697 v = bus_space_read_4(t, mif, GEM_MIF_FRAME); | 1722#ifdef GEM_DEBUG_PHY 1723 printf("gem_mii_writereg: phy %d reg %d val %x\n", phy, reg, val); 1724#endif 1725 1726#if 0 1727 /* Select the desired PHY in the MIF configuration register */ 1728 v = bus_space_read_4(t, mif, GEM_MIF_CONFIG); 1729 /* Clear PHY select bit */ --- 8 unchanged lines hidden (view full) --- 1738 (phy << GEM_MIF_PHY_SHIFT) | 1739 (reg << GEM_MIF_REG_SHIFT) | 1740 (val & GEM_MIF_FRAME_DATA); 1741 1742 bus_space_write_4(t, mif, GEM_MIF_FRAME, v); 1743 for (n = 0; n < 100; n++) { 1744 DELAY(1); 1745 v = bus_space_read_4(t, mif, GEM_MIF_FRAME); |
1698 if (v & GEM_MIF_FRAME_TA0) | 1746 if (v & GEM_MIF_FRAME_TA0) { 1747 GEM_UNLOCK(sc); |
1699 return (1); | 1748 return (1); |
1749 } |
|
1700 } 1701 1702 device_printf(sc->sc_dev, "mii_write timeout\n"); | 1750 } 1751 1752 device_printf(sc->sc_dev, "mii_write timeout\n"); |
1753 GEM_UNLOCK(sc); |
|
1703 return (0); 1704} 1705 1706void 1707gem_mii_statchg(dev) 1708 device_t dev; 1709{ 1710 struct gem_softc *sc = device_get_softc(dev); 1711#ifdef GEM_DEBUG | 1754 return (0); 1755} 1756 1757void 1758gem_mii_statchg(dev) 1759 device_t dev; 1760{ 1761 struct gem_softc *sc = device_get_softc(dev); 1762#ifdef GEM_DEBUG |
1712 int instance = IFM_INST(sc->sc_mii->mii_media.ifm_cur->ifm_media); | 1763 int instance; |
1713#endif 1714 bus_space_tag_t t = sc->sc_bustag; 1715 bus_space_handle_t mac = sc->sc_h; 1716 u_int32_t v; 1717 | 1764#endif 1765 bus_space_tag_t t = sc->sc_bustag; 1766 bus_space_handle_t mac = sc->sc_h; 1767 u_int32_t v; 1768 |
1769 GEM_LOCK(sc); |
|
1718#ifdef GEM_DEBUG | 1770#ifdef GEM_DEBUG |
1771 instance = IFM_INST(sc->sc_mii->mii_media.ifm_cur->ifm_media); |
|
1719 if (sc->sc_debug) 1720 printf("gem_mii_statchg: status change: phy = %d\n", 1721 sc->sc_phys[instance]); 1722#endif 1723 1724 /* Set tx full duplex options */ 1725 bus_space_write_4(t, mac, GEM_MAC_TX_CONFIG, 0); 1726 DELAY(10000); /* reg must be cleared and delay before changing. */ --- 23 unchanged lines hidden (view full) --- 1750 v |= GEM_MAC_XIF_GMII_MODE; 1751 else 1752 v &= ~GEM_MAC_XIF_GMII_MODE; 1753 } else { 1754 /* Internal MII needs buf enable */ 1755 v |= GEM_MAC_XIF_MII_BUF_ENA; 1756 } 1757 bus_space_write_4(t, mac, GEM_MAC_XIF_CONFIG, v); | 1772 if (sc->sc_debug) 1773 printf("gem_mii_statchg: status change: phy = %d\n", 1774 sc->sc_phys[instance]); 1775#endif 1776 1777 /* Set tx full duplex options */ 1778 bus_space_write_4(t, mac, GEM_MAC_TX_CONFIG, 0); 1779 DELAY(10000); /* reg must be cleared and delay before changing. */ --- 23 unchanged lines hidden (view full) --- 1803 v |= GEM_MAC_XIF_GMII_MODE; 1804 else 1805 v &= ~GEM_MAC_XIF_GMII_MODE; 1806 } else { 1807 /* Internal MII needs buf enable */ 1808 v |= GEM_MAC_XIF_MII_BUF_ENA; 1809 } 1810 bus_space_write_4(t, mac, GEM_MAC_XIF_CONFIG, v); |
1811 GEM_UNLOCK(sc); |
|
1758} 1759 1760int 1761gem_mediachange(ifp) 1762 struct ifnet *ifp; 1763{ 1764 struct gem_softc *sc = ifp->if_softc; 1765 --- 4 unchanged lines hidden (view full) --- 1770 1771void 1772gem_mediastatus(ifp, ifmr) 1773 struct ifnet *ifp; 1774 struct ifmediareq *ifmr; 1775{ 1776 struct gem_softc *sc = ifp->if_softc; 1777 | 1812} 1813 1814int 1815gem_mediachange(ifp) 1816 struct ifnet *ifp; 1817{ 1818 struct gem_softc *sc = ifp->if_softc; 1819 --- 4 unchanged lines hidden (view full) --- 1824 1825void 1826gem_mediastatus(ifp, ifmr) 1827 struct ifnet *ifp; 1828 struct ifmediareq *ifmr; 1829{ 1830 struct gem_softc *sc = ifp->if_softc; 1831 |
1778 if ((ifp->if_flags & IFF_UP) == 0) | 1832 GEM_LOCK(sc); 1833 if ((ifp->if_flags & IFF_UP) == 0) { 1834 GEM_UNLOCK(sc); |
1779 return; | 1835 return; |
1836 } |
|
1780 | 1837 |
1838 GEM_UNLOCK(sc); |
|
1781 mii_pollstat(sc->sc_mii); | 1839 mii_pollstat(sc->sc_mii); |
1840 GEM_LOCK(sc); |
|
1782 ifmr->ifm_active = sc->sc_mii->mii_media_active; 1783 ifmr->ifm_status = sc->sc_mii->mii_media_status; | 1841 ifmr->ifm_active = sc->sc_mii->mii_media_active; 1842 ifmr->ifm_status = sc->sc_mii->mii_media_status; |
1843 GEM_UNLOCK(sc); |
|
1784} 1785 1786/* 1787 * Process an ioctl request. 1788 */ 1789static int 1790gem_ioctl(ifp, cmd, data) 1791 struct ifnet *ifp; 1792 u_long cmd; 1793 caddr_t data; 1794{ 1795 struct gem_softc *sc = ifp->if_softc; 1796 struct ifreq *ifr = (struct ifreq *)data; | 1844} 1845 1846/* 1847 * Process an ioctl request. 1848 */ 1849static int 1850gem_ioctl(ifp, cmd, data) 1851 struct ifnet *ifp; 1852 u_long cmd; 1853 caddr_t data; 1854{ 1855 struct gem_softc *sc = ifp->if_softc; 1856 struct ifreq *ifr = (struct ifreq *)data; |
1797 int s, error = 0; | 1857 int error = 0; |
1798 | 1858 |
1859 GEM_LOCK(sc); 1860 |
|
1799 switch (cmd) { 1800 case SIOCSIFADDR: 1801 case SIOCGIFADDR: 1802 case SIOCSIFMTU: | 1861 switch (cmd) { 1862 case SIOCSIFADDR: 1863 case SIOCGIFADDR: 1864 case SIOCSIFMTU: |
1865 GEM_UNLOCK(sc); |
|
1803 error = ether_ioctl(ifp, cmd, data); | 1866 error = ether_ioctl(ifp, cmd, data); |
1867 GEM_LOCK(sc); |
|
1804 break; 1805 case SIOCSIFFLAGS: 1806 if (ifp->if_flags & IFF_UP) { 1807 if ((sc->sc_ifflags ^ ifp->if_flags) == IFF_PROMISC) 1808 gem_setladrf(sc); 1809 else | 1868 break; 1869 case SIOCSIFFLAGS: 1870 if (ifp->if_flags & IFF_UP) { 1871 if ((sc->sc_ifflags ^ ifp->if_flags) == IFF_PROMISC) 1872 gem_setladrf(sc); 1873 else |
1810 gem_init(sc); | 1874 gem_init_locked(sc); |
1811 } else { 1812 if (ifp->if_flags & IFF_RUNNING) 1813 gem_stop(ifp, 0); 1814 } 1815 sc->sc_ifflags = ifp->if_flags; 1816 error = 0; 1817 break; 1818 case SIOCADDMULTI: 1819 case SIOCDELMULTI: 1820 gem_setladrf(sc); 1821 error = 0; 1822 break; 1823 case SIOCGIFMEDIA: 1824 case SIOCSIFMEDIA: | 1875 } else { 1876 if (ifp->if_flags & IFF_RUNNING) 1877 gem_stop(ifp, 0); 1878 } 1879 sc->sc_ifflags = ifp->if_flags; 1880 error = 0; 1881 break; 1882 case SIOCADDMULTI: 1883 case SIOCDELMULTI: 1884 gem_setladrf(sc); 1885 error = 0; 1886 break; 1887 case SIOCGIFMEDIA: 1888 case SIOCSIFMEDIA: |
1889 GEM_UNLOCK(sc); |
|
1825 error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii->mii_media, cmd); | 1890 error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii->mii_media, cmd); |
1891 GEM_LOCK(sc); |
|
1826 break; 1827 default: 1828 error = ENOTTY; 1829 break; 1830 } 1831 1832 /* Try to get things going again */ 1833 if (ifp->if_flags & IFF_UP) | 1892 break; 1893 default: 1894 error = ENOTTY; 1895 break; 1896 } 1897 1898 /* Try to get things going again */ 1899 if (ifp->if_flags & IFF_UP) |
1834 gem_start(ifp); 1835 splx(s); | 1900 gem_start_locked(ifp); 1901 GEM_UNLOCK(sc); |
1836 return (error); 1837} 1838 1839/* 1840 * Set up the logical address filter. 1841 */ 1842static void 1843gem_setladrf(sc) 1844 struct gem_softc *sc; 1845{ 1846 struct ifnet *ifp = sc->sc_ifp; 1847 struct ifmultiaddr *inm; 1848 bus_space_tag_t t = sc->sc_bustag; 1849 bus_space_handle_t h = sc->sc_h; 1850 u_int32_t crc; 1851 u_int32_t hash[16]; 1852 u_int32_t v; 1853 int i; 1854 | 1902 return (error); 1903} 1904 1905/* 1906 * Set up the logical address filter. 1907 */ 1908static void 1909gem_setladrf(sc) 1910 struct gem_softc *sc; 1911{ 1912 struct ifnet *ifp = sc->sc_ifp; 1913 struct ifmultiaddr *inm; 1914 bus_space_tag_t t = sc->sc_bustag; 1915 bus_space_handle_t h = sc->sc_h; 1916 u_int32_t crc; 1917 u_int32_t hash[16]; 1918 u_int32_t v; 1919 int i; 1920 |
1921 GEM_LOCK_ASSERT(sc, MA_OWNED); 1922 |
|
1855 /* Get current RX configuration */ 1856 v = bus_space_read_4(t, h, GEM_MAC_RX_CONFIG); 1857 1858 /* 1859 * Turn off promiscuous mode, promiscuous group mode (all multicast), 1860 * and hash filter. Depending on the case, the right bit will be 1861 * enabled. 1862 */ --- 52 unchanged lines hidden --- | 1923 /* Get current RX configuration */ 1924 v = bus_space_read_4(t, h, GEM_MAC_RX_CONFIG); 1925 1926 /* 1927 * Turn off promiscuous mode, promiscuous group mode (all multicast), 1928 * and hash filter. Depending on the case, the right bit will be 1929 * enabled. 1930 */ --- 52 unchanged lines hidden --- |