ubtbcmfw.c (193045) | ubtbcmfw.c (194228) |
---|---|
1/* 2 * ubtbcmfw.c 3 */ 4 5/*- 6 * Copyright (c) 2003-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com> 7 * All rights reserved. 8 * --- 14 unchanged lines hidden (view full) --- 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $Id: ubtbcmfw.c,v 1.3 2003/10/10 19:15:08 max Exp $ | 1/* 2 * ubtbcmfw.c 3 */ 4 5/*- 6 * Copyright (c) 2003-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com> 7 * All rights reserved. 8 * --- 14 unchanged lines hidden (view full) --- 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $Id: ubtbcmfw.c,v 1.3 2003/10/10 19:15:08 max Exp $ |
31 * $FreeBSD: head/sys/netgraph/bluetooth/drivers/ubtbcmfw/ubtbcmfw.c 193045 2009-05-29 18:46:57Z thompsa $ | 31 * $FreeBSD: head/sys/netgraph/bluetooth/drivers/ubtbcmfw/ubtbcmfw.c 194228 2009-06-15 01:02:43Z thompsa $ |
32 */ 33 34#include "usbdevs.h" 35#include <dev/usb/usb.h> 36#include <dev/usb/usb_mfunc.h> 37#include <dev/usb/usb_error.h> 38#include <dev/usb/usb_ioctl.h> 39 | 32 */ 33 34#include "usbdevs.h" 35#include <dev/usb/usb.h> 36#include <dev/usb/usb_mfunc.h> 37#include <dev/usb/usb_error.h> 38#include <dev/usb/usb_ioctl.h> 39 |
40#define USB_DEBUG_VAR usb2_debug | 40#define USB_DEBUG_VAR usb_debug |
41 42#include <dev/usb/usb_core.h> 43#include <dev/usb/usb_debug.h> 44#include <dev/usb/usb_parse.h> 45#include <dev/usb/usb_lookup.h> 46#include <dev/usb/usb_util.h> 47#include <dev/usb/usb_busdma.h> 48#include <dev/usb/usb_mbuf.h> --- 126 unchanged lines hidden (view full) --- 175 struct usb_attach_arg *uaa = device_get_ivars(dev); 176 177 if (uaa->usb_mode != USB_MODE_HOST) 178 return (ENXIO); 179 180 if (uaa->info.bIfaceIndex != 0) 181 return (ENXIO); 182 | 41 42#include <dev/usb/usb_core.h> 43#include <dev/usb/usb_debug.h> 44#include <dev/usb/usb_parse.h> 45#include <dev/usb/usb_lookup.h> 46#include <dev/usb/usb_util.h> 47#include <dev/usb/usb_busdma.h> 48#include <dev/usb/usb_mbuf.h> --- 126 unchanged lines hidden (view full) --- 175 struct usb_attach_arg *uaa = device_get_ivars(dev); 176 177 if (uaa->usb_mode != USB_MODE_HOST) 178 return (ENXIO); 179 180 if (uaa->info.bIfaceIndex != 0) 181 return (ENXIO); 182 |
183 return (usb2_lookup_id_by_uaa(devs, sizeof(devs), uaa)); | 183 return (usbd_lookup_id_by_uaa(devs, sizeof(devs), uaa)); |
184} /* ubtbcmfw_probe */ 185 186/* 187 * Attach the device 188 */ 189 190static int 191ubtbcmfw_attach(device_t dev) 192{ 193 struct usb_attach_arg *uaa = device_get_ivars(dev); 194 struct ubtbcmfw_softc *sc = device_get_softc(dev); 195 uint8_t iface_index; 196 int error; 197 198 sc->sc_udev = uaa->device; 199 | 184} /* ubtbcmfw_probe */ 185 186/* 187 * Attach the device 188 */ 189 190static int 191ubtbcmfw_attach(device_t dev) 192{ 193 struct usb_attach_arg *uaa = device_get_ivars(dev); 194 struct ubtbcmfw_softc *sc = device_get_softc(dev); 195 uint8_t iface_index; 196 int error; 197 198 sc->sc_udev = uaa->device; 199 |
200 device_set_usb2_desc(dev); | 200 device_set_usb_desc(dev); |
201 202 mtx_init(&sc->sc_mtx, "ubtbcmfw lock", NULL, MTX_DEF | MTX_RECURSE); 203 204 iface_index = UBTBCMFW_IFACE_IDX; | 201 202 mtx_init(&sc->sc_mtx, "ubtbcmfw lock", NULL, MTX_DEF | MTX_RECURSE); 203 204 iface_index = UBTBCMFW_IFACE_IDX; |
205 error = usb2_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, | 205 error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, |
206 ubtbcmfw_config, UBTBCMFW_N_TRANSFER, 207 sc, &sc->sc_mtx); 208 if (error != 0) { 209 device_printf(dev, "allocating USB transfers failed. %s\n", | 206 ubtbcmfw_config, UBTBCMFW_N_TRANSFER, 207 sc, &sc->sc_mtx); 208 if (error != 0) { 209 device_printf(dev, "allocating USB transfers failed. %s\n", |
210 usb2_errstr(error)); | 210 usbd_errstr(error)); |
211 goto detach; 212 } 213 | 211 goto detach; 212 } 213 |
214 error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx, | 214 error = usb_fifo_attach(uaa->device, sc, &sc->sc_mtx, |
215 &ubtbcmfw_fifo_methods, &sc->sc_fifo, 216 device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex, 217 UID_ROOT, GID_OPERATOR, 0644); 218 if (error != 0) { 219 device_printf(dev, "could not attach fifo. %s\n", | 215 &ubtbcmfw_fifo_methods, &sc->sc_fifo, 216 device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex, 217 UID_ROOT, GID_OPERATOR, 0644); 218 if (error != 0) { 219 device_printf(dev, "could not attach fifo. %s\n", |
220 usb2_errstr(error)); | 220 usbd_errstr(error)); |
221 goto detach; 222 } 223 224 return (0); /* success */ 225 226detach: 227 ubtbcmfw_detach(dev); 228 --- 4 unchanged lines hidden (view full) --- 233 * Detach the device 234 */ 235 236static int 237ubtbcmfw_detach(device_t dev) 238{ 239 struct ubtbcmfw_softc *sc = device_get_softc(dev); 240 | 221 goto detach; 222 } 223 224 return (0); /* success */ 225 226detach: 227 ubtbcmfw_detach(dev); 228 --- 4 unchanged lines hidden (view full) --- 233 * Detach the device 234 */ 235 236static int 237ubtbcmfw_detach(device_t dev) 238{ 239 struct ubtbcmfw_softc *sc = device_get_softc(dev); 240 |
241 usb2_fifo_detach(&sc->sc_fifo); | 241 usb_fifo_detach(&sc->sc_fifo); |
242 | 242 |
243 usb2_transfer_unsetup(sc->sc_xfer, UBTBCMFW_N_TRANSFER); | 243 usbd_transfer_unsetup(sc->sc_xfer, UBTBCMFW_N_TRANSFER); |
244 245 mtx_destroy(&sc->sc_mtx); 246 247 return (0); 248} /* ubtbcmfw_detach */ 249 250/* 251 * USB write callback --- 5 unchanged lines hidden (view full) --- 257 struct ubtbcmfw_softc *sc = xfer->priv_sc; 258 struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_TX]; 259 uint32_t actlen; 260 261 switch (USB_GET_STATE(xfer)) { 262 case USB_ST_SETUP: 263 case USB_ST_TRANSFERRED: 264setup_next: | 244 245 mtx_destroy(&sc->sc_mtx); 246 247 return (0); 248} /* ubtbcmfw_detach */ 249 250/* 251 * USB write callback --- 5 unchanged lines hidden (view full) --- 257 struct ubtbcmfw_softc *sc = xfer->priv_sc; 258 struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_TX]; 259 uint32_t actlen; 260 261 switch (USB_GET_STATE(xfer)) { 262 case USB_ST_SETUP: 263 case USB_ST_TRANSFERRED: 264setup_next: |
265 if (usb2_fifo_get_data(f, xfer->frbuffers, 0, | 265 if (usb_fifo_get_data(f, xfer->frbuffers, 0, |
266 xfer->max_data_length, &actlen, 0)) { 267 xfer->frlengths[0] = actlen; | 266 xfer->max_data_length, &actlen, 0)) { 267 xfer->frlengths[0] = actlen; |
268 usb2_start_hardware(xfer); | 268 usbd_transfer_submit(xfer); |
269 } 270 break; 271 272 default: /* Error */ 273 if (xfer->error != USB_ERR_CANCELLED) { 274 /* try to clear stall first */ 275 xfer->flags.stall_pipe = 1; 276 goto setup_next; --- 9 unchanged lines hidden (view full) --- 286static void 287ubtbcmfw_read_callback(struct usb_xfer *xfer) 288{ 289 struct ubtbcmfw_softc *sc = xfer->priv_sc; 290 struct usb_fifo *fifo = sc->sc_fifo.fp[USB_FIFO_RX]; 291 292 switch (USB_GET_STATE(xfer)) { 293 case USB_ST_TRANSFERRED: | 269 } 270 break; 271 272 default: /* Error */ 273 if (xfer->error != USB_ERR_CANCELLED) { 274 /* try to clear stall first */ 275 xfer->flags.stall_pipe = 1; 276 goto setup_next; --- 9 unchanged lines hidden (view full) --- 286static void 287ubtbcmfw_read_callback(struct usb_xfer *xfer) 288{ 289 struct ubtbcmfw_softc *sc = xfer->priv_sc; 290 struct usb_fifo *fifo = sc->sc_fifo.fp[USB_FIFO_RX]; 291 292 switch (USB_GET_STATE(xfer)) { 293 case USB_ST_TRANSFERRED: |
294 usb2_fifo_put_data(fifo, xfer->frbuffers, 0, xfer->actlen, 1); | 294 usb_fifo_put_data(fifo, xfer->frbuffers, 0, xfer->actlen, 1); |
295 /* FALLTHROUGH */ 296 297 case USB_ST_SETUP: 298setup_next: | 295 /* FALLTHROUGH */ 296 297 case USB_ST_SETUP: 298setup_next: |
299 if (usb2_fifo_put_bytes_max(fifo) > 0) { | 299 if (usb_fifo_put_bytes_max(fifo) > 0) { |
300 xfer->frlengths[0] = xfer->max_data_length; | 300 xfer->frlengths[0] = xfer->max_data_length; |
301 usb2_start_hardware(xfer); | 301 usbd_transfer_submit(xfer); |
302 } 303 break; 304 305 default: /* Error */ 306 if (xfer->error != USB_ERR_CANCELLED) { 307 /* try to clear stall first */ 308 xfer->flags.stall_pipe = 1; 309 goto setup_next; --- 6 unchanged lines hidden (view full) --- 316 * Called when we about to start read()ing from the device 317 */ 318 319static void 320ubtbcmfw_start_read(struct usb_fifo *fifo) 321{ 322 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 323 | 302 } 303 break; 304 305 default: /* Error */ 306 if (xfer->error != USB_ERR_CANCELLED) { 307 /* try to clear stall first */ 308 xfer->flags.stall_pipe = 1; 309 goto setup_next; --- 6 unchanged lines hidden (view full) --- 316 * Called when we about to start read()ing from the device 317 */ 318 319static void 320ubtbcmfw_start_read(struct usb_fifo *fifo) 321{ 322 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 323 |
324 usb2_transfer_start(sc->sc_xfer[UBTBCMFW_INTR_DT_RD]); | 324 usbd_transfer_start(sc->sc_xfer[UBTBCMFW_INTR_DT_RD]); |
325} /* ubtbcmfw_start_read */ 326 327/* 328 * Called when we about to stop reading (i.e. closing fifo) 329 */ 330 331static void 332ubtbcmfw_stop_read(struct usb_fifo *fifo) 333{ 334 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 335 | 325} /* ubtbcmfw_start_read */ 326 327/* 328 * Called when we about to stop reading (i.e. closing fifo) 329 */ 330 331static void 332ubtbcmfw_stop_read(struct usb_fifo *fifo) 333{ 334 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 335 |
336 usb2_transfer_stop(sc->sc_xfer[UBTBCMFW_INTR_DT_RD]); | 336 usbd_transfer_stop(sc->sc_xfer[UBTBCMFW_INTR_DT_RD]); |
337} /* ubtbcmfw_stop_read */ 338 339/* 340 * Called when we about to start write()ing to the device, poll()ing 341 * for write or flushing fifo 342 */ 343 344static void 345ubtbcmfw_start_write(struct usb_fifo *fifo) 346{ 347 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 348 | 337} /* ubtbcmfw_stop_read */ 338 339/* 340 * Called when we about to start write()ing to the device, poll()ing 341 * for write or flushing fifo 342 */ 343 344static void 345ubtbcmfw_start_write(struct usb_fifo *fifo) 346{ 347 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 348 |
349 usb2_transfer_start(sc->sc_xfer[UBTBCMFW_BULK_DT_WR]); | 349 usbd_transfer_start(sc->sc_xfer[UBTBCMFW_BULK_DT_WR]); |
350} /* ubtbcmfw_start_write */ 351 352/* 353 * Called when we about to stop writing (i.e. closing fifo) 354 */ 355 356static void 357ubtbcmfw_stop_write(struct usb_fifo *fifo) 358{ 359 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 360 | 350} /* ubtbcmfw_start_write */ 351 352/* 353 * Called when we about to stop writing (i.e. closing fifo) 354 */ 355 356static void 357ubtbcmfw_stop_write(struct usb_fifo *fifo) 358{ 359 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 360 |
361 usb2_transfer_stop(sc->sc_xfer[UBTBCMFW_BULK_DT_WR]); | 361 usbd_transfer_stop(sc->sc_xfer[UBTBCMFW_BULK_DT_WR]); |
362} /* ubtbcmfw_stop_write */ 363 364/* 365 * Called when fifo is open 366 */ 367 368static int 369ubtbcmfw_open(struct usb_fifo *fifo, int fflags) --- 8 unchanged lines hidden (view full) --- 378 379 if (fflags & FREAD) 380 xfer = sc->sc_xfer[UBTBCMFW_INTR_DT_RD]; 381 else if (fflags & FWRITE) 382 xfer = sc->sc_xfer[UBTBCMFW_BULK_DT_WR]; 383 else 384 return (EINVAL); /* should not happen */ 385 | 362} /* ubtbcmfw_stop_write */ 363 364/* 365 * Called when fifo is open 366 */ 367 368static int 369ubtbcmfw_open(struct usb_fifo *fifo, int fflags) --- 8 unchanged lines hidden (view full) --- 378 379 if (fflags & FREAD) 380 xfer = sc->sc_xfer[UBTBCMFW_INTR_DT_RD]; 381 else if (fflags & FWRITE) 382 xfer = sc->sc_xfer[UBTBCMFW_BULK_DT_WR]; 383 else 384 return (EINVAL); /* should not happen */ 385 |
386 if (usb2_fifo_alloc_buffer(fifo, xfer->max_data_length, | 386 if (usb_fifo_alloc_buffer(fifo, xfer->max_data_length, |
387 UBTBCMFW_IFQ_MAXLEN) != 0) 388 return (ENOMEM); 389 390 return (0); 391} /* ubtbcmfw_open */ 392 393/* 394 * Called when fifo is closed 395 */ 396 397static void 398ubtbcmfw_close(struct usb_fifo *fifo, int fflags) 399{ 400 if (fflags & (FREAD | FWRITE)) | 387 UBTBCMFW_IFQ_MAXLEN) != 0) 388 return (ENOMEM); 389 390 return (0); 391} /* ubtbcmfw_open */ 392 393/* 394 * Called when fifo is closed 395 */ 396 397static void 398ubtbcmfw_close(struct usb_fifo *fifo, int fflags) 399{ 400 if (fflags & (FREAD | FWRITE)) |
401 usb2_fifo_free_buffer(fifo); | 401 usb_fifo_free_buffer(fifo); |
402} /* ubtbcmfw_close */ 403 404/* 405 * Process ioctl() on USB device 406 */ 407 408static int 409ubtbcmfw_ioctl(struct usb_fifo *fifo, u_long cmd, void *data, 410 int fflags) 411{ 412 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 413 int error = 0; 414 415 switch (cmd) { 416 case USB_GET_DEVICE_DESC: | 402} /* ubtbcmfw_close */ 403 404/* 405 * Process ioctl() on USB device 406 */ 407 408static int 409ubtbcmfw_ioctl(struct usb_fifo *fifo, u_long cmd, void *data, 410 int fflags) 411{ 412 struct ubtbcmfw_softc *sc = fifo->priv_sc0; 413 int error = 0; 414 415 switch (cmd) { 416 case USB_GET_DEVICE_DESC: |
417 memcpy(data, usb2_get_device_descriptor(sc->sc_udev), | 417 memcpy(data, usbd_get_device_descriptor(sc->sc_udev), |
418 sizeof(struct usb_device_descriptor)); 419 break; 420 421 default: 422 error = EINVAL; 423 break; 424 } 425 426 return (error); 427} /* ubtbcmfw_ioctl */ | 418 sizeof(struct usb_device_descriptor)); 419 break; 420 421 default: 422 error = EINVAL; 423 break; 424 } 425 426 return (error); 427} /* ubtbcmfw_ioctl */ |