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 $ */
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,
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,
217 .bufsize = MCLBYTES,
218 .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
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];
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 }
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];
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 }
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
2007 usbd_transfer_unsetup(sc->sc_xfer, UPGT_N_XFERS);
2008 ieee80211_ifdetach(ic);
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
2026 free(data->buf, M_USBDEV);
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
2039 free(data->buf, M_USBDEV);
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);
2281 usbd_xfer_set_frame_data(xfer, 0, data->buf,
2282 usbd_xfer_max_len(xfer));
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),
2385
2386 { 0, 0 }
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);
2/* $FreeBSD: head/sys/dev/usb/wlan/if_upgt.c 243857 2012-12-04 09:32:43Z glebius $ */
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,
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,
217 .bufsize = MCLBYTES,
218 .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
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];
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 }
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];
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 }
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
2007 usbd_transfer_unsetup(sc->sc_xfer, UPGT_N_XFERS);
2008 ieee80211_ifdetach(ic);
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
2026 free(data->buf, M_USBDEV);
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
2039 free(data->buf, M_USBDEV);
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);
2281 usbd_xfer_set_frame_data(xfer, 0, data->buf,
2282 usbd_xfer_max_len(xfer));
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),
2385
2386 { 0, 0 }
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);