Deleted Added
full compact
if_ti.c (119288) if_ti.c (120980)
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

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

72 * - Raymond Lee of Netgear, for providing a pair of Netgear
73 * GA620 Tigon 2 boards for testing
74 * - Ulf Zimmermann, for bringing the GA260 to my attention and
75 * convincing me to write this driver.
76 * - Andrew Gallatin for providing FreeBSD/Alpha support.
77 */
78
79#include <sys/cdefs.h>
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

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

72 * - Raymond Lee of Netgear, for providing a pair of Netgear
73 * GA620 Tigon 2 boards for testing
74 * - Ulf Zimmermann, for bringing the GA260 to my attention and
75 * convincing me to write this driver.
76 * - Andrew Gallatin for providing FreeBSD/Alpha support.
77 */
78
79#include <sys/cdefs.h>
80__FBSDID("$FreeBSD: head/sys/dev/ti/if_ti.c 119288 2003-08-22 07:20:27Z imp $");
80__FBSDID("$FreeBSD: head/sys/dev/ti/if_ti.c 120980 2003-10-10 20:35:28Z phk $");
81
82#include "opt_ti.h"
83
84#include <sys/param.h>
85#include <sys/systm.h>
86#include <sys/sockio.h>
87#include <sys/mbuf.h>
88#include <sys/malloc.h>

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

127#include <vm/vm_pageout.h>
128#include <sys/vmmeter.h>
129#include <vm/vm_page.h>
130#include <vm/vm_object.h>
131#include <vm/vm_kern.h>
132#include <sys/proc.h>
133#include <sys/jumbo.h>
134#endif /* !TI_PRIVATE_JUMBOS */
81
82#include "opt_ti.h"
83
84#include <sys/param.h>
85#include <sys/systm.h>
86#include <sys/sockio.h>
87#include <sys/mbuf.h>
88#include <sys/malloc.h>

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

127#include <vm/vm_pageout.h>
128#include <sys/vmmeter.h>
129#include <vm/vm_page.h>
130#include <vm/vm_object.h>
131#include <vm/vm_kern.h>
132#include <sys/proc.h>
133#include <sys/jumbo.h>
134#endif /* !TI_PRIVATE_JUMBOS */
135#include <sys/vnode.h> /* for vfindev, vgone */
136
137#include <dev/pci/pcireg.h>
138#include <dev/pci/pcivar.h>
139
140#include <sys/tiio.h>
141#include <pci/if_tireg.h>
142#include <pci/ti_fw.h>
143#include <pci/ti_fw2.h>

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

278};
279
280static devclass_t ti_devclass;
281
282DRIVER_MODULE(ti, pci, ti_driver, ti_devclass, 0, 0);
283MODULE_DEPEND(ti, pci, 1, 1, 1);
284MODULE_DEPEND(ti, ether, 1, 1, 1);
285
135
136#include <dev/pci/pcireg.h>
137#include <dev/pci/pcivar.h>
138
139#include <sys/tiio.h>
140#include <pci/if_tireg.h>
141#include <pci/ti_fw.h>
142#include <pci/ti_fw2.h>

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

