Deleted Added
full compact
if_ti.c (111815) if_ti.c (112872)
1/*
2 * Copyright (c) 1997, 1998, 1999
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, 1999
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/dev/ti/if_ti.c 111815 2003-03-03 12:15:54Z phk $
32 * $FreeBSD: head/sys/dev/ti/if_ti.c 112872 2003-03-31 17:29:43Z njl $
33 */
34
35/*
36 * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD.
37 * Manuals, sample driver and firmware source kits are available
38 * from http://www.alteon.com/support/openkits.
39 *
40 * Written by Bill Paul <wpaul@ctr.columbia.edu>

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

147 * BDs.
148 */
149#if defined(TI_JUMBO_HDRSPLIT) && defined(TI_PRIVATE_JUMBOS)
150#error "options TI_JUMBO_HDRSPLIT and TI_PRIVATE_JUMBOS are mutually exclusive"
151#endif /* TI_JUMBO_HDRSPLIT && TI_JUMBO_HDRSPLIT */
152
153#if !defined(lint)
154static const char rcsid[] =
33 */
34
35/*
36 * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD.
37 * Manuals, sample driver and firmware source kits are available
38 * from http://www.alteon.com/support/openkits.
39 *
40 * Written by Bill Paul <wpaul@ctr.columbia.edu>

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

147 * BDs.
148 */
149#if defined(TI_JUMBO_HDRSPLIT) && defined(TI_PRIVATE_JUMBOS)
150#error "options TI_JUMBO_HDRSPLIT and TI_PRIVATE_JUMBOS are mutually exclusive"
151#endif /* TI_JUMBO_HDRSPLIT && TI_JUMBO_HDRSPLIT */
152
153#if !defined(lint)
154static const char rcsid[] =
155 "$FreeBSD: head/sys/dev/ti/if_ti.c 111815 2003-03-03 12:15:54Z phk $";
155 "$FreeBSD: head/sys/dev/ti/if_ti.c 112872 2003-03-31 17:29:43Z njl $";
156#endif
157
158struct ti_softc *tis[8];
159
160typedef enum {
161 TI_SWAP_HTON,
162 TI_SWAP_NTOH
163} ti_swap_type;

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

2110 device_printf(dev, "\n");
2111 error = EINVAL;
2112 goto fail;
2113 }
2114#endif
2115
2116 sc = device_get_softc(dev);
2117 unit = device_get_unit(dev);
156#endif
157
158struct ti_softc *tis[8];
159
160typedef enum {
161 TI_SWAP_HTON,
162 TI_SWAP_NTOH
163} ti_swap_type;

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

