1/* $OpenBSD: if_upgt.c,v 1.35 2008/04/16 18:32:15 damien Exp $ */ |
2/* $FreeBSD: head/sys/dev/usb/wlan/if_upgt.c 244503 2012-12-20 18:38:02Z hselasky $ */ |
3 4/* 5 * Copyright (c) 2007 Marcus Glocker <mglocker@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * --- 185 unchanged lines hidden (view full) --- 196static usb_callback_t upgt_bulk_rx_callback; 197static usb_callback_t upgt_bulk_tx_callback; 198 199static const struct usb_config upgt_config[UPGT_N_XFERS] = { 200 [UPGT_BULK_TX] = { 201 .type = UE_BULK, 202 .endpoint = UE_ADDR_ANY, 203 .direction = UE_DIR_OUT, |
204 .bufsize = MCLBYTES * UPGT_TX_MAXCOUNT, |
205 .flags = { |
206 .force_short_xfer = 1, 207 .pipe_bof = 1 208 }, 209 .callback = upgt_bulk_tx_callback, 210 .timeout = UPGT_USB_TIMEOUT, /* ms */ 211 }, 212 [UPGT_BULK_RX] = { 213 .type = UE_BULK, 214 .endpoint = UE_ADDR_ANY, 215 .direction = UE_DIR_IN, |
216 .bufsize = MCLBYTES * UPGT_RX_MAXCOUNT, |
217 .flags = { |
218 .pipe_bof = 1, 219 .short_xfer_ok = 1 220 }, 221 .callback = upgt_bulk_rx_callback, 222 }, 223}; 224 225static int --- 44 unchanged lines hidden (view full) --- 270 error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, 271 upgt_config, UPGT_N_XFERS, sc, &sc->sc_mtx); 272 if (error) { 273 device_printf(dev, "could not allocate USB transfers, " 274 "err=%s\n", usbd_errstr(error)); 275 goto fail3; 276 } 277 |
278 sc->sc_rx_dma_buf = usbd_xfer_get_frame_buffer( 279 sc->sc_xfer[UPGT_BULK_RX], 0); 280 sc->sc_tx_dma_buf = usbd_xfer_get_frame_buffer( 281 sc->sc_xfer[UPGT_BULK_TX], 0); 282 |
283 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); 284 if (ifp == NULL) { 285 device_printf(dev, "can not if_alloc()\n"); 286 goto fail4; 287 } 288 289 /* Initialize the device. */ 290 error = upgt_device_reset(sc); --- 1659 unchanged lines hidden (view full) --- 1950 int i; 1951 1952 STAILQ_INIT(&sc->sc_tx_active); 1953 STAILQ_INIT(&sc->sc_tx_inactive); 1954 STAILQ_INIT(&sc->sc_tx_pending); 1955 1956 for (i = 0; i < UPGT_TX_MAXCOUNT; i++) { 1957 struct upgt_data *data = &sc->sc_tx_data[i]; |
1958 data->buf = ((uint8_t *)sc->sc_tx_dma_buf) + (i * MCLBYTES); |
1959 STAILQ_INSERT_TAIL(&sc->sc_tx_inactive, data, next); 1960 UPGT_STAT_INC(sc, st_tx_inactive); 1961 } 1962 1963 return (0); 1964} 1965 1966static int 1967upgt_alloc_rx(struct upgt_softc *sc) 1968{ 1969 int i; 1970 1971 STAILQ_INIT(&sc->sc_rx_active); 1972 STAILQ_INIT(&sc->sc_rx_inactive); 1973 1974 for (i = 0; i < UPGT_RX_MAXCOUNT; i++) { 1975 struct upgt_data *data = &sc->sc_rx_data[i]; |
1976 data->buf = ((uint8_t *)sc->sc_rx_dma_buf) + (i * MCLBYTES); |
1977 STAILQ_INSERT_TAIL(&sc->sc_rx_inactive, data, next); 1978 } 1979 1980 return (0); 1981} 1982 1983static int 1984upgt_detach(device_t dev) --- 5 unchanged lines hidden (view full) --- 1990 if (!device_is_attached(dev)) 1991 return 0; 1992 1993 upgt_stop(sc); 1994 1995 callout_drain(&sc->sc_led_ch); 1996 callout_drain(&sc->sc_watchdog_ch); 1997 |
1998 ieee80211_ifdetach(ic); |
1999 2000 usbd_transfer_unsetup(sc->sc_xfer, UPGT_N_XFERS); 2001 |
2002 upgt_free_rx(sc); 2003 upgt_free_tx(sc); 2004 2005 if_free(ifp); 2006 mtx_destroy(&sc->sc_mtx); 2007 2008 return (0); 2009} 2010 2011static void 2012upgt_free_rx(struct upgt_softc *sc) 2013{ 2014 int i; 2015 2016 for (i = 0; i < UPGT_RX_MAXCOUNT; i++) { 2017 struct upgt_data *data = &sc->sc_rx_data[i]; 2018 |
2019 data->buf = NULL; |
2020 data->ni = NULL; 2021 } 2022} 2023 2024static void 2025upgt_free_tx(struct upgt_softc *sc) 2026{ 2027 int i; 2028 2029 for (i = 0; i < UPGT_TX_MAXCOUNT; i++) { 2030 struct upgt_data *data = &sc->sc_tx_data[i]; 2031 |
2032 data->buf = NULL; |
2033 data->ni = NULL; 2034 } 2035} 2036 2037static void 2038upgt_abort_xfers_locked(struct upgt_softc *sc) 2039{ 2040 int i; --- 225 unchanged lines hidden (view full) --- 2266 /* FALLTHROUGH */ 2267 case USB_ST_SETUP: 2268setup: 2269 data = STAILQ_FIRST(&sc->sc_rx_inactive); 2270 if (data == NULL) 2271 return; 2272 STAILQ_REMOVE_HEAD(&sc->sc_rx_inactive, next); 2273 STAILQ_INSERT_TAIL(&sc->sc_rx_active, data, next); |
2274 usbd_xfer_set_frame_data(xfer, 0, data->buf, MCLBYTES); |
2275 usbd_transfer_submit(xfer); 2276 2277 /* 2278 * To avoid LOR we should unlock our private mutex here to call 2279 * ieee80211_input() because here is at the end of a USB 2280 * callback and safe to unlock. 2281 */ 2282 UPGT_UNLOCK(sc); --- 86 unchanged lines hidden (view full) --- 2369 } 2370} 2371 2372static device_method_t upgt_methods[] = { 2373 /* Device interface */ 2374 DEVMETHOD(device_probe, upgt_match), 2375 DEVMETHOD(device_attach, upgt_attach), 2376 DEVMETHOD(device_detach, upgt_detach), |
2377 DEVMETHOD_END |
2378}; 2379 2380static driver_t upgt_driver = { 2381 .name = "upgt", 2382 .methods = upgt_methods, 2383 .size = sizeof(struct upgt_softc) 2384}; 2385 2386static devclass_t upgt_devclass; 2387 2388DRIVER_MODULE(if_upgt, uhub, upgt_driver, upgt_devclass, NULL, 0); 2389MODULE_VERSION(if_upgt, 1); 2390MODULE_DEPEND(if_upgt, usb, 1, 1, 1); 2391MODULE_DEPEND(if_upgt, wlan, 1, 1, 1); 2392MODULE_DEPEND(if_upgt, upgtfw_fw, 1, 1, 1); |