277};
278
279static devclass_t ti_devclass;
280
281DRIVER_MODULE(ti, pci, ti_driver, ti_devclass, 0, 0);
282MODULE_DEPEND(ti, pci, 1, 1, 1);
283MODULE_DEPEND(ti, ether, 1, 1, 1);
284
286/* List of Tigon softcs */
287static STAILQ_HEAD(ti_softc_list, ti_softc) ti_sc_list;
288
289static struct ti_softc *
290ti_lookup_softc(int unit)
291{
292 struct ti_softc *sc;
293 for (sc = STAILQ_FIRST(&ti_sc_list); sc != NULL;
294 sc = STAILQ_NEXT(sc, ti_links))
295 if (sc->ti_unit == unit)
296 return(sc);
297 return(NULL);
298}
299
300/*
301 * Send an instruction or address to the EEPROM, check for ACK.
302 */
303static u_int32_t ti_eeprom_putbyte(sc, byte)
304 struct ti_softc *sc;
305 int byte;
306{
307 register int i, ack = 0;

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

2242 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
2243 ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO);
2244
2245 /*
2246 * We're assuming here that card initialization is a sequential
2247 * thing. If it isn't, multiple cards probing at the same time
2248 * could stomp on the list of softcs here.
2249 */
285/*
286 * Send an instruction or address to the EEPROM, check for ACK.
287 */
288static u_int32_t ti_eeprom_putbyte(sc, byte)
289 struct ti_softc *sc;
290 int byte;
291{
292 register int i, ack = 0;

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

2227 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
2228 ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO);
2229
2230 /*
2231 * We're assuming here that card initialization is a sequential
2232 * thing. If it isn't, multiple cards probing at the same time
2233 * could stomp on the list of softcs here.
2234 */
2250 /*
2251 * If this is the first card to be initialized, initialize the
2252 * softc queue.
2253 */
2254 if (unit == 0)
2255 STAILQ_INIT(&ti_sc_list);
2256
2235
2257 STAILQ_INSERT_TAIL(&ti_sc_list, sc, ti_links);
2258
2259 /* Register the device */
2260 sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
2261 0600, "ti%d", sc->ti_unit);
2236 /* Register the device */
2237 sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
2238 0600, "ti%d", sc->ti_unit);
2239 sc->dev->si_drv1 = sc;
2262
2263 /*
2264 * Call MI attach routine.
2265 */
2266 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
2267
2268 /* Hook interrupt last to avoid having to lock softc */
2269 error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET,

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

2278fail:
2279 if (sc && error)
2280 ti_detach(dev);
2281
2282 return(error);
2283}
2284
2285/*
2240
2241 /*
2242 * Call MI attach routine.
2243 */
2244 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
2245
2246 /* Hook interrupt last to avoid having to lock softc */
2247 error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET,

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