2110 device_printf(dev, "\n");
2111 error = EINVAL;
2112 goto fail;
2113 }
2114#endif
2115
2116 sc = device_get_softc(dev);
2117 unit = device_get_unit(dev);
2118 bzero(sc, sizeof(struct ti_softc));
2119
2120 mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2121 MTX_DEF | MTX_RECURSE);
2122 sc->arpcom.ac_if.if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING;
2123 sc->arpcom.ac_if.if_capenable = sc->arpcom.ac_if.if_capabilities;
2124
2125 /*
2126 * Map control/status registers.

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

2156 RF_SHAREABLE | RF_ACTIVE);
2157
2158 if (sc->ti_irq == NULL) {
2159 printf("ti%d: couldn't map interrupt\n", unit);
2160 error = ENXIO;
2161 goto fail;
2162 }
2163
2118
2119 mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2120 MTX_DEF | MTX_RECURSE);
2121 sc->arpcom.ac_if.if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING;
2122 sc->arpcom.ac_if.if_capenable = sc->arpcom.ac_if.if_capabilities;
2123
2124 /*
2125 * Map control/status registers.

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

2155 RF_SHAREABLE | RF_ACTIVE);
2156
2157 if (sc->ti_irq == NULL) {
2158 printf("ti%d: couldn't map interrupt\n", unit);
2159 error = ENXIO;
2160 goto fail;
2161 }
2162
2164 error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET,
2165 ti_intr, sc, &sc->ti_intrhand);
2166
2167 if (error) {
2168 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2169 bus_release_resource(dev, SYS_RES_MEMORY,
2170 TI_PCI_LOMEM, sc->ti_res);
2171 printf("ti%d: couldn't set up irq\n", unit);
2172 goto fail;
2173 }
2174
2175 sc->ti_unit = unit;
2176
2177 if (ti_chipinit(sc)) {
2178 printf("ti%d: chip initialization failed\n", sc->ti_unit);
2163 sc->ti_unit = unit;
2164
2165 if (ti_chipinit(sc)) {
2166 printf("ti%d: chip initialization failed\n", sc->ti_unit);
2179 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2180 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2181 bus_release_resource(dev, SYS_RES_MEMORY,
2182 TI_PCI_LOMEM, sc->ti_res);
2183 error = ENXIO;
2184 goto fail;
2185 }
2186
2187 /* Zero out the NIC's on-board SRAM. */
2188 ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL);
2189
2190 /* Init again -- zeroing memory may have clobbered some registers. */
2191 if (ti_chipinit(sc)) {
2192 printf("ti%d: chip initialization failed\n", sc->ti_unit);
2167 error = ENXIO;
2168 goto fail;
2169 }
2170
2171 /* Zero out the NIC's on-board SRAM. */
2172 ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL);
2173
2174 /* Init again -- zeroing memory may have clobbered some registers. */
2175 if (ti_chipinit(sc)) {
2176 printf("ti%d: chip initialization failed\n", sc->ti_unit);
2193 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2194 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2195 bus_release_resource(dev, SYS_RES_MEMORY,
2196 TI_PCI_LOMEM, sc->ti_res);
2197 error = ENXIO;
2198 goto fail;
2199 }
2200
2201 /*
2202 * Get station address from the EEPROM. Note: the manual states
2203 * that the MAC address is at offset 0x8c, however the data is
2204 * stored as two longwords (since that's how it's loaded into
2205 * the NIC). This means the MAC address is actually preceded
2206 * by two zero bytes. We need to skip over those.
2207 */
2208 if (ti_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
2209 TI_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) {
2210 printf("ti%d: failed to read station address\n", unit);
2177 error = ENXIO;
2178 goto fail;
2179 }
2180
2181 /*
2182 * Get station address from the EEPROM. Note: the manual states
2183 * that the MAC address is at offset 0x8c, however the data is
2184 * stored as two longwords (since that's how it's loaded into
2185 * the NIC). This means the MAC address is actually preceded
2186 * by two zero bytes. We need to skip over those.
2187 */
2188 if (ti_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
2189 TI_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) {
2190 printf("ti%d: failed to read station address\n", unit);
2211 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2212 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2213 bus_release_resource(dev, SYS_RES_MEMORY,
2214 TI_PCI_LOMEM, sc->ti_res);
2215 error = ENXIO;
2216 goto fail;
2217 }
2218
2219 /*
2220 * A Tigon chip was detected. Inform the world.
2221 */
2222 printf("ti%d: Ethernet address: %6D\n", unit,
2223 sc->arpcom.ac_enaddr, ":");
2224
2225 /* Allocate the general information block and ring buffers. */
2226 sc->ti_rdata = contigmalloc(sizeof(struct ti_ring_data), M_DEVBUF,
2227 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
2228
2229 if (sc->ti_rdata == NULL) {
2191 error = ENXIO;
2192 goto fail;
2193 }
2194
2195 /*
2196 * A Tigon chip was detected. Inform the world.
2197 */
2198 printf("ti%d: Ethernet address: %6D\n", unit,
2199 sc->arpcom.ac_enaddr, ":");
2200
2201 /* Allocate the general information block and ring buffers. */
2202 sc->ti_rdata = contigmalloc(sizeof(struct ti_ring_data), M_DEVBUF,
2203 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
2204
2205 if (sc->ti_rdata == NULL) {
2230 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2231 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2232 bus_release_resource(dev, SYS_RES_MEMORY,
2233 TI_PCI_LOMEM, sc->ti_res);
2234 error = ENXIO;
2235 printf("ti%d: no memory for list buffers!\n", sc->ti_unit);
2206 printf("ti%d: no memory for list buffers!\n", sc->ti_unit);
2207 error = ENXIO;
2236 goto fail;
2237 }
2238
2239 bzero(sc->ti_rdata, sizeof(struct ti_ring_data));
2240
2241 /* Try to allocate memory for jumbo buffers. */
2242#ifdef TI_PRIVATE_JUMBOS
2243 if (ti_alloc_jumbo_mem(sc)) {
2244 printf("ti%d: jumbo buffer allocation failed\n", sc->ti_unit);
2208 goto fail;
2209 }
2210
2211 bzero(sc->ti_rdata, sizeof(struct ti_ring_data));
2212
2213 /* Try to allocate memory for jumbo buffers. */
2214#ifdef TI_PRIVATE_JUMBOS
2215 if (ti_alloc_jumbo_mem(sc)) {
2216 printf("ti%d: jumbo buffer allocation failed\n", sc->ti_unit);
2245 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2246 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2247 bus_release_resource(dev, SYS_RES_MEMORY,
2248 TI_PCI_LOMEM, sc->ti_res);
2249 contigfree(sc->ti_rdata, sizeof(struct ti_ring_data),
2250 M_DEVBUF);
2251 error = ENXIO;
2252 goto fail;
2253 }
2254#else
2255 if (!jumbo_vm_init()) {
2256 printf("ti%d: VM initialization failed!\n", sc->ti_unit);
2217 error = ENXIO;
2218 goto fail;
2219 }
2220#else
2221 if (!jumbo_vm_init()) {
2222 printf("ti%d: VM initialization failed!\n", sc->ti_unit);
2257 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2258 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2259 bus_release_resource(dev, SYS_RES_MEMORY,
2260 TI_PCI_LOMEM, sc->ti_res);
2261 free(sc->ti_rdata, M_DEVBUF);
2262 error = ENOMEM;
2263 goto fail;
2264 }
2265#endif
2266
2267 /*
2268 * We really need a better way to tell a 1000baseTX card
2269 * from a 1000baseSX one, since in theory there could be

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

2354 /* Register the device */
2355 sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
2356 0600, "ti%d", sc->ti_unit);
2357
2358 /*
2359 * Call MI attach routine.
2360 */
2361 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
2223 error = ENOMEM;
2224 goto fail;
2225 }
2226#endif
2227
2228 /*
2229 * We really need a better way to tell a 1000baseTX card
2230 * from a 1000baseSX one, since in theory there could be

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

2315 /* Register the device */
2316 sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
2317 0600, "ti%d", sc->ti_unit);
2318
2319 /*
2320 * Call MI attach routine.
2321 */
2322 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
2362 return(0);
2363
2323
2324 error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET,
2325 ti_intr, sc, &sc->ti_intrhand);
2326
2327 if (error) {
2328 printf("ti%d: couldn't set up irq\n", unit);
2329 goto fail;
2330 }
2331
2364fail:
2332fail:
2365 mtx_destroy(&sc->ti_mtx);
2333 if (sc && error)
2334 ti_detach(dev);
2335
2366 return(error);
2367}
2368
2369/*
2370 * Verify that our character special device is not currently
2371 * open. Also track down any cached vnodes & kill them before
2372 * the module is unloaded
2373 */

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

