if_upgt.c (243857) | if_upgt.c (244503) |
---|---|
1/* $OpenBSD: if_upgt.c,v 1.35 2008/04/16 18:32:15 damien Exp $ */ | 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 243857 2012-12-04 09:32:43Z glebius $ */ | 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, | 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, | 204 .bufsize = MCLBYTES * UPGT_TX_MAXCOUNT, |
205 .flags = { | 205 .flags = { |
206 .ext_buffer = 1, | |
207 .force_short_xfer = 1, 208 .pipe_bof = 1 209 }, 210 .callback = upgt_bulk_tx_callback, 211 .timeout = UPGT_USB_TIMEOUT, /* ms */ 212 }, 213 [UPGT_BULK_RX] = { 214 .type = UE_BULK, 215 .endpoint = UE_ADDR_ANY, 216 .direction = UE_DIR_IN, | 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, |
217 .bufsize = MCLBYTES, | 216 .bufsize = MCLBYTES * UPGT_RX_MAXCOUNT, |
218 .flags = { | 217 .flags = { |
219 .ext_buffer = 1, | |
220 .pipe_bof = 1, 221 .short_xfer_ok = 1 222 }, 223 .callback = upgt_bulk_rx_callback, 224 }, 225}; 226 227static int --- 44 unchanged lines hidden (view full) --- 272 error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, 273 upgt_config, UPGT_N_XFERS, sc, &sc->sc_mtx); 274 if (error) { 275 device_printf(dev, "could not allocate USB transfers, " 276 "err=%s\n", usbd_errstr(error)); 277 goto fail3; 278 } 279 | 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 |
|
280 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); 281 if (ifp == NULL) { 282 device_printf(dev, "can not if_alloc()\n"); 283 goto fail4; 284 } 285 286 /* Initialize the device. */ 287 error = upgt_device_reset(sc); --- 1659 unchanged lines hidden (view full) --- 1947 int i; 1948 1949 STAILQ_INIT(&sc->sc_tx_active); 1950 STAILQ_INIT(&sc->sc_tx_inactive); 1951 STAILQ_INIT(&sc->sc_tx_pending); 1952 1953 for (i = 0; i < UPGT_TX_MAXCOUNT; i++) { 1954 struct upgt_data *data = &sc->sc_tx_data[i]; | 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]; |
1955 1956 data->buf = malloc(MCLBYTES, M_USBDEV, M_NOWAIT | M_ZERO); 1957 if (data->buf == NULL) { 1958 device_printf(sc->sc_dev, 1959 "could not allocate TX buffer\n"); 1960 return (ENOMEM); 1961 } | 1958 data->buf = ((uint8_t *)sc->sc_tx_dma_buf) + (i * MCLBYTES); |
1962 STAILQ_INSERT_TAIL(&sc->sc_tx_inactive, data, next); 1963 UPGT_STAT_INC(sc, st_tx_inactive); 1964 } 1965 1966 return (0); 1967} 1968 1969static int 1970upgt_alloc_rx(struct upgt_softc *sc) 1971{ 1972 int i; 1973 1974 STAILQ_INIT(&sc->sc_rx_active); 1975 STAILQ_INIT(&sc->sc_rx_inactive); 1976 1977 for (i = 0; i < UPGT_RX_MAXCOUNT; i++) { 1978 struct upgt_data *data = &sc->sc_rx_data[i]; | 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]; |
1979 1980 data->buf = malloc(MCLBYTES, M_USBDEV, M_NOWAIT | M_ZERO); 1981 if (data->buf == NULL) { 1982 device_printf(sc->sc_dev, 1983 "could not allocate RX buffer\n"); 1984 return (ENOMEM); 1985 } | 1976 data->buf = ((uint8_t *)sc->sc_rx_dma_buf) + (i * MCLBYTES); |
1986 STAILQ_INSERT_TAIL(&sc->sc_rx_inactive, data, next); 1987 } 1988 1989 return (0); 1990} 1991 1992static int 1993upgt_detach(device_t dev) --- 5 unchanged lines hidden (view full) --- 1999 if (!device_is_attached(dev)) 2000 return 0; 2001 2002 upgt_stop(sc); 2003 2004 callout_drain(&sc->sc_led_ch); 2005 callout_drain(&sc->sc_watchdog_ch); 2006 | 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 |
2007 usbd_transfer_unsetup(sc->sc_xfer, UPGT_N_XFERS); | |
2008 ieee80211_ifdetach(ic); | 1998 ieee80211_ifdetach(ic); |
1999 2000 usbd_transfer_unsetup(sc->sc_xfer, UPGT_N_XFERS); 2001 |
|
2009 upgt_free_rx(sc); 2010 upgt_free_tx(sc); 2011 2012 if_free(ifp); 2013 mtx_destroy(&sc->sc_mtx); 2014 2015 return (0); 2016} 2017 2018static void 2019upgt_free_rx(struct upgt_softc *sc) 2020{ 2021 int i; 2022 2023 for (i = 0; i < UPGT_RX_MAXCOUNT; i++) { 2024 struct upgt_data *data = &sc->sc_rx_data[i]; 2025 | 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 |
2026 free(data->buf, M_USBDEV); | 2019 data->buf = NULL; |
2027 data->ni = NULL; 2028 } 2029} 2030 2031static void 2032upgt_free_tx(struct upgt_softc *sc) 2033{ 2034 int i; 2035 2036 for (i = 0; i < UPGT_TX_MAXCOUNT; i++) { 2037 struct upgt_data *data = &sc->sc_tx_data[i]; 2038 | 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 |
2039 free(data->buf, M_USBDEV); | 2032 data->buf = NULL; |
2040 data->ni = NULL; 2041 } 2042} 2043 2044static void 2045upgt_abort_xfers_locked(struct upgt_softc *sc) 2046{ 2047 int i; --- 225 unchanged lines hidden (view full) --- 2273 /* FALLTHROUGH */ 2274 case USB_ST_SETUP: 2275setup: 2276 data = STAILQ_FIRST(&sc->sc_rx_inactive); 2277 if (data == NULL) 2278 return; 2279 STAILQ_REMOVE_HEAD(&sc->sc_rx_inactive, next); 2280 STAILQ_INSERT_TAIL(&sc->sc_rx_active, data, next); | 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); |
2281 usbd_xfer_set_frame_data(xfer, 0, data->buf, 2282 usbd_xfer_max_len(xfer)); | 2274 usbd_xfer_set_frame_data(xfer, 0, data->buf, MCLBYTES); |
2283 usbd_transfer_submit(xfer); 2284 2285 /* 2286 * To avoid LOR we should unlock our private mutex here to call 2287 * ieee80211_input() because here is at the end of a USB 2288 * callback and safe to unlock. 2289 */ 2290 UPGT_UNLOCK(sc); --- 86 unchanged lines hidden (view full) --- 2377 } 2378} 2379 2380static device_method_t upgt_methods[] = { 2381 /* Device interface */ 2382 DEVMETHOD(device_probe, upgt_match), 2383 DEVMETHOD(device_attach, upgt_attach), 2384 DEVMETHOD(device_detach, upgt_detach), | 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), |
2385 2386 { 0, 0 } | 2377 DEVMETHOD_END |
2387}; 2388 2389static driver_t upgt_driver = { 2390 .name = "upgt", 2391 .methods = upgt_methods, 2392 .size = sizeof(struct upgt_softc) 2393}; 2394 2395static devclass_t upgt_devclass; 2396 2397DRIVER_MODULE(if_upgt, uhub, upgt_driver, upgt_devclass, NULL, 0); 2398MODULE_VERSION(if_upgt, 1); 2399MODULE_DEPEND(if_upgt, usb, 1, 1, 1); 2400MODULE_DEPEND(if_upgt, wlan, 1, 1, 1); 2401MODULE_DEPEND(if_upgt, upgtfw_fw, 1, 1, 1); | 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); |