2256fail:
2257 if (sc && error)
2258 ti_detach(dev);
2259
2260 return(error);
2261}
2262
2263/*
2286 * Verify that our character special device is not currently
2287 * open. Also track down any cached vnodes & kill them before
2288 * the module is unloaded
2289 */
2290static int
2291ti_unref_special(device_t dev)
2292{
2293 struct vnode *ti_vn;
2294 int count;
2295 struct ti_softc *sc = sc = device_get_softc(dev);
2296
2297 if (!vfinddev(sc->dev, VCHR, &ti_vn)) {
2298 return 0;
2299 }
2300
2301 if ((count = vcount(ti_vn))) {
2302 device_printf(dev, "%d refs to special device, "
2303 "denying unload\n", count);
2304 return count;
2305 }
2306 /* now we know that there's a vnode in the cache. We hunt it
2307 down and kill it now, before unloading */
2308 vgone(ti_vn);
2309 return(0);
2310}
2311
2312/*
2313 * Shutdown hardware and free up resources. This can be called any
2314 * time after the mutex has been initialized. It is called in both
2315 * the error case in attach and the normal detach case so it needs
2316 * to be careful about only freeing resources that have actually been
2317 * allocated.
2318 */
2319static int
2320ti_detach(dev)
2321 device_t dev;
2322{
2323 struct ti_softc *sc;
2324 struct ifnet *ifp;
2325
2264 * Shutdown hardware and free up resources. This can be called any
2265 * time after the mutex has been initialized. It is called in both
2266 * the error case in attach and the normal detach case so it needs
2267 * to be careful about only freeing resources that have actually been
2268 * allocated.
2269 */
2270static int
2271ti_detach(dev)
2272 device_t dev;
2273{
2274 struct ti_softc *sc;
2275 struct ifnet *ifp;
2276
2326 if (ti_unref_special(dev))
2327 return EBUSY;
2328
2329 sc = device_get_softc(dev);
2277 sc = device_get_softc(dev);
2278 destroy_dev(sc->dev);
2330 KASSERT(mtx_initialized(&sc->ti_mtx), ("ti mutex not initialized"));
2331 TI_LOCK(sc);
2332 ifp = &sc->arpcom.ac_if;
2333
2334 /* These should only be active if attach succeeded */
2335 if (device_is_attached(dev)) {
2336 ti_stop(sc);
2337 ether_ifdetach(ifp);

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

3172 TI_UNLOCK(sc);
3173
3174 return(error);
3175}
3176
3177static int
3178ti_open(dev_t dev, int flags, int fmt, struct thread *td)
3179{
2279 KASSERT(mtx_initialized(&sc->ti_mtx), ("ti mutex not initialized"));
2280 TI_LOCK(sc);
2281 ifp = &sc->arpcom.ac_if;
2282
2283 /* These should only be active if attach succeeded */
2284 if (device_is_attached(dev)) {
2285 ti_stop(sc);
2286 ether_ifdetach(ifp);

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

3121 TI_UNLOCK(sc);
3122
3123 return(error);
3124}
3125
3126static int
3127ti_open(dev_t dev, int flags, int fmt, struct thread *td)
3128{
3180 int unit;
3181 struct ti_softc *sc;
3182
3129 struct ti_softc *sc;
3130
3183 unit = minor(dev) & 0xff;
3184
3185 sc = ti_lookup_softc(unit);
3186
3131 sc = dev->si_drv1;
3187 if (sc == NULL)
3188 return(ENODEV);
3189
3190 TI_LOCK(sc);
3191 sc->ti_flags |= TI_FLAG_DEBUGING;
3192 TI_UNLOCK(sc);
3193
3194 return(0);
3195}
3196
3197static int
3198ti_close(dev_t dev, int flag, int fmt, struct thread *td)
3199{
3132 if (sc == NULL)
3133 return(ENODEV);
3134
3135 TI_LOCK(sc);
3136 sc->ti_flags |= TI_FLAG_DEBUGING;
3137 TI_UNLOCK(sc);
3138
3139 return(0);
3140}
3141
3142static int
3143ti_close(dev_t dev, int flag, int fmt, struct thread *td)
3144{
3200 int unit;
3201 struct ti_softc *sc;
3202
3145 struct ti_softc *sc;
3146
3203 unit = minor(dev) & 0xff;
3204
3205 sc = ti_lookup_softc(unit);
3206
3147 sc = dev->si_drv1;
3207 if (sc == NULL)
3208 return(ENODEV);
3209
3210 TI_LOCK(sc);
3211 sc->ti_flags &= ~TI_FLAG_DEBUGING;
3212 TI_UNLOCK(sc);
3213
3214 return(0);
3215}
3216
3217/*
3218 * This ioctl routine goes along with the Tigon character device.
3219 */
3220static int
3221ti_ioctl2(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
3222{
3148 if (sc == NULL)
3149 return(ENODEV);
3150
3151 TI_LOCK(sc);
3152 sc->ti_flags &= ~TI_FLAG_DEBUGING;
3153 TI_UNLOCK(sc);
3154
3155 return(0);
3156}
3157
3158/*
3159 * This ioctl routine goes along with the Tigon character device.
3160 */
3161static int
3162ti_ioctl2(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
3163{
3223 int unit, error;
3164 int error;
3224 struct ti_softc *sc;
3225
3165 struct ti_softc *sc;
3166
3226 unit = minor(dev) & 0xff;
3227
3228 sc = ti_lookup_softc(unit);
3229
3167 sc = dev->si_drv1;
3230 if (sc == NULL)
3231 return(ENODEV);
3232
3233 error = 0;
3234
3235 switch(cmd) {
3236 case TIIOCGETSTATS:
3237 {

--- 342 unchanged lines hidden ---
3168 if (sc == NULL)
3169 return(ENODEV);
3170
3171 error = 0;
3172
3173 switch(cmd) {
3174 case TIIOCGETSTATS:
3175 {

--- 342 unchanged lines hidden ---