2400{
2401 struct ti_softc *sc;
2402 struct ifnet *ifp;
2403
2404 if (ti_unref_special(dev))
2405 return EBUSY;
2406
2407 sc = device_get_softc(dev);
2336 return(error);
2337}
2338
2339/*
2340 * Verify that our character special device is not currently
2341 * open. Also track down any cached vnodes & kill them before
2342 * the module is unloaded
2343 */

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

2370{
2371 struct ti_softc *sc;
2372 struct ifnet *ifp;
2373
2374 if (ti_unref_special(dev))
2375 return EBUSY;
2376
2377 sc = device_get_softc(dev);
2378 KASSERT(mtx_initialized(&sc->ti_mtx), "ti mutex not initialized");
2408 TI_LOCK(sc);
2409 ifp = &sc->arpcom.ac_if;
2410
2379 TI_LOCK(sc);
2380 ifp = &sc->arpcom.ac_if;
2381
2411 ether_ifdetach(ifp);
2412 ti_stop(sc);
2382 if (device_is_alive(dev)) {
2383 if (bus_child_present(dev))
2384 ti_stop(sc);
2385 ether_ifdetach(ifp);
2386 bus_generic_detach(dev);
2387 ifmedia_removeall(&sc->ifmedia);
2388 }
2413
2389
2414 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2415 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2416 bus_release_resource(dev, SYS_RES_MEMORY, TI_PCI_LOMEM, sc->ti_res);
2390 if (sc->ti_intrhand)
2391 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2392 if (sc->ti_irq)
2393 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2394 if (sc->ti_res) {
2395 bus_release_resource(dev, SYS_RES_MEMORY, TI_PCI_LOMEM,
2396 sc->ti_res);
2397 }
2417
2418#ifdef TI_PRIVATE_JUMBOS
2398
2399#ifdef TI_PRIVATE_JUMBOS
2419 contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM, M_DEVBUF);
2400 if (sc->ti_cdata.ti_jumbo_buf)
2401 contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM, M_DEVBUF);
2420#endif
2402#endif
2421 contigfree(sc->ti_rdata, sizeof(struct ti_ring_data), M_DEVBUF);
2422 ifmedia_removeall(&sc->ifmedia);
2403 if (sc->ti_rdata)
2404 contigfree(sc->ti_rdata, sizeof(struct ti_ring_data), M_DEVBUF);
2423
2424 TI_UNLOCK(sc);
2425 mtx_destroy(&sc->ti_mtx);
2426
2427 return(0);
2428}
2429
2430#ifdef TI_JUMBO_HDRSPLIT

--- 1217 unchanged lines hidden ---
2405
2406 TI_UNLOCK(sc);
2407 mtx_destroy(&sc->ti_mtx);
2408
2409 return(0);
2410}
2411
2412#ifdef TI_JUMBO_HDRSPLIT

--- 1217 unchanged lines hidden ---