if_dc.c (112819) | if_dc.c (112872) |
---|---|
1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ee.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, 1999 3 * Bill Paul <wpaul@ee.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/dev/dc/if_dc.c 112819 2003-03-29 21:27:07Z silby $ | 32 * $FreeBSD: head/sys/dev/dc/if_dc.c 112872 2003-03-31 17:29:43Z njl $ |
33 */ 34 35/* 36 * DEC "tulip" clone ethernet driver. Supports the DEC/Intel 21143 37 * series chips and several workalikes including the following: 38 * 39 * Macronix 98713/98715/98725/98727/98732 PMAC (www.macronix.com) 40 * Macronix/Lite-On 82c115 PNIC II (www.macronix.com) --- 91 unchanged lines hidden (view full) --- 132 133MODULE_DEPEND(dc, miibus, 1, 1, 1); 134 135/* "controller miibus0" required. See GENERIC if you get errors here. */ 136#include "miibus_if.h" 137 138#ifndef lint 139static const char rcsid[] = | 33 */ 34 35/* 36 * DEC "tulip" clone ethernet driver. Supports the DEC/Intel 21143 37 * series chips and several workalikes including the following: 38 * 39 * Macronix 98713/98715/98725/98727/98732 PMAC (www.macronix.com) 40 * Macronix/Lite-On 82c115 PNIC II (www.macronix.com) --- 91 unchanged lines hidden (view full) --- 132 133MODULE_DEPEND(dc, miibus, 1, 1, 1); 134 135/* "controller miibus0" required. See GENERIC if you get errors here. */ 136#include "miibus_if.h" 137 138#ifndef lint 139static const char rcsid[] = |
140 "$FreeBSD: head/sys/dev/dc/if_dc.c 112819 2003-03-29 21:27:07Z silby $"; | 140 "$FreeBSD: head/sys/dev/dc/if_dc.c 112872 2003-03-31 17:29:43Z njl $"; |
141#endif 142 143/* 144 * Various supported device vendors/types and their names. 145 */ 146static struct dc_type dc_devs[] = { 147 { DC_VENDORID_DEC, DC_DEVICEID_21143, 148 "Intel 21143 10/100BaseTX" }, --- 1751 unchanged lines hidden (view full) --- 1900 struct dc_softc *sc; 1901 struct ifnet *ifp; 1902 u_int32_t revision; 1903 int unit, error = 0, rid, mac_offset; 1904 u_int8_t *mac; 1905 1906 sc = device_get_softc(dev); 1907 unit = device_get_unit(dev); | 141#endif 142 143/* 144 * Various supported device vendors/types and their names. 145 */ 146static struct dc_type dc_devs[] = { 147 { DC_VENDORID_DEC, DC_DEVICEID_21143, 148 "Intel 21143 10/100BaseTX" }, --- 1751 unchanged lines hidden (view full) --- 1900 struct dc_softc *sc; 1901 struct ifnet *ifp; 1902 u_int32_t revision; 1903 int unit, error = 0, rid, mac_offset; 1904 u_int8_t *mac; 1905 1906 sc = device_get_softc(dev); 1907 unit = device_get_unit(dev); |
1908 bzero(sc, sizeof(struct dc_softc)); | |
1909 1910 mtx_init(&sc->dc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 1911 MTX_DEF | MTX_RECURSE); 1912 1913 /* 1914 * Handle power management nonsense. 1915 */ 1916 dc_acpi(dev); --- 28 unchanged lines hidden (view full) --- 1945 printf("dc%d: couldn't map ports/memory\n", unit); 1946 error = ENXIO; 1947 goto fail; 1948 } 1949 1950 sc->dc_btag = rman_get_bustag(sc->dc_res); 1951 sc->dc_bhandle = rman_get_bushandle(sc->dc_res); 1952 | 1908 1909 mtx_init(&sc->dc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 1910 MTX_DEF | MTX_RECURSE); 1911 1912 /* 1913 * Handle power management nonsense. 1914 */ 1915 dc_acpi(dev); --- 28 unchanged lines hidden (view full) --- 1944 printf("dc%d: couldn't map ports/memory\n", unit); 1945 error = ENXIO; 1946 goto fail; 1947 } 1948 1949 sc->dc_btag = rman_get_bustag(sc->dc_res); 1950 sc->dc_bhandle = rman_get_bushandle(sc->dc_res); 1951 |
1952 /* Allocate interrupt */ 1953 rid = 0; 1954 sc->dc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 1955 RF_SHAREABLE | RF_ACTIVE); 1956 1957 if (sc->dc_irq == NULL) { 1958 printf("dc%d: couldn't map interrupt\n", unit); 1959 error = ENXIO; 1960 goto fail; 1961 } 1962 |
|
1953 /* Need this info to decide on a chip type. */ 1954 sc->dc_info = dc_devtype(dev); 1955 revision = pci_read_config(dev, DC_PCI_CFRV, 4) & 0x000000FF; 1956 1957 /* Get the eeprom width, but PNIC and XIRCOM have diff eeprom */ 1958 if (sc->dc_info->dc_did != DC_DEVICEID_82C168 && 1959 sc->dc_info->dc_did != DC_DEVICEID_X3201) 1960 dc_eeprom_width(sc); --- 175 unchanged lines hidden (view full) --- 2136 case DC_TYPE_CONEXANT: 2137 bcopy(sc->dc_srom + DC_CONEXANT_EE_NODEADDR, &eaddr, 6); 2138 break; 2139 case DC_TYPE_XIRCOM: 2140 /* The MAC comes from the CIS */ 2141 mac = pci_get_ether(dev); 2142 if (!mac) { 2143 device_printf(dev, "No station address in CIS!\n"); | 1963 /* Need this info to decide on a chip type. */ 1964 sc->dc_info = dc_devtype(dev); 1965 revision = pci_read_config(dev, DC_PCI_CFRV, 4) & 0x000000FF; 1966 1967 /* Get the eeprom width, but PNIC and XIRCOM have diff eeprom */ 1968 if (sc->dc_info->dc_did != DC_DEVICEID_82C168 && 1969 sc->dc_info->dc_did != DC_DEVICEID_X3201) 1970 dc_eeprom_width(sc); --- 175 unchanged lines hidden (view full) --- 2146 case DC_TYPE_CONEXANT: 2147 bcopy(sc->dc_srom + DC_CONEXANT_EE_NODEADDR, &eaddr, 6); 2148 break; 2149 case DC_TYPE_XIRCOM: 2150 /* The MAC comes from the CIS */ 2151 mac = pci_get_ether(dev); 2152 if (!mac) { 2153 device_printf(dev, "No station address in CIS!\n"); |
2144 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res); | |
2145 error = ENXIO; 2146 goto fail; 2147 } 2148 bcopy(mac, eaddr, ETHER_ADDR_LEN); 2149 break; 2150 default: 2151 dc_read_eeprom(sc, (caddr_t)&eaddr, DC_EE_NODEADDR, 3, 0); 2152 break; --- 7 unchanged lines hidden (view full) --- 2160 sc->dc_unit = unit; 2161 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 2162 2163 sc->dc_ldata = contigmalloc(sizeof(struct dc_list_data), M_DEVBUF, 2164 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); 2165 2166 if (sc->dc_ldata == NULL) { 2167 printf("dc%d: no memory for list buffers!\n", unit); | 2154 error = ENXIO; 2155 goto fail; 2156 } 2157 bcopy(mac, eaddr, ETHER_ADDR_LEN); 2158 break; 2159 default: 2160 dc_read_eeprom(sc, (caddr_t)&eaddr, DC_EE_NODEADDR, 3, 0); 2161 break; --- 7 unchanged lines hidden (view full) --- 2169 sc->dc_unit = unit; 2170 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 2171 2172 sc->dc_ldata = contigmalloc(sizeof(struct dc_list_data), M_DEVBUF, 2173 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); 2174 2175 if (sc->dc_ldata == NULL) { 2176 printf("dc%d: no memory for list buffers!\n", unit); |
2168 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res); | |
2169 error = ENXIO; 2170 goto fail; 2171 } 2172 2173 bzero(sc->dc_ldata, sizeof(struct dc_list_data)); 2174 2175 ifp = &sc->arpcom.ac_if; 2176 ifp->if_softc = sc; --- 42 unchanged lines hidden (view full) --- 2219 */ 2220 if (pci_read_config(dev, DC_PCI_CSID, 4) != 0x80281033) 2221 sc->dc_flags |= DC_TULIP_LEDS; 2222 error = 0; 2223 } 2224 2225 if (error) { 2226 printf("dc%d: MII without any PHY!\n", sc->dc_unit); | 2177 error = ENXIO; 2178 goto fail; 2179 } 2180 2181 bzero(sc->dc_ldata, sizeof(struct dc_list_data)); 2182 2183 ifp = &sc->arpcom.ac_if; 2184 ifp->if_softc = sc; --- 42 unchanged lines hidden (view full) --- 2227 */ 2228 if (pci_read_config(dev, DC_PCI_CSID, 4) != 0x80281033) 2229 sc->dc_flags |= DC_TULIP_LEDS; 2230 error = 0; 2231 } 2232 2233 if (error) { 2234 printf("dc%d: MII without any PHY!\n", sc->dc_unit); |
2227 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res); 2228 error = ENXIO; | |
2229 goto fail; 2230 } 2231 2232 if (DC_IS_XIRCOM(sc)) { 2233 /* 2234 * setup General Purpose Port mode and data so the tulip 2235 * can talk to the MII. 2236 */ --- 46 unchanged lines hidden (view full) --- 2283 } 2284#endif 2285 2286 /* 2287 * Call MI attach routine. 2288 */ 2289 ether_ifattach(ifp, eaddr); 2290 | 2235 goto fail; 2236 } 2237 2238 if (DC_IS_XIRCOM(sc)) { 2239 /* 2240 * setup General Purpose Port mode and data so the tulip 2241 * can talk to the MII. 2242 */ --- 46 unchanged lines hidden (view full) --- 2289 } 2290#endif 2291 2292 /* 2293 * Call MI attach routine. 2294 */ 2295 ether_ifattach(ifp, eaddr); 2296 |
2291 /* Allocate interrupt */ 2292 rid = 0; 2293 sc->dc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 2294 RF_SHAREABLE | RF_ACTIVE); 2295 2296 if (sc->dc_irq == NULL) { 2297 printf("dc%d: couldn't map interrupt\n", unit); 2298 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res); 2299 error = ENXIO; 2300 goto fail; 2301 } 2302 | 2297 /* Hook interrupt last to avoid having to lock softc */ |
2303 error = bus_setup_intr(dev, sc->dc_irq, INTR_TYPE_NET | 2304 (IS_MPSAFE ? INTR_MPSAFE : 0), 2305 dc_intr, sc, &sc->dc_intrhand); 2306 2307 if (error) { | 2298 error = bus_setup_intr(dev, sc->dc_irq, INTR_TYPE_NET | 2299 (IS_MPSAFE ? INTR_MPSAFE : 0), 2300 dc_intr, sc, &sc->dc_intrhand); 2301 2302 if (error) { |
2308 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->dc_irq); 2309 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res); | |
2310 printf("dc%d: couldn't set up irq\n", unit); | 2303 printf("dc%d: couldn't set up irq\n", unit); |
2304 goto fail; |
|
2311 } 2312 2313fail: | 2305 } 2306 2307fail: |
2314 if (error != 0) 2315 mtx_destroy(&sc->dc_mtx); | 2308 if (error) 2309 dc_detach(dev); |
2316 return (error); 2317} 2318 2319static int 2320dc_detach(dev) 2321 device_t dev; 2322{ 2323 struct dc_softc *sc; 2324 struct ifnet *ifp; 2325 struct dc_mediainfo *m; 2326 2327 sc = device_get_softc(dev); | 2310 return (error); 2311} 2312 2313static int 2314dc_detach(dev) 2315 device_t dev; 2316{ 2317 struct dc_softc *sc; 2318 struct ifnet *ifp; 2319 struct dc_mediainfo *m; 2320 2321 sc = device_get_softc(dev); |
2328 | 2322 KASSERT(mtx_initialized(&sc->dc_mtx), "dc mutex not initialized"); |
2329 DC_LOCK(sc); 2330 2331 ifp = &sc->arpcom.ac_if; 2332 | 2323 DC_LOCK(sc); 2324 2325 ifp = &sc->arpcom.ac_if; 2326 |
2333 dc_stop(sc); 2334 ether_ifdetach(ifp); | 2327 if (device_is_alive(dev)) { 2328 if (bus_child_present(dev)) 2329 dc_stop(sc); 2330 ether_ifdetach(ifp); 2331 device_delete_child(dev, sc->dc_miibus); 2332 bus_generic_detach(dev); 2333 } |
2335 | 2334 |
2336 bus_generic_detach(dev); 2337 device_delete_child(dev, sc->dc_miibus); | 2335 if (sc->dc_intrhand) 2336 bus_teardown_intr(dev, sc->dc_irq, sc->dc_intrhand); 2337 if (sc->dc_irq) 2338 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->dc_irq); 2339 if (sc->dc_res) 2340 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res); |
2338 | 2341 |
2339 bus_teardown_intr(dev, sc->dc_irq, sc->dc_intrhand); 2340 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->dc_irq); 2341 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res); | 2342 if (sc->dc_ldata) 2343 contigfree(sc->dc_ldata, sizeof(struct dc_list_data), M_DEVBUF); 2344 free(sc->dc_pnic_rx_buf, M_DEVBUF); |
2342 | 2345 |
2343 contigfree(sc->dc_ldata, sizeof(struct dc_list_data), M_DEVBUF); 2344 if (sc->dc_pnic_rx_buf != NULL) 2345 free(sc->dc_pnic_rx_buf, M_DEVBUF); 2346 | |
2347 while(sc->dc_mi != NULL) { 2348 m = sc->dc_mi->dc_next; 2349 free(sc->dc_mi, M_DEVBUF); 2350 sc->dc_mi = m; 2351 } 2352 free(sc->dc_srom, M_DEVBUF); 2353 2354 DC_UNLOCK(sc); --- 1413 unchanged lines hidden --- | 2346 while(sc->dc_mi != NULL) { 2347 m = sc->dc_mi->dc_next; 2348 free(sc->dc_mi, M_DEVBUF); 2349 sc->dc_mi = m; 2350 } 2351 free(sc->dc_srom, M_DEVBUF); 2352 2353 DC_UNLOCK(sc); --- 1413 unchanged lines hidden --- |